main: start with no-op handler

Change-Id: I0504ad186687535966179757cef68c3b4eca754f
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 0000000..bbc1bb1
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,85 @@
+---
+Language:        Cpp
+# BasedOnStyle:  LLVM
+AccessModifierOffset: -2
+AlignAfterOpenBracket: Align
+AlignConsecutiveAssignments: false
+AlignConsecutiveDeclarations: false
+AlignEscapedNewlinesLeft: false
+AlignOperands:   true
+AlignTrailingComments: true
+AllowAllParametersOfDeclarationOnNextLine: true
+AllowShortBlocksOnASingleLine: false
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: None
+AllowShortIfStatementsOnASingleLine: false
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterDefinitionReturnType: None
+AlwaysBreakAfterReturnType: None
+AlwaysBreakBeforeMultilineStrings: false
+AlwaysBreakTemplateDeclarations: false
+BinPackArguments: true
+BinPackParameters: true
+BraceWrapping:
+  AfterClass:      true
+  AfterControlStatement: true
+  AfterEnum:       true
+  AfterFunction:   true
+  AfterNamespace:  true
+  AfterObjCDeclaration: true
+  AfterStruct:     true
+  AfterUnion:      true
+  BeforeCatch:     true
+  BeforeElse:      true
+  IndentBraces:    false
+BreakBeforeBinaryOperators: None
+BreakBeforeBraces: Custom
+BreakBeforeTernaryOperators: true
+BreakConstructorInitializers: AfterColon
+ColumnLimit:     80
+CommentPragmas:  '^ IWYU pragma:'
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+ConstructorInitializerIndentWidth: 4
+ContinuationIndentWidth: 4
+Cpp11BracedListStyle: true
+DerivePointerAlignment: true
+PointerAlignment: Left
+DisableFormat:   false
+ExperimentalAutoDetectBinPacking: false
+FixNamespaceComments: true
+ForEachMacros:   [ foreach, Q_FOREACH, BOOST_FOREACH ]
+IndentCaseLabels: true
+IndentWidth:     4
+IndentWrappedFunctionNames: true
+KeepEmptyLinesAtTheStartOfBlocks: true
+MacroBlockBegin: ''
+MacroBlockEnd:   ''
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: None
+ObjCBlockIndentWidth: 2
+ObjCSpaceAfterProperty: false
+ObjCSpaceBeforeProtocolList: true
+PenaltyBreakBeforeFirstCallParameter: 19
+PenaltyBreakComment: 300
+PenaltyBreakFirstLessLess: 120
+PenaltyBreakString: 1000
+PenaltyExcessCharacter: 1000000
+PenaltyReturnTypeOnItsOwnLine: 60
+PointerAlignment: Right
+ReflowComments:  true
+SortIncludes:    false
+SpaceAfterCStyleCast: false
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeParens: ControlStatements
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 1
+SpacesInAngles:  false
+SpacesInContainerLiterals: true
+SpacesInCStyleCastParentheses: false
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+Standard:        Cpp11
+TabWidth:        4
+UseTab:          Never
+...
+
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..80f3f36
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,33 @@
+*~
+*.o
+*.lo
+*.la
+*.sw*
+Makefile
+Makefile.in
+configure
+.deps
+.libs
+aclocal.m4
+ar-lib
+arm-openbmc-linux-gnueabi-libtool
+autom4te.cache/
+compile
+config.guess
+config.h
+config.h.in
+config.log
+config.status
+config.sub
+depcomp
+install-sh
+libtool
+ltmain.sh
+missing
+stamp-h1
+test-driver
+.dirstamp
+x86_64-libtool
+*_unittest
+*_unittest.log
+*_unittest.trs
diff --git a/Makefile.am b/Makefile.am
new file mode 100644
index 0000000..05f493e
--- /dev/null
+++ b/Makefile.am
@@ -0,0 +1,15 @@
+AM_DEFAULT_SOURCE_EXT = .cpp
+
+libflashcmdsdir = ${libdir}/ipmid-providers
+libflashcmds_LTLIBRARIES = libflashcmds.la
+libflashcmds_la_SOURCES = main.cpp
+
+libflashcmds_la_LDFLAGS = $(SYSTEMD_LIBS) \
+                          $(PHOSPHOR_DBUS_INTERFACES_LIBS) \
+                          $(PHOSPHOR_LOGGING_LIBS) \
+                          -version-info 0:0:0 -shared
+libflashcmds_la_CXXFLAGS = $(SYSTEMD_CFLAGS) \
+                           $(PHOSPHOR_DBUS_INTERFACES_CFLAGS) \
+                           $(PHOSPHOR_LOGGING_CFLAGS)
+
+SUBDIRS = .
diff --git a/bootstrap.sh b/bootstrap.sh
new file mode 100755
index 0000000..fce7cfa
--- /dev/null
+++ b/bootstrap.sh
@@ -0,0 +1,19 @@
+#!/bin/sh
+
+AUTOCONF_FILES="Makefile.in aclocal.m4 ar-lib autom4te.cache compile \
+        config.guess config.h.in config.sub configure depcomp install-sh \
+        ltmain.sh missing *libtool test-driver"
+
+case $1 in
+    clean)
+        test -f Makefile && make maintainer-clean
+        for file in ${AUTOCONF_FILES}; do
+            find -name "$file" | xargs -r rm -rf
+        done
+        exit 0
+        ;;
+esac
+
+autoreconf -i
+echo 'Run "./configure ${CONFIGURE_FLAGS} && make"'
+
diff --git a/configure.ac b/configure.ac
new file mode 100644
index 0000000..0add2b8
--- /dev/null
+++ b/configure.ac
@@ -0,0 +1,73 @@
+
+# Initialization
+AC_PREREQ([2.69])
+AC_INIT([flash-ipmi], [1.0], [https://www.google.com])
+AC_LANG([C++])
+AC_CONFIG_HEADERS([config.h])
+AM_INIT_AUTOMAKE([subdir-objects -Wall -Werror foreign dist-xz])
+AM_SILENT_RULES([yes])
+
+# Checks for programs.
+AC_PROG_CXX
+AM_PROG_AR
+AC_PROG_INSTALL
+AC_PROG_MAKE_SET
+
+# Checks for typedefs, structures, and compiler characteristics.
+AX_CXX_COMPILE_STDCXX_14([noext])
+AX_APPEND_COMPILE_FLAGS([-Wall -Werror], [CXXFLAGS])
+
+# Checks for libraries.
+PKG_CHECK_MODULES([SYSTEMD], [libsystemd >= 221], [], [AC_MSG_ERROR(["systemd required and not found"])])
+PKG_CHECK_MODULES([SDBUSPLUS], [sdbusplus], ,[AC_MSG_ERROR([The openbmc/sdbusplus package is required])])
+PKG_CHECK_MODULES([PHOSPHOR_LOGGING], [phosphor-logging], ,[AC_MSG_ERROR([The openbmc/phosphor-logging package is required])])
+PKG_CHECK_MODULES([PHOSPHOR_DBUS_INTERFACES], [phosphor-dbus-interfaces], [], [AC_MSG_ERROR(["phosphor-dbus-interfaces required and not found."])])
+AC_CHECK_HEADER([host-ipmid], [AC_MSG_ERROR(["phosphor-host-ipmid required and not found."])])
+
+# Checks for library functions.
+LT_INIT # Required for systemd linking
+
+# Check/set gtest specific functions.
+PKG_CHECK_MODULES([GTEST], [gtest], [], [AC_MSG_NOTICE([gtest not found, tests will not build])])
+PKG_CHECK_MODULES([GMOCK], [gmock], [], [AC_MSG_NOTICE([gmock not found, tests will not build])])
+PKG_CHECK_MODULES([GTEST_MAIN], [gtest_main], [], [AC_MSG_NOTICE([gtest_main not found, tests will not build])])
+
+# Do you want to register as a Google OEM IPMI handler as well as firmware?
+AC_ARG_ENABLE([google],
+    AS_HELP_STRING([--enable-google], [Enable registration as Google OEM IPMI Handler])
+)
+
+AC_ARG_VAR(ENABLE_GOOGLE, [Enable registration as Google OEM IPMI Handler])
+
+AS_IF([test "x$enable_google" == "xyes"],
+      [ENABLE_GOOGLE="yes"]
+      AC_DEFINE_UNQUOTED([ENABLE_GOOGLE], ["$ENABLE_GOOGLE"], [Enable registration as Google OEM IPMI Handler])
+)
+
+# Add --enable-oe-sdk flag to configure script
+AC_ARG_ENABLE([oe-sdk],
+    AS_HELP_STRING([--enable-oe-sdk], [Link testcases absolutely against OE SDK so they can be ran within it.])
+)
+
+# Check for OECORE_TARGET_SYSROOT in the environment.
+AC_ARG_VAR(OECORE_TARGET_SYSROOT,
+    [Path to the OE SDK SYSROOT])
+
+# Configure OESDK_TESTCASE_FLAGS environment variable, which will be later
+# used in test/Makefile.am
+AS_IF([test "x$enable_oe_sdk" == "xyes"],
+    AS_IF([test "x$OECORE_TARGET_SYSROOT" == "x"],
+          AC_MSG_ERROR([OECORE_TARGET_SYSROOT must be set with --enable-oe-sdk])
+    )
+    AC_MSG_NOTICE([Enabling OE-SDK at $OECORE_TARGET_SYSROOT])
+    [
+        testcase_flags="-Wl,-rpath,\${OECORE_TARGET_SYSROOT}/lib"
+        testcase_flags="${testcase_flags} -Wl,-rpath,\${OECORE_TARGET_SYSROOT}/usr/lib"
+        testcase_flags="${testcase_flags} -Wl,-dynamic-linker,`find \${OECORE_TARGET_SYSROOT}/lib/ld-*.so | sort -r -n | head -n1`"
+    ]
+    AC_SUBST([OESDK_TESTCASE_FLAGS], [$testcase_flags])
+)
+
+# Create configured output
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
diff --git a/main.cpp b/main.cpp
new file mode 100644
index 0000000..36f4662
--- /dev/null
+++ b/main.cpp
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2017 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 "host-ipmid/ipmid-api.h"
+#include "host-ipmid/oemrouter.hpp"
+
+/* TODO: Once OEM IPMI number placement is settled, point to that. */
+namespace oem
+{
+namespace google
+{
+constexpr int number = 11129;
+constexpr int flashOverBTCmd = 127;
+} // namespace google
+} // namespace oem
+
+static ipmi_ret_t flashControl(ipmi_cmd_t cmd, const uint8_t* reqBuf,
+                               uint8_t* replyCmdBuf, size_t* dataLen)
+{
+    /* Verify it's at least as long as the shortest message. */
+    if ((*dataLen) < 1)
+    {
+        return IPMI_CC_INVALID;
+    }
+
+    return IPMI_CC_INVALID;
+}
+
+static ipmi_ret_t ipmiFlashControl(ipmi_netfn_t netFn, ipmi_cmd_t cmd,
+                                   ipmi_request_t request,
+                                   ipmi_response_t response,
+                                   ipmi_data_len_t dataLen,
+                                   ipmi_context_t context)
+{
+    /* request_t, response_t are void*. ipmi_data_len_t is a size_t* */
+    auto reqBuf = static_cast<const uint8_t*>(request);
+    auto replyCmdBuf = static_cast<uint8_t*>(response);
+
+    return flashControl(cmd, reqBuf, replyCmdBuf, dataLen);
+}
+
+void setupGlobalOemFlashControl() __attribute__((constructor));
+
+void setupGlobalOemFlashControl()
+{
+#ifdef ENABLE_GOOGLE
+    oem::Router* router = oem::mutableRouter();
+
+    fprintf(stderr, "Registering OEM:[%#08X], Cmd:[%#04X] for Flash Update\n",
+            oem::google::number, oem::google::flashOverBTCmd);
+
+    router->registerHandler(oem::google::number, oem::google::flashOverBTCmd,
+                            flashControl);
+#endif
+
+    ipmi_register_callback(NETFUN_FIRMWARE, oem::google::flashOverBTCmd, NULL,
+                           ipmiFlashControl, PRIVILEGE_USER);
+}