From 7ddafaf90088efac4c1bc6a56f92f9faa85fdc84 Mon Sep 17 00:00:00 2001 From: Ali Saeed Date: Thu, 6 Jun 2024 01:10:10 +0000 Subject: [PATCH] pw_bluetooth_proxy: Add ProxyHost::HasSendAclCapability() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also add AclDataChannel::GetLeAclCreditsToReserve(). Bug: 344030724 Change-Id: I348b35ac1a9e73d452b3c48545b1eb068f6af9b5 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/214101 Reviewed-by: David Rees Lint: Lint 🤖 Commit-Queue: Ali Saeed --- pw_bluetooth_proxy/acl_data_channel.cc | 4 ++++ pw_bluetooth_proxy/proxy_host.cc | 4 ++++ pw_bluetooth_proxy/proxy_host_test.cc | 10 ++++++++++ .../public/pw_bluetooth_proxy/acl_data_channel.h | 3 +++ .../public/pw_bluetooth_proxy/proxy_host.h | 5 +++++ 5 files changed, 26 insertions(+) diff --git a/pw_bluetooth_proxy/acl_data_channel.cc b/pw_bluetooth_proxy/acl_data_channel.cc index ed8bd1eb6e..2277fd7209 100644 --- a/pw_bluetooth_proxy/acl_data_channel.cc +++ b/pw_bluetooth_proxy/acl_data_channel.cc @@ -64,6 +64,10 @@ AclDataChannel::ProcessSpecificLEReadBufferSizeCommandCompleteEvent< emboss::LEReadBufferSizeV2CommandCompleteEventWriter>( emboss::LEReadBufferSizeV2CommandCompleteEventWriter read_buffer_event); +uint16_t AclDataChannel::GetLeAclCreditsToReserve() const { + return le_acl_credits_to_reserve_; +} + uint16_t AclDataChannel::GetNumFreeLeAclPackets() const { // TODO: https://pwbug.dev/326499611 - Subtract pending packets once we have // them. diff --git a/pw_bluetooth_proxy/proxy_host.cc b/pw_bluetooth_proxy/proxy_host.cc index 23b7d5daca..c3d384ece8 100644 --- a/pw_bluetooth_proxy/proxy_host.cc +++ b/pw_bluetooth_proxy/proxy_host.cc @@ -112,6 +112,10 @@ void ProxyHost::SendToController(H4HciPacket h4_packet) { outward_send_to_controller_fn_(h4_packet); } +bool ProxyHost::HasSendAclCapability() const { + return acl_data_channel_.GetLeAclCreditsToReserve() > 0; +} + uint16_t ProxyHost::GetNumFreeLeAclPackets() const { return acl_data_channel_.GetNumFreeLeAclPackets(); } diff --git a/pw_bluetooth_proxy/proxy_host_test.cc b/pw_bluetooth_proxy/proxy_host_test.cc index c3190eb174..5050ba6f8e 100644 --- a/pw_bluetooth_proxy/proxy_host_test.cc +++ b/pw_bluetooth_proxy/proxy_host_test.cc @@ -511,6 +511,8 @@ TEST(ReserveLeAclCredits, ProxyCreditsReserveCreditsWithLEReadBufferSizeV1) { EXPECT_EQ(proxy.GetNumFreeLeAclPackets(), 2); + EXPECT_TRUE(proxy.HasSendAclCapability()); + // Verify to controller callback was called. EXPECT_EQ(send_called, true); } @@ -551,6 +553,8 @@ TEST(ReserveLeAclCredits, ProxyCreditsReserveCreditsWithLEReadBufferSizeV2) { EXPECT_EQ(proxy.GetNumFreeLeAclPackets(), 2); + EXPECT_TRUE(proxy.HasSendAclCapability()); + // Verify to controller callback was called. EXPECT_EQ(send_called, true); } @@ -630,6 +634,8 @@ TEST(ReserveLeAclCredits, ProxyCreditsReserveZeroCredits) { EXPECT_EQ(proxy.GetNumFreeLeAclPackets(), 0); + EXPECT_FALSE(proxy.HasSendAclCapability()); + // Verify to controller callback was called. EXPECT_EQ(send_called, true); } @@ -669,6 +675,8 @@ TEST(ReserveLeAclPackets, ProxyCreditsZeroWhenHostCreditsZero) { EXPECT_EQ(proxy.GetNumFreeLeAclPackets(), 0); + EXPECT_TRUE(proxy.HasSendAclCapability()); + // Verify to controller callback was called. EXPECT_EQ(send_called, true); } @@ -683,6 +691,8 @@ TEST(ReserveLeAclPackets, ProxyCreditsZeroWhenNotInitialized) { std::move(send_to_host_fn), std::move(send_to_controller_fn), 2); EXPECT_EQ(proxy.GetNumFreeLeAclPackets(), 0); + + EXPECT_TRUE(proxy.HasSendAclCapability()); } } // namespace diff --git a/pw_bluetooth_proxy/public/pw_bluetooth_proxy/acl_data_channel.h b/pw_bluetooth_proxy/public/pw_bluetooth_proxy/acl_data_channel.h index b3e5018b95..cbb703f0e0 100644 --- a/pw_bluetooth_proxy/public/pw_bluetooth_proxy/acl_data_channel.h +++ b/pw_bluetooth_proxy/public/pw_bluetooth_proxy/acl_data_channel.h @@ -48,6 +48,9 @@ class AclDataChannel { ProcessSpecificLEReadBufferSizeCommandCompleteEvent(read_buffer_event); } + // Returns the number of LE ACL send credits reserved for the proxy. + uint16_t GetLeAclCreditsToReserve() const; + // Returns the number of available LE ACL send credits for the proxy. // Can be zero if the controller has not yet been initialized by the host. uint16_t GetNumFreeLeAclPackets() const; diff --git a/pw_bluetooth_proxy/public/pw_bluetooth_proxy/proxy_host.h b/pw_bluetooth_proxy/public/pw_bluetooth_proxy/proxy_host.h index 1172f2d578..546de7ad28 100644 --- a/pw_bluetooth_proxy/public/pw_bluetooth_proxy/proxy_host.h +++ b/pw_bluetooth_proxy/public/pw_bluetooth_proxy/proxy_host.h @@ -81,6 +81,11 @@ class ProxyHost { return pw::Status::Unimplemented(); } + /// Indicates whether the proxy has the capability of sending ACL packets. + /// Note that this indicates intention, so it can be true even if the proxy + /// has not yet or has been unable to reserve credits from the host. + bool HasSendAclCapability() const; + /// Returns the number of available LE ACL send credits for the proxy. /// Can be zero if the controller has not yet been initialized by the host. uint16_t GetNumFreeLeAclPackets() const;