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 #define LOG_TAG "bt_bte"
35 #include "bt_common.h"
37 #include "osi/include/config.h"
38 #include "osi/include/log.h"
39 #include "osi/include/log.h"
42 #include "stack_config.h"
44 #if (AVDT_INCLUDED==TRUE)
47 #if (A2D_INCLUDED==TRUE)
50 #if (BNEP_INCLUDED==TRUE)
53 #if (PAN_INCLUDED==TRUE)
56 #if (BLE_INCLUDED==TRUE)
61 #ifndef DEFAULT_CONF_TRACE_LEVEL
62 #define DEFAULT_CONF_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
65 #ifndef BTE_LOG_BUF_SIZE
66 #define BTE_LOG_BUF_SIZE 1024
69 #define BTE_LOG_MAX_SIZE (BTE_LOG_BUF_SIZE - 12)
71 #define MSG_BUFFER_OFFSET 0
73 /* LayerIDs for BTA, currently everything maps onto appl_trace_level */
74 static const char * const bt_layer_tags[] = {
101 "bt_gki", /* OBSOLETED */
125 static uint8_t BTAPP_SetTraceLevel(uint8_t new_level);
126 static uint8_t BTIF_SetTraceLevel(uint8_t new_level);
127 static uint8_t BTU_SetTraceLevel(uint8_t new_level);
129 /* make sure list is order by increasing layer id!!! */
130 static tBTTRC_FUNC_MAP bttrc_set_level_map[] = {
131 {BTTRC_ID_STK_BTU, BTTRC_ID_STK_HCI, BTU_SetTraceLevel, "TRC_HCI", DEFAULT_CONF_TRACE_LEVEL},
132 {BTTRC_ID_STK_L2CAP, BTTRC_ID_STK_L2CAP, L2CA_SetTraceLevel, "TRC_L2CAP", DEFAULT_CONF_TRACE_LEVEL},
133 {BTTRC_ID_STK_RFCOMM, BTTRC_ID_STK_RFCOMM_DATA, PORT_SetTraceLevel, "TRC_RFCOMM", DEFAULT_CONF_TRACE_LEVEL},
134 #if (AVDT_INCLUDED==TRUE)
135 {BTTRC_ID_STK_AVDT, BTTRC_ID_STK_AVDT, AVDT_SetTraceLevel, "TRC_AVDT", DEFAULT_CONF_TRACE_LEVEL},
137 {BTTRC_ID_STK_AVRC, BTTRC_ID_STK_AVRC, AVRC_SetTraceLevel, "TRC_AVRC", DEFAULT_CONF_TRACE_LEVEL},
138 #if (AVDT_INCLUDED==TRUE)
139 //{BTTRC_ID_AVDT_SCB, BTTRC_ID_AVDT_CCB, NULL, "TRC_AVDT_SCB", DEFAULT_CONF_TRACE_LEVEL},
141 #if (A2D_INCLUDED==TRUE)
142 {BTTRC_ID_STK_A2D, BTTRC_ID_STK_A2D, A2D_SetTraceLevel, "TRC_A2D", DEFAULT_CONF_TRACE_LEVEL},
144 #if (BNEP_INCLUDED==TRUE)
145 {BTTRC_ID_STK_BNEP, BTTRC_ID_STK_BNEP, BNEP_SetTraceLevel, "TRC_BNEP", DEFAULT_CONF_TRACE_LEVEL},
147 {BTTRC_ID_STK_BTM_ACL, BTTRC_ID_STK_BTM_SEC, BTM_SetTraceLevel, "TRC_BTM", DEFAULT_CONF_TRACE_LEVEL},
148 {BTTRC_ID_STK_GAP, BTTRC_ID_STK_GAP, GAP_SetTraceLevel, "TRC_GAP", DEFAULT_CONF_TRACE_LEVEL},
149 #if (PAN_INCLUDED==TRUE)
150 {BTTRC_ID_STK_PAN, BTTRC_ID_STK_PAN, PAN_SetTraceLevel, "TRC_PAN", DEFAULT_CONF_TRACE_LEVEL},
152 {BTTRC_ID_STK_SDP, BTTRC_ID_STK_SDP, SDP_SetTraceLevel, "TRC_SDP", DEFAULT_CONF_TRACE_LEVEL},
153 #if (BLE_INCLUDED==TRUE)
154 {BTTRC_ID_STK_GATT, BTTRC_ID_STK_GATT, GATT_SetTraceLevel, "TRC_GATT", DEFAULT_CONF_TRACE_LEVEL},
155 {BTTRC_ID_STK_SMP, BTTRC_ID_STK_SMP, SMP_SetTraceLevel, "TRC_SMP", DEFAULT_CONF_TRACE_LEVEL},
158 /* LayerIDs for BTA, currently everything maps onto appl_trace_level.
160 {BTTRC_ID_BTA_ACC, BTTRC_ID_BTAPP, BTAPP_SetTraceLevel, "TRC_BTAPP", DEFAULT_CONF_TRACE_LEVEL},
161 {BTTRC_ID_BTA_ACC, BTTRC_ID_BTAPP, BTIF_SetTraceLevel, "TRC_BTIF", DEFAULT_CONF_TRACE_LEVEL},
163 {0, 0, NULL, NULL, DEFAULT_CONF_TRACE_LEVEL}
166 static const UINT16 bttrc_map_size = sizeof(bttrc_set_level_map)/sizeof(tBTTRC_FUNC_MAP);
168 void LogMsg(uint32_t trace_set_mask, const char *fmt_str, ...) {
169 static char buffer[BTE_LOG_BUF_SIZE];
170 int trace_layer = TRACE_GET_LAYER(trace_set_mask);
171 if (trace_layer >= TRACE_LAYER_MAX_NUM)
175 va_start(ap, fmt_str);
176 vsnprintf(&buffer[MSG_BUFFER_OFFSET], BTE_LOG_MAX_SIZE, fmt_str, ap);
179 switch ( TRACE_GET_TYPE(trace_set_mask) ) {
180 case TRACE_TYPE_ERROR:
181 LOG_ERROR(bt_layer_tags[trace_layer], "%s", buffer);
183 case TRACE_TYPE_WARNING:
184 LOG_WARN(bt_layer_tags[trace_layer], "%s", buffer);
187 case TRACE_TYPE_EVENT:
188 LOG_INFO(bt_layer_tags[trace_layer], "%s", buffer);
190 case TRACE_TYPE_DEBUG:
191 LOG_DEBUG(bt_layer_tags[trace_layer], "%s", buffer);
194 LOG_ERROR(bt_layer_tags[trace_layer], "%s", buffer); /* we should never get this */
199 /* this function should go into BTAPP_DM for example */
200 static uint8_t BTAPP_SetTraceLevel(uint8_t new_level) {
201 if (new_level != 0xFF)
202 appl_trace_level = new_level;
204 return appl_trace_level;
207 static uint8_t BTIF_SetTraceLevel(uint8_t new_level) {
208 if (new_level != 0xFF)
209 btif_trace_level = new_level;
211 return btif_trace_level;
214 static uint8_t BTU_SetTraceLevel(uint8_t new_level) {
215 if (new_level != 0xFF)
216 btu_cb.trace_level = new_level;
218 return btu_cb.trace_level;
221 static void load_levels_from_config(const config_t *config) {
222 assert(config != NULL);
224 for (tBTTRC_FUNC_MAP *functions = &bttrc_set_level_map[0]; functions->trc_name; ++functions) {
225 LOG_INFO(LOG_TAG, "BTE_InitTraceLevels -- %s", functions->trc_name);
226 int value = config_get_int(config, CONFIG_DEFAULT_SECTION, functions->trc_name, -1);
228 functions->trace_level = value;
231 functions->p_f(functions->trace_level);
235 static future_t *init(void) {
236 const stack_config_t *stack_config = stack_config_get_interface();
237 if (!stack_config->get_trace_config_enabled()) {
238 LOG_INFO(LOG_TAG, "using compile default trace settings");
242 load_levels_from_config(stack_config->get_all());
246 EXPORT_SYMBOL const module_t bte_logmsg_module = {
247 .name = BTE_LOGMSG_MODULE,