summaryrefslogtreecommitdiffstats
path: root/main
diff options
context:
space:
mode:
authorZach Johnson <zachoverflow@google.com>2014-09-22 22:11:55 -0700
committerAndre Eisenbach <eisenbach@google.com>2015-03-16 16:51:35 -0700
commit9891f32471b5c01cf58e4d7dadb04cb3024a9a88 (patch)
tree818d98eb1ca40f1240f63faf5cfdacce222e5e62 /main
parent72f308ee6d3983ae2c0d67be3de2451f2dd72dcb (diff)
downloadandroid_system_bt-9891f32471b5c01cf58e4d7dadb04cb3024a9a88.tar.gz
android_system_bt-9891f32471b5c01cf58e4d7dadb04cb3024a9a88.tar.bz2
android_system_bt-9891f32471b5c01cf58e4d7dadb04cb3024a9a88.zip
Refactor btsnoop and stack config into modules
Moves stack config out of the combined bte_config, and into its own module. Makes btsnoop more self sufficient and removes uneccessary levels of indirection. Refactor logging slightly into a (temporary) module to disassociate from the direct calls from config. Eliminates some useless stuff in the module as well.
Diffstat (limited to 'main')
-rw-r--r--main/Android.mk3
-rw-r--r--main/bte_conf.c29
-rw-r--r--main/bte_logmsg.c80
-rwxr-xr-xmain/bte_main.c42
-rw-r--r--main/stack_config.c93
5 files changed, 140 insertions, 107 deletions
diff --git a/main/Android.mk b/main/Android.mk
index b25d82884..da5365cac 100644
--- a/main/Android.mk
+++ b/main/Android.mk
@@ -15,7 +15,8 @@ LOCAL_SRC_FILES+= \
bte_main.c \
bte_init.c \
bte_logmsg.c \
- bte_conf.c
+ bte_conf.c \
+ stack_config.c
# BTIF
LOCAL_SRC_FILES += \
diff --git a/main/bte_conf.c b/main/bte_conf.c
index 63ace862a..38607f889 100644
--- a/main/bte_conf.c
+++ b/main/bte_conf.c
@@ -26,35 +26,6 @@
#include "bta_api.h"
#include "config.h"
-// TODO: eliminate these global variables.
-extern char hci_logfile[256];
-extern BOOLEAN hci_logging_enabled;
-extern BOOLEAN hci_save_log;
-extern BOOLEAN trace_conf_enabled;
-void bte_trace_conf_config(const config_t *config);
-
-// Reads the stack configuration file and populates global variables with
-// the contents of the file.
-void bte_load_conf(const char *path) {
- assert(path != NULL);
-
- ALOGI("%s attempt to load stack conf from %s", __func__, path);
-
- config_t *config = config_new(path);
- if (!config) {
- ALOGI("%s file >%s< not found", __func__, path);
- return;
- }
-
- strlcpy(hci_logfile, config_get_string(config, CONFIG_DEFAULT_SECTION, "BtSnoopFileName", ""), sizeof(hci_logfile));
- hci_logging_enabled = config_get_bool(config, CONFIG_DEFAULT_SECTION, "BtSnoopLogOutput", false);
- hci_save_log = config_get_bool(config, CONFIG_DEFAULT_SECTION, "BtSnoopSaveLog", false);
- trace_conf_enabled = config_get_bool(config, CONFIG_DEFAULT_SECTION, "TraceConf", false);
-
- bte_trace_conf_config(config);
- config_free(config);
-}
-
#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
extern int btm_ble_tx_power[BTM_BLE_ADV_TX_POWER_MAX + 1];
void bte_load_ble_conf(const char* path)
diff --git a/main/bte_logmsg.c b/main/bte_logmsg.c
index 416c5ca47..034ede746 100644
--- a/main/bte_logmsg.c
+++ b/main/bte_logmsg.c
@@ -32,6 +32,7 @@
#include "config.h"
#include "gki.h"
#include "l2c_api.h"
+#include "stack_config.h"
#if (RFCOMM_INCLUDED==TRUE)
#include "port_api.h"
@@ -103,8 +104,6 @@
#define MSG_BUFFER_OFFSET 0
-bool trace_conf_enabled = false;
-
/* LayerIDs for BTA, currently everything maps onto appl_trace_level */
static const char * const bt_layer_tags[] = {
"bt-btif",
@@ -231,16 +230,6 @@ static tBTTRC_FUNC_MAP bttrc_set_level_map[] = {
static const UINT16 bttrc_map_size = sizeof(bttrc_set_level_map)/sizeof(tBTTRC_FUNC_MAP);
-void bte_trace_conf_config(const config_t *config) {
- assert(config != NULL);
-
- for (tBTTRC_FUNC_MAP *functions = &bttrc_set_level_map[0]; functions->trc_name; ++functions) {
- int value = config_get_int(config, CONFIG_DEFAULT_SECTION, functions->trc_name, -1);
- if (value != -1)
- functions->trace_level = value;
- }
-}
-
void LogMsg(uint32_t trace_set_mask, const char *fmt_str, ...) {
static char buffer[BTE_LOG_BUF_SIZE];
int trace_layer = TRACE_GET_LAYER(trace_set_mask);
@@ -272,36 +261,6 @@ void LogMsg(uint32_t trace_set_mask, const char *fmt_str, ...) {
}
}
-/********************************************************************************
- **
- ** Function Name: BTE_InitTraceLevels
- **
- ** Purpose: This function can be used to set the boot time reading it from the
- ** platform.
- ** WARNING: it is called under BTU context and it blocks the BTU task
- ** till it returns (sync call)
- **
- ** Input Parameters: None, platform to provide levels
- ** Returns:
- ** Newly set levels, if any!
- **
- *********************************************************************************/
-void BTE_InitTraceLevels(void) {
- // Read and set trace levels by calling the different XXX_SetTraceLevel().
- if (trace_conf_enabled == false) {
- ALOGI("[bttrc] using compile default trace settings");
- return;
- }
-
- tBTTRC_FUNC_MAP *p_f_map = (tBTTRC_FUNC_MAP *)&bttrc_set_level_map[0];
- while (p_f_map->trc_name != NULL) {
- ALOGI("BTE_InitTraceLevels -- %s", p_f_map->trc_name);
- if (p_f_map->p_f)
- p_f_map->p_f(p_f_map->trace_level);
- p_f_map++;
- }
-}
-
/* this function should go into BTAPP_DM for example */
static uint8_t BTAPP_SetTraceLevel(uint8_t new_level) {
if (new_level != 0xFF)
@@ -323,3 +282,40 @@ static uint8_t BTU_SetTraceLevel(uint8_t new_level) {
return btu_cb.trace_level;
}
+
+static void load_levels_from_config(const config_t *config) {
+ assert(config != NULL);
+
+ for (tBTTRC_FUNC_MAP *functions = &bttrc_set_level_map[0]; functions->trc_name; ++functions) {
+ ALOGI("BTE_InitTraceLevels -- %s", functions->trc_name);
+ int value = config_get_int(config, CONFIG_DEFAULT_SECTION, functions->trc_name, -1);
+ if (value != -1)
+ functions->trace_level = value;
+
+ if (functions->p_f)
+ functions->p_f(functions->trace_level);
+ }
+}
+
+static future_t *init(void) {
+ const stack_config_t *stack_config = stack_config_get_interface();
+ if (!stack_config->get_trace_config_enabled()) {
+ ALOGI("[bttrc] using compile default trace settings");
+ return NULL;
+ }
+
+ load_levels_from_config(stack_config->get_all());
+ return NULL;
+}
+
+const module_t bte_logmsg_module = {
+ .name = BTE_LOGMSG_MODULE,
+ .init = init,
+ .start_up = NULL,
+ .shut_down = NULL,
+ .clean_up = NULL,
+ .dependencies = {
+ STACK_CONFIG_MODULE,
+ NULL
+ }
+};
diff --git a/main/bte_main.c b/main/bte_main.c
index e9edb9e75..0c5209a0c 100755
--- a/main/bte_main.c
+++ b/main/bte_main.c
@@ -48,40 +48,28 @@
#include "hash_functions.h"
#include "hash_map.h"
#include "hci_layer.h"
+#include "module.h"
#include "osi.h"
+#include "stack_config.h"
#include "thread.h"
/*******************************************************************************
** Constants & Macros
*******************************************************************************/
-/* Run-time configuration file */
-#ifndef BTE_STACK_CONF_FILE
-#define BTE_STACK_CONF_FILE "/etc/bluetooth/bt_stack.conf"
-#endif
/* Run-time configuration file for BLE*/
#ifndef BTE_BLE_STACK_CONF_FILE
#define BTE_BLE_STACK_CONF_FILE "/etc/bluetooth/ble_stack.conf"
#endif
-/* if not specified in .txt file then use this as default */
-#ifndef HCI_LOGGING_FILENAME
-#define HCI_LOGGING_FILENAME "/data/misc/bluedroid/btsnoop_hci.log"
-#endif
-
/******************************************************************************
** Variables
******************************************************************************/
-BOOLEAN hci_logging_enabled = FALSE; /* by default, turn hci log off */
-BOOLEAN hci_logging_config = FALSE; /* configured from bluetooth framework */
-BOOLEAN hci_save_log = FALSE; /* save a copy of the log before starting again */
-char hci_logfile[256] = HCI_LOGGING_FILENAME;
/*******************************************************************************
** Static variables
*******************************************************************************/
static const hci_t *hci;
-static const btsnoop_t *btsnoop;
static const hci_callbacks_t hci_callbacks;
// Lock to serialize shutdown requests from upper layer.
static pthread_mutex_t shutdown_lock;
@@ -120,8 +108,6 @@ void bte_main_boot_entry(void)
if (!hci)
ALOGE("%s could not get hci layer interface.", __func__);
- btsnoop = btsnoop_get_interface();
-
btu_hci_msg_queue = fixed_queue_new(SIZE_MAX);
if (btu_hci_msg_queue == NULL) {
ALOGE("%s unable to allocate hci message queue.", __func__);
@@ -130,10 +116,10 @@ void bte_main_boot_entry(void)
data_dispatcher_register_default(hci->upward_dispatcher, btu_hci_msg_queue);
- bte_load_conf(BTE_STACK_CONF_FILE);
#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
bte_load_ble_conf(BTE_BLE_STACK_CONF_FILE);
#endif
+ module_init(get_module(STACK_CONFIG_MODULE));
#if (BTTRC_INCLUDED == TRUE)
/* Initialize trace feature */
@@ -141,7 +127,6 @@ void bte_main_boot_entry(void)
#endif
pthread_mutex_init(&shutdown_lock, NULL);
- btsnoop->set_logging_path(hci_logfile);
}
/******************************************************************************
@@ -160,6 +145,8 @@ void bte_main_shutdown()
btu_hci_msg_queue = NULL;
+ module_clean_up(get_module(STACK_CONFIG_MODULE));
+
pthread_mutex_destroy(&shutdown_lock);
GKI_shutdown();
}
@@ -180,8 +167,8 @@ void bte_main_enable()
// BTU_StartUp();
- btsnoop->set_is_running(hci_logging_enabled || hci_logging_config);
assert(hci->start_up_async(btif_local_bd_addr.address, &hci_callbacks));
+ module_start_up(get_module(BTSNOOP_MODULE));
}
/******************************************************************************
@@ -198,11 +185,11 @@ void bte_main_disable(void)
{
APPL_TRACE_DEBUG("%s", __FUNCTION__);
+ module_shut_down(get_module(BTSNOOP_MODULE));
if (hci) {
// Shutdown is not thread safe and must be protected.
pthread_mutex_lock(&shutdown_lock);
- btsnoop->set_is_running(false);
hci->shut_down();
pthread_mutex_unlock(&shutdown_lock);
@@ -213,21 +200,6 @@ void bte_main_disable(void)
/******************************************************************************
**
-** Function bte_main_config_hci_logging
-**
-** Description enable or disable HIC snoop logging
-**
-** Returns None
-**
-******************************************************************************/
-void bte_main_config_hci_logging(BOOLEAN enable, BOOLEAN bt_disabled)
-{
- hci_logging_config = enable;
- btsnoop->set_is_running((hci_logging_config || hci_logging_enabled) && !bt_disabled);
-}
-
-/******************************************************************************
-**
** Function bte_main_postload_cfg
**
** Description BTE MAIN API - Stack postload configuration
diff --git a/main/stack_config.c b/main/stack_config.c
new file mode 100644
index 000000000..a568c23e2
--- /dev/null
+++ b/main/stack_config.c
@@ -0,0 +1,93 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2014 Google, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************/
+
+#define LOG_TAG "bt_stack_config"
+
+#include <assert.h>
+#include <utils/Log.h>
+
+#include "future.h"
+#include "stack_config.h"
+
+const char *BTSNOOP_LOG_PATH_KEY = "BtSnoopFileName";
+const char *BTSNOOP_TURNED_ON_KEY = "BtSnoopLogOutput";
+const char *TRACE_CONFIG_ENABLED_KEY = "TraceConf";
+
+static config_t *config;
+
+// Module lifecycle functions
+
+static future_t *init() {
+ const char *path = "/etc/bluetooth/bt_stack.conf";
+ assert(path != NULL);
+
+ ALOGI("%s attempt to load stack conf from %s", __func__, path);
+
+ config = config_new(path);
+ if (!config) {
+ ALOGI("%s file >%s< not found", __func__, path);
+ return future_new_immediate(FUTURE_FAIL);
+ }
+
+ return future_new_immediate(FUTURE_SUCCESS);
+}
+
+static future_t *clean_up() {
+ config_free(config);
+ return future_new_immediate(FUTURE_SUCCESS);
+}
+
+const module_t stack_config_module = {
+ .name = STACK_CONFIG_MODULE,
+ .init = init,
+ .start_up = NULL,
+ .shut_down = NULL,
+ .clean_up = clean_up,
+ .dependencies = {
+ NULL
+ }
+};
+
+// Interface functions
+
+static const char *get_btsnoop_log_path(void) {
+ return config_get_string(config, CONFIG_DEFAULT_SECTION, BTSNOOP_LOG_PATH_KEY, "/data/misc/bluedroid/btsnoop_hci.log");
+}
+
+static bool get_btsnoop_turned_on(void) {
+ return config_get_bool(config, CONFIG_DEFAULT_SECTION, BTSNOOP_TURNED_ON_KEY, false);
+}
+
+static bool get_trace_config_enabled(void) {
+ return config_get_bool(config, CONFIG_DEFAULT_SECTION, TRACE_CONFIG_ENABLED_KEY, false);
+}
+
+static config_t *get_all(void) {
+ return config;
+}
+
+const stack_config_t interface = {
+ get_btsnoop_log_path,
+ get_btsnoop_turned_on,
+ get_trace_config_enabled,
+ get_all
+};
+
+const stack_config_t *stack_config_get_interface() {
+ return &interface;
+}