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 #include "os/log.h"
26 
27 namespace bluetooth {
28 namespace os {
29 
30 namespace {
31 std::mutex parameter_mutex;
32 std::string config_file_path;
33 std::string snoop_log_file_path;
34 std::string snooz_log_file_path;
35 std::string sysprops_file_path;
36 }  // namespace
37 
38 // Write to $PWD/bt_stack.conf if $PWD can be found, otherwise, write to $HOME/bt_stack.conf
ConfigFilePath()39 std::string ParameterProvider::ConfigFilePath() {
40   {
41     std::lock_guard<std::mutex> lock(parameter_mutex);
42     if (!config_file_path.empty()) {
43       return config_file_path;
44     }
45   }
46   return "/var/lib/bluetooth/bt_config.conf";
47 }
48 
OverrideConfigFilePath(const std::string & path)49 void ParameterProvider::OverrideConfigFilePath(const std::string& path) {
50   std::lock_guard<std::mutex> lock(parameter_mutex);
51   config_file_path = path;
52 }
53 
SnoopLogFilePath()54 std::string ParameterProvider::SnoopLogFilePath() {
55   {
56     std::lock_guard<std::mutex> lock(parameter_mutex);
57     if (!snoop_log_file_path.empty()) {
58       return snoop_log_file_path;
59     }
60   }
61 
62   return "/var/log/bluetooth/btsnoop_hci.log";
63 }
64 
OverrideSnoopLogFilePath(const std::string & path)65 void ParameterProvider::OverrideSnoopLogFilePath(const std::string& path) {
66   std::lock_guard<std::mutex> lock(parameter_mutex);
67   snoop_log_file_path = path;
68 }
69 
SnoozLogFilePath()70 std::string ParameterProvider::SnoozLogFilePath() {
71   {
72     std::lock_guard<std::mutex> lock(parameter_mutex);
73     if (!snooz_log_file_path.empty()) {
74       return snooz_log_file_path;
75     }
76   }
77   return "/var/log/bluetooth/btsnooz_hci.log";
78 }
79 
SyspropsFilePath()80 std::string ParameterProvider::SyspropsFilePath() {
81   {
82     std::lock_guard<std::mutex> lock(parameter_mutex);
83     if (!sysprops_file_path.empty()) {
84       return sysprops_file_path;
85     }
86   }
87   return "/var/lib/bluetooth/sysprops.conf";
88 }
89 
OverrideSyspropsFilePath(const std::string & path)90 void ParameterProvider::OverrideSyspropsFilePath(const std::string& path) {
91   std::lock_guard<std::mutex> lock(parameter_mutex);
92   sysprops_file_path = path;
93 }
94 
GetBtKeystoreInterface()95 bluetooth_keystore::BluetoothKeystoreInterface* ParameterProvider::GetBtKeystoreInterface() {
96   return nullptr;
97 }
98 
SetBtKeystoreInterface(bluetooth_keystore::BluetoothKeystoreInterface * bt_keystore)99 void ParameterProvider::SetBtKeystoreInterface(
100     bluetooth_keystore::BluetoothKeystoreInterface* bt_keystore) {}
101 
IsCommonCriteriaMode()102 bool ParameterProvider::IsCommonCriteriaMode() {
103   return false;
104 }
105 
SetCommonCriteriaMode(bool enable)106 void ParameterProvider::SetCommonCriteriaMode(bool enable) {}
107 
GetCommonCriteriaConfigCompareResult()108 int ParameterProvider::GetCommonCriteriaConfigCompareResult() {
109   return 0b11;
110 }
111 
SetCommonCriteriaConfigCompareResult(int result)112 void ParameterProvider::SetCommonCriteriaConfigCompareResult(int result) {}
113 
114 }  // namespace os
115 }  // namespace bluetooth
116