summaryrefslogtreecommitdiffstats
path: root/apphandler.cpp
diff options
context:
space:
mode:
authorAlexander Amelkin <a.amelkin@yadro.com>2018-09-04 15:49:36 +0300
committerVernon Mauery <vernon.mauery@linux.intel.com>2018-09-25 15:40:12 +0000
commitba19c184dffca849007746ebb41e365bd6c60efe (patch)
tree462dbaf66c271f23b9762b00cfb9d88fa9169f55 /apphandler.cpp
parent1322768c7723b7052bb40fe94646c8189a2e20b3 (diff)
downloadphosphor-host-ipmid-ba19c184dffca849007746ebb41e365bd6c60efe.tar.gz
phosphor-host-ipmid-ba19c184dffca849007746ebb41e365bd6c60efe.zip
Get Device ID: Add handling of availability bit
Make "Device available" bit in Firmware Version 1 field reflect the ready state of BMC as indicated in DBus by CurrentBMCState property of xyz.openbmc_project.State.BMC interface. Change-Id: Ic108507882c68d6cc70b40849668732f7b759ef6 Signed-off-by: Alexander Amelkin <a.amelkin@yadro.com> Signed-off-by: Alexander Filippov <a.filippov@yadro.com>
Diffstat (limited to 'apphandler.cpp')
-rw-r--r--apphandler.cpp34
1 files changed, 32 insertions, 2 deletions
diff --git a/apphandler.cpp b/apphandler.cpp
index d59c6ac..3abac14 100644
--- a/apphandler.cpp
+++ b/apphandler.cpp
@@ -39,9 +39,12 @@ namespace filesystem = std::experimental::filesystem;
#include <xyz/openbmc_project/Common/error.hpp>
#include <xyz/openbmc_project/Software/Activation/server.hpp>
#include <xyz/openbmc_project/Software/Version/server.hpp>
+#include <xyz/openbmc_project/State/BMC/server.hpp>
extern sd_bus* bus;
+constexpr auto bmc_state_interface = "xyz.openbmc_project.State.BMC";
+constexpr auto bmc_state_property = "CurrentBMCState";
constexpr auto bmc_interface = "xyz.openbmc_project.Inventory.Item.Bmc";
constexpr auto bmc_guid_interface = "xyz.openbmc_project.Common.UUID";
constexpr auto bmc_guid_property = "UUID";
@@ -61,6 +64,7 @@ using namespace sdbusplus::xyz::openbmc_project::Common::Error;
using Version = sdbusplus::xyz::openbmc_project::Software::server::Version;
using Activation =
sdbusplus::xyz::openbmc_project::Software::server::Activation;
+using BMC = sdbusplus::xyz::openbmc_project::State::server::BMC;
namespace fs = std::filesystem;
// Offset in get device id command.
@@ -151,6 +155,22 @@ std::string getActiveSoftwareVersionInfo()
return revision;
}
+bool getCurrentBmcState()
+{
+ sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
+
+ // Get the Inventory object implementing the BMC interface
+ ipmi::DbusObjectInfo bmcObject =
+ ipmi::getDbusObject(bus, bmc_state_interface);
+ auto variant =
+ ipmi::getDbusProperty(bus, bmcObject.second, bmcObject.first,
+ bmc_state_interface, bmc_state_property);
+
+ return variant.is<std::string>() &&
+ BMC::convertBMCStateFromString(variant.get<std::string>()) ==
+ BMC::BMCState::Ready;
+}
+
ipmi_ret_t ipmi_app_set_acpi_power_state(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
ipmi_request_t request,
ipmi_response_t response,
@@ -272,6 +292,8 @@ ipmi_ret_t ipmi_app_get_device_id(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
static ipmi_device_id_t dev_id{};
static bool dev_id_initialized = false;
const char* filename = "/usr/share/ipmi-providers/dev_id.json";
+ constexpr auto ipmiDevIdStateShift = 7;
+ constexpr auto ipmiDevIdFw1Mask = ~(1 << ipmiDevIdStateShift);
// Data length
*data_len = sizeof(dev_id);
@@ -294,8 +316,9 @@ ipmi_ret_t ipmi_app_get_device_id(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
// 0=normal operation
// 1=device firmware, SDR update,
// or self-initialization in progress.
- // our SDR is normal working condition, so mask:
- dev_id.fw[0] = 0x7F & rev.major;
+ // The availability may change in run time, so mask here
+ // and initialize later.
+ dev_id.fw[0] = rev.major & ipmiDevIdFw1Mask;
rev.minor = (rev.minor > 99 ? 99 : rev.minor);
dev_id.fw[1] = rev.minor % 10 + (rev.minor / 10) * 16;
@@ -340,6 +363,13 @@ ipmi_ret_t ipmi_app_get_device_id(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
}
}
+ // Set availability to the actual current BMC state
+ dev_id.fw[0] &= ipmiDevIdFw1Mask;
+ if (!getCurrentBmcState())
+ {
+ dev_id.fw[0] |= (1 << ipmiDevIdStateShift);
+ }
+
// Pack the actual response
memcpy(response, &dev_id, *data_len);
OpenPOWER on IntegriCloud