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 const char* PTS_FORCE_EATT_FOR_NOTIFICATIONS = "PTS_ForceEattForNotifications";
37 const char* PTS_CONNECT_EATT_UNCONDITIONALLY =
38 "PTS_ConnectEattUncondictionally";
39 const char* PTS_CONNECT_EATT_UNENCRYPTED = "PTS_ConnectEattUnencrypted";
40 const char* PTS_BROADCAST_UNENCRYPTED = "PTS_BroadcastUnencrypted";
41 const char* PTS_FORCE_LE_AUDIO_MULTIPLE_CONTEXTS_METADATA =
42 "PTS_ForceLeAudioMultipleContextsMetadata";
43 const char* PTS_EATT_PERIPHERAL_COLLISION_SUPPORT =
44 "PTS_EattPeripheralCollionSupport";
45 const char* PTS_EATT_USE_FOR_ALL_SERVICES = "PTS_UseEattForAllServices";
46 const char* PTS_L2CAP_ECOC_UPPER_TESTER = "PTS_L2capEcocUpperTester";
47 const char* PTS_L2CAP_ECOC_MIN_KEY_SIZE = "PTS_L2capEcocMinKeySize";
48 const char* PTS_L2CAP_ECOC_INITIAL_CHAN_CNT = "PTS_L2capEcocInitialChanCnt";
49 const char* PTS_L2CAP_ECOC_CONNECT_REMAINING = "PTS_L2capEcocConnectRemaining";
50 const char* PTS_L2CAP_ECOC_SEND_NUM_OF_SDU = "PTS_L2capEcocSendNumOfSdu";
51 const char* PTS_L2CAP_ECOC_RECONFIGURE = "PTS_L2capEcocReconfigure";
52 const char* PTS_BROADCAST_AUDIO_CONFIG_OPTION =
53 "PTS_BroadcastAudioConfigOption";
54 const char* PTS_LE_AUDIO_SUSPEND_STREAMING = "PTS_LeAudioSuspendStreaming";
55
56 static std::unique_ptr<config_t> config;
57 } // namespace
58
59 // Module lifecycle functions
60
init()61 static future_t* init() {
62 // TODO(armansito): Find a better way than searching by a hardcoded path.
63 #if defined(TARGET_FLOSS)
64 const char* path = "/var/lib/bluetooth/bt_stack.conf";
65 #elif defined(OS_GENERIC)
66 const char* path = "bt_stack.conf";
67 #else // !defined(OS_GENERIC)
68 const char* path = "/apex/com.android.btservices/etc/bluetooth/bt_stack.conf";
69 #endif // defined(OS_GENERIC)
70 CHECK(path != NULL);
71
72 LOG_INFO("%s attempt to load stack conf from %s", __func__, path);
73
74 config = config_new(path);
75 if (!config) {
76 LOG_INFO("%s file >%s< not found", __func__, path);
77 config = config_new_empty();
78 }
79
80 return future_new_immediate(FUTURE_SUCCESS);
81 }
82
clean_up()83 static future_t* clean_up() {
84 config.reset();
85 return future_new_immediate(FUTURE_SUCCESS);
86 }
87
88 EXPORT_SYMBOL extern const module_t stack_config_module = {
89 .name = STACK_CONFIG_MODULE,
90 .init = init,
91 .start_up = NULL,
92 .shut_down = NULL,
93 .clean_up = clean_up,
94 .dependencies = {NULL}};
95
96 // Interface functions
get_trace_config_enabled(void)97 static bool get_trace_config_enabled(void) {
98 return config_get_bool(*config, CONFIG_DEFAULT_SECTION,
99 TRACE_CONFIG_ENABLED_KEY, false);
100 }
101
get_pts_avrcp_test(void)102 static bool get_pts_avrcp_test(void) {
103 return config_get_bool(*config, CONFIG_DEFAULT_SECTION, PTS_AVRCP_TEST,
104 false);
105 }
106
get_pts_secure_only_mode(void)107 static bool get_pts_secure_only_mode(void) {
108 return config_get_bool(*config, CONFIG_DEFAULT_SECTION, PTS_SECURE_ONLY_MODE,
109 false);
110 }
111
get_pts_conn_updates_disabled(void)112 static bool get_pts_conn_updates_disabled(void) {
113 return config_get_bool(*config, CONFIG_DEFAULT_SECTION,
114 PTS_LE_CONN_UPDATED_DISABLED, false);
115 }
116
get_pts_crosskey_sdp_disable(void)117 static bool get_pts_crosskey_sdp_disable(void) {
118 return config_get_bool(*config, CONFIG_DEFAULT_SECTION,
119 PTS_DISABLE_SDP_LE_PAIR, false);
120 }
121
get_pts_smp_options(void)122 static const std::string* get_pts_smp_options(void) {
123 return config_get_string(*config, CONFIG_DEFAULT_SECTION,
124 PTS_SMP_PAIRING_OPTIONS_KEY, NULL);
125 }
126
get_pts_smp_failure_case(void)127 static int get_pts_smp_failure_case(void) {
128 return config_get_int(*config, CONFIG_DEFAULT_SECTION,
129 PTS_SMP_FAILURE_CASE_KEY, 0);
130 }
131
get_pts_force_eatt_for_notifications(void)132 static bool get_pts_force_eatt_for_notifications(void) {
133 return config_get_bool(*config, CONFIG_DEFAULT_SECTION,
134 PTS_FORCE_EATT_FOR_NOTIFICATIONS, false);
135 }
136
get_pts_connect_eatt_unconditionally(void)137 static bool get_pts_connect_eatt_unconditionally(void) {
138 return config_get_bool(*config, CONFIG_DEFAULT_SECTION,
139 PTS_CONNECT_EATT_UNCONDITIONALLY, false);
140 }
141
get_pts_connect_eatt_before_encryption(void)142 static bool get_pts_connect_eatt_before_encryption(void) {
143 return config_get_bool(*config, CONFIG_DEFAULT_SECTION,
144 PTS_CONNECT_EATT_UNENCRYPTED, false);
145 }
146
get_pts_unencrypt_broadcast(void)147 static bool get_pts_unencrypt_broadcast(void) {
148 return config_get_bool(*config, CONFIG_DEFAULT_SECTION,
149 PTS_BROADCAST_UNENCRYPTED, false);
150 }
151
get_pts_eatt_peripheral_collision_support(void)152 static bool get_pts_eatt_peripheral_collision_support(void) {
153 return config_get_bool(*config, CONFIG_DEFAULT_SECTION,
154 PTS_EATT_PERIPHERAL_COLLISION_SUPPORT, false);
155 }
156
get_pts_use_eatt_for_all_services(void)157 static bool get_pts_use_eatt_for_all_services(void) {
158 return config_get_bool(*config, CONFIG_DEFAULT_SECTION,
159 PTS_EATT_USE_FOR_ALL_SERVICES, false);
160 }
161
get_pts_force_le_audio_multiple_contexts_metadata(void)162 static bool get_pts_force_le_audio_multiple_contexts_metadata(void) {
163 return config_get_bool(*config, CONFIG_DEFAULT_SECTION,
164 PTS_FORCE_LE_AUDIO_MULTIPLE_CONTEXTS_METADATA, false);
165 }
166
get_pts_l2cap_ecoc_upper_tester(void)167 static bool get_pts_l2cap_ecoc_upper_tester(void) {
168 return config_get_bool(*config, CONFIG_DEFAULT_SECTION,
169 PTS_L2CAP_ECOC_UPPER_TESTER, false);
170 }
171
get_pts_l2cap_ecoc_min_key_size(void)172 static int get_pts_l2cap_ecoc_min_key_size(void) {
173 return config_get_int(*config, CONFIG_DEFAULT_SECTION,
174 PTS_L2CAP_ECOC_MIN_KEY_SIZE, -1);
175 }
176
get_pts_l2cap_ecoc_initial_chan_cnt(void)177 static int get_pts_l2cap_ecoc_initial_chan_cnt(void) {
178 return config_get_int(*config, CONFIG_DEFAULT_SECTION,
179 PTS_L2CAP_ECOC_INITIAL_CHAN_CNT, -1);
180 }
181
get_pts_l2cap_ecoc_connect_remaining(void)182 static bool get_pts_l2cap_ecoc_connect_remaining(void) {
183 return config_get_bool(*config, CONFIG_DEFAULT_SECTION,
184 PTS_L2CAP_ECOC_CONNECT_REMAINING, false);
185 }
186
get_pts_l2cap_ecoc_send_num_of_sdu(void)187 static int get_pts_l2cap_ecoc_send_num_of_sdu(void) {
188 return config_get_int(*config, CONFIG_DEFAULT_SECTION,
189 PTS_L2CAP_ECOC_SEND_NUM_OF_SDU, -1);
190 }
191
get_pts_l2cap_ecoc_reconfigure(void)192 static bool get_pts_l2cap_ecoc_reconfigure(void) {
193 return config_get_bool(*config, CONFIG_DEFAULT_SECTION,
194 PTS_L2CAP_ECOC_RECONFIGURE, false);
195 }
196
get_pts_broadcast_audio_config_options(void)197 static const std::string* get_pts_broadcast_audio_config_options(void) {
198 if (!config) {
199 LOG_INFO("Config isn't ready, use default option");
200 return NULL;
201 }
202 return config_get_string(*config, CONFIG_DEFAULT_SECTION,
203 PTS_BROADCAST_AUDIO_CONFIG_OPTION, NULL);
204 }
205
get_pts_le_audio_disable_ases_before_stopping(void)206 static bool get_pts_le_audio_disable_ases_before_stopping(void) {
207 return config_get_bool(*config, CONFIG_DEFAULT_SECTION,
208 PTS_LE_AUDIO_SUSPEND_STREAMING, false);
209 }
210
get_all(void)211 static config_t* get_all(void) { return config.get(); }
212
213 const stack_config_t interface = {
214 get_trace_config_enabled,
215 get_pts_avrcp_test,
216 get_pts_secure_only_mode,
217 get_pts_conn_updates_disabled,
218 get_pts_crosskey_sdp_disable,
219 get_pts_smp_options,
220 get_pts_smp_failure_case,
221 get_pts_force_eatt_for_notifications,
222 get_pts_connect_eatt_unconditionally,
223 get_pts_connect_eatt_before_encryption,
224 get_pts_unencrypt_broadcast,
225 get_pts_eatt_peripheral_collision_support,
226 get_pts_use_eatt_for_all_services,
227 get_pts_force_le_audio_multiple_contexts_metadata,
228 get_pts_l2cap_ecoc_upper_tester,
229 get_pts_l2cap_ecoc_min_key_size,
230 get_pts_l2cap_ecoc_initial_chan_cnt,
231 get_pts_l2cap_ecoc_connect_remaining,
232 get_pts_l2cap_ecoc_send_num_of_sdu,
233 get_pts_l2cap_ecoc_reconfigure,
234 get_pts_broadcast_audio_config_options,
235 get_pts_le_audio_disable_ases_before_stopping,
236 get_all};
237
stack_config_get_interface(void)238 const stack_config_t* stack_config_get_interface(void) { return &interface; }
239