Implement get/set shutdown policy IPMI OEM commands
Using the interface defined in intel-dbus-interface
Tested By:
ipmitool raw 0x30 0x60 1
ipmitool raw 0x30 0x62
Change-Id: I31c11218dcd23df8ef19e1f0f525dda889a696b3
Signed-off-by: Yong Li <yong.b.li@linux.intel.com>
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ac4388a..8c8edb8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -39,6 +39,8 @@
link_directories (${CMAKE_BINARY_DIR}/sdbusplus-src/.libs)
include_directories (${CMAKE_BINARY_DIR}/phosphor-logging-src)
link_directories (${CMAKE_BINARY_DIR}/phosphor-logging-src/.libs)
+ include_directories (${CMAKE_BINARY_DIR}/intel-dbus-interfaces-src)
+ link_directories (${CMAKE_BINARY_DIR}/intel-dbus-interfaces-src/.libs)
include_directories (${CMAKE_BINARY_DIR}/phosphor-ipmi-host/include)
include_directories (${CMAKE_BINARY_DIR}/ipmid/user_channel)
include_directories (${CMAKE_BINARY_DIR}) # link_directories
@@ -86,6 +88,7 @@
target_link_libraries (zinteloemcmds ipmid)
target_link_libraries (zinteloemcmds sdbusplus)
target_link_libraries (zinteloemcmds phosphor_logging)
+target_link_libraries (zinteloemcmds intel_dbus)
target_link_libraries (zinteloemcmds -luserlayer)
target_link_libraries (zinteloemcmds -lchannellayer)
diff --git a/CMakeLists.txt.in b/CMakeLists.txt.in
index 7b82143..b805efc 100644
--- a/CMakeLists.txt.in
+++ b/CMakeLists.txt.in
@@ -70,6 +70,28 @@
LOG_DOWNLOAD ON
)
+externalproject_add (
+ intel-dbus-interfaces PREFIX ${CMAKE_BINARY_DIR}/intel-dbus-interfaces DEPENDS
+ sdbusplus-project GIT_REPOSITORY
+ https://github.com/openbmc/intel-dbus-interfaces GIT_TAG
+ 2b8f89f5876c5a97a34cdf922729d4283d5f2627 SOURCE_DIR
+ ${CMAKE_BINARY_DIR}/intel-dbus-interfaces-src BINARY_DIR
+ ${CMAKE_BINARY_DIR}/intel-dbus-interfaces-build CONFIGURE_COMMAND cd
+ ${CMAKE_BINARY_DIR}/intel-dbus-interfaces-src && export
+ PYTHONPATH=${CMAKE_BINARY_DIR}/prefix/lib/python2.7/site-packages:$ENV{PYTHONPATH}
+ && export PATH=${CMAKE_BINARY_DIR}/prefix/bin:$ENV{PATH} && export
+ PKG_CONFIG_PATH=${CMAKE_BINARY_DIR}/prefix/lib/pkgconfig && ./bootstrap.sh
+ && ./configure --prefix=${CMAKE_BINARY_DIR}/prefix
+ CPPFLAGS=-I${CMAKE_BINARY_DIR}/prefix/include/ BUILD_COMMAND cd
+ ${CMAKE_BINARY_DIR}/intel-dbus-interfaces-src && export
+ PYTHONPATH=${CMAKE_BINARY_DIR}/prefix/lib/python2.7/site-packages:$ENV{PYTHONPATH}
+ && export PATH=${CMAKE_BINARY_DIR}/prefix/bin:$ENV{PATH} && export
+ PKG_CONFIG_PATH=${CMAKE_BINARY_DIR}/prefix/lib/pkgconfig && make -j
+ verbose=1 INSTALL_COMMAND cd
+ ${CMAKE_BINARY_DIR}/intel-dbus-interfaces-src && make install
+ LOG_DOWNLOAD ON
+)
+
externalproject_add (cereal GIT_REPOSITORY https://github.com/USCiLab/cereal
GIT_TAG 51cbda5f30e56c801c07fe3d3aba5d7fb9e6cca4
SOURCE_DIR "${CMAKE_BINARY_DIR}/cereal-src" BINARY_DIR
diff --git a/include/oemcommands.hpp b/include/oemcommands.hpp
index cf91f58..2d2042d 100644
--- a/include/oemcommands.hpp
+++ b/include/oemcommands.hpp
@@ -130,10 +130,10 @@
static constexpr const uint8_t noShutdownPolicySupported = 0;
static constexpr const uint8_t shutdownPolicySupported = 1;
static constexpr const char* oemShutdownPolicyIntf =
- "xyz.openbmc_project.Control.ShutdownPolicy";
+ "com.intel.Control.OCOTShutdownPolicy";
static constexpr const char* oemShutdownPolicyObjPath =
- "/xyz/openbmc_project/control/shutdown_policy_config";
-static constexpr const char* oemShutdownPolicyObjPathProp = "Policy";
+ "/com/intel/control/ocotshutdown_policy_config";
+static constexpr const char* oemShutdownPolicyObjPathProp = "OCOTPolicy";
static constexpr const char* fwGetEnvCmd = "/sbin/fw_printenv";
static constexpr const char* fwSetEnvCmd = "/sbin/fw_setenv";
diff --git a/src/oemcommands.cpp b/src/oemcommands.cpp
index 1cb8791..0711183 100644
--- a/src/oemcommands.cpp
+++ b/src/oemcommands.cpp
@@ -23,6 +23,7 @@
#include <boost/container/flat_map.hpp>
#include <boost/process/child.hpp>
#include <boost/process/io.hpp>
+#include <com/intel/Control/OCOTShutdownPolicy/server.hpp>
#include <commandutils.hpp>
#include <iostream>
#include <ipmid/api.hpp>
@@ -557,7 +558,29 @@
Value variant = getDbusProperty(dbus, service, oemShutdownPolicyObjPath,
oemShutdownPolicyIntf,
oemShutdownPolicyObjPathProp);
- resp->policy = sdbusplus::message::variant_ns::get<uint8_t>(variant);
+
+ if (sdbusplus::com::intel::Control::server::OCOTShutdownPolicy::
+ convertPolicyFromString(std::get<std::string>(variant)) ==
+ sdbusplus::com::intel::Control::server::OCOTShutdownPolicy::Policy::
+ NoShutdownOnOCOT)
+ {
+ resp->policy = 0;
+ }
+ else if (sdbusplus::com::intel::Control::server::OCOTShutdownPolicy::
+ convertPolicyFromString(std::get<std::string>(variant)) ==
+ sdbusplus::com::intel::Control::server::OCOTShutdownPolicy::
+ Policy::ShutdownOnOCOT)
+ {
+ resp->policy = 1;
+ }
+ else
+ {
+ phosphor::logging::log<phosphor::logging::level::ERR>(
+ "oem_set_shutdown_policy: invalid property!",
+ phosphor::logging::entry(
+ "PROP=%s", std::get<std::string>(variant).c_str()));
+ return IPMI_CC_UNSPECIFIED_ERROR;
+ }
// TODO needs to check if it is multi-node products,
// policy is only supported on node 3/4
resp->policySupport = shutdownPolicySupported;
@@ -579,6 +602,9 @@
ipmi_context_t context)
{
uint8_t* req = reinterpret_cast<uint8_t*>(request);
+ sdbusplus::com::intel::Control::server::OCOTShutdownPolicy::Policy policy =
+ sdbusplus::com::intel::Control::server::OCOTShutdownPolicy::Policy::
+ NoShutdownOnOCOT;
// TODO needs to check if it is multi-node products,
// policy is only supported on node 3/4
@@ -598,13 +624,25 @@
return IPMI_CC_INVALID_FIELD_REQUEST;
}
+ if (*req == noShutdownOnOCOT)
+ {
+ policy = sdbusplus::com::intel::Control::server::OCOTShutdownPolicy::
+ Policy::NoShutdownOnOCOT;
+ }
+ else
+ {
+ policy = sdbusplus::com::intel::Control::server::OCOTShutdownPolicy::
+ Policy::ShutdownOnOCOT;
+ }
+
try
{
std::string service =
getService(dbus, oemShutdownPolicyIntf, oemShutdownPolicyObjPath);
- setDbusProperty(dbus, service, oemShutdownPolicyObjPath,
- oemShutdownPolicyIntf, oemShutdownPolicyObjPathProp,
- *req);
+ setDbusProperty(
+ dbus, service, oemShutdownPolicyObjPath, oemShutdownPolicyIntf,
+ oemShutdownPolicyObjPathProp,
+ sdbusplus::com::intel::Control::server::convertForMessage(policy));
}
catch (sdbusplus::exception_t& e)
{