tools: lpc: start implementation, send metadata

With the LPC interface, send the window information to the BMC.

Tested: Ran on test system and verified window mapped via ioctl to
driver as expected.

Change-Id: I7ffac6b52205b215fd698a574d098b505091c3d4
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/test/Makefile.am b/test/Makefile.am
index 9be5ae4..431b617 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -29,6 +29,7 @@
 	file_handler_unittest \
 	tools_blob_unittest \
 	tools_bt_unittest \
+	tools_lpc_unittest \
 	tools_updater_unittest \
 	tools_ipmi_unittest \
 	tools_ipmi_error_unittest
@@ -77,6 +78,9 @@
 tools_bt_unittest_SOURCES = tools_bt_unittest.cpp
 tools_bt_unittest_LDADD = $(top_builddir)/tools/bt.o
 
+tools_lpc_unittest_SOURCES = tools_lpc_unittest.cpp
+tools_lpc_unittest_LDADD = $(top_builddir)/tools/lpc.o
+
 tools_updater_unittest_SOURCES = tools_updater_unittest.cpp
 tools_updater_unittest_LDADD = $(top_builddir)/tools/updater.o
 
diff --git a/test/tools_lpc_unittest.cpp b/test/tools_lpc_unittest.cpp
new file mode 100644
index 0000000..5b7ddb1
--- /dev/null
+++ b/test/tools_lpc_unittest.cpp
@@ -0,0 +1,34 @@
+#include "blob_interface_mock.hpp"
+#include "internal_sys_mock.hpp"
+#include "lpc.hpp"
+
+#include <cstring>
+
+#include <gtest/gtest.h>
+
+namespace host_tool
+{
+
+using ::testing::ContainerEq;
+
+TEST(LpcHandleTest, verifySendsFileContents)
+{
+    BlobInterfaceMock blobMock;
+
+    LpcDataHandler handler(&blobMock);
+    std::uint16_t session = 0xbeef;
+    std::string filePath = "/asdf";
+
+    LpcRegion host_lpc_buf;
+    host_lpc_buf.address = 0xfedc1000;
+    host_lpc_buf.length = 0x1000;
+
+    std::vector<std::uint8_t> bytes(sizeof(host_lpc_buf));
+    std::memcpy(bytes.data(), &host_lpc_buf, sizeof(host_lpc_buf));
+
+    EXPECT_CALL(blobMock, writeMeta(session, 0, ContainerEq(bytes)));
+
+    EXPECT_FALSE(handler.sendContents(filePath, session));
+}
+
+} // namespace host_tool
diff --git a/tools/lpc.cpp b/tools/lpc.cpp
index 97b7902..7a5faa2 100644
--- a/tools/lpc.cpp
+++ b/tools/lpc.cpp
@@ -16,12 +16,35 @@
 
 #include "lpc.hpp"
 
+#include <cstring>
+
 namespace host_tool
 {
 
 bool LpcDataHandler::sendContents(const std::string& input,
                                   std::uint16_t session)
 {
+    /* TODO: Add mechanism for configuring this. */
+    LpcRegion host_lpc_buf;
+
+    /* TODO: Remove hard-coded configuration used with test machine. */
+    host_lpc_buf.address = 0xfedc1000;
+    host_lpc_buf.length = 0x1000;
+
+    std::vector<std::uint8_t> payload(sizeof(host_lpc_buf));
+    std::memcpy(payload.data(), &host_lpc_buf, sizeof(host_lpc_buf));
+
+    blob->writeMeta(session, 0x00, payload);
+
+    /* TODO: Call sessionstat and see if the metadata confirms the region was
+     * mapped successfully, once the lpc data handler implements it.
+     */
+
+    /* todo:
+     * configure memory region (somehow)
+     * copy contents from file to memory region
+     * send external chunk (writeBlob) until it's all sent.
+     */
     return false;
 }
 
diff --git a/tools/lpc.hpp b/tools/lpc.hpp
index 913fc5d..9e9c8b3 100644
--- a/tools/lpc.hpp
+++ b/tools/lpc.hpp
@@ -3,9 +3,19 @@
 #include "blob_interface.hpp"
 #include "interface.hpp"
 
+#include <cstdint>
+
 namespace host_tool
 {
 
+struct LpcRegion
+{
+    /* Host LPC address at which the chunk is to be mapped. */
+    std::uint32_t address;
+    /* Size of the chunk to be mapped. */
+    std::uint32_t length;
+};
+
 class LpcDataHandler : public DataInterface
 {
   public: