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 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";
37
38 static config_t *config;
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)
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 assert(path != NULL);
50
51 LOG_INFO(LOG_TAG, "%s attempt to load stack conf from %s", __func__, path);
52
53 config = config_new(path);
54 if (!config) {
55 LOG_INFO(LOG_TAG, "%s file >%s< not found", __func__, path);
56 return future_new_immediate(FUTURE_FAIL);
57 }
58
59 return future_new_immediate(FUTURE_SUCCESS);
60 }
61
clean_up()62 static future_t *clean_up() {
63 config_free(config);
64 config = NULL;
65 return future_new_immediate(FUTURE_SUCCESS);
66 }
67
68 EXPORT_SYMBOL const module_t stack_config_module = {
69 .name = STACK_CONFIG_MODULE,
70 .init = init,
71 .start_up = NULL,
72 .shut_down = NULL,
73 .clean_up = clean_up,
74 .dependencies = {
75 NULL
76 }
77 };
78
79 // Interface functions
80
get_btsnoop_log_path(void)81 static const char *get_btsnoop_log_path(void) {
82 return config_get_string(config, CONFIG_DEFAULT_SECTION, BTSNOOP_LOG_PATH_KEY,
83 "/data/misc/bluetooth/logs/btsnoop_hci.log");
84 }
85
get_btsnoop_turned_on(void)86 static bool get_btsnoop_turned_on(void) {
87 return config_get_bool(config, CONFIG_DEFAULT_SECTION, BTSNOOP_TURNED_ON_KEY, false);
88 }
89
get_btsnoop_should_save_last(void)90 static bool get_btsnoop_should_save_last(void) {
91 return config_get_bool(config, CONFIG_DEFAULT_SECTION, BTSNOOP_SHOULD_SAVE_LAST_KEY, false);
92 }
93
get_trace_config_enabled(void)94 static bool get_trace_config_enabled(void) {
95 return config_get_bool(config, CONFIG_DEFAULT_SECTION, TRACE_CONFIG_ENABLED_KEY, false);
96 }
97
get_pts_secure_only_mode(void)98 static bool get_pts_secure_only_mode(void) {
99 return config_get_bool(config, CONFIG_DEFAULT_SECTION, PTS_SECURE_ONLY_MODE, false);
100 }
101
get_pts_conn_updates_disabled(void)102 static bool get_pts_conn_updates_disabled(void) {
103 return config_get_bool(config, CONFIG_DEFAULT_SECTION, PTS_LE_CONN_UPDATED_DISABLED, false);
104 }
105
get_pts_crosskey_sdp_disable(void)106 static bool get_pts_crosskey_sdp_disable(void) {
107 return config_get_bool(config, CONFIG_DEFAULT_SECTION, PTS_DISABLE_SDP_LE_PAIR, false);
108 }
109
get_pts_smp_options(void)110 static const char *get_pts_smp_options(void) {
111 return config_get_string(config, CONFIG_DEFAULT_SECTION, PTS_SMP_PAIRING_OPTIONS_KEY, NULL);
112 }
113
get_pts_smp_failure_case(void)114 static int get_pts_smp_failure_case(void) {
115 return config_get_int(config, CONFIG_DEFAULT_SECTION, PTS_SMP_FAILURE_CASE_KEY, 0);
116 }
117
get_all(void)118 static config_t *get_all(void) {
119 return config;
120 }
121
122 const stack_config_t interface = {
123 get_btsnoop_log_path,
124 get_btsnoop_turned_on,
125 get_btsnoop_should_save_last,
126 get_trace_config_enabled,
127 get_pts_secure_only_mode,
128 get_pts_conn_updates_disabled,
129 get_pts_crosskey_sdp_disable,
130 get_pts_smp_options,
131 get_pts_smp_failure_case,
132 get_all
133 };
134
stack_config_get_interface()135 const stack_config_t *stack_config_get_interface() {
136 return &interface;
137 }
138