blob: 216af6aa6147b5f37b5be2a3d99a99ec748705eb [file] [log] [blame]
Patrick Venture46470a32018-09-07 19:26:25 -07001#include "config.h"
2
3#include "chassishandler.hpp"
Patrick Venture0b02be92018-08-31 11:55:55 -07004
Patrick Venture0b02be92018-08-31 11:55:55 -07005#include <arpa/inet.h>
6#include <endian.h>
7#include <limits.h>
8#include <mapper.h>
9#include <netinet/in.h>
Patrick Venture0b02be92018-08-31 11:55:55 -070010
Ratan Guptafd28dd72016-08-01 04:58:01 -050011#include <array>
Patrick Venture0b02be92018-08-31 11:55:55 -070012#include <chrono>
Patrick Ventureb51bf9c2018-09-10 15:53:14 -070013#include <cstring>
Vernon Mauerybdda8002019-02-26 10:18:51 -080014#include <filesystem>
Andrew Geisslera6e3a302017-05-31 19:34:00 -050015#include <fstream>
Tom Joseph5110c122018-03-23 17:55:40 +053016#include <future>
Vernon Mauerye08fbff2019-04-03 09:19:34 -070017#include <ipmid/api.hpp>
Vernon Mauery33250242019-03-12 16:49:26 -070018#include <ipmid/types.hpp>
Vernon Mauery6a98fe72019-03-11 15:57:48 -070019#include <ipmid/utils.hpp>
Patrick Venture3a5071a2018-09-12 13:27:42 -070020#include <map>
21#include <phosphor-logging/elog-errors.hpp>
22#include <phosphor-logging/log.hpp>
23#include <sdbusplus/bus.hpp>
William A. Kennington III4c008022018-10-12 17:18:14 -070024#include <sdbusplus/message/types.hpp>
Patrick Venture3a5071a2018-09-12 13:27:42 -070025#include <sdbusplus/server/object.hpp>
Vernon Mauery1181af72018-10-08 12:05:00 -070026#include <sdbusplus/timer.hpp>
Vernon Mauerye278ead2018-10-09 09:23:43 -070027#include <settings.hpp>
Patrick Venture0b02be92018-08-31 11:55:55 -070028#include <sstream>
Patrick Venture3a5071a2018-09-12 13:27:42 -070029#include <string>
30#include <xyz/openbmc_project/Common/error.hpp>
31#include <xyz/openbmc_project/Control/Boot/Mode/server.hpp>
32#include <xyz/openbmc_project/Control/Boot/Source/server.hpp>
33#include <xyz/openbmc_project/Control/Power/RestorePolicy/server.hpp>
34#include <xyz/openbmc_project/State/Host/server.hpp>
35#include <xyz/openbmc_project/State/PowerOnHours/server.hpp>
36
Patrick Venture0b02be92018-08-31 11:55:55 -070037// Defines
38#define SET_PARM_VERSION 0x01
Vernon Mauery1181af72018-10-08 12:05:00 -070039#define SET_PARM_BOOT_FLAGS_PERMANENT 0x40
40#define SET_PARM_BOOT_FLAGS_VALID_ONE_TIME 0x80
41#define SET_PARM_BOOT_FLAGS_VALID_PERMANENT 0xC0
ratagupta6f6bff2016-04-04 06:20:11 -050042
Lei YU4b0ddb62019-01-25 16:43:50 +080043std::unique_ptr<phosphor::Timer> identifyTimer
44 __attribute__((init_priority(101)));
Marri Devender Rao6706c1c2018-05-14 00:29:38 -050045
Yong Lif4e38512019-05-21 14:46:55 +080046static ChassisIDState chassisIDState = ChassisIDState::reserved;
47
Patrick Venture0b02be92018-08-31 11:55:55 -070048constexpr size_t SIZE_MAC = 18;
49constexpr size_t SIZE_BOOT_OPTION = (uint8_t)
50 BootOptionResponseSize::OPAL_NETWORK_SETTINGS; // Maximum size of the boot
51 // option parametrs
Ratan Guptafd28dd72016-08-01 04:58:01 -050052constexpr size_t SIZE_PREFIX = 7;
53constexpr size_t MAX_PREFIX_VALUE = 32;
54constexpr size_t SIZE_COOKIE = 4;
55constexpr size_t SIZE_VERSION = 2;
Tom Joseph5110c122018-03-23 17:55:40 +053056constexpr size_t DEFAULT_IDENTIFY_TIME_OUT = 15;
Ratan Gupta6ec7daa2017-07-15 14:13:01 +053057
Patrick Venture0b02be92018-08-31 11:55:55 -070058// PetiBoot-Specific
Ratan Gupta6ec7daa2017-07-15 14:13:01 +053059static constexpr uint8_t net_conf_initial_bytes[] = {0x80, 0x21, 0x70, 0x62,
Patrick Venture0b02be92018-08-31 11:55:55 -070060 0x21, 0x00, 0x01, 0x06};
Ratan Guptafd28dd72016-08-01 04:58:01 -050061
62static constexpr size_t COOKIE_OFFSET = 1;
63static constexpr size_t VERSION_OFFSET = 5;
Ratan Gupta6ec7daa2017-07-15 14:13:01 +053064static constexpr size_t ADDR_SIZE_OFFSET = 8;
Ratan Guptafd28dd72016-08-01 04:58:01 -050065static constexpr size_t MAC_OFFSET = 9;
66static constexpr size_t ADDRTYPE_OFFSET = 16;
67static constexpr size_t IPADDR_OFFSET = 17;
ratagupta6f6bff2016-04-04 06:20:11 -050068
Vijay Khemka074f64d2020-03-03 15:08:43 -080069static constexpr uint4_t RESERVED = 0;
70static constexpr uint8_t CHANNEL_NOT_SUPPORTED = 0;
71
Marri Devender Rao6706c1c2018-05-14 00:29:38 -050072static constexpr size_t encIdentifyObjectsSize = 1;
73static constexpr size_t chassisIdentifyReqLength = 2;
74static constexpr size_t identifyIntervalPos = 0;
75static constexpr size_t forceIdentifyPos = 1;
shgoupfd84fbbf2015-12-17 10:05:51 +080076
Adriana Kobylak40814c62015-10-27 15:58:44 -050077void register_netfn_chassis_functions() __attribute__((constructor));
78
shgoupfd84fbbf2015-12-17 10:05:51 +080079// Host settings in dbus
80// Service name should be referenced by connection name got via object mapper
Patrick Venture0b02be92018-08-31 11:55:55 -070081const char* settings_object_name = "/org/openbmc/settings/host0";
82const char* settings_intf_name = "org.freedesktop.DBus.Properties";
Patrick Venture0b02be92018-08-31 11:55:55 -070083const char* identify_led_object_name =
Tom Joseph5110c122018-03-23 17:55:40 +053084 "/xyz/openbmc_project/led/groups/enclosure_identify";
shgoupfd84fbbf2015-12-17 10:05:51 +080085
Ratan Guptadcb10672017-07-10 10:33:50 +053086constexpr auto SETTINGS_ROOT = "/";
87constexpr auto SETTINGS_MATCH = "host0";
Ratan Guptadcb10672017-07-10 10:33:50 +053088
89constexpr auto IP_INTERFACE = "xyz.openbmc_project.Network.IP";
90constexpr auto MAC_INTERFACE = "xyz.openbmc_project.Network.MACAddress";
91
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -050092static constexpr auto chassisStateRoot = "/xyz/openbmc_project/state";
93static constexpr auto chassisPOHStateIntf =
Patrick Venture0b02be92018-08-31 11:55:55 -070094 "xyz.openbmc_project.State.PowerOnHours";
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -050095static constexpr auto pOHCounterProperty = "POHCounter";
96static constexpr auto match = "chassis0";
Yong Liae4b0402018-11-02 11:12:14 +080097const static constexpr char chassisCapIntf[] =
98 "xyz.openbmc_project.Control.ChassisCapabilities";
Karthick Sundarrajan86d8bd72019-11-26 12:48:50 -080099const static constexpr char chassisIntrusionProp[] = "ChassisIntrusionEnabled";
100const static constexpr char chassisFrontPanelLockoutProp[] =
101 "ChassisFrontPanelLockoutEnabled";
102const static constexpr char chassisNMIProp[] = "ChassisNMIEnabled";
103const static constexpr char chassisPowerInterlockProp[] =
104 "ChassisPowerInterlockEnabled";
Yong Liae4b0402018-11-02 11:12:14 +0800105const static constexpr char chassisFRUDevAddrProp[] = "FRUDeviceAddress";
106const static constexpr char chassisSDRDevAddrProp[] = "SDRDeviceAddress";
107const static constexpr char chassisSELDevAddrProp[] = "SELDeviceAddress";
108const static constexpr char chassisSMDevAddrProp[] = "SMDeviceAddress";
109const static constexpr char chassisBridgeDevAddrProp[] = "BridgeDeviceAddress";
110static constexpr uint8_t chassisCapFlagMask = 0x0f;
111static constexpr uint8_t chassisCapAddrMask = 0xfe;
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700112static constexpr const char* powerButtonIntf =
113 "xyz.openbmc_project.Chassis.Buttons.Power";
114static constexpr const char* powerButtonPath =
115 "/xyz/openbmc_project/Chassis/Buttons/Power0";
116static constexpr const char* resetButtonIntf =
117 "xyz.openbmc_project.Chassis.Buttons.Reset";
118static constexpr const char* resetButtonPath =
119 "/xyz/openbmc_project/Chassis/Buttons/Reset0";
Ratan Guptadcb10672017-07-10 10:33:50 +0530120
Vishwanatha Subbannab12b0c02017-03-07 18:17:19 +0530121// Phosphor Host State manager
122namespace State = sdbusplus::xyz::openbmc_project::State::server;
123
Vernon Mauery185b9f82018-07-20 10:52:36 -0700124namespace fs = std::filesystem;
Andrew Geisslera6e3a302017-05-31 19:34:00 -0500125
Ratan Guptadcb10672017-07-10 10:33:50 +0530126using namespace phosphor::logging;
127using namespace sdbusplus::xyz::openbmc_project::Common::Error;
Marri Devender Rao81719702018-05-07 00:53:48 -0500128using namespace sdbusplus::xyz::openbmc_project::Control::Boot::server;
William A. Kennington III4c008022018-10-12 17:18:14 -0700129
Deepak Kodihalli8cc19362017-07-21 11:18:38 -0500130namespace chassis
131{
132namespace internal
133{
134
135constexpr auto bootModeIntf = "xyz.openbmc_project.Control.Boot.Mode";
136constexpr auto bootSourceIntf = "xyz.openbmc_project.Control.Boot.Source";
Deepak Kodihalli18b70d12017-07-21 13:36:33 -0500137constexpr auto powerRestoreIntf =
138 "xyz.openbmc_project.Control.Power.RestorePolicy";
Deepak Kodihalli8cc19362017-07-21 11:18:38 -0500139sdbusplus::bus::bus dbus(ipmid_get_sd_bus_connection());
140
141namespace cache
142{
143
James Feist225dec82019-11-26 16:25:06 -0800144std::unique_ptr<settings::Objects> objectsPtr = nullptr;
145
146settings::Objects& getObjects()
147{
148 if (objectsPtr == nullptr)
149 {
150 objectsPtr = std::make_unique<settings::Objects>(
151 dbus, std::vector<std::string>{bootModeIntf, bootSourceIntf,
152 powerRestoreIntf});
153 }
154 return *objectsPtr;
155}
Deepak Kodihalli8cc19362017-07-21 11:18:38 -0500156
157} // namespace cache
158} // namespace internal
159} // namespace chassis
160
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -0500161namespace poh
162{
163
164constexpr auto minutesPerCount = 60;
165
166} // namespace poh
167
Patrick Venture0b02be92018-08-31 11:55:55 -0700168struct get_sys_boot_options_t
169{
Adriana Kobylak40814c62015-10-27 15:58:44 -0500170 uint8_t parameter;
171 uint8_t set;
172 uint8_t block;
Patrick Venture0b02be92018-08-31 11:55:55 -0700173} __attribute__((packed));
Adriana Kobylak40814c62015-10-27 15:58:44 -0500174
Patrick Venture0b02be92018-08-31 11:55:55 -0700175struct get_sys_boot_options_response_t
176{
shgoupfd84fbbf2015-12-17 10:05:51 +0800177 uint8_t version;
178 uint8_t parm;
Ratan Guptafd28dd72016-08-01 04:58:01 -0500179 uint8_t data[SIZE_BOOT_OPTION];
Patrick Venture0b02be92018-08-31 11:55:55 -0700180} __attribute__((packed));
shgoupfd84fbbf2015-12-17 10:05:51 +0800181
Patrick Venture0b02be92018-08-31 11:55:55 -0700182struct set_sys_boot_options_t
183{
shgoupfd84fbbf2015-12-17 10:05:51 +0800184 uint8_t parameter;
Ratan Guptafd28dd72016-08-01 04:58:01 -0500185 uint8_t data[SIZE_BOOT_OPTION];
Patrick Venture0b02be92018-08-31 11:55:55 -0700186} __attribute__((packed));
Ratan Guptafd28dd72016-08-01 04:58:01 -0500187
Ratan Guptadcb10672017-07-10 10:33:50 +0530188int getHostNetworkData(get_sys_boot_options_response_t* respptr)
Ratan Guptafd28dd72016-08-01 04:58:01 -0500189{
Ratan Guptadcb10672017-07-10 10:33:50 +0530190 ipmi::PropertyMap properties;
191 int rc = 0;
Ratan Gupta8c31d232017-08-13 05:49:43 +0530192 uint8_t addrSize = ipmi::network::IPV4_ADDRESS_SIZE_BYTE;
Ratan Guptafd28dd72016-08-01 04:58:01 -0500193
Ratan Guptadcb10672017-07-10 10:33:50 +0530194 try
195 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700196 // TODO There may be cases where an interface is implemented by multiple
Ratan Guptadcb10672017-07-10 10:33:50 +0530197 // objects,to handle such cases we are interested on that object
198 // which are on interested busname.
199 // Currenlty mapper doesn't give the readable busname(gives busid)
200 // so we can't match with bus name so giving some object specific info
201 // as SETTINGS_MATCH.
202 // Later SETTINGS_MATCH will be replaced with busname.
Ratan Guptafd28dd72016-08-01 04:58:01 -0500203
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530204 sdbusplus::bus::bus bus(ipmid_get_sd_bus_connection());
Ratan Guptadcb10672017-07-10 10:33:50 +0530205
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530206 auto ipObjectInfo = ipmi::getDbusObject(bus, IP_INTERFACE,
207 SETTINGS_ROOT, SETTINGS_MATCH);
208
209 auto macObjectInfo = ipmi::getDbusObject(bus, MAC_INTERFACE,
210 SETTINGS_ROOT, SETTINGS_MATCH);
211
Patrick Venture0b02be92018-08-31 11:55:55 -0700212 properties = ipmi::getAllDbusProperties(
213 bus, ipObjectInfo.second, ipObjectInfo.first, IP_INTERFACE);
214 auto variant = ipmi::getDbusProperty(bus, macObjectInfo.second,
215 macObjectInfo.first, MAC_INTERFACE,
216 "MACAddress");
Ratan Guptadcb10672017-07-10 10:33:50 +0530217
Vernon Maueryf442e112019-04-09 11:44:36 -0700218 auto ipAddress = std::get<std::string>(properties["Address"]);
Ratan Guptad70f4532017-08-04 02:07:31 +0530219
Vernon Maueryf442e112019-04-09 11:44:36 -0700220 auto gateway = std::get<std::string>(properties["Gateway"]);
Ratan Guptad70f4532017-08-04 02:07:31 +0530221
Vernon Maueryf442e112019-04-09 11:44:36 -0700222 auto prefix = std::get<uint8_t>(properties["PrefixLength"]);
Ratan Guptad70f4532017-08-04 02:07:31 +0530223
Patrick Venture0b02be92018-08-31 11:55:55 -0700224 uint8_t isStatic =
Vernon Maueryf442e112019-04-09 11:44:36 -0700225 (std::get<std::string>(properties["Origin"]) ==
Patrick Venture0b02be92018-08-31 11:55:55 -0700226 "xyz.openbmc_project.Network.IP.AddressOrigin.Static")
227 ? 1
228 : 0;
Ratan Guptad70f4532017-08-04 02:07:31 +0530229
Vernon Maueryf442e112019-04-09 11:44:36 -0700230 auto MACAddress = std::get<std::string>(variant);
Ratan Guptacc8feb42017-07-25 21:52:10 +0530231
Ratan Guptad70f4532017-08-04 02:07:31 +0530232 // it is expected here that we should get the valid data
233 // but we may also get the default values.
234 // Validation of the data is done by settings.
235 //
236 // if mac address is default mac address then
237 // don't send blank override.
Ratan Gupta8c31d232017-08-13 05:49:43 +0530238 if ((MACAddress == ipmi::network::DEFAULT_MAC_ADDRESS))
Ratan Guptad70f4532017-08-04 02:07:31 +0530239 {
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700240 std::memset(respptr->data, 0, SIZE_BOOT_OPTION);
Ratan Guptad70f4532017-08-04 02:07:31 +0530241 rc = -1;
242 return rc;
243 }
244 // if addr is static then ipaddress,gateway,prefix
245 // should not be default one,don't send blank override.
246 if (isStatic)
247 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700248 if ((ipAddress == ipmi::network::DEFAULT_ADDRESS) ||
249 (gateway == ipmi::network::DEFAULT_ADDRESS) || (!prefix))
Ratan Guptad70f4532017-08-04 02:07:31 +0530250 {
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700251 std::memset(respptr->data, 0, SIZE_BOOT_OPTION);
Ratan Guptad70f4532017-08-04 02:07:31 +0530252 rc = -1;
253 return rc;
254 }
255 }
256
Patrick Venture0b02be92018-08-31 11:55:55 -0700257 sscanf(
258 MACAddress.c_str(), ipmi::network::MAC_ADDRESS_FORMAT,
259 (respptr->data + MAC_OFFSET), (respptr->data + MAC_OFFSET + 1),
260 (respptr->data + MAC_OFFSET + 2), (respptr->data + MAC_OFFSET + 3),
261 (respptr->data + MAC_OFFSET + 4), (respptr->data + MAC_OFFSET + 5));
Ratan Guptadcb10672017-07-10 10:33:50 +0530262
Ratan Guptadcb10672017-07-10 10:33:50 +0530263 respptr->data[MAC_OFFSET + 6] = 0x00;
264
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700265 std::memcpy(respptr->data + ADDRTYPE_OFFSET, &isStatic,
266 sizeof(isStatic));
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530267
Vernon Maueryf442e112019-04-09 11:44:36 -0700268 uint8_t addressFamily = (std::get<std::string>(properties["Type"]) ==
269 "xyz.openbmc_project.Network.IP.Protocol.IPv4")
270 ? AF_INET
271 : AF_INET6;
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530272
Patrick Venture0b02be92018-08-31 11:55:55 -0700273 addrSize = (addressFamily == AF_INET)
274 ? ipmi::network::IPV4_ADDRESS_SIZE_BYTE
275 : ipmi::network::IPV6_ADDRESS_SIZE_BYTE;
Ratan Guptadcb10672017-07-10 10:33:50 +0530276
277 // ipaddress and gateway would be in IPv4 format
Ratan Guptad70f4532017-08-04 02:07:31 +0530278 inet_pton(addressFamily, ipAddress.c_str(),
Patrick Venture0b02be92018-08-31 11:55:55 -0700279 (respptr->data + IPADDR_OFFSET));
Ratan Guptadcb10672017-07-10 10:33:50 +0530280
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530281 uint8_t prefixOffset = IPADDR_OFFSET + addrSize;
282
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700283 std::memcpy(respptr->data + prefixOffset, &prefix, sizeof(prefix));
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530284
285 uint8_t gatewayOffset = prefixOffset + sizeof(decltype(prefix));
286
Ratan Guptad70f4532017-08-04 02:07:31 +0530287 inet_pton(addressFamily, gateway.c_str(),
Patrick Venture0b02be92018-08-31 11:55:55 -0700288 (respptr->data + gatewayOffset));
Ratan Guptadcb10672017-07-10 10:33:50 +0530289 }
290 catch (InternalFailure& e)
291 {
292 commit<InternalFailure>();
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700293 std::memset(respptr->data, 0, SIZE_BOOT_OPTION);
Ratan Guptadcb10672017-07-10 10:33:50 +0530294 rc = -1;
Ratan Guptafd28dd72016-08-01 04:58:01 -0500295 return rc;
296 }
297
Patrick Venture0b02be92018-08-31 11:55:55 -0700298 // PetiBoot-Specific
299 // If success then copy the first 9 bytes to the data
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700300 std::memcpy(respptr->data, net_conf_initial_bytes,
301 sizeof(net_conf_initial_bytes));
Ratan Guptafd28dd72016-08-01 04:58:01 -0500302
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700303 std::memcpy(respptr->data + ADDR_SIZE_OFFSET, &addrSize, sizeof(addrSize));
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530304
Ratan Guptafd28dd72016-08-01 04:58:01 -0500305#ifdef _IPMI_DEBUG_
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700306 std::printf("\n===Printing the IPMI Formatted Data========\n");
Ratan Guptafd28dd72016-08-01 04:58:01 -0500307
Ratan Guptadcb10672017-07-10 10:33:50 +0530308 for (uint8_t pos = 0; pos < index; pos++)
309 {
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700310 std::printf("%02x ", respptr->data[pos]);
Ratan Guptadcb10672017-07-10 10:33:50 +0530311 }
Ratan Guptafd28dd72016-08-01 04:58:01 -0500312#endif
313
Ratan Guptafd28dd72016-08-01 04:58:01 -0500314 return rc;
315}
316
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530317/** @brief convert IPv4 and IPv6 addresses from binary to text form.
318 * @param[in] family - IPv4/Ipv6
319 * @param[in] data - req data pointer.
320 * @param[in] offset - offset in the data.
321 * @param[in] addrSize - size of the data which needs to be read from offset.
322 * @returns address in text form.
323 */
324
Patrick Venture0b02be92018-08-31 11:55:55 -0700325std::string getAddrStr(uint8_t family, uint8_t* data, uint8_t offset,
326 uint8_t addrSize)
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530327{
328 char ipAddr[INET6_ADDRSTRLEN] = {};
329
Patrick Venture0b02be92018-08-31 11:55:55 -0700330 switch (family)
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530331 {
332 case AF_INET:
333 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700334 struct sockaddr_in addr4
335 {
336 };
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700337 std::memcpy(&addr4.sin_addr.s_addr, &data[offset], addrSize);
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530338
Patrick Venture0b02be92018-08-31 11:55:55 -0700339 inet_ntop(AF_INET, &addr4.sin_addr, ipAddr, INET_ADDRSTRLEN);
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530340
341 break;
342 }
343 case AF_INET6:
344 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700345 struct sockaddr_in6 addr6
346 {
347 };
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700348 std::memcpy(&addr6.sin6_addr.s6_addr, &data[offset], addrSize);
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530349
Patrick Venture0b02be92018-08-31 11:55:55 -0700350 inet_ntop(AF_INET6, &addr6.sin6_addr, ipAddr, INET6_ADDRSTRLEN);
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530351
352 break;
353 }
354 default:
355 {
356 return {};
357 }
358 }
359
360 return ipAddr;
361}
362
Ratan Guptadcb10672017-07-10 10:33:50 +0530363int setHostNetworkData(set_sys_boot_options_t* reqptr)
Ratan Guptafd28dd72016-08-01 04:58:01 -0500364{
Ratan Guptadcb10672017-07-10 10:33:50 +0530365 using namespace std::string_literals;
Ratan Guptafd28dd72016-08-01 04:58:01 -0500366 std::string host_network_config;
Patrick Venture0b02be92018-08-31 11:55:55 -0700367 char mac[]{"00:00:00:00:00:00"};
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530368 std::string ipAddress, gateway;
Patrick Venture0b02be92018-08-31 11:55:55 -0700369 char addrOrigin{0};
370 uint8_t addrSize{0};
Ratan Guptadcb10672017-07-10 10:33:50 +0530371 std::string addressOrigin =
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530372 "xyz.openbmc_project.Network.IP.AddressOrigin.DHCP";
Patrick Venture0b02be92018-08-31 11:55:55 -0700373 std::string addressType = "xyz.openbmc_project.Network.IP.Protocol.IPv4";
374 uint8_t prefix{0};
Ratan Guptadcb10672017-07-10 10:33:50 +0530375 uint32_t zeroCookie = 0;
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530376 uint8_t family = AF_INET;
Ratan Guptafd28dd72016-08-01 04:58:01 -0500377
Patrick Venture0b02be92018-08-31 11:55:55 -0700378 // cookie starts from second byte
Ratan Guptafd28dd72016-08-01 04:58:01 -0500379 // version starts from sixth byte
380
Ratan Guptadcb10672017-07-10 10:33:50 +0530381 try
Ratan Guptafd28dd72016-08-01 04:58:01 -0500382 {
Ratan Guptadcb10672017-07-10 10:33:50 +0530383 do
384 {
385 // cookie == 0x21 0x70 0x62 0x21
386 if (memcmp(&(reqptr->data[COOKIE_OFFSET]),
Patrick Venture0b02be92018-08-31 11:55:55 -0700387 (net_conf_initial_bytes + COOKIE_OFFSET),
388 SIZE_COOKIE) != 0)
Ratan Guptadcb10672017-07-10 10:33:50 +0530389 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700390 // cookie == 0
391 if (memcmp(&(reqptr->data[COOKIE_OFFSET]), &zeroCookie,
392 SIZE_COOKIE) == 0)
Ratan Guptadcb10672017-07-10 10:33:50 +0530393 {
394 // need to zero out the network settings.
395 break;
396 }
397
398 log<level::ERR>("Invalid Cookie");
399 elog<InternalFailure>();
400 }
401
402 // vesion == 0x00 0x01
403 if (memcmp(&(reqptr->data[VERSION_OFFSET]),
Patrick Venture0b02be92018-08-31 11:55:55 -0700404 (net_conf_initial_bytes + VERSION_OFFSET),
405 SIZE_VERSION) != 0)
Ratan Guptadcb10672017-07-10 10:33:50 +0530406 {
407
408 log<level::ERR>("Invalid Version");
409 elog<InternalFailure>();
410 }
411
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700412 std::snprintf(
413 mac, SIZE_MAC, ipmi::network::MAC_ADDRESS_FORMAT,
414 reqptr->data[MAC_OFFSET], reqptr->data[MAC_OFFSET + 1],
415 reqptr->data[MAC_OFFSET + 2], reqptr->data[MAC_OFFSET + 3],
416 reqptr->data[MAC_OFFSET + 4], reqptr->data[MAC_OFFSET + 5]);
Ratan Guptadcb10672017-07-10 10:33:50 +0530417
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700418 std::memcpy(&addrOrigin, &(reqptr->data[ADDRTYPE_OFFSET]),
419 sizeof(decltype(addrOrigin)));
Ratan Guptadcb10672017-07-10 10:33:50 +0530420
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530421 if (addrOrigin)
Ratan Guptadcb10672017-07-10 10:33:50 +0530422 {
423 addressOrigin =
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530424 "xyz.openbmc_project.Network.IP.AddressOrigin.Static";
Ratan Guptadcb10672017-07-10 10:33:50 +0530425 }
426
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530427 // Get the address size
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700428 std::memcpy(&addrSize, &reqptr->data[ADDR_SIZE_OFFSET],
429 sizeof(addrSize));
Ratan Guptadcb10672017-07-10 10:33:50 +0530430
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530431 uint8_t prefixOffset = IPADDR_OFFSET + addrSize;
Ratan Guptadcb10672017-07-10 10:33:50 +0530432
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700433 std::memcpy(&prefix, &(reqptr->data[prefixOffset]),
434 sizeof(decltype(prefix)));
Ratan Guptadcb10672017-07-10 10:33:50 +0530435
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530436 uint8_t gatewayOffset = prefixOffset + sizeof(decltype(prefix));
437
Ratan Gupta8c31d232017-08-13 05:49:43 +0530438 if (addrSize != ipmi::network::IPV4_ADDRESS_SIZE_BYTE)
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530439 {
440 addressType = "xyz.openbmc_project.Network.IP.Protocol.IPv6";
441 family = AF_INET6;
442 }
443
Patrick Venture0b02be92018-08-31 11:55:55 -0700444 ipAddress =
445 getAddrStr(family, reqptr->data, IPADDR_OFFSET, addrSize);
Ratan Guptad70f4532017-08-04 02:07:31 +0530446
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530447 gateway = getAddrStr(family, reqptr->data, gatewayOffset, addrSize);
448
Patrick Venture0b02be92018-08-31 11:55:55 -0700449 } while (0);
Ratan Guptadcb10672017-07-10 10:33:50 +0530450
Patrick Venture0b02be92018-08-31 11:55:55 -0700451 // Cookie == 0 or it is a valid cookie
452 host_network_config += "ipaddress="s + ipAddress + ",prefix="s +
453 std::to_string(prefix) + ",gateway="s + gateway +
454 ",mac="s + mac + ",addressOrigin="s +
455 addressOrigin;
Ratan Guptafd28dd72016-08-01 04:58:01 -0500456
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530457 sdbusplus::bus::bus bus(ipmid_get_sd_bus_connection());
458
459 auto ipObjectInfo = ipmi::getDbusObject(bus, IP_INTERFACE,
460 SETTINGS_ROOT, SETTINGS_MATCH);
461 auto macObjectInfo = ipmi::getDbusObject(bus, MAC_INTERFACE,
462 SETTINGS_ROOT, SETTINGS_MATCH);
Ratan Guptadcb10672017-07-10 10:33:50 +0530463 // set the dbus property
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530464 ipmi::setDbusProperty(bus, ipObjectInfo.second, ipObjectInfo.first,
Patrick Venture0b02be92018-08-31 11:55:55 -0700465 IP_INTERFACE, "Address", std::string(ipAddress));
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530466 ipmi::setDbusProperty(bus, ipObjectInfo.second, ipObjectInfo.first,
Patrick Venture0b02be92018-08-31 11:55:55 -0700467 IP_INTERFACE, "PrefixLength", prefix);
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530468 ipmi::setDbusProperty(bus, ipObjectInfo.second, ipObjectInfo.first,
Patrick Venture0b02be92018-08-31 11:55:55 -0700469 IP_INTERFACE, "Origin", addressOrigin);
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530470 ipmi::setDbusProperty(bus, ipObjectInfo.second, ipObjectInfo.first,
Patrick Venture0b02be92018-08-31 11:55:55 -0700471 IP_INTERFACE, "Gateway", std::string(gateway));
472 ipmi::setDbusProperty(
473 bus, ipObjectInfo.second, ipObjectInfo.first, IP_INTERFACE, "Type",
474 std::string("xyz.openbmc_project.Network.IP.Protocol.IPv4"));
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530475 ipmi::setDbusProperty(bus, macObjectInfo.second, macObjectInfo.first,
Patrick Venture0b02be92018-08-31 11:55:55 -0700476 MAC_INTERFACE, "MACAddress", std::string(mac));
Ratan Guptafd28dd72016-08-01 04:58:01 -0500477
Patrick Venture0b02be92018-08-31 11:55:55 -0700478 log<level::DEBUG>(
479 "Network configuration changed",
480 entry("NETWORKCONFIG=%s", host_network_config.c_str()));
Ratan Guptafd28dd72016-08-01 04:58:01 -0500481 }
Ratan Guptadcb10672017-07-10 10:33:50 +0530482 catch (InternalFailure& e)
483 {
484 commit<InternalFailure>();
485 return -1;
486 }
487
488 return 0;
Ratan Guptafd28dd72016-08-01 04:58:01 -0500489}
490
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -0500491uint32_t getPOHCounter()
492{
493 sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
494
Patrick Venture0b02be92018-08-31 11:55:55 -0700495 auto chassisStateObj =
496 ipmi::getDbusObject(bus, chassisPOHStateIntf, chassisStateRoot, match);
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -0500497
Patrick Venture0b02be92018-08-31 11:55:55 -0700498 auto service =
499 ipmi::getService(bus, chassisPOHStateIntf, chassisStateObj.first);
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -0500500
Patrick Venture0b02be92018-08-31 11:55:55 -0700501 auto propValue =
502 ipmi::getDbusProperty(bus, service, chassisStateObj.first,
503 chassisPOHStateIntf, pOHCounterProperty);
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -0500504
Vernon Maueryf442e112019-04-09 11:44:36 -0700505 return std::get<uint32_t>(propValue);
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -0500506}
507
anil kumar appana43263c62019-05-27 12:45:04 +0000508/** @brief Implements the get chassis capabilities command
509 *
510 * @returns IPMI completion code plus response data
511 * chassisCapFlags - chassis capability flag
512 * chassisFRUInfoDevAddr - chassis FRU info Device Address
513 * chassisSDRDevAddr - chassis SDR device address
514 * chassisSELDevAddr - chassis SEL device address
515 * chassisSMDevAddr - chassis system management device address
516 * chassisBridgeDevAddr - chassis bridge device address
517 */
Karthick Sundarrajan86d8bd72019-11-26 12:48:50 -0800518ipmi::RspType<bool, // chassis intrusion sensor
519 bool, // chassis Front panel lockout
520 bool, // chassis NMI
521 bool, // chassis power interlock
522 uint4_t, // reserved
anil kumar appana43263c62019-05-27 12:45:04 +0000523 uint8_t, // chassis FRU info Device Address
524 uint8_t, // chassis SDR device address
525 uint8_t, // chassis SEL device address
526 uint8_t, // chassis system management device address
527 uint8_t // chassis bridge device address
528 >
529 ipmiGetChassisCap()
Nan Li8d15fb42016-08-16 22:29:40 +0800530{
anil kumar appana43263c62019-05-27 12:45:04 +0000531 ipmi::PropertyMap properties;
Yong Liae4b0402018-11-02 11:12:14 +0800532 try
533 {
534 sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
Nan Li8d15fb42016-08-16 22:29:40 +0800535
Yong Liae4b0402018-11-02 11:12:14 +0800536 ipmi::DbusObjectInfo chassisCapObject =
537 ipmi::getDbusObject(bus, chassisCapIntf);
Nan Li8d15fb42016-08-16 22:29:40 +0800538
Yong Liae4b0402018-11-02 11:12:14 +0800539 // capabilities flags
540 // [7..4] - reserved
541 // [3] – 1b = provides power interlock (IPM 1.5)
542 // [2] – 1b = provides Diagnostic Interrupt (FP NMI)
543 // [1] – 1b = provides “Front Panel Lockout” (indicates that the chassis
544 // has capabilities
545 // to lock out external power control and reset button or
546 // front panel interfaces and/or detect tampering with those
547 // interfaces).
548 // [0] -1b = Chassis provides intrusion (physical security) sensor.
549 // set to default value 0x0.
Nan Li8d15fb42016-08-16 22:29:40 +0800550
anil kumar appana43263c62019-05-27 12:45:04 +0000551 properties =
552 ipmi::getAllDbusProperties(bus, chassisCapObject.second,
553 chassisCapObject.first, chassisCapIntf);
Yong Liae4b0402018-11-02 11:12:14 +0800554 }
555 catch (std::exception& e)
556 {
anil kumar appana43263c62019-05-27 12:45:04 +0000557 log<level::ERR>("Failed to fetch Chassis Capability properties",
558 entry("ERROR=%s", e.what()));
559 return ipmi::responseUnspecifiedError();
Yong Liae4b0402018-11-02 11:12:14 +0800560 }
561
Karthick Sundarrajan86d8bd72019-11-26 12:48:50 -0800562 bool* chassisIntrusionFlag =
563 std::get_if<bool>(&properties[chassisIntrusionProp]);
564 if (chassisIntrusionFlag == nullptr)
anil kumar appana43263c62019-05-27 12:45:04 +0000565 {
Karthick Sundarrajan86d8bd72019-11-26 12:48:50 -0800566 log<level::ERR>("Error to get chassis Intrusion flags");
567 return ipmi::responseUnspecifiedError();
568 }
569 bool* chassisFrontPanelFlag =
570 std::get_if<bool>(&properties[chassisFrontPanelLockoutProp]);
571 if (chassisFrontPanelFlag == nullptr)
572 {
573 log<level::ERR>("Error to get chassis intrusion flags");
574 return ipmi::responseUnspecifiedError();
575 }
576 bool* chassisNMIFlag = std::get_if<bool>(&properties[chassisNMIProp]);
577 if (chassisNMIFlag == nullptr)
578 {
579 log<level::ERR>("Error to get chassis NMI flags");
580 return ipmi::responseUnspecifiedError();
581 }
582 bool* chassisPowerInterlockFlag =
583 std::get_if<bool>(&properties[chassisPowerInterlockProp]);
584 if (chassisPowerInterlockFlag == nullptr)
585 {
586 log<level::ERR>("Error to get chassis power interlock flags");
anil kumar appana43263c62019-05-27 12:45:04 +0000587 return ipmi::responseUnspecifiedError();
588 }
589 uint8_t* chassisFRUInfoDevAddr =
590 std::get_if<uint8_t>(&properties[chassisFRUDevAddrProp]);
591 if (chassisFRUInfoDevAddr == nullptr)
592 {
593 log<level::ERR>("Error to get chassis FRU info device address");
594 return ipmi::responseUnspecifiedError();
595 }
596 uint8_t* chassisSDRDevAddr =
597 std::get_if<uint8_t>(&properties[chassisSDRDevAddrProp]);
598 if (chassisSDRDevAddr == nullptr)
599 {
600 log<level::ERR>("Error to get chassis SDR device address");
601 return ipmi::responseUnspecifiedError();
602 }
603 uint8_t* chassisSELDevAddr =
604 std::get_if<uint8_t>(&properties[chassisSELDevAddrProp]);
605 if (chassisSELDevAddr == nullptr)
606 {
607 log<level::ERR>("Error to get chassis SEL device address");
608 return ipmi::responseUnspecifiedError();
609 }
610 uint8_t* chassisSMDevAddr =
611 std::get_if<uint8_t>(&properties[chassisSMDevAddrProp]);
612 if (chassisSMDevAddr == nullptr)
613 {
614 log<level::ERR>("Error to get chassis SM device address");
615 return ipmi::responseUnspecifiedError();
616 }
617 uint8_t* chassisBridgeDevAddr =
618 std::get_if<uint8_t>(&properties[chassisBridgeDevAddrProp]);
619 if (chassisBridgeDevAddr == nullptr)
620 {
621 log<level::ERR>("Error to get chassis bridge device address");
622 return ipmi::responseUnspecifiedError();
623 }
624
Karthick Sundarrajan86d8bd72019-11-26 12:48:50 -0800625 return ipmi::responseSuccess(*chassisIntrusionFlag, *chassisFrontPanelFlag,
626 *chassisNMIFlag, *chassisPowerInterlockFlag, 0,
627 *chassisFRUInfoDevAddr, *chassisSDRDevAddr,
628 *chassisSELDevAddr, *chassisSMDevAddr,
629 *chassisBridgeDevAddr);
Yong Liae4b0402018-11-02 11:12:14 +0800630}
631
anil kumar appana894d0222019-05-27 16:32:14 +0000632/** @brief implements set chassis capalibities command
633 * @param intrusion - chassis intrusion
634 * @param fpLockout - frontpannel lockout
635 * @param reserved1 - skip one bit
636 * @param fruDeviceAddr - chassis FRU info Device Address
637 * @param sdrDeviceAddr - chassis SDR device address
638 * @param selDeviceAddr - chassis SEL device address
639 * @param smDeviceAddr - chassis system management device address
640 * @param bridgeDeviceAddr - chassis bridge device address
641 *
642 * @returns IPMI completion code
643 */
644ipmi::RspType<> ipmiSetChassisCap(bool intrusion, bool fpLockout,
645 uint6_t reserved1,
646
647 uint8_t fruDeviceAddr,
648
649 uint8_t sdrDeviceAddr,
650
651 uint8_t selDeviceAddr,
652
653 uint8_t smDeviceAddr,
654
655 uint8_t bridgeDeviceAddr)
Yong Liae4b0402018-11-02 11:12:14 +0800656{
Yong Liae4b0402018-11-02 11:12:14 +0800657
658 // check input data
anil kumar appana894d0222019-05-27 16:32:14 +0000659 if (reserved1 != 0)
Yong Liae4b0402018-11-02 11:12:14 +0800660 {
anil kumar appana894d0222019-05-27 16:32:14 +0000661 log<level::ERR>("Unsupported request parameter");
662 return ipmi::responseInvalidFieldRequest();
Yong Liae4b0402018-11-02 11:12:14 +0800663 }
664
anil kumar appana894d0222019-05-27 16:32:14 +0000665 if ((fruDeviceAddr & ~chassisCapAddrMask) != 0)
Yong Liae4b0402018-11-02 11:12:14 +0800666 {
667 log<level::ERR>("Unsupported request parameter(FRU Addr)",
anil kumar appana894d0222019-05-27 16:32:14 +0000668 entry("REQ=0x%x", fruDeviceAddr));
669 return ipmi::responseInvalidFieldRequest();
Yong Liae4b0402018-11-02 11:12:14 +0800670 }
anil kumar appana894d0222019-05-27 16:32:14 +0000671 if ((sdrDeviceAddr & ~chassisCapAddrMask) != 0)
Yong Liae4b0402018-11-02 11:12:14 +0800672 {
673 log<level::ERR>("Unsupported request parameter(SDR Addr)",
anil kumar appana894d0222019-05-27 16:32:14 +0000674 entry("REQ=0x%x", sdrDeviceAddr));
675 return ipmi::responseInvalidFieldRequest();
Yong Liae4b0402018-11-02 11:12:14 +0800676 }
677
anil kumar appana894d0222019-05-27 16:32:14 +0000678 if ((selDeviceAddr & ~chassisCapAddrMask) != 0)
Yong Liae4b0402018-11-02 11:12:14 +0800679 {
680 log<level::ERR>("Unsupported request parameter(SEL Addr)",
anil kumar appana894d0222019-05-27 16:32:14 +0000681 entry("REQ=0x%x", selDeviceAddr));
682 return ipmi::responseInvalidFieldRequest();
Yong Liae4b0402018-11-02 11:12:14 +0800683 }
684
anil kumar appana894d0222019-05-27 16:32:14 +0000685 if ((smDeviceAddr & ~chassisCapAddrMask) != 0)
Yong Liae4b0402018-11-02 11:12:14 +0800686 {
anil kumar appana894d0222019-05-27 16:32:14 +0000687 log<level::ERR>("Unsupported request parameter(SM Addr)",
688 entry("REQ=0x%x", smDeviceAddr));
689 return ipmi::responseInvalidFieldRequest();
Yong Liae4b0402018-11-02 11:12:14 +0800690 }
691
anil kumar appana894d0222019-05-27 16:32:14 +0000692 if ((bridgeDeviceAddr & ~chassisCapAddrMask) != 0)
Yong Liae4b0402018-11-02 11:12:14 +0800693 {
694 log<level::ERR>("Unsupported request parameter(Bridge Addr)",
anil kumar appana894d0222019-05-27 16:32:14 +0000695 entry("REQ=0x%x", bridgeDeviceAddr));
696 return ipmi::responseInvalidFieldRequest();
Yong Liae4b0402018-11-02 11:12:14 +0800697 }
698
699 try
700 {
701 sdbusplus::bus::bus bus(ipmid_get_sd_bus_connection());
702 ipmi::DbusObjectInfo chassisCapObject =
703 ipmi::getDbusObject(bus, chassisCapIntf);
704
705 ipmi::setDbusProperty(bus, chassisCapObject.second,
706 chassisCapObject.first, chassisCapIntf,
Karthick Sundarrajan86d8bd72019-11-26 12:48:50 -0800707 chassisIntrusionProp, intrusion);
708
709 ipmi::setDbusProperty(bus, chassisCapObject.second,
710 chassisCapObject.first, chassisCapIntf,
711 chassisFrontPanelLockoutProp, fpLockout);
Yong Liae4b0402018-11-02 11:12:14 +0800712
713 ipmi::setDbusProperty(bus, chassisCapObject.second,
714 chassisCapObject.first, chassisCapIntf,
anil kumar appana894d0222019-05-27 16:32:14 +0000715 chassisFRUDevAddrProp, fruDeviceAddr);
Yong Liae4b0402018-11-02 11:12:14 +0800716
717 ipmi::setDbusProperty(bus, chassisCapObject.second,
718 chassisCapObject.first, chassisCapIntf,
anil kumar appana894d0222019-05-27 16:32:14 +0000719 chassisSDRDevAddrProp, sdrDeviceAddr);
Yong Liae4b0402018-11-02 11:12:14 +0800720
721 ipmi::setDbusProperty(bus, chassisCapObject.second,
722 chassisCapObject.first, chassisCapIntf,
anil kumar appana894d0222019-05-27 16:32:14 +0000723 chassisSELDevAddrProp, selDeviceAddr);
Yong Liae4b0402018-11-02 11:12:14 +0800724
725 ipmi::setDbusProperty(bus, chassisCapObject.second,
726 chassisCapObject.first, chassisCapIntf,
anil kumar appana894d0222019-05-27 16:32:14 +0000727 chassisSMDevAddrProp, smDeviceAddr);
Yong Liae4b0402018-11-02 11:12:14 +0800728
729 ipmi::setDbusProperty(bus, chassisCapObject.second,
730 chassisCapObject.first, chassisCapIntf,
anil kumar appana894d0222019-05-27 16:32:14 +0000731 chassisBridgeDevAddrProp, bridgeDeviceAddr);
Yong Liae4b0402018-11-02 11:12:14 +0800732 }
733 catch (std::exception& e)
734 {
735 log<level::ERR>(e.what());
anil kumar appana894d0222019-05-27 16:32:14 +0000736 return ipmi::responseUnspecifiedError();
Yong Liae4b0402018-11-02 11:12:14 +0800737 }
anil kumar appana894d0222019-05-27 16:32:14 +0000738 return ipmi::responseSuccess();
Nan Li8d15fb42016-08-16 22:29:40 +0800739}
740
Vishwanatha Subbannab12b0c02017-03-07 18:17:19 +0530741//------------------------------------------
742// Calls into Host State Manager Dbus object
743//------------------------------------------
744int initiate_state_transition(State::Host::Transition transition)
vishwa36993272015-11-20 12:43:49 -0600745{
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500746 // OpenBMC Host State Manager dbus framework
Patrick Venture0b02be92018-08-31 11:55:55 -0700747 constexpr auto HOST_STATE_MANAGER_ROOT = "/xyz/openbmc_project/state/host0";
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500748 constexpr auto HOST_STATE_MANAGER_IFACE = "xyz.openbmc_project.State.Host";
Patrick Venture0b02be92018-08-31 11:55:55 -0700749 constexpr auto DBUS_PROPERTY_IFACE = "org.freedesktop.DBus.Properties";
750 constexpr auto PROPERTY = "RequestedHostTransition";
Vishwanatha Subbannab12b0c02017-03-07 18:17:19 +0530751
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500752 // sd_bus error
753 int rc = 0;
Patrick Venture0b02be92018-08-31 11:55:55 -0700754 char* busname = NULL;
vishwa36993272015-11-20 12:43:49 -0600755
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500756 // SD Bus error report mechanism.
757 sd_bus_error bus_error = SD_BUS_ERROR_NULL;
vishwa36993272015-11-20 12:43:49 -0600758
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500759 // Gets a hook onto either a SYSTEM or SESSION bus
Patrick Venture0b02be92018-08-31 11:55:55 -0700760 sd_bus* bus_type = ipmid_get_sd_bus_connection();
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500761 rc = mapper_get_service(bus_type, HOST_STATE_MANAGER_ROOT, &busname);
762 if (rc < 0)
763 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700764 log<level::ERR>(
765 "Failed to get bus name",
766 entry("ERRNO=0x%X, OBJPATH=%s", -rc, HOST_STATE_MANAGER_ROOT));
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500767 return rc;
768 }
Vishwanatha Subbannab12b0c02017-03-07 18:17:19 +0530769
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500770 // Convert to string equivalent of the passed in transition enum.
771 auto request = State::convertForMessage(transition);
Vishwanatha Subbannab12b0c02017-03-07 18:17:19 +0530772
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500773 rc = sd_bus_call_method(bus_type, // On the system bus
774 busname, // Service to contact
775 HOST_STATE_MANAGER_ROOT, // Object path
776 DBUS_PROPERTY_IFACE, // Interface name
777 "Set", // Method to be called
778 &bus_error, // object to return error
779 nullptr, // Response buffer if any
780 "ssv", // Takes 3 arguments
Patrick Venture0b02be92018-08-31 11:55:55 -0700781 HOST_STATE_MANAGER_IFACE, PROPERTY, "s",
782 request.c_str());
783 if (rc < 0)
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500784 {
785 log<level::ERR>("Failed to initiate transition",
Aditya Saripalli5fb14602017-11-09 14:46:27 +0530786 entry("ERRNO=0x%X, REQUEST=%s", -rc, request.c_str()));
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500787 }
788 else
789 {
790 log<level::INFO>("Transition request initiated successfully");
791 }
vishwa36993272015-11-20 12:43:49 -0600792
793 sd_bus_error_free(&bus_error);
Sergey Solomineb9b8142016-08-23 09:07:28 -0500794 free(busname);
vishwa36993272015-11-20 12:43:49 -0600795
Sergey Solomineb9b8142016-08-23 09:07:28 -0500796 return rc;
vishwa36993272015-11-20 12:43:49 -0600797}
798
Kuiying Wang6b0ceaa2019-11-05 15:13:40 +0800799//------------------------------------------
800// Set Enabled property to inform NMI source
801// handling to trigger a NMI_OUT BSOD.
802//------------------------------------------
803int setNmiProperty(const bool value)
804{
805 constexpr const char* nmiSourceObjPath =
806 "/xyz/openbmc_project/Chassis/Control/NMISource";
807 constexpr const char* nmiSourceIntf =
808 "xyz.openbmc_project.Chassis.Control.NMISource";
809 std::string bmcSourceSignal = "xyz.openbmc_project.Chassis.Control."
810 "NMISource.BMCSourceSignal.ChassisCmd";
811 std::shared_ptr<sdbusplus::asio::connection> busp = getSdBus();
812
813 try
814 {
815 auto service = ipmi::getService(*busp, nmiSourceIntf, nmiSourceObjPath);
816 ipmi::setDbusProperty(*busp, service, nmiSourceObjPath, nmiSourceIntf,
817 "BMCSource", bmcSourceSignal);
818 ipmi::setDbusProperty(*busp, service, nmiSourceObjPath, nmiSourceIntf,
819 "Enabled", value);
820 }
821 catch (std::exception& e)
822 {
823 log<level::ERR>("Failed to trigger NMI_OUT",
824 entry("EXCEPTION=%s", e.what()));
825 return -1;
826 }
827
828 return 0;
829}
830
Deepak Kodihalli18b70d12017-07-21 13:36:33 -0500831namespace power_policy
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500832{
Nan Lifdd8ec52016-08-28 03:57:40 +0800833
Deepak Kodihalli18b70d12017-07-21 13:36:33 -0500834using namespace sdbusplus::xyz::openbmc_project::Control::Power::server;
835using IpmiValue = uint8_t;
836using DbusValue = RestorePolicy::Policy;
Nan Lifdd8ec52016-08-28 03:57:40 +0800837
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700838const std::map<DbusValue, IpmiValue> dbusToIpmi = {
Deepak Kodihalli18b70d12017-07-21 13:36:33 -0500839 {RestorePolicy::Policy::AlwaysOff, 0x00},
840 {RestorePolicy::Policy::Restore, 0x01},
Patrick Venture0b02be92018-08-31 11:55:55 -0700841 {RestorePolicy::Policy::AlwaysOn, 0x02}};
Nan Lifdd8ec52016-08-28 03:57:40 +0800842
Yong Lic6713cf2018-09-12 12:35:13 +0800843static constexpr uint8_t noChange = 0x03;
844static constexpr uint8_t allSupport = 0x01 | 0x02 | 0x04;
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700845
846/* helper function for Get Chassis Status Command
847 */
848std::optional<uint2_t> getPowerRestorePolicy()
849{
850 uint2_t restorePolicy = 0;
851 using namespace chassis::internal;
852
James Feist225dec82019-11-26 16:25:06 -0800853 settings::Objects& objects = cache::getObjects();
854
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700855 try
856 {
857 const auto& powerRestoreSetting =
James Feist225dec82019-11-26 16:25:06 -0800858 objects.map.at(powerRestoreIntf).front();
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700859 ipmi::Value result = ipmi::getDbusProperty(
860 *getSdBus(),
James Feist225dec82019-11-26 16:25:06 -0800861 objects.service(powerRestoreSetting, powerRestoreIntf).c_str(),
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700862 powerRestoreSetting.c_str(), powerRestoreIntf,
863 "PowerRestorePolicy");
864 auto powerRestore = RestorePolicy::convertPolicyFromString(
865 std::get<std::string>(result));
866 restorePolicy = dbusToIpmi.at(powerRestore);
867 }
868 catch (const std::exception& e)
869 {
870 log<level::ERR>(
871 "Failed to fetch pgood property", entry("ERROR=%s", e.what()),
James Feist225dec82019-11-26 16:25:06 -0800872 entry("PATH=%s", objects.map.at(powerRestoreIntf).front().c_str()),
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700873 entry("INTERFACE=%s", powerRestoreIntf));
James Feist225dec82019-11-26 16:25:06 -0800874 cache::objectsPtr.reset();
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700875 return std::nullopt;
876 }
877 return std::make_optional(restorePolicy);
878}
879
880/*
881 * getPowerStatus
882 * helper function for Get Chassis Status Command
883 * return - optional value for pgood (no value on error)
884 */
885std::optional<bool> getPowerStatus()
886{
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700887 bool powerGood = false;
888 std::shared_ptr<sdbusplus::asio::connection> busp = getSdBus();
889 try
890 {
Jason M. Bills3de424c2019-05-21 09:57:16 -0700891 constexpr const char* chassisStatePath =
892 "/xyz/openbmc_project/state/chassis0";
893 constexpr const char* chassisStateIntf =
894 "xyz.openbmc_project.State.Chassis";
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700895 auto service =
Jason M. Bills3de424c2019-05-21 09:57:16 -0700896 ipmi::getService(*busp, chassisStateIntf, chassisStatePath);
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700897
Jason M. Bills3de424c2019-05-21 09:57:16 -0700898 ipmi::Value powerState =
899 ipmi::getDbusProperty(*busp, service, chassisStatePath,
900 chassisStateIntf, "CurrentPowerState");
901 powerGood = std::get<std::string>(powerState) ==
902 "xyz.openbmc_project.State.Chassis.PowerState.On";
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700903 }
904 catch (const std::exception& e)
905 {
906 try
907 {
908 // FIXME: some legacy modules use the older path; try that next
909 constexpr const char* legacyPwrCtrlObj =
910 "/org/openbmc/control/power0";
911 constexpr const char* legacyPwrCtrlIntf =
912 "org.openbmc.control.Power";
913 auto service =
914 ipmi::getService(*busp, legacyPwrCtrlIntf, legacyPwrCtrlObj);
915
916 ipmi::Value variant = ipmi::getDbusProperty(
917 *busp, service, legacyPwrCtrlObj, legacyPwrCtrlIntf, "pgood");
918 powerGood = static_cast<bool>(std::get<int>(variant));
919 }
920 catch (const std::exception& e)
921 {
922 log<level::ERR>("Failed to fetch pgood property",
Jason M. Bills3de424c2019-05-21 09:57:16 -0700923 entry("ERROR=%s", e.what()));
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700924 return std::nullopt;
925 }
926 }
927 return std::make_optional(powerGood);
928}
929
Yong Li70ce7352019-05-16 21:15:27 +0800930/*
931 * getACFailStatus
932 * helper function for Get Chassis Status Command
933 * return - bool value for ACFail (false on error)
934 */
935bool getACFailStatus()
936{
937 constexpr const char* powerControlObj =
938 "/xyz/openbmc_project/Chassis/Control/Power0";
939 constexpr const char* powerControlIntf =
940 "xyz.openbmc_project.Chassis.Control.Power";
941 bool acFail = false;
942 std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus();
943 try
944 {
945 auto service =
946 ipmi::getService(*bus, powerControlIntf, powerControlObj);
947
948 ipmi::Value variant = ipmi::getDbusProperty(
949 *bus, service, powerControlObj, powerControlIntf, "PFail");
950 acFail = std::get<bool>(variant);
951 }
952 catch (const std::exception& e)
953 {
954 log<level::ERR>("Failed to fetch PFail property",
955 entry("ERROR=%s", e.what()),
956 entry("PATH=%s", powerControlObj),
957 entry("INTERFACE=%s", powerControlIntf));
958 }
959 return acFail;
960}
Deepak Kodihalli18b70d12017-07-21 13:36:33 -0500961} // namespace power_policy
Nan Lifdd8ec52016-08-28 03:57:40 +0800962
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700963static std::optional<bool> getButtonEnabled(const std::string& buttonPath,
964 const std::string& buttonIntf)
965{
966 std::shared_ptr<sdbusplus::asio::connection> busp = getSdBus();
967 bool buttonDisabled = false;
968 try
969 {
970 auto service = ipmi::getService(*busp, buttonIntf, buttonPath);
971 ipmi::Value enabled = ipmi::getDbusProperty(*busp, service, buttonPath,
972 buttonIntf, "Enabled");
973 buttonDisabled = !std::get<bool>(enabled);
974 }
975 catch (sdbusplus::exception::SdBusError& e)
976 {
977 log<level::ERR>("Fail to get button Enabled property",
978 entry("PATH=%s", buttonPath.c_str()),
979 entry("ERROR=%s", e.what()));
980 return std::nullopt;
981 }
982 return std::make_optional(buttonDisabled);
983}
984
Nan Lifdd8ec52016-08-28 03:57:40 +0800985//----------------------------------------------------------------------
986// Get Chassis Status commands
987//----------------------------------------------------------------------
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700988ipmi::RspType<bool, // Power is on
989 bool, // Power overload
990 bool, // Interlock
991 bool, // power fault
992 bool, // power control fault
993 uint2_t, // power restore policy
994 bool, // reserved
995
996 bool, // AC failed
997 bool, // last power down caused by a Power overload
998 bool, // last power down caused by a power interlock
999 bool, // last power down caused by power fault
1000 bool, // last ‘Power is on’ state was entered via IPMI command
1001 uint3_t, // reserved
1002
1003 bool, // Chassis intrusion active
1004 bool, // Front Panel Lockout active
1005 bool, // Drive Fault
1006 bool, // Cooling/fan fault detected
1007 uint2_t, // Chassis Identify State
1008 bool, // Chassis Identify command and state info supported
1009 bool, // reserved
1010
1011 bool, // Power off button disabled
1012 bool, // Reset button disabled
1013 bool, // Diagnostic Interrupt button disabled
1014 bool, // Standby (sleep) button disabled
1015 bool, // Power off button disable allowed
1016 bool, // Reset button disable allowed
1017 bool, // Diagnostic Interrupt button disable allowed
1018 bool // Standby (sleep) button disable allowed
1019 >
1020 ipmiGetChassisStatus()
Nan Lifdd8ec52016-08-28 03:57:40 +08001021{
Deepak Kodihalli18b70d12017-07-21 13:36:33 -05001022 using namespace chassis::internal;
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001023 std::optional<uint2_t> restorePolicy =
1024 power_policy::getPowerRestorePolicy();
1025 std::optional<bool> powerGood = power_policy::getPowerStatus();
1026 if (!restorePolicy || !powerGood)
Deepak Kodihalli18b70d12017-07-21 13:36:33 -05001027 {
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001028 return ipmi::responseUnspecifiedError();
Deepak Kodihalli18b70d12017-07-21 13:36:33 -05001029 }
Nan Lifdd8ec52016-08-28 03:57:40 +08001030
1031 // Front Panel Button Capabilities and disable/enable status(Optional)
Vernon Mauery6d5b2f72019-05-16 14:48:47 -07001032 std::optional<bool> powerButtonReading =
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001033 getButtonEnabled(powerButtonPath, powerButtonIntf);
Vernon Mauery6d5b2f72019-05-16 14:48:47 -07001034 // allow disable if the interface is present
1035 bool powerButtonDisableAllow = static_cast<bool>(powerButtonReading);
1036 // default return the button is enabled (not disabled)
1037 bool powerButtonDisabled = false;
1038 if (powerButtonDisableAllow)
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001039 {
Vernon Mauery6d5b2f72019-05-16 14:48:47 -07001040 // return the real value of the button status, if present
1041 powerButtonDisabled = *powerButtonReading;
1042 }
1043
1044 std::optional<bool> resetButtonReading =
1045 getButtonEnabled(resetButtonPath, resetButtonIntf);
1046 // allow disable if the interface is present
1047 bool resetButtonDisableAllow = static_cast<bool>(resetButtonReading);
1048 // default return the button is enabled (not disabled)
1049 bool resetButtonDisabled = false;
1050 if (resetButtonDisableAllow)
1051 {
1052 // return the real value of the button status, if present
1053 resetButtonDisabled = *resetButtonReading;
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001054 }
Nan Lifdd8ec52016-08-28 03:57:40 +08001055
Yong Li70ce7352019-05-16 21:15:27 +08001056 bool powerDownAcFailed = power_policy::getACFailStatus();
1057
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001058 // This response has a lot of hard-coded, unsupported fields
1059 // They are set to false or 0
1060 constexpr bool powerOverload = false;
1061 constexpr bool chassisInterlock = false;
1062 constexpr bool powerFault = false;
1063 constexpr bool powerControlFault = false;
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001064 constexpr bool powerDownOverload = false;
1065 constexpr bool powerDownInterlock = false;
1066 constexpr bool powerDownPowerFault = false;
1067 constexpr bool powerStatusIPMI = false;
1068 constexpr bool chassisIntrusionActive = false;
1069 constexpr bool frontPanelLockoutActive = false;
1070 constexpr bool driveFault = false;
1071 constexpr bool coolingFanFault = false;
1072 // chassisIdentifySupport set because this command is implemented
1073 constexpr bool chassisIdentifySupport = true;
Yong Lif4e38512019-05-21 14:46:55 +08001074 uint2_t chassisIdentifyState = static_cast<uint2_t>(chassisIDState);
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001075 constexpr bool diagButtonDisabled = false;
1076 constexpr bool sleepButtonDisabled = false;
1077 constexpr bool diagButtonDisableAllow = false;
1078 constexpr bool sleepButtonDisableAllow = false;
1079
1080 return ipmi::responseSuccess(
1081 *powerGood, powerOverload, chassisInterlock, powerFault,
1082 powerControlFault, *restorePolicy,
1083 false, // reserved
1084
1085 powerDownAcFailed, powerDownOverload, powerDownInterlock,
1086 powerDownPowerFault, powerStatusIPMI,
1087 uint3_t(0), // reserved
1088
1089 chassisIntrusionActive, frontPanelLockoutActive, driveFault,
1090 coolingFanFault, chassisIdentifyState, chassisIdentifySupport,
1091 false, // reserved
1092
Vernon Mauery6d5b2f72019-05-16 14:48:47 -07001093 powerButtonDisabled, resetButtonDisabled, diagButtonDisabled,
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001094 sleepButtonDisabled, powerButtonDisableAllow, resetButtonDisableAllow,
1095 diagButtonDisableAllow, sleepButtonDisableAllow);
Nan Lifdd8ec52016-08-28 03:57:40 +08001096}
Chris Austen7888c4d2015-12-03 15:26:20 -06001097
Vijay Khemka074f64d2020-03-03 15:08:43 -08001098enum class IpmiRestartCause
1099{
1100 Unknown = 0x0,
1101 RemoteCommand = 0x1,
1102 ResetButton = 0x2,
1103 PowerButton = 0x3,
1104 WatchdogTimer = 0x4,
1105 PowerPolicyAlwaysOn = 0x6,
1106 PowerPolicyPreviousState = 0x7,
1107 SoftReset = 0xa,
1108};
1109
1110static IpmiRestartCause
1111 restartCauseToIpmiRestartCause(State::Host::RestartCause cause)
1112{
1113 switch (cause)
1114 {
1115 case State::Host::RestartCause::Unknown:
1116 {
1117 return IpmiRestartCause::Unknown;
1118 }
1119 case State::Host::RestartCause::RemoteCommand:
1120 {
1121 return IpmiRestartCause::RemoteCommand;
1122 }
1123 case State::Host::RestartCause::ResetButton:
1124 {
1125 return IpmiRestartCause::ResetButton;
1126 }
1127 case State::Host::RestartCause::PowerButton:
1128 {
1129 return IpmiRestartCause::PowerButton;
1130 }
1131 case State::Host::RestartCause::WatchdogTimer:
1132 {
1133 return IpmiRestartCause::WatchdogTimer;
1134 }
1135 case State::Host::RestartCause::PowerPolicyAlwaysOn:
1136 {
1137 return IpmiRestartCause::PowerPolicyAlwaysOn;
1138 }
1139 case State::Host::RestartCause::PowerPolicyPreviousState:
1140 {
1141 return IpmiRestartCause::PowerPolicyPreviousState;
1142 }
1143 case State::Host::RestartCause::SoftReset:
1144 {
1145 return IpmiRestartCause::SoftReset;
1146 }
1147 default:
1148 {
1149 return IpmiRestartCause::Unknown;
1150 }
1151 }
1152}
1153
1154/*
1155 * getRestartCause
1156 * helper function for Get Host restart cause Command
1157 * return - optional value for RestartCause (no value on error)
1158 */
1159static std::optional<uint4_t> getRestartCause(ipmi::Context::ptr ctx)
1160{
1161 constexpr const char* restartCausePath =
1162 "/xyz/openbmc_project/control/host0/restart_cause";
1163 constexpr const char* restartCauseIntf =
1164 "xyz.openbmc_project.Control.Host.RestartCause";
1165
1166 std::string service;
1167 boost::system::error_code ec =
1168 ipmi::getService(ctx, restartCauseIntf, restartCausePath, service);
1169 if (!ec)
1170 {
1171 std::string restartCauseStr;
1172 ec = ipmi::getDbusProperty<std::string>(
1173 ctx, service, restartCausePath, restartCauseIntf, "RestartCause",
1174 restartCauseStr);
1175 if (!ec)
1176 {
1177 auto cause =
1178 State::Host::convertRestartCauseFromString(restartCauseStr);
1179 return restartCauseToIpmiRestartCause(cause);
1180 }
1181 }
1182
1183 log<level::ERR>("Failed to fetch RestartCause property",
1184 entry("ERROR=%s", ec.message().c_str()),
1185 entry("PATH=%s", restartCausePath),
1186 entry("INTERFACE=%s", restartCauseIntf));
1187 return std::nullopt;
1188}
1189
1190ipmi::RspType<uint4_t, // Restart Cause
1191 uint4_t, // reserved
1192 uint8_t // channel number (not supported)
1193 >
1194 ipmiGetSystemRestartCause(ipmi::Context::ptr ctx)
1195{
1196 std::optional<uint4_t> cause = getRestartCause(ctx);
1197 if (!cause)
1198 {
1199 return ipmi::responseUnspecifiedError();
1200 }
1201
1202 return ipmi::responseSuccess(cause.value(), RESERVED,
1203 CHANNEL_NOT_SUPPORTED);
1204}
1205
Vishwanatha Subbanna83b5c1c2017-01-25 18:41:51 +05301206//-------------------------------------------------------------
1207// Send a command to SoftPowerOff application to stop any timer
1208//-------------------------------------------------------------
1209int stop_soft_off_timer()
1210{
Patrick Venture0b02be92018-08-31 11:55:55 -07001211 constexpr auto iface = "org.freedesktop.DBus.Properties";
1212 constexpr auto soft_off_iface = "xyz.openbmc_project.Ipmi.Internal."
1213 "SoftPowerOff";
Vishwanatha Subbanna83b5c1c2017-01-25 18:41:51 +05301214
Patrick Venture0b02be92018-08-31 11:55:55 -07001215 constexpr auto property = "ResponseReceived";
1216 constexpr auto value = "xyz.openbmc_project.Ipmi.Internal."
1217 "SoftPowerOff.HostResponse.HostShutdown";
Vishwanatha Subbanna83b5c1c2017-01-25 18:41:51 +05301218
1219 // Get the system bus where most system services are provided.
1220 auto bus = ipmid_get_sd_bus_connection();
1221
1222 // Get the service name
Andrew Geissler2b4e4592017-06-08 11:18:35 -05001223 // TODO openbmc/openbmc#1661 - Mapper refactor
1224 //
1225 // See openbmc/openbmc#1743 for some details but high level summary is that
1226 // for now the code will directly call the soft off interface due to a
1227 // race condition with mapper usage
1228 //
Patrick Venture0b02be92018-08-31 11:55:55 -07001229 // char *busname = nullptr;
1230 // auto r = mapper_get_service(bus, SOFTOFF_OBJPATH, &busname);
1231 // if (r < 0)
Andrew Geissler2b4e4592017-06-08 11:18:35 -05001232 //{
1233 // fprintf(stderr, "Failed to get %s bus name: %s\n",
Aditya Saripalli5fb14602017-11-09 14:46:27 +05301234 // SOFTOFF_OBJPATH, -r);
Andrew Geissler2b4e4592017-06-08 11:18:35 -05001235 // return r;
1236 //}
Vishwanatha Subbanna83b5c1c2017-01-25 18:41:51 +05301237
1238 // No error object or reply expected.
Andrew Geissler2b4e4592017-06-08 11:18:35 -05001239 int rc = sd_bus_call_method(bus, SOFTOFF_BUSNAME, SOFTOFF_OBJPATH, iface,
Patrick Venture0b02be92018-08-31 11:55:55 -07001240 "Set", nullptr, nullptr, "ssv", soft_off_iface,
1241 property, "s", value);
Vishwanatha Subbanna83b5c1c2017-01-25 18:41:51 +05301242 if (rc < 0)
1243 {
Aditya Saripalli5fb14602017-11-09 14:46:27 +05301244 log<level::ERR>("Failed to set property in SoftPowerOff object",
1245 entry("ERRNO=0x%X", -rc));
Vishwanatha Subbanna83b5c1c2017-01-25 18:41:51 +05301246 }
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001247
Patrick Venture0b02be92018-08-31 11:55:55 -07001248 // TODO openbmc/openbmc#1661 - Mapper refactor
1249 // free(busname);
Vishwanatha Subbanna83b5c1c2017-01-25 18:41:51 +05301250 return rc;
1251}
1252
vishwa36993272015-11-20 12:43:49 -06001253//----------------------------------------------------------------------
Andrew Geisslera6e3a302017-05-31 19:34:00 -05001254// Create file to indicate there is no need for softoff notification to host
1255//----------------------------------------------------------------------
1256void indicate_no_softoff_needed()
1257{
1258 fs::path path{HOST_INBAND_REQUEST_DIR};
1259 if (!fs::is_directory(path))
1260 {
1261 fs::create_directory(path);
1262 }
1263
1264 // Add the host instance (default 0 for now) to the file name
1265 std::string file{HOST_INBAND_REQUEST_FILE};
Patrick Venture0b02be92018-08-31 11:55:55 -07001266 auto size = std::snprintf(nullptr, 0, file.c_str(), 0);
Andrew Geisslera6e3a302017-05-31 19:34:00 -05001267 size++; // null
1268 std::unique_ptr<char[]> buf(new char[size]);
Patrick Venture0b02be92018-08-31 11:55:55 -07001269 std::snprintf(buf.get(), size, file.c_str(), 0);
Andrew Geisslera6e3a302017-05-31 19:34:00 -05001270
1271 // Append file name to directory and create it
1272 path /= buf.get();
1273 std::ofstream(path.c_str());
1274}
1275
anil kumar appanadafff5f2019-04-27 18:06:00 +00001276/** @brief Implementation of chassis control command
1277 *
1278 * @param - chassisControl command byte
1279 *
1280 * @return Success or InvalidFieldRequest.
1281 */
1282ipmi::RspType<> ipmiChassisControl(uint8_t chassisControl)
vishwa36993272015-11-20 12:43:49 -06001283{
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001284 int rc = 0;
anil kumar appanadafff5f2019-04-27 18:06:00 +00001285 switch (chassisControl)
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001286 {
1287 case CMD_POWER_ON:
1288 rc = initiate_state_transition(State::Host::Transition::On);
1289 break;
1290 case CMD_POWER_OFF:
Vishwanatha Subbanna8b26d352017-08-04 18:35:18 +05301291 // This path would be hit in 2 conditions.
1292 // 1: When user asks for power off using ipmi chassis command 0x04
1293 // 2: Host asking for power off post shutting down.
1294
1295 // If it's a host requested power off, then need to nudge Softoff
1296 // application that it needs to stop the watchdog timer if running.
1297 // If it is a user requested power off, then this is not really
1298 // needed. But then we need to differentiate between user and host
1299 // calling this same command
1300
1301 // For now, we are going ahead with trying to nudge the soft off and
1302 // interpret the failure to do so as a non softoff case
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001303 rc = stop_soft_off_timer();
Vishwanatha Subbanna8b26d352017-08-04 18:35:18 +05301304
Andrew Geisslera6e3a302017-05-31 19:34:00 -05001305 // Only request the Off transition if the soft power off
1306 // application is not running
1307 if (rc < 0)
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001308 {
Andrew Geisslera6e3a302017-05-31 19:34:00 -05001309 // First create a file to indicate to the soft off application
Vishwanatha Subbanna8b26d352017-08-04 18:35:18 +05301310 // that it should not run. Not doing this will result in State
1311 // manager doing a default soft power off when asked for power
1312 // off.
Andrew Geisslera6e3a302017-05-31 19:34:00 -05001313 indicate_no_softoff_needed();
1314
1315 // Now request the shutdown
1316 rc = initiate_state_transition(State::Host::Transition::Off);
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001317 }
Andrew Geisslera6e3a302017-05-31 19:34:00 -05001318 else
1319 {
Vishwanatha Subbanna8b26d352017-08-04 18:35:18 +05301320 log<level::INFO>("Soft off is running, so let shutdown target "
1321 "stop the host");
Andrew Geisslera6e3a302017-05-31 19:34:00 -05001322 }
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001323 break;
Vishwanatha Subbanna83b5c1c2017-01-25 18:41:51 +05301324
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001325 case CMD_HARD_RESET:
1326 case CMD_POWER_CYCLE:
1327 // SPEC has a section that says certain implementations can trigger
1328 // PowerOn if power is Off when a command to power cycle is
1329 // requested
Andrew Geisslera6e3a302017-05-31 19:34:00 -05001330
1331 // First create a file to indicate to the soft off application
1332 // that it should not run since this is a direct user initiated
1333 // power reboot request (i.e. a reboot request that is not
1334 // originating via a soft power off SMS request)
1335 indicate_no_softoff_needed();
1336
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001337 rc = initiate_state_transition(State::Host::Transition::Reboot);
1338 break;
Vishwanatha Subbanna8b26d352017-08-04 18:35:18 +05301339
1340 case CMD_SOFT_OFF_VIA_OVER_TEMP:
1341 // Request Host State Manager to do a soft power off
1342 rc = initiate_state_transition(State::Host::Transition::Off);
1343 break;
1344
Kuiying Wang6b0ceaa2019-11-05 15:13:40 +08001345 case CMD_PULSE_DIAGNOSTIC_INTR:
1346 rc = setNmiProperty(true);
1347 break;
1348
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001349 default:
1350 {
Aditya Saripalli5fb14602017-11-09 14:46:27 +05301351 log<level::ERR>("Invalid Chassis Control command",
anil kumar appanadafff5f2019-04-27 18:06:00 +00001352 entry("CMD=0x%X", chassisControl));
1353 return ipmi::responseInvalidFieldRequest();
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001354 }
1355 }
vishwa36993272015-11-20 12:43:49 -06001356
anil kumar appanadafff5f2019-04-27 18:06:00 +00001357 return ((rc < 0) ? ipmi::responseUnspecifiedError()
1358 : ipmi::responseSuccess());
vishwa36993272015-11-20 12:43:49 -06001359}
1360
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001361/** @brief Return D-Bus connection string to enclosure identify LED object
1362 *
1363 * @param[in, out] connection - connection to D-Bus object
1364 * @return a IPMI return code
1365 */
1366std::string getEnclosureIdentifyConnection()
Tom Joseph5110c122018-03-23 17:55:40 +05301367{
Tom Joseph5110c122018-03-23 17:55:40 +05301368 // lookup enclosure_identify group owner(s) in mapper
1369 auto mapperCall = chassis::internal::dbus.new_method_call(
Patrick Venture0b02be92018-08-31 11:55:55 -07001370 ipmi::MAPPER_BUS_NAME, ipmi::MAPPER_OBJ, ipmi::MAPPER_INTF,
1371 "GetObject");
Tom Joseph5110c122018-03-23 17:55:40 +05301372
1373 mapperCall.append(identify_led_object_name);
Patrick Venture0b02be92018-08-31 11:55:55 -07001374 static const std::vector<std::string> interfaces = {
1375 "xyz.openbmc_project.Led.Group"};
Tom Joseph5110c122018-03-23 17:55:40 +05301376 mapperCall.append(interfaces);
1377 auto mapperReply = chassis::internal::dbus.call(mapperCall);
1378 if (mapperReply.is_method_error())
1379 {
1380 log<level::ERR>("Chassis Identify: Error communicating to mapper.");
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001381 elog<InternalFailure>();
Tom Joseph5110c122018-03-23 17:55:40 +05301382 }
1383 std::vector<std::pair<std::string, std::vector<std::string>>> mapperResp;
1384 mapperReply.read(mapperResp);
1385
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001386 if (mapperResp.size() != encIdentifyObjectsSize)
Tom Joseph5110c122018-03-23 17:55:40 +05301387 {
Patrick Venture0b02be92018-08-31 11:55:55 -07001388 log<level::ERR>(
1389 "Invalid number of enclosure identify objects.",
1390 entry("ENC_IDENTITY_OBJECTS_SIZE=%d", mapperResp.size()));
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001391 elog<InternalFailure>();
1392 }
1393 auto pair = mapperResp[encIdentifyObjectsSize - 1];
1394 return pair.first;
1395}
Tom Joseph5110c122018-03-23 17:55:40 +05301396
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001397/** @brief Turn On/Off enclosure identify LED
1398 *
1399 * @param[in] flag - true to turn on LED, false to turn off
1400 * @return a IPMI return code
1401 */
1402void enclosureIdentifyLed(bool flag)
1403{
1404 using namespace chassis::internal;
1405 std::string connection = std::move(getEnclosureIdentifyConnection());
Vernon Mauery400cc782018-10-09 13:49:53 -07001406 auto msg = std::string("enclosureIdentifyLed(") +
1407 boost::lexical_cast<std::string>(flag) + ")";
1408 log<level::DEBUG>(msg.c_str());
Patrick Venture0b02be92018-08-31 11:55:55 -07001409 auto led =
1410 dbus.new_method_call(connection.c_str(), identify_led_object_name,
1411 "org.freedesktop.DBus.Properties", "Set");
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001412 led.append("xyz.openbmc_project.Led.Group", "Asserted",
Vernon Mauery16b86932019-05-01 08:36:11 -07001413 std::variant<bool>(flag));
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001414 auto ledReply = dbus.call(led);
1415 if (ledReply.is_method_error())
1416 {
1417 log<level::ERR>("Chassis Identify: Error Setting State On/Off\n",
Patrick Venture0b02be92018-08-31 11:55:55 -07001418 entry("LED_STATE=%d", flag));
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001419 elog<InternalFailure>();
1420 }
1421}
1422
1423/** @brief Callback method to turn off LED
1424 */
1425void enclosureIdentifyLedOff()
1426{
1427 try
1428 {
Yong Lif4e38512019-05-21 14:46:55 +08001429 chassisIDState = ChassisIDState::off;
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001430 enclosureIdentifyLed(false);
1431 }
1432 catch (const InternalFailure& e)
1433 {
1434 report<InternalFailure>();
1435 }
1436}
1437
1438/** @brief Create timer to turn on and off the enclosure LED
1439 */
1440void createIdentifyTimer()
1441{
1442 if (!identifyTimer)
1443 {
Vernon Mauery1181af72018-10-08 12:05:00 -07001444 identifyTimer =
1445 std::make_unique<phosphor::Timer>(enclosureIdentifyLedOff);
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001446 }
1447}
1448
Vernon Mauery400cc782018-10-09 13:49:53 -07001449ipmi::RspType<> ipmiChassisIdentify(std::optional<uint8_t> interval,
1450 std::optional<uint8_t> force)
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001451{
Vernon Mauery400cc782018-10-09 13:49:53 -07001452 uint8_t identifyInterval = interval.value_or(DEFAULT_IDENTIFY_TIME_OUT);
1453 bool forceIdentify = force.value_or(0) & 0x01;
Tom Josephbed26992018-07-31 23:00:24 +05301454
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001455 if (identifyInterval || forceIdentify)
1456 {
Vernon Mauery400cc782018-10-09 13:49:53 -07001457 // stop the timer if already started;
1458 // for force identify we should not turn off LED
Vernon Mauery1181af72018-10-08 12:05:00 -07001459 identifyTimer->stop();
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001460 try
Tom Joseph5110c122018-03-23 17:55:40 +05301461 {
Yong Lif4e38512019-05-21 14:46:55 +08001462 chassisIDState = ChassisIDState::temporaryOn;
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001463 enclosureIdentifyLed(true);
1464 }
1465 catch (const InternalFailure& e)
1466 {
1467 report<InternalFailure>();
Vernon Mauery400cc782018-10-09 13:49:53 -07001468 return ipmi::responseResponseError();
Tom Joseph5110c122018-03-23 17:55:40 +05301469 }
1470
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001471 if (forceIdentify)
Tom Joseph5110c122018-03-23 17:55:40 +05301472 {
Yong Lif4e38512019-05-21 14:46:55 +08001473 chassisIDState = ChassisIDState::indefiniteOn;
Vernon Mauery400cc782018-10-09 13:49:53 -07001474 return ipmi::responseSuccess();
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001475 }
1476 // start the timer
1477 auto time = std::chrono::duration_cast<std::chrono::microseconds>(
Patrick Venture0b02be92018-08-31 11:55:55 -07001478 std::chrono::seconds(identifyInterval));
Vernon Mauery1181af72018-10-08 12:05:00 -07001479 identifyTimer->start(time);
Tom Joseph5110c122018-03-23 17:55:40 +05301480 }
Tom Josephbed26992018-07-31 23:00:24 +05301481 else if (!identifyInterval)
1482 {
Vernon Mauery1181af72018-10-08 12:05:00 -07001483 identifyTimer->stop();
Tom Josephbed26992018-07-31 23:00:24 +05301484 enclosureIdentifyLedOff();
1485 }
Vernon Mauery400cc782018-10-09 13:49:53 -07001486 return ipmi::responseSuccess();
Tom Joseph5110c122018-03-23 17:55:40 +05301487}
1488
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001489namespace boot_options
1490{
1491
1492using namespace sdbusplus::xyz::openbmc_project::Control::Boot::server;
1493using IpmiValue = uint8_t;
1494constexpr auto ipmiDefault = 0;
1495
Patrick Venture0b02be92018-08-31 11:55:55 -07001496std::map<IpmiValue, Source::Sources> sourceIpmiToDbus = {
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001497 {0x01, Source::Sources::Network},
1498 {0x02, Source::Sources::Disk},
1499 {0x05, Source::Sources::ExternalMedia},
Jia, chunhui67c5e5d2019-05-06 11:29:54 +08001500 {0x0f, Source::Sources::RemovableMedia},
Patrick Venture0b02be92018-08-31 11:55:55 -07001501 {ipmiDefault, Source::Sources::Default}};
shgoupfd84fbbf2015-12-17 10:05:51 +08001502
Patrick Venture0b02be92018-08-31 11:55:55 -07001503std::map<IpmiValue, Mode::Modes> modeIpmiToDbus = {
Yong Li5833cb62019-10-30 13:27:12 +08001504#ifdef ENABLE_BOOT_FLAG_SAFE_MODE_SUPPORT
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001505 {0x03, Mode::Modes::Safe},
Yong Li5833cb62019-10-30 13:27:12 +08001506#endif // ENABLE_BOOT_SAFE_MODE_SUPPORT
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001507 {0x06, Mode::Modes::Setup},
Patrick Venture0b02be92018-08-31 11:55:55 -07001508 {ipmiDefault, Mode::Modes::Regular}};
shgoupfd84fbbf2015-12-17 10:05:51 +08001509
Patrick Venture0b02be92018-08-31 11:55:55 -07001510std::map<Source::Sources, IpmiValue> sourceDbusToIpmi = {
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001511 {Source::Sources::Network, 0x01},
1512 {Source::Sources::Disk, 0x02},
1513 {Source::Sources::ExternalMedia, 0x05},
Jia, chunhui67c5e5d2019-05-06 11:29:54 +08001514 {Source::Sources::RemovableMedia, 0x0f},
Patrick Venture0b02be92018-08-31 11:55:55 -07001515 {Source::Sources::Default, ipmiDefault}};
shgoupfd84fbbf2015-12-17 10:05:51 +08001516
Patrick Venture0b02be92018-08-31 11:55:55 -07001517std::map<Mode::Modes, IpmiValue> modeDbusToIpmi = {
Yong Li5833cb62019-10-30 13:27:12 +08001518#ifdef ENABLE_BOOT_FLAG_SAFE_MODE_SUPPORT
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001519 {Mode::Modes::Safe, 0x03},
Yong Li5833cb62019-10-30 13:27:12 +08001520#endif // ENABLE_BOOT_SAFE_MODE_SUPPORT
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001521 {Mode::Modes::Setup, 0x06},
Patrick Venture0b02be92018-08-31 11:55:55 -07001522 {Mode::Modes::Regular, ipmiDefault}};
shgoupfd84fbbf2015-12-17 10:05:51 +08001523
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001524} // namespace boot_options
shgoupfd84fbbf2015-12-17 10:05:51 +08001525
Marri Devender Rao81719702018-05-07 00:53:48 -05001526/** @brief Set the property value for boot source
1527 * @param[in] source - boot source value
1528 * @return On failure return IPMI error.
1529 */
1530static ipmi_ret_t setBootSource(const Source::Sources& source)
1531{
1532 using namespace chassis::internal;
1533 using namespace chassis::internal::cache;
Vernon Mauery16b86932019-05-01 08:36:11 -07001534 std::variant<std::string> property = convertForMessage(source);
James Feist225dec82019-11-26 16:25:06 -08001535 settings::Objects& objects = getObjects();
Marri Devender Rao81719702018-05-07 00:53:48 -05001536 auto bootSetting = settings::boot::setting(objects, bootSourceIntf);
1537 const auto& bootSourceSetting = std::get<settings::Path>(bootSetting);
Patrick Venture0b02be92018-08-31 11:55:55 -07001538 auto method = dbus.new_method_call(
1539 objects.service(bootSourceSetting, bootSourceIntf).c_str(),
1540 bootSourceSetting.c_str(), ipmi::PROP_INTF, "Set");
Marri Devender Rao81719702018-05-07 00:53:48 -05001541 method.append(bootSourceIntf, "BootSource", property);
1542 auto reply = dbus.call(method);
1543 if (reply.is_method_error())
1544 {
1545 log<level::ERR>("Error in BootSource Set");
1546 report<InternalFailure>();
1547 return IPMI_CC_UNSPECIFIED_ERROR;
1548 }
1549 return IPMI_CC_OK;
1550}
1551
Patrick Venture0b02be92018-08-31 11:55:55 -07001552/** @brief Set the property value for boot mode
Marri Devender Rao81719702018-05-07 00:53:48 -05001553 * @param[in] mode - boot mode value
1554 * @return On failure return IPMI error.
1555 */
1556static ipmi_ret_t setBootMode(const Mode::Modes& mode)
1557{
1558 using namespace chassis::internal;
1559 using namespace chassis::internal::cache;
Vernon Mauery16b86932019-05-01 08:36:11 -07001560 std::variant<std::string> property = convertForMessage(mode);
James Feist225dec82019-11-26 16:25:06 -08001561 settings::Objects& objects = getObjects();
Marri Devender Rao81719702018-05-07 00:53:48 -05001562 auto bootSetting = settings::boot::setting(objects, bootModeIntf);
1563 const auto& bootModeSetting = std::get<settings::Path>(bootSetting);
Patrick Venture0b02be92018-08-31 11:55:55 -07001564 auto method = dbus.new_method_call(
1565 objects.service(bootModeSetting, bootModeIntf).c_str(),
1566 bootModeSetting.c_str(), ipmi::PROP_INTF, "Set");
Marri Devender Rao81719702018-05-07 00:53:48 -05001567 method.append(bootModeIntf, "BootMode", property);
1568 auto reply = dbus.call(method);
1569 if (reply.is_method_error())
1570 {
1571 log<level::ERR>("Error in BootMode Set");
1572 report<InternalFailure>();
1573 return IPMI_CC_UNSPECIFIED_ERROR;
1574 }
1575 return IPMI_CC_OK;
1576}
1577
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001578ipmi_ret_t ipmi_chassis_get_sys_boot_options(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
1579 ipmi_request_t request,
1580 ipmi_response_t response,
1581 ipmi_data_len_t data_len,
1582 ipmi_context_t context)
Adriana Kobylak40814c62015-10-27 15:58:44 -05001583{
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001584 using namespace boot_options;
shgoupfd84fbbf2015-12-17 10:05:51 +08001585 ipmi_ret_t rc = IPMI_CC_PARM_NOT_SUPPORTED;
Patrick Venture0b02be92018-08-31 11:55:55 -07001586 char* p = NULL;
1587 get_sys_boot_options_response_t* resp =
1588 (get_sys_boot_options_response_t*)response;
1589 get_sys_boot_options_t* reqptr = (get_sys_boot_options_t*)request;
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001590 IpmiValue bootOption = ipmiDefault;
Adriana Kobylak40814c62015-10-27 15:58:44 -05001591
Patrick Ventureb51bf9c2018-09-10 15:53:14 -07001592 std::memset(resp, 0, sizeof(*resp));
Patrick Venture0b02be92018-08-31 11:55:55 -07001593 resp->version = SET_PARM_VERSION;
1594 resp->parm = 5;
1595 resp->data[0] = SET_PARM_BOOT_FLAGS_VALID_ONE_TIME;
Adriana Kobylak40814c62015-10-27 15:58:44 -05001596
shgoupfd84fbbf2015-12-17 10:05:51 +08001597 /*
1598 * Parameter #5 means boot flags. Please refer to 28.13 of ipmi doc.
1599 * This is the only parameter used by petitboot.
1600 */
Patrick Venture0b02be92018-08-31 11:55:55 -07001601 if (reqptr->parameter ==
1602 static_cast<uint8_t>(BootOptionParameter::BOOT_FLAGS))
1603 {
shgoupfd84fbbf2015-12-17 10:05:51 +08001604
Ratan Guptafd28dd72016-08-01 04:58:01 -05001605 *data_len = static_cast<uint8_t>(BootOptionResponseSize::BOOT_FLAGS);
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001606 using namespace chassis::internal;
1607 using namespace chassis::internal::cache;
shgoupfd84fbbf2015-12-17 10:05:51 +08001608
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001609 try
ratagupta6f6bff2016-04-04 06:20:11 -05001610 {
James Feist225dec82019-11-26 16:25:06 -08001611 settings::Objects& objects = getObjects();
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001612 auto bootSetting = settings::boot::setting(objects, bootSourceIntf);
1613 const auto& bootSourceSetting =
1614 std::get<settings::Path>(bootSetting);
1615 auto oneTimeEnabled =
1616 std::get<settings::boot::OneTimeEnabled>(bootSetting);
Patrick Venture0b02be92018-08-31 11:55:55 -07001617 auto method = dbus.new_method_call(
1618 objects.service(bootSourceSetting, bootSourceIntf).c_str(),
1619 bootSourceSetting.c_str(), ipmi::PROP_INTF, "Get");
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001620 method.append(bootSourceIntf, "BootSource");
1621 auto reply = dbus.call(method);
1622 if (reply.is_method_error())
1623 {
1624 log<level::ERR>("Error in BootSource Get");
1625 report<InternalFailure>();
1626 *data_len = 0;
1627 return IPMI_CC_UNSPECIFIED_ERROR;
1628 }
Vernon Mauery16b86932019-05-01 08:36:11 -07001629 std::variant<std::string> result;
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001630 reply.read(result);
Vernon Maueryf442e112019-04-09 11:44:36 -07001631 auto bootSource =
1632 Source::convertSourcesFromString(std::get<std::string>(result));
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001633
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001634 bootSetting = settings::boot::setting(objects, bootModeIntf);
1635 const auto& bootModeSetting = std::get<settings::Path>(bootSetting);
1636 method = dbus.new_method_call(
Patrick Venture0b02be92018-08-31 11:55:55 -07001637 objects.service(bootModeSetting, bootModeIntf).c_str(),
1638 bootModeSetting.c_str(), ipmi::PROP_INTF, "Get");
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001639 method.append(bootModeIntf, "BootMode");
1640 reply = dbus.call(method);
1641 if (reply.is_method_error())
1642 {
1643 log<level::ERR>("Error in BootMode Get");
1644 report<InternalFailure>();
1645 *data_len = 0;
1646 return IPMI_CC_UNSPECIFIED_ERROR;
1647 }
1648 reply.read(result);
Vernon Maueryf442e112019-04-09 11:44:36 -07001649 auto bootMode =
1650 Mode::convertModesFromString(std::get<std::string>(result));
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001651
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001652 bootOption = sourceDbusToIpmi.at(bootSource);
1653 if ((Mode::Modes::Regular == bootMode) &&
1654 (Source::Sources::Default == bootSource))
1655 {
1656 bootOption = ipmiDefault;
1657 }
1658 else if (Source::Sources::Default == bootSource)
1659 {
1660 bootOption = modeDbusToIpmi.at(bootMode);
1661 }
1662 resp->data[1] = (bootOption << 2);
ratagupta6f6bff2016-04-04 06:20:11 -05001663
Patrick Venture0b02be92018-08-31 11:55:55 -07001664 resp->data[0] = oneTimeEnabled
1665 ? SET_PARM_BOOT_FLAGS_VALID_ONE_TIME
1666 : SET_PARM_BOOT_FLAGS_VALID_PERMANENT;
ratagupta6f6bff2016-04-04 06:20:11 -05001667
ratagupta6f6bff2016-04-04 06:20:11 -05001668 rc = IPMI_CC_OK;
ratagupta6f6bff2016-04-04 06:20:11 -05001669 }
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001670 catch (InternalFailure& e)
1671 {
James Feist225dec82019-11-26 16:25:06 -08001672 cache::objectsPtr.reset();
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001673 report<InternalFailure>();
1674 *data_len = 0;
1675 return IPMI_CC_UNSPECIFIED_ERROR;
1676 }
Patrick Venture0b02be92018-08-31 11:55:55 -07001677 }
1678 else if (reqptr->parameter ==
1679 static_cast<uint8_t>(BootOptionParameter::OPAL_NETWORK_SETTINGS))
1680 {
Ratan Guptafd28dd72016-08-01 04:58:01 -05001681
Patrick Venture0b02be92018-08-31 11:55:55 -07001682 *data_len =
1683 static_cast<uint8_t>(BootOptionResponseSize::OPAL_NETWORK_SETTINGS);
Ratan Guptafd28dd72016-08-01 04:58:01 -05001684
Patrick Venture0b02be92018-08-31 11:55:55 -07001685 resp->parm =
1686 static_cast<uint8_t>(BootOptionParameter::OPAL_NETWORK_SETTINGS);
Ratan Guptafd28dd72016-08-01 04:58:01 -05001687
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001688 int ret = getHostNetworkData(resp);
Ratan Guptafd28dd72016-08-01 04:58:01 -05001689
Patrick Venture0b02be92018-08-31 11:55:55 -07001690 if (ret < 0)
1691 {
Ratan Guptafd28dd72016-08-01 04:58:01 -05001692
Aditya Saripalli5fb14602017-11-09 14:46:27 +05301693 log<level::ERR>(
Patrick Venture0b02be92018-08-31 11:55:55 -07001694 "getHostNetworkData failed for get_sys_boot_options.");
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001695 rc = IPMI_CC_UNSPECIFIED_ERROR;
Patrick Venture0b02be92018-08-31 11:55:55 -07001696 }
1697 else
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001698 rc = IPMI_CC_OK;
Ratan Guptafd28dd72016-08-01 04:58:01 -05001699 }
1700
Patrick Venture0b02be92018-08-31 11:55:55 -07001701 else
1702 {
1703 log<level::ERR>("Unsupported parameter",
1704 entry("PARAM=0x%x", reqptr->parameter));
shgoupfd84fbbf2015-12-17 10:05:51 +08001705 }
1706
1707 if (p)
1708 free(p);
1709
Ratan Guptafd28dd72016-08-01 04:58:01 -05001710 if (rc == IPMI_CC_OK)
1711 {
1712 *data_len += 2;
1713 }
1714
shgoupfd84fbbf2015-12-17 10:05:51 +08001715 return rc;
1716}
1717
shgoupfd84fbbf2015-12-17 10:05:51 +08001718ipmi_ret_t ipmi_chassis_set_sys_boot_options(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001719 ipmi_request_t request,
1720 ipmi_response_t response,
1721 ipmi_data_len_t data_len,
1722 ipmi_context_t context)
shgoupfd84fbbf2015-12-17 10:05:51 +08001723{
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001724 using namespace boot_options;
shgoupfd84fbbf2015-12-17 10:05:51 +08001725 ipmi_ret_t rc = IPMI_CC_OK;
Patrick Venture0b02be92018-08-31 11:55:55 -07001726 set_sys_boot_options_t* reqptr = (set_sys_boot_options_t*)request;
shgoupfd84fbbf2015-12-17 10:05:51 +08001727
Patrick Ventureb51bf9c2018-09-10 15:53:14 -07001728 std::printf("IPMI SET_SYS_BOOT_OPTIONS reqptr->parameter =[%d]\n",
1729 reqptr->parameter);
Ratan Guptafd28dd72016-08-01 04:58:01 -05001730
shgoupfd84fbbf2015-12-17 10:05:51 +08001731 // This IPMI command does not have any resposne data
1732 *data_len = 0;
1733
1734 /* 000101
1735 * Parameter #5 means boot flags. Please refer to 28.13 of ipmi doc.
1736 * This is the only parameter used by petitboot.
1737 */
Ratan Guptafd28dd72016-08-01 04:58:01 -05001738
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001739 if (reqptr->parameter == (uint8_t)BootOptionParameter::BOOT_FLAGS)
1740 {
1741 IpmiValue bootOption = ((reqptr->data[1] & 0x3C) >> 2);
1742 using namespace chassis::internal;
1743 using namespace chassis::internal::cache;
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001744 auto oneTimeEnabled = false;
1745 constexpr auto enabledIntf = "xyz.openbmc_project.Object.Enable";
Tom Joseph57e8eb72017-09-25 18:05:02 +05301746 constexpr auto oneTimePath =
Patrick Venture0b02be92018-08-31 11:55:55 -07001747 "/xyz/openbmc_project/control/host0/boot/one_time";
shgoupfd84fbbf2015-12-17 10:05:51 +08001748
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001749 try
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001750 {
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001751 bool permanent =
1752 (reqptr->data[0] & SET_PARM_BOOT_FLAGS_PERMANENT) ==
1753 SET_PARM_BOOT_FLAGS_PERMANENT;
1754
James Feist225dec82019-11-26 16:25:06 -08001755 settings::Objects& objects = getObjects();
1756
Patrick Venture0b02be92018-08-31 11:55:55 -07001757 auto bootSetting = settings::boot::setting(objects, bootSourceIntf);
Tom Joseph57e8eb72017-09-25 18:05:02 +05301758
1759 oneTimeEnabled =
1760 std::get<settings::boot::OneTimeEnabled>(bootSetting);
1761
1762 /*
1763 * Check if the current boot setting is onetime or permanent, if the
1764 * request in the command is otherwise, then set the "Enabled"
1765 * property in one_time object path to 'True' to indicate onetime
1766 * and 'False' to indicate permanent.
1767 *
1768 * Once the onetime/permanent setting is applied, then the bootMode
1769 * and bootSource is updated for the corresponding object.
1770 */
1771 if ((permanent && oneTimeEnabled) ||
1772 (!permanent && !oneTimeEnabled))
1773 {
1774 auto service = ipmi::getService(dbus, enabledIntf, oneTimePath);
1775
Patrick Venture0b02be92018-08-31 11:55:55 -07001776 ipmi::setDbusProperty(dbus, service, oneTimePath, enabledIntf,
1777 "Enabled", !permanent);
Tom Joseph57e8eb72017-09-25 18:05:02 +05301778 }
1779
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001780 auto modeItr = modeIpmiToDbus.find(bootOption);
1781 auto sourceItr = sourceIpmiToDbus.find(bootOption);
1782 if (sourceIpmiToDbus.end() != sourceItr)
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001783 {
Marri Devender Rao81719702018-05-07 00:53:48 -05001784 rc = setBootSource(sourceItr->second);
1785 if (rc != IPMI_CC_OK)
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001786 {
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001787 *data_len = 0;
Marri Devender Rao81719702018-05-07 00:53:48 -05001788 return rc;
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001789 }
Marri Devender Rao54fa1302018-05-07 01:06:23 -05001790 // If a set boot device is mapping to a boot source, then reset
1791 // the boot mode D-Bus property to default.
1792 // This way the ipmid code can determine which property is not
1793 // at the default value
Patrick Venture0b02be92018-08-31 11:55:55 -07001794 if (sourceItr->second != Source::Sources::Default)
Marri Devender Rao54fa1302018-05-07 01:06:23 -05001795 {
1796 setBootMode(Mode::Modes::Regular);
1797 }
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001798 }
1799 if (modeIpmiToDbus.end() != modeItr)
1800 {
Marri Devender Rao81719702018-05-07 00:53:48 -05001801 rc = setBootMode(modeItr->second);
1802 if (rc != IPMI_CC_OK)
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001803 {
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001804 *data_len = 0;
Marri Devender Rao81719702018-05-07 00:53:48 -05001805 return rc;
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001806 }
Marri Devender Rao54fa1302018-05-07 01:06:23 -05001807 // If a set boot device is mapping to a boot mode, then reset
1808 // the boot source D-Bus property to default.
1809 // This way the ipmid code can determine which property is not
1810 // at the default value
Patrick Venture0b02be92018-08-31 11:55:55 -07001811 if (modeItr->second != Mode::Modes::Regular)
Marri Devender Rao54fa1302018-05-07 01:06:23 -05001812 {
1813 setBootSource(Source::Sources::Default);
1814 }
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001815 }
Jia, chunhui67c5e5d2019-05-06 11:29:54 +08001816 if ((modeIpmiToDbus.end() == modeItr) &&
1817 (sourceIpmiToDbus.end() == sourceItr))
1818 {
1819 // return error if boot option is not supported
1820 *data_len = 0;
1821 return IPMI_CC_INVALID_FIELD_REQUEST;
1822 }
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001823 }
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001824 catch (InternalFailure& e)
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001825 {
James Feist225dec82019-11-26 16:25:06 -08001826 objectsPtr.reset();
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001827 report<InternalFailure>();
1828 *data_len = 0;
1829 return IPMI_CC_UNSPECIFIED_ERROR;
shgoupfd84fbbf2015-12-17 10:05:51 +08001830 }
Patrick Venture0b02be92018-08-31 11:55:55 -07001831 }
1832 else if (reqptr->parameter ==
1833 (uint8_t)BootOptionParameter::OPAL_NETWORK_SETTINGS)
1834 {
Ratan Guptafd28dd72016-08-01 04:58:01 -05001835
1836 int ret = setHostNetworkData(reqptr);
Patrick Venture0b02be92018-08-31 11:55:55 -07001837 if (ret < 0)
1838 {
Aditya Saripalli5fb14602017-11-09 14:46:27 +05301839 log<level::ERR>(
Patrick Venture0b02be92018-08-31 11:55:55 -07001840 "setHostNetworkData failed for set_sys_boot_options");
Ratan Guptafd28dd72016-08-01 04:58:01 -05001841 rc = IPMI_CC_UNSPECIFIED_ERROR;
1842 }
Patrick Venture0b02be92018-08-31 11:55:55 -07001843 }
1844 else if (reqptr->parameter ==
1845 static_cast<uint8_t>(BootOptionParameter::BOOT_INFO))
1846 {
Tom Josephf536c902017-09-25 18:08:15 +05301847 // Handle parameter #4 and return command completed normally
1848 // (IPMI_CC_OK). There is no implementation in OpenBMC for this
1849 // parameter. This is added to support the ipmitool command `chassis
1850 // bootdev` which sends set on parameter #4, before setting the boot
1851 // flags.
1852 rc = IPMI_CC_OK;
Patrick Venture0b02be92018-08-31 11:55:55 -07001853 }
1854 else
1855 {
1856 log<level::ERR>("Unsupported parameter",
1857 entry("PARAM=0x%x", reqptr->parameter));
shgoupfd84fbbf2015-12-17 10:05:51 +08001858 rc = IPMI_CC_PARM_NOT_SUPPORTED;
Adriana Kobylak40814c62015-10-27 15:58:44 -05001859 }
1860
1861 return rc;
1862}
1863
anil kumar appanaa5a76eb2019-04-30 14:57:24 +00001864/** @brief implements Get POH counter command
1865 * @parameter
1866 * - none
1867 * @returns IPMI completion code plus response data
1868 * - minPerCount - Minutes per count
1869 * - counterReading - counter reading
1870 */
1871ipmi::RspType<uint8_t, // Minutes per count
1872 uint32_t // Counter reading
1873 >
1874 ipmiGetPOHCounter()
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -05001875{
1876 // sd_bus error
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -05001877 try
1878 {
anil kumar appanaa5a76eb2019-04-30 14:57:24 +00001879 return ipmi::responseSuccess(static_cast<uint8_t>(poh::minutesPerCount),
1880 getPOHCounter());
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -05001881 }
1882 catch (std::exception& e)
1883 {
1884 log<level::ERR>(e.what());
anil kumar appanaa5a76eb2019-04-30 14:57:24 +00001885 return ipmi::responseUnspecifiedError();
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -05001886 }
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -05001887}
1888
Jason M. Billsbc996a32019-06-17 15:46:37 -07001889ipmi::RspType<uint3_t, // policy support
1890 uint5_t // reserved
1891 >
Vernon Mauerye278ead2018-10-09 09:23:43 -07001892 ipmiChassisSetPowerRestorePolicy(boost::asio::yield_context yield,
Jason M. Billsbc996a32019-06-17 15:46:37 -07001893 uint3_t policy, uint5_t reserved)
Yong Lic6713cf2018-09-12 12:35:13 +08001894{
Yong Lic6713cf2018-09-12 12:35:13 +08001895 power_policy::DbusValue value =
1896 power_policy::RestorePolicy::Policy::AlwaysOff;
1897
Jason M. Billsbc996a32019-06-17 15:46:37 -07001898 if (reserved || (policy > power_policy::noChange))
Yong Lic6713cf2018-09-12 12:35:13 +08001899 {
Vernon Mauerye278ead2018-10-09 09:23:43 -07001900 phosphor::logging::log<level::ERR>(
1901 "Reserved request parameter",
1902 entry("REQ=0x%x", static_cast<int>(policy)));
Jason M. Billsbc996a32019-06-17 15:46:37 -07001903 return ipmi::responseInvalidFieldRequest();
Yong Lic6713cf2018-09-12 12:35:13 +08001904 }
1905
Vernon Mauerye278ead2018-10-09 09:23:43 -07001906 if (policy == power_policy::noChange)
Yong Lic6713cf2018-09-12 12:35:13 +08001907 {
1908 // just return the supported policy
Jason M. Billsbc996a32019-06-17 15:46:37 -07001909 return ipmi::responseSuccess(power_policy::allSupport, reserved);
Yong Lic6713cf2018-09-12 12:35:13 +08001910 }
1911
1912 for (auto const& it : power_policy::dbusToIpmi)
1913 {
Vernon Mauerye278ead2018-10-09 09:23:43 -07001914 if (it.second == policy)
Yong Lic6713cf2018-09-12 12:35:13 +08001915 {
1916 value = it.first;
1917 break;
1918 }
1919 }
1920
1921 try
1922 {
James Feist225dec82019-11-26 16:25:06 -08001923 settings::Objects& objects = chassis::internal::cache::getObjects();
Yong Lic6713cf2018-09-12 12:35:13 +08001924 const settings::Path& powerRestoreSetting =
James Feist225dec82019-11-26 16:25:06 -08001925 objects.map.at(chassis::internal::powerRestoreIntf).front();
Vernon Mauery16b86932019-05-01 08:36:11 -07001926 std::variant<std::string> property = convertForMessage(value);
Yong Lic6713cf2018-09-12 12:35:13 +08001927
Vernon Mauerye278ead2018-10-09 09:23:43 -07001928 auto sdbusp = getSdBus();
1929 boost::system::error_code ec;
1930 sdbusp->yield_method_call<void>(
1931 yield, ec,
James Feist225dec82019-11-26 16:25:06 -08001932 objects
Yong Lic6713cf2018-09-12 12:35:13 +08001933 .service(powerRestoreSetting,
1934 chassis::internal::powerRestoreIntf)
1935 .c_str(),
Vernon Mauerye278ead2018-10-09 09:23:43 -07001936 powerRestoreSetting, ipmi::PROP_INTF, "Set",
1937 chassis::internal::powerRestoreIntf, "PowerRestorePolicy",
1938 property);
1939 if (ec)
Yong Lic6713cf2018-09-12 12:35:13 +08001940 {
1941 phosphor::logging::log<level::ERR>("Unspecified Error");
Vernon Mauerye278ead2018-10-09 09:23:43 -07001942 return ipmi::responseUnspecifiedError();
Yong Lic6713cf2018-09-12 12:35:13 +08001943 }
1944 }
1945 catch (InternalFailure& e)
1946 {
James Feist225dec82019-11-26 16:25:06 -08001947 chassis::internal::cache::objectsPtr.reset();
Yong Lic6713cf2018-09-12 12:35:13 +08001948 report<InternalFailure>();
Vernon Mauerye278ead2018-10-09 09:23:43 -07001949 return ipmi::responseUnspecifiedError();
Yong Lic6713cf2018-09-12 12:35:13 +08001950 }
1951
Jason M. Billsbc996a32019-06-17 15:46:37 -07001952 return ipmi::responseSuccess(power_policy::allSupport, reserved);
Yong Lic6713cf2018-09-12 12:35:13 +08001953}
1954
Adriana Kobylak40814c62015-10-27 15:58:44 -05001955void register_netfn_chassis_functions()
1956{
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001957 createIdentifyTimer();
1958
Tom05732372016-09-06 17:21:23 +05301959 // Get Chassis Capabilities
anil kumar appana43263c62019-05-27 12:45:04 +00001960 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis,
1961 ipmi::chassis::cmdGetChassisCapabilities,
1962 ipmi::Privilege::User, ipmiGetChassisCap);
Nan Li8d15fb42016-08-16 22:29:40 +08001963
Yong Liae4b0402018-11-02 11:12:14 +08001964 // Set Chassis Capabilities
anil kumar appana894d0222019-05-27 16:32:14 +00001965 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis,
1966 ipmi::chassis::cmdSetChassisCapabilities,
1967 ipmi::Privilege::User, ipmiSetChassisCap);
Yong Liae4b0402018-11-02 11:12:14 +08001968
Tom05732372016-09-06 17:21:23 +05301969 // <Get System Boot Options>
Tom05732372016-09-06 17:21:23 +05301970 ipmi_register_callback(NETFUN_CHASSIS, IPMI_CMD_GET_SYS_BOOT_OPTIONS, NULL,
Patrick Venture0b02be92018-08-31 11:55:55 -07001971 ipmi_chassis_get_sys_boot_options,
1972 PRIVILEGE_OPERATOR);
Adriana Kobylak40814c62015-10-27 15:58:44 -05001973
Tom05732372016-09-06 17:21:23 +05301974 // <Get Chassis Status>
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001975 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis,
1976 ipmi::chassis::cmdGetChassisStatus,
1977 ipmi::Privilege::User, ipmiGetChassisStatus);
Nan Lifdd8ec52016-08-28 03:57:40 +08001978
Vijay Khemka074f64d2020-03-03 15:08:43 -08001979 // <Chassis Get System Restart Cause>
1980 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis,
1981 ipmi::chassis::cmdGetSystemRestartCause,
1982 ipmi::Privilege::User, ipmiGetSystemRestartCause);
1983
Tom05732372016-09-06 17:21:23 +05301984 // <Chassis Control>
anil kumar appanadafff5f2019-04-27 18:06:00 +00001985 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis,
1986 ipmi::chassis::cmdChassisControl,
1987 ipmi::Privilege::Operator, ipmiChassisControl);
shgoupfd84fbbf2015-12-17 10:05:51 +08001988
Tom Joseph5110c122018-03-23 17:55:40 +05301989 // <Chassis Identify>
Vernon Mauery400cc782018-10-09 13:49:53 -07001990 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis,
1991 ipmi::chassis::cmdChassisIdentify,
1992 ipmi::Privilege::Operator, ipmiChassisIdentify);
Tom Joseph5110c122018-03-23 17:55:40 +05301993
Tom05732372016-09-06 17:21:23 +05301994 // <Set System Boot Options>
Tom05732372016-09-06 17:21:23 +05301995 ipmi_register_callback(NETFUN_CHASSIS, IPMI_CMD_SET_SYS_BOOT_OPTIONS, NULL,
Patrick Venture0b02be92018-08-31 11:55:55 -07001996 ipmi_chassis_set_sys_boot_options,
1997 PRIVILEGE_OPERATOR);
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -05001998 // <Get POH Counter>
anil kumar appanaa5a76eb2019-04-30 14:57:24 +00001999 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis,
2000 ipmi::chassis::cmdGetPohCounter,
2001 ipmi::Privilege::User, ipmiGetPOHCounter);
Yong Lic6713cf2018-09-12 12:35:13 +08002002
2003 // <Set Power Restore Policy>
Vernon Mauerye278ead2018-10-09 09:23:43 -07002004 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis,
2005 ipmi::chassis::cmdSetPowerRestorePolicy,
2006 ipmi::Privilege::Operator,
2007 ipmiChassisSetPowerRestorePolicy);
vishwa36993272015-11-20 12:43:49 -06002008}