Zach Johnson | 9891f32 | 2014-09-22 22:11:55 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Jakub Pawlowski | 5b790fe | 2017-09-18 09:00:20 -0700 | [diff] [blame] | 3 | * Copyright 2014 Google, Inc. |
Zach Johnson | 9891f32 | 2014-09-22 22:11:55 -0700 | [diff] [blame] | 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 | |
Marie Janssen | 49120dc | 2015-07-07 16:47:20 -0700 | [diff] [blame] | 19 | #define LOG_TAG "bt_stack_config" |
| 20 | |
Marie Janssen | db55458 | 2015-06-26 14:53:46 -0700 | [diff] [blame] | 21 | #include "stack_config.h" |
Zach Johnson | 9891f32 | 2014-09-22 22:11:55 -0700 | [diff] [blame] | 22 | |
Jack He | f2af1c4 | 2016-12-13 01:59:12 -0800 | [diff] [blame] | 23 | #include <base/logging.h> |
Zach Johnson | 9891f32 | 2014-09-22 22:11:55 -0700 | [diff] [blame] | 24 | |
Sharvil Nanavati | 0f9b91e | 2015-03-12 15:42:50 -0700 | [diff] [blame] | 25 | #include "osi/include/future.h" |
Sharvil Nanavati | 4480276 | 2014-12-23 23:08:58 -0800 | [diff] [blame] | 26 | #include "osi/include/log.h" |
Zach Johnson | 9891f32 | 2014-09-22 22:11:55 -0700 | [diff] [blame] | 27 | |
Jakub Pawlowski | f3fb316 | 2017-10-06 00:04:27 -0700 | [diff] [blame] | 28 | namespace { |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 29 | const char* TRACE_CONFIG_ENABLED_KEY = "TraceConf"; |
tedwang | 494dcc5 | 2018-05-16 19:51:26 +0800 | [diff] [blame] | 30 | const char* PTS_AVRCP_TEST = "PTS_AvrcpTest"; |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 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"; |
Zach Johnson | 9891f32 | 2014-09-22 22:11:55 -0700 | [diff] [blame] | 36 | |
Jakub Pawlowski | f3fb316 | 2017-10-06 00:04:27 -0700 | [diff] [blame] | 37 | static std::unique_ptr<config_t> config; |
| 38 | } // namespace |
Zach Johnson | 9891f32 | 2014-09-22 22:11:55 -0700 | [diff] [blame] | 39 | |
| 40 | // Module lifecycle functions |
| 41 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 42 | static future_t* init() { |
Arman Uguray | f2d6434 | 2015-07-08 15:47:39 -0700 | [diff] [blame] | 43 | // TODO(armansito): Find a better way than searching by a hardcoded path. |
| 44 | #if defined(OS_GENERIC) |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 45 | const char* path = "bt_stack.conf"; |
Arman Uguray | f2d6434 | 2015-07-08 15:47:39 -0700 | [diff] [blame] | 46 | #else // !defined(OS_GENERIC) |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 47 | const char* path = "/etc/bluetooth/bt_stack.conf"; |
Arman Uguray | f2d6434 | 2015-07-08 15:47:39 -0700 | [diff] [blame] | 48 | #endif // defined(OS_GENERIC) |
Jack He | f2af1c4 | 2016-12-13 01:59:12 -0800 | [diff] [blame] | 49 | CHECK(path != NULL); |
Zach Johnson | 9891f32 | 2014-09-22 22:11:55 -0700 | [diff] [blame] | 50 | |
Marie Janssen | db55458 | 2015-06-26 14:53:46 -0700 | [diff] [blame] | 51 | LOG_INFO(LOG_TAG, "%s attempt to load stack conf from %s", __func__, path); |
Zach Johnson | 9891f32 | 2014-09-22 22:11:55 -0700 | [diff] [blame] | 52 | |
| 53 | config = config_new(path); |
| 54 | if (!config) { |
Marie Janssen | db55458 | 2015-06-26 14:53:46 -0700 | [diff] [blame] | 55 | LOG_INFO(LOG_TAG, "%s file >%s< not found", __func__, path); |
Jakub Pawlowski | e919eda | 2016-03-10 09:20:45 -0800 | [diff] [blame] | 56 | config = config_new_empty(); |
Zach Johnson | 9891f32 | 2014-09-22 22:11:55 -0700 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | return future_new_immediate(FUTURE_SUCCESS); |
| 60 | } |
| 61 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 62 | static future_t* clean_up() { |
Jakub Pawlowski | f3fb316 | 2017-10-06 00:04:27 -0700 | [diff] [blame] | 63 | config.reset(); |
Zach Johnson | 9891f32 | 2014-09-22 22:11:55 -0700 | [diff] [blame] | 64 | return future_new_immediate(FUTURE_SUCCESS); |
| 65 | } |
| 66 | |
Pavlin Radoslavov | b2a292b | 2016-10-14 19:34:48 -0700 | [diff] [blame] | 67 | EXPORT_SYMBOL extern const module_t stack_config_module = { |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 68 | .name = STACK_CONFIG_MODULE, |
| 69 | .init = init, |
| 70 | .start_up = NULL, |
| 71 | .shut_down = NULL, |
| 72 | .clean_up = clean_up, |
| 73 | .dependencies = {NULL}}; |
Zach Johnson | 9891f32 | 2014-09-22 22:11:55 -0700 | [diff] [blame] | 74 | |
| 75 | // Interface functions |
Zach Johnson | 9891f32 | 2014-09-22 22:11:55 -0700 | [diff] [blame] | 76 | static bool get_trace_config_enabled(void) { |
Jakub Pawlowski | f3fb316 | 2017-10-06 00:04:27 -0700 | [diff] [blame] | 77 | return config_get_bool(*config, CONFIG_DEFAULT_SECTION, |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 78 | TRACE_CONFIG_ENABLED_KEY, false); |
Zach Johnson | 9891f32 | 2014-09-22 22:11:55 -0700 | [diff] [blame] | 79 | } |
| 80 | |
tedwang | 494dcc5 | 2018-05-16 19:51:26 +0800 | [diff] [blame] | 81 | static bool get_pts_avrcp_test(void) { |
| 82 | return config_get_bool(*config, CONFIG_DEFAULT_SECTION, PTS_AVRCP_TEST, |
| 83 | false); |
| 84 | } |
| 85 | |
Nitin Arora | a0ee0f8 | 2016-03-11 12:26:51 -0800 | [diff] [blame] | 86 | static bool get_pts_secure_only_mode(void) { |
Jakub Pawlowski | f3fb316 | 2017-10-06 00:04:27 -0700 | [diff] [blame] | 87 | return config_get_bool(*config, CONFIG_DEFAULT_SECTION, PTS_SECURE_ONLY_MODE, |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 88 | false); |
Nitin Arora | a0ee0f8 | 2016-03-11 12:26:51 -0800 | [diff] [blame] | 89 | } |
| 90 | |
Nitin Arora | 36ad41b | 2015-06-10 17:10:57 -0700 | [diff] [blame] | 91 | static bool get_pts_conn_updates_disabled(void) { |
Jakub Pawlowski | f3fb316 | 2017-10-06 00:04:27 -0700 | [diff] [blame] | 92 | return config_get_bool(*config, CONFIG_DEFAULT_SECTION, |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 93 | PTS_LE_CONN_UPDATED_DISABLED, false); |
Nitin Arora | 36ad41b | 2015-06-10 17:10:57 -0700 | [diff] [blame] | 94 | } |
| 95 | |
Nitin Arora | 4cdb0e5 | 2016-03-10 18:27:24 -0800 | [diff] [blame] | 96 | static bool get_pts_crosskey_sdp_disable(void) { |
Jakub Pawlowski | f3fb316 | 2017-10-06 00:04:27 -0700 | [diff] [blame] | 97 | return config_get_bool(*config, CONFIG_DEFAULT_SECTION, |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 98 | PTS_DISABLE_SDP_LE_PAIR, false); |
Nitin Arora | 4cdb0e5 | 2016-03-10 18:27:24 -0800 | [diff] [blame] | 99 | } |
| 100 | |
Jakub Pawlowski | f3fb316 | 2017-10-06 00:04:27 -0700 | [diff] [blame] | 101 | static const std::string* get_pts_smp_options(void) { |
| 102 | return config_get_string(*config, CONFIG_DEFAULT_SECTION, |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 103 | PTS_SMP_PAIRING_OPTIONS_KEY, NULL); |
Nitin Arora | 2aa2b80 | 2016-03-11 16:37:51 -0800 | [diff] [blame] | 104 | } |
| 105 | |
Nitin Arora | 0bd0c8f | 2016-03-15 15:00:36 -0700 | [diff] [blame] | 106 | static int get_pts_smp_failure_case(void) { |
Jakub Pawlowski | f3fb316 | 2017-10-06 00:04:27 -0700 | [diff] [blame] | 107 | return config_get_int(*config, CONFIG_DEFAULT_SECTION, |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 108 | PTS_SMP_FAILURE_CASE_KEY, 0); |
Nitin Arora | 0bd0c8f | 2016-03-15 15:00:36 -0700 | [diff] [blame] | 109 | } |
| 110 | |
Jakub Pawlowski | f3fb316 | 2017-10-06 00:04:27 -0700 | [diff] [blame] | 111 | static config_t* get_all(void) { return config.get(); } |
Zach Johnson | 9891f32 | 2014-09-22 22:11:55 -0700 | [diff] [blame] | 112 | |
tedwang | 494dcc5 | 2018-05-16 19:51:26 +0800 | [diff] [blame] | 113 | const 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 Johnson | 9891f32 | 2014-09-22 22:11:55 -0700 | [diff] [blame] | 118 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 119 | const stack_config_t* stack_config_get_interface(void) { return &interface; } |