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";
32 const char *PTS_SECURE_ONLY_MODE = "PTS_SecurePairOnly";
33 const char *PTS_LE_CONN_UPDATED_DISABLED = "PTS_DisableConnUpdates";
34 const char *PTS_DISABLE_SDP_LE_PAIR = "PTS_DisableSDPOnLEPair";
35 const char *PTS_SMP_PAIRING_OPTIONS_KEY = "PTS_SmpOptions";
36 const char *PTS_SMP_FAILURE_CASE_KEY = "PTS_SmpFailureCase";
38 static config_t *config;
40 // Module lifecycle functions
42 static future_t *init() {
43 // TODO(armansito): Find a better way than searching by a hardcoded path.
44 #if defined(OS_GENERIC)
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)
51 LOG_INFO(LOG_TAG, "%s attempt to load stack conf from %s", __func__, path);
53 config = config_new(path);
55 LOG_INFO(LOG_TAG, "%s file >%s< not found", __func__, path);
56 return future_new_immediate(FUTURE_FAIL);
59 return future_new_immediate(FUTURE_SUCCESS);
62 static future_t *clean_up() {
65 return future_new_immediate(FUTURE_SUCCESS);
68 EXPORT_SYMBOL const module_t stack_config_module = {
69 .name = STACK_CONFIG_MODULE,
79 // Interface functions
81 static const char *get_btsnoop_log_path(void) {
82 return config_get_string(config, CONFIG_DEFAULT_SECTION, BTSNOOP_LOG_PATH_KEY, "/data/misc/bluedroid/btsnoop_hci.log");
85 static bool get_btsnoop_turned_on(void) {
86 return config_get_bool(config, CONFIG_DEFAULT_SECTION, BTSNOOP_TURNED_ON_KEY, false);
89 static bool get_btsnoop_should_save_last(void) {
90 return config_get_bool(config, CONFIG_DEFAULT_SECTION, BTSNOOP_SHOULD_SAVE_LAST_KEY, false);
93 static bool get_trace_config_enabled(void) {
94 return config_get_bool(config, CONFIG_DEFAULT_SECTION, TRACE_CONFIG_ENABLED_KEY, false);
97 static bool get_pts_secure_only_mode(void) {
98 return config_get_bool(config, CONFIG_DEFAULT_SECTION, PTS_SECURE_ONLY_MODE, false);
101 static bool get_pts_conn_updates_disabled(void) {
102 return config_get_bool(config, CONFIG_DEFAULT_SECTION, PTS_LE_CONN_UPDATED_DISABLED, false);
105 static bool get_pts_crosskey_sdp_disable(void) {
106 return config_get_bool(config, CONFIG_DEFAULT_SECTION, PTS_DISABLE_SDP_LE_PAIR, false);
109 static const char *get_pts_smp_options(void) {
110 return config_get_string(config, CONFIG_DEFAULT_SECTION, PTS_SMP_PAIRING_OPTIONS_KEY, NULL);
113 static int get_pts_smp_failure_case(void) {
114 return config_get_int(config, CONFIG_DEFAULT_SECTION, PTS_SMP_FAILURE_CASE_KEY, 0);
117 static config_t *get_all(void) {
121 const stack_config_t interface = {
122 get_btsnoop_log_path,
123 get_btsnoop_turned_on,
124 get_btsnoop_should_save_last,
125 get_trace_config_enabled,
126 get_pts_secure_only_mode,
127 get_pts_conn_updates_disabled,
128 get_pts_crosskey_sdp_disable,
130 get_pts_smp_failure_case,
134 const stack_config_t *stack_config_get_interface() {