From 95d9586026ee8f67d69042f58bf23a1d23f46523 Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 28 Aug 2024 23:46:09 +0000 Subject: [PATCH] pw_bluetooth_sapphire: Migrate ReadLocalSupportedCommands to emboss MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Commit-Queue: Auto-Submit Pigweed-Auto-Submit: Ben Lawson Lint: Lint 🤖 --- pw_bluetooth_sapphire/host/gap/adapter.cc | 50 +- .../host/gap/adapter_test.cc | 48 +- .../host/gap/low_energy_connector.cc | 4 +- .../host/testing/fake_controller.cc | 191 +++---- .../internal/host/gap/adapter_state.h | 9 +- .../internal/host/hci-spec/constants.h | 464 ------------------ .../internal/host/hci-spec/protocol.h | 9 - .../internal/host/testing/fake_controller.h | 5 + 8 files changed, 128 insertions(+), 652 deletions(-) diff --git a/pw_bluetooth_sapphire/host/gap/adapter.cc b/pw_bluetooth_sapphire/host/gap/adapter.cc index 82127187a8..fe2004916a 100644 --- a/pw_bluetooth_sapphire/host/gap/adapter.cc +++ b/pw_bluetooth_sapphire/host/gap/adapter.cc @@ -775,9 +775,9 @@ void AdapterImpl::GetSupportedDelayRange( pw::bluetooth::emboss::DataPathDirection direction, const std::optional>& 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"); @@ -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(); + std::copy(view.supported_commands().BackingStorage().begin(), + view.supported_commands().BackingStorage().end(), + state_.supported_commands); }); // HCI_Read_Local_Supported_Features @@ -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< @@ -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< @@ -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< @@ -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"); @@ -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, @@ -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< diff --git a/pw_bluetooth_sapphire/host/gap/adapter_test.cc b/pw_bluetooth_sapphire/host/gap/adapter_test.cc index 26b1dd23fd..b38f16216e 100644 --- a/pw_bluetooth_sapphire/host/gap/adapter_test.cc +++ b/pw_bluetooth_sapphire/host/gap/adapter_test.cc @@ -1471,10 +1471,10 @@ TEST_F(AdapterTest, LEReadMaximumAdvertisingDataLengthSupported) { static_cast(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( - hci_spec::SupportedCommand::kLEReadMaximumAdvertisingDataLength); test_device()->set_settings(settings); test_device()->set_maximum_advertising_data_length( hci_spec::kMaxLEExtendedAdvertisingDataLength); @@ -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( - hci_spec::SupportedCommand::kWriteSynchronousFlowControlEnable); + settings.SupportedCommandsView() + .write_synchronous_flow_control_enable() + .Write(true); test_device()->set_settings(settings); bool success = false; @@ -1520,11 +1519,9 @@ TEST_F(AdapterTest, settings.AddBREDRSupportedCommands(); settings.lmp_features_page0 |= static_cast(hci_spec::LMPFeature::kLESupportedHost); - constexpr size_t flow_control_command_byte = 10; - constexpr uint8_t disable_flow_control_mask = ~static_cast( - 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. @@ -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( - hci_spec::SupportedCommand::kWriteSynchronousFlowControlEnable); + settings.SupportedCommandsView() + .write_synchronous_flow_control_enable() + .Write(true); test_device()->set_settings(settings); bool success = false; @@ -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( - hci_spec::SupportedCommand::kWriteSynchronousFlowControlEnable); + settings.SupportedCommandsView() + .write_synchronous_flow_control_enable() + .Write(true); test_device()->set_settings(settings); bool success = false; @@ -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( - hci_spec::SupportedCommand::kReadLocalSupportedControllerDelay); - } else { - settings.supported_commands[kReadLocalSupportedControllerDelayOctet] &= - ~static_cast( - hci_spec::SupportedCommand::kReadLocalSupportedControllerDelay); - } + settings.SupportedCommandsView() + .read_local_supported_controller_delay() + .Write(supported); test_device()->set_settings(settings); diff --git a/pw_bluetooth_sapphire/host/gap/low_energy_connector.cc b/pw_bluetooth_sapphire/host/gap/low_energy_connector.cc index 2ccd8278c4..6261e0ab74 100644 --- a/pw_bluetooth_sapphire/host/gap/low_energy_connector.cc +++ b/pw_bluetooth_sapphire/host/gap/low_energy_connector.cc @@ -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( diff --git a/pw_bluetooth_sapphire/host/testing/fake_controller.cc b/pw_bluetooth_sapphire/host/testing/fake_controller.cc index 9d5e7ca9cb..10ba8ba835 100644 --- a/pw_bluetooth_sapphire/host/testing/fake_controller.cc +++ b/pw_bluetooth_sapphire/host/testing/fake_controller.cc @@ -96,81 +96,53 @@ void FakeController::Settings::ApplyLEOnlyDefaults() { } void FakeController::Settings::AddBREDRSupportedCommands() { - SetBit(supported_commands + 0, hci_spec::SupportedCommand::kCreateConnection); - SetBit(supported_commands + 0, - hci_spec::SupportedCommand::kCreateConnectionCancel); - SetBit(supported_commands + 0, hci_spec::SupportedCommand::kDisconnect); - SetBit(supported_commands + 7, hci_spec::SupportedCommand::kWriteLocalName); - SetBit(supported_commands + 7, hci_spec::SupportedCommand::kReadLocalName); - SetBit(supported_commands + 7, hci_spec::SupportedCommand::kReadScanEnable); - SetBit(supported_commands + 7, hci_spec::SupportedCommand::kWriteScanEnable); - SetBit(supported_commands + 8, - hci_spec::SupportedCommand::kReadPageScanActivity); - SetBit(supported_commands + 8, - hci_spec::SupportedCommand::kWritePageScanActivity); - SetBit(supported_commands + 9, - hci_spec::SupportedCommand::kWriteClassOfDevice); - SetBit(supported_commands + 10, - hci_spec::SupportedCommand::kWriteSynchronousFlowControlEnable); - SetBit(supported_commands + 12, hci_spec::SupportedCommand::kReadInquiryMode); - SetBit(supported_commands + 12, - hci_spec::SupportedCommand::kWriteInquiryMode); - SetBit(supported_commands + 13, - hci_spec::SupportedCommand::kReadPageScanType); - SetBit(supported_commands + 13, - hci_spec::SupportedCommand::kWritePageScanType); - SetBit(supported_commands + 14, hci_spec::SupportedCommand::kReadBufferSize); - SetBit(supported_commands + 17, - hci_spec::SupportedCommand::kReadSimplePairingMode); - SetBit(supported_commands + 17, - hci_spec::SupportedCommand::kWriteSimplePairingMode); - SetBit(supported_commands + 17, - hci_spec::SupportedCommand::kWriteExtendedInquiryResponse); - SetBit(supported_commands + 32, - hci_spec::SupportedCommand::kWriteSecureConnectionsHostSupport); + auto view = SupportedCommandsView(); + view.create_connection().Write(true); + view.create_connection_cancel().Write(true); + view.disconnect().Write(true); + view.write_local_name().Write(true); + view.read_local_name().Write(true); + view.read_scan_enable().Write(true); + view.write_scan_enable().Write(true); + view.read_page_scan_activity().Write(true); + view.write_page_scan_activity().Write(true); + view.write_class_of_device().Write(true); + view.write_synchronous_flow_control_enable().Write(true); + view.read_inquiry_mode().Write(true); + view.write_inquiry_mode().Write(true); + view.read_page_scan_type().Write(true); + view.write_page_scan_type().Write(true); + view.read_buffer_size().Write(true); + view.read_simple_pairing_mode().Write(true); + view.write_simple_pairing_mode().Write(true); + view.write_extended_inquiry_response().Write(true); + view.write_secure_connections_host_support().Write(true); } void FakeController::Settings::AddLESupportedCommands() { - SetBit(supported_commands + 0, hci_spec::SupportedCommand::kDisconnect); - SetBit(supported_commands + 5, hci_spec::SupportedCommand::kSetEventMask); - SetBit(supported_commands + 5, hci_spec::SupportedCommand::kReset); - SetBit(supported_commands + 14, - hci_spec::SupportedCommand::kReadLocalVersionInformation); - SetBit(supported_commands + 14, - hci_spec::SupportedCommand::kReadLocalSupportedFeatures); - SetBit(supported_commands + 14, - hci_spec::SupportedCommand::kReadLocalExtendedFeatures); - SetBit(supported_commands + 24, - hci_spec::SupportedCommand::kWriteLEHostSupport); - SetBit(supported_commands + 25, hci_spec::SupportedCommand::kLESetEventMask); - SetBit(supported_commands + 25, - hci_spec::SupportedCommand::kLEReadBufferSizeV1); - SetBit(supported_commands + 25, - hci_spec::SupportedCommand::kLEReadLocalSupportedFeatures); - SetBit(supported_commands + 25, - hci_spec::SupportedCommand::kLESetRandomAddress); - SetBit(supported_commands + 25, - hci_spec::SupportedCommand::kLESetAdvertisingParameters); - SetBit(supported_commands + 25, - hci_spec::SupportedCommand::kLESetAdvertisingData); - SetBit(supported_commands + 26, - hci_spec::SupportedCommand::kLESetScanResponseData); - SetBit(supported_commands + 26, - hci_spec::SupportedCommand::kLESetAdvertisingEnable); - SetBit(supported_commands + 26, - hci_spec::SupportedCommand::kLECreateConnection); - SetBit(supported_commands + 26, - hci_spec::SupportedCommand::kLECreateConnectionCancel); - SetBit(supported_commands + 27, - hci_spec::SupportedCommand::kLEConnectionUpdate); - SetBit(supported_commands + 27, - hci_spec::SupportedCommand::kLEReadRemoteFeatures); - SetBit(supported_commands + 28, - hci_spec::SupportedCommand::kLEStartEncryption); - SetBit(supported_commands + 41, - hci_spec::SupportedCommand::kLEReadBufferSizeV2); - SetBit(supported_commands + 45, - hci_spec::SupportedCommand::kReadLocalSupportedControllerDelay); + auto view = SupportedCommandsView(); + view.disconnect().Write(true); + view.set_event_mask().Write(true); + view.reset().Write(true); + view.read_local_version_information().Write(true); + view.read_local_supported_features().Write(true); + view.read_local_extended_features().Write(true); + view.write_le_host_support().Write(true); + view.le_set_event_mask().Write(true); + view.le_read_buffer_size_v1().Write(true); + view.le_read_local_supported_features().Write(true); + view.le_set_random_address().Write(true); + view.le_set_advertising_parameters().Write(true); + view.le_set_advertising_data().Write(true); + view.le_set_scan_response_data().Write(true); + view.le_set_advertising_enable().Write(true); + view.le_create_connection().Write(true); + view.le_create_connection_cancel().Write(true); + view.le_connection_update().Write(true); + view.le_read_remote_features().Write(true); + view.le_start_encryption().Write(true); + view.le_read_buffer_size_v2().Write(true); + view.read_local_supported_controller_delay().Write(true); } void FakeController::Settings::ApplyLegacyLEConfig() { @@ -178,33 +150,27 @@ void FakeController::Settings::ApplyLegacyLEConfig() { hci_version = pwemb::CoreSpecificationVersion::V4_2; - SetBit(supported_commands + 26, - hci_spec::SupportedCommand::kLESetScanParameters); - SetBit(supported_commands + 26, hci_spec::SupportedCommand::kLESetScanEnable); + auto view = pwemb::MakeSupportedCommandsView(supported_commands, + sizeof(supported_commands)); + view.le_set_scan_parameters().Write(true); + view.le_set_scan_enable().Write(true); } void FakeController::Settings::ApplyExtendedLEConfig() { ApplyLEOnlyDefaults(); SetBit(&le_features, hci_spec::LESupportedFeature::kLEExtendedAdvertising); - SetBit(supported_commands + 36, - hci_spec::SupportedCommand::kLESetAdvertisingSetRandomAddress); - SetBit(supported_commands + 36, - hci_spec::SupportedCommand::kLESetExtendedAdvertisingParameters); - SetBit(supported_commands + 36, - hci_spec::SupportedCommand::kLESetExtendedAdvertisingData); - SetBit(supported_commands + 36, - hci_spec::SupportedCommand::kLESetExtendedScanResponseData); - SetBit(supported_commands + 36, - hci_spec::SupportedCommand::kLESetExtendedAdvertisingEnable); - SetBit(supported_commands + 36, - hci_spec::SupportedCommand::kLEReadMaximumAdvertisingDataLength); - SetBit(supported_commands + 36, - hci_spec::SupportedCommand::kLEReadNumberOfSupportedAdvertisingSets); - SetBit(supported_commands + 37, - hci_spec::SupportedCommand::kLERemoveAdvertisingSet); - SetBit(supported_commands + 37, - hci_spec::SupportedCommand::kLEClearAdvertisingSets); + + auto view = SupportedCommandsView(); + view.le_set_advertising_set_random_address().Write(true); + view.le_set_extended_advertising_parameters().Write(true); + view.le_set_extended_advertising_data().Write(true); + view.le_set_extended_scan_response_data().Write(true); + view.le_set_extended_advertising_enable().Write(true); + view.le_read_maximum_advertising_data_length().Write(true); + view.le_read_number_of_supported_advertising_sets().Write(true); + view.le_remove_advertising_set().Write(true); + view.le_clear_advertising_sets().Write(true); } void FakeController::Settings::ApplyAndroidVendorExtensionDefaults() { @@ -2190,13 +2156,15 @@ void FakeController::OnReadLocalSupportedFeatures() { } void FakeController::OnReadLocalSupportedCommands() { - hci_spec::ReadLocalSupportedCommandsReturnParams params; - params.status = pwemb::StatusCode::SUCCESS; - std::memcpy(params.supported_commands, + auto packet = hci::EmbossEventPacket::New< + pwemb::ReadLocalSupportedCommandsCommandCompleteEventWriter>( + hci_spec::kCommandCompleteEventCode); + auto view = packet.view_t(); + view.status().Write(pwemb::StatusCode::SUCCESS); + std::memcpy(view.supported_commands().BackingStorage().begin(), settings_.supported_commands, - sizeof(params.supported_commands)); - RespondWithCommandComplete(hci_spec::kReadLocalSupportedCommands, - BufferView(¶ms, sizeof(params))); + sizeof(settings_.supported_commands)); + RespondWithCommandComplete(hci_spec::kReadLocalSupportedCommands, &packet); } void FakeController::OnReadLocalVersionInfo() { @@ -2615,12 +2583,9 @@ void FakeController::OnLEStartEncryptionCommand( void FakeController::OnWriteSynchronousFlowControlEnableCommand( const pwemb::WriteSynchronousFlowControlEnableCommandView& params) { - constexpr size_t flow_control_enable_octet = 10; - bool supported = - settings_.supported_commands[flow_control_enable_octet] & - static_cast( - hci_spec::SupportedCommand::kWriteSynchronousFlowControlEnable); - if (!supported) { + if (!settings_.SupportedCommandsView() + .write_synchronous_flow_control_enable() + .Read()) { RespondWithCommandComplete(hci_spec::kWriteSynchronousFlowControlEnable, pwemb::StatusCode::UNKNOWN_COMMAND); return; @@ -3301,12 +3266,9 @@ void FakeController::OnLESetExtendedAdvertisingEnable( } void FakeController::OnLEReadMaximumAdvertisingDataLength() { - constexpr size_t octet = 36; - constexpr hci_spec::SupportedCommand command = - hci_spec::SupportedCommand::kLEReadMaximumAdvertisingDataLength; - bool supported = - settings_.supported_commands[octet] & static_cast(command); - if (!supported) { + if (!settings_.SupportedCommandsView() + .le_read_maximum_advertising_data_length() + .Read()) { RespondWithCommandComplete(hci_spec::kLEReadMaximumAdvertisingDataLength, pwemb::StatusCode::UNKNOWN_COMMAND); } @@ -3435,10 +3397,9 @@ void FakeController::OnReadLocalSupportedControllerDelay( pwemb::ReadLocalSupportedControllerDelayCommandCompleteEventWriter>( hci_spec::kCommandCompleteEventCode); auto response_view = packet.view_t(); - constexpr size_t kReadLocalSupportedControllerDelayOctet = 45; - if (settings_.supported_commands[kReadLocalSupportedControllerDelayOctet] & - static_cast( - hci_spec::SupportedCommand::kReadLocalSupportedControllerDelay)) { + if (settings_.SupportedCommandsView() + .read_local_supported_controller_delay() + .Read()) { response_view.status().Write(pwemb::StatusCode::SUCCESS); response_view.min_controller_delay().Write(0); // no delay response_view.max_controller_delay().Write( diff --git a/pw_bluetooth_sapphire/public/pw_bluetooth_sapphire/internal/host/gap/adapter_state.h b/pw_bluetooth_sapphire/public/pw_bluetooth_sapphire/internal/host/gap/adapter_state.h index 8238453fb9..4c14a8f137 100644 --- a/pw_bluetooth_sapphire/public/pw_bluetooth_sapphire/internal/host/gap/adapter_state.h +++ b/pw_bluetooth_sapphire/public/pw_bluetooth_sapphire/internal/host/gap/adapter_state.h @@ -69,12 +69,9 @@ struct AdapterState final { hci_spec::LMPFeature::kSecureConnectionsHostSupport); } - // Returns true if |command_bit| in the given |octet| is set in the supported - // command list. - inline bool IsCommandSupported(size_t octet, - hci_spec::SupportedCommand command_bit) const { - BT_DEBUG_ASSERT(octet < sizeof(supported_commands)); - return supported_commands[octet] & static_cast(command_bit); + inline auto SupportedCommands() const { + return pw::bluetooth::emboss::MakeSupportedCommandsView( + supported_commands, sizeof(supported_commands)); } // HCI version supported by the controller. diff --git a/pw_bluetooth_sapphire/public/pw_bluetooth_sapphire/internal/host/hci-spec/constants.h b/pw_bluetooth_sapphire/public/pw_bluetooth_sapphire/internal/host/hci-spec/constants.h index ba35713ed9..69faf68028 100644 --- a/pw_bluetooth_sapphire/public/pw_bluetooth_sapphire/internal/host/hci-spec/constants.h +++ b/pw_bluetooth_sapphire/public/pw_bluetooth_sapphire/internal/host/hci-spec/constants.h @@ -133,470 +133,6 @@ enum class LMPFeature : uint64_t { kTrainNudging = (1ull << 11) }; -// Bitmask values for the 64-octet Supported Commands bit-field. See Core Spec -// v5.0, Volume 2, Part E, Section 6.27 "Supported Commands". -enum class SupportedCommand : uint8_t { - // Octet 0 - kInquiry = (1 << 0), - kInquiryCancel = (1 << 1), - kPeriodicInquiryMode = (1 << 2), - kExitPeriodicInquiryMode = (1 << 3), - kCreateConnection = (1 << 4), - kDisconnect = (1 << 5), - kAddSCOConnection = (1 << 6), // deprecated - kCreateConnectionCancel = (1 << 7), - - // Octet 1 - kAcceptConnectionRequest = (1 << 0), - kRejectConnectionRequest = (1 << 1), - kLinkKeyRequestReply = (1 << 2), - kLinkKeyRequestNegativeReply = (1 << 3), - kPINCodeRequestReply = (1 << 4), - kPINCodeRequestNegativeReply = (1 << 5), - kChangeConnectionPacketType = (1 << 6), - kAuthenticationRequested = (1 << 7), - - // Octet 2 - kSetConnectionEncryption = (1 << 0), - kChangeConnectionLinkKey = (1 << 1), - kLinkKeySelection = (1 << 2), - kRemoteNameRequest = (1 << 3), - kRemoteNameRequestCancel = (1 << 4), - kReadRemoteSupportedFeatures = (1 << 5), - kReadRemoteExtendedFeatures = (1 << 6), - kReadRemoteVersionInformation = (1 << 7), - - // Octet 3 - kReadClockOffset = (1 << 0), - kReadLMPHandle = (1 << 1), - // kReserved = (1 << 2), - // kReserved = (1 << 3), - // kReserved = (1 << 4), - // kReserved = (1 << 5), - // kReserved = (1 << 6), - // kReserved = (1 << 7), - - // Octet 4 - // kReserved = (1 << 0), - kHoldMode = (1 << 1), - kSniffMode = (1 << 2), - kExitSniffMode = (1 << 3), - kParkState = (1 << 4), // reserved in 5.0 - kExitParkState = (1 << 5), // reserved in 5.0 - kQOSSetup = (1 << 6), - kRoleDiscovery = (1 << 7), - - // Octet 5 - kSwitchRole = (1 << 0), - kReadLinkPolicySettings = (1 << 1), - kWriteLinkPolicySettings = (1 << 2), - kReadDefaultLinkPolicySettings = (1 << 3), - kWriteDefaultLinkPolicySettings = (1 << 4), - kFlowSpecification = (1 << 5), - kSetEventMask = (1 << 6), - kReset = (1 << 7), - - // Octet 6 - kSetEventFilter = (1 << 0), - kFlush = (1 << 1), - kReadPINType = (1 << 2), - kWritePINType = (1 << 3), - kCreateNewUnitKey = (1 << 4), // reserved in 5.0 - kReadStoredLinkKey = (1 << 5), - kWriteStoredLinkKey = (1 << 6), - kDeletedStoredLinkKey = (1 << 7), - - // Octet 7 - kWriteLocalName = (1 << 0), - kReadLocalName = (1 << 1), - kReadConnectionAttemptTimeout = (1 << 2), - kWriteConnectionAttemptTimeout = (1 << 3), - kReadPageTimeout = (1 << 4), - kWritePageTimeout = (1 << 5), - kReadScanEnable = (1 << 6), - kWriteScanEnable = (1 << 7), - - // Octet 8 - kReadPageScanActivity = (1 << 0), - kWritePageScanActivity = (1 << 1), - kReadInquiryScanActivity = (1 << 2), - kWriteInquiryScanActivity = (1 << 3), - kReadAuthenticationEnable = (1 << 4), - kWriteAuthenticationEnable = (1 << 5), - kReadEncryptionMode = (1 << 6), // deprecated - kWriteEncryptionMode = (1 << 7), // deprecated - - // Octet 9 - kReadClassOfDevice = (1 << 0), - kWriteClassOfDevice = (1 << 1), - kReadVoiceSetting = (1 << 2), - kWriteVoiceSetting = (1 << 3), - kReadAutomaticFlushTimeout = (1 << 4), - kWriteAutomaticFlushTimeout = (1 << 5), - kReadNumBroadcastRetransmissions = (1 << 6), - kWriteNumBroadcastRetransmissions = (1 << 7), - - // Octet 10 - kReadHoldModeActivity = (1 << 0), - kWriteHoldModeActivity = (1 << 1), - kReadTransmitPowerLevel = (1 << 2), - kReadSynchronousFlowControlEnable = (1 << 3), - kWriteSynchronousFlowControlEnable = (1 << 4), - kSetControllerToHostFlowControl = (1 << 5), - kHostBufferSize = (1 << 6), - kHostNumberOfCompletedPackets = (1 << 7), - - // Octet 11 - kReadLinkSupervisionTimeout = (1 << 0), - kWriteLinkSupervisionTimeout = (1 << 1), - kReadNumberOfSupportedIAC = (1 << 2), - kReadCurrentIACLAP = (1 << 3), - kWriteCurrentIACLAP = (1 << 4), - kReadPageScanModePeriod = (1 << 5), // deprecated - kWritePageScanModePeriod = (1 << 6), // deprecated - kReadPageScanMode = (1 << 7), // deprecated - - // Octet 12 - kWritePageScanMode = (1 << 0), // deprecated - kSetAFHHostChannelClassification = (1 << 1), - // kReserved = (1 << 2), - // kReserved = (1 << 3), - kReadInquiryScanType = (1 << 4), - kWriteInquiryScanType = (1 << 5), - kReadInquiryMode = (1 << 6), - kWriteInquiryMode = (1 << 7), - - // Octet 13 - kReadPageScanType = (1 << 0), - kWritePageScanType = (1 << 1), - kReadAFHChannelAssessmentMode = (1 << 2), - kWriteAFHChannelAssessmentMode = (1 << 3), - // kReserved = (1 << 4), - // kReserved = (1 << 5), - // kReserved = (1 << 6), - // kReserved = (1 << 7), - - // Octet 14 - // kReserved = (1 << 0), - // kReserved = (1 << 1), - // kReserved = (1 << 2), - kReadLocalVersionInformation = (1 << 3), - // kReserved = (1 << 4), - kReadLocalSupportedFeatures = (1 << 5), - kReadLocalExtendedFeatures = (1 << 6), - kReadBufferSize = (1 << 7), - - // Octet 15 - kReadCountryCode = (1 << 0), // deprecated - kReadBDADDR = (1 << 1), - kReadFailedContactCounter = (1 << 2), - kResetFailedContactCOunter = (1 << 3), - kReadLinkQuality = (1 << 4), - kReadRSSI = (1 << 5), - kReadAFHChannelMap = (1 << 6), - kReadClock = (1 << 7), - - // Octet 16 - kReadLoopbackMode = (1 << 0), - kWriteLoopbackMode = (1 << 1), - kEnableDeviceUnderTestMode = (1 << 2), - kSetupSynchronousConnectionRequest = (1 << 3), - kAcceptSynchronousConnectionRequest = (1 << 4), - kRejectSynchronousConnectionRequest = (1 << 5), - // kReserved = (1 << 6), - // kReserved = (1 << 7), - - // Octet 17 - kReadExtendedInquiryResponse = (1 << 0), - kWriteExtendedInquiryResponse = (1 << 1), - kRefreshEncryptionKey = (1 << 2), - // kReserved = (1 << 3), - kSniffSubrating = (1 << 4), - kReadSimplePairingMode = (1 << 5), - kWriteSimplePairingMode = (1 << 6), - kReadLocalOOBData = (1 << 7), - - // Octet 18 - kReadInquiryResponseTransmitPowerLevel = (1 << 0), - kWriteInquiryTransmitPowerLevel = (1 << 1), - kReadDefaultErroneousDataReporting = (1 << 2), - kWriteDefaultErroneousDataReporting = (1 << 3), - // kReserved = (1 << 4), - // kReserved = (1 << 5), - // kReserved = (1 << 6), - kIOCapabilityRequestReply = (1 << 7), - - // Octet 19 - kUserConfirmationRequestReply = (1 << 0), - kUserConfirmationRequestNegativeReply = (1 << 1), - kUserPasskeyRequestReply = (1 << 2), - kUserPasskeyRequestNegativeReply = (1 << 3), - kRemoteOOBDataRequestReply = (1 << 4), - kWriteSimplePairingDebugMode = (1 << 5), - kEnhancedFlush = (1 << 6), - kRemoteOOBDataRequestNegativeReply = (1 << 7), - - // Octet 20 - // kReserved = (1 << 0), - // kReserved = (1 << 1), - kSendKeypressNotification = (1 << 2), - kIOCapabilityRequestNegativeReply = (1 << 3), - kReadEncryptionKeySize = (1 << 4), - // kReserved = (1 << 5), - // kReserved = (1 << 6), - // kReserved = (1 << 7), - - // Octet 21 - kCreatePhysicalLink = (1 << 0), - kAcceptPhysicalLink = (1 << 1), - kDisconnectPhysicalLink = (1 << 2), - kCreateLogicalLink = (1 << 3), - kAcceptLogicalLink = (1 << 4), - kDisconnectLogicalLink = (1 << 5), - kLogicalLinkCancel = (1 << 6), - kFlowSpecModify = (1 << 7), - - // Octet 22 - kReadLogicalLinkAcceptTimeout = (1 << 0), - kWriteLogicalLinkAcceptTimeout = (1 << 1), - kSetEventMaskPage2 = (1 << 2), - kReadLocationData = (1 << 3), - kWriteLocationData = (1 << 4), - kReadLocalAMPInfo = (1 << 5), - kReadLocalAMPASSOC = (1 << 6), - kWriteRemoteAMPASSOC = (1 << 7), - - // Octet 23 - kReadFlowControlMode = (1 << 0), - kWriteFlowControlMode = (1 << 1), - kReadDataBlockSize = (1 << 2), - // kReserved = (1 << 3), - // kReserved = (1 << 4), - kEnableAMPReceiverReports = (1 << 5), - kAMPTestEnd = (1 << 6), - kAMPTest = (1 << 7), - - // Octet 24 - kReadEnhancedTransmitPowerLevel = (1 << 0), - // kReserved = (1 << 1), - kReadBestEffortFlushTimeout = (1 << 2), - kWriteBestEffortFlushTimeout = (1 << 3), - kShortRangeMode = (1 << 4), - kReadLEHostSupported = (1 << 5), - kWriteLEHostSupport = (1 << 6), - // kReserved = (1 << 7), - - // Octet 25 - kLESetEventMask = (1 << 0), - kLEReadBufferSizeV1 = (1 << 1), - kLEReadLocalSupportedFeatures = (1 << 2), - // kReserved = (1 << 3), - kLESetRandomAddress = (1 << 4), - kLESetAdvertisingParameters = (1 << 5), - kLEReadAdvertisingChannelTXPower = (1 << 6), - kLESetAdvertisingData = (1 << 7), - - // Octet 26 - kLESetScanResponseData = (1 << 0), - kLESetAdvertisingEnable = (1 << 1), - kLESetScanParameters = (1 << 2), - kLESetScanEnable = (1 << 3), - kLECreateConnection = (1 << 4), - kLECreateConnectionCancel = (1 << 5), - kLEReadFilterAcceptListSize = (1 << 6), - kLEClearFilterAcceptList = (1 << 7), - - // Octet 27 - kLEAddDeviceToFilterAcceptList = (1 << 0), - kLERemoveDeviceFromFilterAcceptList = (1 << 1), - kLEConnectionUpdate = (1 << 2), - kLESetHostChannelClassification = (1 << 3), - kLEReadChannelMap = (1 << 4), - kLEReadRemoteFeatures = (1 << 5), - kLEEncrypt = (1 << 6), - kLERand = (1 << 7), - - // Octet 28 - kLEStartEncryption = (1 << 0), - kLELongTermKeyRequestReply = (1 << 1), - kLELongTermKeyRequestNegativeReply = (1 << 2), - kLEReadSupportedStates = (1 << 3), - kLEReceiverTestV1 = (1 << 4), - kLETransmitterTestV1 = (1 << 5), - kLETestEnd = (1 << 6), - // kReserved = (1 << 7), - - // Octet 29 - // kReserved = (1 << 0), - // kReserved = (1 << 1), - // kReserved = (1 << 2), - kEnhancedSetupSynchronousConnection = (1 << 3), - kEnhancedAcceptSynchronousConnection = (1 << 4), - kReadLocalSupportedCodecs = (1 << 5), - kSetMWSChannelParameters = (1 << 6), - kSetExternalFrameConfiguration = (1 << 7), - - // Octet 30 - kSetMWSSignaling = (1 << 0), - kSetMWSTransportLayer = (1 << 1), - kSetMWSScanFrequencyTable = (1 << 2), - kGetMWSTransportLayerConfiguration = (1 << 3), - kSetMWSPATTERNConfiguration = (1 << 4), - kSetTriggeredClockCapture = (1 << 5), - kTruncatedPage = (1 << 6), - kTruncatedPageCancel = (1 << 7), - - // Octet 31 - kSetConnectionlessPeripheralBroadcast = (1 << 0), - kSetConnectionlessPeripheralBroadcastReceive = (1 << 1), - kStartSynchronizationTrain = (1 << 2), - kReceiveSynchronizationTrain = (1 << 3), - kSetReservedLTADDR = (1 << 4), - kDeleteReservedLTADDR = (1 << 5), - kSetConnectionlessPeripheralBroadcastData = (1 << 6), - kReadSynchronizationTrainParameters = (1 << 7), - - // Octet 32 - kWriteSynchronizationTrainParameters = (1 << 0), - kRemoteOOBExtendedDataRequestReply = (1 << 1), - kReadSecureConnectionsHostSupport = (1 << 2), - kWriteSecureConnectionsHostSupport = (1 << 3), - kReadAuthenticatedPayloadTimeout = (1 << 4), - kWriteAuthenticatedPayloadTimeout = (1 << 5), - kReadLocalOOBExtendedData = (1 << 6), - kWriteSecureConnectionsTestMode = (1 << 7), - - // Octet 33 - kReadExtendedPageTimeout = (1 << 0), - kWriteExtendedPageTimeout = (1 << 1), - kReadExtendedInquiryLength = (1 << 2), - kWriteExtendedInquiryLength = (1 << 3), - kLERemoteConnectionParameterRequestReply = (1 << 4), - kLERemoteConnectionParameterRequestNegativeReply = (1 << 5), - kLESetDataLength = (1 << 6), - kLEReadSuggestedDefaultDataLength = (1 << 7), - - // Octet 34 - kLEWriteSuggestedDefaultDataLength = (1 << 0), - kLEReadLocalP256PublicKey = (1 << 1), - kLEGenerateDHKeyV1 = (1 << 2), - kLEAddDeviceToResolvingList = (1 << 3), - kLERemoveDeviceFromResolvingList = (1 << 4), - kLEClearResolvingList = (1 << 5), - kLEReadResolvingListSize = (1 << 6), - kLEReadPeerResolvableAddress = (1 << 7), - - // Octet 35 - kLEReadLocalResolvableAddress = (1 << 0), - kLESetAddressResolutionEnable = (1 << 1), - kLESetResolvablePrivateAddressTimeout = (1 << 2), - kLEReadMaximumDataLength = (1 << 3), - kLEReadPHY = (1 << 4), - kLESetDefaultPHY = (1 << 5), - kLESetPHY = (1 << 6), - kLEEnhancedReceiverTestV2 = (1 << 7), - - // Octet 36 - kLEEnhancedTransmitterTestV2 = (1 << 0), - kLESetAdvertisingSetRandomAddress = (1 << 1), - kLESetExtendedAdvertisingParameters = (1 << 2), - kLESetExtendedAdvertisingData = (1 << 3), - kLESetExtendedScanResponseData = (1 << 4), - kLESetExtendedAdvertisingEnable = (1 << 5), - kLEReadMaximumAdvertisingDataLength = (1 << 6), - kLEReadNumberOfSupportedAdvertisingSets = (1 << 7), - - // Octet 37 - kLERemoveAdvertisingSet = (1 << 0), - kLEClearAdvertisingSets = (1 << 1), - kLESetPeriodicAdvertisingParameters = (1 << 2), - kLESetPeriodicAdvertisingData = (1 << 3), - kLESetPeriodicAdvertisingEnable = (1 << 4), - kLESetExtendedScanParameters = (1 << 5), - kLESetExtendedScanEnable = (1 << 6), - kLEExtendedCreateConnection = (1 << 7), - - // Octet 38 - kLEPeriodicAdvertisingCreateSync = (1 << 0), - kLEPeriodicAdvertisingCreateSyncCancel = (1 << 1), - kLEPeriodicAdvertisingTerminateSync = (1 << 2), - kLEAddDeviceToPeriodicAdvertiserList = (1 << 3), - kLERemoveDeviceFromPeriodicAdvertiserList = (1 << 4), - kLEClearPeriodicAdvertiserList = (1 << 5), - kLEReadPeriodicAdvertiserListSize = (1 << 6), - kLEReadTransmitPower = (1 << 7), - - // Octet 39 - kLEReadRFPathCompensation = (1 << 0), - kLEWriteRFPathCompensation = (1 << 1), - kLESetPrivacyMode = (1 << 2), - kLEReceiverTestV3 = (1 << 3), - kLETransmitterTestV3 = (1 << 4), - kLESetConnectionlessCTETransmitParameters = (1 << 5), - kLESetConnectionlessCTETransmitEnable = (1 << 6), - kLESetConnectionlessIQSamplingEnable = (1 << 7), - - // Octet 40 - kLESetConnectionCTEReceiveParameters = (1 << 0), - kLESetConnectionCTETransmitParameters = (1 << 1), - kLEConnectionCTERequestEnable = (1 << 2), - kLEConnectionCTEResponseEnable = (1 << 3), - kLEReadAntennaInformation = (1 << 4), - kLESetPeriodicAdvertisingReceiveEnable = (1 << 5), - kLEPeriodicAdvertisingSyncTransfer = (1 << 6), - kLEPeriodicAdvertisingSetInfoTransfer = (1 << 7), - - // Octet 41 - kLESetPeriodicAdvertisingSyncTransferParameters = (1 << 0), - kLESetDefaultPeriodicAdvertisingSyncTransferParameters = (1 << 1), - kLEGenerateDHKeyV3 = (1 << 2), - kReadLocalSimplePairingOptions = (1 << 3), - kLEModifySleepClockAccuracy = (1 << 4), - kLEReadBufferSizeV2 = (1 << 5), - kLEReadISOTXSync = (1 << 6), - kLESetCIGParameters = (1 << 7), - - // Octet 42 - kLESetCIGParametersTest = (1 << 0), - kLECreateCIS = (1 << 1), - kLERemoveCIG = (1 << 2), - kLEAcceptCISRequest = (1 << 3), - kLERejectCISRequest = (1 << 4), - kLECreateBIG = (1 << 5), - kLECreateBIGTest = (1 << 6), - kLETerminateBIG = (1 << 7), - - // Octet 43 - kLEBIGCreateSync = (1 << 0), - kLEBIGTerminateSync = (1 << 1), - kLERequestPeerSCA = (1 << 2), - kLESetupISODataPath = (1 << 3), - kLERemoveISODataPath = (1 << 4), - kLEISOTransmitTest = (1 << 5), - kLEISOReceiveTest = (1 << 6), - kLEISOReadTestCounters = (1 << 7), - - // Octet 44 - kLEISOTestEnd = (1 << 0), - kLESetHostFeature = (1 << 1), - kLEReadISOLinkQuality = (1 << 2), - kLEEnhancedReadTransmitPowerLevel = (1 << 3), - kLEReadRemoteTransmitPowerLevel = (1 << 4), - kLESetPathLossReportingParameters = (1 << 5), - kLESetPathLossReportingEnable = (1 << 6), - kLESetTransmitPowerReportingEnable = (1 << 7), - - // Octet 45 - kLETransmitterTestV4 = (1 << 0), - kSetEcosystemBaseInterval = (1 << 1), - kReadLocalSupportedCodecsV2 = (1 << 2), - kReadLocalSupportedCodecCapabilities = (1 << 3), - kReadLocalSupportedControllerDelay = (1 << 4), - kConfigureDataPath = (1 << 5), - // kReserved = (1 << 6), - // kReserved = (1 << 7), -}; - // Bitmask of 8-octet LE supported features field. See Core Spec // v5.0, Volume 6, Part B, Section 4.6 "Feature Support". struct LESupportedFeatures { diff --git a/pw_bluetooth_sapphire/public/pw_bluetooth_sapphire/internal/host/hci-spec/protocol.h b/pw_bluetooth_sapphire/public/pw_bluetooth_sapphire/internal/host/hci-spec/protocol.h index 01e079f221..fe3282edb4 100644 --- a/pw_bluetooth_sapphire/public/pw_bluetooth_sapphire/internal/host/hci-spec/protocol.h +++ b/pw_bluetooth_sapphire/public/pw_bluetooth_sapphire/internal/host/hci-spec/protocol.h @@ -663,15 +663,6 @@ constexpr OpCode kReadLocalVersionInfo = InformationalParamsOpCode(0x0001); constexpr OpCode kReadLocalSupportedCommands = InformationalParamsOpCode(0x0002); -struct ReadLocalSupportedCommandsReturnParams { - // See enum StatusCode in hci_constants.h. - StatusCode status; - - // See enum class SupportedCommand in hci_constants.h for how to interpret - // this bitfield. - uint8_t supported_commands[64]; -} __attribute__((packed)); - // ============================================ // Read Local Supported Features Command (v1.1) constexpr OpCode kReadLocalSupportedFeatures = diff --git a/pw_bluetooth_sapphire/public/pw_bluetooth_sapphire/internal/host/testing/fake_controller.h b/pw_bluetooth_sapphire/public/pw_bluetooth_sapphire/internal/host/testing/fake_controller.h index ddd82aad12..4b8b76c542 100644 --- a/pw_bluetooth_sapphire/public/pw_bluetooth_sapphire/internal/host/testing/fake_controller.h +++ b/pw_bluetooth_sapphire/public/pw_bluetooth_sapphire/internal/host/testing/fake_controller.h @@ -59,6 +59,11 @@ class FakeController final : public ControllerTestDoubleBase, bool is_event_unmasked(hci_spec::LEEventMask event) const; + auto SupportedCommandsView() { + return pw::bluetooth::emboss::MakeSupportedCommandsView( + supported_commands, sizeof(supported_commands)); + } + // The time elapsed from the receipt of a LE Create Connection command until // the resulting LE Connection Complete event. pw::chrono::SystemClock::duration le_connection_delay =