blob: 6b937aa94a540b44bbfe3db85d0cd0585763b072 [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";
30const char* PTS_SECURE_ONLY_MODE = "PTS_SecurePairOnly";
31const char* PTS_LE_CONN_UPDATED_DISABLED = "PTS_DisableConnUpdates";
32const char* PTS_DISABLE_SDP_LE_PAIR = "PTS_DisableSDPOnLEPair";
33const char* PTS_SMP_PAIRING_OPTIONS_KEY = "PTS_SmpOptions";
34const char* PTS_SMP_FAILURE_CASE_KEY = "PTS_SmpFailureCase";
Zach Johnson9891f322014-09-22 22:11:55 -070035
Jakub Pawlowskif3fb3162017-10-06 00:04:27 -070036static std::unique_ptr<config_t> config;
37} // namespace
Zach Johnson9891f322014-09-22 22:11:55 -070038
39// Module lifecycle functions
40
Myles Watson911d1ae2016-11-28 16:44:40 -080041static future_t* init() {
Arman Ugurayf2d64342015-07-08 15:47:39 -070042// TODO(armansito): Find a better way than searching by a hardcoded path.
43#if defined(OS_GENERIC)
Myles Watson911d1ae2016-11-28 16:44:40 -080044 const char* path = "bt_stack.conf";
Arman Ugurayf2d64342015-07-08 15:47:39 -070045#else // !defined(OS_GENERIC)
Myles Watson911d1ae2016-11-28 16:44:40 -080046 const char* path = "/etc/bluetooth/bt_stack.conf";
Arman Ugurayf2d64342015-07-08 15:47:39 -070047#endif // defined(OS_GENERIC)
Jack Hef2af1c42016-12-13 01:59:12 -080048 CHECK(path != NULL);
Zach Johnson9891f322014-09-22 22:11:55 -070049
Marie Janssendb554582015-06-26 14:53:46 -070050 LOG_INFO(LOG_TAG, "%s attempt to load stack conf from %s", __func__, path);
Zach Johnson9891f322014-09-22 22:11:55 -070051
52 config = config_new(path);
53 if (!config) {
Marie Janssendb554582015-06-26 14:53:46 -070054 LOG_INFO(LOG_TAG, "%s file >%s< not found", __func__, path);
Jakub Pawlowskie919eda2016-03-10 09:20:45 -080055 config = config_new_empty();
Zach Johnson9891f322014-09-22 22:11:55 -070056 }
57
58 return future_new_immediate(FUTURE_SUCCESS);
59}
60
Myles Watson911d1ae2016-11-28 16:44:40 -080061static future_t* clean_up() {
Jakub Pawlowskif3fb3162017-10-06 00:04:27 -070062 config.reset();
Zach Johnson9891f322014-09-22 22:11:55 -070063 return future_new_immediate(FUTURE_SUCCESS);
64}
65
Pavlin Radoslavovb2a292b2016-10-14 19:34:48 -070066EXPORT_SYMBOL extern const module_t stack_config_module = {
Myles Watson911d1ae2016-11-28 16:44:40 -080067 .name = STACK_CONFIG_MODULE,
68 .init = init,
69 .start_up = NULL,
70 .shut_down = NULL,
71 .clean_up = clean_up,
72 .dependencies = {NULL}};
Zach Johnson9891f322014-09-22 22:11:55 -070073
74// Interface functions
Zach Johnson9891f322014-09-22 22:11:55 -070075static bool get_trace_config_enabled(void) {
Jakub Pawlowskif3fb3162017-10-06 00:04:27 -070076 return config_get_bool(*config, CONFIG_DEFAULT_SECTION,
Myles Watson911d1ae2016-11-28 16:44:40 -080077 TRACE_CONFIG_ENABLED_KEY, false);
Zach Johnson9891f322014-09-22 22:11:55 -070078}
79
Nitin Aroraa0ee0f82016-03-11 12:26:51 -080080static bool get_pts_secure_only_mode(void) {
Jakub Pawlowskif3fb3162017-10-06 00:04:27 -070081 return config_get_bool(*config, CONFIG_DEFAULT_SECTION, PTS_SECURE_ONLY_MODE,
Myles Watson911d1ae2016-11-28 16:44:40 -080082 false);
Nitin Aroraa0ee0f82016-03-11 12:26:51 -080083}
84
Nitin Arora36ad41b2015-06-10 17:10:57 -070085static bool get_pts_conn_updates_disabled(void) {
Jakub Pawlowskif3fb3162017-10-06 00:04:27 -070086 return config_get_bool(*config, CONFIG_DEFAULT_SECTION,
Myles Watson911d1ae2016-11-28 16:44:40 -080087 PTS_LE_CONN_UPDATED_DISABLED, false);
Nitin Arora36ad41b2015-06-10 17:10:57 -070088}
89
Nitin Arora4cdb0e52016-03-10 18:27:24 -080090static bool get_pts_crosskey_sdp_disable(void) {
Jakub Pawlowskif3fb3162017-10-06 00:04:27 -070091 return config_get_bool(*config, CONFIG_DEFAULT_SECTION,
Myles Watson911d1ae2016-11-28 16:44:40 -080092 PTS_DISABLE_SDP_LE_PAIR, false);
Nitin Arora4cdb0e52016-03-10 18:27:24 -080093}
94
Jakub Pawlowskif3fb3162017-10-06 00:04:27 -070095static const std::string* get_pts_smp_options(void) {
96 return config_get_string(*config, CONFIG_DEFAULT_SECTION,
Myles Watson911d1ae2016-11-28 16:44:40 -080097 PTS_SMP_PAIRING_OPTIONS_KEY, NULL);
Nitin Arora2aa2b802016-03-11 16:37:51 -080098}
99
Nitin Arora0bd0c8f2016-03-15 15:00:36 -0700100static int get_pts_smp_failure_case(void) {
Jakub Pawlowskif3fb3162017-10-06 00:04:27 -0700101 return config_get_int(*config, CONFIG_DEFAULT_SECTION,
Myles Watson911d1ae2016-11-28 16:44:40 -0800102 PTS_SMP_FAILURE_CASE_KEY, 0);
Nitin Arora0bd0c8f2016-03-15 15:00:36 -0700103}
104
Jakub Pawlowskif3fb3162017-10-06 00:04:27 -0700105static config_t* get_all(void) { return config.get(); }
Zach Johnson9891f322014-09-22 22:11:55 -0700106
Ajay Panicker99c34222017-04-17 20:53:24 -0700107const stack_config_t interface = {get_trace_config_enabled,
108 get_pts_secure_only_mode,
109 get_pts_conn_updates_disabled,
110 get_pts_crosskey_sdp_disable,
111 get_pts_smp_options,
112 get_pts_smp_failure_case,
113 get_all};
Zach Johnson9891f322014-09-22 22:11:55 -0700114
Myles Watson911d1ae2016-11-28 16:44:40 -0800115const stack_config_t* stack_config_get_interface(void) { return &interface; }