Skip to content

Commit

Permalink
pw_bluetooth_sapphire: Migrate LELongTermKeyRequest event to Emboss
Browse files Browse the repository at this point in the history
Bug: b/42167863
Test: fx test bt-host-hci-tests
Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/1112374
GitOrigin-RevId: c63b6cde39546d752418e0f181f48013f3352147
Change-Id: Iae47329940c2ebc31942ec525637fe11b06e3879
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/235352
Reviewed-by: Faraaz Sareshwala <[email protected]>
Pigweed-Auto-Submit: Ben Lawson <[email protected]>
Commit-Queue: Ben Lawson <[email protected]>
Docs-Not-Needed: Ben Lawson <[email protected]>
Lint: Lint 🤖 <[email protected]>
  • Loading branch information
BenjaminLawson authored and CQ Bot Account committed Sep 12, 2024
1 parent 9de41b0 commit 73627bf
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 27 deletions.
1 change: 1 addition & 0 deletions pw_bluetooth_sapphire/host/hci/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ cc_library(
"-Wno-unused-parameter",
"-Wno-deprecated-this-capture",
"-Wswitch-enum",
"-Wno-shadow",
] + COPTS,
deps = [
"//pw_bluetooth_sapphire:public",
Expand Down
5 changes: 5 additions & 0 deletions pw_bluetooth_sapphire/host/hci/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ import("$dir_pw_unit_test/test.gni")

dir_public_hci = "../../public/pw_bluetooth_sapphire/internal/host/hci"

config("copts") {
cflags_cc = [ "-Wno-shadow" ]
}

pw_source_set("hci") {
public = [
"$dir_public_hci/acl_connection.h",
Expand Down Expand Up @@ -67,6 +71,7 @@ pw_source_set("hci") {

remove_configs = [ "$dir_pw_build:internal_strict_warnings" ]
configs = [
":copts",
"$dir_pw_build:internal_strict_warnings_core",
"$dir_pw_bluetooth_sapphire/host:copts",
]
Expand Down
22 changes: 8 additions & 14 deletions pw_bluetooth_sapphire/host/hci/low_energy_connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,30 +119,24 @@ void LowEnergyConnection::HandleEncryptionStatus(Result<bool> result,
}

CommandChannel::EventCallbackResult
LowEnergyConnection::OnLELongTermKeyRequestEvent(const EventPacket& event) {
BT_ASSERT(event.event_code() == hci_spec::kLEMetaEventCode);
BT_ASSERT(event.params<hci_spec::LEMetaEventParams>().subevent_code ==
hci_spec::kLELongTermKeyRequestSubeventCode);

auto* params =
event.subevent_params<hci_spec::LELongTermKeyRequestSubeventParams>();
if (!params) {
LowEnergyConnection::OnLELongTermKeyRequestEvent(
const EmbossEventPacket& event) {
auto view = event.unchecked_view<
pw::bluetooth::emboss::LELongTermKeyRequestSubeventView>();
if (!view.IsComplete()) {
bt_log(WARN, "hci", "malformed LE LTK request event");
return CommandChannel::EventCallbackResult::kContinue;
}

hci_spec::ConnectionHandle handle = pw::bytes::ConvertOrderFrom(
cpp20::endian::little, params->connection_handle);
hci_spec::ConnectionHandle handle = view.connection_handle().Read();

// Silently ignore the event as it isn't meant for this connection.
if (handle != this->handle()) {
return CommandChannel::EventCallbackResult::kContinue;
}

uint64_t rand =
pw::bytes::ConvertOrderFrom(cpp20::endian::little, params->random_number);
uint16_t ediv = pw::bytes::ConvertOrderFrom(cpp20::endian::little,
params->encrypted_diversifier);
uint64_t rand = view.random_number().Read();
uint16_t ediv = view.encrypted_diversifier().Read();

bt_log(DEBUG,
"hci",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -700,18 +700,6 @@ constexpr EventCode kLEReadRemoteFeaturesCompleteSubeventCode = 0x04;
// LE Long Term Key Request Event (v4.0) (LE)
constexpr EventCode kLELongTermKeyRequestSubeventCode = 0x05;

struct LELongTermKeyRequestSubeventParams {
// Connection Handle (only the lower 12-bits are meaningful).
// Range: 0x0000 to kConnectionHandleMax in hci_constants.h
ConnectionHandle connection_handle;

// 64-bit random number.
uint64_t random_number;

// 16-bit encrypted diversifier.
uint16_t encrypted_diversifier;
} __attribute__((packed));

// LE Remote Connection Parameter Request Event (v4.1) (LE)
constexpr EventCode kLERemoteConnectionParameterRequestSubeventCode = 0x06;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class LowEnergyConnection : public AclConnection,

// HCI event handlers.
CommandChannel::EventCallbackResult OnLELongTermKeyRequestEvent(
const EventPacket& event);
const EmbossEventPacket& event);

// IDs for encryption related HCI event handlers.
CommandChannel::EventHandlerId le_ltk_request_id_;
Expand Down

0 comments on commit 73627bf

Please sign in to comment.