blob: 0e56250058846506ef8a99fb1c10904fc43db0b9 [file] [log] [blame]
Zach Johnson9891f322014-09-22 22:11:55 -07001/******************************************************************************
2 *
Jakub Pawlowski5b790fe2017-09-18 09:00:20 -07003 * Copyright 2014 Google, Inc.
Zach Johnson9891f322014-09-22 22:11:55 -07004 *
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
Marie Janssen49120dc2015-07-07 16:47:20 -070019#define LOG_TAG "bt_stack_config"
20
Marie Janssendb554582015-06-26 14:53:46 -070021#include "stack_config.h"
Zach Johnson9891f322014-09-22 22:11:55 -070022
Jack Hef2af1c42016-12-13 01:59:12 -080023#include <base/logging.h>
Zach Johnson9891f322014-09-22 22:11:55 -070024
Sharvil Nanavati0f9b91e2015-03-12 15:42:50 -070025#include "osi/include/future.h"
Sharvil Nanavati44802762014-12-23 23:08:58 -080026#include "osi/include/log.h"
Zach Johnson9891f322014-09-22 22:11:55 -070027
Jakub Pawlowskif3fb3162017-10-06 00:04:27 -070028namespace {
Myles Watson911d1ae2016-11-28 16:44:40 -080029const char* TRACE_CONFIG_ENABLED_KEY = "TraceConf";
tedwang494dcc52018-05-16 19:51:26 +080030const char* PTS_AVRCP_TEST = "PTS_AvrcpTest";
Myles Watson911d1ae2016-11-28 16:44:40 -080031const char* PTS_SECURE_ONLY_MODE = "PTS_SecurePairOnly";
32const char* PTS_LE_CONN_UPDATED_DISABLED = "PTS_DisableConnUpdates";
33const char* PTS_DISABLE_SDP_LE_PAIR = "PTS_DisableSDPOnLEPair";
34const char* PTS_SMP_PAIRING_OPTIONS_KEY = "PTS_SmpOptions";
35const char* PTS_SMP_FAILURE_CASE_KEY = "PTS_SmpFailureCase";
Zach Johnson9891f322014-09-22 22:11:55 -070036
Jakub Pawlowskif3fb3162017-10-06 00:04:27 -070037static std::unique_ptr<config_t> config;
38} // namespace
Zach Johnson9891f322014-09-22 22:11:55 -070039
40// Module lifecycle functions
41
Myles Watson911d1ae2016-11-28 16:44:40 -080042static future_t* init() {
Arman Ugurayf2d64342015-07-08 15:47:39 -070043// TODO(armansito): Find a better way than searching by a hardcoded path.
44#if defined(OS_GENERIC)
Myles Watson911d1ae2016-11-28 16:44:40 -080045 const char* path = "bt_stack.conf";
Arman Ugurayf2d64342015-07-08 15:47:39 -070046#else // !defined(OS_GENERIC)
Myles Watson911d1ae2016-11-28 16:44:40 -080047 const char* path = "/etc/bluetooth/bt_stack.conf";
Arman Ugurayf2d64342015-07-08 15:47:39 -070048#endif // defined(OS_GENERIC)
Jack Hef2af1c42016-12-13 01:59:12 -080049 CHECK(path != NULL);
Zach Johnson9891f322014-09-22 22:11:55 -070050
Marie Janssendb554582015-06-26 14:53:46 -070051 LOG_INFO(LOG_TAG, "%s attempt to load stack conf from %s", __func__, path);
Zach Johnson9891f322014-09-22 22:11:55 -070052
53 config = config_new(path);
54 if (!config) {
Marie Janssendb554582015-06-26 14:53:46 -070055 LOG_INFO(LOG_TAG, "%s file >%s< not found", __func__, path);
Jakub Pawlowskie919eda2016-03-10 09:20:45 -080056 config = config_new_empty();
Zach Johnson9891f322014-09-22 22:11:55 -070057 }
58
59 return future_new_immediate(FUTURE_SUCCESS);
60}
61
Myles Watson911d1ae2016-11-28 16:44:40 -080062static future_t* clean_up() {
Jakub Pawlowskif3fb3162017-10-06 00:04:27 -070063 config.reset();
Zach Johnson9891f322014-09-22 22:11:55 -070064 return future_new_immediate(FUTURE_SUCCESS);
65}
66
Pavlin Radoslavovb2a292b2016-10-14 19:34:48 -070067EXPORT_SYMBOL extern const module_t stack_config_module = {
Myles Watson911d1ae2016-11-28 16:44:40 -080068 .name = STACK_CONFIG_MODULE,
69 .init = init,
70 .start_up = NULL,
71 .shut_down = NULL,
72 .clean_up = clean_up,
73 .dependencies = {NULL}};
Zach Johnson9891f322014-09-22 22:11:55 -070074
75// Interface functions
Zach Johnson9891f322014-09-22 22:11:55 -070076static bool get_trace_config_enabled(void) {
Jakub Pawlowskif3fb3162017-10-06 00:04:27 -070077 return config_get_bool(*config, CONFIG_DEFAULT_SECTION,
Myles Watson911d1ae2016-11-28 16:44:40 -080078 TRACE_CONFIG_ENABLED_KEY, false);
Zach Johnson9891f322014-09-22 22:11:55 -070079}
80
tedwang494dcc52018-05-16 19:51:26 +080081static bool get_pts_avrcp_test(void) {
82 return config_get_bool(*config, CONFIG_DEFAULT_SECTION, PTS_AVRCP_TEST,
83 false);
84}
85
Nitin Aroraa0ee0f82016-03-11 12:26:51 -080086static bool get_pts_secure_only_mode(void) {
Jakub Pawlowskif3fb3162017-10-06 00:04:27 -070087 return config_get_bool(*config, CONFIG_DEFAULT_SECTION, PTS_SECURE_ONLY_MODE,
Myles Watson911d1ae2016-11-28 16:44:40 -080088 false);
Nitin Aroraa0ee0f82016-03-11 12:26:51 -080089}
90
Nitin Arora36ad41b2015-06-10 17:10:57 -070091static bool get_pts_conn_updates_disabled(void) {
Jakub Pawlowskif3fb3162017-10-06 00:04:27 -070092 return config_get_bool(*config, CONFIG_DEFAULT_SECTION,
Myles Watson911d1ae2016-11-28 16:44:40 -080093 PTS_LE_CONN_UPDATED_DISABLED, false);
Nitin Arora36ad41b2015-06-10 17:10:57 -070094}
95
Nitin Arora4cdb0e52016-03-10 18:27:24 -080096static bool get_pts_crosskey_sdp_disable(void) {
Jakub Pawlowskif3fb3162017-10-06 00:04:27 -070097 return config_get_bool(*config, CONFIG_DEFAULT_SECTION,
Myles Watson911d1ae2016-11-28 16:44:40 -080098 PTS_DISABLE_SDP_LE_PAIR, false);
Nitin Arora4cdb0e52016-03-10 18:27:24 -080099}
100
Jakub Pawlowskif3fb3162017-10-06 00:04:27 -0700101static const std::string* get_pts_smp_options(void) {
102 return config_get_string(*config, CONFIG_DEFAULT_SECTION,
Myles Watson911d1ae2016-11-28 16:44:40 -0800103 PTS_SMP_PAIRING_OPTIONS_KEY, NULL);
Nitin Arora2aa2b802016-03-11 16:37:51 -0800104}
105
Nitin Arora0bd0c8f2016-03-15 15:00:36 -0700106static int get_pts_smp_failure_case(void) {
Jakub Pawlowskif3fb3162017-10-06 00:04:27 -0700107 return config_get_int(*config, CONFIG_DEFAULT_SECTION,
Myles Watson911d1ae2016-11-28 16:44:40 -0800108 PTS_SMP_FAILURE_CASE_KEY, 0);
Nitin Arora0bd0c8f2016-03-15 15:00:36 -0700109}
110
Jakub Pawlowskif3fb3162017-10-06 00:04:27 -0700111static config_t* get_all(void) { return config.get(); }
Zach Johnson9891f322014-09-22 22:11:55 -0700112
tedwang494dcc52018-05-16 19:51:26 +0800113const 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};
Zach Johnson9891f322014-09-22 22:11:55 -0700118
Myles Watson911d1ae2016-11-28 16:44:40 -0800119const stack_config_t* stack_config_get_interface(void) { return &interface; }