Loading system/gd/Android.bp +4 −0 Original line number Diff line number Diff line Loading @@ -326,9 +326,11 @@ cc_binary { ], shared_libs: [ "libPlatformProperties", "libbase", "libcrypto", "libgrpc++", "libgrpc_wrap", "liblog", "libprotobuf-cpp-full", "libunwindstack", "server_configurable_flags", Loading Loading @@ -879,7 +881,9 @@ cc_library_host_shared { "pybind11_headers", ], static_libs: [ "libbase", "libbluetooth_l2cap_pdl", "libbluetooth_log", ], cflags: [ "-fexceptions", Loading system/gd/hci/BUILD.gn +4 −1 Original line number Diff line number Diff line Loading @@ -45,7 +45,10 @@ source_set("BluetoothHciSources") { "//bt/system/gd:gd_default_deps", ] configs += [ "//bt/system:target_defaults" ] configs += [ "//bt/system:target_defaults", "//bt/system/log:log_defaults", ] } if (use.test) { Loading system/gd/hci/acl_manager.cc +8 −6 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ #include "hci/acl_manager.h" #include <bluetooth/log.h> #include <atomic> #include <future> #include <mutex> Loading Loading @@ -129,8 +131,8 @@ struct AclManager::impl { if (!timed_out) { unsent_packets.push_back(itr); } else { LOG_ERROR( "Dropping packet of size %zu to unknown connection 0x%0hx", log::error( "Dropping packet of size {} to unknown connection 0x{:x}", itr.size(), itr.GetHandle()); } Loading @@ -140,7 +142,7 @@ struct AclManager::impl { } static void on_unknown_acl_timer(struct AclManager::impl* impl) { LOG_INFO("Timer fired!"); log::info("Timer fired!"); impl->retry_unknown_acl(/* timed_out = */ true); impl->unknown_acl_alarm_.reset(); } Loading @@ -155,7 +157,7 @@ struct AclManager::impl { auto packet = hci_queue_end_->TryDequeue(); ASSERT(packet != nullptr); if (!packet->IsValid()) { LOG_INFO("Dropping invalid packet of size %zu", packet->size()); log::info("Dropping invalid packet of size {}", packet->size()); return; } uint16_t handle = packet->GetHandle(); Loading @@ -170,8 +172,8 @@ struct AclManager::impl { unknown_acl_alarm_.reset(new os::Alarm(handler_)); } waiting_packets_.push_back(*packet); LOG_INFO( "Saving packet of size %zu to unknown connection 0x%0hx", log::info( "Saving packet of size {} to unknown connection 0x{:x}", packet->size(), packet->GetHandle()); unknown_acl_alarm_->Schedule( Loading system/gd/hci/acl_manager/acl_scheduler.cc +16 −12 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ #include "acl_scheduler.h" #include <bluetooth/log.h> #include <optional> #include <unordered_set> #include <variant> Loading Loading @@ -77,12 +79,12 @@ struct AclScheduler::impl { void ReportOutgoingAclConnectionFailure() { if (!outgoing_entry_.has_value()) { LOG_ERROR("Outgoing connection failure reported, but none present!"); log::error("Outgoing connection failure reported, but none present!"); return; } auto entry = std::get_if<AclCreateConnectionQueueEntry>(&outgoing_entry_.value()); if (entry == nullptr) { LOG_ERROR("Outgoing connection failure reported, but we're currently doing an RNR!"); log::error("Outgoing connection failure reported, but we're currently doing an RNR!"); return; } outgoing_entry_.reset(); Loading @@ -101,7 +103,8 @@ struct AclScheduler::impl { [&]() { cancel_connection.Invoke(); }, [&](auto /* entry */) { cancel_connection_completed.Invoke(); }); if (!ok) { LOG_ERROR("Attempted to cancel connection to %s that does not exist", log::error( "Attempted to cancel connection to {} that does not exist", ADDRESS_TO_LOGGABLE_CSTR(address)); } } Loading @@ -117,7 +120,7 @@ struct AclScheduler::impl { void ReportRemoteNameRequestCompletion(Address /* address */) { if (!outgoing_entry_.has_value()) { LOG_ERROR("Remote name request completion reported, but none taking place!"); log::error("Remote name request completion reported, but none taking place!"); return; } Loading @@ -125,11 +128,11 @@ struct AclScheduler::impl { [](auto&& entry) { using T = std::decay_t<decltype(entry)>; if constexpr (std::is_same_v<T, RemoteNameRequestQueueEntry>) { LOG_INFO("Remote name request completed"); log::info("Remote name request completed"); } else if constexpr (std::is_same_v<T, AclCreateConnectionQueueEntry>) { LOG_ERROR( "Received RNR completion when ACL connection is outstanding - assuming the connection has failed and " "continuing"); log::error( "Received RNR completion when ACL connection is outstanding - assuming the " "connection has failed and continuing"); } else { static_assert(!sizeof(T*), "non-exhaustive visitor!"); } Loading @@ -149,8 +152,9 @@ struct AclScheduler::impl { [&]() { cancel_request.Invoke(); }, [](auto entry) { std::get<RemoteNameRequestQueueEntry>(entry).callback_when_cancelled.Invoke(); }); if (!ok) { LOG_ERROR("Attempted to cancel remote name request " "to %s that does not exist", ADDRESS_TO_LOGGABLE_CSTR(address)); log::error( "Attempted to cancel remote name request to {} that does not exist", ADDRESS_TO_LOGGABLE_CSTR(address)); } }; Loading @@ -165,7 +169,7 @@ struct AclScheduler::impl { } if (incoming_connecting_address_set_.empty() && !outgoing_entry_.has_value() && !pending_outgoing_operations_.empty()) { LOG_INFO("Pending connections is not empty; so sending next connection"); log::info("Pending connections is not empty; so sending next connection"); auto entry = std::move(pending_outgoing_operations_.front()); pending_outgoing_operations_.pop_front(); std::visit([](auto&& variant) { variant.callback.Invoke(); }, entry); Loading system/gd/hci/acl_manager/assembler.h +14 −7 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ #pragma once #include <bluetooth/log.h> #include <cstddef> #include <cstdint> #include <memory> Loading Loading @@ -98,30 +100,34 @@ struct assembler { PacketView<packet::kLittleEndian> payload = packet.GetPayload(); auto broadcast_flag = packet.GetBroadcastFlag(); if (broadcast_flag == BroadcastFlag::ACTIVE_PERIPHERAL_BROADCAST) { LOG_WARN("Dropping broadcast from remote"); log::warn("Dropping broadcast from remote"); return; } auto packet_boundary_flag = packet.GetPacketBoundaryFlag(); if (packet_boundary_flag == PacketBoundaryFlag::FIRST_NON_AUTOMATICALLY_FLUSHABLE) { LOG_ERROR("Controller is not allowed to send FIRST_NON_AUTOMATICALLY_FLUSHABLE to host except loopback mode"); log::error( "Controller is not allowed to send FIRST_NON_AUTOMATICALLY_FLUSHABLE to host except " "loopback mode"); return; } if (packet_boundary_flag == PacketBoundaryFlag::CONTINUING_FRAGMENT) { if (!recombination_stage_.ReceivedFirstPacket()) { LOG_ERROR("Continuing fragment received without previous first, dropping it."); log::error("Continuing fragment received without previous first, dropping it."); return; } recombination_stage_.AppendPacketView(payload); } else if (packet_boundary_flag == PacketBoundaryFlag::FIRST_AUTOMATICALLY_FLUSHABLE) { if (recombination_stage_.ReceivedFirstPacket()) { LOG_ERROR("Controller sent a starting packet without finishing previous packet. Drop previous one."); log::error( "Controller sent a starting packet without finishing previous packet. Drop previous " "one."); } recombination_stage_ = payload; } // Check the size of the packet size_t expected_size = GetL2capPduSize(recombination_stage_) + kL2capBasicFrameHeaderSize; if (expected_size < recombination_stage_.size()) { LOG_INFO("Packet size doesn't match L2CAP header, dropping it."); log::info("Packet size doesn't match L2CAP header, dropping it."); recombination_stage_ = PacketViewForRecombination(); return; } else if (expected_size > recombination_stage_.size()) { Loading @@ -129,7 +135,8 @@ struct assembler { return; } if (incoming_queue_.size() > kMaxQueuedPacketsPerConnection) { LOG_ERROR("Dropping packet from %s due to congestion", log::error( "Dropping packet from {} due to congestion", ADDRESS_TO_LOGGABLE_CSTR(address_with_type_)); recombination_stage_ = PacketViewForRecombination(); return; Loading Loading
system/gd/Android.bp +4 −0 Original line number Diff line number Diff line Loading @@ -326,9 +326,11 @@ cc_binary { ], shared_libs: [ "libPlatformProperties", "libbase", "libcrypto", "libgrpc++", "libgrpc_wrap", "liblog", "libprotobuf-cpp-full", "libunwindstack", "server_configurable_flags", Loading Loading @@ -879,7 +881,9 @@ cc_library_host_shared { "pybind11_headers", ], static_libs: [ "libbase", "libbluetooth_l2cap_pdl", "libbluetooth_log", ], cflags: [ "-fexceptions", Loading
system/gd/hci/BUILD.gn +4 −1 Original line number Diff line number Diff line Loading @@ -45,7 +45,10 @@ source_set("BluetoothHciSources") { "//bt/system/gd:gd_default_deps", ] configs += [ "//bt/system:target_defaults" ] configs += [ "//bt/system:target_defaults", "//bt/system/log:log_defaults", ] } if (use.test) { Loading
system/gd/hci/acl_manager.cc +8 −6 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ #include "hci/acl_manager.h" #include <bluetooth/log.h> #include <atomic> #include <future> #include <mutex> Loading Loading @@ -129,8 +131,8 @@ struct AclManager::impl { if (!timed_out) { unsent_packets.push_back(itr); } else { LOG_ERROR( "Dropping packet of size %zu to unknown connection 0x%0hx", log::error( "Dropping packet of size {} to unknown connection 0x{:x}", itr.size(), itr.GetHandle()); } Loading @@ -140,7 +142,7 @@ struct AclManager::impl { } static void on_unknown_acl_timer(struct AclManager::impl* impl) { LOG_INFO("Timer fired!"); log::info("Timer fired!"); impl->retry_unknown_acl(/* timed_out = */ true); impl->unknown_acl_alarm_.reset(); } Loading @@ -155,7 +157,7 @@ struct AclManager::impl { auto packet = hci_queue_end_->TryDequeue(); ASSERT(packet != nullptr); if (!packet->IsValid()) { LOG_INFO("Dropping invalid packet of size %zu", packet->size()); log::info("Dropping invalid packet of size {}", packet->size()); return; } uint16_t handle = packet->GetHandle(); Loading @@ -170,8 +172,8 @@ struct AclManager::impl { unknown_acl_alarm_.reset(new os::Alarm(handler_)); } waiting_packets_.push_back(*packet); LOG_INFO( "Saving packet of size %zu to unknown connection 0x%0hx", log::info( "Saving packet of size {} to unknown connection 0x{:x}", packet->size(), packet->GetHandle()); unknown_acl_alarm_->Schedule( Loading
system/gd/hci/acl_manager/acl_scheduler.cc +16 −12 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ #include "acl_scheduler.h" #include <bluetooth/log.h> #include <optional> #include <unordered_set> #include <variant> Loading Loading @@ -77,12 +79,12 @@ struct AclScheduler::impl { void ReportOutgoingAclConnectionFailure() { if (!outgoing_entry_.has_value()) { LOG_ERROR("Outgoing connection failure reported, but none present!"); log::error("Outgoing connection failure reported, but none present!"); return; } auto entry = std::get_if<AclCreateConnectionQueueEntry>(&outgoing_entry_.value()); if (entry == nullptr) { LOG_ERROR("Outgoing connection failure reported, but we're currently doing an RNR!"); log::error("Outgoing connection failure reported, but we're currently doing an RNR!"); return; } outgoing_entry_.reset(); Loading @@ -101,7 +103,8 @@ struct AclScheduler::impl { [&]() { cancel_connection.Invoke(); }, [&](auto /* entry */) { cancel_connection_completed.Invoke(); }); if (!ok) { LOG_ERROR("Attempted to cancel connection to %s that does not exist", log::error( "Attempted to cancel connection to {} that does not exist", ADDRESS_TO_LOGGABLE_CSTR(address)); } } Loading @@ -117,7 +120,7 @@ struct AclScheduler::impl { void ReportRemoteNameRequestCompletion(Address /* address */) { if (!outgoing_entry_.has_value()) { LOG_ERROR("Remote name request completion reported, but none taking place!"); log::error("Remote name request completion reported, but none taking place!"); return; } Loading @@ -125,11 +128,11 @@ struct AclScheduler::impl { [](auto&& entry) { using T = std::decay_t<decltype(entry)>; if constexpr (std::is_same_v<T, RemoteNameRequestQueueEntry>) { LOG_INFO("Remote name request completed"); log::info("Remote name request completed"); } else if constexpr (std::is_same_v<T, AclCreateConnectionQueueEntry>) { LOG_ERROR( "Received RNR completion when ACL connection is outstanding - assuming the connection has failed and " "continuing"); log::error( "Received RNR completion when ACL connection is outstanding - assuming the " "connection has failed and continuing"); } else { static_assert(!sizeof(T*), "non-exhaustive visitor!"); } Loading @@ -149,8 +152,9 @@ struct AclScheduler::impl { [&]() { cancel_request.Invoke(); }, [](auto entry) { std::get<RemoteNameRequestQueueEntry>(entry).callback_when_cancelled.Invoke(); }); if (!ok) { LOG_ERROR("Attempted to cancel remote name request " "to %s that does not exist", ADDRESS_TO_LOGGABLE_CSTR(address)); log::error( "Attempted to cancel remote name request to {} that does not exist", ADDRESS_TO_LOGGABLE_CSTR(address)); } }; Loading @@ -165,7 +169,7 @@ struct AclScheduler::impl { } if (incoming_connecting_address_set_.empty() && !outgoing_entry_.has_value() && !pending_outgoing_operations_.empty()) { LOG_INFO("Pending connections is not empty; so sending next connection"); log::info("Pending connections is not empty; so sending next connection"); auto entry = std::move(pending_outgoing_operations_.front()); pending_outgoing_operations_.pop_front(); std::visit([](auto&& variant) { variant.callback.Invoke(); }, entry); Loading
system/gd/hci/acl_manager/assembler.h +14 −7 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ #pragma once #include <bluetooth/log.h> #include <cstddef> #include <cstdint> #include <memory> Loading Loading @@ -98,30 +100,34 @@ struct assembler { PacketView<packet::kLittleEndian> payload = packet.GetPayload(); auto broadcast_flag = packet.GetBroadcastFlag(); if (broadcast_flag == BroadcastFlag::ACTIVE_PERIPHERAL_BROADCAST) { LOG_WARN("Dropping broadcast from remote"); log::warn("Dropping broadcast from remote"); return; } auto packet_boundary_flag = packet.GetPacketBoundaryFlag(); if (packet_boundary_flag == PacketBoundaryFlag::FIRST_NON_AUTOMATICALLY_FLUSHABLE) { LOG_ERROR("Controller is not allowed to send FIRST_NON_AUTOMATICALLY_FLUSHABLE to host except loopback mode"); log::error( "Controller is not allowed to send FIRST_NON_AUTOMATICALLY_FLUSHABLE to host except " "loopback mode"); return; } if (packet_boundary_flag == PacketBoundaryFlag::CONTINUING_FRAGMENT) { if (!recombination_stage_.ReceivedFirstPacket()) { LOG_ERROR("Continuing fragment received without previous first, dropping it."); log::error("Continuing fragment received without previous first, dropping it."); return; } recombination_stage_.AppendPacketView(payload); } else if (packet_boundary_flag == PacketBoundaryFlag::FIRST_AUTOMATICALLY_FLUSHABLE) { if (recombination_stage_.ReceivedFirstPacket()) { LOG_ERROR("Controller sent a starting packet without finishing previous packet. Drop previous one."); log::error( "Controller sent a starting packet without finishing previous packet. Drop previous " "one."); } recombination_stage_ = payload; } // Check the size of the packet size_t expected_size = GetL2capPduSize(recombination_stage_) + kL2capBasicFrameHeaderSize; if (expected_size < recombination_stage_.size()) { LOG_INFO("Packet size doesn't match L2CAP header, dropping it."); log::info("Packet size doesn't match L2CAP header, dropping it."); recombination_stage_ = PacketViewForRecombination(); return; } else if (expected_size > recombination_stage_.size()) { Loading @@ -129,7 +135,8 @@ struct assembler { return; } if (incoming_queue_.size() > kMaxQueuedPacketsPerConnection) { LOG_ERROR("Dropping packet from %s due to congestion", log::error( "Dropping packet from {} due to congestion", ADDRESS_TO_LOGGABLE_CSTR(address_with_type_)); recombination_stage_ = PacketViewForRecombination(); return; Loading