1 /******************************************************************************
3 * Copyright (C) 2001-2012 Broadcom Corporation
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 ******************************************************************************/
19 /******************************************************************************
21 * Contains the LogMsg wrapper routines for BTE. It routes calls the
22 * appropriate application's LogMsg equivalent.
24 ******************************************************************************/
38 #if MMI_INCLUDED == TRUE
42 /* always enable trace framework */
46 #if (RFCOMM_INCLUDED==TRUE)
49 #if (OBX_INCLUDED==TRUE)
52 #if (AVCT_INCLUDED==TRUE)
55 #if (AVDT_INCLUDED==TRUE)
58 #if (AVRC_INCLUDED==TRUE)
61 #if (AVDT_INCLUDED==TRUE)
64 #if (A2D_INCLUDED==TRUE)
67 #if (BIP_INCLUDED==TRUE)
70 #if (BNEP_INCLUDED==TRUE)
73 #if (BPP_INCLUDED==TRUE)
77 #if (DUN_INCLUDED==TRUE)
80 #if (GAP_INCLUDED==TRUE)
83 #if (GOEP_INCLUDED==TRUE)
84 #include "goep_util.h"
86 #if (HCRP_INCLUDED==TRUE)
89 #if (PAN_INCLUDED==TRUE)
94 #if (BLE_INCLUDED==TRUE)
99 /* LayerIDs for BTA, currently everything maps onto appl_trace_level */
100 #if (BTA_INCLUDED==TRUE)
105 #if defined(__CYGWIN__) || defined(__linux__)
107 #include <sys/time.h>
110 #if (defined(ANDROID_USE_LOGCAT) && (ANDROID_USE_LOGCAT==TRUE))
111 const char * const bt_layer_tags[] = {
164 #include <cutils/log.h>
165 #define LOGI0(t,s) __android_log_write(ANDROID_LOG_INFO, t, s)
166 #define LOGD0(t,s) __android_log_write(ANDROID_LOG_DEBUG, t, s)
167 #define LOGW0(t,s) __android_log_write(ANDROID_LOG_WARN, t, s)
168 #define LOGE0(t,s) __android_log_write(ANDROID_LOG_ERROR, t, s)
171 #undef ANDROID_USE_LOGCAT
177 //#include "btl_cfg.h"
178 #define BTL_GLOBAL_PROP_TRC_FLAG "TRC_BTAPP"
179 #ifndef DEFAULT_CONF_TRACE_LEVEL
180 #define DEFAULT_CONF_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
183 #ifndef BTE_LOG_BUF_SIZE
184 #define BTE_LOG_BUF_SIZE 1024
186 #define BTE_LOG_MAX_SIZE (BTE_LOG_BUF_SIZE - 12)
189 //#define BTE_MAP_TRACE_LEVEL FALSE
190 /* map by default BTE trace levels onto android trace levels */
191 #ifndef BTE_MAP_TRACE_LEVEL
192 #define BTE_MAP_TRACE_LEVEL TRUE
195 // #define BTE_ANDROID_INTERNAL_TIMESTAMP TRUE
196 /* by default no internal timestamp. adb logcate -v time allows having timestamps */
197 #ifndef BTE_ANDROID_INTERNAL_TIMESTAMP
198 #define BTE_ANDROID_INTERNAL_TIMESTAMP FALSE
200 #if (BTE_ANDROID_INTERNAL_TIMESTAMP==TRUE)
201 #define MSG_BUFFER_OFFSET strlen(buffer)
203 #define MSG_BUFFER_OFFSET 0
208 #if defined( DBG_TRACE )
209 #define DBG_TRACE_API0( m ) BT_TRACE( TRACE_LAYER_HCI, TRACE_TYPE_API, m )
210 #define DBG_TRACE_WARNING2( m, p0, p1 ) BT_TRACE( TRACE_LAYER_BTM, (TRACE_ORG_APPL|TRACE_TYPE_WARNING), m, p0, p1 )
212 #define DBG_TRACE_API0( m )
213 #define DBG_TRACE_WARNING2( m, p0, p1 )
215 #define DBG_TRACE_DEBUG2( m, p0, p1 ) BT_TRACE( TRACE_LAYER_BTM, (TRACE_ORG_APPL|TRACE_TYPE_DEBUG), m, p0, p1 )
218 LogMsg(UINT32 trace_set_mask, const char *fmt_str, ...)
220 static char buffer[BTE_LOG_BUF_SIZE];
221 int trace_layer = TRACE_GET_LAYER(trace_set_mask);
222 if (trace_layer >= TRACE_LAYER_MAX_NUM)
226 #if (BTE_ANDROID_INTERNAL_TIMESTAMP==TRUE)
232 gettimeofday(&tv, &tz);
236 sprintf(buffer, "%02d:%02d:%02d.%03d ", tm->tm_hour, tm->tm_min, tm->tm_sec,
239 va_start(ap, fmt_str);
240 vsnprintf(&buffer[MSG_BUFFER_OFFSET], BTE_LOG_MAX_SIZE, fmt_str, ap);
243 #if (defined(ANDROID_USE_LOGCAT) && (ANDROID_USE_LOGCAT==TRUE))
244 #if (BTE_MAP_TRACE_LEVEL==TRUE)
245 switch ( TRACE_GET_TYPE(trace_set_mask) )
247 case TRACE_TYPE_ERROR:
248 LOGE0(bt_layer_tags[trace_layer], buffer);
250 case TRACE_TYPE_WARNING:
251 LOGW0(bt_layer_tags[trace_layer], buffer);
254 case TRACE_TYPE_EVENT:
255 LOGI0(bt_layer_tags[trace_layer], buffer);
257 case TRACE_TYPE_DEBUG:
258 LOGD0(bt_layer_tags[trace_layer], buffer);
261 LOGE0(bt_layer_tags[trace_layer], buffer); /* we should never get this */
265 LOGI0(bt_layer_tags[trace_layer], buffer);
268 write(2, buffer, strlen(buffer));
274 ScrLog(UINT32 trace_set_mask, const char *fmt_str, ...)
276 static char buffer[BTE_LOG_BUF_SIZE];
283 int trace_layer = TRACE_GET_LAYER(trace_set_mask);
284 if (trace_layer >= TRACE_LAYER_MAX_NUM)
286 gettimeofday(&tv, &tz);
290 sprintf(buffer, "%02d:%02d:%02d.%03ld ", tm->tm_hour, tm->tm_min, tm->tm_sec,
293 va_start(ap, fmt_str);
294 vsnprintf(&buffer[strlen(buffer)], BTE_LOG_MAX_SIZE, fmt_str, ap);
297 #if (defined(ANDROID_USE_LOGCAT) && (ANDROID_USE_LOGCAT==TRUE))
298 LOGI0(bt_layer_tags[trace_layer], buffer);
300 write(2, buffer, strlen(buffer));
305 /* this function should go into BTAPP_DM for example */
306 BT_API UINT8 BTAPP_SetTraceLevel( UINT8 new_level )
308 if (new_level != 0xFF)
309 appl_trace_level = new_level;
311 return (appl_trace_level);
314 BT_API UINT8 BTIF_SetTraceLevel( UINT8 new_level )
316 if (new_level != 0xFF)
317 btif_trace_level = new_level;
319 return (btif_trace_level);
322 BTU_API UINT8 BTU_SetTraceLevel( UINT8 new_level )
324 if (new_level != 0xFF)
325 btu_cb.trace_level = new_level;
327 return (btu_cb.trace_level);
330 BOOLEAN trace_conf_enabled = FALSE;
332 void bte_trace_conf(const char *p_conf_name, const char *p_conf_value)
334 tBTTRC_FUNC_MAP *p_f_map = (tBTTRC_FUNC_MAP *) &bttrc_set_level_map[0];
336 while (p_f_map->trc_name != NULL)
338 if (strcmp(p_f_map->trc_name, (const char *)p_conf_name) == 0)
340 p_f_map->trace_level = (UINT8) atoi(p_conf_value);
347 void bte_trace_conf_config(const config_t *config) {
348 assert(config != NULL);
350 for (tBTTRC_FUNC_MAP *functions = &bttrc_set_level_map[0]; functions->trc_name; ++functions) {
351 int value = config_get_int(config, CONFIG_DEFAULT_SECTION, functions->trc_name, -1);
353 functions->trace_level = value;
357 /********************************************************************************
359 ** Function Name: BTA_SysSetTraceLevel
361 ** Purpose: set or reads the different Trace Levels of layer IDs (see bt_trace.h,
364 ** Input Parameters: Array with trace layers to set to a given level or read. a layer ID of 0
365 ** defines the end of the list
366 ** WARNING: currently type should be 0-5! or FF for reading!!!!
369 ** input array with trace levels for given layer id
371 *********************************************************************************/
372 BT_API tBTTRC_LEVEL * BTA_SysSetTraceLevel(tBTTRC_LEVEL * p_levels)
374 const tBTTRC_FUNC_MAP *p_f_map;
375 tBTTRC_LEVEL *p_l = p_levels;
377 DBG_TRACE_API0( "BTA_SysSetTraceLevel()" );
379 while (0 != p_l->layer_id)
381 p_f_map = &bttrc_set_level_map[0];
383 while (0 != p_f_map->layer_id_start)
385 printf("BTA_SysSetTraceLevel - trace id in map start = %d end= %d, paramter id = %d\r\n", p_f_map->layer_id_start, p_f_map->layer_id_end, p_l->layer_id );
386 /* as p_f_map is ordered by increasing layer id, go to next map entry as long end id
388 //if (p_f_map->layer_id_end < p_l->layer_id)
394 /* check if layer_id actually false into a range or if it is note existing in the map */
395 if ((NULL != p_f_map->p_f) && (p_f_map->layer_id_start <= p_l->layer_id) && (p_f_map->layer_id_end >= p_l->layer_id) )
397 DBG_TRACE_DEBUG2( "BTA_SysSetTraceLevel( id:%d, level:%d ): setting/reading",
398 p_l->layer_id, p_l->type );
399 p_l->type = p_f_map->p_f(p_l->type);
404 DBG_TRACE_WARNING2( "BTA_SysSetTraceLevel( id:%d, level:%d ): MISSING Set function OR ID in map!",
405 p_l->layer_id, p_l->type );
407 /* set/read next trace level by getting out ot map loop */
413 //if (0 == p_f_map->layer_id_start)
415 DBG_TRACE_WARNING2( "BTA_SysSetTraceLevel( id:%d, level:%d ): ID NOT FOUND in map. Skip to next",
416 p_l->layer_id, p_l->type );
422 } /* BTA_SysSetTraceLevel() */
424 /* make sure list is order by increasing layer id!!! */
425 tBTTRC_FUNC_MAP bttrc_set_level_map[] = {
426 {BTTRC_ID_STK_BTU, BTTRC_ID_STK_HCI, BTU_SetTraceLevel, "TRC_HCI", DEFAULT_CONF_TRACE_LEVEL},
427 {BTTRC_ID_STK_L2CAP, BTTRC_ID_STK_L2CAP, L2CA_SetTraceLevel, "TRC_L2CAP", DEFAULT_CONF_TRACE_LEVEL},
428 #if (RFCOMM_INCLUDED==TRUE)
429 {BTTRC_ID_STK_RFCOMM, BTTRC_ID_STK_RFCOMM_DATA, PORT_SetTraceLevel, "TRC_RFCOMM", DEFAULT_CONF_TRACE_LEVEL},
431 #if (OBX_INCLUDED==TRUE)
432 {BTTRC_ID_STK_OBEX, BTTRC_ID_STK_OBEX, OBX_SetTraceLevel, "TRC_OBEX", DEFAULT_CONF_TRACE_LEVEL},
434 #if (AVCT_INCLUDED==TRUE)
435 //{BTTRC_ID_STK_AVCT, BTTRC_ID_STK_AVCT, NULL, "TRC_AVCT", DEFAULT_CONF_TRACE_LEVEL},
437 #if (AVDT_INCLUDED==TRUE)
438 {BTTRC_ID_STK_AVDT, BTTRC_ID_STK_AVDT, AVDT_SetTraceLevel, "TRC_AVDT", DEFAULT_CONF_TRACE_LEVEL},
440 #if (AVRC_INCLUDED==TRUE)
441 {BTTRC_ID_STK_AVRC, BTTRC_ID_STK_AVRC, AVRC_SetTraceLevel, "TRC_AVRC", DEFAULT_CONF_TRACE_LEVEL},
443 #if (AVDT_INCLUDED==TRUE)
444 //{BTTRC_ID_AVDT_SCB, BTTRC_ID_AVDT_CCB, NULL, "TRC_AVDT_SCB", DEFAULT_CONF_TRACE_LEVEL},
446 #if (A2D_INCLUDED==TRUE)
447 {BTTRC_ID_STK_A2D, BTTRC_ID_STK_A2D, A2D_SetTraceLevel, "TRC_A2D", DEFAULT_CONF_TRACE_LEVEL},
449 #if (BIP_INCLUDED==TRUE)
450 {BTTRC_ID_STK_BIP, BTTRC_ID_STK_BIP, BIP_SetTraceLevel, "TRC_BIP", DEFAULT_CONF_TRACE_LEVEL},
452 #if (BNEP_INCLUDED==TRUE)
453 {BTTRC_ID_STK_BNEP, BTTRC_ID_STK_BNEP, BNEP_SetTraceLevel, "TRC_BNEP", DEFAULT_CONF_TRACE_LEVEL},
455 #if (BPP_INCLUDED==TRUE)
456 {BTTRC_ID_STK_BPP, BTTRC_ID_STK_BPP, BPP_SetTraceLevel, "TRC_BPP", DEFAULT_CONF_TRACE_LEVEL},
458 {BTTRC_ID_STK_BTM_ACL, BTTRC_ID_STK_BTM_SEC, BTM_SetTraceLevel, "TRC_BTM", DEFAULT_CONF_TRACE_LEVEL},
459 #if (DUN_INCLUDED==TRUE)
460 {BTTRC_ID_STK_DUN, BTTRC_ID_STK_DUN, DUN_SetTraceLevel, "TRC_DUN", DEFAULT_CONF_TRACE_LEVEL},
462 #if (GAP_INCLUDED==TRUE)
463 {BTTRC_ID_STK_GAP, BTTRC_ID_STK_GAP, GAP_SetTraceLevel, "TRC_GAP", DEFAULT_CONF_TRACE_LEVEL},
465 #if (GOEP_INCLUDED==TRUE)
466 {BTTRC_ID_STK_GOEP, BTTRC_ID_STK_GOEP, GOEP_SetTraceLevel, "TRC_GOEP", DEFAULT_CONF_TRACE_LEVEL},
468 #if (HCRP_INCLUDED==TRUE)
469 {BTTRC_ID_STK_HCRP, BTTRC_ID_STK_HCRP, HCRP_SetTraceLevel, "TRC_HCRP", DEFAULT_CONF_TRACE_LEVEL},
471 #if (PAN_INCLUDED==TRUE)
472 {BTTRC_ID_STK_PAN, BTTRC_ID_STK_PAN, PAN_SetTraceLevel, "TRC_PAN", DEFAULT_CONF_TRACE_LEVEL},
474 #if (SAP_SERVER_INCLUDED==TRUE)
475 {BTTRC_ID_STK_SAP, BTTRC_ID_STK_SAP, NULL, "TRC_SAP", DEFAULT_CONF_TRACE_LEVEL},
477 {BTTRC_ID_STK_SDP, BTTRC_ID_STK_SDP, SDP_SetTraceLevel, "TRC_SDP", DEFAULT_CONF_TRACE_LEVEL},
478 #if (BLE_INCLUDED==TRUE)
479 {BTTRC_ID_STK_GATT, BTTRC_ID_STK_GATT, GATT_SetTraceLevel, "TRC_GATT", DEFAULT_CONF_TRACE_LEVEL},
480 {BTTRC_ID_STK_SMP, BTTRC_ID_STK_SMP, SMP_SetTraceLevel, "TRC_SMP", DEFAULT_CONF_TRACE_LEVEL},
483 #if (BTA_INCLUDED==TRUE)
484 /* LayerIDs for BTA, currently everything maps onto appl_trace_level.
485 * BTL_GLOBAL_PROP_TRC_FLAG serves as flag in conf.
487 {BTTRC_ID_BTA_ACC, BTTRC_ID_BTAPP, BTAPP_SetTraceLevel, BTL_GLOBAL_PROP_TRC_FLAG, DEFAULT_CONF_TRACE_LEVEL},
490 #if (BT_TRACE_BTIF == TRUE)
491 {BTTRC_ID_BTA_ACC, BTTRC_ID_BTAPP, BTIF_SetTraceLevel, "TRC_BTIF", DEFAULT_CONF_TRACE_LEVEL},
494 {0, 0, NULL, NULL, DEFAULT_CONF_TRACE_LEVEL}
497 const UINT16 bttrc_map_size = sizeof(bttrc_set_level_map)/sizeof(tBTTRC_FUNC_MAP);
500 /********************************************************************************
502 ** Function Name: BTE_InitTraceLevels
504 ** Purpose: This function can be used to set the boot time reading it from the
506 ** WARNING: it is called under BTU context and it blocks the BTU task
507 ** till it returns (sync call)
509 ** Input Parameters: None, platform to provide levels
511 ** Newly set levels, if any!
513 *********************************************************************************/
514 BT_API void BTE_InitTraceLevels( void )
516 /* read and set trace levels by calling the different XXX_SetTraceLevel().
518 #if ( BT_USE_TRACES==TRUE )
519 if (trace_conf_enabled == TRUE)
521 tBTTRC_FUNC_MAP *p_f_map = (tBTTRC_FUNC_MAP *) &bttrc_set_level_map[0];
523 while (p_f_map->trc_name != NULL)
525 ALOGI("BTE_InitTraceLevels -- %s", p_f_map->trc_name);
528 p_f_map->p_f(p_f_map->trace_level);
535 ALOGI("[bttrc] using compile default trace settings");