ipmi: start implementing flashHashData
Change-Id: Ib8c57c0f482515ed64867b9f1c98942d39c8a10f
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/ipmi.cpp b/ipmi.cpp
index 00f027a..50208d3 100644
--- a/ipmi.cpp
+++ b/ipmi.cpp
@@ -26,6 +26,7 @@
{FlashSubCmds::flashStartTransfer, sizeof(struct StartTx)},
{FlashSubCmds::flashDataBlock, sizeof(struct ChunkHdr) + 1},
{FlashSubCmds::flashStartHash, sizeof(struct StartTx)},
+ {FlashSubCmds::flashHashData, sizeof(struct ChunkHdr) + 1},
};
auto results = minimumLengths.find(command);
@@ -66,10 +67,10 @@
struct ChunkHdr hdr;
std::memcpy(&hdr, reqBuf, sizeof(hdr));
- size_t requestLength = (*dataLen);
+ auto requestLength = *dataLen;
/* Grab the bytes from the packet. */
- size_t bytesLength = requestLength - sizeof(struct ChunkHdr);
+ auto bytesLength = requestLength - sizeof(struct ChunkHdr);
std::vector<uint8_t> bytes(bytesLength);
std::memcpy(bytes.data(), &reqBuf[sizeof(struct ChunkHdr)], bytesLength);
@@ -115,3 +116,29 @@
(*dataLen) = 1;
return IPMI_CC_OK;
}
+
+ipmi_ret_t hashBlock(UpdateInterface* updater, const uint8_t* reqBuf,
+ uint8_t* replyBuf, size_t* dataLen)
+{
+ struct ChunkHdr hdr;
+ std::memcpy(&hdr, reqBuf, sizeof(hdr));
+
+ auto requestLength = *dataLen;
+
+ /* Grab the bytes from the packet. */
+ auto bytesLength = requestLength - sizeof(struct ChunkHdr);
+ std::vector<uint8_t> bytes(bytesLength);
+ std::memcpy(bytes.data(), &reqBuf[sizeof(struct ChunkHdr)], bytesLength);
+
+ /* TODO: Refactor this and dataBlock for re-use. */
+
+ if (!updater->hashData(hdr.offset, bytes))
+ {
+ return IPMI_CC_INVALID;
+ }
+
+ /* We were successful and set the response byte to 0. */
+ replyBuf[0] = 0x00;
+ (*dataLen) = 1;
+ return IPMI_CC_OK;
+}