• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <private/android_filesystem_config.h>
20 #include <unistd.h>
21 
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 bluetooth_keystore::BluetoothKeystoreInterface* bt_keystore_interface = nullptr;
34 bool is_common_criteria_mode = false;
35 int common_criteria_config_compare_result = 0b11;
36 }  // namespace
37 
38 // On Android we always write a single default location
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 "/data/misc/bluedroid/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   return "/data/misc/bluetooth/logs/btsnoop_hci.log";
62 }
63 
OverrideSnoopLogFilePath(const std::string & path)64 void ParameterProvider::OverrideSnoopLogFilePath(const std::string& path) {
65   std::lock_guard<std::mutex> lock(parameter_mutex);
66   snoop_log_file_path = path;
67 }
68 
69 // Return the path to the default snooz log file location
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 "/data/misc/bluetooth/logs/btsnooz_hci.log";
78 }
79 
OverrideSnoozLogFilePath(const std::string & path)80 void ParameterProvider::OverrideSnoozLogFilePath(const std::string& path) {
81   std::lock_guard<std::mutex> lock(parameter_mutex);
82   snooz_log_file_path = path;
83 }
84 
GetBtKeystoreInterface()85 bluetooth_keystore::BluetoothKeystoreInterface* ParameterProvider::GetBtKeystoreInterface() {
86   std::lock_guard<std::mutex> lock(parameter_mutex);
87   return bt_keystore_interface;
88 }
89 
SetBtKeystoreInterface(bluetooth_keystore::BluetoothKeystoreInterface * bt_keystore)90 void ParameterProvider::SetBtKeystoreInterface(bluetooth_keystore::BluetoothKeystoreInterface* bt_keystore) {
91   std::lock_guard<std::mutex> lock(parameter_mutex);
92   bt_keystore_interface = bt_keystore;
93 }
94 
IsCommonCriteriaMode()95 bool ParameterProvider::IsCommonCriteriaMode() {
96   std::lock_guard<std::mutex> lock(parameter_mutex);
97   return (getuid() == AID_BLUETOOTH) && is_common_criteria_mode;
98 }
99 
SetCommonCriteriaMode(bool enable)100 void ParameterProvider::SetCommonCriteriaMode(bool enable) {
101   std::lock_guard<std::mutex> lock(parameter_mutex);
102   is_common_criteria_mode = enable;
103 }
104 
GetCommonCriteriaConfigCompareResult()105 int ParameterProvider::GetCommonCriteriaConfigCompareResult() {
106   std::lock_guard<std::mutex> lock(parameter_mutex);
107   return common_criteria_config_compare_result;
108 }
109 
SetCommonCriteriaConfigCompareResult(int result)110 void ParameterProvider::SetCommonCriteriaConfigCompareResult(int result) {
111   std::lock_guard<std::mutex> lock(parameter_mutex);
112   common_criteria_config_compare_result = result;
113 }
114 
115 }  // namespace os
116 }  // namespace bluetooth