1 /* 2 * Copyright 2020 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 #pragma once 18 19 #include <future> 20 #include <memory> 21 22 #include "hci/acl_manager/connection_callbacks.h" 23 #include "hci/acl_manager/le_connection_callbacks.h" 24 #include "hci/address.h" 25 #include "hci/address_with_type.h" 26 #include "hci/class_of_device.h" 27 #include "main/shim/acl_interface.h" 28 #include "os/handler.h" 29 #include "packet/raw_builder.h" 30 #include "types/raw_address.h" 31 32 void DumpsysAcl(int fd); 33 void DumpsysNeighbor(int fd); 34 35 namespace bluetooth { 36 namespace shim { 37 38 class Acl : public hci::acl_manager::ConnectionCallbacks, 39 public hci::acl_manager::LeConnectionCallbacks { 40 public: 41 Acl(os::Handler* handler, const acl_interface_t& acl_interface, 42 uint8_t max_address_resolution_size); 43 44 Acl(const Acl&) = delete; 45 Acl& operator=(const Acl&) = delete; 46 47 ~Acl(); 48 49 // hci::acl_manager::ConnectionCallbacks 50 void OnConnectSuccess(std::unique_ptr<hci::acl_manager::ClassicAclConnection>) override; 51 void OnConnectRequest(hci::Address, hci::ClassOfDevice) override; 52 void OnConnectFail(hci::Address, hci::ErrorCode reason, bool locally_initiated) override; 53 54 void OnClassicLinkDisconnected(uint16_t handle, hci::ErrorCode reason); 55 56 // hci::acl_manager::LeConnectionCallbacks 57 void OnLeConnectSuccess(hci::AddressWithType, 58 std::unique_ptr<hci::acl_manager::LeAclConnection>) override; 59 void OnLeConnectFail(hci::AddressWithType, hci::ErrorCode reason) override; 60 void OnLeLinkDisconnected(uint16_t handle, hci::ErrorCode reason); 61 void GetConnectionLocalAddress(uint16_t handle, bool ota_address, 62 std::promise<bluetooth::hci::AddressWithType> promise); 63 void GetConnectionPeerAddress(uint16_t handle, bool ota_address, 64 std::promise<bluetooth::hci::AddressWithType> promise); 65 void GetAdvertisingSetConnectedTo(const RawAddress& remote_bda, 66 std::promise<std::optional<uint8_t>> promise); 67 68 void CreateClassicConnection(const hci::Address& address); 69 void CancelClassicConnection(const hci::Address& address); 70 void DisconnectClassic(uint16_t handle, tHCI_REASON reason, std::string comment); 71 void DisconnectLe(uint16_t handle, tHCI_REASON reason, std::string comment); 72 void UpdateConnectionParameters(uint16_t handle, uint16_t conn_int_min, uint16_t conn_int_max, 73 uint16_t conn_latency, uint16_t conn_timeout, uint16_t min_ce_len, 74 uint16_t max_ce_len); 75 76 // Address Resolution List 77 void AddToAddressResolution(const hci::AddressWithType& address_with_type, 78 const std::array<uint8_t, 16>& peer_irk, 79 const std::array<uint8_t, 16>& local_irk); 80 void RemoveFromAddressResolution(const hci::AddressWithType& address_with_type); 81 void ClearAddressResolution(); 82 83 void LeSubrateRequest(uint16_t hci_handle, uint16_t subrate_min, uint16_t subrate_max, 84 uint16_t max_latency, uint16_t cont_num, uint16_t sup_tout); 85 86 void WriteData(uint16_t hci_handle, std::unique_ptr<packet::RawBuilder> packet); 87 88 void Flush(uint16_t hci_handle); 89 90 void Dump(int fd) const; 91 void DumpConnectionHistory(int fd) const; 92 93 void Shutdown(); 94 void FinalShutdown(); 95 96 void ClearFilterAcceptList(); 97 void DisconnectAllForSuspend(); 98 void SetSystemSuspendState(bool suspended); 99 100 protected: 101 void on_incoming_acl_credits(uint16_t handle, uint16_t credits); 102 void write_data_sync(uint16_t hci_handle, std::unique_ptr<packet::RawBuilder> packet); 103 void flush(uint16_t hci_handle); 104 105 private: 106 os::Handler* handler_; 107 const acl_interface_t acl_interface_; 108 109 bool CheckForOrphanedAclConnections() const; 110 111 struct impl; 112 std::unique_ptr<impl> pimpl_; 113 }; 114 115 } // namespace shim 116 } // namespace bluetooth 117