From e830f7dc8049c8ea92e21abf193057cdc367f355 Mon Sep 17 00:00:00 2001 From: Ben Date: Fri, 23 Aug 2024 18:47:25 +0000 Subject: [PATCH] pw_bluetooth_sapphire: Migrate SimplePairingCompleteEvent to emboss MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug: b/42167863 Test: fx test bt-host-gap-tests Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/1095799 GitOrigin-RevId: dcbb832b358915d7e8363946f3531062cf719706 Change-Id: Ia86dae48fc6fba097260ad1001aeb083d6e7805d Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/230555 Commit-Queue: Jason Graffius Reviewed-by: Josh Conner Lint: Lint 🤖 --- .../host/gap/bredr_connection_manager.cc | 19 +++++++-------- .../host/testing/fake_controller.cc | 23 +++++++++++-------- .../host/transport/control_packets.cc | 1 - .../host/gap/bredr_connection_manager.h | 2 +- .../internal/host/hci-spec/protocol.h | 8 ------- 5 files changed, 24 insertions(+), 29 deletions(-) diff --git a/pw_bluetooth_sapphire/host/gap/bredr_connection_manager.cc b/pw_bluetooth_sapphire/host/gap/bredr_connection_manager.cc index 2aa7ae5397..27ae6298d4 100644 --- a/pw_bluetooth_sapphire/host/gap/bredr_connection_manager.cc +++ b/pw_bluetooth_sapphire/host/gap/bredr_connection_manager.cc @@ -1496,23 +1496,24 @@ BrEdrConnectionManager::OnLinkKeyNotification( } hci::CommandChannel::EventCallbackResult -BrEdrConnectionManager::OnSimplePairingComplete(const hci::EventPacket& event) { - BT_DEBUG_ASSERT(event.event_code() == - hci_spec::kSimplePairingCompleteEventCode); - const auto& params = - event.params(); +BrEdrConnectionManager::OnSimplePairingComplete( + const hci::EmbossEventPacket& event_packet) { + auto params = + event_packet + .view(); + DeviceAddressBytes bd_addr = DeviceAddressBytes(params.bd_addr()); - auto conn_pair = FindConnectionByAddress(params.bd_addr); + auto conn_pair = FindConnectionByAddress(bd_addr); if (!conn_pair) { bt_log(WARN, "gap-bredr", "got Simple Pairing Complete (status: %s) for unconnected addr %s", - bt_str(ToResult(params.status)), - bt_str(params.bd_addr)); + bt_str(ToResult(params.status().Read())), + bt_str(bd_addr)); return hci::CommandChannel::EventCallbackResult::kContinue; } conn_pair->second->pairing_state_manager().OnSimplePairingComplete( - params.status); + params.status().Read()); return hci::CommandChannel::EventCallbackResult::kContinue; } diff --git a/pw_bluetooth_sapphire/host/testing/fake_controller.cc b/pw_bluetooth_sapphire/host/testing/fake_controller.cc index 1e679f211c..7ee0659ac3 100644 --- a/pw_bluetooth_sapphire/host/testing/fake_controller.cc +++ b/pw_bluetooth_sapphire/host/testing/fake_controller.cc @@ -2403,11 +2403,12 @@ void FakeController::OnUserConfirmationRequestReplyCommand( RespondWithCommandStatus(hci_spec::kUserConfirmationRequestReply, pwemb::StatusCode::SUCCESS); - hci_spec::SimplePairingCompleteEventParams pairing_event; - pairing_event.bd_addr = DeviceAddressBytes(params.bd_addr()); - pairing_event.status = pwemb::StatusCode::SUCCESS; - SendEvent(hci_spec::kSimplePairingCompleteEventCode, - BufferView(&pairing_event, sizeof(pairing_event))); + auto pairing_event = + hci::EmbossEventPacket::New( + hci_spec::kSimplePairingCompleteEventCode); + pairing_event.view_t().bd_addr().CopyFrom(params.bd_addr()); + pairing_event.view_t().status().Write(pwemb::StatusCode::SUCCESS); + SendCommandChannelPacket(pairing_event.data()); auto link_key_event = hci::EmbossEventPacket::New( @@ -2463,11 +2464,13 @@ void FakeController::OnUserConfirmationRequestNegativeReplyCommand( RespondWithCommandComplete(hci_spec::kUserConfirmationRequestNegativeReply, pwemb::StatusCode::SUCCESS); - hci_spec::SimplePairingCompleteEventParams pairing_event; - pairing_event.bd_addr = DeviceAddressBytes(params.bd_addr()); - pairing_event.status = pwemb::StatusCode::AUTHENTICATION_FAILURE; - SendEvent(hci_spec::kSimplePairingCompleteEventCode, - BufferView(&pairing_event, sizeof(pairing_event))); + auto pairing_event = + hci::EmbossEventPacket::New( + hci_spec::kSimplePairingCompleteEventCode); + pairing_event.view_t().bd_addr().CopyFrom(params.bd_addr()); + pairing_event.view_t().status().Write( + pwemb::StatusCode::AUTHENTICATION_FAILURE); + SendCommandChannelPacket(pairing_event.data()); } void FakeController::OnSetConnectionEncryptionCommand( diff --git a/pw_bluetooth_sapphire/host/transport/control_packets.cc b/pw_bluetooth_sapphire/host/transport/control_packets.cc index 151944e70c..ddb11f427b 100644 --- a/pw_bluetooth_sapphire/host/transport/control_packets.cc +++ b/pw_bluetooth_sapphire/host/transport/control_packets.cc @@ -170,7 +170,6 @@ bool EventPacket::ToStatusCode( CASE_EMBOSS_EVENT_STATUS(DisconnectionComplete); CASE_EMBOSS_EVENT_STATUS(RemoteNameRequestComplete); CASE_EVENT_STATUS(ReadRemoteSupportedFeaturesComplete); - CASE_EVENT_STATUS(SimplePairingComplete); CASE_EMBOSS_EVENT_STATUS(InquiryComplete); case hci_spec::kEncryptionChangeEventCode: return StatusCodeFromEmbossEvent< diff --git a/pw_bluetooth_sapphire/public/pw_bluetooth_sapphire/internal/host/gap/bredr_connection_manager.h b/pw_bluetooth_sapphire/public/pw_bluetooth_sapphire/internal/host/gap/bredr_connection_manager.h index 79d5f275a2..017d5c184d 100644 --- a/pw_bluetooth_sapphire/public/pw_bluetooth_sapphire/internal/host/gap/bredr_connection_manager.h +++ b/pw_bluetooth_sapphire/public/pw_bluetooth_sapphire/internal/host/gap/bredr_connection_manager.h @@ -282,7 +282,7 @@ class BrEdrConnectionManager final { hci::CommandChannel::EventCallbackResult OnLinkKeyNotification( const hci::EmbossEventPacket& event); hci::CommandChannel::EventCallbackResult OnSimplePairingComplete( - const hci::EventPacket& event); + const hci::EmbossEventPacket& event_packet); hci::CommandChannel::EventCallbackResult OnUserConfirmationRequest( const hci::EmbossEventPacket& event_packet); hci::CommandChannel::EventCallbackResult OnUserPasskeyRequest( diff --git a/pw_bluetooth_sapphire/public/pw_bluetooth_sapphire/internal/host/hci-spec/protocol.h b/pw_bluetooth_sapphire/public/pw_bluetooth_sapphire/internal/host/hci-spec/protocol.h index b24f4631c0..155ee4f9b1 100644 --- a/pw_bluetooth_sapphire/public/pw_bluetooth_sapphire/internal/host/hci-spec/protocol.h +++ b/pw_bluetooth_sapphire/public/pw_bluetooth_sapphire/internal/host/hci-spec/protocol.h @@ -930,14 +930,6 @@ constexpr EventCode kUserPasskeyRequestEventCode = 0x34; // Simple Pairing Complete Event (v2.1 + EDR) (BR/EDR) constexpr EventCode kSimplePairingCompleteEventCode = 0x36; -struct SimplePairingCompleteEventParams { - // See enum StatusCode in hci_constants.h. - StatusCode status; - - // Address of the device involved in simple pairing process - DeviceAddressBytes bd_addr; -} __attribute__((packed)); - // ===================================================== // User Passkey Notification Event (v2.1 + EDR) (BR/EDR) constexpr EventCode kUserPasskeyNotificationEventCode = 0x3B;