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 "security_manager.h"
19 
20 #include "os/log.h"
21 
22 namespace bluetooth {
23 namespace security {
24 
25 // Definition of Pure Virtual Destructor
~ISecurityManagerListener()26 ISecurityManagerListener::~ISecurityManagerListener() {}
27 
Init()28 void SecurityManager::Init() {
29   security_handler_->Post(
30       common::BindOnce(&internal::SecurityManagerImpl::Init, common::Unretained(security_manager_impl_)));
31 }
32 
CreateBond(hci::AddressWithType device)33 void SecurityManager::CreateBond(hci::AddressWithType device) {
34   security_handler_->Post(common::BindOnce(&internal::SecurityManagerImpl::CreateBond,
35                                            common::Unretained(security_manager_impl_),
36                                            std::forward<hci::AddressWithType>(device)));
37 }
38 
CreateBondLe(hci::AddressWithType device)39 void SecurityManager::CreateBondLe(hci::AddressWithType device) {
40   security_handler_->Post(common::BindOnce(&internal::SecurityManagerImpl::CreateBondLe,
41                                            common::Unretained(security_manager_impl_),
42                                            std::forward<hci::AddressWithType>(device)));
43 }
44 
CancelBond(hci::AddressWithType device)45 void SecurityManager::CancelBond(hci::AddressWithType device) {
46   security_handler_->Post(common::BindOnce(&internal::SecurityManagerImpl::CancelBond,
47                                            common::Unretained(security_manager_impl_),
48                                            std::forward<hci::AddressWithType>(device)));
49 }
50 
RemoveBond(hci::AddressWithType device)51 void SecurityManager::RemoveBond(hci::AddressWithType device) {
52   security_handler_->Post(common::BindOnce(&internal::SecurityManagerImpl::RemoveBond,
53                                            common::Unretained(security_manager_impl_),
54                                            std::forward<hci::AddressWithType>(device)));
55 }
56 
SetUserInterfaceHandler(UI * user_interface,os::Handler * handler)57 void SecurityManager::SetUserInterfaceHandler(UI* user_interface, os::Handler* handler) {
58   security_handler_->Post(common::BindOnce(&internal::SecurityManagerImpl::SetUserInterfaceHandler,
59                                            common::Unretained(security_manager_impl_), user_interface, handler));
60 }
61 
62 // TODO(jpawlowski): remove once we have config file abstraction in cert tests
SetLeInitiatorAddressPolicyForTest(hci::LeAddressManager::AddressPolicy address_policy,hci::AddressWithType fixed_address,crypto_toolbox::Octet16 rotation_irk,std::chrono::milliseconds minimum_rotation_time,std::chrono::milliseconds maximum_rotation_time)63 void SecurityManager::SetLeInitiatorAddressPolicyForTest(
64     hci::LeAddressManager::AddressPolicy address_policy,
65     hci::AddressWithType fixed_address,
66     crypto_toolbox::Octet16 rotation_irk,
67     std::chrono::milliseconds minimum_rotation_time,
68     std::chrono::milliseconds maximum_rotation_time) {
69   security_handler_->Post(common::BindOnce(
70       &internal::SecurityManagerImpl::SetLeInitiatorAddressPolicyForTest,
71       common::Unretained(security_manager_impl_),
72       address_policy,
73       fixed_address,
74       rotation_irk,
75       minimum_rotation_time,
76       maximum_rotation_time));
77 }
78 
RegisterCallbackListener(ISecurityManagerListener * listener,os::Handler * handler)79 void SecurityManager::RegisterCallbackListener(ISecurityManagerListener* listener, os::Handler* handler) {
80   security_handler_->Post(common::BindOnce(&internal::SecurityManagerImpl::RegisterCallbackListener,
81                                            common::Unretained(security_manager_impl_), listener, handler));
82 }
83 
UnregisterCallbackListener(ISecurityManagerListener * listener)84 void SecurityManager::UnregisterCallbackListener(ISecurityManagerListener* listener) {
85   security_handler_->Post(common::BindOnce(&internal::SecurityManagerImpl::UnregisterCallbackListener,
86                                            common::Unretained(security_manager_impl_), listener));
87 }
88 
OnPairingPromptAccepted(const bluetooth::hci::AddressWithType & address,bool confirmed)89 void SecurityManager::OnPairingPromptAccepted(const bluetooth::hci::AddressWithType& address, bool confirmed) {
90   security_handler_->Post(common::BindOnce(&internal::SecurityManagerImpl::OnPairingPromptAccepted,
91                                            common::Unretained(security_manager_impl_), address, confirmed));
92 }
OnConfirmYesNo(const bluetooth::hci::AddressWithType & address,bool confirmed)93 void SecurityManager::OnConfirmYesNo(const bluetooth::hci::AddressWithType& address, bool confirmed) {
94   security_handler_->Post(common::BindOnce(&internal::SecurityManagerImpl::OnConfirmYesNo,
95                                            common::Unretained(security_manager_impl_), address, confirmed));
96 }
OnPasskeyEntry(const bluetooth::hci::AddressWithType & address,uint32_t passkey)97 void SecurityManager::OnPasskeyEntry(const bluetooth::hci::AddressWithType& address, uint32_t passkey) {
98   security_handler_->Post(common::BindOnce(&internal::SecurityManagerImpl::OnPasskeyEntry,
99                                            common::Unretained(security_manager_impl_), address, passkey));
100 }
101 
102 }  // namespace security
103 }  // namespace bluetooth
104