• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  *  Copyright 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 #define LOG_TAG "bt_bte"
20 
21 #include <cstdarg>
22 #include <cstdint>
23 
24 #include "internal_include/bt_trace.h"
25 #include "internal_include/stack_config.h"
26 #include "main/main_int.h"
27 #include "osi/include/log.h"
28 
29 #ifndef BTE_LOG_BUF_SIZE
30 #define BTE_LOG_BUF_SIZE 256
31 #endif
32 
33 #define BTE_LOG_MAX_SIZE (BTE_LOG_BUF_SIZE - 12)
34 
35 #define MSG_BUFFER_OFFSET 0
36 
37 /* LayerIDs for BTA, currently everything maps onto appl_trace_level */
38 static const char* const bt_layer_tags[] = {
39     "bt_btif",
40     "bt_usb",
41     "bt_serial",
42     "bt_socket",
43     "bt_rs232",
44     "bt_lc",
45     "bt_lm",
46     "bt_hci",
47     "bt_l2cap",
48     "bt_rfcomm",
49     "bt_sdp",
50     "bt_tcs",
51     "bt_obex",
52     "bt_btm",
53     "bt_gap",
54     "UNUSED",
55     "UNUSED",
56     "bt_icp",
57     "bt_hsp2",
58     "bt_spp",
59     "bt_ctp",
60     "bt_bpp",
61     "bt_hcrp",
62     "bt_ftp",
63     "bt_opp",
64     "bt_btu",
65     "bt_gki_deprecated",
66     "bt_bnep",
67     "bt_pan",
68     "bt_hfp",
69     "bt_hid",
70     "bt_bip",
71     "bt_avp",
72     "bt_a2d",
73     "bt_sap",
74     "bt_amp",
75     "bt_mca_deprecated",
76     "bt_att",
77     "bt_smp",
78     "bt_nfc",
79     "bt_nci",
80     "bt_idep",
81     "bt_ndep",
82     "bt_llcp",
83     "bt_rw",
84     "bt_ce",
85     "bt_snep",
86     "bt_ndef",
87     "bt_nfa",
88 };
89 
LogMsg(uint32_t trace_set_mask,const char * fmt_str,...)90 void LogMsg(uint32_t trace_set_mask, const char* fmt_str, ...) {
91   char buffer[BTE_LOG_BUF_SIZE];
92   int trace_layer = TRACE_GET_LAYER(trace_set_mask);
93   if (trace_layer >= TRACE_LAYER_MAX_NUM) trace_layer = 0;
94 
95   va_list ap;
96   va_start(ap, fmt_str);
97   vsnprintf(&buffer[MSG_BUFFER_OFFSET], BTE_LOG_MAX_SIZE, fmt_str, ap);
98   va_end(ap);
99 
100 #undef LOG_TAG
101 #define LOG_TAG bt_layer_tags[trace_layer]
102 
103   switch (TRACE_GET_TYPE(trace_set_mask)) {
104     case TRACE_TYPE_ERROR:
105       LOG_ERROR("%s", buffer);
106       break;
107     case TRACE_TYPE_WARNING:
108       LOG_WARN("%s", buffer);
109       break;
110     case TRACE_TYPE_API:
111     case TRACE_TYPE_EVENT:
112       LOG_INFO("%s", buffer);
113       break;
114     case TRACE_TYPE_DEBUG:
115       LOG_INFO("%s", buffer);
116       break;
117     case TRACE_TYPE_INFO:
118       LOG_INFO("%s", buffer);
119       break;
120     default:
121       /* we should never get this */
122       LOG_ERROR("!BAD TRACE TYPE! %s", buffer);
123       CHECK(TRACE_GET_TYPE(trace_set_mask) == TRACE_TYPE_ERROR);
124       break;
125   }
126 #undef LOG_TAG
127 #define LOG_TAG "bt_bte"
128 }
129 
init(void)130 static future_t* init(void) {
131   const stack_config_t* stack_config = stack_config_get_interface();
132   if (!stack_config->get_trace_config_enabled()) {
133     LOG_INFO("using compile default trace settings");
134     return NULL;
135   }
136 
137   init_cpp_logging(stack_config->get_all());
138 
139   return NULL;
140 }
141 
142 EXPORT_SYMBOL extern const module_t bte_logmsg_module = {
143     .name = BTE_LOGMSG_MODULE,
144     .init = init,
145     .start_up = NULL,
146     .shut_down = NULL,
147     .clean_up = NULL,
148     .dependencies = {STACK_CONFIG_MODULE, NULL}};
149