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/flash_size.cpp b/flash_size.cpp
index 069b1b1..4fb4976 100644
--- a/flash_size.cpp
+++ b/flash_size.cpp
@@ -22,6 +22,7 @@
#include <cstdint>
#include <cstring>
+#include <ipmid/api-types.hpp>
#include <string>
#include <vector>
@@ -30,30 +31,8 @@
namespace ipmi
{
-struct GetFlashSizeRequest
+Resp getFlashSize(const std::vector<std::uint8_t>&, HandlerInterface* handler)
{
- uint8_t subcommand;
-} __attribute__((packed));
-
-struct GetFlashSizeReply
-{
- uint8_t subcommand;
- uint32_t flashSize;
-} __attribute__((packed));
-
-ipmi_ret_t getFlashSize(const uint8_t* reqBuf, uint8_t* replyBuf,
- size_t* dataLen, HandlerInterface* handler)
-{
- struct GetFlashSizeRequest request;
-
- if ((*dataLen) < sizeof(request))
- {
- std::fprintf(stderr, "Invalid command length: %u\n",
- static_cast<uint32_t>(*dataLen));
- return IPMI_CC_REQ_DATA_LEN_INVALID;
- }
-
- std::memcpy(&request, &reqBuf[0], sizeof(request));
uint32_t flashSize;
try
{
@@ -61,15 +40,15 @@
}
catch (const IpmiException& e)
{
- return e.getIpmiError();
+ return ::ipmi::response(e.getIpmiError());
}
- auto reply = reinterpret_cast<struct GetFlashSizeReply*>(&replyBuf[0]);
- reply->subcommand = SysGetFlashSize;
- reply->flashSize = htole32(flashSize);
-
- (*dataLen) = sizeof(struct GetFlashSizeReply);
- return IPMI_CC_OK;
+ flashSize = htole32(flashSize);
+ return ::ipmi::responseSuccess(
+ SysOEMCommands::SysGetFlashSize,
+ std::vector<std::uint8_t>((std::uint8_t*)&(flashSize),
+ (std::uint8_t*)&(flashSize) +
+ sizeof(std::uint32_t)));
}
} // namespace ipmi
} // namespace google