Skip to content

Commit

Permalink
pw_bluetooth_sapphire: Migrate LE Read Buffer Size v1 event to Emboss
Browse files Browse the repository at this point in the history
Update Adapter tests to use minimum LE ACL packet size (0x1B) according
to spec. This is necessary because this minimum is enforced by Emboss.

Bug: b/42167863
Test: fx test bt-host-gap-tests
Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/1110339
GitOrigin-RevId: b72218517caa309e5fe04ad53121138105a0f087
Change-Id: Iaf2b0fe5dfdb40c8d08d118af83b3105ccdde0e9
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/235314
Commit-Queue: Ben Lawson <[email protected]>
Lint: Lint 🤖 <[email protected]>
Docs-Not-Needed: Ben Lawson <[email protected]>
Presubmit-Verified: CQ Bot Account <[email protected]>
Reviewed-by: Ben Lawson <[email protected]>
Reviewed-by: Faraaz Sareshwala <[email protected]>
Pigweed-Auto-Submit: Ben Lawson <[email protected]>
  • Loading branch information
BenjaminLawson authored and CQ Bot Account committed Sep 12, 2024
1 parent cff65b9 commit 9de41b0
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 30 deletions.
10 changes: 5 additions & 5 deletions pw_bluetooth_sapphire/host/gap/adapter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1210,17 +1210,17 @@ void AdapterImpl::InitializeStep2() {
hci::EmbossCommandPacket::New<
pw::bluetooth::emboss::LEReadBufferSizeCommandV1View>(
hci_spec::kLEReadBufferSizeV1),
[this](const hci::EventPacket& cmd_complete) {
[this](const hci::EmbossEventPacket& cmd_complete) {
if (hci_is_error(
cmd_complete, WARN, "gap", "LE read buffer size failed")) {
return;
}
auto params =
cmd_complete
.return_params<hci_spec::LEReadBufferSizeV1ReturnParams>();
uint16_t mtu = pw::bytes::ConvertOrderFrom(
cpp20::endian::little, params->hc_le_acl_data_packet_length);
uint8_t max_count = params->hc_total_num_le_acl_data_packets;
.view<pw::bluetooth::emboss::
LEReadBufferSizeV1CommandCompleteEventView>();
uint16_t mtu = params.le_acl_data_packet_length().Read();
uint8_t max_count = params.total_num_le_acl_data_packets().Read();
if (mtu && max_count) {
state_.low_energy_state.acl_data_buffer_info_ =
hci::DataBufferInfo(mtu, max_count);
Expand Down
18 changes: 9 additions & 9 deletions pw_bluetooth_sapphire/host/gap/adapter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ TEST_F(AdapterTest, InitializeNoBREDR) {
static_cast<uint64_t>(hci_spec::LMPFeature::kLESupportedHost);
settings.lmp_features_page0 |=
static_cast<uint64_t>(hci_spec::LMPFeature::kBREDRNotSupported);
settings.le_acl_data_packet_length = 5;
settings.le_acl_data_packet_length = 0x1B;
settings.le_total_num_acl_data_packets = 1;
test_device()->set_settings(settings);

Expand Down Expand Up @@ -245,7 +245,7 @@ TEST_F(AdapterTest, InitializeSuccess) {
FakeController::Settings settings;
settings.lmp_features_page0 |=
static_cast<uint64_t>(hci_spec::LMPFeature::kLESupportedHost);
settings.le_acl_data_packet_length = 5;
settings.le_acl_data_packet_length = 0x1B;
settings.le_total_num_acl_data_packets = 1;
test_device()->set_settings(settings);

Expand Down Expand Up @@ -1126,7 +1126,7 @@ TEST_F(AdapterTest, InspectHierarchy) {
settings.AddBREDRSupportedCommands();
settings.lmp_features_page0 |=
static_cast<uint64_t>(hci_spec::LMPFeature::kLESupportedHost);
settings.le_acl_data_packet_length = 5;
settings.le_acl_data_packet_length = 0x1B;
settings.le_total_num_acl_data_packets = 1;
settings.synchronous_data_packet_length = 6;
settings.total_num_synchronous_data_packets = 2;
Expand Down Expand Up @@ -1502,7 +1502,7 @@ TEST_F(AdapterTest, ScoDataChannelInitializedSuccessfully) {
settings.AddBREDRSupportedCommands();
settings.lmp_features_page0 |=
static_cast<uint64_t>(hci_spec::LMPFeature::kLESupportedHost);
settings.le_acl_data_packet_length = 5;
settings.le_acl_data_packet_length = 0x1B;
settings.le_total_num_acl_data_packets = 1;
// Ensure SCO buffers are available.
settings.synchronous_data_packet_length = 6;
Expand Down Expand Up @@ -1530,7 +1530,7 @@ TEST_F(AdapterTest,
settings.SupportedCommandsView()
.write_synchronous_flow_control_enable()
.Write(false);
settings.le_acl_data_packet_length = 5;
settings.le_acl_data_packet_length = 0x1B;
settings.le_total_num_acl_data_packets = 1;
// Ensure SCO buffers are available.
settings.synchronous_data_packet_length = 6;
Expand All @@ -1550,7 +1550,7 @@ TEST_F(AdapterTest, ScoDataChannelNotInitializedBecauseBufferInfoNotAvailable) {
settings.AddBREDRSupportedCommands();
settings.lmp_features_page0 |=
static_cast<uint64_t>(hci_spec::LMPFeature::kLESupportedHost);
settings.le_acl_data_packet_length = 5;
settings.le_acl_data_packet_length = 0x1B;
settings.le_total_num_acl_data_packets = 1;
// Ensure SCO buffers are not available.
settings.synchronous_data_packet_length = 1;
Expand All @@ -1575,7 +1575,7 @@ TEST_F(AdapterScoAndIsoDisabledTest,
settings.AddBREDRSupportedCommands();
settings.lmp_features_page0 |=
static_cast<uint64_t>(hci_spec::LMPFeature::kLESupportedHost);
settings.le_acl_data_packet_length = 5;
settings.le_acl_data_packet_length = 0x1B;
settings.le_total_num_acl_data_packets = 1;
// Ensure SCO buffers are available.
settings.synchronous_data_packet_length = 6;
Expand Down Expand Up @@ -1647,7 +1647,7 @@ TEST_F(AdapterTest, InitializeWriteSecureConnectionsHostSupport) {
static_cast<uint64_t>(hci_spec::LMPFeature::kExtendedFeatures);
settings.lmp_features_page1 |= static_cast<uint64_t>(
hci_spec::LMPFeature::kSecureConnectionsHostSupport);
settings.le_acl_data_packet_length = 5;
settings.le_acl_data_packet_length = 0x1B;
settings.le_total_num_acl_data_packets = 1;
test_device()->set_settings(settings);

Expand All @@ -1670,7 +1670,7 @@ void AdapterTest::GetSupportedDelayRangeHelper(
// Define minimum required settings for an LE controller
settings.lmp_features_page0 |=
static_cast<uint64_t>(hci_spec::LMPFeature::kLESupportedHost);
settings.le_acl_data_packet_length = 5;
settings.le_acl_data_packet_length = 0x1B;
settings.le_total_num_acl_data_packets = 1;

// Enable or disable the "Read Local Supported Controller Delay" command
Expand Down
17 changes: 9 additions & 8 deletions pw_bluetooth_sapphire/host/testing/fake_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1635,14 +1635,15 @@ void FakeController::OnLESetEventMask(
}

void FakeController::OnLEReadBufferSizeV1() {
hci_spec::LEReadBufferSizeV1ReturnParams params;
params.status = pwemb::StatusCode::SUCCESS;
params.hc_le_acl_data_packet_length = pw::bytes::ConvertOrderTo(
cpp20::endian::little, settings_.le_acl_data_packet_length);
params.hc_total_num_le_acl_data_packets =
settings_.le_total_num_acl_data_packets;
RespondWithCommandComplete(hci_spec::kLEReadBufferSizeV1,
BufferView(&params, sizeof(params)));
auto packet = hci::EmbossEventPacket::New<
pwemb::LEReadBufferSizeV1CommandCompleteEventWriter>(
hci_spec::kCommandCompleteEventCode);
auto view = packet.view_t();
view.status().Write(pwemb::StatusCode::SUCCESS);
view.le_acl_data_packet_length().Write(settings_.le_acl_data_packet_length);
view.total_num_le_acl_data_packets().Write(
settings_.le_total_num_acl_data_packets);
RespondWithCommandComplete(pwemb::OpCode::LE_READ_BUFFER_SIZE_V1, &packet);
}

void FakeController::OnLEReadBufferSizeV2() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -824,14 +824,6 @@ constexpr OpCode kLESetEventMask = LEControllerCommandOpCode(0x0001);
// LE Read Buffer Size [v1] Command (v4.0) (LE)
constexpr OpCode kLEReadBufferSizeV1 = LEControllerCommandOpCode(0x0002);

struct LEReadBufferSizeV1ReturnParams {
// See enum StatusCode in hci_constants.h.
StatusCode status;

uint16_t hc_le_acl_data_packet_length;
uint8_t hc_total_num_le_acl_data_packets;
} __attribute__((packed));

// ====================================================
// LE Read Local Supported Features Command (v4.0) (LE)
constexpr OpCode kLEReadLocalSupportedFeatures =
Expand Down

0 comments on commit 9de41b0

Please sign in to comment.