From 42d905b44b4b135b0fd4f7449eee468be95b5f8f Mon Sep 17 00:00:00 2001 From: Ben Date: Fri, 23 Aug 2024 17:38:43 +0000 Subject: [PATCH] pw_bluetooth_sapphire: Migrate UserConfirmationRequest event 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/+/1094832 GitOrigin-RevId: b0efa5e53ef74107090b8e8d5c6304d86399fb1c Change-Id: Ieb11ae142a54cfb82923e441dd59bfe1dbe74b54 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/230534 Lint: Lint 🤖 Commit-Queue: Jason Graffius Reviewed-by: Lulu Wang --- .../host/gap/bredr_connection_manager.cc | 22 +++++++++---------- .../host/testing/fake_controller.cc | 11 +++++----- .../host/gap/bredr_connection_manager.h | 2 +- .../internal/host/hci-spec/protocol.h | 8 ------- 4 files changed, 17 insertions(+), 26 deletions(-) diff --git a/pw_bluetooth_sapphire/host/gap/bredr_connection_manager.cc b/pw_bluetooth_sapphire/host/gap/bredr_connection_manager.cc index 4a567c5329..370369b4e7 100644 --- a/pw_bluetooth_sapphire/host/gap/bredr_connection_manager.cc +++ b/pw_bluetooth_sapphire/host/gap/bredr_connection_manager.cc @@ -1518,25 +1518,24 @@ BrEdrConnectionManager::OnSimplePairingComplete(const hci::EventPacket& event) { hci::CommandChannel::EventCallbackResult BrEdrConnectionManager::OnUserConfirmationRequest( - const hci::EventPacket& event) { - BT_DEBUG_ASSERT(event.event_code() == - hci_spec::kUserConfirmationRequestEventCode); - const auto& params = - event.params(); + 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 %s for unconnected addr %s", __func__, - bt_str(params.bd_addr)); - SendUserConfirmationRequestNegativeReply(params.bd_addr); + bt_str(bd_addr)); + SendUserConfirmationRequestNegativeReply(bd_addr); return hci::CommandChannel::EventCallbackResult::kContinue; } - auto confirm_cb = [self = weak_self_.GetWeakPtr(), - bd_addr = params.bd_addr](bool confirm) { + auto confirm_cb = [self = weak_self_.GetWeakPtr(), bd_addr](bool confirm) { if (!self.is_alive()) { return; } @@ -1548,8 +1547,7 @@ BrEdrConnectionManager::OnUserConfirmationRequest( } }; conn_pair->second->pairing_state_manager().OnUserConfirmationRequest( - pw::bytes::ConvertOrderFrom(cpp20::endian::little, params.numeric_value), - std::move(confirm_cb)); + params.numeric_value().Read(), std::move(confirm_cb)); 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 1a67c29e70..1e679f211c 100644 --- a/pw_bluetooth_sapphire/host/testing/fake_controller.cc +++ b/pw_bluetooth_sapphire/host/testing/fake_controller.cc @@ -2382,11 +2382,12 @@ void FakeController::OnIOCapabilityRequestReplyCommand( SendCommandChannelPacket(io_response.data()); // Event type based on |params.io_capability| and |io_response.io_capability|. - hci_spec::UserConfirmationRequestEventParams request = {}; - request.bd_addr = DeviceAddressBytes(params.bd_addr()); - request.numeric_value = 0; - SendEvent(hci_spec::kUserConfirmationRequestEventCode, - BufferView(&request, sizeof(request))); + auto event = + hci::EmbossEventPacket::New( + hci_spec::kUserConfirmationRequestEventCode); + event.view_t().bd_addr().CopyFrom(params.bd_addr()); + event.view_t().numeric_value().Write(0); + SendCommandChannelPacket(event.data()); } void FakeController::OnUserConfirmationRequestReplyCommand( 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 29aa6438e6..5b45419001 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 @@ -284,7 +284,7 @@ class BrEdrConnectionManager final { hci::CommandChannel::EventCallbackResult OnSimplePairingComplete( const hci::EventPacket& event); hci::CommandChannel::EventCallbackResult OnUserConfirmationRequest( - const hci::EventPacket& event); + const hci::EmbossEventPacket& event_packet); hci::CommandChannel::EventCallbackResult OnUserPasskeyRequest( const hci::EventPacket& event); hci::CommandChannel::EventCallbackResult OnUserPasskeyNotification( 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 7c95024285..379f1cb391 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 @@ -921,14 +921,6 @@ constexpr EventCode kIOCapabilityResponseEventCode = 0x32; // User Confirmation Request Event (v2.1 + EDR) (BR/EDR) constexpr EventCode kUserConfirmationRequestEventCode = 0x33; -struct UserConfirmationRequestEventParams { - // Address of the device involved in simple pairing process - DeviceAddressBytes bd_addr; - - // Numeric value to be displayed. Valid values are 0 - 999999. - uint32_t numeric_value; -} __attribute__((packed)); - // ================================================ // User Passkey Request Event (v2.1 + EDR) (BR/EDR) constexpr EventCode kUserPasskeyRequestEventCode = 0x34;