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 ******************************************************************************/
20 #include <cutils/log.h>
35 #include "stack_config.h"
37 #if (RFCOMM_INCLUDED==TRUE)
40 #if (AVCT_INCLUDED==TRUE)
43 #if (AVDT_INCLUDED==TRUE)
46 #if (AVRC_INCLUDED==TRUE)
49 #if (AVDT_INCLUDED==TRUE)
52 #if (A2D_INCLUDED==TRUE)
55 #if (BNEP_INCLUDED==TRUE)
59 #if (GAP_INCLUDED==TRUE)
62 #if (PAN_INCLUDED==TRUE)
67 #if (BLE_INCLUDED==TRUE)
72 #define LOGI0(t,s) __android_log_write(ANDROID_LOG_INFO, t, s)
73 #define LOGD0(t,s) __android_log_write(ANDROID_LOG_DEBUG, t, s)
74 #define LOGW0(t,s) __android_log_write(ANDROID_LOG_WARN, t, s)
75 #define LOGE0(t,s) __android_log_write(ANDROID_LOG_ERROR, t, s)
77 #ifndef DEFAULT_CONF_TRACE_LEVEL
78 #define DEFAULT_CONF_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
81 #ifndef BTE_LOG_BUF_SIZE
82 #define BTE_LOG_BUF_SIZE 1024
85 #define BTE_LOG_MAX_SIZE (BTE_LOG_BUF_SIZE - 12)
87 #define MSG_BUFFER_OFFSET 0
89 /* LayerIDs for BTA, currently everything maps onto appl_trace_level */
90 static const char * const bt_layer_tags[] = {
141 static uint8_t BTAPP_SetTraceLevel(uint8_t new_level);
142 static uint8_t BTIF_SetTraceLevel(uint8_t new_level);
143 static uint8_t BTU_SetTraceLevel(uint8_t new_level);
145 /* make sure list is order by increasing layer id!!! */
146 static tBTTRC_FUNC_MAP bttrc_set_level_map[] = {
147 {BTTRC_ID_STK_BTU, BTTRC_ID_STK_HCI, BTU_SetTraceLevel, "TRC_HCI", DEFAULT_CONF_TRACE_LEVEL},
148 {BTTRC_ID_STK_L2CAP, BTTRC_ID_STK_L2CAP, L2CA_SetTraceLevel, "TRC_L2CAP", DEFAULT_CONF_TRACE_LEVEL},
149 #if (RFCOMM_INCLUDED==TRUE)
150 {BTTRC_ID_STK_RFCOMM, BTTRC_ID_STK_RFCOMM_DATA, PORT_SetTraceLevel, "TRC_RFCOMM", DEFAULT_CONF_TRACE_LEVEL},
152 #if (AVCT_INCLUDED==TRUE)
153 //{BTTRC_ID_STK_AVCT, BTTRC_ID_STK_AVCT, NULL, "TRC_AVCT", DEFAULT_CONF_TRACE_LEVEL},
155 #if (AVDT_INCLUDED==TRUE)
156 {BTTRC_ID_STK_AVDT, BTTRC_ID_STK_AVDT, AVDT_SetTraceLevel, "TRC_AVDT", DEFAULT_CONF_TRACE_LEVEL},
158 #if (AVRC_INCLUDED==TRUE)
159 {BTTRC_ID_STK_AVRC, BTTRC_ID_STK_AVRC, AVRC_SetTraceLevel, "TRC_AVRC", DEFAULT_CONF_TRACE_LEVEL},
161 #if (AVDT_INCLUDED==TRUE)
162 //{BTTRC_ID_AVDT_SCB, BTTRC_ID_AVDT_CCB, NULL, "TRC_AVDT_SCB", DEFAULT_CONF_TRACE_LEVEL},
164 #if (A2D_INCLUDED==TRUE)
165 {BTTRC_ID_STK_A2D, BTTRC_ID_STK_A2D, A2D_SetTraceLevel, "TRC_A2D", DEFAULT_CONF_TRACE_LEVEL},
167 #if (BNEP_INCLUDED==TRUE)
168 {BTTRC_ID_STK_BNEP, BTTRC_ID_STK_BNEP, BNEP_SetTraceLevel, "TRC_BNEP", DEFAULT_CONF_TRACE_LEVEL},
170 {BTTRC_ID_STK_BTM_ACL, BTTRC_ID_STK_BTM_SEC, BTM_SetTraceLevel, "TRC_BTM", DEFAULT_CONF_TRACE_LEVEL},
171 #if (GAP_INCLUDED==TRUE)
172 {BTTRC_ID_STK_GAP, BTTRC_ID_STK_GAP, GAP_SetTraceLevel, "TRC_GAP", DEFAULT_CONF_TRACE_LEVEL},
174 #if (PAN_INCLUDED==TRUE)
175 {BTTRC_ID_STK_PAN, BTTRC_ID_STK_PAN, PAN_SetTraceLevel, "TRC_PAN", DEFAULT_CONF_TRACE_LEVEL},
177 {BTTRC_ID_STK_SDP, BTTRC_ID_STK_SDP, SDP_SetTraceLevel, "TRC_SDP", DEFAULT_CONF_TRACE_LEVEL},
178 #if (BLE_INCLUDED==TRUE)
179 {BTTRC_ID_STK_GATT, BTTRC_ID_STK_GATT, GATT_SetTraceLevel, "TRC_GATT", DEFAULT_CONF_TRACE_LEVEL},
180 {BTTRC_ID_STK_SMP, BTTRC_ID_STK_SMP, SMP_SetTraceLevel, "TRC_SMP", DEFAULT_CONF_TRACE_LEVEL},
183 /* LayerIDs for BTA, currently everything maps onto appl_trace_level.
185 {BTTRC_ID_BTA_ACC, BTTRC_ID_BTAPP, BTAPP_SetTraceLevel, "TRC_BTAPP", DEFAULT_CONF_TRACE_LEVEL},
186 {BTTRC_ID_BTA_ACC, BTTRC_ID_BTAPP, BTIF_SetTraceLevel, "TRC_BTIF", DEFAULT_CONF_TRACE_LEVEL},
188 {0, 0, NULL, NULL, DEFAULT_CONF_TRACE_LEVEL}
191 static const UINT16 bttrc_map_size = sizeof(bttrc_set_level_map)/sizeof(tBTTRC_FUNC_MAP);
193 void LogMsg(uint32_t trace_set_mask, const char *fmt_str, ...) {
194 static char buffer[BTE_LOG_BUF_SIZE];
195 int trace_layer = TRACE_GET_LAYER(trace_set_mask);
196 if (trace_layer >= TRACE_LAYER_MAX_NUM)
200 va_start(ap, fmt_str);
201 vsnprintf(&buffer[MSG_BUFFER_OFFSET], BTE_LOG_MAX_SIZE, fmt_str, ap);
204 switch ( TRACE_GET_TYPE(trace_set_mask) ) {
205 case TRACE_TYPE_ERROR:
206 LOGE0(bt_layer_tags[trace_layer], buffer);
208 case TRACE_TYPE_WARNING:
209 LOGW0(bt_layer_tags[trace_layer], buffer);
212 case TRACE_TYPE_EVENT:
213 LOGI0(bt_layer_tags[trace_layer], buffer);
215 case TRACE_TYPE_DEBUG:
216 LOGD0(bt_layer_tags[trace_layer], buffer);
219 LOGE0(bt_layer_tags[trace_layer], buffer); /* we should never get this */
224 /* this function should go into BTAPP_DM for example */
225 static uint8_t BTAPP_SetTraceLevel(uint8_t new_level) {
226 if (new_level != 0xFF)
227 appl_trace_level = new_level;
229 return appl_trace_level;
232 static uint8_t BTIF_SetTraceLevel(uint8_t new_level) {
233 if (new_level != 0xFF)
234 btif_trace_level = new_level;
236 return btif_trace_level;
239 static uint8_t BTU_SetTraceLevel(uint8_t new_level) {
240 if (new_level != 0xFF)
241 btu_cb.trace_level = new_level;
243 return btu_cb.trace_level;
246 static void load_levels_from_config(const config_t *config) {
247 assert(config != NULL);
249 for (tBTTRC_FUNC_MAP *functions = &bttrc_set_level_map[0]; functions->trc_name; ++functions) {
250 ALOGI("BTE_InitTraceLevels -- %s", functions->trc_name);
251 int value = config_get_int(config, CONFIG_DEFAULT_SECTION, functions->trc_name, -1);
253 functions->trace_level = value;
256 functions->p_f(functions->trace_level);
260 static future_t *init(void) {
261 const stack_config_t *stack_config = stack_config_get_interface();
262 if (!stack_config->get_trace_config_enabled()) {
263 ALOGI("[bttrc] using compile default trace settings");
267 load_levels_from_config(stack_config->get_all());
271 const module_t bte_logmsg_module = {
272 .name = BTE_LOGMSG_MODULE,