Refactor hoth_updater_cli to reuse definitions

Remove hardcoded command values and redundant structs and use
definitions from google3/host_commands.h for consistency.

TESTED=pending image

Google-Bug-Id:442614164

Change-Id: I64baa9c07ec59a6295581305ea2a0cb51df18d88
Signed-off-by: Christian Kungler ckungler@google.com
diff --git a/google3/host_commands.h b/google3/host_commands.h
index d327c8b..f53a90a 100644
--- a/google3/host_commands.h
+++ b/google3/host_commands.h
@@ -702,5 +702,6 @@
 // EC_PRV_CMD_HOTH_GET_SECURE_BOOT_ENFORCEMENT queries the current secure boot
 // enforcement state.
 #define EC_PRV_CMD_HOTH_GET_SECURE_BOOT_ENFORCEMENT 0x001D
+#define EC_PRV_CMD_HOTH_SET_SECURE_BOOT_ENFORCEMENT 0x001C
 
 #endif /* __PRIVATE_CR51_INCLUDE_CR51_HOST_COMMANDS_H */
diff --git a/tools/hoth_updater_cli.cpp b/tools/hoth_updater_cli.cpp
index fc01cdc..6e43b92 100644
--- a/tools/hoth_updater_cli.cpp
+++ b/tools/hoth_updater_cli.cpp
@@ -14,6 +14,7 @@
 
 #include "hoth_updater_cli.hpp"
 
+#include "google3/host_commands.h"
 #include "message_util.hpp"
 
 #include <boost/endian/arithmetic.hpp>
@@ -243,10 +244,13 @@
 HothVersionStringsRsp HothUpdaterCLI::getHothVersion(sdbusplus::bus::bus& bus,
                                                      std::string_view hoth_id)
 {
-    const std::vector<uint8_t> versionStringsCommand = {0x03, 0xfb, 0x02, 0x00,
-                                                        0x00, 0x00, 0x00, 0x00};
-    std::vector<uint8_t> resp_bytes =
-        sendHostCommand(bus, hoth_id, versionStringsCommand);
+    google::hoth::internal::ReqHeader header;
+    google::hoth::internal::populateReqHeader(EC_CMD_GET_VERSION, 0, nullptr, 0,
+                                              &header);
+
+    auto header_span = stdplus::raw::asSpan<uint8_t>(header);
+    std::vector<uint8_t> command(header_span.begin(), header_span.end());
+    std::vector<uint8_t> resp_bytes = sendHostCommand(bus, hoth_id, command);
 
     auto response = stdplus::raw::copyFrom<HothVersionStringsRsp>(resp_bytes);
 
@@ -380,14 +384,6 @@
     }
 }
 
-// from libhoth command HOTH_PRV_CMD_HOTH_SET_SECURE_BOOT_ENFORCEMENT
-constexpr uint16_t kSetSecureBootEnforcementCmd = 0x3E1D;
-
-struct SetSecureBootEnforcementReq {
-  uint8_t enabled = 1;
-  uint8_t reserved[3] = {0};
-};
-
 void HothUpdaterCLI::doEnableSecurebootEnforcement(const Args& args)
 {
     sdbusplus::bus::bus bus = sdbusplus::bus::new_default();
@@ -398,10 +394,10 @@
     sdbusplus::bus::bus& bus, const Args& args)
 {
     google::hoth::internal::ReqHeader header;
-    SetSecureBootEnforcementReq payload;
-    google::hoth::internal::populateReqHeader(kSetSecureBootEnforcementCmd, 0,
-                                              &payload, sizeof(payload),
-                                              &header);
+    secure_boot_enforcement_state payload = {.enabled = 1, .reserved0 = {0}};
+    google::hoth::internal::populateReqHeader(
+        EC_CMD_BOARD_SPECIFIC_BASE + EC_PRV_CMD_HOTH_SET_SECURE_BOOT_ENFORCEMENT,
+        0, &payload, sizeof(payload), &header);
 
     auto header_span = stdplus::raw::asSpan<uint8_t>(header);
     auto payload_span = stdplus::raw::asSpan<uint8_t>(payload);