Skip to content

Commit

Permalink
pw_bluetooth_sapphire: Migrate ReadLocalSupportedCommands to emboss
Browse files Browse the repository at this point in the history
Delete SupportedCommand enum.

Bug: b/42167863
Test: fx test bt-host-gap-tests bt-host-fidl-tests
Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/1097198
GitOrigin-RevId: 5288adad98c519e6529a8d30f89bf52e562c6389
Change-Id: I0a57d300bb444b44aa91458a26f880681faf1d01
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/230540
Reviewed-by: Josh Conner <[email protected]>
Commit-Queue: Auto-Submit <[email protected]>
Pigweed-Auto-Submit: Ben Lawson <[email protected]>
Lint: Lint 🤖 <[email protected]>
  • Loading branch information
BenjaminLawson authored and CQ Bot Account committed Aug 28, 2024
1 parent 6338bfb commit 95d9586
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 652 deletions.
50 changes: 24 additions & 26 deletions pw_bluetooth_sapphire/host/gap/adapter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -775,9 +775,9 @@ void AdapterImpl::GetSupportedDelayRange(
pw::bluetooth::emboss::DataPathDirection direction,
const std::optional<std::vector<uint8_t>>& codec_configuration,
GetSupportedDelayRangeCallback cb) {
if (!state_.IsCommandSupported(
/*octet=*/45,
hci_spec::SupportedCommand::kReadLocalSupportedControllerDelay)) {
if (!state_.SupportedCommands()
.read_local_supported_controller_delay()
.Read()) {
bt_log(WARN,
"gap",
"read local supported controller delay command not supported");
Expand Down Expand Up @@ -967,18 +967,20 @@ void AdapterImpl::InitializeStep1() {
hci::EmbossCommandPacket::New<
pw::bluetooth::emboss::ReadLocalSupportedCommandsCommandView>(
hci_spec::kReadLocalSupportedCommands),
[this](const hci::EventPacket& cmd_complete) {
[this](const hci::EmbossEventPacket& cmd_complete) {
if (hci_is_error(cmd_complete,
WARN,
"gap",
"read local supported commands failed")) {
return;
}
auto params = cmd_complete.return_params<
hci_spec::ReadLocalSupportedCommandsReturnParams>();
std::memcpy(state_.supported_commands,
params->supported_commands,
sizeof(params->supported_commands));
auto view =
cmd_complete
.view<pw::bluetooth::emboss::
ReadLocalSupportedCommandsCommandCompleteEventView>();
std::copy(view.supported_commands().BackingStorage().begin(),
view.supported_commands().BackingStorage().end(),
state_.supported_commands);
});

// HCI_Read_Local_Supported_Features
Expand Down Expand Up @@ -1058,8 +1060,7 @@ void AdapterImpl::InitializeStep2() {

// If the controller supports the Read Buffer Size command then send it.
// Otherwise we'll default to 0 when initializing the ACLDataChannel.
if (state_.IsCommandSupported(/*octet=*/14,
hci_spec::SupportedCommand::kReadBufferSize)) {
if (state_.SupportedCommands().read_buffer_size().Read()) {
// HCI_Read_Buffer_Size
init_seq_runner_->QueueCommand(
hci::EmbossCommandPacket::New<
Expand Down Expand Up @@ -1130,9 +1131,9 @@ void AdapterImpl::InitializeStep2() {
cpp20::endian::little, params->le_states);
});

if (state_.IsCommandSupported(
/*octet=*/36,
hci_spec::SupportedCommand::kLEReadMaximumAdvertisingDataLength)) {
if (state_.SupportedCommands()
.le_read_maximum_advertising_data_length()
.Read()) {
// HCI_LE_Read_Maximum_Advertising_Data_Length
init_seq_runner_->QueueCommand(
hci::EmbossCommandPacket::New<
Expand Down Expand Up @@ -1166,8 +1167,7 @@ void AdapterImpl::InitializeStep2() {
hci_spec::kMaxLEAdvertisingDataLength;
}

if (state_.IsCommandSupported(
/*octet=*/41, hci_spec::SupportedCommand::kLEReadBufferSizeV2)) {
if (state_.SupportedCommands().le_read_buffer_size_v2().Read()) {
// HCI_LE_Read_Buffer_Size [v2]
init_seq_runner_->QueueCommand(
hci::EmbossCommandPacket::New<
Expand Down Expand Up @@ -1243,8 +1243,7 @@ void AdapterImpl::InitializeStep2() {
if (state_.features.HasBit(/*page=*/0u,
hci_spec::LMPFeature::kExtendedFeatures)) {
// HCI_Write_LE_Host_Support
if (!state_.IsCommandSupported(
/*octet=*/24, hci_spec::SupportedCommand::kWriteLEHostSupport)) {
if (!state_.SupportedCommands().write_le_host_support().Read()) {
bt_log(INFO, "gap", "LE Host is not supported");
} else {
bt_log(INFO, "gap", "LE Host is supported. Enabling LE Host mode");
Expand All @@ -1261,9 +1260,9 @@ void AdapterImpl::InitializeStep2() {
}

// HCI_Write_Secure_Connections_Host_Support
if (!state_.IsCommandSupported(
/*octet=*/32,
hci_spec::SupportedCommand::kWriteSecureConnectionsHostSupport)) {
if (!state_.SupportedCommands()
.write_secure_connections_host_support()
.Read()) {
bt_log(INFO, "gap", "Secure Connections (Host Support) is not supported");
} else {
bt_log(INFO,
Expand Down Expand Up @@ -1328,11 +1327,10 @@ void AdapterImpl::InitializeStep3() {
// The controller may not support SCO flow control (as implied by not
// supporting HCI_Write_Synchronous_Flow_Control_Enable), in which case we
// don't support HCI SCO on this controller yet.
// TODO(fxbug.dev/42171056): Support controllers that don't support SCO flow
// control.
bool sco_flow_control_supported = state_.IsCommandSupported(
/*octet=*/10,
hci_spec::SupportedCommand::kWriteSynchronousFlowControlEnable);
// TODO(fxbug.dev/42171056): Support controllers that don't support
// SCO flow control.
bool sco_flow_control_supported =
state_.SupportedCommands().write_synchronous_flow_control_enable().Read();
if (state_.sco_buffer_info.IsAvailable() && sco_flow_control_supported) {
// Enable SCO flow control.
auto sync_flow_control = hci::EmbossCommandPacket::New<
Expand Down
48 changes: 18 additions & 30 deletions pw_bluetooth_sapphire/host/gap/adapter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1471,10 +1471,10 @@ TEST_F(AdapterTest, LEReadMaximumAdvertisingDataLengthSupported) {
static_cast<uint64_t>(hci_spec::LMPFeature::kLESupportedHost);
settings.le_acl_data_packet_length = 0x1B;
settings.le_total_num_acl_data_packets = 2;
settings.SupportedCommandsView()
.le_read_maximum_advertising_data_length()
.Write(true);

constexpr size_t octet = 36;
settings.supported_commands[octet] |= static_cast<uint8_t>(
hci_spec::SupportedCommand::kLEReadMaximumAdvertisingDataLength);
test_device()->set_settings(settings);
test_device()->set_maximum_advertising_data_length(
hci_spec::kMaxLEExtendedAdvertisingDataLength);
Expand All @@ -1500,10 +1500,9 @@ TEST_F(AdapterTest, ScoDataChannelInitializedSuccessfully) {
settings.synchronous_data_packet_length = 6;
settings.total_num_synchronous_data_packets = 2;
// Enable SCO flow control command.
constexpr size_t flow_control_enable_octet = 10;
settings.supported_commands[flow_control_enable_octet] |=
static_cast<uint8_t>(
hci_spec::SupportedCommand::kWriteSynchronousFlowControlEnable);
settings.SupportedCommandsView()
.write_synchronous_flow_control_enable()
.Write(true);
test_device()->set_settings(settings);

bool success = false;
Expand All @@ -1520,11 +1519,9 @@ TEST_F(AdapterTest,
settings.AddBREDRSupportedCommands();
settings.lmp_features_page0 |=
static_cast<uint64_t>(hci_spec::LMPFeature::kLESupportedHost);
constexpr size_t flow_control_command_byte = 10;
constexpr uint8_t disable_flow_control_mask = ~static_cast<uint8_t>(
hci_spec::SupportedCommand::kWriteSynchronousFlowControlEnable);
settings.supported_commands[flow_control_command_byte] &=
disable_flow_control_mask;
settings.SupportedCommandsView()
.write_synchronous_flow_control_enable()
.Write(false);
settings.le_acl_data_packet_length = 5;
settings.le_total_num_acl_data_packets = 1;
// Ensure SCO buffers are available.
Expand All @@ -1551,10 +1548,9 @@ TEST_F(AdapterTest, ScoDataChannelNotInitializedBecauseBufferInfoNotAvailable) {
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;
settings.supported_commands[flow_control_enable_octet] |=
static_cast<uint8_t>(
hci_spec::SupportedCommand::kWriteSynchronousFlowControlEnable);
settings.SupportedCommandsView()
.write_synchronous_flow_control_enable()
.Write(true);
test_device()->set_settings(settings);

bool success = false;
Expand All @@ -1577,10 +1573,9 @@ TEST_F(AdapterScoAndIsoDisabledTest,
settings.synchronous_data_packet_length = 6;
settings.total_num_synchronous_data_packets = 2;
// Enable SCO flow control command.
constexpr size_t flow_control_enable_octet = 10;
settings.supported_commands[flow_control_enable_octet] |=
static_cast<uint8_t>(
hci_spec::SupportedCommand::kWriteSynchronousFlowControlEnable);
settings.SupportedCommandsView()
.write_synchronous_flow_control_enable()
.Write(true);
test_device()->set_settings(settings);

bool success = false;
Expand Down Expand Up @@ -1671,16 +1666,9 @@ void AdapterTest::GetSupportedDelayRangeHelper(
settings.le_total_num_acl_data_packets = 1;

// Enable or disable the "Read Local Supported Controller Delay" command
constexpr size_t kReadLocalSupportedControllerDelayOctet = 45;
if (supported) {
settings.supported_commands[kReadLocalSupportedControllerDelayOctet] |=
static_cast<uint8_t>(
hci_spec::SupportedCommand::kReadLocalSupportedControllerDelay);
} else {
settings.supported_commands[kReadLocalSupportedControllerDelayOctet] &=
~static_cast<uint8_t>(
hci_spec::SupportedCommand::kReadLocalSupportedControllerDelay);
}
settings.SupportedCommandsView()
.read_local_supported_controller_delay()
.Write(supported);

test_device()->set_settings(settings);

Expand Down
4 changes: 2 additions & 2 deletions pw_bluetooth_sapphire/host/gap/low_energy_connector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,8 @@ void LowEnergyConnector::StartInterrogation() {
state_.Set(State::kInterrogating);
auto peer = peer_cache_->FindById(peer_id_);
BT_ASSERT(peer);
bool sca_supported = adapter_state_.IsCommandSupported(
/*octet=*/43, hci_spec::SupportedCommand::kLERequestPeerSCA);
bool sca_supported =
adapter_state_.SupportedCommands().le_request_peer_sca().Read();
interrogator_.emplace(
peer->GetWeakPtr(), connection_->handle(), cmd_, sca_supported);
interrogator_->Start(
Expand Down
Loading

0 comments on commit 95d9586

Please sign in to comment.