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 "hci/octets.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
CreateBondOutOfBand(hci::AddressWithType device,pairing::OobData remote_p192_oob_data,pairing::OobData remote_p256_oob_data)39 void SecurityManager::CreateBondOutOfBand(
40 hci::AddressWithType device, pairing::OobData remote_p192_oob_data, pairing::OobData remote_p256_oob_data) {
41 security_handler_->Post(common::BindOnce(
42 &internal::SecurityManagerImpl::CreateBondOutOfBand,
43 common::Unretained(security_manager_impl_),
44 std::forward<hci::AddressWithType>(device),
45 remote_p192_oob_data,
46 remote_p256_oob_data));
47 }
48
GetOutOfBandData(channel::SecurityCommandStatusCallback callback)49 void SecurityManager::GetOutOfBandData(channel::SecurityCommandStatusCallback callback) {
50 security_handler_->Post(common::BindOnce(
51 &internal::SecurityManagerImpl::GetOutOfBandData,
52 common::Unretained(security_manager_impl_),
53 std::forward<channel::SecurityCommandStatusCallback>(callback)));
54 }
55
CreateBondLe(hci::AddressWithType device)56 void SecurityManager::CreateBondLe(hci::AddressWithType device) {
57 security_handler_->Post(common::BindOnce(&internal::SecurityManagerImpl::CreateBondLe,
58 common::Unretained(security_manager_impl_),
59 std::forward<hci::AddressWithType>(device)));
60 }
61
CancelBond(hci::AddressWithType device)62 void SecurityManager::CancelBond(hci::AddressWithType device) {
63 security_handler_->Post(common::BindOnce(&internal::SecurityManagerImpl::CancelBond,
64 common::Unretained(security_manager_impl_),
65 std::forward<hci::AddressWithType>(device)));
66 }
67
RemoveBond(hci::AddressWithType device)68 void SecurityManager::RemoveBond(hci::AddressWithType device) {
69 security_handler_->Post(common::BindOnce(&internal::SecurityManagerImpl::RemoveBond,
70 common::Unretained(security_manager_impl_),
71 std::forward<hci::AddressWithType>(device)));
72 }
73
SetUserInterfaceHandler(UI * user_interface,os::Handler * handler)74 void SecurityManager::SetUserInterfaceHandler(UI* user_interface, os::Handler* handler) {
75 security_handler_->Post(common::BindOnce(&internal::SecurityManagerImpl::SetUserInterfaceHandler,
76 common::Unretained(security_manager_impl_), user_interface, handler));
77 }
78
79 // TODO(jpawlowski): remove once we have config file abstraction in cert tests
SetLeInitiatorAddressPolicyForTest(hci::LeAddressManager::AddressPolicy address_policy,hci::AddressWithType fixed_address,hci::Octet16 rotation_irk,std::chrono::milliseconds minimum_rotation_time,std::chrono::milliseconds maximum_rotation_time)80 void SecurityManager::SetLeInitiatorAddressPolicyForTest(
81 hci::LeAddressManager::AddressPolicy address_policy,
82 hci::AddressWithType fixed_address,
83 hci::Octet16 rotation_irk,
84 std::chrono::milliseconds minimum_rotation_time,
85 std::chrono::milliseconds maximum_rotation_time) {
86 security_handler_->Post(common::BindOnce(
87 &internal::SecurityManagerImpl::SetLeInitiatorAddressPolicyForTest,
88 common::Unretained(security_manager_impl_),
89 address_policy,
90 fixed_address,
91 rotation_irk,
92 minimum_rotation_time,
93 maximum_rotation_time));
94 }
95
RegisterCallbackListener(ISecurityManagerListener * listener,os::Handler * handler)96 void SecurityManager::RegisterCallbackListener(ISecurityManagerListener* listener, os::Handler* handler) {
97 security_handler_->Post(common::BindOnce(&internal::SecurityManagerImpl::RegisterCallbackListener,
98 common::Unretained(security_manager_impl_), listener, handler));
99 }
100
UnregisterCallbackListener(ISecurityManagerListener * listener)101 void SecurityManager::UnregisterCallbackListener(ISecurityManagerListener* listener) {
102 security_handler_->Post(common::BindOnce(&internal::SecurityManagerImpl::UnregisterCallbackListener,
103 common::Unretained(security_manager_impl_), listener));
104 }
105
OnPairingPromptAccepted(const bluetooth::hci::AddressWithType & address,bool confirmed)106 void SecurityManager::OnPairingPromptAccepted(const bluetooth::hci::AddressWithType& address, bool confirmed) {
107 security_handler_->Post(common::BindOnce(&internal::SecurityManagerImpl::OnPairingPromptAccepted,
108 common::Unretained(security_manager_impl_), address, confirmed));
109 }
110
OnConfirmYesNo(const bluetooth::hci::AddressWithType & address,bool confirmed)111 void SecurityManager::OnConfirmYesNo(const bluetooth::hci::AddressWithType& address, bool confirmed) {
112 security_handler_->Post(common::BindOnce(&internal::SecurityManagerImpl::OnConfirmYesNo,
113 common::Unretained(security_manager_impl_), address, confirmed));
114 }
115
OnPasskeyEntry(const bluetooth::hci::AddressWithType & address,uint32_t passkey)116 void SecurityManager::OnPasskeyEntry(const bluetooth::hci::AddressWithType& address, uint32_t passkey) {
117 security_handler_->Post(common::BindOnce(&internal::SecurityManagerImpl::OnPasskeyEntry,
118 common::Unretained(security_manager_impl_), address, passkey));
119 }
120
OnPinEntry(const bluetooth::hci::AddressWithType & address,std::vector<uint8_t> pin)121 void SecurityManager::OnPinEntry(const bluetooth::hci::AddressWithType& address, std::vector<uint8_t> pin) {
122 security_handler_->Post(common::BindOnce(
123 &internal::SecurityManagerImpl::OnPinEntry, common::Unretained(security_manager_impl_), address, std::move(pin)));
124 }
125
126 } // namespace security
127 } // namespace bluetooth
128