summaryrefslogtreecommitdiffstats
path: root/chassishandler.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'chassishandler.cpp')
-rw-r--r--chassishandler.cpp730
1 files changed, 365 insertions, 365 deletions
diff --git a/chassishandler.cpp b/chassishandler.cpp
index 2ad9948..6002e7a 100644
--- a/chassishandler.cpp
+++ b/chassishandler.cpp
@@ -1,72 +1,78 @@
#include "chassishandler.h"
-#include "host-ipmid/ipmid-api.h"
-#include "types.hpp"
+
#include "ipmid.hpp"
#include "settings.hpp"
+#include "types.hpp"
#include "utils.hpp"
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdint.h>
-#include <mapper.h>
#include <arpa/inet.h>
-#include <netinet/in.h>
+#include <endian.h>
#include <limits.h>
+#include <mapper.h>
+#include <netinet/in.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
-#include <endian.h>
-#include <sstream>
+
#include <array>
+#include <chrono>
#include <fstream>
#include <future>
-#include <chrono>
+#include <sstream>
+
+#include "host-ipmid/ipmid-api.h"
#if __has_include(<filesystem>)
#include <filesystem>
#elif __has_include(<experimental/filesystem>)
#include <experimental/filesystem>
-namespace std {
- // splice experimental::filesystem into std
- namespace filesystem = std::experimental::filesystem;
-}
+namespace std
+{
+// splice experimental::filesystem into std
+namespace filesystem = std::experimental::filesystem;
+} // namespace std
#else
-# error filesystem not available
+#error filesystem not available
#endif
-#include <string>
-#include <map>
+#include "config.h"
-#include <phosphor-logging/log.hpp>
-#include <phosphor-logging/elog-errors.hpp>
-#include <xyz/openbmc_project/State/Host/server.hpp>
-#include "xyz/openbmc_project/Common/error.hpp"
+#include "timer.hpp"
+#include <map>
+#include <phosphor-logging/elog-errors.hpp>
+#include <phosphor-logging/log.hpp>
#include <sdbusplus/bus.hpp>
#include <sdbusplus/server/object.hpp>
-#include <xyz/openbmc_project/Control/Boot/Source/server.hpp>
+#include <string>
+#include <xyz/openbmc_project/Common/error.hpp>
#include <xyz/openbmc_project/Control/Boot/Mode/server.hpp>
+#include <xyz/openbmc_project/Control/Boot/Source/server.hpp>
#include <xyz/openbmc_project/Control/Power/RestorePolicy/server.hpp>
+#include <xyz/openbmc_project/State/Host/server.hpp>
#include <xyz/openbmc_project/State/PowerOnHours/server.hpp>
-
-#include "config.h"
-#include "timer.hpp"
-//Defines
-#define SET_PARM_VERSION 0x01
-#define SET_PARM_BOOT_FLAGS_PERMANENT 0x40 //boot flags data1 7th bit on
-#define SET_PARM_BOOT_FLAGS_VALID_ONE_TIME 0x80 //boot flags data1 8th bit on
-#define SET_PARM_BOOT_FLAGS_VALID_PERMANENT 0xC0 //boot flags data1 7 & 8 bit on
+// Defines
+#define SET_PARM_VERSION 0x01
+#define SET_PARM_BOOT_FLAGS_PERMANENT 0x40 // boot flags data1 7th bit on
+#define SET_PARM_BOOT_FLAGS_VALID_ONE_TIME 0x80 // boot flags data1 8th bit on
+#define SET_PARM_BOOT_FLAGS_VALID_PERMANENT \
+ 0xC0 // boot flags data1 7 & 8 bit
+ // on
std::unique_ptr<phosphor::ipmi::Timer> identifyTimer = nullptr;
-constexpr size_t SIZE_MAC = 18;
-constexpr size_t SIZE_BOOT_OPTION = (uint8_t)BootOptionResponseSize::
- OPAL_NETWORK_SETTINGS;//Maximum size of the boot option parametrs
+constexpr size_t SIZE_MAC = 18;
+constexpr size_t SIZE_BOOT_OPTION = (uint8_t)
+ BootOptionResponseSize::OPAL_NETWORK_SETTINGS; // Maximum size of the boot
+ // option parametrs
constexpr size_t SIZE_PREFIX = 7;
constexpr size_t MAX_PREFIX_VALUE = 32;
constexpr size_t SIZE_COOKIE = 4;
constexpr size_t SIZE_VERSION = 2;
constexpr size_t DEFAULT_IDENTIFY_TIME_OUT = 15;
-//PetiBoot-Specific
+// PetiBoot-Specific
static constexpr uint8_t net_conf_initial_bytes[] = {0x80, 0x21, 0x70, 0x62,
- 0x21, 0x00, 0x01, 0x06};
+ 0x21, 0x00, 0x01, 0x06};
static constexpr size_t COOKIE_OFFSET = 1;
static constexpr size_t VERSION_OFFSET = 5;
@@ -84,10 +90,10 @@ void register_netfn_chassis_functions() __attribute__((constructor));
// Host settings in dbus
// Service name should be referenced by connection name got via object mapper
-const char *settings_object_name = "/org/openbmc/settings/host0";
-const char *settings_intf_name = "org.freedesktop.DBus.Properties";
-const char *host_intf_name = "org.openbmc.settings.Host";
-const char *identify_led_object_name =
+const char* settings_object_name = "/org/openbmc/settings/host0";
+const char* settings_intf_name = "org.freedesktop.DBus.Properties";
+const char* host_intf_name = "org.openbmc.settings.Host";
+const char* identify_led_object_name =
"/xyz/openbmc_project/led/groups/enclosure_identify";
constexpr auto SETTINGS_ROOT = "/";
@@ -98,7 +104,7 @@ constexpr auto MAC_INTERFACE = "xyz.openbmc_project.Network.MACAddress";
static constexpr auto chassisStateRoot = "/xyz/openbmc_project/state";
static constexpr auto chassisPOHStateIntf =
- "xyz.openbmc_project.State.PowerOnHours";
+ "xyz.openbmc_project.State.PowerOnHours";
static constexpr auto pOHCounterProperty = "POHCounter";
static constexpr auto match = "chassis0";
@@ -110,7 +116,7 @@ typedef struct
uint8_t sel_dev_addr;
uint8_t system_management_dev_addr;
uint8_t bridge_dev_addr;
-}__attribute__((packed)) ipmi_chassis_cap_t;
+} __attribute__((packed)) ipmi_chassis_cap_t;
typedef struct
{
@@ -118,16 +124,16 @@ typedef struct
uint8_t last_power_event;
uint8_t misc_power_state;
uint8_t front_panel_button_cap_status;
-}__attribute__((packed)) ipmi_get_chassis_status_t;
+} __attribute__((packed)) ipmi_get_chassis_status_t;
/**
* @struct Get POH counter command response data
*/
struct GetPOHCountResponse
{
- uint8_t minPerCount; ///< Minutes per count
+ uint8_t minPerCount; ///< Minutes per count
uint8_t counterReading[4]; ///< Counter reading
-}__attribute__((packed));
+} __attribute__((packed));
// Phosphor Host State manager
namespace State = sdbusplus::xyz::openbmc_project::State::server;
@@ -165,27 +171,28 @@ constexpr auto minutesPerCount = 60;
} // namespace poh
-//TODO : Can remove the below function as we have
+// TODO : Can remove the below function as we have
// new functions which uses sdbusplus.
//
// openbmc/openbmc#1489
-int dbus_get_property(const char *name, char **buf)
+int dbus_get_property(const char* name, char** buf)
{
sd_bus_error error = SD_BUS_ERROR_NULL;
- sd_bus_message *m = NULL;
- sd_bus *bus = NULL;
- char *temp_buf = NULL;
- char *connection = NULL;
+ sd_bus_message* m = NULL;
+ sd_bus* bus = NULL;
+ char* temp_buf = NULL;
+ char* connection = NULL;
int r;
// Get the system bus where most system services are provided.
bus = ipmid_get_sd_bus_connection();
r = mapper_get_service(bus, settings_object_name, &connection);
- if (r < 0) {
- log<level::ERR>("Failed to get connection",
- entry("OBJ_NAME=%s", settings_object_name),
- entry("ERRNO=0x%X", -r));
+ if (r < 0)
+ {
+ log<level::ERR>("Failed to get connection",
+ entry("OBJ_NAME=%s", settings_object_name),
+ entry("ERRNO=0x%X", -r));
goto finish;
}
@@ -195,18 +202,18 @@ int dbus_get_property(const char *name, char **buf)
* Signatures and input arguments are provided by the arguments at the
* end.
*/
- r = sd_bus_call_method(bus,
- connection, /* service to contact */
- settings_object_name, /* object path */
- settings_intf_name, /* interface name */
- "Get", /* method name */
- &error, /* object to return error in */
- &m, /* return message on success */
- "ss", /* input signature */
- host_intf_name, /* first argument */
- name); /* second argument */
-
- if (r < 0) {
+ r = sd_bus_call_method(bus, connection, /* service to contact */
+ settings_object_name, /* object path */
+ settings_intf_name, /* interface name */
+ "Get", /* method name */
+ &error, /* object to return error in */
+ &m, /* return message on success */
+ "ss", /* input signature */
+ host_intf_name, /* first argument */
+ name); /* second argument */
+
+ if (r < 0)
+ {
log<level::ERR>("Failed to issue Get method call",
entry("ERRNO=0x%X", r));
goto finish;
@@ -217,7 +224,8 @@ int dbus_get_property(const char *name, char **buf)
* specified.
*/
r = sd_bus_message_read(m, "v", "s", &temp_buf);
- if (r < 0) {
+ if (r < 0)
+ {
log<level::ERR>("Failed to parse response message",
entry("ERRNO=0x%X", -r));
goto finish;
@@ -230,7 +238,6 @@ int dbus_get_property(const char *name, char **buf)
}
*/
-
finish:
sd_bus_error_free(&error);
sd_bus_message_unref(m);
@@ -239,24 +246,25 @@ finish:
return r;
}
-//TODO : Can remove the below function as we have
+// TODO : Can remove the below function as we have
// new functions which uses sdbusplus.
//
// openbmc/openbmc#1489
-int dbus_set_property(const char * name, const char *value)
+int dbus_set_property(const char* name, const char* value)
{
sd_bus_error error = SD_BUS_ERROR_NULL;
- sd_bus_message *m = NULL;
- sd_bus *bus = NULL;
- char *connection = NULL;
+ sd_bus_message* m = NULL;
+ sd_bus* bus = NULL;
+ char* connection = NULL;
int r;
// Get the system bus where most system services are provided.
bus = ipmid_get_sd_bus_connection();
r = mapper_get_service(bus, settings_object_name, &connection);
- if (r < 0) {
+ if (r < 0)
+ {
log<level::ERR>("Failed to get connection",
entry("OBJ_NAME=%s", settings_object_name),
entry("ERRNO=0x%X", -r));
@@ -269,26 +277,26 @@ int dbus_set_property(const char * name, const char *value)
* Signatures and input arguments are provided by the arguments at the
* end.
*/
- r = sd_bus_call_method(bus,
- connection, /* service to contact */
- settings_object_name, /* object path */
- settings_intf_name, /* interface name */
- "Set", /* method name */
- &error, /* object to return error in */
- &m, /* return message on success */
- "ssv", /* input signature */
- host_intf_name, /* first argument */
- name, /* second argument */
- "s", /* third argument */
- value); /* fourth argument */
-
- if (r < 0) {
+ r = sd_bus_call_method(bus, connection, /* service to contact */
+ settings_object_name, /* object path */
+ settings_intf_name, /* interface name */
+ "Set", /* method name */
+ &error, /* object to return error in */
+ &m, /* return message on success */
+ "ssv", /* input signature */
+ host_intf_name, /* first argument */
+ name, /* second argument */
+ "s", /* third argument */
+ value); /* fourth argument */
+
+ if (r < 0)
+ {
log<level::ERR>("Failed to issue Set method call",
entry("ERRNO=0x%X", r));
goto finish;
}
- finish:
+finish:
sd_bus_error_free(&error);
sd_bus_message_unref(m);
free(connection);
@@ -296,23 +304,25 @@ int dbus_set_property(const char * name, const char *value)
return r;
}
-struct get_sys_boot_options_t {
+struct get_sys_boot_options_t
+{
uint8_t parameter;
uint8_t set;
uint8_t block;
-} __attribute__ ((packed));
+} __attribute__((packed));
-struct get_sys_boot_options_response_t {
+struct get_sys_boot_options_response_t
+{
uint8_t version;
uint8_t parm;
uint8_t data[SIZE_BOOT_OPTION];
-} __attribute__ ((packed));
+} __attribute__((packed));
-struct set_sys_boot_options_t {
+struct set_sys_boot_options_t
+{
uint8_t parameter;
uint8_t data[SIZE_BOOT_OPTION];
-} __attribute__ ((packed));
-
+} __attribute__((packed));
int getHostNetworkData(get_sys_boot_options_response_t* respptr)
{
@@ -322,7 +332,7 @@ int getHostNetworkData(get_sys_boot_options_response_t* respptr)
try
{
- //TODO There may be cases where an interface is implemented by multiple
+ // TODO There may be cases where an interface is implemented by multiple
// objects,to handle such cases we are interested on that object
// which are on interested busname.
// Currenlty mapper doesn't give the readable busname(gives busid)
@@ -338,22 +348,23 @@ int getHostNetworkData(get_sys_boot_options_response_t* respptr)
auto macObjectInfo = ipmi::getDbusObject(bus, MAC_INTERFACE,
SETTINGS_ROOT, SETTINGS_MATCH);
- properties = ipmi::getAllDbusProperties(bus, ipObjectInfo.second,
- ipObjectInfo.first, IP_INTERFACE);
- auto variant =
- ipmi::getDbusProperty(bus, macObjectInfo.second,
- macObjectInfo.first,
- MAC_INTERFACE, "MACAddress");
+ properties = ipmi::getAllDbusProperties(
+ bus, ipObjectInfo.second, ipObjectInfo.first, IP_INTERFACE);
+ auto variant = ipmi::getDbusProperty(bus, macObjectInfo.second,
+ macObjectInfo.first, MAC_INTERFACE,
+ "MACAddress");
- auto ipAddress = properties["Address"].get<std::string>();
+ auto ipAddress = properties["Address"].get<std::string>();
auto gateway = properties["Gateway"].get<std::string>();
auto prefix = properties["PrefixLength"].get<uint8_t>();
- uint8_t isStatic = (properties["Origin"].get<std::string>() ==
- "xyz.openbmc_project.Network.IP.AddressOrigin.Static")
- ? 1 : 0;
+ uint8_t isStatic =
+ (properties["Origin"].get<std::string>() ==
+ "xyz.openbmc_project.Network.IP.AddressOrigin.Static")
+ ? 1
+ : 0;
auto MACAddress = variant.get<std::string>();
@@ -373,9 +384,8 @@ int getHostNetworkData(get_sys_boot_options_response_t* respptr)
// should not be default one,don't send blank override.
if (isStatic)
{
- if((ipAddress == ipmi::network::DEFAULT_ADDRESS) ||
- (gateway == ipmi::network::DEFAULT_ADDRESS) ||
- (!prefix))
+ if ((ipAddress == ipmi::network::DEFAULT_ADDRESS) ||
+ (gateway == ipmi::network::DEFAULT_ADDRESS) || (!prefix))
{
memset(respptr->data, 0, SIZE_BOOT_OPTION);
rc = -1;
@@ -383,30 +393,28 @@ int getHostNetworkData(get_sys_boot_options_response_t* respptr)
}
}
- sscanf(MACAddress.c_str(), ipmi::network::MAC_ADDRESS_FORMAT,
- (respptr->data + MAC_OFFSET),
- (respptr->data + MAC_OFFSET + 1),
- (respptr->data + MAC_OFFSET + 2),
- (respptr->data + MAC_OFFSET + 3),
- (respptr->data + MAC_OFFSET + 4),
- (respptr->data + MAC_OFFSET + 5));
+ sscanf(
+ MACAddress.c_str(), ipmi::network::MAC_ADDRESS_FORMAT,
+ (respptr->data + MAC_OFFSET), (respptr->data + MAC_OFFSET + 1),
+ (respptr->data + MAC_OFFSET + 2), (respptr->data + MAC_OFFSET + 3),
+ (respptr->data + MAC_OFFSET + 4), (respptr->data + MAC_OFFSET + 5));
respptr->data[MAC_OFFSET + 6] = 0x00;
- memcpy(respptr->data + ADDRTYPE_OFFSET, &isStatic,
- sizeof(isStatic));
+ memcpy(respptr->data + ADDRTYPE_OFFSET, &isStatic, sizeof(isStatic));
uint8_t addressFamily = (properties["Type"].get<std::string>() ==
- "xyz.openbmc_project.Network.IP.Protocol.IPv4") ?
- AF_INET : AF_INET6;
+ "xyz.openbmc_project.Network.IP.Protocol.IPv4")
+ ? AF_INET
+ : AF_INET6;
- addrSize = (addressFamily == AF_INET) ?
- ipmi::network::IPV4_ADDRESS_SIZE_BYTE :
- ipmi::network::IPV6_ADDRESS_SIZE_BYTE;
+ addrSize = (addressFamily == AF_INET)
+ ? ipmi::network::IPV4_ADDRESS_SIZE_BYTE
+ : ipmi::network::IPV6_ADDRESS_SIZE_BYTE;
// ipaddress and gateway would be in IPv4 format
inet_pton(addressFamily, ipAddress.c_str(),
- (respptr->data + IPADDR_OFFSET));
+ (respptr->data + IPADDR_OFFSET));
uint8_t prefixOffset = IPADDR_OFFSET + addrSize;
@@ -415,8 +423,7 @@ int getHostNetworkData(get_sys_boot_options_response_t* respptr)
uint8_t gatewayOffset = prefixOffset + sizeof(decltype(prefix));
inet_pton(addressFamily, gateway.c_str(),
- (respptr->data + gatewayOffset));
-
+ (respptr->data + gatewayOffset));
}
catch (InternalFailure& e)
{
@@ -426,8 +433,8 @@ int getHostNetworkData(get_sys_boot_options_response_t* respptr)
return rc;
}
- //PetiBoot-Specific
- //If success then copy the first 9 bytes to the data
+ // PetiBoot-Specific
+ // If success then copy the first 9 bytes to the data
memcpy(respptr->data, net_conf_initial_bytes,
sizeof(net_conf_initial_bytes));
@@ -453,30 +460,32 @@ int getHostNetworkData(get_sys_boot_options_response_t* respptr)
* @returns address in text form.
*/
-std::string getAddrStr(uint8_t family, uint8_t* data,
- uint8_t offset, uint8_t addrSize)
+std::string getAddrStr(uint8_t family, uint8_t* data, uint8_t offset,
+ uint8_t addrSize)
{
char ipAddr[INET6_ADDRSTRLEN] = {};
- switch(family)
+ switch (family)
{
case AF_INET:
{
- struct sockaddr_in addr4 {};
+ struct sockaddr_in addr4
+ {
+ };
memcpy(&addr4.sin_addr.s_addr, &data[offset], addrSize);
- inet_ntop(AF_INET, &addr4.sin_addr,
- ipAddr, INET_ADDRSTRLEN);
+ inet_ntop(AF_INET, &addr4.sin_addr, ipAddr, INET_ADDRSTRLEN);
break;
}
case AF_INET6:
{
- struct sockaddr_in6 addr6 {};
+ struct sockaddr_in6 addr6
+ {
+ };
memcpy(&addr6.sin6_addr.s6_addr, &data[offset], addrSize);
- inet_ntop(AF_INET6, &addr6.sin6_addr,
- ipAddr, INET6_ADDRSTRLEN);
+ inet_ntop(AF_INET6, &addr6.sin6_addr, ipAddr, INET6_ADDRSTRLEN);
break;
}
@@ -493,19 +502,18 @@ int setHostNetworkData(set_sys_boot_options_t* reqptr)
{
using namespace std::string_literals;
std::string host_network_config;
- char mac[] {"00:00:00:00:00:00"};
+ char mac[]{"00:00:00:00:00:00"};
std::string ipAddress, gateway;
- char addrOrigin {0};
- uint8_t addrSize {0};
+ char addrOrigin{0};
+ uint8_t addrSize{0};
std::string addressOrigin =
"xyz.openbmc_project.Network.IP.AddressOrigin.DHCP";
- std::string addressType =
- "xyz.openbmc_project.Network.IP.Protocol.IPv4";
- uint8_t prefix {0};
+ std::string addressType = "xyz.openbmc_project.Network.IP.Protocol.IPv4";
+ uint8_t prefix{0};
uint32_t zeroCookie = 0;
uint8_t family = AF_INET;
- //cookie starts from second byte
+ // cookie starts from second byte
// version starts from sixth byte
try
@@ -514,13 +522,12 @@ int setHostNetworkData(set_sys_boot_options_t* reqptr)
{
// cookie == 0x21 0x70 0x62 0x21
if (memcmp(&(reqptr->data[COOKIE_OFFSET]),
- (net_conf_initial_bytes + COOKIE_OFFSET),
- SIZE_COOKIE) != 0)
+ (net_conf_initial_bytes + COOKIE_OFFSET),
+ SIZE_COOKIE) != 0)
{
- //cookie == 0
- if (memcmp(&(reqptr->data[COOKIE_OFFSET]),
- &zeroCookie,
- SIZE_COOKIE) == 0)
+ // cookie == 0
+ if (memcmp(&(reqptr->data[COOKIE_OFFSET]), &zeroCookie,
+ SIZE_COOKIE) == 0)
{
// need to zero out the network settings.
break;
@@ -532,8 +539,8 @@ int setHostNetworkData(set_sys_boot_options_t* reqptr)
// vesion == 0x00 0x01
if (memcmp(&(reqptr->data[VERSION_OFFSET]),
- (net_conf_initial_bytes + VERSION_OFFSET),
- SIZE_VERSION) != 0)
+ (net_conf_initial_bytes + VERSION_OFFSET),
+ SIZE_VERSION) != 0)
{
log<level::ERR>("Invalid Version");
@@ -541,10 +548,8 @@ int setHostNetworkData(set_sys_boot_options_t* reqptr)
}
snprintf(mac, SIZE_MAC, ipmi::network::MAC_ADDRESS_FORMAT,
- reqptr->data[MAC_OFFSET],
- reqptr->data[MAC_OFFSET + 1],
- reqptr->data[MAC_OFFSET + 2],
- reqptr->data[MAC_OFFSET + 3],
+ reqptr->data[MAC_OFFSET], reqptr->data[MAC_OFFSET + 1],
+ reqptr->data[MAC_OFFSET + 2], reqptr->data[MAC_OFFSET + 3],
reqptr->data[MAC_OFFSET + 4],
reqptr->data[MAC_OFFSET + 5]);
@@ -558,7 +563,8 @@ int setHostNetworkData(set_sys_boot_options_t* reqptr)
}
// Get the address size
- memcpy(&addrSize ,&reqptr->data[ADDR_SIZE_OFFSET], sizeof(addrSize));
+ memcpy(&addrSize, &reqptr->data[ADDR_SIZE_OFFSET],
+ sizeof(addrSize));
uint8_t prefixOffset = IPADDR_OFFSET + addrSize;
@@ -573,17 +579,18 @@ int setHostNetworkData(set_sys_boot_options_t* reqptr)
family = AF_INET6;
}
- ipAddress = getAddrStr(family, reqptr->data, IPADDR_OFFSET, addrSize);
+ ipAddress =
+ getAddrStr(family, reqptr->data, IPADDR_OFFSET, addrSize);
gateway = getAddrStr(family, reqptr->data, gatewayOffset, addrSize);
- } while(0);
-
- //Cookie == 0 or it is a valid cookie
- host_network_config += "ipaddress="s + ipAddress +
- ",prefix="s + std::to_string(prefix) + ",gateway="s + gateway +
- ",mac="s + mac + ",addressOrigin="s + addressOrigin;
+ } while (0);
+ // Cookie == 0 or it is a valid cookie
+ host_network_config += "ipaddress="s + ipAddress + ",prefix="s +
+ std::to_string(prefix) + ",gateway="s + gateway +
+ ",mac="s + mac + ",addressOrigin="s +
+ addressOrigin;
sdbusplus::bus::bus bus(ipmid_get_sd_bus_connection());
@@ -593,22 +600,22 @@ int setHostNetworkData(set_sys_boot_options_t* reqptr)
SETTINGS_ROOT, SETTINGS_MATCH);
// set the dbus property
ipmi::setDbusProperty(bus, ipObjectInfo.second, ipObjectInfo.first,
- IP_INTERFACE, "Address", std::string(ipAddress));
- ipmi::setDbusProperty(bus, ipObjectInfo.second, ipObjectInfo.first,
- IP_INTERFACE, "PrefixLength", prefix);
+ IP_INTERFACE, "Address", std::string(ipAddress));
ipmi::setDbusProperty(bus, ipObjectInfo.second, ipObjectInfo.first,
- IP_INTERFACE, "Origin", addressOrigin);
+ IP_INTERFACE, "PrefixLength", prefix);
ipmi::setDbusProperty(bus, ipObjectInfo.second, ipObjectInfo.first,
- IP_INTERFACE, "Gateway", std::string(gateway));
+ IP_INTERFACE, "Origin", addressOrigin);
ipmi::setDbusProperty(bus, ipObjectInfo.second, ipObjectInfo.first,
- IP_INTERFACE, "Type",
- std::string("xyz.openbmc_project.Network.IP.Protocol.IPv4"));
+ IP_INTERFACE, "Gateway", std::string(gateway));
+ ipmi::setDbusProperty(
+ bus, ipObjectInfo.second, ipObjectInfo.first, IP_INTERFACE, "Type",
+ std::string("xyz.openbmc_project.Network.IP.Protocol.IPv4"));
ipmi::setDbusProperty(bus, macObjectInfo.second, macObjectInfo.first,
- MAC_INTERFACE,"MACAddress", std::string(mac));
-
- log<level::DEBUG>("Network configuration changed",
- entry("NETWORKCONFIG=%s", host_network_config.c_str()));
+ MAC_INTERFACE, "MACAddress", std::string(mac));
+ log<level::DEBUG>(
+ "Network configuration changed",
+ entry("NETWORKCONFIG=%s", host_network_config.c_str()));
}
catch (InternalFailure& e)
{
@@ -623,15 +630,15 @@ uint32_t getPOHCounter()
{
sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
- auto chassisStateObj = ipmi::getDbusObject(bus, chassisPOHStateIntf,
- chassisStateRoot, match);
+ auto chassisStateObj =
+ ipmi::getDbusObject(bus, chassisPOHStateIntf, chassisStateRoot, match);
- auto service = ipmi::getService(bus, chassisPOHStateIntf,
- chassisStateObj.first);
+ auto service =
+ ipmi::getService(bus, chassisPOHStateIntf, chassisStateObj.first);
- auto propValue = ipmi::getDbusProperty(bus, service, chassisStateObj.first,
- chassisPOHStateIntf,
- pOHCounterProperty);
+ auto propValue =
+ ipmi::getDbusProperty(bus, service, chassisStateObj.first,
+ chassisPOHStateIntf, pOHCounterProperty);
return propValue.get<uint32_t>();
}
@@ -649,8 +656,10 @@ ipmi_ret_t ipmi_chassis_wildcard(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
}
ipmi_ret_t ipmi_get_chassis_cap(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
- ipmi_request_t request, ipmi_response_t response,
- ipmi_data_len_t data_len, ipmi_context_t context)
+ ipmi_request_t request,
+ ipmi_response_t response,
+ ipmi_data_len_t data_len,
+ ipmi_context_t context)
{
// sd_bus error
ipmi_ret_t rc = IPMI_CC_OK;
@@ -665,9 +674,11 @@ ipmi_ret_t ipmi_get_chassis_cap(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
// [7..4] - reserved
// [3] – 1b = provides power interlock (IPM 1.5)
// [2] – 1b = provides Diagnostic Interrupt (FP NMI)
- // [1] – 1b = provides “Front Panel Lockout” (indicates that the chassis has capabilities
- // to lock out external power control and reset button or front panel interfaces
- // and/or detect tampering with those interfaces).
+ // [1] – 1b = provides “Front Panel Lockout” (indicates that the chassis has
+ // capabilities
+ // to lock out external power control and reset button or front
+ // panel interfaces and/or detect tampering with those
+ // interfaces).
// [0] -1b = Chassis provides intrusion (physical security) sensor.
// set to default value 0x0.
chassis_cap.cap_flags = 0x0;
@@ -700,26 +711,26 @@ ipmi_ret_t ipmi_get_chassis_cap(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
int initiate_state_transition(State::Host::Transition transition)
{
// OpenBMC Host State Manager dbus framework
- constexpr auto HOST_STATE_MANAGER_ROOT = "/xyz/openbmc_project/state/host0";
+ constexpr auto HOST_STATE_MANAGER_ROOT = "/xyz/openbmc_project/state/host0";
constexpr auto HOST_STATE_MANAGER_IFACE = "xyz.openbmc_project.State.Host";
- constexpr auto DBUS_PROPERTY_IFACE = "org.freedesktop.DBus.Properties";
- constexpr auto PROPERTY = "RequestedHostTransition";
+ constexpr auto DBUS_PROPERTY_IFACE = "org.freedesktop.DBus.Properties";
+ constexpr auto PROPERTY = "RequestedHostTransition";
// sd_bus error
int rc = 0;
- char *busname = NULL;
+ char* busname = NULL;
// SD Bus error report mechanism.
sd_bus_error bus_error = SD_BUS_ERROR_NULL;
// Gets a hook onto either a SYSTEM or SESSION bus
- sd_bus *bus_type = ipmid_get_sd_bus_connection();
+ sd_bus* bus_type = ipmid_get_sd_bus_connection();
rc = mapper_get_service(bus_type, HOST_STATE_MANAGER_ROOT, &busname);
if (rc < 0)
{
- log<level::ERR>("Failed to get bus name",
- entry("ERRNO=0x%X, OBJPATH=%s",
- -rc, HOST_STATE_MANAGER_ROOT));
+ log<level::ERR>(
+ "Failed to get bus name",
+ entry("ERRNO=0x%X, OBJPATH=%s", -rc, HOST_STATE_MANAGER_ROOT));
return rc;
}
@@ -734,10 +745,9 @@ int initiate_state_transition(State::Host::Transition transition)
&bus_error, // object to return error
nullptr, // Response buffer if any
"ssv", // Takes 3 arguments
- HOST_STATE_MANAGER_IFACE,
- PROPERTY,
- "s", request.c_str());
- if(rc < 0)
+ HOST_STATE_MANAGER_IFACE, PROPERTY, "s",
+ request.c_str());
+ if (rc < 0)
{
log<level::ERR>("Failed to initiate transition",
entry("ERRNO=0x%X, REQUEST=%s", -rc, request.c_str()));
@@ -760,12 +770,10 @@ using namespace sdbusplus::xyz::openbmc_project::Control::Power::server;
using IpmiValue = uint8_t;
using DbusValue = RestorePolicy::Policy;
-std::map<DbusValue, IpmiValue> dbusToIpmi =
-{
+std::map<DbusValue, IpmiValue> dbusToIpmi = {
{RestorePolicy::Policy::AlwaysOff, 0x00},
{RestorePolicy::Policy::Restore, 0x01},
- {RestorePolicy::Policy::AlwaysOn, 0x02}
-};
+ {RestorePolicy::Policy::AlwaysOn, 0x02}};
} // namespace power_policy
@@ -778,14 +786,14 @@ ipmi_ret_t ipmi_get_chassis_status(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
ipmi_data_len_t data_len,
ipmi_context_t context)
{
- const char *objname = "/org/openbmc/control/power0";
- const char *intf = "org.openbmc.control.Power";
+ const char* objname = "/org/openbmc/control/power0";
+ const char* intf = "org.openbmc.control.Power";
- sd_bus *bus = NULL;
- sd_bus_message *reply = NULL;
+ sd_bus* bus = NULL;
+ sd_bus_message* reply = NULL;
int r = 0;
int pgood = 0;
- char *busname = NULL;
+ char* busname = NULL;
ipmi_ret_t rc = IPMI_CC_OK;
ipmi_get_chassis_status_t chassis_status{};
@@ -796,12 +804,9 @@ ipmi_ret_t ipmi_get_chassis_status(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
using namespace power_policy;
const auto& powerRestoreSetting = objects.map.at(powerRestoreIntf).front();
- auto method =
- dbus.new_method_call(
- objects.service(powerRestoreSetting, powerRestoreIntf).c_str(),
- powerRestoreSetting.c_str(),
- ipmi::PROP_INTF,
- "Get");
+ auto method = dbus.new_method_call(
+ objects.service(powerRestoreSetting, powerRestoreIntf).c_str(),
+ powerRestoreSetting.c_str(), ipmi::PROP_INTF, "Get");
method.append(powerRestoreIntf, "PowerRestorePolicy");
auto resp = dbus.call(method);
if (resp.is_method_error())
@@ -821,29 +826,29 @@ ipmi_ret_t ipmi_get_chassis_status(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
bus = ipmid_get_sd_bus_connection();
r = mapper_get_service(bus, objname, &busname);
- if (r < 0) {
- log<level::ERR>("Failed to get bus name",
- entry("ERRNO=0x%X", -r));
+ if (r < 0)
+ {
+ log<level::ERR>("Failed to get bus name", entry("ERRNO=0x%X", -r));
rc = IPMI_CC_UNSPECIFIED_ERROR;
goto finish;
}
- r = sd_bus_get_property(bus, busname, objname, intf, "pgood", NULL, &reply, "i");
- if (r < 0) {
+ r = sd_bus_get_property(bus, busname, objname, intf, "pgood", NULL, &reply,
+ "i");
+ if (r < 0)
+ {
log<level::ERR>("Failed to call sd_bus_get_property",
- entry("PROPERTY=%s","pgood"),
- entry("ERRNO=0x%X", -r),
- entry("BUS=%s", busname),
- entry("PATH=%s", objname),
+ entry("PROPERTY=%s", "pgood"), entry("ERRNO=0x%X", -r),
+ entry("BUS=%s", busname), entry("PATH=%s", objname),
entry("INTERFACE=%s", intf));
rc = IPMI_CC_UNSPECIFIED_ERROR;
goto finish;
}
r = sd_bus_message_read(reply, "i", &pgood);
- if (r < 0) {
- log<level::ERR>("Failed to read sensor:",
- entry("ERRNO=0x%X", -r));
+ if (r < 0)
+ {
+ log<level::ERR>("Failed to read sensor:", entry("ERRNO=0x%X", -r));
rc = IPMI_CC_UNSPECIFIED_ERROR;
goto finish;
}
@@ -859,7 +864,8 @@ ipmi_ret_t ipmi_get_chassis_status(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
// 10b = chassis always powers up after AC/mains returns
// 11b = unknow
// Set to 00b, by observing the hardware behavior.
- // Do we need to define a dbus property to identify the restore policy?
+ // Do we need to define a dbus property to identify the restore
+ // policy?
// [4] power control fault
// 1b = controller attempted to turn system power on or off, but
@@ -882,7 +888,7 @@ ipmi_ret_t ipmi_get_chassis_status(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
// 1b = system power is on
// 0b = system power is off(soft-off S4/S5, or mechanical off)
- chassis_status.cur_power_state = ((s & 0x3)<<5) | (pgood & 0x1);
+ chassis_status.cur_power_state = ((s & 0x3) << 5) | (pgood & 0x1);
// Last Power Event
// [7..5] – reserved
@@ -901,7 +907,8 @@ ipmi_ret_t ipmi_get_chassis_status(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
// 0b = Chassis Identify command support unspecified via this command.
// (The Get Command Support command , if implemented, would still
// indicate support for the Chassis Identify command)
- // [5..4] – Chassis Identify State. Mandatory when bit[6] =1b, reserved (return
+ // [5..4] – Chassis Identify State. Mandatory when bit[6] =1b, reserved
+ // (return
// as 00b) otherwise. Returns the present chassis identify state.
// Refer to the Chassis Identify command for more info.
// 00b = chassis identify state = Off
@@ -935,13 +942,13 @@ finish:
//-------------------------------------------------------------
int stop_soft_off_timer()
{
- constexpr auto iface = "org.freedesktop.DBus.Properties";
- constexpr auto soft_off_iface = "xyz.openbmc_project.Ipmi.Internal."
- "SoftPowerOff";
+ constexpr auto iface = "org.freedesktop.DBus.Properties";
+ constexpr auto soft_off_iface = "xyz.openbmc_project.Ipmi.Internal."
+ "SoftPowerOff";
- constexpr auto property = "ResponseReceived";
- constexpr auto value = "xyz.openbmc_project.Ipmi.Internal."
- "SoftPowerOff.HostResponse.HostShutdown";
+ constexpr auto property = "ResponseReceived";
+ constexpr auto value = "xyz.openbmc_project.Ipmi.Internal."
+ "SoftPowerOff.HostResponse.HostShutdown";
// Get the system bus where most system services are provided.
auto bus = ipmid_get_sd_bus_connection();
@@ -953,9 +960,9 @@ int stop_soft_off_timer()
// for now the code will directly call the soft off interface due to a
// race condition with mapper usage
//
- //char *busname = nullptr;
- //auto r = mapper_get_service(bus, SOFTOFF_OBJPATH, &busname);
- //if (r < 0)
+ // char *busname = nullptr;
+ // auto r = mapper_get_service(bus, SOFTOFF_OBJPATH, &busname);
+ // if (r < 0)
//{
// fprintf(stderr, "Failed to get %s bus name: %s\n",
// SOFTOFF_OBJPATH, -r);
@@ -964,16 +971,16 @@ int stop_soft_off_timer()
// No error object or reply expected.
int rc = sd_bus_call_method(bus, SOFTOFF_BUSNAME, SOFTOFF_OBJPATH, iface,
- "Set", nullptr, nullptr, "ssv",
- soft_off_iface, property, "s", value);
+ "Set", nullptr, nullptr, "ssv", soft_off_iface,
+ property, "s", value);
if (rc < 0)
{
log<level::ERR>("Failed to set property in SoftPowerOff object",
entry("ERRNO=0x%X", -rc));
}
- //TODO openbmc/openbmc#1661 - Mapper refactor
- //free(busname);
+ // TODO openbmc/openbmc#1661 - Mapper refactor
+ // free(busname);
return rc;
}
@@ -990,10 +997,10 @@ void indicate_no_softoff_needed()
// Add the host instance (default 0 for now) to the file name
std::string file{HOST_INBAND_REQUEST_FILE};
- auto size = std::snprintf(nullptr,0,file.c_str(),0);
+ auto size = std::snprintf(nullptr, 0, file.c_str(), 0);
size++; // null
std::unique_ptr<char[]> buf(new char[size]);
- std::snprintf(buf.get(),size,file.c_str(),0);
+ std::snprintf(buf.get(), size, file.c_str(), 0);
// Append file name to directory and create it
path /= buf.get();
@@ -1016,9 +1023,9 @@ ipmi_ret_t ipmi_chassis_control(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
*data_len = 0;
// Catch the actual operaton by peeking into request buffer
- uint8_t chassis_ctrl_cmd = *(uint8_t *)request;
+ uint8_t chassis_ctrl_cmd = *(uint8_t*)request;
- switch(chassis_ctrl_cmd)
+ switch (chassis_ctrl_cmd)
{
case CMD_POWER_ON:
rc = initiate_state_transition(State::Host::Transition::On);
@@ -1086,7 +1093,7 @@ ipmi_ret_t ipmi_chassis_control(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
}
}
- return ( (rc < 0) ? IPMI_CC_INVALID : IPMI_CC_OK);
+ return ((rc < 0) ? IPMI_CC_INVALID : IPMI_CC_OK);
}
/** @brief Return D-Bus connection string to enclosure identify LED object
@@ -1098,16 +1105,12 @@ std::string getEnclosureIdentifyConnection()
{
// lookup enclosure_identify group owner(s) in mapper
auto mapperCall = chassis::internal::dbus.new_method_call(
- ipmi::MAPPER_BUS_NAME,
- ipmi::MAPPER_OBJ,
- ipmi::MAPPER_INTF,
- "GetObject");
+ ipmi::MAPPER_BUS_NAME, ipmi::MAPPER_OBJ, ipmi::MAPPER_INTF,
+ "GetObject");
mapperCall.append(identify_led_object_name);
- static const std::vector<std::string> interfaces =
- {
- "xyz.openbmc_project.Led.Group"
- };
+ static const std::vector<std::string> interfaces = {
+ "xyz.openbmc_project.Led.Group"};
mapperCall.append(interfaces);
auto mapperReply = chassis::internal::dbus.call(mapperCall);
if (mapperReply.is_method_error())
@@ -1120,8 +1123,9 @@ std::string getEnclosureIdentifyConnection()
if (mapperResp.size() != encIdentifyObjectsSize)
{
- log<level::ERR>("Invalid number of enclosure identify objects.",
- entry("ENC_IDENTITY_OBJECTS_SIZE=%d", mapperResp.size()));
+ log<level::ERR>(
+ "Invalid number of enclosure identify objects.",
+ entry("ENC_IDENTITY_OBJECTS_SIZE=%d", mapperResp.size()));
elog<InternalFailure>();
}
auto pair = mapperResp[encIdentifyObjectsSize - 1];
@@ -1137,15 +1141,16 @@ void enclosureIdentifyLed(bool flag)
{
using namespace chassis::internal;
std::string connection = std::move(getEnclosureIdentifyConnection());
- auto led = dbus.new_method_call(connection.c_str(),
- identify_led_object_name, "org.freedesktop.DBus.Properties", "Set");
+ auto led =
+ dbus.new_method_call(connection.c_str(), identify_led_object_name,
+ "org.freedesktop.DBus.Properties", "Set");
led.append("xyz.openbmc_project.Led.Group", "Asserted",
- sdbusplus::message::variant<bool>(flag));
+ sdbusplus::message::variant<bool>(flag));
auto ledReply = dbus.call(led);
if (ledReply.is_method_error())
{
log<level::ERR>("Chassis Identify: Error Setting State On/Off\n",
- entry("LED_STATE=%d", flag));
+ entry("LED_STATE=%d", flag));
elog<InternalFailure>();
}
}
@@ -1185,11 +1190,14 @@ ipmi_ret_t ipmi_chassis_identify(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
{
return IPMI_CC_REQ_DATA_LEN_INVALID;
}
- uint8_t identifyInterval = *data_len > identifyIntervalPos ?
- (static_cast<uint8_t*>(request))[identifyIntervalPos] :
- DEFAULT_IDENTIFY_TIME_OUT;
- bool forceIdentify = (*data_len == chassisIdentifyReqLength) ?
- (static_cast<uint8_t*>(request))[forceIdentifyPos] & 0x01 : false;
+ uint8_t identifyInterval =
+ *data_len > identifyIntervalPos
+ ? (static_cast<uint8_t*>(request))[identifyIntervalPos]
+ : DEFAULT_IDENTIFY_TIME_OUT;
+ bool forceIdentify =
+ (*data_len == chassisIdentifyReqLength)
+ ? (static_cast<uint8_t*>(request))[forceIdentifyPos] & 0x01
+ : false;
if (identifyInterval || forceIdentify)
{
@@ -1212,7 +1220,7 @@ ipmi_ret_t ipmi_chassis_identify(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
}
// start the timer
auto time = std::chrono::duration_cast<std::chrono::microseconds>(
- std::chrono::seconds(identifyInterval));
+ std::chrono::seconds(identifyInterval));
identifyTimer->startTimer(time);
}
else if (!identifyInterval)
@@ -1230,39 +1238,30 @@ using namespace sdbusplus::xyz::openbmc_project::Control::Boot::server;
using IpmiValue = uint8_t;
constexpr auto ipmiDefault = 0;
-std::map<IpmiValue, Source::Sources> sourceIpmiToDbus =
-{
+std::map<IpmiValue, Source::Sources> sourceIpmiToDbus = {
{0x01, Source::Sources::Network},
{0x02, Source::Sources::Disk},
{0x05, Source::Sources::ExternalMedia},
- {ipmiDefault, Source::Sources::Default}
-};
+ {ipmiDefault, Source::Sources::Default}};
-std::map<IpmiValue, Mode::Modes> modeIpmiToDbus =
-{
+std::map<IpmiValue, Mode::Modes> modeIpmiToDbus = {
{0x03, Mode::Modes::Safe},
{0x06, Mode::Modes::Setup},
- {ipmiDefault, Mode::Modes::Regular}
-};
+ {ipmiDefault, Mode::Modes::Regular}};
-std::map<Source::Sources, IpmiValue> sourceDbusToIpmi =
-{
+std::map<Source::Sources, IpmiValue> sourceDbusToIpmi = {
{Source::Sources::Network, 0x01},
{Source::Sources::Disk, 0x02},
{Source::Sources::ExternalMedia, 0x05},
- {Source::Sources::Default, ipmiDefault}
-};
+ {Source::Sources::Default, ipmiDefault}};
-std::map<Mode::Modes, IpmiValue> modeDbusToIpmi =
-{
+std::map<Mode::Modes, IpmiValue> modeDbusToIpmi = {
{Mode::Modes::Safe, 0x03},
{Mode::Modes::Setup, 0x06},
- {Mode::Modes::Regular, ipmiDefault}
-};
+ {Mode::Modes::Regular, ipmiDefault}};
} // namespace boot_options
-
/** @brief Set the property value for boot source
* @param[in] source - boot source value
* @return On failure return IPMI error.
@@ -1275,10 +1274,9 @@ static ipmi_ret_t setBootSource(const Source::Sources& source)
convertForMessage(source);
auto bootSetting = settings::boot::setting(objects, bootSourceIntf);
const auto& bootSourceSetting = std::get<settings::Path>(bootSetting);
- auto method =
- dbus.new_method_call(
- objects.service(bootSourceSetting, bootSourceIntf).c_str(),
- bootSourceSetting.c_str(), ipmi::PROP_INTF, "Set");
+ auto method = dbus.new_method_call(
+ objects.service(bootSourceSetting, bootSourceIntf).c_str(),
+ bootSourceSetting.c_str(), ipmi::PROP_INTF, "Set");
method.append(bootSourceIntf, "BootSource", property);
auto reply = dbus.call(method);
if (reply.is_method_error())
@@ -1290,7 +1288,7 @@ static ipmi_ret_t setBootSource(const Source::Sources& source)
return IPMI_CC_OK;
}
- /** @brief Set the property value for boot mode
+/** @brief Set the property value for boot mode
* @param[in] mode - boot mode value
* @return On failure return IPMI error.
*/
@@ -1298,14 +1296,12 @@ static ipmi_ret_t setBootMode(const Mode::Modes& mode)
{
using namespace chassis::internal;
using namespace chassis::internal::cache;
- sdbusplus::message::variant<std::string> property =
- convertForMessage(mode);
+ sdbusplus::message::variant<std::string> property = convertForMessage(mode);
auto bootSetting = settings::boot::setting(objects, bootModeIntf);
const auto& bootModeSetting = std::get<settings::Path>(bootSetting);
- auto method =
- dbus.new_method_call(
- objects.service(bootModeSetting, bootModeIntf).c_str(),
- bootModeSetting.c_str(), ipmi::PROP_INTF, "Set");
+ auto method = dbus.new_method_call(
+ objects.service(bootModeSetting, bootModeIntf).c_str(),
+ bootModeSetting.c_str(), ipmi::PROP_INTF, "Set");
method.append(bootModeIntf, "BootMode", property);
auto reply = dbus.call(method);
if (reply.is_method_error())
@@ -1325,23 +1321,24 @@ ipmi_ret_t ipmi_chassis_get_sys_boot_options(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
{
using namespace boot_options;
ipmi_ret_t rc = IPMI_CC_PARM_NOT_SUPPORTED;
- char *p = NULL;
- get_sys_boot_options_response_t *resp = (get_sys_boot_options_response_t *) response;
- get_sys_boot_options_t *reqptr = (get_sys_boot_options_t*) request;
+ char* p = NULL;
+ get_sys_boot_options_response_t* resp =
+ (get_sys_boot_options_response_t*)response;
+ get_sys_boot_options_t* reqptr = (get_sys_boot_options_t*)request;
IpmiValue bootOption = ipmiDefault;
- memset(resp,0,sizeof(*resp));
- resp->version = SET_PARM_VERSION;
- resp->parm = 5;
- resp->data[0] = SET_PARM_BOOT_FLAGS_VALID_ONE_TIME;
-
+ memset(resp, 0, sizeof(*resp));
+ resp->version = SET_PARM_VERSION;
+ resp->parm = 5;
+ resp->data[0] = SET_PARM_BOOT_FLAGS_VALID_ONE_TIME;
/*
* Parameter #5 means boot flags. Please refer to 28.13 of ipmi doc.
* This is the only parameter used by petitboot.
*/
- if ( reqptr->parameter == static_cast<uint8_t>
- ( BootOptionParameter::BOOT_FLAGS )) {
+ if (reqptr->parameter ==
+ static_cast<uint8_t>(BootOptionParameter::BOOT_FLAGS))
+ {
*data_len = static_cast<uint8_t>(BootOptionResponseSize::BOOT_FLAGS);
using namespace chassis::internal;
@@ -1354,12 +1351,9 @@ ipmi_ret_t ipmi_chassis_get_sys_boot_options(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
std::get<settings::Path>(bootSetting);
auto oneTimeEnabled =
std::get<settings::boot::OneTimeEnabled>(bootSetting);
- auto method =
- dbus.new_method_call(
- objects.service(bootSourceSetting, bootSourceIntf).c_str(),
- bootSourceSetting.c_str(),
- ipmi::PROP_INTF,
- "Get");
+ auto method = dbus.new_method_call(
+ objects.service(bootSourceSetting, bootSourceIntf).c_str(),
+ bootSourceSetting.c_str(), ipmi::PROP_INTF, "Get");
method.append(bootSourceIntf, "BootSource");
auto reply = dbus.call(method);
if (reply.is_method_error())
@@ -1377,11 +1371,8 @@ ipmi_ret_t ipmi_chassis_get_sys_boot_options(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
bootSetting = settings::boot::setting(objects, bootModeIntf);
const auto& bootModeSetting = std::get<settings::Path>(bootSetting);
method = dbus.new_method_call(
- objects.service(bootModeSetting, bootModeIntf).
- c_str(),
- bootModeSetting.c_str(),
- ipmi::PROP_INTF,
- "Get");
+ objects.service(bootModeSetting, bootModeIntf).c_str(),
+ bootModeSetting.c_str(), ipmi::PROP_INTF, "Get");
method.append(bootModeIntf, "BootMode");
reply = dbus.call(method);
if (reply.is_method_error())
@@ -1407,9 +1398,9 @@ ipmi_ret_t ipmi_chassis_get_sys_boot_options(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
}
resp->data[1] = (bootOption << 2);
- resp->data[0] = oneTimeEnabled ?
- SET_PARM_BOOT_FLAGS_VALID_ONE_TIME:
- SET_PARM_BOOT_FLAGS_VALID_PERMANENT;
+ resp->data[0] = oneTimeEnabled
+ ? SET_PARM_BOOT_FLAGS_VALID_ONE_TIME
+ : SET_PARM_BOOT_FLAGS_VALID_PERMANENT;
rc = IPMI_CC_OK;
}
@@ -1419,28 +1410,34 @@ ipmi_ret_t ipmi_chassis_get_sys_boot_options(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
*data_len = 0;
return IPMI_CC_UNSPECIFIED_ERROR;
}
- } else if ( reqptr->parameter == static_cast<uint8_t>
- ( BootOptionParameter::OPAL_NETWORK_SETTINGS )) {
+ }
+ else if (reqptr->parameter ==
+ static_cast<uint8_t>(BootOptionParameter::OPAL_NETWORK_SETTINGS))
+ {
- *data_len = static_cast<uint8_t>(BootOptionResponseSize::OPAL_NETWORK_SETTINGS);
+ *data_len =
+ static_cast<uint8_t>(BootOptionResponseSize::OPAL_NETWORK_SETTINGS);
- resp->parm = static_cast<uint8_t>(BootOptionParameter::OPAL_NETWORK_SETTINGS);
+ resp->parm =
+ static_cast<uint8_t>(BootOptionParameter::OPAL_NETWORK_SETTINGS);
int ret = getHostNetworkData(resp);
- if (ret < 0) {
+ if (ret < 0)
+ {
log<level::ERR>(
- "getHostNetworkData failed for get_sys_boot_options.");
+ "getHostNetworkData failed for get_sys_boot_options.");
rc = IPMI_CC_UNSPECIFIED_ERROR;
-
- }else
+ }
+ else
rc = IPMI_CC_OK;
}
- else {
- log<level::ERR>("Unsupported parameter", entry(
- "PARAM=0x%x", reqptr->parameter));
+ else
+ {
+ log<level::ERR>("Unsupported parameter",
+ entry("PARAM=0x%x", reqptr->parameter));
}
if (p)
@@ -1454,8 +1451,6 @@ ipmi_ret_t ipmi_chassis_get_sys_boot_options(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
return rc;
}
-
-
ipmi_ret_t ipmi_chassis_set_sys_boot_options(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
ipmi_request_t request,
ipmi_response_t response,
@@ -1464,9 +1459,10 @@ ipmi_ret_t ipmi_chassis_set_sys_boot_options(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
{
using namespace boot_options;
ipmi_ret_t rc = IPMI_CC_OK;
- set_sys_boot_options_t *reqptr = (set_sys_boot_options_t *) request;
+ set_sys_boot_options_t* reqptr = (set_sys_boot_options_t*)request;
- printf("IPMI SET_SYS_BOOT_OPTIONS reqptr->parameter =[%d]\n",reqptr->parameter);
+ printf("IPMI SET_SYS_BOOT_OPTIONS reqptr->parameter =[%d]\n",
+ reqptr->parameter);
// This IPMI command does not have any resposne data
*data_len = 0;
@@ -1484,7 +1480,7 @@ ipmi_ret_t ipmi_chassis_set_sys_boot_options(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
auto oneTimeEnabled = false;
constexpr auto enabledIntf = "xyz.openbmc_project.Object.Enable";
constexpr auto oneTimePath =
- "/xyz/openbmc_project/control/host0/boot/one_time";
+ "/xyz/openbmc_project/control/host0/boot/one_time";
try
{
@@ -1492,8 +1488,7 @@ ipmi_ret_t ipmi_chassis_set_sys_boot_options(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
(reqptr->data[0] & SET_PARM_BOOT_FLAGS_PERMANENT) ==
SET_PARM_BOOT_FLAGS_PERMANENT;
- auto bootSetting =
- settings::boot::setting(objects, bootSourceIntf);
+ auto bootSetting = settings::boot::setting(objects, bootSourceIntf);
oneTimeEnabled =
std::get<settings::boot::OneTimeEnabled>(bootSetting);
@@ -1512,12 +1507,8 @@ ipmi_ret_t ipmi_chassis_set_sys_boot_options(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
{
auto service = ipmi::getService(dbus, enabledIntf, oneTimePath);
- ipmi::setDbusProperty(dbus,
- service,
- oneTimePath,
- enabledIntf,
- "Enabled",
- !permanent);
+ ipmi::setDbusProperty(dbus, service, oneTimePath, enabledIntf,
+ "Enabled", !permanent);
}
auto modeItr = modeIpmiToDbus.find(bootOption);
@@ -1534,7 +1525,7 @@ ipmi_ret_t ipmi_chassis_set_sys_boot_options(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
// the boot mode D-Bus property to default.
// This way the ipmid code can determine which property is not
// at the default value
- if(sourceItr->second != Source::Sources::Default)
+ if (sourceItr->second != Source::Sources::Default)
{
setBootMode(Mode::Modes::Regular);
}
@@ -1551,7 +1542,7 @@ ipmi_ret_t ipmi_chassis_set_sys_boot_options(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
// the boot source D-Bus property to default.
// This way the ipmid code can determine which property is not
// at the default value
- if(modeItr->second != Mode::Modes::Regular)
+ if (modeItr->second != Mode::Modes::Regular)
{
setBootSource(Source::Sources::Default);
}
@@ -1563,26 +1554,33 @@ ipmi_ret_t ipmi_chassis_set_sys_boot_options(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
*data_len = 0;
return IPMI_CC_UNSPECIFIED_ERROR;
}
- } else if (reqptr->parameter ==
- (uint8_t)BootOptionParameter::OPAL_NETWORK_SETTINGS) {
+ }
+ else if (reqptr->parameter ==
+ (uint8_t)BootOptionParameter::OPAL_NETWORK_SETTINGS)
+ {
int ret = setHostNetworkData(reqptr);
- if (ret < 0) {
+ if (ret < 0)
+ {
log<level::ERR>(
- "setHostNetworkData failed for set_sys_boot_options");
+ "setHostNetworkData failed for set_sys_boot_options");
rc = IPMI_CC_UNSPECIFIED_ERROR;
}
- } else if (reqptr->parameter ==
- static_cast<uint8_t>(BootOptionParameter::BOOT_INFO)) {
+ }
+ else if (reqptr->parameter ==
+ static_cast<uint8_t>(BootOptionParameter::BOOT_INFO))
+ {
// Handle parameter #4 and return command completed normally
// (IPMI_CC_OK). There is no implementation in OpenBMC for this
// parameter. This is added to support the ipmitool command `chassis
// bootdev` which sends set on parameter #4, before setting the boot
// flags.
rc = IPMI_CC_OK;
- } else {
- log<level::ERR>("Unsupported parameter", entry(
- "PARAM=0x%x", reqptr->parameter));
+ }
+ else
+ {
+ log<level::ERR>("Unsupported parameter",
+ entry("PARAM=0x%x", reqptr->parameter));
rc = IPMI_CC_PARM_NOT_SUPPORTED;
}
@@ -1623,24 +1621,25 @@ void register_netfn_chassis_functions()
createIdentifyTimer();
// <Wildcard Command>
- ipmi_register_callback(NETFUN_CHASSIS, IPMI_CMD_WILDCARD, NULL, ipmi_chassis_wildcard,
- PRIVILEGE_USER);
+ ipmi_register_callback(NETFUN_CHASSIS, IPMI_CMD_WILDCARD, NULL,
+ ipmi_chassis_wildcard, PRIVILEGE_USER);
// Get Chassis Capabilities
- ipmi_register_callback(NETFUN_CHASSIS, IPMI_CMD_GET_CHASSIS_CAP, NULL, ipmi_get_chassis_cap,
- PRIVILEGE_USER);
+ ipmi_register_callback(NETFUN_CHASSIS, IPMI_CMD_GET_CHASSIS_CAP, NULL,
+ ipmi_get_chassis_cap, PRIVILEGE_USER);
// <Get System Boot Options>
ipmi_register_callback(NETFUN_CHASSIS, IPMI_CMD_GET_SYS_BOOT_OPTIONS, NULL,
- ipmi_chassis_get_sys_boot_options, PRIVILEGE_OPERATOR);
+ ipmi_chassis_get_sys_boot_options,
+ PRIVILEGE_OPERATOR);
// <Get Chassis Status>
- ipmi_register_callback(NETFUN_CHASSIS, IPMI_CMD_CHASSIS_STATUS, NULL, ipmi_get_chassis_status,
- PRIVILEGE_USER);
+ ipmi_register_callback(NETFUN_CHASSIS, IPMI_CMD_CHASSIS_STATUS, NULL,
+ ipmi_get_chassis_status, PRIVILEGE_USER);
// <Chassis Control>
- ipmi_register_callback(NETFUN_CHASSIS, IPMI_CMD_CHASSIS_CONTROL, NULL, ipmi_chassis_control,
- PRIVILEGE_OPERATOR);
+ ipmi_register_callback(NETFUN_CHASSIS, IPMI_CMD_CHASSIS_CONTROL, NULL,
+ ipmi_chassis_control, PRIVILEGE_OPERATOR);
// <Chassis Identify>
ipmi_register_callback(NETFUN_CHASSIS, IPMI_CMD_CHASSIS_IDENTIFY, NULL,
@@ -1648,7 +1647,8 @@ void register_netfn_chassis_functions()
// <Set System Boot Options>
ipmi_register_callback(NETFUN_CHASSIS, IPMI_CMD_SET_SYS_BOOT_OPTIONS, NULL,
- ipmi_chassis_set_sys_boot_options, PRIVILEGE_OPERATOR);
+ ipmi_chassis_set_sys_boot_options,
+ PRIVILEGE_OPERATOR);
// <Get POH Counter>
ipmi_register_callback(NETFUN_CHASSIS, IPMI_CMD_GET_POH_COUNTER, NULL,
ipmiGetPOHCounter, PRIVILEGE_USER);
OpenPOWER on IntegriCloud