1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
/*
* Copyright 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <future>
#include <memory>
#include "gd/hci/acl_manager/connection_callbacks.h"
#include "gd/hci/acl_manager/le_connection_callbacks.h"
#include "gd/hci/address.h"
#include "gd/hci/address_with_type.h"
#include "gd/hci/class_of_device.h"
#include "gd/os/handler.h"
#include "gd/packet/raw_builder.h"
#include "main/shim/acl_legacy_interface.h"
#include "main/shim/link_connection_interface.h"
#include "main/shim/link_policy_interface.h"
#include "stack/include/bt_types.h"
#include "types/raw_address.h"
namespace bluetooth {
namespace shim {
namespace legacy {
class Acl : public hci::acl_manager::ConnectionCallbacks,
public hci::acl_manager::LeConnectionCallbacks,
public LinkConnectionInterface,
public LinkPolicyInterface {
public:
Acl(os::Handler* handler, const acl_interface_t& acl_interface,
uint8_t max_acceptlist_size, uint8_t max_address_resolution_size);
Acl(const Acl&) = delete;
Acl& operator=(const Acl&) = delete;
~Acl();
// hci::acl_manager::ConnectionCallbacks
void OnConnectSuccess(
std::unique_ptr<hci::acl_manager::ClassicAclConnection>) override;
void OnConnectFail(hci::Address, hci::ErrorCode reason) override;
void HACK_OnEscoConnectRequest(hci::Address, hci::ClassOfDevice) override;
void HACK_OnScoConnectRequest(hci::Address, hci::ClassOfDevice) override;
void OnClassicLinkDisconnected(uint16_t handle, hci::ErrorCode reason);
// hci::acl_manager::LeConnectionCallbacks
void OnLeConnectSuccess(
hci::AddressWithType,
std::unique_ptr<hci::acl_manager::LeAclConnection>) override;
void OnLeConnectFail(hci::AddressWithType, hci::ErrorCode reason) override;
void OnLeLinkDisconnected(uint16_t handle, hci::ErrorCode reason);
bluetooth::hci::AddressWithType GetConnectionLocalAddress(
const RawAddress& remote_bda);
// LinkConnectionInterface
void CreateClassicConnection(const hci::Address& address) override;
void CancelClassicConnection(const hci::Address& address) override;
void AcceptLeConnectionFrom(const hci::AddressWithType& address_with_type,
bool is_direct,
std::promise<bool> promise) override;
void IgnoreLeConnectionFrom(
const hci::AddressWithType& address_with_type) override;
void DisconnectClassic(uint16_t handle, tHCI_REASON reason,
std::string comment) override;
void DisconnectLe(uint16_t handle, tHCI_REASON reason,
std::string comment) override;
// Address Resolution List
void AddToAddressResolution(const hci::AddressWithType& address_with_type,
const std::array<uint8_t, 16>& peer_irk,
const std::array<uint8_t, 16>& local_irk);
void RemoveFromAddressResolution(
const hci::AddressWithType& address_with_type);
void ClearAddressResolution();
// LinkPolicyInterface
bool HoldMode(uint16_t hci_handle, uint16_t max_interval,
uint16_t min_interval) override;
bool SniffMode(uint16_t hci_handle, uint16_t max_interval,
uint16_t min_interval, uint16_t attempt,
uint16_t timeout) override;
bool ExitSniffMode(uint16_t hci_handle) override;
bool SniffSubrating(uint16_t hci_handle, uint16_t maximum_latency,
uint16_t minimum_remote_timeout,
uint16_t minimum_local_timeout) override;
void WriteData(uint16_t hci_handle,
std::unique_ptr<packet::RawBuilder> packet);
void Dump(int fd) const;
void DumpConnectionHistory(int fd) const;
void Shutdown();
void FinalShutdown();
void ClearAcceptList();
protected:
void on_incoming_acl_credits(uint16_t handle, uint16_t credits);
void write_data_sync(uint16_t hci_handle,
std::unique_ptr<packet::RawBuilder> packet);
private:
os::Handler* handler_;
const acl_interface_t acl_interface_;
bool CheckForOrphanedAclConnections() const;
struct impl;
std::unique_ptr<impl> pimpl_;
};
} // namespace legacy
} // namespace shim
} // namespace bluetooth
|