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 #define RPC_INCLUDED TRUE
109 #include <sys/time.h>
112 #if (defined(ANDROID_USE_LOGCAT) && (ANDROID_USE_LOGCAT==TRUE))
113 const char * const bt_layer_tags[] = {
166 #include <cutils/log.h>
167 #define LOGI0(t,s) __android_log_write(ANDROID_LOG_INFO, t, s)
168 #define LOGD0(t,s) __android_log_write(ANDROID_LOG_DEBUG, t, s)
169 #define LOGW0(t,s) __android_log_write(ANDROID_LOG_WARN, t, s)
170 #define LOGE0(t,s) __android_log_write(ANDROID_LOG_ERROR, t, s)
173 #undef ANDROID_USE_LOGCAT
179 //#include "btl_cfg.h"
180 #define BTL_GLOBAL_PROP_TRC_FLAG "TRC_BTAPP"
181 #ifndef DEFAULT_CONF_TRACE_LEVEL
182 #define DEFAULT_CONF_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
185 #ifndef BTE_LOG_BUF_SIZE
186 #define BTE_LOG_BUF_SIZE 1024
188 #define BTE_LOG_MAX_SIZE (BTE_LOG_BUF_SIZE - 12)
191 //#define BTE_MAP_TRACE_LEVEL FALSE
192 /* map by default BTE trace levels onto android trace levels */
193 #ifndef BTE_MAP_TRACE_LEVEL
194 #define BTE_MAP_TRACE_LEVEL TRUE
197 // #define BTE_ANDROID_INTERNAL_TIMESTAMP TRUE
198 /* by default no internal timestamp. adb logcate -v time allows having timestamps */
199 #ifndef BTE_ANDROID_INTERNAL_TIMESTAMP
200 #define BTE_ANDROID_INTERNAL_TIMESTAMP FALSE
202 #if (BTE_ANDROID_INTERNAL_TIMESTAMP==TRUE)
203 #define MSG_BUFFER_OFFSET strlen(buffer)
205 #define MSG_BUFFER_OFFSET 0
210 #if defined( DBG_TRACE )
211 #define DBG_TRACE_API0( m ) BT_TRACE( TRACE_LAYER_HCI, TRACE_TYPE_API, m )
212 #define DBG_TRACE_WARNING2( m, p0, p1 ) BT_TRACE( TRACE_LAYER_BTM, (TRACE_ORG_APPL|TRACE_TYPE_WARNING), m, p0, p1 )
214 #define DBG_TRACE_API0( m )
215 #define DBG_TRACE_WARNING2( m, p0, p1 )
217 #define DBG_TRACE_DEBUG2( m, p0, p1 ) BT_TRACE( TRACE_LAYER_BTM, (TRACE_ORG_APPL|TRACE_TYPE_DEBUG), m, p0, p1 )
220 LogMsg(UINT32 trace_set_mask, const char *fmt_str, ...)
222 static char buffer[BTE_LOG_BUF_SIZE];
223 int trace_layer = TRACE_GET_LAYER(trace_set_mask);
224 if (trace_layer >= TRACE_LAYER_MAX_NUM)
228 #if (BTE_ANDROID_INTERNAL_TIMESTAMP==TRUE)
234 gettimeofday(&tv, &tz);
238 sprintf(buffer, "%02d:%02d:%02d.%03d ", tm->tm_hour, tm->tm_min, tm->tm_sec,
241 va_start(ap, fmt_str);
242 vsnprintf(&buffer[MSG_BUFFER_OFFSET], BTE_LOG_MAX_SIZE, fmt_str, ap);
245 #if (defined(ANDROID_USE_LOGCAT) && (ANDROID_USE_LOGCAT==TRUE))
246 #if (BTE_MAP_TRACE_LEVEL==TRUE)
247 switch ( TRACE_GET_TYPE(trace_set_mask) )
249 case TRACE_TYPE_ERROR:
250 LOGE0(bt_layer_tags[trace_layer], buffer);
252 case TRACE_TYPE_WARNING:
253 LOGW0(bt_layer_tags[trace_layer], buffer);
256 case TRACE_TYPE_EVENT:
257 LOGI0(bt_layer_tags[trace_layer], buffer);
259 case TRACE_TYPE_DEBUG:
260 LOGD0(bt_layer_tags[trace_layer], buffer);
263 LOGE0(bt_layer_tags[trace_layer], buffer); /* we should never get this */
267 LOGI0(bt_layer_tags[trace_layer], buffer);
270 write(2, buffer, strlen(buffer));
276 ScrLog(UINT32 trace_set_mask, const char *fmt_str, ...)
278 static char buffer[BTE_LOG_BUF_SIZE];
285 int trace_layer = TRACE_GET_LAYER(trace_set_mask);
286 if (trace_layer >= TRACE_LAYER_MAX_NUM)
288 gettimeofday(&tv, &tz);
292 sprintf(buffer, "%02d:%02d:%02d.%03ld ", tm->tm_hour, tm->tm_min, tm->tm_sec,
295 va_start(ap, fmt_str);
296 vsnprintf(&buffer[strlen(buffer)], BTE_LOG_MAX_SIZE, fmt_str, ap);
299 #if (defined(ANDROID_USE_LOGCAT) && (ANDROID_USE_LOGCAT==TRUE))
300 LOGI0(bt_layer_tags[trace_layer], buffer);
302 write(2, buffer, strlen(buffer));
307 /* this function should go into BTAPP_DM for example */
308 BT_API UINT8 BTAPP_SetTraceLevel( UINT8 new_level )
310 if (new_level != 0xFF)
311 appl_trace_level = new_level;
313 return (appl_trace_level);
316 BT_API UINT8 BTIF_SetTraceLevel( UINT8 new_level )
318 if (new_level != 0xFF)
319 btif_trace_level = new_level;
321 return (btif_trace_level);
324 BTU_API UINT8 BTU_SetTraceLevel( UINT8 new_level )
326 if (new_level != 0xFF)
327 btu_cb.trace_level = new_level;
329 return (btu_cb.trace_level);
332 BOOLEAN trace_conf_enabled = FALSE;
334 void bte_trace_conf(const char *p_conf_name, const char *p_conf_value)
336 tBTTRC_FUNC_MAP *p_f_map = (tBTTRC_FUNC_MAP *) &bttrc_set_level_map[0];
338 while (p_f_map->trc_name != NULL)
340 if (strcmp(p_f_map->trc_name, (const char *)p_conf_name) == 0)
342 p_f_map->trace_level = (UINT8) atoi(p_conf_value);
349 void bte_trace_conf_config(const config_t *config) {
350 assert(config != NULL);
352 for (tBTTRC_FUNC_MAP *functions = &bttrc_set_level_map[0]; functions->trc_name; ++functions) {
353 int value = config_get_int(config, CONFIG_DEFAULT_SECTION, functions->trc_name, -1);
355 functions->trace_level = value;
359 /********************************************************************************
361 ** Function Name: BTA_SysSetTraceLevel
363 ** Purpose: set or reads the different Trace Levels of layer IDs (see bt_trace.h,
366 ** Input Parameters: Array with trace layers to set to a given level or read. a layer ID of 0
367 ** defines the end of the list
368 ** WARNING: currently type should be 0-5! or FF for reading!!!!
371 ** input array with trace levels for given layer id
373 *********************************************************************************/
374 BT_API tBTTRC_LEVEL * BTA_SysSetTraceLevel(tBTTRC_LEVEL * p_levels)
376 const tBTTRC_FUNC_MAP *p_f_map;
377 tBTTRC_LEVEL *p_l = p_levels;
379 DBG_TRACE_API0( "BTA_SysSetTraceLevel()" );
381 while (0 != p_l->layer_id)
383 p_f_map = &bttrc_set_level_map[0];
385 while (0 != p_f_map->layer_id_start)
387 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 );
388 /* as p_f_map is ordered by increasing layer id, go to next map entry as long end id
390 //if (p_f_map->layer_id_end < p_l->layer_id)
396 /* check if layer_id actually false into a range or if it is note existing in the map */
397 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) )
399 DBG_TRACE_DEBUG2( "BTA_SysSetTraceLevel( id:%d, level:%d ): setting/reading",
400 p_l->layer_id, p_l->type );
401 p_l->type = p_f_map->p_f(p_l->type);
406 DBG_TRACE_WARNING2( "BTA_SysSetTraceLevel( id:%d, level:%d ): MISSING Set function OR ID in map!",
407 p_l->layer_id, p_l->type );
409 /* set/read next trace level by getting out ot map loop */
415 //if (0 == p_f_map->layer_id_start)
417 DBG_TRACE_WARNING2( "BTA_SysSetTraceLevel( id:%d, level:%d ): ID NOT FOUND in map. Skip to next",
418 p_l->layer_id, p_l->type );
424 } /* BTA_SysSetTraceLevel() */
426 /* make sure list is order by increasing layer id!!! */
427 tBTTRC_FUNC_MAP bttrc_set_level_map[] = {
428 {BTTRC_ID_STK_BTU, BTTRC_ID_STK_HCI, BTU_SetTraceLevel, "TRC_HCI", DEFAULT_CONF_TRACE_LEVEL},
429 {BTTRC_ID_STK_L2CAP, BTTRC_ID_STK_L2CAP, L2CA_SetTraceLevel, "TRC_L2CAP", DEFAULT_CONF_TRACE_LEVEL},
430 #if (RFCOMM_INCLUDED==TRUE)
431 {BTTRC_ID_STK_RFCOMM, BTTRC_ID_STK_RFCOMM_DATA, PORT_SetTraceLevel, "TRC_RFCOMM", DEFAULT_CONF_TRACE_LEVEL},
433 #if (OBX_INCLUDED==TRUE)
434 {BTTRC_ID_STK_OBEX, BTTRC_ID_STK_OBEX, OBX_SetTraceLevel, "TRC_OBEX", DEFAULT_CONF_TRACE_LEVEL},
436 #if (AVCT_INCLUDED==TRUE)
437 //{BTTRC_ID_STK_AVCT, BTTRC_ID_STK_AVCT, NULL, "TRC_AVCT", DEFAULT_CONF_TRACE_LEVEL},
439 #if (AVDT_INCLUDED==TRUE)
440 {BTTRC_ID_STK_AVDT, BTTRC_ID_STK_AVDT, AVDT_SetTraceLevel, "TRC_AVDT", DEFAULT_CONF_TRACE_LEVEL},
442 #if (AVRC_INCLUDED==TRUE)
443 {BTTRC_ID_STK_AVRC, BTTRC_ID_STK_AVRC, AVRC_SetTraceLevel, "TRC_AVRC", DEFAULT_CONF_TRACE_LEVEL},
445 #if (AVDT_INCLUDED==TRUE)
446 //{BTTRC_ID_AVDT_SCB, BTTRC_ID_AVDT_CCB, NULL, "TRC_AVDT_SCB", DEFAULT_CONF_TRACE_LEVEL},
448 #if (A2D_INCLUDED==TRUE)
449 {BTTRC_ID_STK_A2D, BTTRC_ID_STK_A2D, A2D_SetTraceLevel, "TRC_A2D", DEFAULT_CONF_TRACE_LEVEL},
451 #if (BIP_INCLUDED==TRUE)
452 {BTTRC_ID_STK_BIP, BTTRC_ID_STK_BIP, BIP_SetTraceLevel, "TRC_BIP", DEFAULT_CONF_TRACE_LEVEL},
454 #if (BNEP_INCLUDED==TRUE)
455 {BTTRC_ID_STK_BNEP, BTTRC_ID_STK_BNEP, BNEP_SetTraceLevel, "TRC_BNEP", DEFAULT_CONF_TRACE_LEVEL},
457 #if (BPP_INCLUDED==TRUE)
458 {BTTRC_ID_STK_BPP, BTTRC_ID_STK_BPP, BPP_SetTraceLevel, "TRC_BPP", DEFAULT_CONF_TRACE_LEVEL},
460 {BTTRC_ID_STK_BTM_ACL, BTTRC_ID_STK_BTM_SEC, BTM_SetTraceLevel, "TRC_BTM", DEFAULT_CONF_TRACE_LEVEL},
461 #if (DUN_INCLUDED==TRUE)
462 {BTTRC_ID_STK_DUN, BTTRC_ID_STK_DUN, DUN_SetTraceLevel, "TRC_DUN", DEFAULT_CONF_TRACE_LEVEL},
464 #if (GAP_INCLUDED==TRUE)
465 {BTTRC_ID_STK_GAP, BTTRC_ID_STK_GAP, GAP_SetTraceLevel, "TRC_GAP", DEFAULT_CONF_TRACE_LEVEL},
467 #if (GOEP_INCLUDED==TRUE)
468 {BTTRC_ID_STK_GOEP, BTTRC_ID_STK_GOEP, GOEP_SetTraceLevel, "TRC_GOEP", DEFAULT_CONF_TRACE_LEVEL},
470 #if (HCRP_INCLUDED==TRUE)
471 {BTTRC_ID_STK_HCRP, BTTRC_ID_STK_HCRP, HCRP_SetTraceLevel, "TRC_HCRP", DEFAULT_CONF_TRACE_LEVEL},
473 #if (PAN_INCLUDED==TRUE)
474 {BTTRC_ID_STK_PAN, BTTRC_ID_STK_PAN, PAN_SetTraceLevel, "TRC_PAN", DEFAULT_CONF_TRACE_LEVEL},
476 #if (SAP_SERVER_INCLUDED==TRUE)
477 {BTTRC_ID_STK_SAP, BTTRC_ID_STK_SAP, NULL, "TRC_SAP", DEFAULT_CONF_TRACE_LEVEL},
479 {BTTRC_ID_STK_SDP, BTTRC_ID_STK_SDP, SDP_SetTraceLevel, "TRC_SDP", DEFAULT_CONF_TRACE_LEVEL},
480 #if (BLE_INCLUDED==TRUE)
481 {BTTRC_ID_STK_GATT, BTTRC_ID_STK_GATT, GATT_SetTraceLevel, "TRC_GATT", DEFAULT_CONF_TRACE_LEVEL},
482 {BTTRC_ID_STK_SMP, BTTRC_ID_STK_SMP, SMP_SetTraceLevel, "TRC_SMP", DEFAULT_CONF_TRACE_LEVEL},
485 #if (BTA_INCLUDED==TRUE)
486 /* LayerIDs for BTA, currently everything maps onto appl_trace_level.
487 * BTL_GLOBAL_PROP_TRC_FLAG serves as flag in conf.
489 {BTTRC_ID_BTA_ACC, BTTRC_ID_BTAPP, BTAPP_SetTraceLevel, BTL_GLOBAL_PROP_TRC_FLAG, DEFAULT_CONF_TRACE_LEVEL},
492 #if (BT_TRACE_BTIF == TRUE)
493 {BTTRC_ID_BTA_ACC, BTTRC_ID_BTAPP, BTIF_SetTraceLevel, "TRC_BTIF", DEFAULT_CONF_TRACE_LEVEL},
496 {0, 0, NULL, NULL, DEFAULT_CONF_TRACE_LEVEL}
499 const UINT16 bttrc_map_size = sizeof(bttrc_set_level_map)/sizeof(tBTTRC_FUNC_MAP);
502 /********************************************************************************
504 ** Function Name: BTE_InitTraceLevels
506 ** Purpose: This function can be used to set the boot time reading it from the
508 ** WARNING: it is called under BTU context and it blocks the BTU task
509 ** till it returns (sync call)
511 ** Input Parameters: None, platform to provide levels
513 ** Newly set levels, if any!
515 *********************************************************************************/
516 BT_API void BTE_InitTraceLevels( void )
518 /* read and set trace levels by calling the different XXX_SetTraceLevel().
520 #if ( BT_USE_TRACES==TRUE )
521 if (trace_conf_enabled == TRUE)
523 tBTTRC_FUNC_MAP *p_f_map = (tBTTRC_FUNC_MAP *) &bttrc_set_level_map[0];
525 while (p_f_map->trc_name != NULL)
527 ALOGI("BTE_InitTraceLevels -- %s", p_f_map->trc_name);
530 p_f_map->p_f(p_f_map->trace_level);
537 ALOGI("[bttrc] using compile default trace settings");