Skip to content

Commit

Permalink
pw_bluetooth_sapphire: Migrate UserConfirmationRequest event 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/+/1094832
GitOrigin-RevId: b0efa5e53ef74107090b8e8d5c6304d86399fb1c
Change-Id: Ieb11ae142a54cfb82923e441dd59bfe1dbe74b54
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/230534
Lint: Lint 🤖 <[email protected]>
Commit-Queue: Jason Graffius <[email protected]>
Reviewed-by: Lulu Wang <[email protected]>
  • Loading branch information
BenjaminLawson authored and CQ Bot Account committed Aug 23, 2024
1 parent 1d56224 commit 42d905b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 26 deletions.
22 changes: 10 additions & 12 deletions pw_bluetooth_sapphire/host/gap/bredr_connection_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<hci_spec::UserConfirmationRequestEventParams>();
const hci::EmbossEventPacket& event_packet) {
auto params =
event_packet
.view<pw::bluetooth::emboss::UserConfirmationRequestEventView>();
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;
}
Expand All @@ -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;
}

Expand Down
11 changes: 6 additions & 5 deletions pw_bluetooth_sapphire/host/testing/fake_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<pwemb::UserConfirmationRequestEventWriter>(
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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 42d905b

Please sign in to comment.