Skip to content

Commit

Permalink
pw_bluetooth_sapphire: Migrate SimplePairingCompleteEvent to emboss
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Josh Conner <[email protected]>
Lint: Lint 🤖 <[email protected]>
  • Loading branch information
BenjaminLawson authored and CQ Bot Account committed Aug 23, 2024
1 parent cdd0561 commit e830f7d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 29 deletions.
19 changes: 10 additions & 9 deletions pw_bluetooth_sapphire/host/gap/bredr_connection_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<hci_spec::SimplePairingCompleteEventParams>();
BrEdrConnectionManager::OnSimplePairingComplete(
const hci::EmbossEventPacket& event_packet) {
auto params =
event_packet
.view<pw::bluetooth::emboss::SimplePairingCompleteEventView>();
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;
}

Expand Down
23 changes: 13 additions & 10 deletions pw_bluetooth_sapphire/host/testing/fake_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<pwemb::SimplePairingCompleteEventWriter>(
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<pwemb::LinkKeyNotificationEventWriter>(
Expand Down Expand Up @@ -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<pwemb::SimplePairingCompleteEventWriter>(
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(
Expand Down
1 change: 0 additions & 1 deletion pw_bluetooth_sapphire/host/transport/control_packets.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e830f7d

Please sign in to comment.