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/eth.cpp b/eth.cpp
index be6eefe..bbe1940 100644
--- a/eth.cpp
+++ b/eth.cpp
@@ -19,63 +19,48 @@
 
 #include <cstdint>
 #include <cstring>
+#include <ipmid/api-types.hpp>
 #include <string>
 #include <tuple>
+#include <vector>
 
 namespace google
 {
 namespace ipmi
 {
 
-struct EthDeviceRequest
-{
-    uint8_t subcommand;
-} __attribute__((packed));
-
 // TOOD(venture): The ipmid.h has this macro, which is a header we
 // can't normally access.
 #ifndef MAX_IPMI_BUFFER
 #define MAX_IPMI_BUFFER 64
 #endif
 
-ipmi_ret_t getEthDevice(const uint8_t* reqBuf, uint8_t* replyBuf,
-                        size_t* dataLen, const HandlerInterface* handler)
+Resp getEthDevice(const std::vector<std::uint8_t>& data,
+                  const HandlerInterface* handler)
 {
-    if ((*dataLen) < sizeof(struct EthDeviceRequest))
-    {
-        std::fprintf(stderr, "Invalid command length: %u\n",
-                     static_cast<uint32_t>(*dataLen));
-        return IPMI_CC_REQ_DATA_LEN_INVALID;
-    }
-    reqBuf += sizeof(struct EthDeviceRequest);
-    *dataLen -= sizeof(struct EthDeviceRequest);
-
-    std::tuple<std::uint8_t, std::string> details = handler->getEthDetails(
-        std::string(reinterpret_cast<const char*>(reqBuf), *dataLen));
+    std::tuple<std::uint8_t, std::string> details =
+        handler->getEthDetails(std::string(data.begin(), data.end()));
 
     std::string device = std::get<1>(details);
     if (device.length() == 0)
     {
         std::fprintf(stderr, "Invalid eth string\n");
-        return IPMI_CC_REQ_DATA_LEN_INVALID;
+        return ::ipmi::responseReqDataLenInvalid();
     }
 
     if ((sizeof(struct EthDeviceReply) + device.length()) > MAX_IPMI_BUFFER)
     {
         std::fprintf(stderr, "Response would overflow response buffer\n");
-        return IPMI_CC_REQUESTED_TOO_MANY_BYTES;
+        return ::ipmi::responseRetBytesUnavailable();
     }
 
-    // Fill in the response buffer.
-    auto reply = reinterpret_cast<struct EthDeviceReply*>(&replyBuf[0]);
-    reply->subcommand = SysGetEthDevice;
-    reply->channel = std::get<0>(details);
-    reply->ifNameLength = device.length();
-    std::memcpy(reply + 1, device.c_str(), device.length());
+    std::vector<std::uint8_t> reply;
+    reply.reserve(device.length() + sizeof(struct EthDeviceReply));
+    reply.emplace_back(std::get<0>(details));                /* channel */
+    reply.emplace_back(device.length());                     /* ifNameLength */
+    reply.insert(reply.end(), device.begin(), device.end()); /* name */
 
-    (*dataLen) = sizeof(struct EthDeviceReply) + device.length();
-
-    return IPMI_CC_OK;
+    return ::ipmi::responseSuccess(SysOEMCommands::SysGetEthDevice, reply);
 }
 
 } // namespace ipmi