1 /******************************************************************************
2 *
3 * Copyright 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 <base/logging.h>
24
25 #include "osi/include/future.h"
26 #include "osi/include/log.h"
27
28 namespace {
29 const char* TRACE_CONFIG_ENABLED_KEY = "TraceConf";
30 const char* PTS_AVRCP_TEST = "PTS_AvrcpTest";
31 const char* PTS_SECURE_ONLY_MODE = "PTS_SecurePairOnly";
32 const char* PTS_LE_CONN_UPDATED_DISABLED = "PTS_DisableConnUpdates";
33 const char* PTS_DISABLE_SDP_LE_PAIR = "PTS_DisableSDPOnLEPair";
34 const char* PTS_SMP_PAIRING_OPTIONS_KEY = "PTS_SmpOptions";
35 const char* PTS_SMP_FAILURE_CASE_KEY = "PTS_SmpFailureCase";
36
37 static std::unique_ptr<config_t> config;
38 } // namespace
39
40 // Module lifecycle functions
41
init()42 static future_t* init() {
43 // TODO(armansito): Find a better way than searching by a hardcoded path.
44 #if defined(OS_GENERIC) && !defined(TARGET_FLOSS)
45 const char* path = "bt_stack.conf";
46 #else // !defined(OS_GENERIC)
47 const char* path = "/etc/bluetooth/bt_stack.conf";
48 #endif // defined(OS_GENERIC)
49 CHECK(path != NULL);
50
51 LOG_INFO("%s attempt to load stack conf from %s", __func__, path);
52
53 config = config_new(path);
54 if (!config) {
55 LOG_INFO("%s file >%s< not found", __func__, path);
56 config = config_new_empty();
57 }
58
59 return future_new_immediate(FUTURE_SUCCESS);
60 }
61
clean_up()62 static future_t* clean_up() {
63 config.reset();
64 return future_new_immediate(FUTURE_SUCCESS);
65 }
66
67 EXPORT_SYMBOL extern const module_t stack_config_module = {
68 .name = STACK_CONFIG_MODULE,
69 .init = init,
70 .start_up = NULL,
71 .shut_down = NULL,
72 .clean_up = clean_up,
73 .dependencies = {NULL}};
74
75 // Interface functions
get_trace_config_enabled(void)76 static bool get_trace_config_enabled(void) {
77 return config_get_bool(*config, CONFIG_DEFAULT_SECTION,
78 TRACE_CONFIG_ENABLED_KEY, false);
79 }
80
get_pts_avrcp_test(void)81 static bool get_pts_avrcp_test(void) {
82 return config_get_bool(*config, CONFIG_DEFAULT_SECTION, PTS_AVRCP_TEST,
83 false);
84 }
85
get_pts_secure_only_mode(void)86 static bool get_pts_secure_only_mode(void) {
87 return config_get_bool(*config, CONFIG_DEFAULT_SECTION, PTS_SECURE_ONLY_MODE,
88 false);
89 }
90
get_pts_conn_updates_disabled(void)91 static bool get_pts_conn_updates_disabled(void) {
92 return config_get_bool(*config, CONFIG_DEFAULT_SECTION,
93 PTS_LE_CONN_UPDATED_DISABLED, false);
94 }
95
get_pts_crosskey_sdp_disable(void)96 static bool get_pts_crosskey_sdp_disable(void) {
97 return config_get_bool(*config, CONFIG_DEFAULT_SECTION,
98 PTS_DISABLE_SDP_LE_PAIR, false);
99 }
100
get_pts_smp_options(void)101 static const std::string* get_pts_smp_options(void) {
102 return config_get_string(*config, CONFIG_DEFAULT_SECTION,
103 PTS_SMP_PAIRING_OPTIONS_KEY, NULL);
104 }
105
get_pts_smp_failure_case(void)106 static int get_pts_smp_failure_case(void) {
107 return config_get_int(*config, CONFIG_DEFAULT_SECTION,
108 PTS_SMP_FAILURE_CASE_KEY, 0);
109 }
110
get_all(void)111 static config_t* get_all(void) { return config.get(); }
112
113 const stack_config_t interface = {
114 get_trace_config_enabled, get_pts_avrcp_test,
115 get_pts_secure_only_mode, get_pts_conn_updates_disabled,
116 get_pts_crosskey_sdp_disable, get_pts_smp_options,
117 get_pts_smp_failure_case, get_all};
118
stack_config_get_interface(void)119 const stack_config_t* stack_config_get_interface(void) { return &interface; }
120