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 "common/bind.h"
20 #include "crypto_toolbox/crypto_toolbox.h"
21 #include "hci/acl_manager/assembler.h"
22 #include "hci/acl_manager/disconnector_for_le.h"
23 #include "hci/acl_manager/round_robin_scheduler.h"
24 #include "hci/le_address_manager.h"
25 #include "os/alarm.h"
26 #include "os/rand.h"
27 
28 using bluetooth::crypto_toolbox::Octet16;
29 
30 namespace bluetooth {
31 namespace hci {
32 namespace acl_manager {
33 
34 using common::BindOnce;
35 
36 struct le_acl_connection {
le_acl_connectionle_acl_connection37   le_acl_connection(
38       AddressWithType address_with_type, AclConnection::QueueDownEnd* queue_down_end, os::Handler* handler)
39       : assembler_(address_with_type, queue_down_end, handler), address_with_type_(address_with_type) {}
40   ~le_acl_connection() = default;
41   struct acl_manager::assembler assembler_;
42   AddressWithType address_with_type_;
43   LeConnectionManagementCallbacks* le_connection_management_callbacks_ = nullptr;
44 };
45 
46 struct le_impl : public bluetooth::hci::LeAddressManagerCallback {
le_implle_impl47   le_impl(HciLayer* hci_layer, Controller* controller, os::Handler* handler, RoundRobinScheduler* round_robin_scheduler,
48           DisconnectorForLe* disconnector)
49       : hci_layer_(hci_layer), controller_(controller), round_robin_scheduler_(round_robin_scheduler),
50         disconnector_(disconnector) {
51     hci_layer_ = hci_layer;
52     controller_ = controller;
53     handler_ = handler;
54     le_acl_connection_interface_ = hci_layer_->GetLeAclConnectionInterface(
55         handler_->BindOn(this, &le_impl::on_le_event), handler_->BindOn(this, &le_impl::on_le_disconnect));
56     le_address_manager_ = new LeAddressManager(
57         common::Bind(&le_impl::enqueue_command, common::Unretained(this)),
58         handler_,
59         controller->GetControllerMacAddress(),
60         controller->GetControllerLeConnectListSize(),
61         controller->GetControllerLeResolvingListSize());
62   }
63 
~le_implle_impl64   ~le_impl() {
65     for (auto subevent_code : LeConnectionManagementEvents) {
66       hci_layer_->UnregisterLeEventHandler(subevent_code);
67     }
68     if (address_manager_registered) {
69       le_address_manager_->Unregister(this);
70     }
71     delete le_address_manager_;
72     le_acl_connections_.clear();
73   }
74 
on_le_eventle_impl75   void on_le_event(LeMetaEventView event_packet) {
76     SubeventCode code = event_packet.GetSubeventCode();
77     switch (code) {
78       case SubeventCode::CONNECTION_COMPLETE:
79         on_le_connection_complete(event_packet);
80         break;
81       case SubeventCode::ENHANCED_CONNECTION_COMPLETE:
82         on_le_enhanced_connection_complete(event_packet);
83         break;
84       case SubeventCode::CONNECTION_UPDATE_COMPLETE:
85         on_le_connection_update_complete(event_packet);
86         break;
87       default:
88         LOG_ALWAYS_FATAL("Unhandled event code %s", SubeventCodeText(code).c_str());
89     }
90   }
91 
on_le_disconnectle_impl92   void on_le_disconnect(uint16_t handle, ErrorCode reason) {
93     if (le_acl_connections_.count(handle) == 1) {
94       auto& connection = le_acl_connections_.find(handle)->second;
95       round_robin_scheduler_->Unregister(handle);
96       connection.le_connection_management_callbacks_->OnDisconnection(reason);
97       le_acl_connections_.erase(handle);
98     }
99   }
100 
on_common_le_connection_completele_impl101   void on_common_le_connection_complete(AddressWithType address_with_type) {
102     auto connecting_addr_with_type = connecting_le_.find(address_with_type);
103     if (connecting_addr_with_type == connecting_le_.end()) {
104       LOG_WARN("No prior connection request for %s", address_with_type.ToString().c_str());
105     } else {
106       connecting_le_.erase(connecting_addr_with_type);
107     }
108   }
109 
on_le_connection_completele_impl110   void on_le_connection_complete(LeMetaEventView packet) {
111     LeConnectionCompleteView connection_complete = LeConnectionCompleteView::Create(packet);
112     ASSERT(connection_complete.IsValid());
113     auto status = connection_complete.GetStatus();
114     auto address = connection_complete.GetPeerAddress();
115     auto peer_address_type = connection_complete.GetPeerAddressType();
116     // TODO: find out which address and type was used to initiate the connection
117     AddressWithType remote_address(address, peer_address_type);
118     AddressWithType local_address = le_address_manager_->GetCurrentAddress();
119     on_common_le_connection_complete(remote_address);
120     if (status == ErrorCode::UNKNOWN_CONNECTION &&
121         canceled_connections_.find(remote_address) != canceled_connections_.end()) {
122       // connection canceled by LeAddressManager.OnPause(), will auto reconnect by LeAddressManager.OnResume()
123       return;
124     } else {
125       canceled_connections_.erase(remote_address);
126       ready_to_unregister = true;
127       remove_device_from_connect_list(remote_address);
128     }
129 
130     if (status != ErrorCode::SUCCESS) {
131       le_client_handler_->Post(common::BindOnce(&LeConnectionCallbacks::OnLeConnectFail,
132                                                 common::Unretained(le_client_callbacks_), remote_address, status));
133       return;
134     }
135 
136     uint16_t conn_interval = connection_complete.GetConnInterval();
137     uint16_t conn_latency = connection_complete.GetConnLatency();
138     uint16_t supervision_timeout = connection_complete.GetSupervisionTimeout();
139     if (!check_connection_parameters(conn_interval, conn_interval, conn_latency, supervision_timeout)) {
140       LOG_ERROR("Receive connection complete with invalid connection parameters");
141       return;
142     }
143 
144     auto role = connection_complete.GetRole();
145     uint16_t handle = connection_complete.GetConnectionHandle();
146     ASSERT(le_acl_connections_.count(handle) == 0);
147     auto queue = std::make_shared<AclConnection::Queue>(10);
148     le_acl_connections_.emplace(std::piecewise_construct, std::forward_as_tuple(handle),
149                                 std::forward_as_tuple(remote_address, queue->GetDownEnd(), handler_));
150     auto& connection_proxy = check_and_get_le_connection(handle);
151     auto do_disconnect =
152         common::BindOnce(&DisconnectorForLe::handle_disconnect, common::Unretained(disconnector_), handle);
153     round_robin_scheduler_->Register(RoundRobinScheduler::ConnectionType::LE, handle, queue);
154     std::unique_ptr<LeAclConnection> connection(new LeAclConnection(std::move(queue), le_acl_connection_interface_,
155                                                                     std::move(do_disconnect), handle, local_address,
156                                                                     remote_address, role));
157     connection_proxy.le_connection_management_callbacks_ = connection->GetEventCallbacks();
158     le_client_handler_->Post(common::BindOnce(&LeConnectionCallbacks::OnLeConnectSuccess,
159                                               common::Unretained(le_client_callbacks_), remote_address,
160                                               std::move(connection)));
161   }
162 
on_le_enhanced_connection_completele_impl163   void on_le_enhanced_connection_complete(LeMetaEventView packet) {
164     LeEnhancedConnectionCompleteView connection_complete = LeEnhancedConnectionCompleteView::Create(packet);
165     ASSERT(connection_complete.IsValid());
166     auto status = connection_complete.GetStatus();
167     auto address = connection_complete.GetPeerAddress();
168     auto peer_address_type = connection_complete.GetPeerAddressType();
169     auto peer_resolvable_address = connection_complete.GetPeerResolvablePrivateAddress();
170     AddressWithType remote_address(address, peer_address_type);
171     AddressWithType local_address = le_address_manager_->GetCurrentAddress();
172     if (!peer_resolvable_address.IsEmpty()) {
173       remote_address = AddressWithType(peer_resolvable_address, AddressType::RANDOM_DEVICE_ADDRESS);
174     }
175     on_common_le_connection_complete(remote_address);
176     if (status == ErrorCode::UNKNOWN_CONNECTION &&
177         canceled_connections_.find(remote_address) != canceled_connections_.end()) {
178       // connection canceled by LeAddressManager.OnPause(), will auto reconnect by LeAddressManager.OnResume()
179       return;
180     } else {
181       canceled_connections_.erase(remote_address);
182       ready_to_unregister = true;
183       remove_device_from_connect_list(remote_address);
184     }
185 
186     if (status != ErrorCode::SUCCESS) {
187       le_client_handler_->Post(common::BindOnce(&LeConnectionCallbacks::OnLeConnectFail,
188                                                 common::Unretained(le_client_callbacks_), remote_address, status));
189       return;
190     }
191     uint16_t conn_interval = connection_complete.GetConnInterval();
192     uint16_t conn_latency = connection_complete.GetConnLatency();
193     uint16_t supervision_timeout = connection_complete.GetSupervisionTimeout();
194     if (!check_connection_parameters(conn_interval, conn_interval, conn_latency, supervision_timeout)) {
195       LOG_ERROR("Receive enhenced connection complete with invalid connection parameters");
196       return;
197     }
198     uint16_t handle = connection_complete.GetConnectionHandle();
199     ASSERT(le_acl_connections_.count(handle) == 0);
200     auto queue = std::make_shared<AclConnection::Queue>(10);
201     le_acl_connections_.emplace(std::piecewise_construct, std::forward_as_tuple(handle),
202                                 std::forward_as_tuple(remote_address, queue->GetDownEnd(), handler_));
203     auto& connection_proxy = check_and_get_le_connection(handle);
204     round_robin_scheduler_->Register(RoundRobinScheduler::ConnectionType::LE, handle, queue);
205     auto role = connection_complete.GetRole();
206     auto do_disconnect =
207         common::BindOnce(&DisconnectorForLe::handle_disconnect, common::Unretained(disconnector_), handle);
208     std::unique_ptr<LeAclConnection> connection(new LeAclConnection(std::move(queue), le_acl_connection_interface_,
209                                                                     std::move(do_disconnect), handle, local_address,
210                                                                     remote_address, role));
211     connection_proxy.le_connection_management_callbacks_ = connection->GetEventCallbacks();
212     le_client_handler_->Post(common::BindOnce(&LeConnectionCallbacks::OnLeConnectSuccess,
213                                               common::Unretained(le_client_callbacks_), remote_address,
214                                               std::move(connection)));
215   }
216 
on_le_connection_update_completele_impl217   void on_le_connection_update_complete(LeMetaEventView view) {
218     auto complete_view = LeConnectionUpdateCompleteView::Create(view);
219     if (!complete_view.IsValid()) {
220       LOG_ERROR("Received on_le_connection_update_complete with invalid packet");
221       return;
222     } else if (complete_view.GetStatus() != ErrorCode::SUCCESS) {
223       auto status = complete_view.GetStatus();
224       std::string error_code = ErrorCodeText(status);
225       LOG_ERROR("Received on_le_connection_update_complete with error code %s", error_code.c_str());
226       return;
227     }
228     auto handle = complete_view.GetConnectionHandle();
229     if (le_acl_connections_.find(handle) == le_acl_connections_.end()) {
230       LOG_WARN("Can't find connection %hd", handle);
231       return;
232     }
233     auto& connection = le_acl_connections_.find(handle)->second;
234     connection.le_connection_management_callbacks_->OnConnectionUpdate(
235         complete_view.GetConnInterval(), complete_view.GetConnLatency(), complete_view.GetSupervisionTimeout());
236   }
237 
enqueue_commandle_impl238   void enqueue_command(std::unique_ptr<CommandPacketBuilder> command_packet) {
239     hci_layer_->EnqueueCommand(
240         std::move(command_packet),
241         handler_->BindOnce(&LeAddressManager::OnCommandComplete, common::Unretained(le_address_manager_)));
242   }
243 
add_device_to_connect_listle_impl244   void add_device_to_connect_list(AddressWithType address_with_type) {
245     AddressType address_type = address_with_type.GetAddressType();
246     if (!address_manager_registered) {
247       le_address_manager_->Register(this);
248       address_manager_registered = true;
249     }
250     pause_connection = true;
251     switch (address_type) {
252       case AddressType::PUBLIC_DEVICE_ADDRESS:
253       case AddressType::PUBLIC_IDENTITY_ADDRESS: {
254         le_address_manager_->AddDeviceToConnectList(ConnectListAddressType::PUBLIC, address_with_type.GetAddress());
255       } break;
256       case AddressType::RANDOM_DEVICE_ADDRESS:
257       case AddressType::RANDOM_IDENTITY_ADDRESS: {
258         le_address_manager_->AddDeviceToConnectList(ConnectListAddressType::RANDOM, address_with_type.GetAddress());
259       }
260     }
261   }
262 
add_device_to_resolving_listle_impl263   void add_device_to_resolving_list(
264       AddressWithType address_with_type,
265       const std::array<uint8_t, 16>& peer_irk,
266       const std::array<uint8_t, 16>& local_irk) {
267     AddressType address_type = address_with_type.GetAddressType();
268     if (!address_manager_registered) {
269       le_address_manager_->Register(this);
270       address_manager_registered = true;
271     }
272     pause_connection = true;
273     switch (address_type) {
274       case AddressType::PUBLIC_DEVICE_ADDRESS:
275       case AddressType::PUBLIC_IDENTITY_ADDRESS: {
276         le_address_manager_->AddDeviceToResolvingList(
277             PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, address_with_type.GetAddress(), peer_irk, local_irk);
278       } break;
279       case AddressType::RANDOM_DEVICE_ADDRESS:
280       case AddressType::RANDOM_IDENTITY_ADDRESS: {
281         le_address_manager_->AddDeviceToResolvingList(
282             PeerAddressType::RANDOM_DEVICE_OR_IDENTITY_ADDRESS, address_with_type.GetAddress(), peer_irk, local_irk);
283       }
284     }
285   }
286 
create_le_connectionle_impl287   void create_le_connection(AddressWithType address_with_type, bool add_to_connect_list) {
288     // TODO: Configure default LE connection parameters?
289 
290     if (add_to_connect_list) {
291       add_device_to_connect_list(address_with_type);
292     }
293 
294     if (!address_manager_registered) {
295       auto policy = le_address_manager_->Register(this);
296       address_manager_registered = true;
297 
298       // Pause connection, wait for set random address complete
299       if (policy == LeAddressManager::AddressPolicy::USE_RESOLVABLE_ADDRESS ||
300           policy == LeAddressManager::AddressPolicy::USE_NON_RESOLVABLE_ADDRESS) {
301         pause_connection = true;
302       }
303     }
304 
305     if (pause_connection) {
306       canceled_connections_.insert(address_with_type);
307       return;
308     }
309 
310     uint16_t le_scan_interval = 0x0060;
311     uint16_t le_scan_window = 0x0030;
312     InitiatorFilterPolicy initiator_filter_policy = InitiatorFilterPolicy::USE_CONNECT_LIST;
313     OwnAddressType own_address_type =
314         static_cast<OwnAddressType>(le_address_manager_->GetCurrentAddress().GetAddressType());
315     uint16_t conn_interval_min = 0x0018;
316     uint16_t conn_interval_max = 0x0028;
317     uint16_t conn_latency = 0x0000;
318     uint16_t supervision_timeout = 0x001f4;
319     ASSERT(le_client_callbacks_ != nullptr);
320     ASSERT(check_connection_parameters(conn_interval_min, conn_interval_max, conn_latency, supervision_timeout));
321 
322     connecting_le_.insert(address_with_type);
323 
324     // TODO: make features check nicer, like HCI_LE_EXTENDED_ADVERTISING_SUPPORTED
325     if (controller_->GetControllerLeLocalSupportedFeatures() & 0x0010) {
326       LeCreateConnPhyScanParameters tmp;
327       tmp.scan_interval_ = le_scan_interval;
328       tmp.scan_window_ = le_scan_window;
329       tmp.conn_interval_min_ = conn_interval_min;
330       tmp.conn_interval_max_ = conn_interval_max;
331       tmp.conn_latency_ = conn_latency;
332       tmp.supervision_timeout_ = supervision_timeout;
333       tmp.min_ce_length_ = 0x00;
334       tmp.max_ce_length_ = 0x00;
335 
336       le_acl_connection_interface_->EnqueueCommand(
337           LeExtendedCreateConnectionBuilder::Create(initiator_filter_policy, own_address_type,
338                                                     address_with_type.GetAddressType(), address_with_type.GetAddress(),
339                                                     0x01 /* 1M PHY ONLY */, {tmp}),
340           handler_->BindOnce([](CommandStatusView status) {
341             ASSERT(status.IsValid());
342             ASSERT(status.GetCommandOpCode() == OpCode::LE_EXTENDED_CREATE_CONNECTION);
343           }));
344     } else {
345       le_acl_connection_interface_->EnqueueCommand(
346           LeCreateConnectionBuilder::Create(le_scan_interval, le_scan_window, initiator_filter_policy,
347                                             address_with_type.GetAddressType(), address_with_type.GetAddress(),
348                                             own_address_type, conn_interval_min, conn_interval_max, conn_latency,
349                                             supervision_timeout, kMinimumCeLength, kMaximumCeLength),
350           handler_->BindOnce([](CommandStatusView status) {
351             ASSERT(status.IsValid());
352             ASSERT(status.GetCommandOpCode() == OpCode::LE_CREATE_CONNECTION);
353           }));
354     }
355   }
356 
cancel_connectle_impl357   void cancel_connect(AddressWithType address_with_type) {
358     // the connection will be canceled by LeAddressManager.OnPause()
359     remove_device_from_connect_list(address_with_type);
360   }
361 
remove_device_from_connect_listle_impl362   void remove_device_from_connect_list(AddressWithType address_with_type) {
363     AddressType address_type = address_with_type.GetAddressType();
364     if (!address_manager_registered) {
365       le_address_manager_->Register(this);
366       address_manager_registered = true;
367     }
368     pause_connection = true;
369     switch (address_type) {
370       case AddressType::PUBLIC_DEVICE_ADDRESS:
371       case AddressType::PUBLIC_IDENTITY_ADDRESS: {
372         le_address_manager_->RemoveDeviceFromConnectList(
373             ConnectListAddressType::PUBLIC, address_with_type.GetAddress());
374       } break;
375       case AddressType::RANDOM_DEVICE_ADDRESS:
376       case AddressType::RANDOM_IDENTITY_ADDRESS: {
377         le_address_manager_->RemoveDeviceFromConnectList(
378             ConnectListAddressType::RANDOM, address_with_type.GetAddress());
379       }
380     }
381   }
382 
remove_device_from_resolving_listle_impl383   void remove_device_from_resolving_list(AddressWithType address_with_type) {
384     AddressType address_type = address_with_type.GetAddressType();
385     if (!address_manager_registered) {
386       le_address_manager_->Register(this);
387       address_manager_registered = true;
388     }
389     pause_connection = true;
390     switch (address_type) {
391       case AddressType::PUBLIC_DEVICE_ADDRESS:
392       case AddressType::PUBLIC_IDENTITY_ADDRESS: {
393         le_address_manager_->RemoveDeviceFromResolvingList(
394             PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, address_with_type.GetAddress());
395       } break;
396       case AddressType::RANDOM_DEVICE_ADDRESS:
397       case AddressType::RANDOM_IDENTITY_ADDRESS: {
398         le_address_manager_->RemoveDeviceFromResolvingList(
399             PeerAddressType::RANDOM_DEVICE_OR_IDENTITY_ADDRESS, address_with_type.GetAddress());
400       }
401     }
402   }
403 
set_privacy_policy_for_initiator_addressle_impl404   void set_privacy_policy_for_initiator_address(
405       LeAddressManager::AddressPolicy address_policy,
406       AddressWithType fixed_address,
407       crypto_toolbox::Octet16 rotation_irk,
408       std::chrono::milliseconds minimum_rotation_time,
409       std::chrono::milliseconds maximum_rotation_time) {
410     le_address_manager_->SetPrivacyPolicyForInitiatorAddress(
411         address_policy, fixed_address, rotation_irk, minimum_rotation_time, maximum_rotation_time);
412   }
413 
414   // TODO(jpawlowski): remove once we have config file abstraction in cert tests
set_privacy_policy_for_initiator_address_for_testle_impl415   void set_privacy_policy_for_initiator_address_for_test(
416       LeAddressManager::AddressPolicy address_policy,
417       AddressWithType fixed_address,
418       crypto_toolbox::Octet16 rotation_irk,
419       std::chrono::milliseconds minimum_rotation_time,
420       std::chrono::milliseconds maximum_rotation_time) {
421     le_address_manager_->SetPrivacyPolicyForInitiatorAddressForTest(
422         address_policy, fixed_address, rotation_irk, minimum_rotation_time, maximum_rotation_time);
423   }
424 
handle_register_le_callbacksle_impl425   void handle_register_le_callbacks(LeConnectionCallbacks* callbacks, os::Handler* handler) {
426     ASSERT(le_client_callbacks_ == nullptr);
427     ASSERT(le_client_handler_ == nullptr);
428     le_client_callbacks_ = callbacks;
429     le_client_handler_ = handler;
430   }
431 
check_and_get_le_connectionle_impl432   le_acl_connection& check_and_get_le_connection(uint16_t handle) {
433     auto connection = le_acl_connections_.find(handle);
434     ASSERT(connection != le_acl_connections_.end());
435     return connection->second;
436   }
437 
check_connection_parametersle_impl438   bool check_connection_parameters(
439       uint16_t conn_interval_min, uint16_t conn_interval_max, uint16_t conn_latency, uint16_t supervision_timeout) {
440     if (conn_interval_min < 0x0006 || conn_interval_min > 0x0C80 || conn_interval_max < 0x0006 ||
441         conn_interval_max > 0x0C80 || conn_latency > 0x01F3 || supervision_timeout < 0x000A ||
442         supervision_timeout > 0x0C80) {
443       LOG_ERROR("Invalid parameter");
444       return false;
445     }
446 
447     // The Maximum interval in milliseconds will be conn_interval_max * 1.25 ms
448     // The Timeout in milliseconds will be expected_supervision_timeout * 10 ms
449     // The Timeout in milliseconds shall be larger than (1 + Latency) * Interval_Max * 2, where Interval_Max is given in
450     // milliseconds.
451     uint32_t supervision_timeout_min = (uint32_t)(1 + conn_latency) * conn_interval_max * 2 + 1;
452     if (supervision_timeout * 8 < supervision_timeout_min || conn_interval_max < conn_interval_min) {
453       LOG_ERROR("Invalid parameter");
454       return false;
455     }
456 
457     return true;
458   }
459 
OnPausele_impl460   void OnPause() override {
461     pause_connection = true;
462     if (connecting_le_.empty()) {
463       le_address_manager_->AckPause(this);
464       return;
465     }
466     canceled_connections_ = connecting_le_;
467     le_acl_connection_interface_->EnqueueCommand(
468         LeCreateConnectionCancelBuilder::Create(),
469         handler_->BindOnce(&le_impl::on_create_connection_cancel_complete, common::Unretained(this)));
470   }
471 
on_create_connection_cancel_completele_impl472   void on_create_connection_cancel_complete(CommandCompleteView view) {
473     auto complete_view = LeCreateConnectionCancelCompleteView::Create(view);
474     ASSERT(complete_view.IsValid());
475     if (complete_view.GetStatus() != ErrorCode::SUCCESS) {
476       auto status = complete_view.GetStatus();
477       std::string error_code = ErrorCodeText(status);
478       LOG_WARN("Received on_create_connection_cancel_complete with error code %s", error_code.c_str());
479     }
480     le_address_manager_->AckPause(this);
481   }
482 
check_for_unregisterle_impl483   void check_for_unregister() {
484     if (le_acl_connections_.empty() && connecting_le_.empty() && canceled_connections_.empty() &&
485         address_manager_registered && ready_to_unregister) {
486       le_address_manager_->Unregister(this);
487       address_manager_registered = false;
488       pause_connection = false;
489       ready_to_unregister = false;
490     }
491   }
492 
OnResumele_impl493   void OnResume() override {
494     pause_connection = false;
495     if (!canceled_connections_.empty()) {
496       create_le_connection(*canceled_connections_.begin(), false);
497     }
498     canceled_connections_.clear();
499     le_address_manager_->AckResume(this);
500     check_for_unregister();
501   }
502 
HACK_get_handlele_impl503   uint16_t HACK_get_handle(Address address) {
504     for (auto it = le_acl_connections_.begin(); it != le_acl_connections_.end(); it++) {
505       if (it->second.address_with_type_.GetAddress() == address) {
506         return it->first;
507       }
508     }
509     return 0xFFFF;
510   }
511 
512   static constexpr uint16_t kMinimumCeLength = 0x0002;
513   static constexpr uint16_t kMaximumCeLength = 0x0C00;
514   HciLayer* hci_layer_ = nullptr;
515   Controller* controller_ = nullptr;
516   os::Handler* handler_ = nullptr;
517   RoundRobinScheduler* round_robin_scheduler_ = nullptr;
518   LeAddressManager* le_address_manager_ = nullptr;
519   LeAclConnectionInterface* le_acl_connection_interface_ = nullptr;
520   LeConnectionCallbacks* le_client_callbacks_ = nullptr;
521   os::Handler* le_client_handler_ = nullptr;
522   std::map<uint16_t, le_acl_connection> le_acl_connections_;
523   std::set<AddressWithType> connecting_le_;
524   std::set<AddressWithType> canceled_connections_;
525   DisconnectorForLe* disconnector_;
526   bool address_manager_registered = false;
527   bool ready_to_unregister = false;
528   bool pause_connection = false;
529 };
530 
531 }  // namespace acl_manager
532 }  // namespace hci
533 }  // namespace bluetooth
534