1 /******************************************************************************
3 * Copyright (C) 2014 Google, Inc.
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_stack_config"
23 #include "osi/include/future.h"
24 #include "stack_config.h"
25 #include "osi/include/log.h"
27 const char *BTSNOOP_LOG_PATH_KEY = "BtSnoopFileName";
28 const char *BTSNOOP_TURNED_ON_KEY = "BtSnoopLogOutput";
29 const char *BTSNOOP_SHOULD_SAVE_LAST_KEY = "BtSnoopSaveLog";
30 const char *TRACE_CONFIG_ENABLED_KEY = "TraceConf";
32 static config_t *config;
34 // Module lifecycle functions
36 static future_t *init() {
37 const char *path = "/etc/bluetooth/bt_stack.conf";
40 LOG_INFO("%s attempt to load stack conf from %s", __func__, path);
42 config = config_new(path);
44 LOG_INFO("%s file >%s< not found", __func__, path);
45 return future_new_immediate(FUTURE_FAIL);
48 return future_new_immediate(FUTURE_SUCCESS);
51 static future_t *clean_up() {
53 return future_new_immediate(FUTURE_SUCCESS);
56 const module_t stack_config_module = {
57 .name = STACK_CONFIG_MODULE,
67 // Interface functions
69 static const char *get_btsnoop_log_path(void) {
70 return config_get_string(config, CONFIG_DEFAULT_SECTION, BTSNOOP_LOG_PATH_KEY, "/data/misc/bluedroid/btsnoop_hci.log");
73 static bool get_btsnoop_turned_on(void) {
74 return config_get_bool(config, CONFIG_DEFAULT_SECTION, BTSNOOP_TURNED_ON_KEY, false);
77 static bool get_btsnoop_should_save_last(void) {
78 return config_get_bool(config, CONFIG_DEFAULT_SECTION, BTSNOOP_SHOULD_SAVE_LAST_KEY, false);
81 static bool get_trace_config_enabled(void) {
82 return config_get_bool(config, CONFIG_DEFAULT_SECTION, TRACE_CONFIG_ENABLED_KEY, false);
85 static config_t *get_all(void) {
89 const stack_config_t interface = {
91 get_btsnoop_turned_on,
92 get_btsnoop_should_save_last,
93 get_trace_config_enabled,
97 const stack_config_t *stack_config_get_interface() {