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"
21 #include "stack_config.h"
25 #include "osi/include/future.h"
26 #include "osi/include/log.h"
28 const char *BTSNOOP_LOG_PATH_KEY = "BtSnoopFileName";
29 const char *BTSNOOP_TURNED_ON_KEY = "BtSnoopLogOutput";
30 const char *BTSNOOP_SHOULD_SAVE_LAST_KEY = "BtSnoopSaveLog";
31 const char *TRACE_CONFIG_ENABLED_KEY = "TraceConf";
33 static config_t *config;
35 // Module lifecycle functions
37 static future_t *init() {
38 // TODO(armansito): Find a better way than searching by a hardcoded path.
39 #if defined(OS_GENERIC)
40 const char *path = "bt_stack.conf";
41 #else // !defined(OS_GENERIC)
42 const char *path = "/etc/bluetooth/bt_stack.conf";
43 #endif // defined(OS_GENERIC)
46 LOG_INFO(LOG_TAG, "%s attempt to load stack conf from %s", __func__, path);
48 config = config_new(path);
50 LOG_INFO(LOG_TAG, "%s file >%s< not found", __func__, path);
51 return future_new_immediate(FUTURE_FAIL);
54 return future_new_immediate(FUTURE_SUCCESS);
57 static future_t *clean_up() {
59 return future_new_immediate(FUTURE_SUCCESS);
62 EXPORT_SYMBOL const module_t stack_config_module = {
63 .name = STACK_CONFIG_MODULE,
73 // Interface functions
75 static const char *get_btsnoop_log_path(void) {
76 return config_get_string(config, CONFIG_DEFAULT_SECTION, BTSNOOP_LOG_PATH_KEY, "/data/misc/bluedroid/btsnoop_hci.log");
79 static bool get_btsnoop_turned_on(void) {
80 return config_get_bool(config, CONFIG_DEFAULT_SECTION, BTSNOOP_TURNED_ON_KEY, false);
83 static bool get_btsnoop_should_save_last(void) {
84 return config_get_bool(config, CONFIG_DEFAULT_SECTION, BTSNOOP_SHOULD_SAVE_LAST_KEY, false);
87 static bool get_trace_config_enabled(void) {
88 return config_get_bool(config, CONFIG_DEFAULT_SECTION, TRACE_CONFIG_ENABLED_KEY, false);
91 static config_t *get_all(void) {
95 const stack_config_t interface = {
97 get_btsnoop_turned_on,
98 get_btsnoop_should_save_last,
99 get_trace_config_enabled,
103 const stack_config_t *stack_config_get_interface() {