1 /*
2  * Copyright 2019 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 "l2cap/classic/internal/link.h"
18 
19 #include <chrono>
20 #include <memory>
21 
22 #include "common/bind.h"
23 #include "hci/acl_manager/classic_acl_connection.h"
24 #include "l2cap/classic/dynamic_channel_manager.h"
25 #include "l2cap/classic/internal/fixed_channel_impl.h"
26 #include "l2cap/classic/internal/link_manager.h"
27 #include "l2cap/internal/parameter_provider.h"
28 #include "os/alarm.h"
29 
30 namespace bluetooth {
31 namespace l2cap {
32 namespace classic {
33 namespace internal {
34 
35 using RetransmissionAndFlowControlMode = DynamicChannelConfigurationOption::RetransmissionAndFlowControlMode;
36 using ConnectionResult = DynamicChannelManager::ConnectionResult;
37 using ConnectionResultCode = DynamicChannelManager::ConnectionResultCode;
38 
Link(os::Handler * l2cap_handler,std::unique_ptr<hci::acl_manager::ClassicAclConnection> acl_connection,l2cap::internal::ParameterProvider * parameter_provider,DynamicChannelServiceManagerImpl * dynamic_service_manager,FixedChannelServiceManagerImpl * fixed_service_manager,LinkManager * link_manager)39 Link::Link(
40     os::Handler* l2cap_handler,
41     std::unique_ptr<hci::acl_manager::ClassicAclConnection> acl_connection,
42     l2cap::internal::ParameterProvider* parameter_provider,
43     DynamicChannelServiceManagerImpl* dynamic_service_manager,
44     FixedChannelServiceManagerImpl* fixed_service_manager,
45     LinkManager* link_manager)
46     : l2cap_handler_(l2cap_handler),
47       acl_connection_(std::move(acl_connection)),
48       data_pipeline_manager_(l2cap_handler, this, acl_connection_->GetAclQueueEnd()),
49       parameter_provider_(parameter_provider),
50       dynamic_service_manager_(dynamic_service_manager),
51       fixed_service_manager_(fixed_service_manager),
52       link_manager_(link_manager),
53       signalling_manager_(
54           l2cap_handler_,
55           this,
56           &data_pipeline_manager_,
57           dynamic_service_manager_,
58           &dynamic_channel_allocator_,
59           fixed_service_manager_),
60       acl_handle_(acl_connection_->GetHandle()) {
61   ASSERT(l2cap_handler_ != nullptr);
62   ASSERT(acl_connection_ != nullptr);
63   ASSERT(parameter_provider_ != nullptr);
64   link_idle_disconnect_alarm_.Schedule(common::BindOnce(&Link::Disconnect, common::Unretained(this)),
65                                        parameter_provider_->GetClassicLinkIdleDisconnectTimeout());
66   acl_connection_->RegisterCallbacks(this, l2cap_handler_);
67 }
68 
OnAclDisconnected(hci::ErrorCode status)69 void Link::OnAclDisconnected(hci::ErrorCode status) {
70   signalling_manager_.CancelAlarm();
71   fixed_channel_allocator_.OnAclDisconnected(status);
72   dynamic_channel_allocator_.OnAclDisconnected(status);
73   ConnectionResult result{
74       .connection_result_code = ConnectionResultCode::FAIL_HCI_ERROR,
75       .hci_error = status,
76       .l2cap_connection_response_result = ConnectionResponseResult::SUCCESS,
77   };
78   while (!local_cid_to_pending_dynamic_channel_connection_map_.empty()) {
79     auto entry = local_cid_to_pending_dynamic_channel_connection_map_.begin();
80     NotifyChannelFail(entry->first, result);
81   }
82 }
83 
Disconnect()84 void Link::Disconnect() {
85   acl_connection_->Disconnect(hci::DisconnectReason::REMOTE_USER_TERMINATED_CONNECTION);
86 }
87 
Encrypt()88 void Link::Encrypt() {
89   if (encryption_enabled_ == hci::EncryptionEnabled::OFF) {
90     acl_connection_->SetConnectionEncryption(hci::Enable::ENABLED);
91   }
92 }
93 
Authenticate()94 void Link::Authenticate() {
95   if (!IsAuthenticated() && !has_requested_authentication_) {
96     has_requested_authentication_ = true;
97     acl_connection_->AuthenticationRequested();
98   }
99 }
100 
IsAuthenticated() const101 bool Link::IsAuthenticated() const {
102   return encryption_enabled_ != hci::EncryptionEnabled::OFF;
103 }
104 
ReadRemoteVersionInformation()105 void Link::ReadRemoteVersionInformation() {
106   acl_connection_->ReadRemoteVersionInformation();
107 }
108 
ReadRemoteSupportedFeatures()109 void Link::ReadRemoteSupportedFeatures() {
110   acl_connection_->ReadRemoteSupportedFeatures();
111 }
112 
ReadRemoteExtendedFeatures(uint8_t page_number)113 void Link::ReadRemoteExtendedFeatures(uint8_t page_number) {
114   acl_connection_->ReadRemoteExtendedFeatures(page_number);
115 }
116 
ReadClockOffset()117 void Link::ReadClockOffset() {
118   acl_connection_->ReadClockOffset();
119 }
120 
AcquireSecurityHold()121 void Link::AcquireSecurityHold() {
122   used_by_security_module_ = true;
123   RefreshRefCount();
124 }
ReleaseSecurityHold()125 void Link::ReleaseSecurityHold() {
126   used_by_security_module_ = false;
127   RefreshRefCount();
128 }
129 
AllocateFixedChannel(Cid cid)130 std::shared_ptr<FixedChannelImpl> Link::AllocateFixedChannel(Cid cid) {
131   auto channel = fixed_channel_allocator_.AllocateChannel(cid);
132   data_pipeline_manager_.AttachChannel(cid, channel, l2cap::internal::DataPipelineManager::ChannelMode::BASIC);
133   return channel;
134 }
135 
IsFixedChannelAllocated(Cid cid)136 bool Link::IsFixedChannelAllocated(Cid cid) {
137   return fixed_channel_allocator_.IsChannelAllocated(cid);
138 }
139 
ReserveDynamicChannel()140 Cid Link::ReserveDynamicChannel() {
141   return dynamic_channel_allocator_.ReserveChannel();
142 }
143 
SendConnectionRequest(Psm psm,Cid local_cid)144 void Link::SendConnectionRequest(Psm psm, Cid local_cid) {
145   signalling_manager_.SendConnectionRequest(psm, local_cid);
146 }
147 
SendConnectionRequest(Psm psm,Cid local_cid,PendingDynamicChannelConnection pending_dynamic_channel_connection)148 void Link::SendConnectionRequest(Psm psm, Cid local_cid,
149                                  PendingDynamicChannelConnection pending_dynamic_channel_connection) {
150   if (pending_dynamic_channel_connection.configuration_.channel_mode ==
151           RetransmissionAndFlowControlMode::ENHANCED_RETRANSMISSION &&
152       !remote_extended_feature_received_) {
153     pending_dynamic_psm_list_.push_back(psm);
154     pending_dynamic_channel_callback_list_.push_back(std::move(pending_dynamic_channel_connection));
155     LOG_INFO("Will connect after information response ERTM feature support is received");
156     dynamic_channel_allocator_.FreeChannel(local_cid);
157     return;
158   } else if (pending_dynamic_channel_connection.configuration_.channel_mode ==
159                  RetransmissionAndFlowControlMode::ENHANCED_RETRANSMISSION &&
160              !GetRemoteSupportsErtm()) {
161     LOG_WARN("Remote doesn't support ERTM. Dropping connection request");
162     ConnectionResult result{
163         .connection_result_code = ConnectionResultCode::FAIL_REMOTE_NOT_SUPPORT,
164     };
165     pending_dynamic_channel_connection.on_fail_callback_.Invoke(result);
166     dynamic_channel_allocator_.FreeChannel(local_cid);
167     return;
168   } else {
169     local_cid_to_pending_dynamic_channel_connection_map_[local_cid] = std::move(pending_dynamic_channel_connection);
170     signalling_manager_.SendConnectionRequest(psm, local_cid);
171   }
172 }
173 
SetChannelTxPriority(Cid local_cid,bool high_priority)174 void Link::SetChannelTxPriority(Cid local_cid, bool high_priority) {
175   data_pipeline_manager_.SetChannelTxPriority(local_cid, high_priority);
176 }
177 
SetPendingDynamicChannels(std::list<Psm> psm_list,std::list<Link::PendingDynamicChannelConnection> callback_list)178 void Link::SetPendingDynamicChannels(std::list<Psm> psm_list,
179                                      std::list<Link::PendingDynamicChannelConnection> callback_list) {
180   ASSERT(psm_list.size() == callback_list.size());
181   pending_dynamic_psm_list_ = std::move(psm_list);
182   pending_dynamic_channel_callback_list_ = std::move(callback_list);
183 }
184 
connect_to_pending_dynamic_channels()185 void Link::connect_to_pending_dynamic_channels() {
186   auto psm = pending_dynamic_psm_list_.begin();
187   auto callback = pending_dynamic_channel_callback_list_.begin();
188   while (psm != pending_dynamic_psm_list_.end()) {
189     SendConnectionRequest(*psm, ReserveDynamicChannel(), std::move(*callback));
190     psm++;
191     callback++;
192   }
193 }
194 
send_pending_configuration_requests()195 void Link::send_pending_configuration_requests() {
196   for (auto local_cid : pending_outgoing_configuration_request_list_) {
197     signalling_manager_.SendInitialConfigRequest(local_cid);
198   }
199   pending_outgoing_configuration_request_list_.clear();
200 }
201 
OnOutgoingConnectionRequestFail(Cid local_cid,ConnectionResult result)202 void Link::OnOutgoingConnectionRequestFail(Cid local_cid, ConnectionResult result) {
203   if (local_cid_to_pending_dynamic_channel_connection_map_.find(local_cid) !=
204       local_cid_to_pending_dynamic_channel_connection_map_.end()) {
205     NotifyChannelFail(local_cid, result);
206   }
207   dynamic_channel_allocator_.FreeChannel(local_cid);
208 }
209 
SendInitialConfigRequestOrQueue(Cid local_cid)210 void Link::SendInitialConfigRequestOrQueue(Cid local_cid) {
211   if (remote_extended_feature_received_) {
212     signalling_manager_.SendInitialConfigRequest(local_cid);
213   } else {
214     pending_outgoing_configuration_request_list_.push_back(local_cid);
215   }
216 }
217 
SendDisconnectionRequest(Cid local_cid,Cid remote_cid)218 void Link::SendDisconnectionRequest(Cid local_cid, Cid remote_cid) {
219   signalling_manager_.SendDisconnectionRequest(local_cid, remote_cid);
220 }
221 
SendInformationRequest(InformationRequestInfoType type)222 void Link::SendInformationRequest(InformationRequestInfoType type) {
223   signalling_manager_.SendInformationRequest(type);
224 }
225 
AllocateDynamicChannel(Psm psm,Cid remote_cid)226 std::shared_ptr<l2cap::internal::DynamicChannelImpl> Link::AllocateDynamicChannel(Psm psm, Cid remote_cid) {
227   auto channel = dynamic_channel_allocator_.AllocateChannel(psm, remote_cid);
228   if (channel != nullptr) {
229     RefreshRefCount();
230     channel->local_initiated_ = false;
231   }
232   return channel;
233 }
234 
AllocateReservedDynamicChannel(Cid reserved_cid,Psm psm,Cid remote_cid)235 std::shared_ptr<l2cap::internal::DynamicChannelImpl> Link::AllocateReservedDynamicChannel(Cid reserved_cid, Psm psm,
236                                                                                           Cid remote_cid) {
237   auto channel = dynamic_channel_allocator_.AllocateReservedChannel(reserved_cid, psm, remote_cid);
238   if (channel != nullptr) {
239     RefreshRefCount();
240   }
241   channel->local_initiated_ = true;
242   return channel;
243 }
244 
GetConfigurationForInitialConfiguration(Cid cid)245 classic::DynamicChannelConfigurationOption Link::GetConfigurationForInitialConfiguration(Cid cid) {
246   ASSERT(local_cid_to_pending_dynamic_channel_connection_map_.find(cid) !=
247          local_cid_to_pending_dynamic_channel_connection_map_.end());
248   return local_cid_to_pending_dynamic_channel_connection_map_[cid].configuration_;
249 }
250 
FreeDynamicChannel(Cid cid)251 void Link::FreeDynamicChannel(Cid cid) {
252   if (dynamic_channel_allocator_.FindChannelByCid(cid) == nullptr) {
253     return;
254   }
255   dynamic_channel_allocator_.FreeChannel(cid);
256   RefreshRefCount();
257 }
258 
RefreshRefCount()259 void Link::RefreshRefCount() {
260   int ref_count = 0;
261   ref_count += fixed_channel_allocator_.GetRefCount();
262   ref_count += dynamic_channel_allocator_.NumberOfChannels();
263   if (used_by_security_module_) {
264     ref_count += 1;
265   }
266   ASSERT_LOG(ref_count >= 0, "ref_count %d is less than 0", ref_count);
267   if (ref_count > 0) {
268     link_idle_disconnect_alarm_.Cancel();
269   } else {
270     link_idle_disconnect_alarm_.Schedule(common::BindOnce(&Link::Disconnect, common::Unretained(this)),
271                                          parameter_provider_->GetClassicLinkIdleDisconnectTimeout());
272   }
273 }
274 
NotifyChannelCreation(Cid cid,std::unique_ptr<DynamicChannel> user_channel)275 void Link::NotifyChannelCreation(Cid cid, std::unique_ptr<DynamicChannel> user_channel) {
276   ASSERT(local_cid_to_pending_dynamic_channel_connection_map_.find(cid) !=
277          local_cid_to_pending_dynamic_channel_connection_map_.end());
278   auto& pending_dynamic_channel_connection = local_cid_to_pending_dynamic_channel_connection_map_[cid];
279   pending_dynamic_channel_connection.on_open_callback_.Invoke(std::move(user_channel));
280   local_cid_to_pending_dynamic_channel_connection_map_.erase(cid);
281 }
282 
NotifyChannelFail(Cid cid,ConnectionResult result)283 void Link::NotifyChannelFail(Cid cid, ConnectionResult result) {
284   ASSERT(local_cid_to_pending_dynamic_channel_connection_map_.find(cid) !=
285          local_cid_to_pending_dynamic_channel_connection_map_.end());
286   auto& pending_dynamic_channel_connection = local_cid_to_pending_dynamic_channel_connection_map_[cid];
287   pending_dynamic_channel_connection.on_fail_callback_.Invoke(result);
288   local_cid_to_pending_dynamic_channel_connection_map_.erase(cid);
289 }
290 
SetRemoteConnectionlessMtu(Mtu mtu)291 void Link::SetRemoteConnectionlessMtu(Mtu mtu) {
292   remote_connectionless_mtu_ = mtu;
293 }
294 
GetRemoteConnectionlessMtu() const295 Mtu Link::GetRemoteConnectionlessMtu() const {
296   return remote_connectionless_mtu_;
297 }
298 
GetRemoteSupportsErtm() const299 bool Link::GetRemoteSupportsErtm() const {
300   return remote_supports_ertm_;
301 }
302 
GetRemoteSupportsFcs() const303 bool Link::GetRemoteSupportsFcs() const {
304   return remote_supports_fcs_;
305 }
306 
OnRemoteExtendedFeatureReceived(bool ertm_supported,bool fcs_supported)307 void Link::OnRemoteExtendedFeatureReceived(bool ertm_supported, bool fcs_supported) {
308   remote_supports_ertm_ = ertm_supported;
309   remote_supports_fcs_ = fcs_supported;
310   remote_extended_feature_received_ = true;
311   connect_to_pending_dynamic_channels();
312   send_pending_configuration_requests();
313 }
314 
OnConnectionPacketTypeChanged(uint16_t packet_type)315 void Link::OnConnectionPacketTypeChanged(uint16_t packet_type) {
316   LOG_INFO("UNIMPLEMENTED %s packet_type:%x", __func__, packet_type);
317 }
318 
OnAuthenticationComplete(hci::ErrorCode hci_status)319 void Link::OnAuthenticationComplete(hci::ErrorCode hci_status) {
320   link_manager_->OnAuthenticationComplete(hci_status, GetDevice().GetAddress());
321 }
322 
OnEncryptionChange(hci::EncryptionEnabled enabled)323 void Link::OnEncryptionChange(hci::EncryptionEnabled enabled) {
324   encryption_enabled_ = enabled;
325   link_manager_->OnEncryptionChange(GetDevice().GetAddress(), enabled);
326   for (auto& listener : encryption_change_listener_) {
327     signalling_manager_.on_security_result_for_outgoing(
328         ClassicSignallingManager::SecurityEnforcementType::ENCRYPTION,
329         listener.psm,
330         listener.cid,
331         enabled != hci::EncryptionEnabled::OFF);
332   }
333 }
334 
OnChangeConnectionLinkKeyComplete()335 void Link::OnChangeConnectionLinkKeyComplete() {
336   LOG_INFO("UNIMPLEMENTED %s", __func__);
337 }
338 
OnReadClockOffsetComplete(uint16_t clock_offset)339 void Link::OnReadClockOffsetComplete(uint16_t clock_offset) {
340   link_manager_->OnReadClockOffset(GetDevice().GetAddress(), clock_offset);
341 }
342 
OnModeChange(hci::ErrorCode status,hci::Mode current_mode,uint16_t interval)343 void Link::OnModeChange(hci::ErrorCode status, hci::Mode current_mode, uint16_t interval) {
344   link_manager_->OnModeChange(status, GetDevice().GetAddress(), current_mode, interval);
345 }
346 
OnSniffSubrating(hci::ErrorCode hci_status,uint16_t maximum_transmit_latency,uint16_t maximum_receive_latency,uint16_t minimum_remote_timeout,uint16_t minimum_local_timeout)347 void Link::OnSniffSubrating(
348     hci::ErrorCode hci_status,
349     uint16_t maximum_transmit_latency,
350     uint16_t maximum_receive_latency,
351     uint16_t minimum_remote_timeout,
352     uint16_t minimum_local_timeout) {
353   link_manager_->OnSniffSubrating(
354       hci_status,
355       GetDevice().GetAddress(),
356       maximum_transmit_latency,
357       maximum_receive_latency,
358       minimum_remote_timeout,
359       minimum_local_timeout);
360 }
361 
OnQosSetupComplete(hci::ServiceType service_type,uint32_t token_rate,uint32_t peak_bandwidth,uint32_t latency,uint32_t delay_variation)362 void Link::OnQosSetupComplete(hci::ServiceType service_type, uint32_t token_rate, uint32_t peak_bandwidth,
363                               uint32_t latency, uint32_t delay_variation) {
364   LOG_INFO(
365       "UNIMPLEMENTED %s service_type:%s token_rate:%d peak_bandwidth:%d latency:%d delay_varitation:%d",
366       __func__,
367       hci::ServiceTypeText(service_type).c_str(),
368       token_rate,
369       peak_bandwidth,
370       latency,
371       delay_variation);
372 }
OnFlowSpecificationComplete(hci::FlowDirection flow_direction,hci::ServiceType service_type,uint32_t token_rate,uint32_t token_bucket_size,uint32_t peak_bandwidth,uint32_t access_latency)373 void Link::OnFlowSpecificationComplete(hci::FlowDirection flow_direction, hci::ServiceType service_type,
374                                        uint32_t token_rate, uint32_t token_bucket_size, uint32_t peak_bandwidth,
375                                        uint32_t access_latency) {
376   LOG_INFO(
377       "UNIMPLEMENTED %s flow_direction:%s service_type:%s token_rate:%d token_bucket_size:%d peak_bandwidth:%d "
378       "access_latency:%d",
379       __func__,
380       hci::FlowDirectionText(flow_direction).c_str(),
381       hci::ServiceTypeText(service_type).c_str(),
382       token_rate,
383       token_bucket_size,
384       peak_bandwidth,
385       access_latency);
386 }
OnFlushOccurred()387 void Link::OnFlushOccurred() {
388   LOG_INFO("UNIMPLEMENTED %s", __func__);
389 }
OnRoleDiscoveryComplete(hci::Role current_role)390 void Link::OnRoleDiscoveryComplete(hci::Role current_role) {
391   role_ = current_role;
392 }
OnReadLinkPolicySettingsComplete(uint16_t link_policy_settings)393 void Link::OnReadLinkPolicySettingsComplete(uint16_t link_policy_settings) {
394   LOG_INFO("UNIMPLEMENTED %s link_policy_settings:0x%x", __func__, link_policy_settings);
395 }
OnReadAutomaticFlushTimeoutComplete(uint16_t flush_timeout)396 void Link::OnReadAutomaticFlushTimeoutComplete(uint16_t flush_timeout) {
397   LOG_INFO("UNIMPLEMENTED %s flush_timeout:%d", __func__, flush_timeout);
398 }
OnReadTransmitPowerLevelComplete(uint8_t transmit_power_level)399 void Link::OnReadTransmitPowerLevelComplete(uint8_t transmit_power_level) {
400   LOG_INFO("UNIMPLEMENTED %s transmit_power_level:%d", __func__, transmit_power_level);
401 }
OnReadLinkSupervisionTimeoutComplete(uint16_t link_supervision_timeout)402 void Link::OnReadLinkSupervisionTimeoutComplete(uint16_t link_supervision_timeout) {
403   LOG_INFO("UNIMPLEMENTED %s link_supervision_timeout:%d", __func__, link_supervision_timeout);
404 }
OnReadFailedContactCounterComplete(uint16_t failed_contact_counter)405 void Link::OnReadFailedContactCounterComplete(uint16_t failed_contact_counter) {
406   LOG_INFO("UNIMPLEMENTED %sfailed_contact_counter:%hu", __func__, failed_contact_counter);
407 }
OnReadLinkQualityComplete(uint8_t link_quality)408 void Link::OnReadLinkQualityComplete(uint8_t link_quality) {
409   LOG_INFO("UNIMPLEMENTED %s link_quality:%hhu", __func__, link_quality);
410 }
OnReadAfhChannelMapComplete(hci::AfhMode afh_mode,std::array<uint8_t,10> afh_channel_map)411 void Link::OnReadAfhChannelMapComplete(hci::AfhMode afh_mode, std::array<uint8_t, 10> afh_channel_map) {
412   LOG_INFO("UNIMPLEMENTED %s afh_mode:%s", __func__, hci::AfhModeText(afh_mode).c_str());
413 }
OnReadRssiComplete(uint8_t rssi)414 void Link::OnReadRssiComplete(uint8_t rssi) {
415   LOG_INFO("UNIMPLEMENTED %s rssi:%hhd", __func__, rssi);
416 }
OnReadClockComplete(uint32_t clock,uint16_t accuracy)417 void Link::OnReadClockComplete(uint32_t clock, uint16_t accuracy) {
418   LOG_INFO("UNIMPLEMENTED %s clock:%u accuracy:%hu", __func__, clock, accuracy);
419 }
OnCentralLinkKeyComplete(hci::KeyFlag key_flag)420 void Link::OnCentralLinkKeyComplete(hci::KeyFlag key_flag) {
421   LOG_INFO("UNIMPLEMENTED key_flag:%s", hci::KeyFlagText(key_flag).c_str());
422 }
OnRoleChange(hci::ErrorCode hci_status,hci::Role new_role)423 void Link::OnRoleChange(hci::ErrorCode hci_status, hci::Role new_role) {
424   role_ = new_role;
425   link_manager_->OnRoleChange(hci_status, GetDevice().GetAddress(), new_role);
426 }
OnDisconnection(hci::ErrorCode reason)427 void Link::OnDisconnection(hci::ErrorCode reason) {
428   OnAclDisconnected(reason);
429   link_manager_->OnDisconnect(GetDevice().GetAddress(), reason);
430 }
OnReadRemoteVersionInformationComplete(hci::ErrorCode hci_status,uint8_t lmp_version,uint16_t manufacturer_name,uint16_t sub_version)431 void Link::OnReadRemoteVersionInformationComplete(
432     hci::ErrorCode hci_status, uint8_t lmp_version, uint16_t manufacturer_name, uint16_t sub_version) {
433   LOG_INFO(
434       "UNIMPLEMENTED hci_status:%s lmp_version:%hhu manufacturer_name:%hu sub_version:%hu",
435       ErrorCodeText(hci_status).c_str(),
436       lmp_version,
437       manufacturer_name,
438       sub_version);
439   link_manager_->OnReadRemoteVersionInformation(
440       hci_status, GetDevice().GetAddress(), lmp_version, manufacturer_name, sub_version);
441 }
OnReadRemoteSupportedFeaturesComplete(uint64_t features)442 void Link::OnReadRemoteSupportedFeaturesComplete(uint64_t features) {
443   LOG_INFO("page_number:%hhu features:0x%lx", static_cast<uint8_t>(0), static_cast<unsigned long>(features));
444   link_manager_->OnReadRemoteSupportedFeatures(GetDevice().GetAddress(), features);
445 }
446 
OnReadRemoteExtendedFeaturesComplete(uint8_t page_number,uint8_t max_page_number,uint64_t features)447 void Link::OnReadRemoteExtendedFeaturesComplete(uint8_t page_number, uint8_t max_page_number, uint64_t features) {
448   LOG_INFO(
449       "page_number:%hhu max_page_number:%hhu features:0x%lx",
450       page_number,
451       max_page_number,
452       static_cast<unsigned long>(features));
453   link_manager_->OnReadRemoteExtendedFeatures(GetDevice().GetAddress(), page_number, max_page_number, features);
454 }
455 
AddEncryptionChangeListener(EncryptionChangeListener listener)456 void Link::AddEncryptionChangeListener(EncryptionChangeListener listener) {
457   encryption_change_listener_.push_back(listener);
458 }
459 
OnPendingPacketChange(Cid local_cid,bool has_packet)460 void Link::OnPendingPacketChange(Cid local_cid, bool has_packet) {
461   if (has_packet) {
462     remaining_packets_to_be_sent_++;
463   } else {
464     remaining_packets_to_be_sent_--;
465   }
466   if (link_manager_ != nullptr) {
467     link_manager_->OnPendingPacketChange(GetDevice().GetAddress(), remaining_packets_to_be_sent_);
468   }
469 }
470 
471 }  // namespace internal
472 }  // namespace classic
473 }  // namespace l2cap
474 }  // namespace bluetooth
475