Skip to content

Commit

Permalink
pw_bluetooth_sapphire: Embossify ReadLocalNameReturnParams
Browse files Browse the repository at this point in the history
Use emboss definitions instead of the packed struct
ReadLocalNameReturnParams.

Bug: b/42167863
Test: fx test //src/connectivity/bluetooth/core/bt-host
Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/1107956
GitOrigin-RevId: 296ccbb302582669f5dbb323fcdaf1217c216bc7
Change-Id: I2e74f500cfdef1b4b204684721fddf6ee97ec626
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/232753
Pigweed-Auto-Submit: Jason Graffius <[email protected]>
Commit-Queue: Auto-Submit <[email protected]>
Lint: Lint 🤖 <[email protected]>
Reviewed-by: Ben Lawson <[email protected]>
  • Loading branch information
josh-conner authored and CQ Bot Account committed Aug 31, 2024
1 parent 99acb26 commit 904184e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 20 deletions.
17 changes: 9 additions & 8 deletions pw_bluetooth_sapphire/host/testing/fake_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1854,14 +1854,15 @@ void FakeController::OnReadScanEnable() {
}

void FakeController::OnReadLocalName() {
hci_spec::ReadLocalNameReturnParams params;
params.status = pwemb::StatusCode::SUCCESS;
auto mut_view =
MutableBufferView(params.local_name, hci_spec::kMaxNameLength);
mut_view.Write((const uint8_t*)(local_name_.c_str()),
std::min(local_name_.length() + 1, hci_spec::kMaxNameLength));
RespondWithCommandComplete(hci_spec::kReadLocalName,
BufferView(&params, sizeof(params)));
auto event_packet = hci::EmbossEventPacket::New<
pwemb::ReadLocalNameCommandCompleteEventWriter>(
hci_spec::kCommandCompleteEventCode);
auto view = event_packet.view_t();
view.status().Write(pwemb::StatusCode::SUCCESS);
unsigned char* name_from_event = view.local_name().BackingStorage().data();
char* name_as_cstr = reinterpret_cast<char*>(name_from_event);
std::strncpy(name_as_cstr, local_name_.c_str(), hci_spec::kMaxNameLength);
RespondWithCommandComplete(pwemb::OpCode::READ_LOCAL_NAME, &event_packet);
}

void FakeController::OnWriteLocalName(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,18 +298,6 @@ constexpr OpCode kWriteLocalName = ControllerAndBasebandOpCode(0x0013);
// Read Local Name Command (v1.1) (BR/EDR)
constexpr OpCode kReadLocalName = ControllerAndBasebandOpCode(0x0014);

struct ReadLocalNameReturnParams {
// See enum StatusCode in hci_constants.h.
StatusCode status;

// A UTF-8 encoded User Friendly Descriptive Name for the device.
// If the name contained in the parameter is shorter than 248 octets, the end
// of the name is indicated by a NULL octet (0x00), and the following octets
// (to fill up 248 octets, which is the length of the parameter) do not have
// valid values.
uint8_t local_name[kMaxNameLength];
} __attribute__((packed));

// ==========================================
// Write Page Timeout Command (v1.1) (BR/EDR)
constexpr OpCode kWritePageTimeout = ControllerAndBasebandOpCode(0x0018);
Expand Down

0 comments on commit 904184e

Please sign in to comment.