OSDN Git Service

Remove always false flag BTM_BYPASS_EVENT_FILTERING
[android-x86/system-bt.git] / main / bte_logmsg.c
1 /******************************************************************************
2  *
3  *  Copyright (C) 2001-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
19 #include <assert.h>
20 #include <cutils/log.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <stdarg.h>
25 #include <sys/time.h>
26 #include <time.h>
27
28 #include "bte.h"
29 #include "bta_api.h"
30 #include "bte_appl.h"
31 #include "btu.h"
32 #include "config.h"
33 #include "gki.h"
34 #include "l2c_api.h"
35 #include "stack_config.h"
36
37 #if (RFCOMM_INCLUDED==TRUE)
38 #include "port_api.h"
39 #endif
40 #if (AVCT_INCLUDED==TRUE)
41 #include "avct_api.h"
42 #endif
43 #if (AVDT_INCLUDED==TRUE)
44 #include "avdt_api.h"
45 #endif
46 #if (AVRC_INCLUDED==TRUE)
47 #include "avrc_api.h"
48 #endif
49 #if (AVDT_INCLUDED==TRUE)
50 #include "avdt_api.h"
51 #endif
52 #if (A2D_INCLUDED==TRUE)
53 #include "a2d_api.h"
54 #endif
55 #if (BNEP_INCLUDED==TRUE)
56 #include "bnep_api.h"
57 #endif
58 #include "btm_api.h"
59 #if (GAP_INCLUDED==TRUE)
60 #include "gap_api.h"
61 #endif
62 #if (PAN_INCLUDED==TRUE)
63 #include "pan_api.h"
64 #endif
65 #include "sdp_api.h"
66
67 #if (BLE_INCLUDED==TRUE)
68 #include "gatt_api.h"
69 #include "smp_api.h"
70 #endif
71
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)
76
77 #ifndef DEFAULT_CONF_TRACE_LEVEL
78 #define DEFAULT_CONF_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
79 #endif
80
81 #ifndef BTE_LOG_BUF_SIZE
82 #define BTE_LOG_BUF_SIZE  1024
83 #endif
84
85 #define BTE_LOG_MAX_SIZE  (BTE_LOG_BUF_SIZE - 12)
86
87 #define MSG_BUFFER_OFFSET 0
88
89 /* LayerIDs for BTA, currently everything maps onto appl_trace_level */
90 static const char * const bt_layer_tags[] = {
91   "bt-btif",
92   "bt-usb",
93   "bt-serial",
94   "bt-socket",
95   "bt-rs232",
96   "bt-lc",
97   "bt-lm",
98   "bt-hci",
99   "bt-l2cap",
100   "bt-rfcomm",
101   "bt-sdp",
102   "bt-tcs",
103   "bt-obex",
104   "bt-btm",
105   "bt-gap",
106   "UNUSED",
107   "UNUSED",
108   "bt-icp",
109   "bt-hsp2",
110   "bt-spp",
111   "bt-ctp",
112   "bt-bpp",
113   "bt-hcrp",
114   "bt-ftp",
115   "bt-opp",
116   "bt-btu",
117   "bt-gki",
118   "bt-bnep",
119   "bt-pan",
120   "bt-hfp",
121   "bt-hid",
122   "bt-bip",
123   "bt-avp",
124   "bt-a2d",
125   "bt-sap",
126   "bt-amp",
127   "bt-mca",
128   "bt-att",
129   "bt-smp",
130   "bt-nfc",
131   "bt-nci",
132   "bt-idep",
133   "bt-ndep",
134   "bt-llcp",
135   "bt-rw",
136   "bt-ce",
137   "bt-snep",
138   "bt-ndef",
139   "bt-nfa",
140 };
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);
144
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},
151 #endif
152 #if (AVCT_INCLUDED==TRUE)
153   //{BTTRC_ID_STK_AVCT, BTTRC_ID_STK_AVCT, NULL, "TRC_AVCT", DEFAULT_CONF_TRACE_LEVEL},
154 #endif
155 #if (AVDT_INCLUDED==TRUE)
156   {BTTRC_ID_STK_AVDT, BTTRC_ID_STK_AVDT, AVDT_SetTraceLevel, "TRC_AVDT", DEFAULT_CONF_TRACE_LEVEL},
157 #endif
158 #if (AVRC_INCLUDED==TRUE)
159   {BTTRC_ID_STK_AVRC, BTTRC_ID_STK_AVRC, AVRC_SetTraceLevel, "TRC_AVRC", DEFAULT_CONF_TRACE_LEVEL},
160 #endif
161 #if (AVDT_INCLUDED==TRUE)
162   //{BTTRC_ID_AVDT_SCB, BTTRC_ID_AVDT_CCB, NULL, "TRC_AVDT_SCB", DEFAULT_CONF_TRACE_LEVEL},
163 #endif
164 #if (A2D_INCLUDED==TRUE)
165   {BTTRC_ID_STK_A2D, BTTRC_ID_STK_A2D, A2D_SetTraceLevel, "TRC_A2D", DEFAULT_CONF_TRACE_LEVEL},
166 #endif
167 #if (BNEP_INCLUDED==TRUE)
168   {BTTRC_ID_STK_BNEP, BTTRC_ID_STK_BNEP, BNEP_SetTraceLevel, "TRC_BNEP", DEFAULT_CONF_TRACE_LEVEL},
169 #endif
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},
173 #endif
174 #if (PAN_INCLUDED==TRUE)
175   {BTTRC_ID_STK_PAN, BTTRC_ID_STK_PAN, PAN_SetTraceLevel, "TRC_PAN", DEFAULT_CONF_TRACE_LEVEL},
176 #endif
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},
181 #endif
182
183   /* LayerIDs for BTA, currently everything maps onto appl_trace_level.
184    */
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},
187
188   {0, 0, NULL, NULL, DEFAULT_CONF_TRACE_LEVEL}
189 };
190
191 static const UINT16 bttrc_map_size = sizeof(bttrc_set_level_map)/sizeof(tBTTRC_FUNC_MAP);
192
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)
197     trace_layer = 0;
198
199   va_list ap;
200   va_start(ap, fmt_str);
201   vsnprintf(&buffer[MSG_BUFFER_OFFSET], BTE_LOG_MAX_SIZE, fmt_str, ap);
202   va_end(ap);
203
204   switch ( TRACE_GET_TYPE(trace_set_mask) ) {
205     case TRACE_TYPE_ERROR:
206       LOGE0(bt_layer_tags[trace_layer], buffer);
207       break;
208     case TRACE_TYPE_WARNING:
209       LOGW0(bt_layer_tags[trace_layer], buffer);
210       break;
211     case TRACE_TYPE_API:
212     case TRACE_TYPE_EVENT:
213       LOGI0(bt_layer_tags[trace_layer], buffer);
214       break;
215     case TRACE_TYPE_DEBUG:
216       LOGD0(bt_layer_tags[trace_layer], buffer);
217       break;
218     default:
219       LOGE0(bt_layer_tags[trace_layer], buffer);      /* we should never get this */
220       break;
221   }
222 }
223
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;
228
229   return appl_trace_level;
230 }
231
232 static uint8_t BTIF_SetTraceLevel(uint8_t new_level) {
233   if (new_level != 0xFF)
234     btif_trace_level = new_level;
235
236   return btif_trace_level;
237 }
238
239 static uint8_t BTU_SetTraceLevel(uint8_t new_level) {
240   if (new_level != 0xFF)
241     btu_cb.trace_level = new_level;
242
243   return btu_cb.trace_level;
244 }
245
246 static void load_levels_from_config(const config_t *config) {
247   assert(config != NULL);
248
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);
252     if (value != -1)
253       functions->trace_level = value;
254
255     if (functions->p_f)
256       functions->p_f(functions->trace_level);
257   }
258 }
259
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");
264     return NULL;
265   }
266
267   load_levels_from_config(stack_config->get_all());
268   return NULL;
269 }
270
271 const module_t bte_logmsg_module = {
272   .name = BTE_LOGMSG_MODULE,
273   .init = init,
274   .start_up = NULL,
275   .shut_down = NULL,
276   .clean_up = NULL,
277   .dependencies = {
278     STACK_CONFIG_MODULE,
279     NULL
280   }
281 };