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 
SetDisconnectCallback(internal::SecurityManagerImpl::FacadeDisconnectCallback callback)27 void FacadeConfigurationApi::SetDisconnectCallback(internal::SecurityManagerImpl::FacadeDisconnectCallback callback) {
28   security_handler_->CallOn(security_manager_impl_, &internal::SecurityManagerImpl::SetDisconnectCallback, callback);
29 }
30 
SetIoCapability(hci::IoCapability io_capability)31 void FacadeConfigurationApi::SetIoCapability(hci::IoCapability io_capability) {
32   security_handler_->CallOn(security_manager_impl_, &internal::SecurityManagerImpl::SetIoCapability, io_capability);
33 }
34 
SetAuthenticationRequirements(hci::AuthenticationRequirements authentication_requirement)35 void FacadeConfigurationApi::SetAuthenticationRequirements(hci::AuthenticationRequirements authentication_requirement) {
36   security_handler_->CallOn(
37       security_manager_impl_,
38       &internal::SecurityManagerImpl::SetAuthenticationRequirements,
39       authentication_requirement);
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 
SetLeMaximumEncryptionKeySize(uint8_t maximum_encryption_key_size)50 void FacadeConfigurationApi::SetLeMaximumEncryptionKeySize(uint8_t maximum_encryption_key_size) {
51   security_handler_->CallOn(
52       security_manager_impl_,
53       &internal::SecurityManagerImpl::SetLeMaximumEncryptionKeySize,
54       maximum_encryption_key_size);
55 }
56 
SetLeOobDataPresent(OobDataFlag oob_present)57 void FacadeConfigurationApi::SetLeOobDataPresent(OobDataFlag oob_present) {
58   security_handler_->CallOn(security_manager_impl_, &internal::SecurityManagerImpl::SetLeOobDataPresent, oob_present);
59 }
60 
GetLeOutOfBandData(std::array<uint8_t,16> * confirmation_value,std::array<uint8_t,16> * random_value)61 void FacadeConfigurationApi::GetLeOutOfBandData(
62     std::array<uint8_t, 16>* confirmation_value, std::array<uint8_t, 16>* random_value) {
63   security_manager_impl_->GetLeOutOfBandData(confirmation_value, random_value);
64 }
65 
SetOutOfBandData(hci::AddressWithType remote_address,std::array<uint8_t,16> confirmation_value,std::array<uint8_t,16> random_value)66 void FacadeConfigurationApi::SetOutOfBandData(
67     hci::AddressWithType remote_address,
68     std::array<uint8_t, 16> confirmation_value,
69     std::array<uint8_t, 16> random_value) {
70   security_handler_->CallOn(
71       security_manager_impl_,
72       &internal::SecurityManagerImpl::SetOutOfBandData,
73       remote_address,
74       confirmation_value,
75       random_value);
76 }
77 
EnforceSecurityPolicy(hci::AddressWithType remote,l2cap::classic::SecurityPolicy policy,l2cap::classic::SecurityEnforcementInterface::ResultCallback callback)78 void FacadeConfigurationApi::EnforceSecurityPolicy(
79     hci::AddressWithType remote,
80     l2cap::classic::SecurityPolicy policy,
81     l2cap::classic::SecurityEnforcementInterface::ResultCallback callback) {
82   security_handler_->CallOn(
83       security_manager_impl_,
84       &internal::SecurityManagerImpl::EnforceSecurityPolicy,
85       remote,
86       policy,
87       std::move(callback));
88 }
89 
90 }  // namespace security
91 }  // namespace bluetooth
92