ipmi: start implementing flashDataBlock
Change-Id: I780c0e5da77a027ce23a674bd3fdbf08b8a81c14
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/ipmi.cpp b/ipmi.cpp
index 65a719a..6201f0e 100644
--- a/ipmi.cpp
+++ b/ipmi.cpp
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+#include <cstring>
+
#include "flash-ipmi.hpp"
#include "ipmi.hpp"
@@ -38,3 +40,32 @@
(*dataLen) = 1;
return IPMI_CC_OK;
}
+
+ipmi_ret_t dataBlock(UpdateInterface* updater, const uint8_t* reqBuf,
+ uint8_t* replyBuf, size_t* dataLen)
+{
+ size_t requestLength = (*dataLen);
+ /* Require at least one byte. */
+ if (requestLength < sizeof(struct ChunkHdr) + 1)
+ {
+ return IPMI_CC_INVALID;
+ }
+
+ struct ChunkHdr hdr;
+ std::memcpy(&hdr, reqBuf, sizeof(hdr));
+
+ /* Grab the bytes from the packet. */
+ size_t bytesLength = requestLength - sizeof(struct ChunkHdr);
+ std::vector<uint8_t> bytes(bytesLength);
+ std::memcpy(bytes.data(), &reqBuf[sizeof(struct ChunkHdr)], bytesLength);
+
+ if (!updater->flashData(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;
+}