1 /*
2  *
3  *  Copyright 2019 The Android Open Source Project
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 #include "facade_configuration_api.h"
19 
20 #include "common/bind.h"
21 #include "l2cap/classic/security_enforcement_interface.h"
22 #include "os/log.h"
23 
24 namespace bluetooth {
25 namespace security {
26 
SetIoCapability(hci::IoCapability io_capability)27 void FacadeConfigurationApi::SetIoCapability(hci::IoCapability io_capability) {
28   security_handler_->CallOn(security_manager_impl_, &internal::SecurityManagerImpl::SetIoCapability, io_capability);
29 }
30 
SetAuthenticationRequirements(hci::AuthenticationRequirements authentication_requirement)31 void FacadeConfigurationApi::SetAuthenticationRequirements(hci::AuthenticationRequirements authentication_requirement) {
32   security_handler_->CallOn(
33       security_manager_impl_,
34       &internal::SecurityManagerImpl::SetAuthenticationRequirements,
35       authentication_requirement);
36 }
37 
SetOobDataPresent(hci::OobDataPresent data_present)38 void FacadeConfigurationApi::SetOobDataPresent(hci::OobDataPresent data_present) {
39   security_handler_->CallOn(security_manager_impl_, &internal::SecurityManagerImpl::SetOobDataPresent, data_present);
40 }
41 
SetLeIoCapability(security::IoCapability io_capability)42 void FacadeConfigurationApi::SetLeIoCapability(security::IoCapability io_capability) {
43   security_handler_->CallOn(security_manager_impl_, &internal::SecurityManagerImpl::SetLeIoCapability, io_capability);
44 }
45 
SetLeAuthRequirements(uint8_t auth_req)46 void FacadeConfigurationApi::SetLeAuthRequirements(uint8_t auth_req) {
47   security_handler_->CallOn(security_manager_impl_, &internal::SecurityManagerImpl::SetLeAuthRequirements, auth_req);
48 }
49 
SetLeOobDataPresent(OobDataFlag oob_present)50 void FacadeConfigurationApi::SetLeOobDataPresent(OobDataFlag oob_present) {
51   security_handler_->CallOn(security_manager_impl_, &internal::SecurityManagerImpl::SetLeOobDataPresent, oob_present);
52 }
53 
GetOutOfBandData(std::array<uint8_t,16> * le_sc_confirmation_value,std::array<uint8_t,16> * le_sc_random_value)54 void FacadeConfigurationApi::GetOutOfBandData(
55     std::array<uint8_t, 16>* le_sc_confirmation_value, std::array<uint8_t, 16>* le_sc_random_value) {
56   security_manager_impl_->GetOutOfBandData(le_sc_confirmation_value, le_sc_random_value);
57 }
58 
SetOutOfBandData(hci::AddressWithType remote_address,std::array<uint8_t,16> le_sc_confirmation_value,std::array<uint8_t,16> le_sc_random_value)59 void FacadeConfigurationApi::SetOutOfBandData(
60     hci::AddressWithType remote_address,
61     std::array<uint8_t, 16> le_sc_confirmation_value,
62     std::array<uint8_t, 16> le_sc_random_value) {
63   security_handler_->CallOn(
64       security_manager_impl_,
65       &internal::SecurityManagerImpl::SetOutOfBandData,
66       remote_address,
67       le_sc_confirmation_value,
68       le_sc_random_value);
69 }
70 
EnforceSecurityPolicy(hci::AddressWithType remote,l2cap::classic::SecurityPolicy policy,l2cap::classic::SecurityEnforcementInterface::ResultCallback callback)71 void FacadeConfigurationApi::EnforceSecurityPolicy(
72     hci::AddressWithType remote,
73     l2cap::classic::SecurityPolicy policy,
74     l2cap::classic::SecurityEnforcementInterface::ResultCallback callback) {
75   security_handler_->CallOn(
76       security_manager_impl_,
77       &internal::SecurityManagerImpl::EnforceSecurityPolicy,
78       remote,
79       policy,
80       std::move(callback));
81 }
82 
83 }  // namespace security
84 }  // namespace bluetooth
85