[bt][hci-spec] Migrate Read Remote Version Info command to Emboss

Bug: 86811
Test: fx test //src/connectivity/bluetooth/core/bt-host
Change-Id: Ib5d65241f9aba1695893370c1d3f3a63aef5044f
Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/772144
Commit-Queue: Ben Lawson <benlawson@google.com>
Reviewed-by: Faraaz Sareshwala <fsareshwala@google.com>
diff --git a/pw_bluetooth_sapphire/host/gap/bredr_interrogator.cc b/pw_bluetooth_sapphire/host/gap/bredr_interrogator.cc
index 33e4ee8..4e5ff7b 100644
--- a/pw_bluetooth_sapphire/host/gap/bredr_interrogator.cc
+++ b/pw_bluetooth_sapphire/host/gap/bredr_interrogator.cc
@@ -174,10 +174,9 @@
 }
 
 void BrEdrInterrogator::QueueReadRemoteVersionInformation() {
-  auto packet = hci::CommandPacket::New(hci_spec::kReadRemoteVersionInfo,
-                                        sizeof(hci_spec::ReadRemoteVersionInfoCommandParams));
-  packet->mutable_payload<hci_spec::ReadRemoteVersionInfoCommandParams>()->connection_handle =
-      htole16(handle_);
+  auto packet = hci::EmbossCommandPacket::New<hci_spec::ReadRemoteVersionInfoCommandWriter>(
+      hci_spec::kReadRemoteVersionInfo);
+  packet.view_t().connection_handle().Write(handle_);
 
   auto cmd_cb = [this](const hci::EventPacket& event) {
     if (hci_is_error(event, WARN, "gap", "read remote version info failed")) {
diff --git a/pw_bluetooth_sapphire/host/gap/low_energy_interrogator.cc b/pw_bluetooth_sapphire/host/gap/low_energy_interrogator.cc
index 57c68ed..ee82edf 100644
--- a/pw_bluetooth_sapphire/host/gap/low_energy_interrogator.cc
+++ b/pw_bluetooth_sapphire/host/gap/low_energy_interrogator.cc
@@ -93,10 +93,9 @@
 }
 
 void LowEnergyInterrogator::QueueReadRemoteVersionInformation() {
-  auto packet = hci::CommandPacket::New(hci_spec::kReadRemoteVersionInfo,
-                                        sizeof(hci_spec::ReadRemoteVersionInfoCommandParams));
-  packet->mutable_payload<hci_spec::ReadRemoteVersionInfoCommandParams>()->connection_handle =
-      htole16(handle_);
+  auto packet = hci::EmbossCommandPacket::New<hci_spec::ReadRemoteVersionInfoCommandWriter>(
+      hci_spec::kReadRemoteVersionInfo);
+  packet.view_t().connection_handle().Write(handle_);
 
   // It's safe to capture |this| instead of a weak ptr to self because |cmd_runner_| guarantees that
   // |cmd_cb| won't be invoked if |cmd_runner_| is destroyed, and |this| outlives |cmd_runner_|.
diff --git a/pw_bluetooth_sapphire/host/hci-spec/hci-protocol.emb b/pw_bluetooth_sapphire/host/hci-spec/hci-protocol.emb
index 864a47d..b300a30 100644
--- a/pw_bluetooth_sapphire/host/hci-spec/hci-protocol.emb
+++ b/pw_bluetooth_sapphire/host/hci-spec/hci-protocol.emb
@@ -450,6 +450,20 @@
     --  - 0x01-0xFF the corresponding features page (see Vol 2, Part C, Sec 3.3).
 
 
+struct ReadRemoteVersionInfoCommand:
+  -- Read Remote Version Information Command (v1.1) (BR/EDR & LE)
+  --
+  -- NOTE on ReturnParams: No Command Complete event will be sent by the
+  -- Controller to indicate that this command has been completed. Instead, the
+  -- Read Remote Version Information Complete event will indicate that this
+  -- command has been completed.
+  let hdr_size = EmbossCommandHeader.$size_in_bytes
+  0     [+hdr_size]  EmbossCommandHeader  header
+  $next [+2]         UInt                 connection_handle
+    -- Connection_Handle (only the lower 12-bits are meaningful).
+    --   Range: 0x0000 to 0x0EFF
+
+
 struct SynchronousConnectionParameters:
   -- Enhanced Setup Synchronous Connection Command (CSA2) (BR/EDR)
 
diff --git a/pw_bluetooth_sapphire/host/hci-spec/protocol.h b/pw_bluetooth_sapphire/host/hci-spec/protocol.h
index 774950c..524680d 100644
--- a/pw_bluetooth_sapphire/host/hci-spec/protocol.h
+++ b/pw_bluetooth_sapphire/host/hci-spec/protocol.h
@@ -213,17 +213,6 @@
 // Read Remote Version Information Command (v1.1) (BR/EDR & LE)
 constexpr OpCode kReadRemoteVersionInfo = LinkControlOpCode(0x001D);
 
-struct ReadRemoteVersionInfoCommandParams {
-  // Connection_Handle (only the lower 12-bits are meaningful).
-  //   Range: 0x0000 to kConnectionHandleMax in hci_constants.h
-  ConnectionHandle connection_handle;
-} __PACKED;
-
-// NOTE on ReturnParams: No Command Complete event will be sent by the
-// Controller to indicate that this command has been completed. Instead, the
-// Read Remote Version Information Complete event will indicate that this
-// command has been completed.
-
 // =============================================
 // Reject Synchronous Connection Command (BR/EDR)
 constexpr OpCode kRejectSynchronousConnectionRequest = LinkControlOpCode(0x002A);
diff --git a/pw_bluetooth_sapphire/host/testing/fake_controller.cc b/pw_bluetooth_sapphire/host/testing/fake_controller.cc
index 6ac0cea..4275eb8 100644
--- a/pw_bluetooth_sapphire/host/testing/fake_controller.cc
+++ b/pw_bluetooth_sapphire/host/testing/fake_controller.cc
@@ -1378,12 +1378,12 @@
 }
 
 void FakeController::OnReadRemoteVersionInfoCommandReceived(
-    const hci_spec::ReadRemoteVersionInfoCommandParams& params) {
+    hci_spec::ReadRemoteVersionInfoCommandView params) {
   RespondWithCommandStatus(hci_spec::kReadRemoteVersionInfo, hci_spec::StatusCode::SUCCESS);
 
   hci_spec::ReadRemoteVersionInfoCompleteEventParams response = {};
   response.status = hci_spec::StatusCode::SUCCESS;
-  response.connection_handle = params.connection_handle;
+  response.connection_handle = htole16(params.connection_handle().Read());
   response.lmp_version = hci_spec::HCIVersion::k4_2;
   response.manufacturer_name = 0xFFFF;  // anything
   response.lmp_subversion = 0xADDE;     // anything
@@ -2968,11 +2968,6 @@
       OnWriteLEHostSupportCommandReceived(params);
       break;
     }
-    case hci_spec::kReadRemoteVersionInfo: {
-      const auto& params = command_packet.payload<hci_spec::ReadRemoteVersionInfoCommandParams>();
-      OnReadRemoteVersionInfoCommandReceived(params);
-      break;
-    }
     case hci_spec::kLinkKeyRequestReply: {
       const auto& params = command_packet.payload<hci_spec::LinkKeyRequestReplyCommandView>();
       OnLinkKeyRequestReplyCommandReceived(params);
@@ -3031,7 +3026,8 @@
     case hci_spec::kSetConnectionEncryption:
     case hci_spec::kRemoteNameRequest:
     case hci_spec::kReadRemoteSupportedFeatures:
-    case hci_spec::kReadRemoteExtendedFeatures: {
+    case hci_spec::kReadRemoteExtendedFeatures:
+    case hci_spec::kReadRemoteVersionInfo: {
       // This case is for packet types that have been migrated to the new Emboss architecture. Their
       // old version can be still be assembled from the HciEmulator channel, so here we repackage
       // and forward them as Emboss packets.
@@ -3128,6 +3124,11 @@
       OnReadRemoteExtendedFeaturesCommandReceived(params);
       break;
     }
+    case hci_spec::kReadRemoteVersionInfo: {
+      const auto params = command_packet.view<hci_spec::ReadRemoteVersionInfoCommandView>();
+      OnReadRemoteVersionInfoCommandReceived(params);
+      break;
+    }
     default: {
       bt_log(WARN, "fake-hci",
              "received Emboss command either unimplemented or not yet migrated to Emboss, with "
diff --git a/pw_bluetooth_sapphire/host/testing/fake_controller.h b/pw_bluetooth_sapphire/host/testing/fake_controller.h
index a5abd4a..d54bd37 100644
--- a/pw_bluetooth_sapphire/host/testing/fake_controller.h
+++ b/pw_bluetooth_sapphire/host/testing/fake_controller.h
@@ -615,8 +615,7 @@
       hci_spec::ReadRemoteSupportedFeaturesCommandView params);
 
   // Called when a HCI_Read_Remote_Version_Information command is received.
-  void OnReadRemoteVersionInfoCommandReceived(
-      const hci_spec::ReadRemoteVersionInfoCommandParams& params);
+  void OnReadRemoteVersionInfoCommandReceived(hci_spec::ReadRemoteVersionInfoCommandView params);
 
   // Called when a HCI_Read_Remote_Extended_Features command is received.
   void OnReadRemoteExtendedFeaturesCommandReceived(