1 /****************************************************************************** 2 * 3 * Copyright (C) 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 <assert.h> 24 25 #include "osi/include/future.h" 26 #include "osi/include/log.h" 27 28 const char *BTSNOOP_LOG_PATH_KEY = "BtSnoopFileName"; 29 const char *BTSNOOP_TURNED_ON_KEY = "BtSnoopLogOutput"; 30 const char *BTSNOOP_SHOULD_SAVE_LAST_KEY = "BtSnoopSaveLog"; 31 const char *TRACE_CONFIG_ENABLED_KEY = "TraceConf"; 32 const char *PTS_SECURE_ONLY_MODE = "PTS_SecurePairOnly"; 33 const char *PTS_LE_CONN_UPDATED_DISABLED = "PTS_DisableConnUpdates"; 34 const char *PTS_DISABLE_SDP_LE_PAIR = "PTS_DisableSDPOnLEPair"; 35 const char *PTS_SMP_PAIRING_OPTIONS_KEY = "PTS_SmpOptions"; 36 const char *PTS_SMP_FAILURE_CASE_KEY = "PTS_SmpFailureCase"; 37 38 static config_t *config; 39 40 // Module lifecycle functions 41 42 static future_t *init() { 43 // TODO(armansito): Find a better way than searching by a hardcoded path. 44 #if defined(OS_GENERIC) 45 const char *path = "bt_stack.conf"; 46 #else // !defined(OS_GENERIC) 47 const char *path = "/etc/bluetooth/bt_stack.conf"; 48 #endif // defined(OS_GENERIC) 49 assert(path != NULL); 50 51 LOG_INFO(LOG_TAG, "%s attempt to load stack conf from %s", __func__, path); 52 53 config = config_new(path); 54 if (!config) { 55 LOG_INFO(LOG_TAG, "%s file >%s< not found", __func__, path); 56 return future_new_immediate(FUTURE_FAIL); 57 } 58 59 return future_new_immediate(FUTURE_SUCCESS); 60 } 61 62 static future_t *clean_up() { 63 config_free(config); 64 config = NULL; 65 return future_new_immediate(FUTURE_SUCCESS); 66 } 67 68 EXPORT_SYMBOL const module_t stack_config_module = { 69 .name = STACK_CONFIG_MODULE, 70 .init = init, 71 .start_up = NULL, 72 .shut_down = NULL, 73 .clean_up = clean_up, 74 .dependencies = { 75 NULL 76 } 77 }; 78 79 // Interface functions 80 81 static const char *get_btsnoop_log_path(void) { 82 return config_get_string(config, CONFIG_DEFAULT_SECTION, BTSNOOP_LOG_PATH_KEY, "/data/misc/bluedroid/btsnoop_hci.log"); 83 } 84 85 static bool get_btsnoop_turned_on(void) { 86 return config_get_bool(config, CONFIG_DEFAULT_SECTION, BTSNOOP_TURNED_ON_KEY, false); 87 } 88 89 static bool get_btsnoop_should_save_last(void) { 90 return config_get_bool(config, CONFIG_DEFAULT_SECTION, BTSNOOP_SHOULD_SAVE_LAST_KEY, false); 91 } 92 93 static bool get_trace_config_enabled(void) { 94 return config_get_bool(config, CONFIG_DEFAULT_SECTION, TRACE_CONFIG_ENABLED_KEY, false); 95 } 96 97 static bool get_pts_secure_only_mode(void) { 98 return config_get_bool(config, CONFIG_DEFAULT_SECTION, PTS_SECURE_ONLY_MODE, false); 99 } 100 101 static bool get_pts_conn_updates_disabled(void) { 102 return config_get_bool(config, CONFIG_DEFAULT_SECTION, PTS_LE_CONN_UPDATED_DISABLED, false); 103 } 104 105 static bool get_pts_crosskey_sdp_disable(void) { 106 return config_get_bool(config, CONFIG_DEFAULT_SECTION, PTS_DISABLE_SDP_LE_PAIR, false); 107 } 108 109 static const char *get_pts_smp_options(void) { 110 return config_get_string(config, CONFIG_DEFAULT_SECTION, PTS_SMP_PAIRING_OPTIONS_KEY, NULL); 111 } 112 113 static int get_pts_smp_failure_case(void) { 114 return config_get_int(config, CONFIG_DEFAULT_SECTION, PTS_SMP_FAILURE_CASE_KEY, 0); 115 } 116 117 static config_t *get_all(void) { 118 return config; 119 } 120 121 const stack_config_t interface = { 122 get_btsnoop_log_path, 123 get_btsnoop_turned_on, 124 get_btsnoop_should_save_last, 125 get_trace_config_enabled, 126 get_pts_secure_only_mode, 127 get_pts_conn_updates_disabled, 128 get_pts_crosskey_sdp_disable, 129 get_pts_smp_options, 130 get_pts_smp_failure_case, 131 get_all 132 }; 133 134 const stack_config_t *stack_config_get_interface() { 135 return &interface; 136 } 137