ipmi: start implementing flashDataVerify
Change-Id: I446ca8573db31eb53dc7aefbe25cdb9d23d51d29
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/flash-ipmi.cpp b/flash-ipmi.cpp
index 35f8ad2..69002f7 100644
--- a/flash-ipmi.cpp
+++ b/flash-ipmi.cpp
@@ -67,3 +67,9 @@
/* TODO: implement. */
return false;
}
+
+bool FlashUpdate::startDataVerification()
+{
+ /* TODO: implement. */
+ return false;
+}
diff --git a/flash-ipmi.hpp b/flash-ipmi.hpp
index baf4c7f..561d6c8 100644
--- a/flash-ipmi.hpp
+++ b/flash-ipmi.hpp
@@ -129,6 +129,13 @@
* Called to indicate the host is done sending the hash bytes.
*/
virtual bool hashFinish() = 0;
+
+ /**
+ * Kick off the flash image verification process.
+ *
+ * @return true if it was started succesfully.
+ */
+ virtual bool startDataVerification() = 0;
};
class FlashUpdate : public UpdateInterface
@@ -149,6 +156,8 @@
bool hashData(uint32_t offset, const std::vector<uint8_t>& bytes) override;
bool hashFinish() override;
+ bool startDataVerification() override;
+
private:
/**
* Tries to close out and delete anything staged.
diff --git a/ipmi.cpp b/ipmi.cpp
index fad2049..fc6092c 100644
--- a/ipmi.cpp
+++ b/ipmi.cpp
@@ -30,6 +30,7 @@
{FlashSubCmds::flashStartHash, startHash},
{FlashSubCmds::flashHashData, hashBlock},
{FlashSubCmds::flashHashFinish, hashFinish},
+ {FlashSubCmds::flashDataVerify, dataVerify},
};
auto results = subHandlers.find(command);
@@ -177,3 +178,17 @@
(*dataLen) = 1;
return IPMI_CC_OK;
}
+
+ipmi_ret_t dataVerify(UpdateInterface* updater, const uint8_t* reqBuf,
+ uint8_t* replyBuf, size_t* dataLen)
+{
+ if (!updater->startDataVerification())
+ {
+ return IPMI_CC_INVALID;
+ }
+
+ /* We were successful and set the response byte to 0. */
+ replyBuf[0] = 0x00;
+ (*dataLen) = 1;
+ return IPMI_CC_OK;
+}
diff --git a/ipmi.hpp b/ipmi.hpp
index a892300..a389e8e 100644
--- a/ipmi.hpp
+++ b/ipmi.hpp
@@ -104,3 +104,16 @@
*/
ipmi_ret_t hashFinish(UpdateInterface* updater, const uint8_t* reqBuf,
uint8_t* replyBuf, size_t* dataLen);
+
+/**
+ * Start the flash image verification process (whatever that is).
+ *
+ * @param[in] updater - Pointer to Updater object.
+ * @param[in] reqBuf - the IPMI packet.
+ * @param[in] replyBuf - Pointer to buffer for any response.
+ * @param[in,out] dataLen - Initially reqBuf length, set to replyBuf
+ * length when done.
+ * @return corresponding IPMI return code.
+ */
+ipmi_ret_t dataVerify(UpdateInterface* updater, const uint8_t* reqBuf,
+ uint8_t* replyBuf, size_t* dataLen);
diff --git a/test/Makefile.am b/test/Makefile.am
index 4230ce0..4d4c806 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -16,6 +16,7 @@
ipmi_starthash_unittest \
ipmi_hashdata_unittest \
ipmi_hashfinish_unittest \
+ ipmi_startverify_unittest \
ipmi_validate_unittest \
ipmi_command_unittest
@@ -39,6 +40,9 @@
ipmi_hashfinish_unittest_SOURCES = ipmi_hashfinish_unittest.cpp
ipmi_hashfinish_unittest_LDADD = $(top_builddir)/ipmi.o
+ipmi_startverify_unittest_SOURCES = ipmi_startverify_unittest.cpp
+ipmi_startverify_unittest_LDADD = $(top_builddir)/ipmi.o
+
ipmi_validate_unittest_SOURCES = ipmi_validate_unittest.cpp
ipmi_validate_unittest_LDADD = $(top_builddir)/ipmi.o
diff --git a/test/ipmi_startverify_unittest.cpp b/test/ipmi_startverify_unittest.cpp
new file mode 100644
index 0000000..87e818d
--- /dev/null
+++ b/test/ipmi_startverify_unittest.cpp
@@ -0,0 +1,32 @@
+#include "ipmi.hpp"
+
+#include "updater_mock.hpp"
+
+#include <gtest/gtest.h>
+
+using ::testing::Return;
+using ::testing::StrictMock;
+
+// ipmid.hpp isn't installed where we can grab it and this value is per BMC
+// SoC.
+#define MAX_IPMI_BUFFER 64
+
+TEST(IpmiStartDataVerifyTest, CallPassedOn)
+{
+ // The IPMI handler in this case just passes on the call and returns the
+ // result without any extra validation.
+
+ StrictMock<UpdaterMock> updater;
+
+ size_t dataLen;
+ uint8_t request[MAX_IPMI_BUFFER] = {0};
+ uint8_t reply[MAX_IPMI_BUFFER] = {0};
+
+ dataLen = 1; // request is only the command.
+ request[0] = FlashSubCmds::flashDataVerify;
+
+ EXPECT_CALL(updater, startDataVerification()).WillOnce(Return(true));
+ EXPECT_EQ(IPMI_CC_OK, dataVerify(&updater, request, reply, &dataLen));
+ EXPECT_EQ(sizeof(uint8_t), dataLen);
+ EXPECT_EQ(0, reply[0]);
+}
diff --git a/test/updater_mock.hpp b/test/updater_mock.hpp
index fa912ea..2074eeb 100644
--- a/test/updater_mock.hpp
+++ b/test/updater_mock.hpp
@@ -16,4 +16,5 @@
MOCK_METHOD1(startHash, bool(uint32_t));
MOCK_METHOD2(hashData, bool(uint32_t, const std::vector<uint8_t>&));
MOCK_METHOD0(hashFinish, bool());
+ MOCK_METHOD0(startDataVerification, bool());
};