1 /*
2  * Copyright 2021 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 <cstdint>
18 #include <future>
19 #include <memory>
20 #include <optional>
21 #include <string>
22 
23 #include "hci/acl_manager.h"
24 #include "hci/acl_manager/classic_acl_connection.h"
25 #include "hci/acl_manager/le_acl_connection.h"
26 #include "hci/address.h"
27 #include "hci/address_with_type.h"
28 #include "hci/class_of_device.h"
29 #include "main/shim/acl.h"
30 #include "main/shim/entry.h"
31 #include "os/handler.h"
32 #include "stack/acl/acl.h"
33 #include "test/common/mock_functions.h"
34 #include "types/raw_address.h"
35 
36 using namespace bluetooth;
37 
DumpsysL2cap(int)38 void DumpsysL2cap(int /* fd */) { inc_func_call_count(__func__); }
39 
DumpsysAcl(int)40 void DumpsysAcl(int /* fd */) { inc_func_call_count(__func__); }
41 
DumpsysBtm(int)42 void DumpsysBtm(int /* fd */) { inc_func_call_count(__func__); }
43 
DumpsysRecord(int)44 void DumpsysRecord(int /* fd */) { inc_func_call_count(__func__); }
45 
DumpsysNeighbor(int)46 void DumpsysNeighbor(int /* fd */) { inc_func_call_count(__func__); }
47 
Dump(int) const48 void shim::legacy::Acl::Dump(int /* fd */) const {
49   inc_func_call_count(__func__);
50 }
51 
Acl(os::Handler *,const acl_interface_t & acl_interface,uint8_t,uint8_t)52 shim::legacy::Acl::Acl(os::Handler* /* handler */,
53                        const acl_interface_t& acl_interface,
54                        uint8_t /* max_acceptlist_size */,
55                        uint8_t /* max_address_resolution_size */)
56     : acl_interface_(acl_interface) {
57   inc_func_call_count(__func__);
58 }
~Acl()59 shim::legacy::Acl::~Acl() { inc_func_call_count(__func__); }
60 
CheckForOrphanedAclConnections() const61 bool shim::legacy::Acl::CheckForOrphanedAclConnections() const {
62   inc_func_call_count(__func__);
63   return false;
64 }
65 
on_incoming_acl_credits(uint16_t,uint16_t)66 void shim::legacy::Acl::on_incoming_acl_credits(uint16_t /* handle */,
67                                                 uint16_t /* credits */) {
68   inc_func_call_count(__func__);
69 }
70 
71 using HciHandle = uint16_t;
72 
73 struct shim::legacy::Acl::impl {};
74 
CreateClassicConnection(const hci::Address &)75 void shim::legacy::Acl::CreateClassicConnection(
76     const hci::Address& /* address */) {
77   inc_func_call_count(__func__);
78 }
79 
CancelClassicConnection(const hci::Address &)80 void shim::legacy::Acl::CancelClassicConnection(
81     const hci::Address& /* address */) {
82   inc_func_call_count(__func__);
83 }
84 
AcceptLeConnectionFrom(const hci::AddressWithType &,bool,std::promise<bool>)85 void shim::legacy::Acl::AcceptLeConnectionFrom(
86     const hci::AddressWithType& /* address_with_type */, bool /* is_direct */,
87     std::promise<bool> /* promise */) {
88   inc_func_call_count(__func__);
89 }
90 
IgnoreLeConnectionFrom(const hci::AddressWithType &)91 void shim::legacy::Acl::IgnoreLeConnectionFrom(
92     const hci::AddressWithType& /* address_with_type */) {
93   inc_func_call_count(__func__);
94 }
95 
OnClassicLinkDisconnected(HciHandle,hci::ErrorCode)96 void bluetooth::shim::legacy::Acl::OnClassicLinkDisconnected(
97     HciHandle /* handle */, hci::ErrorCode /* reason */) {
98   inc_func_call_count(__func__);
99 }
100 
GetConnectionLocalAddress(uint16_t,bool)101 bluetooth::hci::AddressWithType shim::legacy::Acl::GetConnectionLocalAddress(
102     uint16_t /* handle */, bool /* ota_address */) {
103   inc_func_call_count(__func__);
104   return hci::AddressWithType();
105 }
GetConnectionPeerAddress(uint16_t,bool)106 bluetooth::hci::AddressWithType shim::legacy::Acl::GetConnectionPeerAddress(
107     uint16_t /* handle */, bool /* ota_address */) {
108   inc_func_call_count(__func__);
109   return hci::AddressWithType();
110 }
111 
GetAdvertisingSetConnectedTo(const RawAddress &)112 std::optional<uint8_t> shim::legacy::Acl::GetAdvertisingSetConnectedTo(
113     const RawAddress& /* remote_bda */) {
114   inc_func_call_count(__func__);
115   return std::nullopt;
116   ;
117 }
118 
OnLeLinkDisconnected(HciHandle,hci::ErrorCode)119 void shim::legacy::Acl::OnLeLinkDisconnected(HciHandle /* handle */,
120                                              hci::ErrorCode /* reason */) {
121   inc_func_call_count(__func__);
122 }
123 
OnConnectSuccess(std::unique_ptr<hci::acl_manager::ClassicAclConnection>)124 void shim::legacy::Acl::OnConnectSuccess(
125     std::unique_ptr<hci::acl_manager::ClassicAclConnection> /* connection */) {
126   inc_func_call_count(__func__);
127 }
128 
OnConnectRequest(hci::Address,hci::ClassOfDevice)129 void shim::legacy::Acl::OnConnectRequest(hci::Address /* address */,
130                                          hci::ClassOfDevice /* cod */) {
131   inc_func_call_count(__func__);
132 }
OnConnectFail(hci::Address,hci::ErrorCode,bool)133 void shim::legacy::Acl::OnConnectFail(hci::Address /* address */,
134                                       hci::ErrorCode /* reason */,
135                                       bool /* locally_initiated */) {
136   inc_func_call_count(__func__);
137 }
138 
OnLeConnectSuccess(hci::AddressWithType,std::unique_ptr<hci::acl_manager::LeAclConnection>)139 void shim::legacy::Acl::OnLeConnectSuccess(
140     hci::AddressWithType /* address_with_type */,
141     std::unique_ptr<hci::acl_manager::LeAclConnection> /* connection */) {
142   inc_func_call_count(__func__);
143 }
144 
OnLeConnectFail(hci::AddressWithType,hci::ErrorCode)145 void shim::legacy::Acl::OnLeConnectFail(
146     hci::AddressWithType /* address_with_type */, hci::ErrorCode /* reason */) {
147   inc_func_call_count(__func__);
148 }
149 
DisconnectClassic(uint16_t,tHCI_STATUS,std::string)150 void shim::legacy::Acl::DisconnectClassic(uint16_t /* handle */,
151                                           tHCI_STATUS /* reason */,
152                                           std::string /* comment */) {
153   inc_func_call_count(__func__);
154 }
155 
DisconnectLe(uint16_t,tHCI_STATUS,std::string)156 void shim::legacy::Acl::DisconnectLe(uint16_t /* handle */,
157                                      tHCI_STATUS /* reason */,
158                                      std::string /* comment */) {
159   inc_func_call_count(__func__);
160 }
161 
LeSetDefaultSubrate(uint16_t,uint16_t,uint16_t,uint16_t,uint16_t)162 void shim::legacy::Acl::LeSetDefaultSubrate(uint16_t /* subrate_min */,
163                                             uint16_t /* subrate_max */,
164                                             uint16_t /* max_latency */,
165                                             uint16_t /* cont_num */,
166                                             uint16_t /* sup_tout */) {
167   inc_func_call_count(__func__);
168 }
169 
LeSubrateRequest(uint16_t,uint16_t,uint16_t,uint16_t,uint16_t,uint16_t)170 void shim::legacy::Acl::LeSubrateRequest(uint16_t /* hci_handle */,
171                                          uint16_t /* subrate_min */,
172                                          uint16_t /* subrate_max */,
173                                          uint16_t /* max_latency */,
174                                          uint16_t /* cont_num */,
175                                          uint16_t /* sup_tout */) {
176   inc_func_call_count(__func__);
177 }
178 
DumpConnectionHistory(int) const179 void shim::legacy::Acl::DumpConnectionHistory(int /* fd */) const {
180   inc_func_call_count(__func__);
181 }
182 
DisconnectAllForSuspend()183 void shim::legacy::Acl::DisconnectAllForSuspend() {
184   inc_func_call_count(__func__);
185 }
186 
Shutdown()187 void shim::legacy::Acl::Shutdown() { inc_func_call_count(__func__); }
188 
FinalShutdown()189 void shim::legacy::Acl::FinalShutdown() { inc_func_call_count(__func__); }
190 
ClearFilterAcceptList()191 void shim::legacy::Acl::ClearFilterAcceptList() {
192   inc_func_call_count(__func__);
193 }
194 
AddToAddressResolution(const hci::AddressWithType &,const std::array<uint8_t,16> &,const std::array<uint8_t,16> &)195 void shim::legacy::Acl::AddToAddressResolution(
196     const hci::AddressWithType& /* address_with_type */,
197     const std::array<uint8_t, 16>& /* peer_irk */,
198     const std::array<uint8_t, 16>& /* local_irk */) {
199   inc_func_call_count(__func__);
200 }
201 
RemoveFromAddressResolution(const hci::AddressWithType &)202 void shim::legacy::Acl::RemoveFromAddressResolution(
203     const hci::AddressWithType& /* address_with_type */) {
204   inc_func_call_count(__func__);
205 }
206 
ClearAddressResolution()207 void shim::legacy::Acl::ClearAddressResolution() {
208   inc_func_call_count(__func__);
209 }
210 
SetSystemSuspendState(bool)211 void shim::legacy::Acl::SetSystemSuspendState(bool /* suspended */) {
212   inc_func_call_count(__func__);
213 }
214 
UpdateConnectionParameters(uint16_t,uint16_t,uint16_t,uint16_t,uint16_t,uint16_t,uint16_t)215 void shim::legacy::Acl::UpdateConnectionParameters(uint16_t /* handle */,
216                                                    uint16_t /* conn_int_min */,
217                                                    uint16_t /* conn_int_max */,
218                                                    uint16_t /* conn_latency */,
219                                                    uint16_t /* conn_timeout */,
220                                                    uint16_t /* min_ce_len */,
221                                                    uint16_t /* max_ce_len */) {
222   inc_func_call_count(__func__);
223 }
224