tools: start implementing data interface
The host must provide multiple data interfaces. Each data interface is
responsible for configuring its data pathway and sending the contents
via this pathway, as well as any flow control.
Change-Id: If856519536d01043e69c45044fcd0ad525592486
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/tools/Makefile.am b/tools/Makefile.am
index 88c72e2..1d7d814 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -8,4 +8,6 @@
libupdater_la_LDFLAGS = -static
libupdater_la_CXXFLAGS =
libupdater_la_SOURCES = \
- updater.cpp
+ updater.cpp \
+ bt.cpp \
+ lpc.cpp
diff --git a/tools/bt.cpp b/tools/bt.cpp
new file mode 100644
index 0000000..de26b27
--- /dev/null
+++ b/tools/bt.cpp
@@ -0,0 +1,7 @@
+#include "bt.hpp"
+
+bool BtDataHandler::sendContents(const std::string& input,
+ std::uint16_t session)
+{
+ return false;
+}
diff --git a/tools/bt.hpp b/tools/bt.hpp
new file mode 100644
index 0000000..dbd5c8c
--- /dev/null
+++ b/tools/bt.hpp
@@ -0,0 +1,11 @@
+#pragma once
+
+#include "interface.hpp"
+
+class BtDataHandler : public DataInterface
+{
+ public:
+ BtDataHandler() = default;
+
+ bool sendContents(const std::string& input, std::uint16_t session) override;
+};
diff --git a/tools/interface.hpp b/tools/interface.hpp
new file mode 100644
index 0000000..39f3fb8
--- /dev/null
+++ b/tools/interface.hpp
@@ -0,0 +1,22 @@
+#pragma once
+
+#include <cstdint>
+#include <string>
+
+class DataInterface
+{
+ public:
+ virtual ~DataInterface() = default;
+
+ /**
+ * Given an open session to either /flash/image, /flash/tarball, or
+ * /flash/hash, this method will configure, and send the data, but not close
+ * the session.
+ *
+ * @param[in] input - path to file to send.
+ * @param[in] session - the session ID to use.
+ * @return bool on success.
+ */
+ virtual bool sendContents(const std::string& input,
+ std::uint16_t session) = 0;
+};
diff --git a/tools/lpc.cpp b/tools/lpc.cpp
new file mode 100644
index 0000000..9e8e01d
--- /dev/null
+++ b/tools/lpc.cpp
@@ -0,0 +1,23 @@
+/*
+ * Copyright 2018 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "lpc.hpp"
+
+bool LpcDataHandler::sendContents(const std::string& input,
+ std::uint16_t session)
+{
+ return false;
+}
diff --git a/tools/lpc.hpp b/tools/lpc.hpp
new file mode 100644
index 0000000..de35c1b
--- /dev/null
+++ b/tools/lpc.hpp
@@ -0,0 +1,11 @@
+#pragma once
+
+#include "interface.hpp"
+
+class LpcDataHandler : public DataInterface
+{
+ public:
+ LpcDataHandler() = default;
+
+ bool sendContents(const std::string& input, std::uint16_t session) override;
+};
diff --git a/tools/test/data_interface_mock.hpp b/tools/test/data_interface_mock.hpp
new file mode 100644
index 0000000..d823da5
--- /dev/null
+++ b/tools/test/data_interface_mock.hpp
@@ -0,0 +1,14 @@
+#pragma once
+
+#include "interface.hpp"
+
+#include <gmock/gmock.h>
+
+class DataInterfaceMock : public DataInterface
+{
+
+ public:
+ virtual ~DataInterfaceMock() = default;
+
+ MOCK_METHOD2(sendContents, bool(const std::string&, std::uint16_t));
+};
diff --git a/tools/updater.cpp b/tools/updater.cpp
index 4771180..4041d4c 100644
--- a/tools/updater.cpp
+++ b/tools/updater.cpp
@@ -16,8 +16,48 @@
#include "updater.hpp"
+#include "bt.hpp"
+#include "interface.hpp"
+#include "lpc.hpp"
+
+#include <memory>
+
int updaterMain(const std::string& interface, const std::string& imagePath,
const std::string& signaturePath)
{
+ std::unique_ptr<DataInterface> handler;
+
+ /* Input has already been validated in this case. */
+ if (interface == "ipmibt")
+ {
+ handler = std::make_unique<BtDataHandler>();
+ }
+ else if (interface == "ipmilpc")
+ {
+ handler = std::make_unique<LpcDataHandler>();
+ }
+
+ if (!handler)
+ {
+ /* TODO(venture): use a custom exception. */
+ std::fprintf(stderr, "Interface %s is unavailable\n",
+ interface.c_str());
+ return -1;
+ }
+
+ /* TODO(venture): Add optional parameter to specify the flash type, default
+ * to legacy for now.
+ */
+ std::string goalfirmware = "/flash/image";
+
+ /* Get list of blob_ids, check for /flash/image, or /flash/tarball.
+ * TODO(venture) the mechanism doesn't care, but the caller of burn_my_bmc
+ * will have in mind which they're sending and we need to verify it's
+ * available and use it.
+ */
+
+ /* Call stat on /flash/image (or /flash/tarball) and check if data interface
+ * is supported. */
+
return 0;
}