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"; |
| 30 | const char* PTS_SECURE_ONLY_MODE = "PTS_SecurePairOnly"; |
| 31 | const char* PTS_LE_CONN_UPDATED_DISABLED = "PTS_DisableConnUpdates"; |
| 32 | const char* PTS_DISABLE_SDP_LE_PAIR = "PTS_DisableSDPOnLEPair"; |
| 33 | const char* PTS_SMP_PAIRING_OPTIONS_KEY = "PTS_SmpOptions"; |
| 34 | const char* PTS_SMP_FAILURE_CASE_KEY = "PTS_SmpFailureCase"; |
Zach Johnson | 9891f32 | 2014-09-22 22:11:55 -0700 | [diff] [blame] | 35 | |
Jakub Pawlowski | f3fb316 | 2017-10-06 00:04:27 -0700 | [diff] [blame] | 36 | static std::unique_ptr<config_t> config; |
| 37 | } // namespace |
Zach Johnson | 9891f32 | 2014-09-22 22:11:55 -0700 | [diff] [blame] | 38 | |
| 39 | // Module lifecycle functions |
| 40 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 41 | static future_t* init() { |
Arman Uguray | f2d6434 | 2015-07-08 15:47:39 -0700 | [diff] [blame] | 42 | // TODO(armansito): Find a better way than searching by a hardcoded path. |
| 43 | #if defined(OS_GENERIC) |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 44 | const char* path = "bt_stack.conf"; |
Arman Uguray | f2d6434 | 2015-07-08 15:47:39 -0700 | [diff] [blame] | 45 | #else // !defined(OS_GENERIC) |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 46 | const char* path = "/etc/bluetooth/bt_stack.conf"; |
Arman Uguray | f2d6434 | 2015-07-08 15:47:39 -0700 | [diff] [blame] | 47 | #endif // defined(OS_GENERIC) |
Jack He | f2af1c4 | 2016-12-13 01:59:12 -0800 | [diff] [blame] | 48 | CHECK(path != NULL); |
Zach Johnson | 9891f32 | 2014-09-22 22:11:55 -0700 | [diff] [blame] | 49 | |
Marie Janssen | db55458 | 2015-06-26 14:53:46 -0700 | [diff] [blame] | 50 | 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] | 51 | |
| 52 | config = config_new(path); |
| 53 | if (!config) { |
Marie Janssen | db55458 | 2015-06-26 14:53:46 -0700 | [diff] [blame] | 54 | LOG_INFO(LOG_TAG, "%s file >%s< not found", __func__, path); |
Jakub Pawlowski | e919eda | 2016-03-10 09:20:45 -0800 | [diff] [blame] | 55 | config = config_new_empty(); |
Zach Johnson | 9891f32 | 2014-09-22 22:11:55 -0700 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | return future_new_immediate(FUTURE_SUCCESS); |
| 59 | } |
| 60 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 61 | static future_t* clean_up() { |
Jakub Pawlowski | f3fb316 | 2017-10-06 00:04:27 -0700 | [diff] [blame] | 62 | config.reset(); |
Zach Johnson | 9891f32 | 2014-09-22 22:11:55 -0700 | [diff] [blame] | 63 | return future_new_immediate(FUTURE_SUCCESS); |
| 64 | } |
| 65 | |
Pavlin Radoslavov | b2a292b | 2016-10-14 19:34:48 -0700 | [diff] [blame] | 66 | EXPORT_SYMBOL extern const module_t stack_config_module = { |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 67 | .name = STACK_CONFIG_MODULE, |
| 68 | .init = init, |
| 69 | .start_up = NULL, |
| 70 | .shut_down = NULL, |
| 71 | .clean_up = clean_up, |
| 72 | .dependencies = {NULL}}; |
Zach Johnson | 9891f32 | 2014-09-22 22:11:55 -0700 | [diff] [blame] | 73 | |
| 74 | // Interface functions |
Zach Johnson | 9891f32 | 2014-09-22 22:11:55 -0700 | [diff] [blame] | 75 | static bool get_trace_config_enabled(void) { |
Jakub Pawlowski | f3fb316 | 2017-10-06 00:04:27 -0700 | [diff] [blame] | 76 | return config_get_bool(*config, CONFIG_DEFAULT_SECTION, |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 77 | TRACE_CONFIG_ENABLED_KEY, false); |
Zach Johnson | 9891f32 | 2014-09-22 22:11:55 -0700 | [diff] [blame] | 78 | } |
| 79 | |
Nitin Arora | a0ee0f8 | 2016-03-11 12:26:51 -0800 | [diff] [blame] | 80 | static bool get_pts_secure_only_mode(void) { |
Jakub Pawlowski | f3fb316 | 2017-10-06 00:04:27 -0700 | [diff] [blame] | 81 | return config_get_bool(*config, CONFIG_DEFAULT_SECTION, PTS_SECURE_ONLY_MODE, |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 82 | false); |
Nitin Arora | a0ee0f8 | 2016-03-11 12:26:51 -0800 | [diff] [blame] | 83 | } |
| 84 | |
Nitin Arora | 36ad41b | 2015-06-10 17:10:57 -0700 | [diff] [blame] | 85 | static bool get_pts_conn_updates_disabled(void) { |
Jakub Pawlowski | f3fb316 | 2017-10-06 00:04:27 -0700 | [diff] [blame] | 86 | return config_get_bool(*config, CONFIG_DEFAULT_SECTION, |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 87 | PTS_LE_CONN_UPDATED_DISABLED, false); |
Nitin Arora | 36ad41b | 2015-06-10 17:10:57 -0700 | [diff] [blame] | 88 | } |
| 89 | |
Nitin Arora | 4cdb0e5 | 2016-03-10 18:27:24 -0800 | [diff] [blame] | 90 | static bool get_pts_crosskey_sdp_disable(void) { |
Jakub Pawlowski | f3fb316 | 2017-10-06 00:04:27 -0700 | [diff] [blame] | 91 | return config_get_bool(*config, CONFIG_DEFAULT_SECTION, |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 92 | PTS_DISABLE_SDP_LE_PAIR, false); |
Nitin Arora | 4cdb0e5 | 2016-03-10 18:27:24 -0800 | [diff] [blame] | 93 | } |
| 94 | |
Jakub Pawlowski | f3fb316 | 2017-10-06 00:04:27 -0700 | [diff] [blame] | 95 | static const std::string* get_pts_smp_options(void) { |
| 96 | return config_get_string(*config, CONFIG_DEFAULT_SECTION, |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 97 | PTS_SMP_PAIRING_OPTIONS_KEY, NULL); |
Nitin Arora | 2aa2b80 | 2016-03-11 16:37:51 -0800 | [diff] [blame] | 98 | } |
| 99 | |
Nitin Arora | 0bd0c8f | 2016-03-15 15:00:36 -0700 | [diff] [blame] | 100 | static int get_pts_smp_failure_case(void) { |
Jakub Pawlowski | f3fb316 | 2017-10-06 00:04:27 -0700 | [diff] [blame] | 101 | return config_get_int(*config, CONFIG_DEFAULT_SECTION, |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 102 | PTS_SMP_FAILURE_CASE_KEY, 0); |
Nitin Arora | 0bd0c8f | 2016-03-15 15:00:36 -0700 | [diff] [blame] | 103 | } |
| 104 | |
Jakub Pawlowski | f3fb316 | 2017-10-06 00:04:27 -0700 | [diff] [blame] | 105 | static config_t* get_all(void) { return config.get(); } |
Zach Johnson | 9891f32 | 2014-09-22 22:11:55 -0700 | [diff] [blame] | 106 | |
Ajay Panicker | 99c3422 | 2017-04-17 20:53:24 -0700 | [diff] [blame] | 107 | const 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 Johnson | 9891f32 | 2014-09-22 22:11:55 -0700 | [diff] [blame] | 114 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 115 | const stack_config_t* stack_config_get_interface(void) { return &interface; } |