Skip to content

Commit

Permalink
pw_bluetooth_sapphire: Migrate ReadBufferSize event to emboss
Browse files Browse the repository at this point in the history
Bug: b/42167863
Test: fx test bt-host-gap-tests
Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/1096061
GitOrigin-RevId: 11df89844d3506cfd288cf42d3642540a1993cfa
Change-Id: I2394192edf5607f3c2122d1567515f98634fb584
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/230557
Reviewed-by: Lulu Wang <[email protected]>
Lint: Lint 🤖 <[email protected]>
Commit-Queue: Jason Graffius <[email protected]>
  • Loading branch information
BenjaminLawson authored and CQ Bot Account committed Aug 23, 2024
1 parent 5335b95 commit 4ca3507
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 39 deletions.
25 changes: 12 additions & 13 deletions pw_bluetooth_sapphire/host/gap/adapter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1065,27 +1065,26 @@ void AdapterImpl::InitializeStep2() {
hci::EmbossCommandPacket::New<
pw::bluetooth::emboss::ReadBufferSizeCommandView>(
hci_spec::kReadBufferSize),
[this](const hci::EventPacket& cmd_complete) {
[this](const hci::EmbossEventPacket& cmd_complete) {
if (hci_is_error(
cmd_complete, WARN, "gap", "read buffer size failed")) {
return;
}
auto params =
cmd_complete
.return_params<hci_spec::ReadBufferSizeReturnParams>();
uint16_t acl_mtu = pw::bytes::ConvertOrderFrom(
cpp20::endian::little, params->hc_acl_data_packet_length);
uint16_t acl_max_count = pw::bytes::ConvertOrderFrom(
cpp20::endian::little, params->hc_total_num_acl_data_packets);
auto packet = cmd_complete.view<
pw::bluetooth::emboss::ReadBufferSizeCommandCompleteEventView>();
uint16_t acl_mtu = packet.acl_data_packet_length().Read();
uint16_t acl_max_count = packet.total_num_acl_data_packets().Read();
if (acl_mtu && acl_max_count) {
state_.bredr_data_buffer_info =
hci::DataBufferInfo(acl_mtu, acl_max_count);
}
uint16_t sco_mtu = pw::bytes::ConvertOrderFrom(
cpp20::endian::little, params->hc_synchronous_data_packet_length);
uint16_t sco_max_count = pw::bytes::ConvertOrderFrom(
cpp20::endian::little,
params->hc_total_num_synchronous_data_packets);
// Use UncheckedRead because this field is supposed to
// be 0x01-0xFF, but it is possible and harmless for controllers to
// set to 0x00 if not supported.
uint16_t sco_mtu =
packet.synchronous_data_packet_length().UncheckedRead();
uint16_t sco_max_count =
packet.total_num_synchronous_data_packets().Read();
if (sco_mtu && sco_max_count) {
state_.sco_buffer_info =
hci::DataBufferInfo(sco_mtu, sco_max_count);
Expand Down
2 changes: 1 addition & 1 deletion pw_bluetooth_sapphire/host/gap/adapter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1548,7 +1548,7 @@ TEST_F(AdapterTest, ScoDataChannelNotInitializedBecauseBufferInfoNotAvailable) {
settings.le_acl_data_packet_length = 5;
settings.le_total_num_acl_data_packets = 1;
// Ensure SCO buffers are not available.
settings.synchronous_data_packet_length = 0;
settings.synchronous_data_packet_length = 1;
settings.total_num_synchronous_data_packets = 0;
// Enable SCO flow control command.
constexpr size_t flow_control_enable_octet = 10;
Expand Down
25 changes: 13 additions & 12 deletions pw_bluetooth_sapphire/host/testing/fake_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ void FakeController::Settings::ApplyDualModeDefaults() {
total_num_acl_data_packets = 1;
le_acl_data_packet_length = 512;
le_total_num_acl_data_packets = 1;
synchronous_data_packet_length = 0;
// Must be 0x01-0xFF, even if not supported
synchronous_data_packet_length = 1;
total_num_synchronous_data_packets = 0;
iso_data_packet_length = 512;
total_num_iso_data_packets = 1;
Expand Down Expand Up @@ -1934,17 +1935,17 @@ void FakeController::OnCreateConnectionCancel() {
}

void FakeController::OnReadBufferSize() {
hci_spec::ReadBufferSizeReturnParams params;
std::memset(&params, 0, sizeof(params));
params.hc_acl_data_packet_length = pw::bytes::ConvertOrderTo(
cpp20::endian::little, settings_.acl_data_packet_length);
params.hc_total_num_acl_data_packets = settings_.total_num_acl_data_packets;
params.hc_synchronous_data_packet_length =
settings_.synchronous_data_packet_length;
params.hc_total_num_synchronous_data_packets =
settings_.total_num_synchronous_data_packets;
RespondWithCommandComplete(hci_spec::kReadBufferSize,
BufferView(&params, sizeof(params)));
auto packet = hci::EmbossEventPacket::New<
pwemb::ReadBufferSizeCommandCompleteEventWriter>(
hci_spec::kCommandCompleteEventCode);
auto view = packet.view_t();
view.acl_data_packet_length().Write(settings_.acl_data_packet_length);
view.total_num_acl_data_packets().Write(settings_.total_num_acl_data_packets);
view.synchronous_data_packet_length().Write(
settings_.synchronous_data_packet_length);
view.total_num_synchronous_data_packets().Write(
settings_.total_num_synchronous_data_packets);
RespondWithCommandComplete(hci_spec::kReadBufferSize, &packet);
}

void FakeController::OnReadBRADDR() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -694,16 +694,6 @@ struct ReadLocalExtendedFeaturesReturnParams {
// Read Buffer Size Command (v1.1)
constexpr OpCode kReadBufferSize = InformationalParamsOpCode(0x0005);

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

uint16_t hc_acl_data_packet_length;
uint8_t hc_synchronous_data_packet_length;
uint16_t hc_total_num_acl_data_packets;
uint16_t hc_total_num_synchronous_data_packets;
} __attribute__((packed));

// ========================================
// Read BD_ADDR Command (v1.1) (BR/EDR, LE)
constexpr OpCode kReadBDADDR = InformationalParamsOpCode(0x0009);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ class FakeController final : public ControllerTestDoubleBase,
uint8_t supported_commands[64] = {0};

// Buffer Size.
uint16_t acl_data_packet_length = 0;
uint8_t total_num_acl_data_packets = 0;
uint16_t acl_data_packet_length = 1;
uint8_t total_num_acl_data_packets = 1;
uint16_t le_acl_data_packet_length = 0;
uint8_t le_total_num_acl_data_packets = 0;
uint8_t synchronous_data_packet_length = 0;
uint8_t synchronous_data_packet_length = 1;
uint8_t total_num_synchronous_data_packets = 0;
uint16_t iso_data_packet_length = 0;
uint8_t total_num_iso_data_packets = 0;
Expand Down

0 comments on commit 4ca3507

Please sign in to comment.