Skip to content

Commit

Permalink
pw_bluetooth_proxy: Add ProxyHost::HasSendAclCapability()
Browse files Browse the repository at this point in the history
Also add AclDataChannel::GetLeAclCreditsToReserve().

Bug: 344030724
Change-Id: I348b35ac1a9e73d452b3c48545b1eb068f6af9b5
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/214101
Reviewed-by: David Rees <[email protected]>
Lint: Lint 🤖 <[email protected]>
Commit-Queue: Ali Saeed <[email protected]>
  • Loading branch information
acsaeed authored and CQ Bot Account committed Jun 6, 2024
1 parent 21bcbe6 commit 7ddafaf
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pw_bluetooth_proxy/acl_data_channel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions pw_bluetooth_proxy/proxy_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
10 changes: 10 additions & 0 deletions pw_bluetooth_proxy/proxy_host_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions pw_bluetooth_proxy/public/pw_bluetooth_proxy/proxy_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 7ddafaf

Please sign in to comment.