google-ipmi-sys: Refactor to use new version of OEM IPMI Handler

Using the new version of ipmi handler provide a higher level wrapper
over the same functionalities. It helps us parse the input and output to
have more control of the input/output we see.

The input and output will be
`std::uint8_t, std::optional<std::vector<uint8_t>>`.

This represents `subcommand` and any input data.

Changes to note,
- all subcommand in the request/response struct are removed. It will be
  managed by the wrapper directly.
    - Unit tests checking for input with only the subcommand are
      removed.
- Move all reply struct to header files to be accessible in unit test.

Tested:
All IPMI OEM command still works the same as before this change.

Change-Id: I4230ab84a497a867248fe82224e32cc69b314b64
Signed-off-by: Willy Tu <wltu@google.com>
diff --git a/machine_name.cpp b/machine_name.cpp
index c8bf701..c1b9c4e 100644
--- a/machine_name.cpp
+++ b/machine_name.cpp
@@ -14,41 +14,24 @@
 
 #include "machine_name.hpp"
 
+#include "commands.hpp"
 #include "errors.hpp"
 
 #include <cstddef>
 #include <cstdio>
 #include <cstring>
+#include <ipmid/api-types.hpp>
 #include <optional>
 #include <string>
+#include <vector>
 
 namespace google
 {
 namespace ipmi
 {
 
-struct GetMachineNameRequest
+Resp getMachineName(const std::vector<std::uint8_t>&, HandlerInterface* handler)
 {
-    uint8_t subcommand;
-} __attribute__((packed));
-
-struct GetMachineNameReply
-{
-    uint8_t subcommand;
-    uint8_t machineNameLength;
-} __attribute__((packed));
-
-ipmi_ret_t getMachineName(const uint8_t* reqBuf, uint8_t* replyBuf,
-                          size_t* dataLen, HandlerInterface* handler)
-{
-    GetMachineNameRequest request;
-    if (*dataLen < sizeof(request))
-    {
-        std::fprintf(stderr, "Invalid command length: %zu\n", *dataLen);
-        return IPMI_CC_REQ_DATA_LEN_INVALID;
-    }
-    std::memcpy(&request, reqBuf, sizeof(request));
-
     static std::optional<std::string> machineName;
     if (!machineName)
     {
@@ -58,24 +41,24 @@
         }
         catch (const IpmiException& e)
         {
-            return e.getIpmiError();
+            return ::ipmi::response(e.getIpmiError());
         }
     }
 
-    GetMachineNameReply reply;
-    size_t len = sizeof(reply) + machineName->size();
+    size_t len = sizeof(struct GetMachineNameReply) + machineName->size();
     if (len > MAX_IPMI_BUFFER)
     {
         std::fprintf(stderr, "Response would overflow response buffer\n");
-        return IPMI_CC_INVALID;
+        return ::ipmi::responseInvalidCommand();
     }
-    reply.subcommand = request.subcommand;
-    reply.machineNameLength = machineName->size();
-    std::memcpy(replyBuf, &reply, sizeof(reply));
-    std::memcpy(replyBuf + sizeof(reply), machineName->data(),
-                machineName->size());
-    (*dataLen) = len;
-    return IPMI_CC_OK;
+
+    std::vector<std::uint8_t> reply;
+    reply.reserve(len);
+    reply.emplace_back(machineName->size()); /* machineNameLength */
+    reply.insert(reply.end(), machineName->begin(),
+                 machineName->end()); /* machineName */
+
+    return ::ipmi::responseSuccess(SysOEMCommands::SysMachineName, reply);
 }
 
 } // namespace ipmi