From 023c89e7ff61c4451bfe9c7cacf00339bf6018b0 Mon Sep 17 00:00:00 2001 From: Henri Chataing Date: Wed, 28 Feb 2024 09:12:32 -0800 Subject: [PATCH] Sync with aosp/main Synchronized to packages/modules/Bluetooth commit 084589ff8d0b64617776b63a3fadd23cbf14da67 Changelist: - Improve handling of packet parsing errors - Report correct extended flag in extended scan responses - Register an handler for invalid packets in DualModeController --- model/controller/dual_mode_controller.cc | 391 ++++++++++++---------- model/controller/dual_mode_controller.h | 37 ++ model/controller/link_layer_controller.cc | 31 +- model/controller/link_layer_controller.h | 1 + test/LL/DDI/SCN/BV_20_C.py | 264 +++++++++++++++ test/invalid_packet_handler_unittest.cc | 82 +++++ test/main.py | 1 + 7 files changed, 619 insertions(+), 188 deletions(-) create mode 100644 test/LL/DDI/SCN/BV_20_C.py create mode 100644 test/invalid_packet_handler_unittest.cc diff --git a/model/controller/dual_mode_controller.cc b/model/controller/dual_mode_controller.cc index 6b029f2..728c60e 100644 --- a/model/controller/dual_mode_controller.cc +++ b/model/controller/dual_mode_controller.cc @@ -52,6 +52,14 @@ constexpr uint8_t kTransmitPowerLevel = -20; constexpr bool kLeApcfTransportDiscoveryDataFilterSupported = true; constexpr bool kLeApcfAdTypeFilterSupported = true; +#define CHECK_PACKET_VIEW(view) \ + do { \ + if (!CheckPacketView(view, fmt::format("{}:{} - {}() invalid packet", \ + __FILE__, __LINE__, __func__))) { \ + return; \ + } \ + } while (0) + void DualModeController::SetProperties(ControllerProperties properties) { WARNING(id_, "updating the device properties!"); properties_ = std::move(properties); @@ -89,6 +97,12 @@ DualModeController::DualModeController(ControllerProperties properties) ASSERT(Address::FromString("3C:5A:B4:04:05:06", public_address)); SetAddress(public_address); + // Default invalid packet handler will abort the controller + // when receiving an invalid packet. + invalid_packet_handler_ = + [](uint32_t, InvalidPacketReason, std::string message, + std::vector const&) { FATAL("{}", message); }; + link_layer_controller_.RegisterRemoteChannel( [this](std::shared_ptr packet, Phy::Type phy_type, int8_t tx_power) { @@ -109,7 +123,8 @@ void DualModeController::ForwardToLl(CommandView command) { void DualModeController::HandleAcl( std::shared_ptr> packet) { auto acl_packet = bluetooth::hci::AclView::Create(pdl::packet::slice(packet)); - ASSERT(acl_packet.IsValid()); + CHECK_PACKET_VIEW(acl_packet); + if (loopback_mode_ == LoopbackMode::ENABLE_LOCAL) { uint16_t handle = acl_packet.GetHandle(); @@ -134,7 +149,8 @@ void DualModeController::HandleAcl( void DualModeController::HandleSco( std::shared_ptr> packet) { auto sco_packet = bluetooth::hci::ScoView::Create(pdl::packet::slice(packet)); - ASSERT(sco_packet.IsValid()); + CHECK_PACKET_VIEW(sco_packet); + if (loopback_mode_ == LoopbackMode::ENABLE_LOCAL) { uint16_t handle = sco_packet.GetHandle(); @@ -159,7 +175,7 @@ void DualModeController::HandleSco( void DualModeController::HandleIso( std::shared_ptr> packet) { auto iso = bluetooth::hci::IsoView::Create(pdl::packet::slice(packet)); - ASSERT(iso.IsValid()); + CHECK_PACKET_VIEW(iso); link_layer_controller_.HandleIso(iso); } @@ -167,7 +183,7 @@ void DualModeController::HandleCommand( std::shared_ptr> packet) { auto command_packet = bluetooth::hci::CommandView::Create(pdl::packet::slice(packet)); - ASSERT(command_packet.IsValid()); + CHECK_PACKET_VIEW(command_packet); OpCode op_code = command_packet.GetOpCode(); const bool is_vendor_command = (static_cast(op_code) >> 10) == 0x3f; @@ -237,6 +253,13 @@ void DualModeController::HandleCommand( } } +void DualModeController::RegisterInvalidPacketHandler( + const std::function const&)>& handler) { + INFO(id_, "updating the invalid packet handler"); + invalid_packet_handler_ = handler; +} + void DualModeController::RegisterEventChannel( const std::function>)>& send_event) { @@ -284,7 +307,7 @@ void DualModeController::RegisterIsoChannel( void DualModeController::Reset(CommandView command) { auto command_view = bluetooth::hci::ResetView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Reset"); @@ -298,7 +321,7 @@ void DualModeController::Reset(CommandView command) { void DualModeController::ReadBufferSize(CommandView command) { auto command_view = bluetooth::hci::ReadBufferSizeView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Read Buffer Size"); @@ -312,7 +335,7 @@ void DualModeController::ReadBufferSize(CommandView command) { void DualModeController::ReadFailedContactCounter(CommandView command) { auto command_view = bluetooth::hci::ReadFailedContactCounterView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); uint16_t connection_handle = command_view.GetConnectionHandle(); uint16_t failed_contact_counter = 0; @@ -330,7 +353,7 @@ void DualModeController::ReadFailedContactCounter(CommandView command) { void DualModeController::ResetFailedContactCounter(CommandView command) { auto command_view = bluetooth::hci::ReadFailedContactCounterView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); uint16_t connection_handle = command_view.GetConnectionHandle(); DEBUG(id_, "<< Reset Failed Contact Counter"); @@ -346,7 +369,7 @@ void DualModeController::ResetFailedContactCounter(CommandView command) { void DualModeController::ReadRssi(CommandView command) { auto command_view = bluetooth::hci::ReadRssiView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); uint16_t connection_handle = command_view.GetConnectionHandle(); int8_t rssi = 0; @@ -362,7 +385,7 @@ void DualModeController::ReadRssi(CommandView command) { void DualModeController::ReadEncryptionKeySize(CommandView command) { auto command_view = bluetooth::hci::ReadEncryptionKeySizeView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Read Encryption Key Size"); DEBUG(id_, " connection_handle=0x{:x}", command_view.GetConnectionHandle()); @@ -375,7 +398,7 @@ void DualModeController::ReadEncryptionKeySize(CommandView command) { void DualModeController::HostBufferSize(CommandView command) { auto command_view = bluetooth::hci::HostBufferSizeView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Host Buffer Size"); @@ -386,7 +409,7 @@ void DualModeController::HostBufferSize(CommandView command) { void DualModeController::ReadLocalVersionInformation(CommandView command) { auto command_view = bluetooth::hci::ReadLocalVersionInformationView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Read Local Version Information"); @@ -405,7 +428,7 @@ void DualModeController::ReadLocalVersionInformation(CommandView command) { void DualModeController::ReadRemoteVersionInformation(CommandView command) { auto command_view = bluetooth::hci::ReadRemoteVersionInformationView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Read Remote Version Information"); DEBUG(id_, " connection_handle=0x{:x}", command_view.GetConnectionHandle()); @@ -420,7 +443,7 @@ void DualModeController::ReadRemoteVersionInformation(CommandView command) { void DualModeController::ReadBdAddr(CommandView command) { auto command_view = bluetooth::hci::ReadBdAddrView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Read BD_ADDR"); @@ -431,7 +454,7 @@ void DualModeController::ReadBdAddr(CommandView command) { void DualModeController::ReadLocalSupportedCommands(CommandView command) { auto command_view = bluetooth::hci::ReadLocalSupportedCommandsView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Read Local Supported Commands"); @@ -442,7 +465,7 @@ void DualModeController::ReadLocalSupportedCommands(CommandView command) { void DualModeController::ReadLocalSupportedFeatures(CommandView command) { auto command_view = bluetooth::hci::ReadLocalSupportedFeaturesView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Read Local Supported Features"); @@ -454,7 +477,7 @@ void DualModeController::ReadLocalSupportedFeatures(CommandView command) { void DualModeController::ReadLocalSupportedCodecsV1(CommandView command) { auto command_view = bluetooth::hci::ReadLocalSupportedCodecsV1View::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Read Local Supported Codecs V1"); @@ -467,7 +490,7 @@ void DualModeController::ReadLocalSupportedCodecsV1(CommandView command) { void DualModeController::ReadLocalExtendedFeatures(CommandView command) { auto command_view = bluetooth::hci::ReadLocalExtendedFeaturesView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); uint8_t page_number = command_view.GetPageNumber(); DEBUG(id_, "<< Read Local Extended Features"); @@ -482,7 +505,7 @@ void DualModeController::ReadLocalExtendedFeatures(CommandView command) { void DualModeController::ReadRemoteExtendedFeatures(CommandView command) { auto command_view = bluetooth::hci::ReadRemoteExtendedFeaturesView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Read Remote Extended Features"); DEBUG(id_, " connection_handle=0x{:x}", command_view.GetConnectionHandle()); @@ -498,7 +521,7 @@ void DualModeController::ReadRemoteExtendedFeatures(CommandView command) { void DualModeController::SwitchRole(CommandView command) { auto command_view = bluetooth::hci::SwitchRoleView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Switch Role"); DEBUG(id_, " bd_addr={}", command_view.GetBdAddr()); @@ -514,7 +537,7 @@ void DualModeController::SwitchRole(CommandView command) { void DualModeController::ReadRemoteSupportedFeatures(CommandView command) { auto command_view = bluetooth::hci::ReadRemoteSupportedFeaturesView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Read Remote Supported Features"); DEBUG(id_, " connection_handle=0x{:x}", command_view.GetConnectionHandle()); @@ -529,7 +552,7 @@ void DualModeController::ReadRemoteSupportedFeatures(CommandView command) { void DualModeController::ReadClockOffset(CommandView command) { auto command_view = bluetooth::hci::ReadClockOffsetView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Read Clock Offset"); DEBUG(id_, " connection_handle=0x{:x}", command_view.GetConnectionHandle()); @@ -547,7 +570,7 @@ void DualModeController::ReadClockOffset(CommandView command) { // Support is provided to satisfy PTS tester requirements. void DualModeController::AddScoConnection(CommandView command) { auto command_view = bluetooth::hci::AddScoConnectionView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Add SCO Connection"); DEBUG(id_, " connection_handle=0x{:x}", command_view.GetConnectionHandle()); @@ -564,7 +587,7 @@ void DualModeController::AddScoConnection(CommandView command) { void DualModeController::SetupSynchronousConnection(CommandView command) { auto command_view = bluetooth::hci::SetupSynchronousConnectionView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Setup Synchronous Connection"); DEBUG(id_, " connection_handle=0x{:x}", command_view.GetConnectionHandle()); @@ -584,7 +607,7 @@ void DualModeController::SetupSynchronousConnection(CommandView command) { void DualModeController::AcceptSynchronousConnection(CommandView command) { auto command_view = bluetooth::hci::AcceptSynchronousConnectionView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Accept Synchronous Connection"); DEBUG(id_, " bd_addr={}", command_view.GetBdAddr()); @@ -606,7 +629,7 @@ void DualModeController::EnhancedSetupSynchronousConnection( auto command_view = bluetooth::hci::EnhancedSetupSynchronousConnectionView::Create(command); auto status = ErrorCode::SUCCESS; - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Enhanced Setup Synchronous Connection"); DEBUG(id_, " connection_handle=0x{:x}", command_view.GetConnectionHandle()); @@ -753,7 +776,7 @@ void DualModeController::EnhancedAcceptSynchronousConnection( auto command_view = bluetooth::hci::EnhancedAcceptSynchronousConnectionView::Create(command); auto status = ErrorCode::SUCCESS; - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Enhanced Accept Synchronous Connection"); DEBUG(id_, " bd_addr={}", command_view.GetBdAddr()); @@ -897,7 +920,7 @@ void DualModeController::EnhancedAcceptSynchronousConnection( void DualModeController::RejectSynchronousConnection(CommandView command) { auto command_view = bluetooth::hci::RejectSynchronousConnectionView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Reject Synchronous Connection"); DEBUG(id_, " bd_addr={}", command_view.GetBdAddr()); @@ -916,7 +939,7 @@ void DualModeController::ReadInquiryResponseTransmitPowerLevel( auto command_view = bluetooth::hci::ReadInquiryResponseTransmitPowerLevelView::Create( command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Read Inquiry Response Transmit Power Level"); @@ -928,7 +951,7 @@ void DualModeController::ReadInquiryResponseTransmitPowerLevel( void DualModeController::EnhancedFlush(CommandView command) { auto command_view = bluetooth::hci::EnhancedFlushView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Enhanced Flush"); DEBUG(id_, " connection_handle=0x{:x}", command_view.GetConnectionHandle()); @@ -948,7 +971,7 @@ void DualModeController::EnhancedFlush(CommandView command) { void DualModeController::SetEventMaskPage2(CommandView command) { auto command_view = bluetooth::hci::SetEventMaskPage2View::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Set Event Mask Page 2"); DEBUG(id_, " event_mask_page_2=0x{:x}", command_view.GetEventMaskPage2()); @@ -978,7 +1001,7 @@ void DualModeController::ReadLocalOobExtendedData(CommandView command) { void DualModeController::WriteSimplePairingMode(CommandView command) { auto command_view = bluetooth::hci::WriteSimplePairingModeView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Write Simple Pairing Mode"); DEBUG(id_, " simple_pairing_mode={}", @@ -994,7 +1017,7 @@ void DualModeController::WriteSimplePairingMode(CommandView command) { void DualModeController::ChangeConnectionPacketType(CommandView command) { auto command_view = bluetooth::hci::ChangeConnectionPacketTypeView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Change Connection Packet Type"); DEBUG(id_, " connection_handle=0x{:x}", command_view.GetConnectionHandle()); @@ -1011,7 +1034,7 @@ void DualModeController::ChangeConnectionPacketType(CommandView command) { void DualModeController::WriteLeHostSupport(CommandView command) { auto command_view = bluetooth::hci::WriteLeHostSupportView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Write LE Host Support"); DEBUG(id_, " le_supported_host={}", @@ -1028,7 +1051,7 @@ void DualModeController::WriteSecureConnectionsHostSupport( CommandView command) { auto command_view = bluetooth::hci::WriteSecureConnectionsHostSupportView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Write Secure Connections Host Support"); DEBUG(id_, " secure_connections_host_support={}", @@ -1045,7 +1068,7 @@ void DualModeController::WriteSecureConnectionsHostSupport( void DualModeController::SetEventMask(CommandView command) { auto command_view = bluetooth::hci::SetEventMaskView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Set Event Mask"); DEBUG(id_, " event_mask=0x{:x}", command_view.GetEventMask()); @@ -1057,7 +1080,7 @@ void DualModeController::SetEventMask(CommandView command) { void DualModeController::ReadInquiryMode(CommandView command) { auto command_view = bluetooth::hci::ReadInquiryModeView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Read Inquiry Mode"); @@ -1069,7 +1092,7 @@ void DualModeController::ReadInquiryMode(CommandView command) { void DualModeController::WriteInquiryMode(CommandView command) { auto command_view = bluetooth::hci::WriteInquiryModeView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Write Inquiry Mode"); DEBUG(id_, " inquiry_mode={}", @@ -1083,7 +1106,7 @@ void DualModeController::WriteInquiryMode(CommandView command) { void DualModeController::ReadPageScanType(CommandView command) { auto command_view = bluetooth::hci::ReadPageScanTypeView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Read Page Scan Type"); @@ -1095,7 +1118,7 @@ void DualModeController::ReadPageScanType(CommandView command) { void DualModeController::WritePageScanType(CommandView command) { auto command_view = bluetooth::hci::WritePageScanTypeView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Write Page Scan Type"); DEBUG(id_, " page_scan_type={}", @@ -1107,7 +1130,7 @@ void DualModeController::WritePageScanType(CommandView command) { void DualModeController::ReadInquiryScanType(CommandView command) { auto command_view = bluetooth::hci::ReadInquiryScanTypeView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Read Inquiry Scan Type"); @@ -1119,7 +1142,7 @@ void DualModeController::ReadInquiryScanType(CommandView command) { void DualModeController::WriteInquiryScanType(CommandView command) { auto command_view = bluetooth::hci::WriteInquiryScanTypeView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Write Inquiry Scan Type"); DEBUG(id_, " inquiry_scan_type={}", @@ -1132,7 +1155,7 @@ void DualModeController::WriteInquiryScanType(CommandView command) { void DualModeController::ChangeConnectionLinkKey(CommandView command) { auto command_view = bluetooth::hci::ChangeConnectionLinkKeyView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Change Connection Link Key"); DEBUG(id_, " connection_handle=0x{:x}", command_view.GetConnectionHandle()); @@ -1146,7 +1169,7 @@ void DualModeController::ChangeConnectionLinkKey(CommandView command) { void DualModeController::CentralLinkKey(CommandView command) { auto command_view = bluetooth::hci::CentralLinkKeyView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Central Link Key"); DEBUG(id_, " key_flag={}", @@ -1162,7 +1185,7 @@ void DualModeController::CentralLinkKey(CommandView command) { void DualModeController::WriteAuthenticationEnable(CommandView command) { auto command_view = bluetooth::hci::WriteAuthenticationEnableView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Write Authentication Enable"); DEBUG(id_, " authentication_enable={}", @@ -1178,7 +1201,7 @@ void DualModeController::WriteAuthenticationEnable(CommandView command) { void DualModeController::ReadAuthenticationEnable(CommandView command) { auto command_view = bluetooth::hci::ReadAuthenticationEnableView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Read Authentication Enable"); @@ -1190,7 +1213,7 @@ void DualModeController::ReadAuthenticationEnable(CommandView command) { void DualModeController::ReadClassOfDevice(CommandView command) { auto command_view = bluetooth::hci::ReadClassOfDeviceView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Read Class of Device"); @@ -1201,7 +1224,7 @@ void DualModeController::ReadClassOfDevice(CommandView command) { void DualModeController::WriteClassOfDevice(CommandView command) { auto command_view = bluetooth::hci::WriteClassOfDeviceView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Write Class of Device"); DEBUG(id_, " class_of_device=0x{:x}", command_view.GetClassOfDevice()); @@ -1213,7 +1236,7 @@ void DualModeController::WriteClassOfDevice(CommandView command) { void DualModeController::ReadPageTimeout(CommandView command) { auto command_view = bluetooth::hci::ReadPageTimeoutView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Read Page Timeout"); @@ -1224,7 +1247,7 @@ void DualModeController::ReadPageTimeout(CommandView command) { void DualModeController::WritePageTimeout(CommandView command) { auto command_view = bluetooth::hci::WritePageTimeoutView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Write Page Timeout"); DEBUG(id_, " page_timeout={}", command_view.GetPageTimeout()); @@ -1236,7 +1259,7 @@ void DualModeController::WritePageTimeout(CommandView command) { void DualModeController::HoldMode(CommandView command) { auto command_view = bluetooth::hci::HoldModeView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); uint16_t handle = command_view.GetConnectionHandle(); uint16_t hold_mode_max_interval = command_view.GetHoldModeMaxInterval(); uint16_t hold_mode_min_interval = command_view.GetHoldModeMinInterval(); @@ -1253,7 +1276,7 @@ void DualModeController::HoldMode(CommandView command) { void DualModeController::SniffMode(CommandView command) { auto command_view = bluetooth::hci::SniffModeView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); uint16_t handle = command_view.GetConnectionHandle(); uint16_t sniff_max_interval = command_view.GetSniffMaxInterval(); uint16_t sniff_min_interval = command_view.GetSniffMinInterval(); @@ -1273,7 +1296,7 @@ void DualModeController::SniffMode(CommandView command) { void DualModeController::ExitSniffMode(CommandView command) { auto command_view = bluetooth::hci::ExitSniffModeView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Exit Sniff Mode"); DEBUG(id_, " connection_handle=0x{:x}", command_view.GetConnectionHandle()); @@ -1287,7 +1310,7 @@ void DualModeController::ExitSniffMode(CommandView command) { void DualModeController::QosSetup(CommandView command) { auto command_view = bluetooth::hci::QosSetupView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); uint16_t handle = command_view.GetConnectionHandle(); uint8_t service_type = static_cast(command_view.GetServiceType()); uint32_t token_rate = command_view.GetTokenRate(); @@ -1308,7 +1331,7 @@ void DualModeController::QosSetup(CommandView command) { void DualModeController::RoleDiscovery(CommandView command) { auto command_view = bluetooth::hci::RoleDiscoveryView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); uint16_t handle = command_view.GetConnectionHandle(); DEBUG(id_, "<< Role Discovery"); @@ -1324,7 +1347,7 @@ void DualModeController::RoleDiscovery(CommandView command) { void DualModeController::ReadDefaultLinkPolicySettings(CommandView command) { auto command_view = bluetooth::hci::ReadDefaultLinkPolicySettingsView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Read Default Link Policy Settings"); @@ -1337,7 +1360,7 @@ void DualModeController::ReadDefaultLinkPolicySettings(CommandView command) { void DualModeController::WriteDefaultLinkPolicySettings(CommandView command) { auto command_view = bluetooth::hci::WriteDefaultLinkPolicySettingsView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Write Default Link Policy Settings"); DEBUG(id_, " default_link_policy_settings=0x{:x}", @@ -1352,7 +1375,7 @@ void DualModeController::WriteDefaultLinkPolicySettings(CommandView command) { void DualModeController::SniffSubrating(CommandView command) { auto command_view = bluetooth::hci::SniffSubratingView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); uint16_t connection_handle = command_view.GetConnectionHandle(); DEBUG(id_, "<< Sniff Subrating"); @@ -1364,7 +1387,7 @@ void DualModeController::SniffSubrating(CommandView command) { void DualModeController::FlowSpecification(CommandView command) { auto command_view = bluetooth::hci::FlowSpecificationView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); uint16_t handle = command_view.GetConnectionHandle(); uint8_t flow_direction = static_cast(command_view.GetFlowDirection()); @@ -1388,7 +1411,7 @@ void DualModeController::FlowSpecification(CommandView command) { void DualModeController::ReadLinkPolicySettings(CommandView command) { auto command_view = bluetooth::hci::ReadLinkPolicySettingsView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); uint16_t handle = command_view.GetConnectionHandle(); DEBUG(id_, "<< Read Link Policy Settings"); @@ -1405,7 +1428,7 @@ void DualModeController::ReadLinkPolicySettings(CommandView command) { void DualModeController::WriteLinkPolicySettings(CommandView command) { auto command_view = bluetooth::hci::WriteLinkPolicySettingsView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); uint16_t handle = command_view.GetConnectionHandle(); uint16_t settings = command_view.GetLinkPolicySettings(); @@ -1423,7 +1446,7 @@ void DualModeController::WriteLinkPolicySettings(CommandView command) { void DualModeController::WriteLinkSupervisionTimeout(CommandView command) { auto command_view = bluetooth::hci::WriteLinkSupervisionTimeoutView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); uint16_t handle = command_view.GetConnectionHandle(); uint16_t timeout = command_view.GetLinkSupervisionTimeout(); @@ -1440,7 +1463,7 @@ void DualModeController::WriteLinkSupervisionTimeout(CommandView command) { void DualModeController::ReadLocalName(CommandView command) { auto command_view = bluetooth::hci::ReadLocalNameView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Read Local Name"); @@ -1451,7 +1474,7 @@ void DualModeController::ReadLocalName(CommandView command) { void DualModeController::WriteLocalName(CommandView command) { auto command_view = bluetooth::hci::WriteLocalNameView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Write Local Name"); @@ -1463,7 +1486,7 @@ void DualModeController::WriteLocalName(CommandView command) { void DualModeController::WriteExtendedInquiryResponse(CommandView command) { auto command_view = bluetooth::hci::WriteExtendedInquiryResponseView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Write Extended Inquiry Response"); @@ -1476,7 +1499,7 @@ void DualModeController::WriteExtendedInquiryResponse(CommandView command) { void DualModeController::RefreshEncryptionKey(CommandView command) { auto command_view = bluetooth::hci::RefreshEncryptionKeyView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); uint16_t handle = command_view.GetConnectionHandle(); DEBUG(id_, "<< Refresh Encryption Key"); @@ -1491,7 +1514,7 @@ void DualModeController::RefreshEncryptionKey(CommandView command) { void DualModeController::ReadVoiceSetting(CommandView command) { auto command_view = bluetooth::hci::ReadVoiceSettingView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Read Voice Setting"); @@ -1502,7 +1525,7 @@ void DualModeController::ReadVoiceSetting(CommandView command) { void DualModeController::WriteVoiceSetting(CommandView command) { auto command_view = bluetooth::hci::WriteVoiceSettingView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Write Voice Setting"); DEBUG(id_, " voice_setting=0x{:x}", command_view.GetVoiceSetting()); @@ -1516,7 +1539,7 @@ void DualModeController::WriteVoiceSetting(CommandView command) { void DualModeController::ReadNumberOfSupportedIac(CommandView command) { auto command_view = bluetooth::hci::ReadNumberOfSupportedIacView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Read Number of Supported Iac"); @@ -1526,7 +1549,7 @@ void DualModeController::ReadNumberOfSupportedIac(CommandView command) { void DualModeController::ReadCurrentIacLap(CommandView command) { auto command_view = bluetooth::hci::ReadCurrentIacLapView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Read Current Iac Lap"); @@ -1537,7 +1560,7 @@ void DualModeController::ReadCurrentIacLap(CommandView command) { void DualModeController::WriteCurrentIacLap(CommandView command) { auto command_view = bluetooth::hci::WriteCurrentIacLapView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Write Current Iac Lap"); @@ -1548,7 +1571,7 @@ void DualModeController::WriteCurrentIacLap(CommandView command) { void DualModeController::ReadPageScanActivity(CommandView command) { auto command_view = bluetooth::hci::ReadPageScanActivityView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Read Page Scan Activity"); @@ -1561,7 +1584,7 @@ void DualModeController::ReadPageScanActivity(CommandView command) { void DualModeController::WritePageScanActivity(CommandView command) { auto command_view = bluetooth::hci::WritePageScanActivityView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Write Page Scan Activity"); @@ -1572,7 +1595,7 @@ void DualModeController::WritePageScanActivity(CommandView command) { void DualModeController::ReadInquiryScanActivity(CommandView command) { auto command_view = bluetooth::hci::ReadInquiryScanActivityView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Read Inquiry Scan Activity"); @@ -1585,7 +1608,7 @@ void DualModeController::ReadInquiryScanActivity(CommandView command) { void DualModeController::WriteInquiryScanActivity(CommandView command) { auto command_view = bluetooth::hci::WriteInquiryScanActivityView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Write Inquiry Scan Activity"); @@ -1595,7 +1618,7 @@ void DualModeController::WriteInquiryScanActivity(CommandView command) { void DualModeController::ReadScanEnable(CommandView command) { auto command_view = bluetooth::hci::ReadScanEnableView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Read Scan Enable"); @@ -1615,7 +1638,7 @@ void DualModeController::ReadScanEnable(CommandView command) { void DualModeController::WriteScanEnable(CommandView command) { auto command_view = bluetooth::hci::WriteScanEnableView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); bluetooth::hci::ScanEnable scan_enable = command_view.GetScanEnable(); bool inquiry_scan = scan_enable == bluetooth::hci::ScanEnable::INQUIRY_AND_PAGE_SCAN || @@ -1635,7 +1658,7 @@ void DualModeController::WriteScanEnable(CommandView command) { void DualModeController::ReadTransmitPowerLevel(CommandView command) { auto command_view = bluetooth::hci::ReadTransmitPowerLevelView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); uint16_t connection_handle = command_view.GetConnectionHandle(); DEBUG(id_, "<< Read Transmit Power Level"); @@ -1651,7 +1674,7 @@ void DualModeController::ReadTransmitPowerLevel(CommandView command) { void DualModeController::ReadEnhancedTransmitPowerLevel(CommandView command) { auto command_view = bluetooth::hci::ReadEnhancedTransmitPowerLevelView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); uint16_t connection_handle = command_view.GetConnectionHandle(); DEBUG(id_, "<< Read Enhanced Transmit Power Level"); @@ -1669,7 +1692,7 @@ void DualModeController::ReadEnhancedTransmitPowerLevel(CommandView command) { void DualModeController::ReadSynchronousFlowControlEnable(CommandView command) { auto command_view = bluetooth::hci::ReadSynchronousFlowControlEnableView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Read Synchronous Flow Control Enable"); @@ -1686,7 +1709,7 @@ void DualModeController::WriteSynchronousFlowControlEnable( CommandView command) { auto command_view = bluetooth::hci::WriteSynchronousFlowControlEnableView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); auto enabled = command_view.GetEnable() == bluetooth::hci::Enable::ENABLED; DEBUG(id_, "<< Write Synchronous Flow Control Enable"); @@ -1700,7 +1723,7 @@ void DualModeController::WriteSynchronousFlowControlEnable( void DualModeController::SetEventFilter(CommandView command) { auto command_view = bluetooth::hci::SetEventFilterView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Set Event Filter"); DEBUG(id_, " filter_type={}", @@ -1718,7 +1741,7 @@ void DualModeController::SetEventFilter(CommandView command) { void DualModeController::Inquiry(CommandView command) { auto command_view = bluetooth::hci::InquiryView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); auto max_responses = command_view.GetNumResponses(); auto length = command_view.GetInquiryLength(); @@ -1741,7 +1764,7 @@ void DualModeController::Inquiry(CommandView command) { void DualModeController::InquiryCancel(CommandView command) { auto command_view = bluetooth::hci::InquiryCancelView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Inquiry Cancel"); @@ -1753,7 +1776,7 @@ void DualModeController::InquiryCancel(CommandView command) { void DualModeController::AcceptConnectionRequest(CommandView command) { auto command_view = bluetooth::hci::AcceptConnectionRequestView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); Address bd_addr = command_view.GetBdAddr(); bool try_role_switch = command_view.GetRole() == @@ -1772,7 +1795,7 @@ void DualModeController::AcceptConnectionRequest(CommandView command) { void DualModeController::RejectConnectionRequest(CommandView command) { auto command_view = bluetooth::hci::RejectConnectionRequestView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); Address bd_addr = command_view.GetBdAddr(); auto reason = command_view.GetReason(); @@ -1789,7 +1812,7 @@ void DualModeController::RejectConnectionRequest(CommandView command) { void DualModeController::DeleteStoredLinkKey(CommandView command) { auto command_view = bluetooth::hci::DeleteStoredLinkKeyView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Delete Stored Link Key"); @@ -1799,7 +1822,7 @@ void DualModeController::DeleteStoredLinkKey(CommandView command) { void DualModeController::RemoteNameRequest(CommandView command) { auto command_view = bluetooth::hci::RemoteNameRequestView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); Address bd_addr = command_view.GetBdAddr(); DEBUG(id_, "<< Remote Name Request"); @@ -1814,7 +1837,7 @@ void DualModeController::RemoteNameRequest(CommandView command) { void DualModeController::LeSetEventMask(CommandView command) { auto command_view = bluetooth::hci::LeSetEventMaskView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Set Event Mask"); DEBUG(id_, " le_event_mask=0x{:x}", command_view.GetLeEventMask()); @@ -1826,7 +1849,7 @@ void DualModeController::LeSetEventMask(CommandView command) { void DualModeController::LeRequestPeerSca(CommandView command) { auto command_view = bluetooth::hci::LeRequestPeerScaView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); uint16_t connection_handle = command_view.GetConnectionHandle(); DEBUG(id_, "<< LE Request Peer SCA"); @@ -1858,7 +1881,7 @@ void DualModeController::LeRequestPeerSca(CommandView command) { void DualModeController::LeSetHostFeature(CommandView command) { auto command_view = bluetooth::hci::LeSetHostFeatureView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); uint8_t bit_number = static_cast(command_view.GetBitNumber()); uint8_t bit_value = static_cast(command_view.GetBitValue()); @@ -1874,7 +1897,7 @@ void DualModeController::LeSetHostFeature(CommandView command) { void DualModeController::LeReadBufferSizeV1(CommandView command) { auto command_view = bluetooth::hci::LeReadBufferSizeV1View::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Read Buffer Size V1"); @@ -1889,7 +1912,7 @@ void DualModeController::LeReadBufferSizeV1(CommandView command) { void DualModeController::LeReadBufferSizeV2(CommandView command) { auto command_view = bluetooth::hci::LeReadBufferSizeV2View::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Read Buffer Size V2"); @@ -1909,7 +1932,7 @@ void DualModeController::LeReadBufferSizeV2(CommandView command) { void DualModeController::LeSetAddressResolutionEnable(CommandView command) { auto command_view = bluetooth::hci::LeSetAddressResolutionEnableView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Set Address Resolution Enable"); DEBUG(id_, " address_resolution_enable={}", @@ -1928,7 +1951,7 @@ void DualModeController::LeSetResolvablePrivateAddressTimeout( CommandView command) { auto command_view = bluetooth::hci::LeSetResolvablePrivateAddressTimeoutView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Set Resolvable Private Address Timeout"); @@ -1943,7 +1966,7 @@ void DualModeController::LeSetResolvablePrivateAddressTimeout( void DualModeController::LeReadLocalSupportedFeatures(CommandView command) { auto command_view = bluetooth::hci::LeReadLocalSupportedFeaturesView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Read Local Supported Features"); @@ -1955,7 +1978,7 @@ void DualModeController::LeReadLocalSupportedFeatures(CommandView command) { void DualModeController::LeSetRandomAddress(CommandView command) { auto command_view = bluetooth::hci::LeSetRandomAddressView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Set Random Address"); DEBUG(id_, " random_address={}", command_view.GetRandomAddress()); @@ -1969,7 +1992,7 @@ void DualModeController::LeSetRandomAddress(CommandView command) { void DualModeController::LeSetAdvertisingParameters(CommandView command) { auto command_view = bluetooth::hci::LeSetAdvertisingParametersView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Set Advertising Parameters"); @@ -1989,7 +2012,7 @@ void DualModeController::LeReadAdvertisingPhysicalChannelTxPower( auto command_view = bluetooth::hci::LeReadAdvertisingPhysicalChannelTxPowerView::Create( command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Read Physical Channel Tx Power"); @@ -2001,7 +2024,7 @@ void DualModeController::LeReadAdvertisingPhysicalChannelTxPower( void DualModeController::LeSetAdvertisingData(CommandView command) { auto command_view = bluetooth::hci::LeSetAdvertisingDataView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Set Advertising Data"); @@ -2014,7 +2037,7 @@ void DualModeController::LeSetAdvertisingData(CommandView command) { void DualModeController::LeSetScanResponseData(CommandView command) { auto command_view = bluetooth::hci::LeSetScanResponseDataView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Set Scan Response Data"); @@ -2027,7 +2050,7 @@ void DualModeController::LeSetScanResponseData(CommandView command) { void DualModeController::LeSetAdvertisingEnable(CommandView command) { auto command_view = bluetooth::hci::LeSetAdvertisingEnableView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Set Advertising Enable"); DEBUG(id_, " advertising_enable={}", @@ -2041,7 +2064,7 @@ void DualModeController::LeSetAdvertisingEnable(CommandView command) { void DualModeController::LeSetScanParameters(CommandView command) { auto command_view = bluetooth::hci::LeSetScanParametersView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Set Scan Parameters"); @@ -2055,7 +2078,7 @@ void DualModeController::LeSetScanParameters(CommandView command) { void DualModeController::LeSetScanEnable(CommandView command) { auto command_view = bluetooth::hci::LeSetScanEnableView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Set Scan Enable"); DEBUG(id_, " scan_enable={}", @@ -2070,7 +2093,7 @@ void DualModeController::LeSetScanEnable(CommandView command) { void DualModeController::LeCreateConnection(CommandView command) { auto command_view = bluetooth::hci::LeCreateConnectionView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Create Connection"); DEBUG(id_, " peer_address={}", command_view.GetPeerAddress()); @@ -2100,7 +2123,7 @@ void DualModeController::LeCreateConnection(CommandView command) { void DualModeController::LeCreateConnectionCancel(CommandView command) { auto command_view = bluetooth::hci::LeCreateConnectionCancelView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Create Connection Cancel"); @@ -2111,7 +2134,7 @@ void DualModeController::LeCreateConnectionCancel(CommandView command) { void DualModeController::LeConnectionUpdate(CommandView command) { auto command_view = bluetooth::hci::LeConnectionUpdateView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Connection Update"); DEBUG(id_, " connection_handle=0x{:x}", command_view.GetConnectionHandle()); @@ -2128,7 +2151,7 @@ void DualModeController::LeConnectionUpdate(CommandView command) { void DualModeController::CreateConnection(CommandView command) { auto command_view = bluetooth::hci::CreateConnectionView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); Address bd_addr = command_view.GetBdAddr(); uint16_t packet_type = command_view.GetPacketType(); uint8_t page_scan_mode = @@ -2156,7 +2179,7 @@ void DualModeController::CreateConnection(CommandView command) { void DualModeController::CreateConnectionCancel(CommandView command) { auto command_view = bluetooth::hci::CreateConnectionCancelView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); Address address = command_view.GetBdAddr(); DEBUG(id_, "<< Create Connection Cancel"); @@ -2170,7 +2193,7 @@ void DualModeController::CreateConnectionCancel(CommandView command) { void DualModeController::Disconnect(CommandView command) { auto command_view = bluetooth::hci::DisconnectView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); uint16_t connection_handle = command_view.GetConnectionHandle(); DEBUG(id_, "<< Disconnect"); @@ -2191,7 +2214,7 @@ void DualModeController::Disconnect(CommandView command) { void DualModeController::LeReadFilterAcceptListSize(CommandView command) { auto command_view = bluetooth::hci::LeReadFilterAcceptListSizeView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Read Filter Accept List Size"); @@ -2203,7 +2226,7 @@ void DualModeController::LeReadFilterAcceptListSize(CommandView command) { void DualModeController::LeClearFilterAcceptList(CommandView command) { auto command_view = bluetooth::hci::LeClearFilterAcceptListView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Clear Filter Accept List"); @@ -2215,7 +2238,7 @@ void DualModeController::LeClearFilterAcceptList(CommandView command) { void DualModeController::LeAddDeviceToFilterAcceptList(CommandView command) { auto command_view = bluetooth::hci::LeAddDeviceToFilterAcceptListView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Add Device To Filter Accept List"); DEBUG(id_, " address={}", command_view.GetAddress()); @@ -2234,7 +2257,7 @@ void DualModeController::LeRemoveDeviceFromFilterAcceptList( CommandView command) { auto command_view = bluetooth::hci::LeRemoveDeviceFromFilterAcceptListView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Remove Device From Filter Accept List"); DEBUG(id_, " address={}", command_view.GetAddress()); @@ -2251,7 +2274,7 @@ void DualModeController::LeRemoveDeviceFromFilterAcceptList( void DualModeController::LeClearResolvingList(CommandView command) { auto command_view = bluetooth::hci::LeClearResolvingListView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Clear Resolving List"); @@ -2263,7 +2286,7 @@ void DualModeController::LeClearResolvingList(CommandView command) { void DualModeController::LeReadResolvingListSize(CommandView command) { auto command_view = bluetooth::hci::LeReadResolvingListSizeView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Read Resolving List Size"); @@ -2275,7 +2298,7 @@ void DualModeController::LeReadResolvingListSize(CommandView command) { void DualModeController::LeReadPeerResolvableAddress(CommandView command) { auto command_view = bluetooth::hci::LeReadPeerResolvableAddressView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Read Peer Resolvable Address"); DEBUG(id_, " peer_identity_address={}", @@ -2296,7 +2319,7 @@ void DualModeController::LeReadPeerResolvableAddress(CommandView command) { void DualModeController::LeReadLocalResolvableAddress(CommandView command) { auto command_view = bluetooth::hci::LeReadLocalResolvableAddressView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Read Local Resolvable Address"); DEBUG(id_, " peer_identity_address={}", @@ -2317,7 +2340,7 @@ void DualModeController::LeReadLocalResolvableAddress(CommandView command) { void DualModeController::LeReadMaximumDataLength(CommandView command) { auto command_view = bluetooth::hci::LeReadMaximumDataLengthView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Read Maximum Data Length"); @@ -2332,7 +2355,7 @@ void DualModeController::LeReadMaximumDataLength(CommandView command) { void DualModeController::LeReadPhy(CommandView command) { auto command_view = bluetooth::hci::LeReadPhyView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); uint16_t connection_handle = command_view.GetConnectionHandle(); DEBUG(id_, "<< LE Read Phy"); @@ -2348,7 +2371,7 @@ void DualModeController::LeReadPhy(CommandView command) { void DualModeController::LeSetDefaultPhy(CommandView command) { auto command_view = bluetooth::hci::LeSetDefaultPhyView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Set Default Phy"); @@ -2362,7 +2385,7 @@ void DualModeController::LeSetDefaultPhy(CommandView command) { void DualModeController::LeSetPhy(CommandView command) { auto command_view = bluetooth::hci::LeSetPhyView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Set Phy"); DEBUG(id_, " connection_handle=0x{:x}", command_view.GetConnectionHandle()); @@ -2379,7 +2402,7 @@ void DualModeController::LeSetPhy(CommandView command) { void DualModeController::LeReadSuggestedDefaultDataLength(CommandView command) { auto command_view = bluetooth::hci::LeReadSuggestedDefaultDataLengthView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Read Suggested Default Data Length"); @@ -2394,7 +2417,7 @@ void DualModeController::LeWriteSuggestedDefaultDataLength( CommandView command) { auto command_view = bluetooth::hci::LeWriteSuggestedDefaultDataLengthView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Write Suggested Default Data Length"); @@ -2417,7 +2440,7 @@ void DualModeController::LeWriteSuggestedDefaultDataLength( void DualModeController::LeAddDeviceToResolvingList(CommandView command) { auto command_view = bluetooth::hci::LeAddDeviceToResolvingListView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Add Device to Resolving List"); DEBUG(id_, " peer_identity_address={}", @@ -2437,7 +2460,7 @@ void DualModeController::LeAddDeviceToResolvingList(CommandView command) { void DualModeController::LeRemoveDeviceFromResolvingList(CommandView command) { auto command_view = bluetooth::hci::LeRemoveDeviceFromResolvingListView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Remove Device from Resolving List"); DEBUG(id_, " peer_identity_address={}", @@ -2458,7 +2481,7 @@ void DualModeController::LeSetPeriodicAdvertisingParameters( CommandView command) { auto command_view = bluetooth::hci::LeSetPeriodicAdvertisingParametersView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Set Periodic Advertising Parameters"); DEBUG(id_, " advertising_handle={}", command_view.GetAdvertisingHandle()); @@ -2476,7 +2499,7 @@ void DualModeController::LeSetPeriodicAdvertisingParameters( void DualModeController::LeSetPeriodicAdvertisingData(CommandView command) { auto command_view = bluetooth::hci::LeSetPeriodicAdvertisingDataView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Set Periodic Advertising Data"); DEBUG(id_, " advertising_handle={}", command_view.GetAdvertisingHandle()); @@ -2492,7 +2515,7 @@ void DualModeController::LeSetPeriodicAdvertisingData(CommandView command) { void DualModeController::LeSetPeriodicAdvertisingEnable(CommandView command) { auto command_view = bluetooth::hci::LeSetPeriodicAdvertisingEnableView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Set Periodic Advertising Enable"); DEBUG(id_, " advertising_handle={}", command_view.GetAdvertisingHandle()); @@ -2509,7 +2532,7 @@ void DualModeController::LeSetPeriodicAdvertisingEnable(CommandView command) { void DualModeController::LePeriodicAdvertisingCreateSync(CommandView command) { auto command_view = bluetooth::hci::LePeriodicAdvertisingCreateSyncView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Periodic Advertising Create Sync"); DEBUG(id_, " advertiser_address={}", command_view.GetAdvertiserAddress()); @@ -2532,7 +2555,7 @@ void DualModeController::LePeriodicAdvertisingCreateSyncCancel( auto command_view = bluetooth::hci::LePeriodicAdvertisingCreateSyncCancelView::Create( command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Periodic Advertising Create Sync Cancel"); @@ -2547,7 +2570,7 @@ void DualModeController::LePeriodicAdvertisingTerminateSync( CommandView command) { auto command_view = bluetooth::hci::LePeriodicAdvertisingTerminateSyncView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Periodic Advertising Terminate Sync"); DEBUG(id_, " sync_handle=0x{:x}", command_view.GetSyncHandle()); @@ -2563,7 +2586,7 @@ void DualModeController::LeAddDeviceToPeriodicAdvertiserList( CommandView command) { auto command_view = bluetooth::hci::LeAddDeviceToPeriodicAdvertiserListView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Add Device to Periodic Advertiser List"); DEBUG(id_, " advertiser_address={}", command_view.GetAdvertiserAddress()); @@ -2584,7 +2607,7 @@ void DualModeController::LeRemoveDeviceFromPeriodicAdvertiserList( auto command_view = bluetooth::hci::LeRemoveDeviceFromPeriodicAdvertiserListView::Create( command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Remove Device from Periodic Advertiser List"); DEBUG(id_, " advertiser_address={}", command_view.GetAdvertiserAddress()); @@ -2605,7 +2628,7 @@ void DualModeController::LeRemoveDeviceFromPeriodicAdvertiserList( void DualModeController::LeClearPeriodicAdvertiserList(CommandView command) { auto command_view = bluetooth::hci::LeClearPeriodicAdvertiserListView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Clear Periodic Advertiser List"); @@ -2618,7 +2641,7 @@ void DualModeController::LeClearPeriodicAdvertiserList(CommandView command) { void DualModeController::LeReadPeriodicAdvertiserListSize(CommandView command) { auto command_view = bluetooth::hci::LeReadPeriodicAdvertiserListSizeView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Read Periodic Advertiser List Size"); @@ -2631,7 +2654,7 @@ void DualModeController::LeReadPeriodicAdvertiserListSize(CommandView command) { void DualModeController::LeSetExtendedScanParameters(CommandView command) { auto command_view = bluetooth::hci::LeSetExtendedScanParametersView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Set Extended Scan Parameters"); @@ -2646,7 +2669,7 @@ void DualModeController::LeSetExtendedScanParameters(CommandView command) { void DualModeController::LeSetExtendedScanEnable(CommandView command) { auto command_view = bluetooth::hci::LeSetExtendedScanEnableView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Set Extended Scan Enable"); DEBUG(id_, " enable={}", @@ -2663,7 +2686,7 @@ void DualModeController::LeSetExtendedScanEnable(CommandView command) { void DualModeController::LeExtendedCreateConnection(CommandView command) { auto command_view = bluetooth::hci::LeExtendedCreateConnectionView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Extended Create Connection"); DEBUG(id_, " peer_address={}", command_view.GetPeerAddress()); @@ -2698,7 +2721,7 @@ void DualModeController::LeExtendedCreateConnection(CommandView command) { void DualModeController::LeSetPrivacyMode(CommandView command) { auto command_view = bluetooth::hci::LeSetPrivacyModeView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Set Privacy Mode"); DEBUG(id_, " peer_identity_address={}", @@ -2718,7 +2741,7 @@ void DualModeController::LeSetPrivacyMode(CommandView command) { void DualModeController::LeReadRemoteFeatures(CommandView command) { auto command_view = bluetooth::hci::LeReadRemoteFeaturesView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); uint16_t handle = command_view.GetConnectionHandle(); DEBUG(id_, "<< LE Read Remote Features"); @@ -2733,7 +2756,7 @@ void DualModeController::LeReadRemoteFeatures(CommandView command) { void DualModeController::LeEncrypt(CommandView command) { auto command_view = bluetooth::hci::LeEncryptView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Encrypt"); @@ -2746,7 +2769,7 @@ void DualModeController::LeEncrypt(CommandView command) { void DualModeController::LeRand(CommandView command) { auto command_view = bluetooth::hci::LeRandView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Rand"); @@ -2757,7 +2780,7 @@ void DualModeController::LeRand(CommandView command) { void DualModeController::LeReadSupportedStates(CommandView command) { auto command_view = bluetooth::hci::LeReadSupportedStatesView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Read Supported States"); @@ -2770,7 +2793,7 @@ void DualModeController::LeRemoteConnectionParameterRequestReply( auto command_view = bluetooth::hci::LeRemoteConnectionParameterRequestReplyView::Create( command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Remote Connection Parameters Request Reply"); DEBUG(id_, " connection_handle=0x{:x}", command_view.GetConnectionHandle()); @@ -2790,7 +2813,7 @@ void DualModeController::LeRemoteConnectionParameterRequestNegativeReply( CommandView command) { auto command_view = bluetooth::hci:: LeRemoteConnectionParameterRequestNegativeReplyView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Remote Connection Parameters Request Negative Reply"); DEBUG(id_, " connection_handle=0x{:x}", command_view.GetConnectionHandle()); @@ -2808,7 +2831,7 @@ void DualModeController::LeRemoteConnectionParameterRequestNegativeReply( void DualModeController::LeGetVendorCapabilities(CommandView command) { auto command_view = bluetooth::hci::LeGetVendorCapabilitiesView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); if (!properties_.supports_le_get_vendor_capabilities_command) { SendCommandCompleteUnknownOpCodeEvent(OpCode::LE_GET_VENDOR_CAPABILITIES); @@ -2838,13 +2861,13 @@ void DualModeController::LeGetVendorCapabilities(CommandView command) { void DualModeController::LeBatchScan(CommandView command) { auto command_view = bluetooth::hci::LeBatchScanView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); SendCommandCompleteUnknownOpCodeEvent(OpCode::LE_BATCH_SCAN); } void DualModeController::LeApcf(CommandView command) { auto command_view = bluetooth::hci::LeApcfView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); if (!properties_.supports_le_apcf_vendor_command) { SendCommandCompleteUnknownOpCodeEvent(OpCode::LE_APCF); @@ -2855,7 +2878,7 @@ void DualModeController::LeApcf(CommandView command) { case bluetooth::hci::ApcfOpcode::ENABLE: { auto subcommand_view = bluetooth::hci::LeApcfEnableView::Create(command_view); - ASSERT(subcommand_view.IsValid()); + CHECK_PACKET_VIEW(subcommand_view); DEBUG(id_, "<< LE APCF Enable"); DEBUG(id_, " enable={}", @@ -2871,7 +2894,7 @@ void DualModeController::LeApcf(CommandView command) { auto subcommand_view = bluetooth::hci::LeApcfSetFilteringParametersView::Create( command_view); - ASSERT(subcommand_view.IsValid()); + CHECK_PACKET_VIEW(subcommand_view); DEBUG(id_, "<< LE APCF Set Filtering Parameters"); DEBUG(id_, " action={}", @@ -2885,7 +2908,7 @@ void DualModeController::LeApcf(CommandView command) { auto subsubcommand_view = bluetooth::hci::LeApcfAddFilteringParametersView::Create( subcommand_view); - ASSERT(subsubcommand_view.IsValid()); + CHECK_PACKET_VIEW(subcommand_view); status = link_layer_controller_.LeApcfAddFilteringParameters( subsubcommand_view.GetApcfFilterIndex(), subsubcommand_view.GetApcfFeatureSelection(), @@ -2905,7 +2928,7 @@ void DualModeController::LeApcf(CommandView command) { auto subsubcommand_view = bluetooth::hci::LeApcfDeleteFilteringParametersView::Create( subcommand_view); - ASSERT(subsubcommand_view.IsValid()); + CHECK_PACKET_VIEW(subcommand_view); status = link_layer_controller_.LeApcfDeleteFilteringParameters( subsubcommand_view.GetApcfFilterIndex(), &apcf_available_spaces); break; @@ -2914,7 +2937,7 @@ void DualModeController::LeApcf(CommandView command) { auto subsubcommand_view = bluetooth::hci::LeApcfClearFilteringParametersView::Create( subcommand_view); - ASSERT(subsubcommand_view.IsValid()); + CHECK_PACKET_VIEW(subcommand_view); status = link_layer_controller_.LeApcfClearFilteringParameters( &apcf_available_spaces); break; @@ -2934,7 +2957,7 @@ void DualModeController::LeApcf(CommandView command) { case bluetooth::hci::ApcfOpcode::BROADCASTER_ADDRESS: { auto subcommand_view = bluetooth::hci::LeApcfBroadcasterAddressView::Create(command_view); - ASSERT(subcommand_view.IsValid()); + CHECK_PACKET_VIEW(subcommand_view); DEBUG(id_, "<< LE APCF Broadcaster Address"); DEBUG(id_, " action={}", @@ -2948,7 +2971,7 @@ void DualModeController::LeApcf(CommandView command) { auto subsubcommand_view = bluetooth::hci::LeApcfAddBroadcasterAddressView::Create( subcommand_view); - ASSERT(subsubcommand_view.IsValid()); + CHECK_PACKET_VIEW(subcommand_view); status = link_layer_controller_.LeApcfBroadcasterAddress( bluetooth::hci::ApcfAction::ADD, subsubcommand_view.GetApcfFilterIndex(), @@ -2961,7 +2984,7 @@ void DualModeController::LeApcf(CommandView command) { auto subsubcommand_view = bluetooth::hci::LeApcfDeleteBroadcasterAddressView::Create( subcommand_view); - ASSERT(subsubcommand_view.IsValid()); + CHECK_PACKET_VIEW(subcommand_view); status = link_layer_controller_.LeApcfBroadcasterAddress( bluetooth::hci::ApcfAction::DELETE, subsubcommand_view.GetApcfFilterIndex(), @@ -2974,7 +2997,7 @@ void DualModeController::LeApcf(CommandView command) { auto subsubcommand_view = bluetooth::hci::LeApcfClearBroadcasterAddressView::Create( subcommand_view); - ASSERT(subsubcommand_view.IsValid()); + CHECK_PACKET_VIEW(subcommand_view); status = link_layer_controller_.LeApcfBroadcasterAddress( bluetooth::hci::ApcfAction::CLEAR, subsubcommand_view.GetApcfFilterIndex(), Address(), @@ -2997,7 +3020,7 @@ void DualModeController::LeApcf(CommandView command) { case bluetooth::hci::ApcfOpcode::SERVICE_UUID: { auto subcommand_view = bluetooth::hci::LeApcfServiceUuidView::Create(command_view); - ASSERT(subcommand_view.IsValid()); + CHECK_PACKET_VIEW(subcommand_view); DEBUG(id_, "<< LE APCF Service UUID"); DEBUG(id_, " action={}", @@ -3016,7 +3039,7 @@ void DualModeController::LeApcf(CommandView command) { auto subcommand_view = bluetooth::hci::LeApcfServiceSolicitationUuidView::Create( command_view); - ASSERT(subcommand_view.IsValid()); + CHECK_PACKET_VIEW(subcommand_view); DEBUG(id_, "<< LE APCF Service Solicitation UUID"); DEBUG(id_, " action={}", @@ -3035,7 +3058,7 @@ void DualModeController::LeApcf(CommandView command) { case bluetooth::hci::ApcfOpcode::LOCAL_NAME: { auto subcommand_view = bluetooth::hci::LeApcfLocalNameView::Create(command_view); - ASSERT(subcommand_view.IsValid()); + CHECK_PACKET_VIEW(subcommand_view); DEBUG(id_, "<< LE APCF Local Name"); DEBUG(id_, " action={}", @@ -3053,7 +3076,7 @@ void DualModeController::LeApcf(CommandView command) { case bluetooth::hci::ApcfOpcode::MANUFACTURER_DATA: { auto subcommand_view = bluetooth::hci::LeApcfManufacturerDataView::Create(command_view); - ASSERT(subcommand_view.IsValid()); + CHECK_PACKET_VIEW(subcommand_view); DEBUG(id_, "<< LE APCF Manufacturer Data"); DEBUG(id_, " action={}", @@ -3071,7 +3094,7 @@ void DualModeController::LeApcf(CommandView command) { case bluetooth::hci::ApcfOpcode::SERVICE_DATA: { auto subcommand_view = bluetooth::hci::LeApcfServiceDataView::Create(command_view); - ASSERT(subcommand_view.IsValid()); + CHECK_PACKET_VIEW(subcommand_view); DEBUG(id_, "<< LE APCF Service Data"); DEBUG(id_, " action={}", @@ -3089,7 +3112,7 @@ void DualModeController::LeApcf(CommandView command) { case bluetooth::hci::ApcfOpcode::AD_TYPE_FILTER: { auto subcommand_view = bluetooth::hci::LeApcfAdTypeFilterView::Create(command_view); - ASSERT(subcommand_view.IsValid()); + CHECK_PACKET_VIEW(subcommand_view); DEBUG(id_, "<< LE APCF AD Type Filter"); DEBUG(id_, " action={}", @@ -3108,7 +3131,7 @@ void DualModeController::LeApcf(CommandView command) { case bluetooth::hci::ApcfOpcode::READ_EXTENDED_FEATURES: { auto subcommand_view = bluetooth::hci::LeApcfReadExtendedFeaturesView::Create(command_view); - ASSERT(subcommand_view.IsValid()); + CHECK_PACKET_VIEW(subcommand_view); DEBUG(id_, "<< LE APCF Read Extended Features"); @@ -3129,7 +3152,7 @@ void DualModeController::LeGetControllerActivityEnergyInfo( CommandView command) { auto command_view = bluetooth::hci::LeGetControllerActivityEnergyInfoView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); SendCommandCompleteUnknownOpCodeEvent( OpCode::LE_GET_CONTROLLER_ACTIVITY_ENERGY_INFO); } @@ -3137,14 +3160,14 @@ void DualModeController::LeGetControllerActivityEnergyInfo( void DualModeController::LeExSetScanParameters(CommandView command) { auto command_view = bluetooth::hci::LeExSetScanParametersView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); SendCommandCompleteUnknownOpCodeEvent(OpCode::LE_EX_SET_SCAN_PARAMETERS); } void DualModeController::GetControllerDebugInfo(CommandView command) { auto command_view = bluetooth::hci::GetControllerDebugInfoView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Get Controller Debug Info"); @@ -3333,7 +3356,7 @@ void DualModeController::CsrWritePskey(CsrPskey pskey, void DualModeController::LeSetAdvertisingSetRandomAddress(CommandView command) { auto command_view = bluetooth::hci::LeSetAdvertisingSetRandomAddressView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Set Advertising Set Random Address"); DEBUG(id_, " advertising_handle={}", command_view.GetAdvertisingHandle()); @@ -3350,7 +3373,7 @@ void DualModeController::LeSetExtendedAdvertisingParameters( CommandView command) { auto command_view = bluetooth::hci::LeSetExtendedAdvertisingParametersView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Set Extended Advertising Parameters"); DEBUG(id_, " advertising_handle={}", command_view.GetAdvertisingHandle()); @@ -3379,7 +3402,7 @@ void DualModeController::LeSetExtendedAdvertisingParameters( void DualModeController::LeSetExtendedAdvertisingData(CommandView command) { auto command_view = bluetooth::hci::LeSetExtendedAdvertisingDataView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Set Extended Advertising Data"); DEBUG(id_, " advertising_handle={}", command_view.GetAdvertisingHandle()); @@ -3395,7 +3418,7 @@ void DualModeController::LeSetExtendedAdvertisingData(CommandView command) { void DualModeController::LeSetExtendedScanResponseData(CommandView command) { auto command_view = bluetooth::hci::LeSetExtendedScanResponseDataView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Set Extended Scan Response Data"); DEBUG(id_, " advertising_handle={}", command_view.GetAdvertisingHandle()); @@ -3411,7 +3434,7 @@ void DualModeController::LeSetExtendedScanResponseData(CommandView command) { void DualModeController::LeSetExtendedAdvertisingEnable(CommandView command) { auto command_view = bluetooth::hci::LeSetExtendedAdvertisingEnableView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Set Extended Advertising Enable"); DEBUG(id_, " enable={}", @@ -3432,7 +3455,7 @@ void DualModeController::LeReadMaximumAdvertisingDataLength( CommandView command) { auto command_view = bluetooth::hci::LeReadMaximumAdvertisingDataLengthView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Read Maximum Advertising Data Length"); @@ -3447,7 +3470,7 @@ void DualModeController::LeReadNumberOfSupportedAdvertisingSets( auto command_view = bluetooth::hci::LeReadNumberOfSupportedAdvertisingSetsView::Create( command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Read Number of Supported Advertising Sets"); @@ -3460,7 +3483,7 @@ void DualModeController::LeReadNumberOfSupportedAdvertisingSets( void DualModeController::LeRemoveAdvertisingSet(CommandView command) { auto command_view = bluetooth::hci::LeRemoveAdvertisingSetView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Remove Advertising Set"); DEBUG(id_, " advertising_handle={}", command_view.GetAdvertisingHandle()); @@ -3474,7 +3497,7 @@ void DualModeController::LeRemoveAdvertisingSet(CommandView command) { void DualModeController::LeClearAdvertisingSets(CommandView command) { auto command_view = bluetooth::hci::LeClearAdvertisingSetsView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Clear Advertising Sets"); @@ -3485,7 +3508,7 @@ void DualModeController::LeClearAdvertisingSets(CommandView command) { void DualModeController::LeStartEncryption(CommandView command) { auto command_view = bluetooth::hci::LeStartEncryptionView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Start Encryption"); DEBUG(id_, " connection_handle=0x{:x}", command_view.GetConnectionHandle()); @@ -3501,7 +3524,7 @@ void DualModeController::LeStartEncryption(CommandView command) { void DualModeController::LeLongTermKeyRequestReply(CommandView command) { auto command_view = bluetooth::hci::LeLongTermKeyRequestReplyView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); uint16_t handle = command_view.GetConnectionHandle(); DEBUG(id_, "<< LE Long Term Key Request Reply"); @@ -3518,7 +3541,7 @@ void DualModeController::LeLongTermKeyRequestNegativeReply( CommandView command) { auto command_view = bluetooth::hci::LeLongTermKeyRequestNegativeReplyView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); uint16_t handle = command_view.GetConnectionHandle(); DEBUG(id_, "<< LE Long Term Key Request Negative Reply"); @@ -3535,7 +3558,7 @@ void DualModeController::LeLongTermKeyRequestNegativeReply( void DualModeController::ReadConnectionAcceptTimeout(CommandView command) { auto command_view = bluetooth::hci::ReadConnectionAcceptTimeoutView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Read Connection Accept Timeout"); @@ -3548,7 +3571,7 @@ void DualModeController::ReadConnectionAcceptTimeout(CommandView command) { void DualModeController::WriteConnectionAcceptTimeout(CommandView command) { auto command_view = bluetooth::hci::WriteConnectionAcceptTimeoutView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Write Connection Accept Timeout"); @@ -3562,7 +3585,7 @@ void DualModeController::WriteConnectionAcceptTimeout(CommandView command) { void DualModeController::ReadLoopbackMode(CommandView command) { auto command_view = bluetooth::hci::ReadLoopbackModeView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Read Loopback Mode"); @@ -3572,7 +3595,7 @@ void DualModeController::ReadLoopbackMode(CommandView command) { void DualModeController::WriteLoopbackMode(CommandView command) { auto command_view = bluetooth::hci::WriteLoopbackModeView::Create(command); - ASSERT(command_view.IsValid()); + CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Write Loopback Mode"); DEBUG(id_, " loopback_mode={}", diff --git a/model/controller/dual_mode_controller.h b/model/controller/dual_mode_controller.h index 3f56acc..f3b0ce1 100644 --- a/model/controller/dual_mode_controller.h +++ b/model/controller/dual_mode_controller.h @@ -40,6 +40,13 @@ namespace rootcanal { using ::bluetooth::hci::Address; using ::bluetooth::hci::CommandView; +// List of reject reasons for invalid packets. +enum InvalidPacketReason { + kUnknown = 0, + kParseError = 1, + kUnsupported = 2, +}; + // Emulates a dual mode BR/EDR + LE controller by maintaining the link layer // state machine detailed in the Bluetooth Core Specification Version 4.2, // Volume 6, Part B, Section 1.1 (page 30). Provides methods corresponding to @@ -78,6 +85,13 @@ class DualModeController : public Device { void HandleSco(std::shared_ptr> sco_packet); void HandleIso(std::shared_ptr> iso_packet); + /// Report invalid packets received for this controller instance + /// to an external tracker. Packets are rejected if they failed to + /// be parsed, or run into an unimplemented part of the controller. + void RegisterInvalidPacketHandler( + const std::function const&)>& handler); + // Set the callbacks for sending packets to the HCI. void RegisterEventChannel( const std::function>)>& @@ -539,6 +553,24 @@ class DualModeController : public Device { void SendCommandCompleteUnknownOpCodeEvent( bluetooth::hci::OpCode op_code) const; + // Validate that a received packet is correctly formatted. + // If the packet failed to be parsed, the function sends a + // HCI Hardware Error event to the host and logs the packet to + // the configured handler. + template + bool CheckPacketView(T const& view, std::string reason) { + if (view.IsValid()) { + return true; + } + + // Send a hardware error to reset the host, and report the packet + // for tracing. + send_event_(bluetooth::hci::HardwareErrorBuilder::Create(0x43)); + invalid_packet_handler_(id_, InvalidPacketReason::kParseError, reason, + view.bytes().bytes()); + return false; + } + // Callbacks to send packets back to the HCI. std::function)> send_acl_; std::function)> @@ -546,6 +578,11 @@ class DualModeController : public Device { std::function)> send_sco_; std::function)> send_iso_; + // Report invalid packets received on this controller instance. + std::function const&)> + invalid_packet_handler_; + // Loopback mode (Vol 4, Part E § 7.6.1). // The local loopback mode is used to pass the android Vendor Test Suite // with RootCanal. diff --git a/model/controller/link_layer_controller.cc b/model/controller/link_layer_controller.cc index 71d950d..d0754bd 100644 --- a/model/controller/link_layer_controller.cc +++ b/model/controller/link_layer_controller.cc @@ -3165,6 +3165,7 @@ void LinkLayerController::ScanIncomingLeLegacyAdvertisingPdu( // Save the original advertising type to report if the advertising // is connectable in the scan response report. scanner_.connectable_scan_response = connectable_advertising; + scanner_.extended_scan_response = false; scanner_.pending_scan_request = advertising_address; scanner_.pending_scan_request_timeout = std::chrono::steady_clock::now() + kScanRequestTimeout; @@ -3588,6 +3589,7 @@ void LinkLayerController::ScanIncomingLeExtendedAdvertisingPdu( // Save the original advertising type to report if the advertising // is connectable in the scan response report. scanner_.connectable_scan_response = connectable_advertising; + scanner_.extended_scan_response = true; scanner_.pending_scan_request = advertising_address; INFO(id_, @@ -4963,15 +4965,36 @@ void LinkLayerController::IncomingLeScanResponsePacket( resolved_advertising_address.GetAddressType()); response.connectable_ = scanner_.connectable_scan_response; response.scannable_ = true; - response.legacy_ = true; + response.legacy_ = !scanner_.extended_scan_response; response.scan_response_ = true; response.primary_phy_ = bluetooth::hci::PrimaryPhyType::LE_1M; + // TODO: SID should be set in scan response PDU response.advertising_sid_ = 0xFF; response.tx_power_ = 0x7F; - response.advertising_data_ = scan_response.GetScanResponseData(); response.rssi_ = rssi; - send_event_( - bluetooth::hci::LeExtendedAdvertisingReportBuilder::Create({response})); + response.direct_address_type_ = + bluetooth::hci::DirectAdvertisingAddressType::NO_ADDRESS_PROVIDED; + + // Each extended advertising report can only pass 229 bytes of + // advertising data (255 - size of report fields). + // RootCanal must fragment the report as necessary. + const size_t max_fragment_size = 229; + size_t offset = 0; + std::vector advertising_data = scan_response.GetScanResponseData(); + + do { + size_t remaining_size = advertising_data.size() - offset; + size_t fragment_size = std::min(max_fragment_size, remaining_size); + response.data_status_ = remaining_size <= max_fragment_size + ? bluetooth::hci::DataStatus::COMPLETE + : bluetooth::hci::DataStatus::CONTINUING; + response.advertising_data_ = + std::vector(advertising_data.begin() + offset, + advertising_data.begin() + offset + fragment_size); + offset += fragment_size; + send_event_(bluetooth::hci::LeExtendedAdvertisingReportBuilder::Create( + {response})); + } while (offset < advertising_data.size()); } } diff --git a/model/controller/link_layer_controller.h b/model/controller/link_layer_controller.h index b7af7a3..e9645b8 100644 --- a/model/controller/link_layer_controller.h +++ b/model/controller/link_layer_controller.h @@ -1070,6 +1070,7 @@ class LinkLayerController { // Save information about the advertising PDU being scanned. bool connectable_scan_response; + bool extended_scan_response; std::optional pending_scan_request{}; std::optional pending_scan_request_timeout{}; diff --git a/test/LL/DDI/SCN/BV_20_C.py b/test/LL/DDI/SCN/BV_20_C.py new file mode 100644 index 0000000..726e35a --- /dev/null +++ b/test/LL/DDI/SCN/BV_20_C.py @@ -0,0 +1,264 @@ +# Copyright 2024 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import hci_packets as hci +import link_layer_packets as ll +import math +import random +from dataclasses import dataclass +from hci_packets import ErrorCode +from py.bluetooth import Address +from py.controller import ControllerTest +from typing import Optional + +ADV_IND = 0x13 +ADV_DIRECT_IND = 0x15 +ADV_SCAN_IND = 0x12 +ADV_EXT_IND = 0x02 + + +@dataclass +class TestRound: + advertising_event_properties: int + target_address: Optional[Address] + scan_data_length: int + + +class Test(ControllerTest): + + # LL/DDI/SCN/BV-20-C [Extended Scanning, Active – LE 1M PHY, Core 5.0] + # + # Verify that a scanner IUT detects and requests additional information from + # advertisements received and reports the results from the Controller. The + # Lower Tester advertises using scannable extended advertising events on one + # channel at a time and expects the IUT to report the advertising to the + # Upper Tester. Both directed and undirected advertising events are tested. + async def test(self): + # Test rounds. + # Note: some tests are skipped as no distinction is made between + # ADV_EXT_IND, AUX_ADV_IND, AUX_CHAIN_IND. + controller = self.controller + invalid_address = Address("11:22:33:44:55:66") + test_rounds = [ + TestRound(ADV_IND, None, 0), + TestRound(ADV_IND, None, 31), + TestRound(ADV_SCAN_IND, None, 0), + TestRound(ADV_SCAN_IND, None, 31), + TestRound(ADV_EXT_IND, None, 1), + TestRound(ADV_EXT_IND, controller.address, 1), + TestRound(ADV_EXT_IND, invalid_address, 1), + TestRound(ADV_EXT_IND, None, 191), + TestRound(ADV_EXT_IND, None, 382), + TestRound(ADV_EXT_IND, None, 1647), + ] + + # 1. For each round as specified in Table 4.2-35 based on Table 4.2-36, if ScanData Length is less + # than or equal to the “Scan Max Data” then perform steps 2–8 and otherwise omit this round. + for test_round in test_rounds: + await self.steps_2_8(**vars(test_round)) + + async def steps_2_8(self, advertising_event_properties: int, target_address: Optional[Address], + scan_data_length: int): + + controller = self.controller + lower_tester_address = Address("ca:fe:ca:fe:00:01") + + # 2. The Upper Tester sends an HCI_LE_Set_Extended_Scan_Parameters command to the IUT. The + # Scanning_PHYs parameter is set as specified in Table 4.2-35, Scan_Type[0] set to 0x01 (Active + # Scanning), Scan_Interval[0] set to 0x0010, and Scan_Window[0] set to 0x0010. + # Own_Address_Type is set to 0x00 (Public Device Address), and Scanning_Filter_Policy is set to + # 0x00 (Accept All) and receives a successful HCI_Command_Complete. + controller.send_cmd( + hci.LeSetExtendedScanParameters(own_address_type=hci.OwnAddressType.PUBLIC_DEVICE_ADDRESS, + scanning_filter_policy=hci.LeScanningFilterPolicy.ACCEPT_ALL, + scanning_phys=0x1, + scanning_phy_parameters=[ + hci.ScanningPhyParameters(le_scan_type=hci.LeScanType.ACTIVE, + le_scan_interval=0x0010, + le_scan_window=0x0010) + ])) + + await self.expect_evt( + hci.LeSetExtendedScanParametersComplete(status=ErrorCode.SUCCESS, num_hci_command_packets=1)) + + # 3. The Upper Tester sends an HCI_LE_Set_Extended_Scan_Enable command to the IUT to enable + # scanning. Filter_Duplicates, Duration, and Period are all set to zero and receive a successful + # HCI_Command_Complete. + controller.send_cmd( + hci.LeSetExtendedScanEnable(enable=hci.Enable.ENABLED, + filter_duplicates=hci.Enable.DISABLED, + duration=0, + period=0)) + + await self.expect_evt(hci.LeSetExtendedScanEnableComplete(status=ErrorCode.SUCCESS, num_hci_command_packets=1)) + + # 4. The Lower Tester begins advertising on the channel as specified in Table 4.2-35 using the PDU + # Type specified in Table 4.2-36 for this round. If AUX_ADV_IND is included in the round, the + # ADV_EXT_IND includes an AuxPtr that refers to the AUX_ADV_IND on the PHY as specified in + # Table 4.2-35, and all fields specified should be included with the AUX_ADV_IND only. If AdvA is + # specified, the appropriate PDU includes the field, where “LT” equals the Lower Tester address. If + # TargetA is specified, the appropriate PDU includes the field, where “IUT” equals the IUT address + # and “Not IUT” equals a random address other than the IUT address. Repeat for at least 20 + # advertising intervals or until step 5 occurs. + connectable = (advertising_event_properties & 0x1) != 0 + scannable = (advertising_event_properties & 0x2) != 0 + directed = (advertising_event_properties & 0x4) != 0 + high_duty_cycle = (advertising_event_properties & 0x8) != 0 + legacy = (advertising_event_properties & 0x10) != 0 + + if legacy: + if advertising_event_properties == ADV_IND: + advertising_type = ll.LegacyAdvertisingType.ADV_IND + elif advertising_event_properties == ADV_DIRECT_IND: + advertising_type = ll.LegacyAdvertisingType.ADV_DIRECT_IND + elif advertising_event_properties == ADV_SCAN_IND: + advertising_type = ll.LegacyAdvertisingType.ADV_SCAN_IND + elif advertising_event_properties == ADV_NONCONN_IND: + advertising_type = ll.LegacyAdvertisingType.ADV_NONCONN_IND + pdu = ll.LeLegacyAdvertisingPdu(source_address=lower_tester_address, + destination_address=target_address or Address(), + advertising_address_type=ll.AddressType.PUBLIC, + target_address_type=ll.AddressType.PUBLIC, + advertising_type=advertising_type, + advertising_data=[]) + else: + pdu = ll.LeExtendedAdvertisingPdu(source_address=lower_tester_address, + destination_address=target_address or Address(), + advertising_address_type=ll.AddressType.PUBLIC, + target_address_type=ll.AddressType.PUBLIC, + connectable=connectable, + scannable=scannable, + directed=not target_address is None, + sid=0, + tx_power=0x7f, + primary_phy=ll.PrimaryPhyType.LE_1M, + secondary_phy=ll.SecondaryPhyType.NO_PACKETS, + advertising_data=[]) + + # 5. For undirected advertisements or advertisements directed at the IUT, the Lower Tester receives + # either a SCAN_REQ (if advertising with legacy PDUs) or an AUX_SCAN_REQ (if advertising with + # extended PDUs) on the appropriate advertising channel. The ScanA field is set to the IUT’s + # address, and the AdvA address is set to the Lower Tester’s address. The Upper Tester receives + # an HCI_LE_Extended_Advertising_Report event from the IUT with an Event_Type where bit 3 + # (Scan response) is not set, the Data Status in the Event_Type field is set to Complete (0b00), + # Periodic_Advertising_Interval is set to 0, and no advertising data. If the advertisements were + # directed but TargetA is not the IUT, skip to step 8. + for n in range(3): + if not legacy: + sid = random.randint(0, 15) + pdu.sid = sid + else: + sid = 0xff + + controller.send_ll(pdu, rssi=0) + + if target_address and target_address != controller.address: + # If the controller still emits an event, the error + # will appear in the subsequent rounds. + continue + + await self.expect_evt( + hci.LeExtendedAdvertisingReport(responses=[ + hci.LeExtendedAdvertisingResponse( + connectable=connectable, + scannable=scannable, + directed=not target_address is None, + scan_response=False, + legacy=legacy, + data_status=hci.DataStatus.COMPLETE, + address_type=hci.AddressType.PUBLIC_DEVICE_ADDRESS, + address=lower_tester_address, + primary_phy=hci.PrimaryPhyType.LE_1M, + secondary_phy=hci.SecondaryPhyType.NO_PACKETS, + advertising_sid=sid, + tx_power=0x7f, + rssi=0, + periodic_advertising_interval=0, + direct_address_type=hci.DirectAdvertisingAddressType.NO_ADDRESS_PROVIDED + if not target_address else hci.DirectAdvertisingAddressType.PUBLIC_DEVICE_ADDRESS, + direct_address=target_address or Address(), + advertising_data=[]) + ])) + + await self.expect_ll( + ll.LeScan(source_address=controller.address, + destination_address=lower_tester_address, + scanning_address_type=ll.AddressType.PUBLIC, + advertising_address_type=ll.AddressType.PUBLIC)) + + advertising_data = [random.randint(1, 254) for n in range(scan_data_length)] + + # 6. Perform step 6A or 6B depending on the PDU sent by the IUT in step 5. + # Alternative 6A (The IUT sent a SCAN_REQ in step 5): + # 6A.1 The Lower Tester responds with a SCAN_RSP packet to the IUT T_IFS after the end + # of the SCAN_REQ PDU. If ScanData is specified, the SCAN_RSP PDU includes the + # field populated with random octets from 1 to 254 of the specified count. + # Alternative 6B (The IUT sent an AUX_SCAN_REQ in step 5): + # 6B.1 The Lower Tester responds with an AUX_SCAN_RSP packet to the IUT T_IFS after + # the end of the AUX_SCAN_REQ PDU with an AdvMode of 0b00. If ScanData is + # specified, the AUX_SCAN_RSP PDU includes the AdvData field populated with + # random octets from 1 to 254 of the specified count. If the ScanData is greater in + # length than will fit in one PDU, the Lower Tester includes an AuxPtr field and sends + # one or more AUX_CHAIN_IND PDUs containing the remaining data. Each PDU + # except the last contains as much AdvData as can fit. + controller.send_ll(ll.LeScanResponse(source_address=lower_tester_address, + destination_address=controller.address, + advertising_address_type=ll.AddressType.PUBLIC, + scan_response_data=advertising_data), + rssi=0) + + # 7. If the Lower Tester sent a scan response in step 6, the Upper Tester receives one or more + # HCI_LE_Extended_Advertising_Report events from the IUT with an Event_Type where bit 3 + # (Scan response) is set, and Periodic_Advertising_Interval is set to 0. If ScanData was included in + # the response, the Upper Tester receives the data included in one of the advertising packets. If + # ScanData is sent to the Upper Tester in multiple reports, the Data Status in the Event_Type field + # for each report except the last is set to “Incomplete, more data to come”, 0b01. The Event_Type + # field for the last report sent with advertisement data is set to “Complete”, 0b00. + offset = 0 + max_fragment_length = 229 + num_fragments = math.ceil(scan_data_length / max_fragment_length) or 1 + + for n in range(num_fragments): + remaining_length = scan_data_length - offset + fragment_length = min(max_fragment_length, remaining_length) + data_status = hci.DataStatus.CONTINUING if remaining_length > max_fragment_length else hci.DataStatus.COMPLETE + await self.expect_evt( + hci.LeExtendedAdvertisingReport(responses=[ + hci.LeExtendedAdvertisingResponse( + connectable=connectable, + scannable=scannable, + directed=False, + scan_response=True, + legacy=legacy, + data_status=data_status, + address_type=hci.AddressType.PUBLIC_DEVICE_ADDRESS, + address=lower_tester_address, + primary_phy=hci.PrimaryPhyType.LE_1M, + secondary_phy=hci.SecondaryPhyType.NO_PACKETS, + # TODO SID should be set in scan response PDU + advertising_sid=0xff, + tx_power=0x7f, + rssi=0, + periodic_advertising_interval=0, + direct_address_type=hci.DirectAdvertisingAddressType.NO_ADDRESS_PROVIDED, + direct_address=Address(), + advertising_data=advertising_data[offset:offset + fragment_length]) + ])) + offset += fragment_length + + # 8. The Upper Tester sends an HCI_LE_Set_Scan_Enable to the IUT to disable scanning and + # receives an HCI_Command_Complete event in response. + controller.send_cmd(hci.LeSetExtendedScanEnable(enable=hci.Enable.DISABLED)) + + await self.expect_evt(hci.LeSetExtendedScanEnableComplete(status=ErrorCode.SUCCESS, num_hci_command_packets=1)) diff --git a/test/invalid_packet_handler_unittest.cc b/test/invalid_packet_handler_unittest.cc new file mode 100644 index 0000000..803124b --- /dev/null +++ b/test/invalid_packet_handler_unittest.cc @@ -0,0 +1,82 @@ +/* + * Copyright 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "log.h" +#include "model/controller/dual_mode_controller.h" + +namespace rootcanal { + +using namespace bluetooth::hci; + +class InvalidPacketHandlerTest : public ::testing::Test { + public: + InvalidPacketHandlerTest() = default; + ~InvalidPacketHandlerTest() override = default; + + protected: + DualModeController controller_; +}; + +// Set Event Mask command with missing parameters. +const std::vector kInvalidCommandPacket = {0x01, 0x0C, 0x03, + 0xff, 0xff, 0xff}; + +// Hardware Error event with code 0x43. +const std::vector kHardwareErrorEvent = {0x10, 0x01, 0x43}; + +TEST_F(InvalidPacketHandlerTest, DefaultHandler) { + // Validate that the default invalid packet handler causes + // an abort when an invalid packet is received. + ASSERT_DEATH(controller_.HandleCommand(std::make_shared>( + kInvalidCommandPacket)), + ""); +} + +TEST_F(InvalidPacketHandlerTest, RegisteredHandler) { + static struct { + uint32_t id; + InvalidPacketReason reason; + std::vector bytes; + } invalid_packet; + + static std::vector hci_event; + + // Validate that the registered invalid packet handler is correctly + // invoked when an invalid packet is received. + controller_.RegisterInvalidPacketHandler( + [&](uint32_t id, InvalidPacketReason reason, std::string, + std::vector const& bytes) { + invalid_packet.id = id; + invalid_packet.reason = reason; + invalid_packet.bytes = bytes; + }); + + controller_.RegisterEventChannel( + [&](std::shared_ptr> packet) { + hci_event = std::vector(*packet); + }); + + controller_.HandleCommand( + std::make_shared>(kInvalidCommandPacket)); + ASSERT_EQ(invalid_packet.id, controller_.id_); + ASSERT_EQ(invalid_packet.reason, InvalidPacketReason::kParseError); + ASSERT_EQ(invalid_packet.bytes, kInvalidCommandPacket); + ASSERT_EQ(hci_event, kHardwareErrorEvent); +} + +} // namespace rootcanal diff --git a/test/main.py b/test/main.py index ecf8609..b61a5b8 100644 --- a/test/main.py +++ b/test/main.py @@ -58,6 +58,7 @@ 'LL.DDI.SCN.BV_14_C', 'LL.DDI.SCN.BV_18_C', 'LL.DDI.SCN.BV_19_C', + 'LL.DDI.SCN.BV_20_C', 'LL.DDI.SCN.BV_79_C', 'LL.SEC.ADV.BV_11_C', 'LMP.LIH.BV_01_C',