1 /*
2  * Copyright 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "os/parameter_provider.h"
18 
19 #include <unistd.h>
20 
21 #include <cerrno>
22 #include <mutex>
23 #include <string>
24 
25 namespace bluetooth {
26 namespace os {
27 
28 namespace {
29 std::mutex parameter_mutex;
30 std::string config_file_path;
31 std::string snoop_log_file_path;
32 std::string snooz_log_file_path;
33 std::string sysprops_file_path;
34 }  // namespace
35 
36 // Write to $PWD/bt_stack.conf if $PWD can be found, otherwise, write to $HOME/bt_stack.conf
ConfigFilePath()37 std::string ParameterProvider::ConfigFilePath() {
38   {
39     std::lock_guard<std::mutex> lock(parameter_mutex);
40     if (!config_file_path.empty()) {
41       return config_file_path;
42     }
43   }
44   return "/var/lib/bluetooth/bt_config.conf";
45 }
46 
OverrideConfigFilePath(const std::string & path)47 void ParameterProvider::OverrideConfigFilePath(const std::string& path) {
48   std::lock_guard<std::mutex> lock(parameter_mutex);
49   config_file_path = path;
50 }
51 
SnoopLogFilePath()52 std::string ParameterProvider::SnoopLogFilePath() {
53   {
54     std::lock_guard<std::mutex> lock(parameter_mutex);
55     if (!snoop_log_file_path.empty()) {
56       return snoop_log_file_path;
57     }
58   }
59 
60   return "/var/log/bluetooth/btsnoop_hci.log";
61 }
62 
OverrideSnoopLogFilePath(const std::string & path)63 void ParameterProvider::OverrideSnoopLogFilePath(const std::string& path) {
64   std::lock_guard<std::mutex> lock(parameter_mutex);
65   snoop_log_file_path = path;
66 }
67 
SnoozLogFilePath()68 std::string ParameterProvider::SnoozLogFilePath() {
69   {
70     std::lock_guard<std::mutex> lock(parameter_mutex);
71     if (!snooz_log_file_path.empty()) {
72       return snooz_log_file_path;
73     }
74   }
75   return "/var/log/bluetooth/btsnooz_hci.log";
76 }
77 
SyspropsFilePath()78 std::string ParameterProvider::SyspropsFilePath() {
79   {
80     std::lock_guard<std::mutex> lock(parameter_mutex);
81     if (!sysprops_file_path.empty()) {
82       return sysprops_file_path;
83     }
84   }
85   return "/var/lib/bluetooth/sysprops.conf";
86 }
87 
OverrideSyspropsFilePath(const std::string & path)88 void ParameterProvider::OverrideSyspropsFilePath(const std::string& path) {
89   std::lock_guard<std::mutex> lock(parameter_mutex);
90   sysprops_file_path = path;
91 }
92 
GetBtKeystoreInterface()93 bluetooth_keystore::BluetoothKeystoreInterface* ParameterProvider::GetBtKeystoreInterface() {
94   return nullptr;
95 }
96 
SetBtKeystoreInterface(bluetooth_keystore::BluetoothKeystoreInterface * bt_keystore)97 void ParameterProvider::SetBtKeystoreInterface(
98         bluetooth_keystore::BluetoothKeystoreInterface* bt_keystore) {}
99 
IsCommonCriteriaMode()100 bool ParameterProvider::IsCommonCriteriaMode() { return false; }
101 
SetCommonCriteriaMode(bool enable)102 void ParameterProvider::SetCommonCriteriaMode(bool enable) {}
103 
GetCommonCriteriaConfigCompareResult()104 int ParameterProvider::GetCommonCriteriaConfigCompareResult() { return 0b11; }
105 
SetCommonCriteriaConfigCompareResult(int result)106 void ParameterProvider::SetCommonCriteriaConfigCompareResult(int result) {}
107 
108 }  // namespace os
109 }  // namespace bluetooth
110