OSDN Git Service

Make default SBC bitrate configurable by device. am: 5f308397b7
[android-x86/system-bt.git] / main / stack_config.c
1 /******************************************************************************
2  *
3  *  Copyright (C) 2014 Google, Inc.
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_stack_config"
20
21 #include "stack_config.h"
22
23 #include <assert.h>
24
25 #include "osi/include/future.h"
26 #include "osi/include/log.h"
27
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";
32
33 static config_t *config;
34
35 // Module lifecycle functions
36
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)
44   assert(path != NULL);
45
46   LOG_INFO(LOG_TAG, "%s attempt to load stack conf from %s", __func__, path);
47
48   config = config_new(path);
49   if (!config) {
50     LOG_INFO(LOG_TAG, "%s file >%s< not found", __func__, path);
51     return future_new_immediate(FUTURE_FAIL);
52   }
53
54   return future_new_immediate(FUTURE_SUCCESS);
55 }
56
57 static future_t *clean_up() {
58   config_free(config);
59   return future_new_immediate(FUTURE_SUCCESS);
60 }
61
62 EXPORT_SYMBOL const module_t stack_config_module = {
63   .name = STACK_CONFIG_MODULE,
64   .init = init,
65   .start_up = NULL,
66   .shut_down = NULL,
67   .clean_up = clean_up,
68   .dependencies = {
69     NULL
70   }
71 };
72
73 // Interface functions
74
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");
77 }
78
79 static bool get_btsnoop_turned_on(void) {
80   return config_get_bool(config, CONFIG_DEFAULT_SECTION, BTSNOOP_TURNED_ON_KEY, false);
81 }
82
83 static bool get_btsnoop_should_save_last(void) {
84   return config_get_bool(config, CONFIG_DEFAULT_SECTION, BTSNOOP_SHOULD_SAVE_LAST_KEY, false);
85 }
86
87 static bool get_trace_config_enabled(void) {
88   return config_get_bool(config, CONFIG_DEFAULT_SECTION, TRACE_CONFIG_ENABLED_KEY, false);
89 }
90
91 static config_t *get_all(void) {
92   return config;
93 }
94
95 const stack_config_t interface = {
96   get_btsnoop_log_path,
97   get_btsnoop_turned_on,
98   get_btsnoop_should_save_last,
99   get_trace_config_enabled,
100   get_all
101 };
102
103 const stack_config_t *stack_config_get_interface() {
104   return &interface;
105 }