blob: 89d3e003a4a5a6ea9189adee7cd52de61dc507fd [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
Vernon Mauerye08fbff2019-04-03 09:19:34 -070011#include <ipmid/api.hpp>
Vernon Mauery33250242019-03-12 16:49:26 -070012#include <ipmid/types.hpp>
Vernon Mauery6a98fe72019-03-11 15:57:48 -070013#include <ipmid/utils.hpp>
Patrick Venture3a5071a2018-09-12 13:27:42 -070014#include <phosphor-logging/elog-errors.hpp>
15#include <phosphor-logging/log.hpp>
16#include <sdbusplus/bus.hpp>
William A. Kennington III4c008022018-10-12 17:18:14 -070017#include <sdbusplus/message/types.hpp>
Patrick Venture3a5071a2018-09-12 13:27:42 -070018#include <sdbusplus/server/object.hpp>
Vernon Mauery1181af72018-10-08 12:05:00 -070019#include <sdbusplus/timer.hpp>
Vernon Mauerye278ead2018-10-09 09:23:43 -070020#include <settings.hpp>
Patrick Venture3a5071a2018-09-12 13:27:42 -070021#include <xyz/openbmc_project/Common/error.hpp>
22#include <xyz/openbmc_project/Control/Boot/Mode/server.hpp>
23#include <xyz/openbmc_project/Control/Boot/Source/server.hpp>
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +030024#include <xyz/openbmc_project/Control/Boot/Type/server.hpp>
Patrick Venture3a5071a2018-09-12 13:27:42 -070025#include <xyz/openbmc_project/Control/Power/RestorePolicy/server.hpp>
Jason M. Billsad588bf2020-01-30 16:18:33 -080026#include <xyz/openbmc_project/State/Chassis/server.hpp>
Patrick Venture3a5071a2018-09-12 13:27:42 -070027#include <xyz/openbmc_project/State/Host/server.hpp>
28#include <xyz/openbmc_project/State/PowerOnHours/server.hpp>
29
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -050030#include <array>
31#include <chrono>
32#include <cstring>
33#include <filesystem>
34#include <fstream>
35#include <future>
36#include <map>
37#include <sstream>
38#include <string>
39
Lei YU4b0ddb62019-01-25 16:43:50 +080040std::unique_ptr<phosphor::Timer> identifyTimer
41 __attribute__((init_priority(101)));
Marri Devender Rao6706c1c2018-05-14 00:29:38 -050042
Yong Lif4e38512019-05-21 14:46:55 +080043static ChassisIDState chassisIDState = ChassisIDState::reserved;
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +000044static constexpr uint8_t setParmVersion = 0x01;
Yong Lif4e38512019-05-21 14:46:55 +080045
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +000046constexpr size_t sizeVersion = 2;
Tom Joseph5110c122018-03-23 17:55:40 +053047constexpr size_t DEFAULT_IDENTIFY_TIME_OUT = 15;
Ratan Gupta6ec7daa2017-07-15 14:13:01 +053048
Patrick Venture0b02be92018-08-31 11:55:55 -070049// PetiBoot-Specific
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +000050static constexpr uint8_t netConfInitialBytes[] = {0x80, 0x21, 0x70, 0x62,
51 0x21, 0x00, 0x01, 0x06};
52static constexpr uint8_t oemParmStart = 96;
53static constexpr uint8_t oemParmEnd = 127;
Ratan Guptafd28dd72016-08-01 04:58:01 -050054
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +000055static constexpr size_t cookieOffset = 1;
56static constexpr size_t versionOffset = 5;
57static constexpr size_t addrSizeOffset = 8;
58static constexpr size_t macOffset = 9;
59static constexpr size_t addrTypeOffset = 16;
60static constexpr size_t ipAddrOffset = 17;
ratagupta6f6bff2016-04-04 06:20:11 -050061
Marri Devender Rao6706c1c2018-05-14 00:29:38 -050062static constexpr size_t encIdentifyObjectsSize = 1;
63static constexpr size_t chassisIdentifyReqLength = 2;
64static constexpr size_t identifyIntervalPos = 0;
65static constexpr size_t forceIdentifyPos = 1;
shgoupfd84fbbf2015-12-17 10:05:51 +080066
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +000067namespace ipmi
68{
69constexpr Cc ccParmNotSupported = 0x80;
70
71static inline auto responseParmNotSupported()
72{
73 return response(ccParmNotSupported);
74}
75} // namespace ipmi
76
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";
Patrick Williams7345ac42021-04-30 20:57:39 -050095static constexpr auto pohCounterProperty = "POHCounter";
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -050096static 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
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +0300135constexpr auto bootSettingsPath = "/xyz/openbmc_project/control/host0/boot";
136constexpr auto bootEnableIntf = "xyz.openbmc_project.Object.Enable";
Deepak Kodihalli8cc19362017-07-21 11:18:38 -0500137constexpr auto bootModeIntf = "xyz.openbmc_project.Control.Boot.Mode";
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +0300138constexpr auto bootTypeIntf = "xyz.openbmc_project.Control.Boot.Type";
Deepak Kodihalli8cc19362017-07-21 11:18:38 -0500139constexpr auto bootSourceIntf = "xyz.openbmc_project.Control.Boot.Source";
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +0300140constexpr auto bootSettingsOneTimePath =
141 "/xyz/openbmc_project/control/host0/boot/one_time";
142constexpr auto bootOneTimeIntf = "xyz.openbmc_project.Object.Enable";
143
Deepak Kodihalli18b70d12017-07-21 13:36:33 -0500144constexpr auto powerRestoreIntf =
145 "xyz.openbmc_project.Control.Power.RestorePolicy";
Patrick Williams5d82f472022-07-22 19:26:53 -0500146sdbusplus::bus_t dbus(ipmid_get_sd_bus_connection());
Deepak Kodihalli8cc19362017-07-21 11:18:38 -0500147
148namespace cache
149{
150
James Feist225dec82019-11-26 16:25:06 -0800151std::unique_ptr<settings::Objects> objectsPtr = nullptr;
152
153settings::Objects& getObjects()
154{
155 if (objectsPtr == nullptr)
156 {
157 objectsPtr = std::make_unique<settings::Objects>(
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +0300158 dbus, std::vector<std::string>{bootModeIntf, bootTypeIntf,
159 bootSourceIntf, powerRestoreIntf});
James Feist225dec82019-11-26 16:25:06 -0800160 }
161 return *objectsPtr;
162}
Deepak Kodihalli8cc19362017-07-21 11:18:38 -0500163
164} // namespace cache
165} // namespace internal
166} // namespace chassis
167
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -0500168namespace poh
169{
170
171constexpr auto minutesPerCount = 60;
172
173} // namespace poh
174
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000175int getHostNetworkData(ipmi::message::Payload& payload)
Ratan Guptafd28dd72016-08-01 04:58:01 -0500176{
Ratan Guptadcb10672017-07-10 10:33:50 +0530177 ipmi::PropertyMap properties;
178 int rc = 0;
Ratan Gupta8c31d232017-08-13 05:49:43 +0530179 uint8_t addrSize = ipmi::network::IPV4_ADDRESS_SIZE_BYTE;
Ratan Guptafd28dd72016-08-01 04:58:01 -0500180
Ratan Guptadcb10672017-07-10 10:33:50 +0530181 try
182 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700183 // TODO There may be cases where an interface is implemented by multiple
Ratan Guptadcb10672017-07-10 10:33:50 +0530184 // objects,to handle such cases we are interested on that object
185 // which are on interested busname.
186 // Currenlty mapper doesn't give the readable busname(gives busid)
187 // so we can't match with bus name so giving some object specific info
188 // as SETTINGS_MATCH.
189 // Later SETTINGS_MATCH will be replaced with busname.
Ratan Guptafd28dd72016-08-01 04:58:01 -0500190
Patrick Williams5d82f472022-07-22 19:26:53 -0500191 sdbusplus::bus_t bus(ipmid_get_sd_bus_connection());
Ratan Guptadcb10672017-07-10 10:33:50 +0530192
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530193 auto ipObjectInfo = ipmi::getDbusObject(bus, IP_INTERFACE,
194 SETTINGS_ROOT, SETTINGS_MATCH);
195
196 auto macObjectInfo = ipmi::getDbusObject(bus, MAC_INTERFACE,
197 SETTINGS_ROOT, SETTINGS_MATCH);
198
Patrick Venture0b02be92018-08-31 11:55:55 -0700199 properties = ipmi::getAllDbusProperties(
200 bus, ipObjectInfo.second, ipObjectInfo.first, IP_INTERFACE);
201 auto variant = ipmi::getDbusProperty(bus, macObjectInfo.second,
202 macObjectInfo.first, MAC_INTERFACE,
203 "MACAddress");
Ratan Guptadcb10672017-07-10 10:33:50 +0530204
Vernon Maueryf442e112019-04-09 11:44:36 -0700205 auto ipAddress = std::get<std::string>(properties["Address"]);
Ratan Guptad70f4532017-08-04 02:07:31 +0530206
Vernon Maueryf442e112019-04-09 11:44:36 -0700207 auto gateway = std::get<std::string>(properties["Gateway"]);
Ratan Guptad70f4532017-08-04 02:07:31 +0530208
Vernon Maueryf442e112019-04-09 11:44:36 -0700209 auto prefix = std::get<uint8_t>(properties["PrefixLength"]);
Ratan Guptad70f4532017-08-04 02:07:31 +0530210
Patrick Venture0b02be92018-08-31 11:55:55 -0700211 uint8_t isStatic =
Vernon Maueryf442e112019-04-09 11:44:36 -0700212 (std::get<std::string>(properties["Origin"]) ==
Patrick Venture0b02be92018-08-31 11:55:55 -0700213 "xyz.openbmc_project.Network.IP.AddressOrigin.Static")
214 ? 1
215 : 0;
Ratan Guptad70f4532017-08-04 02:07:31 +0530216
Vernon Maueryf442e112019-04-09 11:44:36 -0700217 auto MACAddress = std::get<std::string>(variant);
Ratan Guptacc8feb42017-07-25 21:52:10 +0530218
Ratan Guptad70f4532017-08-04 02:07:31 +0530219 // it is expected here that we should get the valid data
220 // but we may also get the default values.
221 // Validation of the data is done by settings.
222 //
223 // if mac address is default mac address then
224 // don't send blank override.
Ratan Gupta8c31d232017-08-13 05:49:43 +0530225 if ((MACAddress == ipmi::network::DEFAULT_MAC_ADDRESS))
Ratan Guptad70f4532017-08-04 02:07:31 +0530226 {
Ratan Guptad70f4532017-08-04 02:07:31 +0530227 rc = -1;
228 return rc;
229 }
230 // if addr is static then ipaddress,gateway,prefix
231 // should not be default one,don't send blank override.
232 if (isStatic)
233 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700234 if ((ipAddress == ipmi::network::DEFAULT_ADDRESS) ||
235 (gateway == ipmi::network::DEFAULT_ADDRESS) || (!prefix))
Ratan Guptad70f4532017-08-04 02:07:31 +0530236 {
Ratan Guptad70f4532017-08-04 02:07:31 +0530237 rc = -1;
238 return rc;
239 }
240 }
241
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000242 std::string token;
243 std::stringstream ss(MACAddress);
Ratan Guptadcb10672017-07-10 10:33:50 +0530244
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000245 // First pack macOffset no of bytes in payload.
246 // Latter this PetiBoot-Specific data will be populated.
247 std::vector<uint8_t> payloadInitialBytes(macOffset);
248 payload.pack(payloadInitialBytes);
Ratan Guptadcb10672017-07-10 10:33:50 +0530249
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000250 while (std::getline(ss, token, ':'))
251 {
252 payload.pack(stoi(token, nullptr, 16));
253 }
254
255 payload.pack(0x00);
256
257 payload.pack(isStatic);
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530258
Vernon Maueryf442e112019-04-09 11:44:36 -0700259 uint8_t addressFamily = (std::get<std::string>(properties["Type"]) ==
260 "xyz.openbmc_project.Network.IP.Protocol.IPv4")
261 ? AF_INET
262 : AF_INET6;
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530263
Patrick Venture0b02be92018-08-31 11:55:55 -0700264 addrSize = (addressFamily == AF_INET)
265 ? ipmi::network::IPV4_ADDRESS_SIZE_BYTE
266 : ipmi::network::IPV6_ADDRESS_SIZE_BYTE;
Ratan Guptadcb10672017-07-10 10:33:50 +0530267
268 // ipaddress and gateway would be in IPv4 format
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000269 std::vector<uint8_t> addrInBinary(addrSize);
Ratan Guptad70f4532017-08-04 02:07:31 +0530270 inet_pton(addressFamily, ipAddress.c_str(),
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000271 reinterpret_cast<void*>(addrInBinary.data()));
Ratan Guptadcb10672017-07-10 10:33:50 +0530272
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000273 payload.pack(addrInBinary);
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530274
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000275 payload.pack(prefix);
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530276
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000277 std::vector<uint8_t> gatewayDetails(addrSize);
Ratan Guptad70f4532017-08-04 02:07:31 +0530278 inet_pton(addressFamily, gateway.c_str(),
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000279 reinterpret_cast<void*>(gatewayDetails.data()));
280 payload.pack(gatewayDetails);
Ratan Guptadcb10672017-07-10 10:33:50 +0530281 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -0500282 catch (const InternalFailure& e)
Ratan Guptadcb10672017-07-10 10:33:50 +0530283 {
284 commit<InternalFailure>();
Ratan Guptadcb10672017-07-10 10:33:50 +0530285 rc = -1;
Ratan Guptafd28dd72016-08-01 04:58:01 -0500286 return rc;
287 }
288
Patrick Venture0b02be92018-08-31 11:55:55 -0700289 // PetiBoot-Specific
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000290 // If success then copy the first 9 bytes to the payload message
291 // payload first 2 bytes contain the parameter values. Skip that 2 bytes.
292 uint8_t skipFirstTwoBytes = 2;
293 size_t payloadSize = payload.size();
294 uint8_t* configDataStartingAddress = payload.data() + skipFirstTwoBytes;
Ratan Guptafd28dd72016-08-01 04:58:01 -0500295
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000296 if (payloadSize < skipFirstTwoBytes + sizeof(netConfInitialBytes))
297 {
298 log<level::ERR>("Invalid net config ");
299 rc = -1;
300 return rc;
301 }
302 std::copy(netConfInitialBytes,
303 netConfInitialBytes + sizeof(netConfInitialBytes),
304 configDataStartingAddress);
305
306 if (payloadSize < skipFirstTwoBytes + addrSizeOffset + sizeof(addrSize))
307 {
308 log<level::ERR>("Invalid length of address size");
309 rc = -1;
310 return rc;
311 }
312 std::copy(&addrSize, &(addrSize) + sizeof(addrSize),
313 configDataStartingAddress + addrSizeOffset);
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530314
Ratan Guptafd28dd72016-08-01 04:58:01 -0500315#ifdef _IPMI_DEBUG_
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700316 std::printf("\n===Printing the IPMI Formatted Data========\n");
Ratan Guptafd28dd72016-08-01 04:58:01 -0500317
Ratan Guptadcb10672017-07-10 10:33:50 +0530318 for (uint8_t pos = 0; pos < index; pos++)
319 {
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000320 std::printf("%02x ", payloadStartingAddress[pos]);
Ratan Guptadcb10672017-07-10 10:33:50 +0530321 }
Ratan Guptafd28dd72016-08-01 04:58:01 -0500322#endif
323
Ratan Guptafd28dd72016-08-01 04:58:01 -0500324 return rc;
325}
326
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530327/** @brief convert IPv4 and IPv6 addresses from binary to text form.
328 * @param[in] family - IPv4/Ipv6
329 * @param[in] data - req data pointer.
330 * @param[in] offset - offset in the data.
331 * @param[in] addrSize - size of the data which needs to be read from offset.
332 * @returns address in text form.
333 */
334
Patrick Venture0b02be92018-08-31 11:55:55 -0700335std::string getAddrStr(uint8_t family, uint8_t* data, uint8_t offset,
336 uint8_t addrSize)
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530337{
338 char ipAddr[INET6_ADDRSTRLEN] = {};
339
Patrick Venture0b02be92018-08-31 11:55:55 -0700340 switch (family)
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530341 {
342 case AF_INET:
343 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700344 struct sockaddr_in addr4
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -0500345 {};
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700346 std::memcpy(&addr4.sin_addr.s_addr, &data[offset], addrSize);
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530347
Patrick Venture0b02be92018-08-31 11:55:55 -0700348 inet_ntop(AF_INET, &addr4.sin_addr, ipAddr, INET_ADDRSTRLEN);
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530349
350 break;
351 }
352 case AF_INET6:
353 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700354 struct sockaddr_in6 addr6
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -0500355 {};
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700356 std::memcpy(&addr6.sin6_addr.s6_addr, &data[offset], addrSize);
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530357
Patrick Venture0b02be92018-08-31 11:55:55 -0700358 inet_ntop(AF_INET6, &addr6.sin6_addr, ipAddr, INET6_ADDRSTRLEN);
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530359
360 break;
361 }
362 default:
363 {
364 return {};
365 }
366 }
367
368 return ipAddr;
369}
370
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000371ipmi::Cc setHostNetworkData(ipmi::message::Payload& data)
Ratan Guptafd28dd72016-08-01 04:58:01 -0500372{
Ratan Guptadcb10672017-07-10 10:33:50 +0530373 using namespace std::string_literals;
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000374 std::string hostNetworkConfig;
375 std::string mac("00:00:00:00:00:00");
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530376 std::string ipAddress, gateway;
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000377 std::string addrOrigin{0};
Patrick Venture0b02be92018-08-31 11:55:55 -0700378 uint8_t addrSize{0};
Ratan Guptadcb10672017-07-10 10:33:50 +0530379 std::string addressOrigin =
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530380 "xyz.openbmc_project.Network.IP.AddressOrigin.DHCP";
Patrick Venture0b02be92018-08-31 11:55:55 -0700381 std::string addressType = "xyz.openbmc_project.Network.IP.Protocol.IPv4";
382 uint8_t prefix{0};
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530383 uint8_t family = AF_INET;
Ratan Guptafd28dd72016-08-01 04:58:01 -0500384
Patrick Venture0b02be92018-08-31 11:55:55 -0700385 // cookie starts from second byte
Ratan Guptafd28dd72016-08-01 04:58:01 -0500386 // version starts from sixth byte
387
Ratan Guptadcb10672017-07-10 10:33:50 +0530388 try
Ratan Guptafd28dd72016-08-01 04:58:01 -0500389 {
Ratan Guptadcb10672017-07-10 10:33:50 +0530390 do
391 {
392 // cookie == 0x21 0x70 0x62 0x21
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000393 data.trailingOk = true;
394 auto msgLen = data.size();
395 std::vector<uint8_t> msgPayloadBytes(msgLen);
396 if (data.unpack(msgPayloadBytes) != 0 || !data.fullyUnpacked())
Ratan Guptadcb10672017-07-10 10:33:50 +0530397 {
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000398 log<level::ERR>(
399 "Error in unpacking message of setHostNetworkData");
400 return ipmi::ccReqDataLenInvalid;
401 }
402
403 uint8_t* msgPayloadStartingPos = msgPayloadBytes.data();
404 constexpr size_t cookieSize = 4;
405 if (msgLen < cookieOffset + cookieSize)
406 {
407 log<level::ERR>(
408 "Error in cookie getting of setHostNetworkData");
409 return ipmi::ccReqDataLenInvalid;
410 }
411 if (std::equal(msgPayloadStartingPos + cookieOffset,
412 msgPayloadStartingPos + cookieOffset + cookieSize,
413 (netConfInitialBytes + cookieOffset)) != 0)
414 {
415 // all cookie == 0
416 if (std::all_of(msgPayloadStartingPos + cookieOffset,
417 msgPayloadStartingPos + cookieOffset +
418 cookieSize,
419 [](int i) { return i == 0; }) == true)
Ratan Guptadcb10672017-07-10 10:33:50 +0530420 {
421 // need to zero out the network settings.
422 break;
423 }
424
425 log<level::ERR>("Invalid Cookie");
426 elog<InternalFailure>();
427 }
428
429 // vesion == 0x00 0x01
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000430 if (msgLen < versionOffset + sizeVersion)
Ratan Guptadcb10672017-07-10 10:33:50 +0530431 {
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000432 log<level::ERR>(
433 "Error in version getting of setHostNetworkData");
434 return ipmi::ccReqDataLenInvalid;
435 }
436 if (std::equal(msgPayloadStartingPos + versionOffset,
437 msgPayloadStartingPos + versionOffset + sizeVersion,
438 (netConfInitialBytes + versionOffset)) != 0)
439 {
Ratan Guptadcb10672017-07-10 10:33:50 +0530440 log<level::ERR>("Invalid Version");
441 elog<InternalFailure>();
442 }
443
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000444 if (msgLen < macOffset + 6)
445 {
446 log<level::ERR>(
447 "Error in mac address getting of setHostNetworkData");
448 return ipmi::ccReqDataLenInvalid;
449 }
450 std::stringstream result;
451 std::copy((msgPayloadStartingPos + macOffset),
452 (msgPayloadStartingPos + macOffset + 5),
453 std::ostream_iterator<int>(result, ":"));
454 mac = result.str();
Ratan Guptadcb10672017-07-10 10:33:50 +0530455
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000456 if (msgLen < addrTypeOffset + sizeof(decltype(addrOrigin)))
457 {
458 log<level::ERR>(
459 "Error in original address getting of setHostNetworkData");
460 return ipmi::ccReqDataLenInvalid;
461 }
462 std::copy(msgPayloadStartingPos + addrTypeOffset,
463 msgPayloadStartingPos + addrTypeOffset +
464 sizeof(decltype(addrOrigin)),
465 std::ostream_iterator<int>(result, ""));
466 addrOrigin = result.str();
Ratan Guptadcb10672017-07-10 10:33:50 +0530467
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000468 if (!addrOrigin.empty())
Ratan Guptadcb10672017-07-10 10:33:50 +0530469 {
470 addressOrigin =
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530471 "xyz.openbmc_project.Network.IP.AddressOrigin.Static";
Ratan Guptadcb10672017-07-10 10:33:50 +0530472 }
473
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000474 if (msgLen < addrSizeOffset + sizeof(decltype(addrSize)))
475 {
476 log<level::ERR>(
477 "Error in address size getting of setHostNetworkData");
478 return ipmi::ccReqDataLenInvalid;
479 }
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530480 // Get the address size
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000481 std::copy(msgPayloadStartingPos + addrSizeOffset,
482 (msgPayloadStartingPos + addrSizeOffset +
483 sizeof(decltype(addrSize))),
484 &addrSize);
Ratan Guptadcb10672017-07-10 10:33:50 +0530485
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000486 uint8_t prefixOffset = ipAddrOffset + addrSize;
487 if (msgLen < prefixOffset + sizeof(decltype(prefix)))
488 {
489 log<level::ERR>(
490 "Error in prefix getting of setHostNetworkData");
491 return ipmi::ccReqDataLenInvalid;
492 }
William A. Kennington III4c521022023-07-28 13:07:30 -0700493 // std::copy(msgPayloadStartingPos + prefixOffset,
494 // msgPayloadStartingPos + prefixOffset +
495 // sizeof(decltype(prefix)),
496 // &prefix);
497 // Workaround compiler misdetecting out of bounds memcpy
498 prefix = msgPayloadStartingPos[prefixOffset];
Ratan Guptadcb10672017-07-10 10:33:50 +0530499
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530500 uint8_t gatewayOffset = prefixOffset + sizeof(decltype(prefix));
Ratan Gupta8c31d232017-08-13 05:49:43 +0530501 if (addrSize != ipmi::network::IPV4_ADDRESS_SIZE_BYTE)
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530502 {
503 addressType = "xyz.openbmc_project.Network.IP.Protocol.IPv6";
504 family = AF_INET6;
505 }
506
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000507 if (msgLen < ipAddrOffset + addrSize)
508 {
509 log<level::ERR>(
510 "Error in IP address getting of setHostNetworkData");
511 return ipmi::ccReqDataLenInvalid;
512 }
513 ipAddress = getAddrStr(family, msgPayloadStartingPos, ipAddrOffset,
514 addrSize);
Ratan Guptad70f4532017-08-04 02:07:31 +0530515
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000516 if (msgLen < gatewayOffset + addrSize)
517 {
518 log<level::ERR>(
519 "Error in gateway address getting of setHostNetworkData");
520 return ipmi::ccReqDataLenInvalid;
521 }
522 gateway = getAddrStr(family, msgPayloadStartingPos, gatewayOffset,
523 addrSize);
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530524
Patrick Venture0b02be92018-08-31 11:55:55 -0700525 } while (0);
Ratan Guptadcb10672017-07-10 10:33:50 +0530526
Patrick Venture0b02be92018-08-31 11:55:55 -0700527 // Cookie == 0 or it is a valid cookie
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000528 hostNetworkConfig += "ipaddress="s + ipAddress + ",prefix="s +
529 std::to_string(prefix) + ",gateway="s + gateway +
530 ",mac="s + mac + ",addressOrigin="s +
531 addressOrigin;
Ratan Guptafd28dd72016-08-01 04:58:01 -0500532
Patrick Williams5d82f472022-07-22 19:26:53 -0500533 sdbusplus::bus_t bus(ipmid_get_sd_bus_connection());
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530534
535 auto ipObjectInfo = ipmi::getDbusObject(bus, IP_INTERFACE,
536 SETTINGS_ROOT, SETTINGS_MATCH);
537 auto macObjectInfo = ipmi::getDbusObject(bus, MAC_INTERFACE,
538 SETTINGS_ROOT, SETTINGS_MATCH);
Ratan Guptadcb10672017-07-10 10:33:50 +0530539 // set the dbus property
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530540 ipmi::setDbusProperty(bus, ipObjectInfo.second, ipObjectInfo.first,
Patrick Venture0b02be92018-08-31 11:55:55 -0700541 IP_INTERFACE, "Address", std::string(ipAddress));
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530542 ipmi::setDbusProperty(bus, ipObjectInfo.second, ipObjectInfo.first,
Patrick Venture0b02be92018-08-31 11:55:55 -0700543 IP_INTERFACE, "PrefixLength", prefix);
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530544 ipmi::setDbusProperty(bus, ipObjectInfo.second, ipObjectInfo.first,
Patrick Venture0b02be92018-08-31 11:55:55 -0700545 IP_INTERFACE, "Origin", addressOrigin);
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530546 ipmi::setDbusProperty(bus, ipObjectInfo.second, ipObjectInfo.first,
Patrick Venture0b02be92018-08-31 11:55:55 -0700547 IP_INTERFACE, "Gateway", std::string(gateway));
548 ipmi::setDbusProperty(
549 bus, ipObjectInfo.second, ipObjectInfo.first, IP_INTERFACE, "Type",
550 std::string("xyz.openbmc_project.Network.IP.Protocol.IPv4"));
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530551 ipmi::setDbusProperty(bus, macObjectInfo.second, macObjectInfo.first,
Patrick Venture0b02be92018-08-31 11:55:55 -0700552 MAC_INTERFACE, "MACAddress", std::string(mac));
Ratan Guptafd28dd72016-08-01 04:58:01 -0500553
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000554 log<level::DEBUG>("Network configuration changed",
555 entry("NETWORKCONFIG=%s", hostNetworkConfig.c_str()));
Ratan Guptafd28dd72016-08-01 04:58:01 -0500556 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -0500557 catch (const sdbusplus::exception_t& e)
Ratan Guptadcb10672017-07-10 10:33:50 +0530558 {
559 commit<InternalFailure>();
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000560 log<level::ERR>("Error in ipmiChassisSetSysBootOptions call");
561 return ipmi::ccUnspecifiedError;
Ratan Guptadcb10672017-07-10 10:33:50 +0530562 }
563
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000564 return ipmi::ccSuccess;
Ratan Guptafd28dd72016-08-01 04:58:01 -0500565}
566
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -0500567uint32_t getPOHCounter()
568{
Patrick Williams5d82f472022-07-22 19:26:53 -0500569 sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()};
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -0500570
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -0500571 auto chassisStateObj = ipmi::getDbusObject(bus, chassisPOHStateIntf,
572 chassisStateRoot, match);
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -0500573
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -0500574 auto service = ipmi::getService(bus, chassisPOHStateIntf,
575 chassisStateObj.first);
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -0500576
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -0500577 auto propValue = ipmi::getDbusProperty(bus, service, chassisStateObj.first,
578 chassisPOHStateIntf,
579 pohCounterProperty);
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -0500580
Vernon Maueryf442e112019-04-09 11:44:36 -0700581 return std::get<uint32_t>(propValue);
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -0500582}
583
anil kumar appana43263c62019-05-27 12:45:04 +0000584/** @brief Implements the get chassis capabilities command
585 *
586 * @returns IPMI completion code plus response data
587 * chassisCapFlags - chassis capability flag
588 * chassisFRUInfoDevAddr - chassis FRU info Device Address
589 * chassisSDRDevAddr - chassis SDR device address
590 * chassisSELDevAddr - chassis SEL device address
591 * chassisSMDevAddr - chassis system management device address
592 * chassisBridgeDevAddr - chassis bridge device address
593 */
Karthick Sundarrajan86d8bd72019-11-26 12:48:50 -0800594ipmi::RspType<bool, // chassis intrusion sensor
595 bool, // chassis Front panel lockout
596 bool, // chassis NMI
597 bool, // chassis power interlock
598 uint4_t, // reserved
anil kumar appana43263c62019-05-27 12:45:04 +0000599 uint8_t, // chassis FRU info Device Address
600 uint8_t, // chassis SDR device address
601 uint8_t, // chassis SEL device address
602 uint8_t, // chassis system management device address
603 uint8_t // chassis bridge device address
604 >
605 ipmiGetChassisCap()
Nan Li8d15fb42016-08-16 22:29:40 +0800606{
anil kumar appana43263c62019-05-27 12:45:04 +0000607 ipmi::PropertyMap properties;
Yong Liae4b0402018-11-02 11:12:14 +0800608 try
609 {
Patrick Williams5d82f472022-07-22 19:26:53 -0500610 sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()};
Nan Li8d15fb42016-08-16 22:29:40 +0800611
Yong Liae4b0402018-11-02 11:12:14 +0800612 ipmi::DbusObjectInfo chassisCapObject =
613 ipmi::getDbusObject(bus, chassisCapIntf);
Nan Li8d15fb42016-08-16 22:29:40 +0800614
Yong Liae4b0402018-11-02 11:12:14 +0800615 // capabilities flags
616 // [7..4] - reserved
617 // [3] – 1b = provides power interlock (IPM 1.5)
618 // [2] – 1b = provides Diagnostic Interrupt (FP NMI)
619 // [1] – 1b = provides “Front Panel Lockout” (indicates that the chassis
620 // has capabilities
621 // to lock out external power control and reset button or
622 // front panel interfaces and/or detect tampering with those
623 // interfaces).
624 // [0] -1b = Chassis provides intrusion (physical security) sensor.
625 // set to default value 0x0.
Nan Li8d15fb42016-08-16 22:29:40 +0800626
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -0500627 properties = ipmi::getAllDbusProperties(bus, chassisCapObject.second,
628 chassisCapObject.first,
629 chassisCapIntf);
Yong Liae4b0402018-11-02 11:12:14 +0800630 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -0500631 catch (const std::exception& e)
Yong Liae4b0402018-11-02 11:12:14 +0800632 {
anil kumar appana43263c62019-05-27 12:45:04 +0000633 log<level::ERR>("Failed to fetch Chassis Capability properties",
634 entry("ERROR=%s", e.what()));
635 return ipmi::responseUnspecifiedError();
Yong Liae4b0402018-11-02 11:12:14 +0800636 }
637
Karthick Sundarrajan86d8bd72019-11-26 12:48:50 -0800638 bool* chassisIntrusionFlag =
639 std::get_if<bool>(&properties[chassisIntrusionProp]);
640 if (chassisIntrusionFlag == nullptr)
anil kumar appana43263c62019-05-27 12:45:04 +0000641 {
Karthick Sundarrajan86d8bd72019-11-26 12:48:50 -0800642 log<level::ERR>("Error to get chassis Intrusion flags");
643 return ipmi::responseUnspecifiedError();
644 }
645 bool* chassisFrontPanelFlag =
646 std::get_if<bool>(&properties[chassisFrontPanelLockoutProp]);
647 if (chassisFrontPanelFlag == nullptr)
648 {
649 log<level::ERR>("Error to get chassis intrusion flags");
650 return ipmi::responseUnspecifiedError();
651 }
652 bool* chassisNMIFlag = std::get_if<bool>(&properties[chassisNMIProp]);
653 if (chassisNMIFlag == nullptr)
654 {
655 log<level::ERR>("Error to get chassis NMI flags");
656 return ipmi::responseUnspecifiedError();
657 }
658 bool* chassisPowerInterlockFlag =
659 std::get_if<bool>(&properties[chassisPowerInterlockProp]);
660 if (chassisPowerInterlockFlag == nullptr)
661 {
662 log<level::ERR>("Error to get chassis power interlock flags");
anil kumar appana43263c62019-05-27 12:45:04 +0000663 return ipmi::responseUnspecifiedError();
664 }
665 uint8_t* chassisFRUInfoDevAddr =
666 std::get_if<uint8_t>(&properties[chassisFRUDevAddrProp]);
667 if (chassisFRUInfoDevAddr == nullptr)
668 {
669 log<level::ERR>("Error to get chassis FRU info device address");
670 return ipmi::responseUnspecifiedError();
671 }
672 uint8_t* chassisSDRDevAddr =
673 std::get_if<uint8_t>(&properties[chassisSDRDevAddrProp]);
674 if (chassisSDRDevAddr == nullptr)
675 {
676 log<level::ERR>("Error to get chassis SDR device address");
677 return ipmi::responseUnspecifiedError();
678 }
679 uint8_t* chassisSELDevAddr =
680 std::get_if<uint8_t>(&properties[chassisSELDevAddrProp]);
681 if (chassisSELDevAddr == nullptr)
682 {
683 log<level::ERR>("Error to get chassis SEL device address");
684 return ipmi::responseUnspecifiedError();
685 }
686 uint8_t* chassisSMDevAddr =
687 std::get_if<uint8_t>(&properties[chassisSMDevAddrProp]);
688 if (chassisSMDevAddr == nullptr)
689 {
690 log<level::ERR>("Error to get chassis SM device address");
691 return ipmi::responseUnspecifiedError();
692 }
693 uint8_t* chassisBridgeDevAddr =
694 std::get_if<uint8_t>(&properties[chassisBridgeDevAddrProp]);
695 if (chassisBridgeDevAddr == nullptr)
696 {
697 log<level::ERR>("Error to get chassis bridge device address");
698 return ipmi::responseUnspecifiedError();
699 }
700
Karthick Sundarrajan86d8bd72019-11-26 12:48:50 -0800701 return ipmi::responseSuccess(*chassisIntrusionFlag, *chassisFrontPanelFlag,
702 *chassisNMIFlag, *chassisPowerInterlockFlag, 0,
703 *chassisFRUInfoDevAddr, *chassisSDRDevAddr,
704 *chassisSELDevAddr, *chassisSMDevAddr,
705 *chassisBridgeDevAddr);
Yong Liae4b0402018-11-02 11:12:14 +0800706}
707
anil kumar appana894d0222019-05-27 16:32:14 +0000708/** @brief implements set chassis capalibities command
709 * @param intrusion - chassis intrusion
710 * @param fpLockout - frontpannel lockout
711 * @param reserved1 - skip one bit
712 * @param fruDeviceAddr - chassis FRU info Device Address
713 * @param sdrDeviceAddr - chassis SDR device address
714 * @param selDeviceAddr - chassis SEL device address
715 * @param smDeviceAddr - chassis system management device address
716 * @param bridgeDeviceAddr - chassis bridge device address
717 *
718 * @returns IPMI completion code
719 */
720ipmi::RspType<> ipmiSetChassisCap(bool intrusion, bool fpLockout,
721 uint6_t reserved1,
722
723 uint8_t fruDeviceAddr,
724
725 uint8_t sdrDeviceAddr,
726
727 uint8_t selDeviceAddr,
728
729 uint8_t smDeviceAddr,
730
731 uint8_t bridgeDeviceAddr)
Yong Liae4b0402018-11-02 11:12:14 +0800732{
Yong Liae4b0402018-11-02 11:12:14 +0800733 // check input data
anil kumar appana894d0222019-05-27 16:32:14 +0000734 if (reserved1 != 0)
Yong Liae4b0402018-11-02 11:12:14 +0800735 {
anil kumar appana894d0222019-05-27 16:32:14 +0000736 log<level::ERR>("Unsupported request parameter");
737 return ipmi::responseInvalidFieldRequest();
Yong Liae4b0402018-11-02 11:12:14 +0800738 }
739
anil kumar appana894d0222019-05-27 16:32:14 +0000740 if ((fruDeviceAddr & ~chassisCapAddrMask) != 0)
Yong Liae4b0402018-11-02 11:12:14 +0800741 {
742 log<level::ERR>("Unsupported request parameter(FRU Addr)",
anil kumar appana894d0222019-05-27 16:32:14 +0000743 entry("REQ=0x%x", fruDeviceAddr));
744 return ipmi::responseInvalidFieldRequest();
Yong Liae4b0402018-11-02 11:12:14 +0800745 }
anil kumar appana894d0222019-05-27 16:32:14 +0000746 if ((sdrDeviceAddr & ~chassisCapAddrMask) != 0)
Yong Liae4b0402018-11-02 11:12:14 +0800747 {
748 log<level::ERR>("Unsupported request parameter(SDR Addr)",
anil kumar appana894d0222019-05-27 16:32:14 +0000749 entry("REQ=0x%x", sdrDeviceAddr));
750 return ipmi::responseInvalidFieldRequest();
Yong Liae4b0402018-11-02 11:12:14 +0800751 }
752
anil kumar appana894d0222019-05-27 16:32:14 +0000753 if ((selDeviceAddr & ~chassisCapAddrMask) != 0)
Yong Liae4b0402018-11-02 11:12:14 +0800754 {
755 log<level::ERR>("Unsupported request parameter(SEL Addr)",
anil kumar appana894d0222019-05-27 16:32:14 +0000756 entry("REQ=0x%x", selDeviceAddr));
757 return ipmi::responseInvalidFieldRequest();
Yong Liae4b0402018-11-02 11:12:14 +0800758 }
759
anil kumar appana894d0222019-05-27 16:32:14 +0000760 if ((smDeviceAddr & ~chassisCapAddrMask) != 0)
Yong Liae4b0402018-11-02 11:12:14 +0800761 {
anil kumar appana894d0222019-05-27 16:32:14 +0000762 log<level::ERR>("Unsupported request parameter(SM Addr)",
763 entry("REQ=0x%x", smDeviceAddr));
764 return ipmi::responseInvalidFieldRequest();
Yong Liae4b0402018-11-02 11:12:14 +0800765 }
766
anil kumar appana894d0222019-05-27 16:32:14 +0000767 if ((bridgeDeviceAddr & ~chassisCapAddrMask) != 0)
Yong Liae4b0402018-11-02 11:12:14 +0800768 {
769 log<level::ERR>("Unsupported request parameter(Bridge Addr)",
anil kumar appana894d0222019-05-27 16:32:14 +0000770 entry("REQ=0x%x", bridgeDeviceAddr));
771 return ipmi::responseInvalidFieldRequest();
Yong Liae4b0402018-11-02 11:12:14 +0800772 }
773
774 try
775 {
Patrick Williams5d82f472022-07-22 19:26:53 -0500776 sdbusplus::bus_t bus(ipmid_get_sd_bus_connection());
Yong Liae4b0402018-11-02 11:12:14 +0800777 ipmi::DbusObjectInfo chassisCapObject =
778 ipmi::getDbusObject(bus, chassisCapIntf);
779
780 ipmi::setDbusProperty(bus, chassisCapObject.second,
781 chassisCapObject.first, chassisCapIntf,
Karthick Sundarrajan86d8bd72019-11-26 12:48:50 -0800782 chassisIntrusionProp, intrusion);
783
784 ipmi::setDbusProperty(bus, chassisCapObject.second,
785 chassisCapObject.first, chassisCapIntf,
786 chassisFrontPanelLockoutProp, fpLockout);
Yong Liae4b0402018-11-02 11:12:14 +0800787
788 ipmi::setDbusProperty(bus, chassisCapObject.second,
789 chassisCapObject.first, chassisCapIntf,
anil kumar appana894d0222019-05-27 16:32:14 +0000790 chassisFRUDevAddrProp, fruDeviceAddr);
Yong Liae4b0402018-11-02 11:12:14 +0800791
792 ipmi::setDbusProperty(bus, chassisCapObject.second,
793 chassisCapObject.first, chassisCapIntf,
anil kumar appana894d0222019-05-27 16:32:14 +0000794 chassisSDRDevAddrProp, sdrDeviceAddr);
Yong Liae4b0402018-11-02 11:12:14 +0800795
796 ipmi::setDbusProperty(bus, chassisCapObject.second,
797 chassisCapObject.first, chassisCapIntf,
anil kumar appana894d0222019-05-27 16:32:14 +0000798 chassisSELDevAddrProp, selDeviceAddr);
Yong Liae4b0402018-11-02 11:12:14 +0800799
800 ipmi::setDbusProperty(bus, chassisCapObject.second,
801 chassisCapObject.first, chassisCapIntf,
anil kumar appana894d0222019-05-27 16:32:14 +0000802 chassisSMDevAddrProp, smDeviceAddr);
Yong Liae4b0402018-11-02 11:12:14 +0800803
804 ipmi::setDbusProperty(bus, chassisCapObject.second,
805 chassisCapObject.first, chassisCapIntf,
anil kumar appana894d0222019-05-27 16:32:14 +0000806 chassisBridgeDevAddrProp, bridgeDeviceAddr);
Yong Liae4b0402018-11-02 11:12:14 +0800807 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -0500808 catch (const std::exception& e)
Yong Liae4b0402018-11-02 11:12:14 +0800809 {
810 log<level::ERR>(e.what());
anil kumar appana894d0222019-05-27 16:32:14 +0000811 return ipmi::responseUnspecifiedError();
Yong Liae4b0402018-11-02 11:12:14 +0800812 }
anil kumar appana894d0222019-05-27 16:32:14 +0000813 return ipmi::responseSuccess();
Nan Li8d15fb42016-08-16 22:29:40 +0800814}
815
Vishwanatha Subbannab12b0c02017-03-07 18:17:19 +0530816//------------------------------------------
817// Calls into Host State Manager Dbus object
818//------------------------------------------
Jason M. Bills664e1c32020-01-30 16:02:39 -0800819int initiateHostStateTransition(ipmi::Context::ptr& ctx,
820 State::Host::Transition transition)
vishwa36993272015-11-20 12:43:49 -0600821{
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500822 // OpenBMC Host State Manager dbus framework
Jason M. Bills664e1c32020-01-30 16:02:39 -0800823 constexpr auto hostStatePath = "/xyz/openbmc_project/state/host0";
824 constexpr auto hostStateIntf = "xyz.openbmc_project.State.Host";
Vishwanatha Subbannab12b0c02017-03-07 18:17:19 +0530825
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500826 // Convert to string equivalent of the passed in transition enum.
827 auto request = State::convertForMessage(transition);
Vishwanatha Subbannab12b0c02017-03-07 18:17:19 +0530828
Jason M. Bills664e1c32020-01-30 16:02:39 -0800829 std::string service;
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -0500830 boost::system::error_code ec = ipmi::getService(ctx, hostStateIntf,
831 hostStatePath, service);
Jason M. Bills664e1c32020-01-30 16:02:39 -0800832
833 if (!ec)
834 {
835 ec = ipmi::setDbusProperty(ctx, service, hostStatePath, hostStateIntf,
836 "RequestedHostTransition", request);
837 }
838 if (ec)
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500839 {
840 log<level::ERR>("Failed to initiate transition",
Jason M. Bills664e1c32020-01-30 16:02:39 -0800841 entry("EXCEPTION=%s, REQUEST=%s", ec.message().c_str(),
842 request.c_str()));
843 return -1;
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500844 }
Jason M. Bills664e1c32020-01-30 16:02:39 -0800845 log<level::INFO>(
846 "Transition request initiated successfully",
847 entry("USERID=%d, REQUEST=%s", ctx->userId, request.c_str()));
848 return 0;
vishwa36993272015-11-20 12:43:49 -0600849}
850
Kuiying Wang6b0ceaa2019-11-05 15:13:40 +0800851//------------------------------------------
Jason M. Billsad588bf2020-01-30 16:18:33 -0800852// Calls into Chassis State Manager Dbus object
853//------------------------------------------
854int initiateChassisStateTransition(ipmi::Context::ptr& ctx,
855 State::Chassis::Transition transition)
856{
857 // OpenBMC Chassis State Manager dbus framework
858 constexpr auto chassisStatePath = "/xyz/openbmc_project/state/chassis0";
859 constexpr auto chassisStateIntf = "xyz.openbmc_project.State.Chassis";
860
861 std::string service;
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -0500862 boost::system::error_code ec = ipmi::getService(ctx, chassisStateIntf,
863 chassisStatePath, service);
Jason M. Billsad588bf2020-01-30 16:18:33 -0800864
865 // Convert to string equivalent of the passed in transition enum.
866 auto request = State::convertForMessage(transition);
867
868 if (!ec)
869 {
870 ec = ipmi::setDbusProperty(ctx, service, chassisStatePath,
871 chassisStateIntf, "RequestedPowerTransition",
872 request);
873 }
874 if (ec)
875 {
876 log<level::ERR>("Failed to initiate transition",
877 entry("EXCEPTION=%s, REQUEST=%s", ec.message().c_str(),
878 request.c_str()));
879 return -1;
880 }
881
882 return 0;
883}
884
885//------------------------------------------
Kuiying Wang6b0ceaa2019-11-05 15:13:40 +0800886// Set Enabled property to inform NMI source
887// handling to trigger a NMI_OUT BSOD.
888//------------------------------------------
Vernon Mauery9bb4a382021-11-05 12:46:19 -0700889int setNmiProperty(ipmi::Context::ptr& ctx, const bool value)
Kuiying Wang6b0ceaa2019-11-05 15:13:40 +0800890{
891 constexpr const char* nmiSourceObjPath =
892 "/xyz/openbmc_project/Chassis/Control/NMISource";
893 constexpr const char* nmiSourceIntf =
894 "xyz.openbmc_project.Chassis.Control.NMISource";
895 std::string bmcSourceSignal = "xyz.openbmc_project.Chassis.Control."
896 "NMISource.BMCSourceSignal.ChassisCmd";
Kuiying Wang6b0ceaa2019-11-05 15:13:40 +0800897
Vernon Mauery9bb4a382021-11-05 12:46:19 -0700898 std::string service;
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -0500899 boost::system::error_code ec = ipmi::getService(ctx, nmiSourceIntf,
900 nmiSourceObjPath, service);
Vernon Mauery9bb4a382021-11-05 12:46:19 -0700901 if (!ec)
Kuiying Wang6b0ceaa2019-11-05 15:13:40 +0800902 {
Vernon Mauery9bb4a382021-11-05 12:46:19 -0700903 ec = ipmi::setDbusProperty(ctx, service, nmiSourceObjPath,
904 nmiSourceIntf, "BMCSource", bmcSourceSignal);
Kuiying Wang6b0ceaa2019-11-05 15:13:40 +0800905 }
Vernon Mauery9bb4a382021-11-05 12:46:19 -0700906 if (!ec)
907 {
908 ec = ipmi::setDbusProperty(ctx, service, nmiSourceObjPath,
909 nmiSourceIntf, "Enabled", value);
910 }
911 if (ec)
Kuiying Wang6b0ceaa2019-11-05 15:13:40 +0800912 {
913 log<level::ERR>("Failed to trigger NMI_OUT",
Vernon Mauery9bb4a382021-11-05 12:46:19 -0700914 entry("EXCEPTION=%s", ec.message().c_str()));
Kuiying Wang6b0ceaa2019-11-05 15:13:40 +0800915 return -1;
916 }
917
918 return 0;
919}
920
Deepak Kodihalli18b70d12017-07-21 13:36:33 -0500921namespace power_policy
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500922{
Nan Lifdd8ec52016-08-28 03:57:40 +0800923
Deepak Kodihalli18b70d12017-07-21 13:36:33 -0500924using namespace sdbusplus::xyz::openbmc_project::Control::Power::server;
925using IpmiValue = uint8_t;
926using DbusValue = RestorePolicy::Policy;
Nan Lifdd8ec52016-08-28 03:57:40 +0800927
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700928const std::map<DbusValue, IpmiValue> dbusToIpmi = {
Deepak Kodihalli18b70d12017-07-21 13:36:33 -0500929 {RestorePolicy::Policy::AlwaysOff, 0x00},
930 {RestorePolicy::Policy::Restore, 0x01},
Patrick Venture0b02be92018-08-31 11:55:55 -0700931 {RestorePolicy::Policy::AlwaysOn, 0x02}};
Nan Lifdd8ec52016-08-28 03:57:40 +0800932
Yong Lic6713cf2018-09-12 12:35:13 +0800933static constexpr uint8_t noChange = 0x03;
934static constexpr uint8_t allSupport = 0x01 | 0x02 | 0x04;
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700935
936/* helper function for Get Chassis Status Command
937 */
938std::optional<uint2_t> getPowerRestorePolicy()
939{
940 uint2_t restorePolicy = 0;
941 using namespace chassis::internal;
942
James Feist225dec82019-11-26 16:25:06 -0800943 settings::Objects& objects = cache::getObjects();
944
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700945 try
946 {
947 const auto& powerRestoreSetting =
James Feist225dec82019-11-26 16:25:06 -0800948 objects.map.at(powerRestoreIntf).front();
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700949 ipmi::Value result = ipmi::getDbusProperty(
950 *getSdBus(),
James Feist225dec82019-11-26 16:25:06 -0800951 objects.service(powerRestoreSetting, powerRestoreIntf).c_str(),
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700952 powerRestoreSetting.c_str(), powerRestoreIntf,
953 "PowerRestorePolicy");
954 auto powerRestore = RestorePolicy::convertPolicyFromString(
955 std::get<std::string>(result));
956 restorePolicy = dbusToIpmi.at(powerRestore);
957 }
958 catch (const std::exception& e)
959 {
960 log<level::ERR>(
961 "Failed to fetch pgood property", entry("ERROR=%s", e.what()),
James Feist225dec82019-11-26 16:25:06 -0800962 entry("PATH=%s", objects.map.at(powerRestoreIntf).front().c_str()),
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700963 entry("INTERFACE=%s", powerRestoreIntf));
James Feist225dec82019-11-26 16:25:06 -0800964 cache::objectsPtr.reset();
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700965 return std::nullopt;
966 }
967 return std::make_optional(restorePolicy);
968}
969
970/*
971 * getPowerStatus
972 * helper function for Get Chassis Status Command
973 * return - optional value for pgood (no value on error)
974 */
975std::optional<bool> getPowerStatus()
976{
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700977 bool powerGood = false;
978 std::shared_ptr<sdbusplus::asio::connection> busp = getSdBus();
979 try
980 {
Jason M. Bills3de424c2019-05-21 09:57:16 -0700981 constexpr const char* chassisStatePath =
982 "/xyz/openbmc_project/state/chassis0";
983 constexpr const char* chassisStateIntf =
984 "xyz.openbmc_project.State.Chassis";
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -0500985 auto service = ipmi::getService(*busp, chassisStateIntf,
986 chassisStatePath);
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700987
Jason M. Bills3de424c2019-05-21 09:57:16 -0700988 ipmi::Value powerState =
989 ipmi::getDbusProperty(*busp, service, chassisStatePath,
990 chassisStateIntf, "CurrentPowerState");
991 powerGood = std::get<std::string>(powerState) ==
992 "xyz.openbmc_project.State.Chassis.PowerState.On";
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700993 }
994 catch (const std::exception& e)
995 {
996 try
997 {
998 // FIXME: some legacy modules use the older path; try that next
999 constexpr const char* legacyPwrCtrlObj =
1000 "/org/openbmc/control/power0";
1001 constexpr const char* legacyPwrCtrlIntf =
1002 "org.openbmc.control.Power";
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05001003 auto service = ipmi::getService(*busp, legacyPwrCtrlIntf,
1004 legacyPwrCtrlObj);
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001005
1006 ipmi::Value variant = ipmi::getDbusProperty(
1007 *busp, service, legacyPwrCtrlObj, legacyPwrCtrlIntf, "pgood");
1008 powerGood = static_cast<bool>(std::get<int>(variant));
1009 }
1010 catch (const std::exception& e)
1011 {
1012 log<level::ERR>("Failed to fetch pgood property",
Jason M. Bills3de424c2019-05-21 09:57:16 -07001013 entry("ERROR=%s", e.what()));
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001014 return std::nullopt;
1015 }
1016 }
1017 return std::make_optional(powerGood);
1018}
1019
Yong Li70ce7352019-05-16 21:15:27 +08001020/*
1021 * getACFailStatus
1022 * helper function for Get Chassis Status Command
1023 * return - bool value for ACFail (false on error)
1024 */
1025bool getACFailStatus()
1026{
1027 constexpr const char* powerControlObj =
1028 "/xyz/openbmc_project/Chassis/Control/Power0";
1029 constexpr const char* powerControlIntf =
1030 "xyz.openbmc_project.Chassis.Control.Power";
1031 bool acFail = false;
1032 std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus();
1033 try
1034 {
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05001035 auto service = ipmi::getService(*bus, powerControlIntf,
1036 powerControlObj);
Yong Li70ce7352019-05-16 21:15:27 +08001037
1038 ipmi::Value variant = ipmi::getDbusProperty(
1039 *bus, service, powerControlObj, powerControlIntf, "PFail");
1040 acFail = std::get<bool>(variant);
1041 }
1042 catch (const std::exception& e)
1043 {
1044 log<level::ERR>("Failed to fetch PFail property",
1045 entry("ERROR=%s", e.what()),
1046 entry("PATH=%s", powerControlObj),
1047 entry("INTERFACE=%s", powerControlIntf));
1048 }
1049 return acFail;
1050}
Deepak Kodihalli18b70d12017-07-21 13:36:33 -05001051} // namespace power_policy
Nan Lifdd8ec52016-08-28 03:57:40 +08001052
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001053static std::optional<bool> getButtonEnabled(const std::string& buttonPath,
1054 const std::string& buttonIntf)
1055{
1056 std::shared_ptr<sdbusplus::asio::connection> busp = getSdBus();
1057 bool buttonDisabled = false;
1058 try
1059 {
1060 auto service = ipmi::getService(*busp, buttonIntf, buttonPath);
1061 ipmi::Value enabled = ipmi::getDbusProperty(*busp, service, buttonPath,
1062 buttonIntf, "Enabled");
1063 buttonDisabled = !std::get<bool>(enabled);
1064 }
Patrick Williams5d82f472022-07-22 19:26:53 -05001065 catch (const sdbusplus::exception_t& e)
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001066 {
1067 log<level::ERR>("Fail to get button Enabled property",
1068 entry("PATH=%s", buttonPath.c_str()),
1069 entry("ERROR=%s", e.what()));
1070 return std::nullopt;
1071 }
1072 return std::make_optional(buttonDisabled);
1073}
1074
Kuiying Wang21addc52019-01-04 10:50:21 +08001075static bool setButtonEnabled(ipmi::Context::ptr& ctx,
1076 const std::string& buttonPath,
1077 const std::string& buttonIntf, bool enable)
1078{
1079 std::string service;
1080 boost::system::error_code ec;
1081 ec = ipmi::getService(ctx, buttonIntf, buttonPath, service);
1082 if (!ec)
1083 {
1084 ec = ipmi::setDbusProperty(ctx, service, buttonPath, buttonIntf,
1085 "Enabled", enable);
1086 }
1087 if (ec)
1088 {
1089 log<level::ERR>("Fail to set button Enabled property",
1090 entry("SERVICE=%s", service.c_str()),
1091 entry("PATH=%s", buttonPath.c_str()),
1092 entry("ERROR=%s", ec.message().c_str()));
1093 return false;
1094 }
1095 return true;
1096}
1097
Chau Ly9e666cd2023-03-06 08:46:14 +00001098static std::optional<bool> getChassisIntrusionStatus(ipmi::Context::ptr& ctx)
1099{
1100 constexpr const char* chassisIntrusionPath =
1101 "/xyz/openbmc_project/Chassis/Intrusion";
1102 constexpr const char* chassisIntrusionInf =
1103 "xyz.openbmc_project.Chassis.Intrusion";
1104
1105 std::string service;
1106 boost::system::error_code ec = ipmi::getService(
1107 ctx, chassisIntrusionInf, chassisIntrusionPath, service);
1108 if (!ec)
1109 {
1110 std::string chassisIntrusionStr;
1111 ec = ipmi::getDbusProperty<std::string>(
1112 ctx, service, chassisIntrusionPath, chassisIntrusionInf, "Status",
1113 chassisIntrusionStr);
1114 if (!ec)
1115 {
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05001116 bool ret = (chassisIntrusionStr == "HardwareIntrusion") ? true
1117 : false;
Chau Ly9e666cd2023-03-06 08:46:14 +00001118 return std::make_optional(ret);
1119 }
1120 }
1121 log<level::ERR>("Fail to get Chassis Intrusion Status property",
1122 entry("PATH=%s", chassisIntrusionPath),
1123 entry("INTERFACE=%s", chassisIntrusionInf),
1124 entry("ERROR=%s", ec.message().c_str()));
1125 return std::nullopt;
1126}
1127
Nan Lifdd8ec52016-08-28 03:57:40 +08001128//----------------------------------------------------------------------
1129// Get Chassis Status commands
1130//----------------------------------------------------------------------
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001131ipmi::RspType<bool, // Power is on
1132 bool, // Power overload
1133 bool, // Interlock
1134 bool, // power fault
1135 bool, // power control fault
1136 uint2_t, // power restore policy
1137 bool, // reserved
1138
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05001139 bool, // AC failed
1140 bool, // last power down caused by a Power overload
1141 bool, // last power down caused by a power interlock
1142 bool, // last power down caused by power fault
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001143 bool, // last ‘Power is on’ state was entered via IPMI command
1144 uint3_t, // reserved
1145
1146 bool, // Chassis intrusion active
1147 bool, // Front Panel Lockout active
1148 bool, // Drive Fault
1149 bool, // Cooling/fan fault detected
1150 uint2_t, // Chassis Identify State
1151 bool, // Chassis Identify command and state info supported
1152 bool, // reserved
1153
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05001154 bool, // Power off button disabled
1155 bool, // Reset button disabled
1156 bool, // Diagnostic Interrupt button disabled
1157 bool, // Standby (sleep) button disabled
1158 bool, // Power off button disable allowed
1159 bool, // Reset button disable allowed
1160 bool, // Diagnostic Interrupt button disable allowed
1161 bool // Standby (sleep) button disable allowed
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001162 >
Chau Ly9e666cd2023-03-06 08:46:14 +00001163 ipmiGetChassisStatus(ipmi::Context::ptr& ctx)
Nan Lifdd8ec52016-08-28 03:57:40 +08001164{
Deepak Kodihalli18b70d12017-07-21 13:36:33 -05001165 using namespace chassis::internal;
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001166 std::optional<uint2_t> restorePolicy =
1167 power_policy::getPowerRestorePolicy();
1168 std::optional<bool> powerGood = power_policy::getPowerStatus();
1169 if (!restorePolicy || !powerGood)
Deepak Kodihalli18b70d12017-07-21 13:36:33 -05001170 {
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001171 return ipmi::responseUnspecifiedError();
Deepak Kodihalli18b70d12017-07-21 13:36:33 -05001172 }
Nan Lifdd8ec52016-08-28 03:57:40 +08001173
1174 // Front Panel Button Capabilities and disable/enable status(Optional)
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05001175 std::optional<bool> powerButtonReading = getButtonEnabled(powerButtonPath,
1176 powerButtonIntf);
Vernon Mauery6d5b2f72019-05-16 14:48:47 -07001177 // allow disable if the interface is present
1178 bool powerButtonDisableAllow = static_cast<bool>(powerButtonReading);
1179 // default return the button is enabled (not disabled)
1180 bool powerButtonDisabled = false;
1181 if (powerButtonDisableAllow)
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001182 {
Vernon Mauery6d5b2f72019-05-16 14:48:47 -07001183 // return the real value of the button status, if present
1184 powerButtonDisabled = *powerButtonReading;
1185 }
1186
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05001187 std::optional<bool> resetButtonReading = getButtonEnabled(resetButtonPath,
1188 resetButtonIntf);
Vernon Mauery6d5b2f72019-05-16 14:48:47 -07001189 // allow disable if the interface is present
1190 bool resetButtonDisableAllow = static_cast<bool>(resetButtonReading);
1191 // default return the button is enabled (not disabled)
1192 bool resetButtonDisabled = false;
1193 if (resetButtonDisableAllow)
1194 {
1195 // return the real value of the button status, if present
1196 resetButtonDisabled = *resetButtonReading;
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001197 }
Nan Lifdd8ec52016-08-28 03:57:40 +08001198
Yong Li70ce7352019-05-16 21:15:27 +08001199 bool powerDownAcFailed = power_policy::getACFailStatus();
1200
Chau Ly9e666cd2023-03-06 08:46:14 +00001201 bool chassisIntrusionActive = false;
1202 std::optional<bool> chassisIntrusionStatus = getChassisIntrusionStatus(ctx);
1203 if (chassisIntrusionStatus)
1204 {
1205 chassisIntrusionActive = chassisIntrusionStatus.value();
1206 }
1207
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001208 // This response has a lot of hard-coded, unsupported fields
1209 // They are set to false or 0
1210 constexpr bool powerOverload = false;
1211 constexpr bool chassisInterlock = false;
1212 constexpr bool powerFault = false;
1213 constexpr bool powerControlFault = false;
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001214 constexpr bool powerDownOverload = false;
1215 constexpr bool powerDownInterlock = false;
1216 constexpr bool powerDownPowerFault = false;
1217 constexpr bool powerStatusIPMI = false;
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001218 constexpr bool frontPanelLockoutActive = false;
1219 constexpr bool driveFault = false;
1220 constexpr bool coolingFanFault = false;
1221 // chassisIdentifySupport set because this command is implemented
1222 constexpr bool chassisIdentifySupport = true;
William A. Kennington III7a0e5df2021-05-19 13:31:29 -07001223 uint2_t chassisIdentifyState = types::enum_cast<uint2_t>(chassisIDState);
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001224 constexpr bool diagButtonDisabled = false;
1225 constexpr bool sleepButtonDisabled = false;
1226 constexpr bool diagButtonDisableAllow = false;
1227 constexpr bool sleepButtonDisableAllow = false;
1228
1229 return ipmi::responseSuccess(
1230 *powerGood, powerOverload, chassisInterlock, powerFault,
1231 powerControlFault, *restorePolicy,
1232 false, // reserved
1233
1234 powerDownAcFailed, powerDownOverload, powerDownInterlock,
1235 powerDownPowerFault, powerStatusIPMI,
1236 uint3_t(0), // reserved
1237
1238 chassisIntrusionActive, frontPanelLockoutActive, driveFault,
1239 coolingFanFault, chassisIdentifyState, chassisIdentifySupport,
1240 false, // reserved
1241
Vernon Mauery6d5b2f72019-05-16 14:48:47 -07001242 powerButtonDisabled, resetButtonDisabled, diagButtonDisabled,
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001243 sleepButtonDisabled, powerButtonDisableAllow, resetButtonDisableAllow,
1244 diagButtonDisableAllow, sleepButtonDisableAllow);
Nan Lifdd8ec52016-08-28 03:57:40 +08001245}
Chris Austen7888c4d2015-12-03 15:26:20 -06001246
Vijay Khemka074f64d2020-03-03 15:08:43 -08001247enum class IpmiRestartCause
1248{
1249 Unknown = 0x0,
1250 RemoteCommand = 0x1,
1251 ResetButton = 0x2,
1252 PowerButton = 0x3,
1253 WatchdogTimer = 0x4,
1254 PowerPolicyAlwaysOn = 0x6,
1255 PowerPolicyPreviousState = 0x7,
1256 SoftReset = 0xa,
1257};
1258
1259static IpmiRestartCause
1260 restartCauseToIpmiRestartCause(State::Host::RestartCause cause)
1261{
1262 switch (cause)
1263 {
1264 case State::Host::RestartCause::Unknown:
1265 {
1266 return IpmiRestartCause::Unknown;
1267 }
1268 case State::Host::RestartCause::RemoteCommand:
1269 {
1270 return IpmiRestartCause::RemoteCommand;
1271 }
1272 case State::Host::RestartCause::ResetButton:
1273 {
1274 return IpmiRestartCause::ResetButton;
1275 }
1276 case State::Host::RestartCause::PowerButton:
1277 {
1278 return IpmiRestartCause::PowerButton;
1279 }
1280 case State::Host::RestartCause::WatchdogTimer:
1281 {
1282 return IpmiRestartCause::WatchdogTimer;
1283 }
1284 case State::Host::RestartCause::PowerPolicyAlwaysOn:
1285 {
1286 return IpmiRestartCause::PowerPolicyAlwaysOn;
1287 }
1288 case State::Host::RestartCause::PowerPolicyPreviousState:
1289 {
1290 return IpmiRestartCause::PowerPolicyPreviousState;
1291 }
1292 case State::Host::RestartCause::SoftReset:
1293 {
1294 return IpmiRestartCause::SoftReset;
1295 }
1296 default:
1297 {
1298 return IpmiRestartCause::Unknown;
1299 }
1300 }
1301}
1302
1303/*
1304 * getRestartCause
1305 * helper function for Get Host restart cause Command
1306 * return - optional value for RestartCause (no value on error)
1307 */
1308static std::optional<uint4_t> getRestartCause(ipmi::Context::ptr ctx)
1309{
1310 constexpr const char* restartCausePath =
1311 "/xyz/openbmc_project/control/host0/restart_cause";
1312 constexpr const char* restartCauseIntf =
1313 "xyz.openbmc_project.Control.Host.RestartCause";
1314
1315 std::string service;
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05001316 boost::system::error_code ec = ipmi::getService(ctx, restartCauseIntf,
1317 restartCausePath, service);
Vijay Khemka074f64d2020-03-03 15:08:43 -08001318 if (!ec)
1319 {
1320 std::string restartCauseStr;
1321 ec = ipmi::getDbusProperty<std::string>(
1322 ctx, service, restartCausePath, restartCauseIntf, "RestartCause",
1323 restartCauseStr);
1324 if (!ec)
1325 {
1326 auto cause =
1327 State::Host::convertRestartCauseFromString(restartCauseStr);
William A. Kennington III7a0e5df2021-05-19 13:31:29 -07001328 return types::enum_cast<uint4_t>(
1329 restartCauseToIpmiRestartCause(cause));
Vijay Khemka074f64d2020-03-03 15:08:43 -08001330 }
1331 }
1332
1333 log<level::ERR>("Failed to fetch RestartCause property",
1334 entry("ERROR=%s", ec.message().c_str()),
1335 entry("PATH=%s", restartCausePath),
1336 entry("INTERFACE=%s", restartCauseIntf));
1337 return std::nullopt;
1338}
1339
1340ipmi::RspType<uint4_t, // Restart Cause
1341 uint4_t, // reserved
1342 uint8_t // channel number (not supported)
1343 >
1344 ipmiGetSystemRestartCause(ipmi::Context::ptr ctx)
1345{
1346 std::optional<uint4_t> cause = getRestartCause(ctx);
1347 if (!cause)
1348 {
1349 return ipmi::responseUnspecifiedError();
1350 }
1351
Vernon Mauery916d4232021-03-29 13:42:16 -07001352 constexpr uint4_t reserved = 0;
1353 auto channel = static_cast<uint8_t>(ctx->channel);
1354 return ipmi::responseSuccess(cause.value(), reserved, channel);
Vijay Khemka074f64d2020-03-03 15:08:43 -08001355}
anil kumar appanadafff5f2019-04-27 18:06:00 +00001356/** @brief Implementation of chassis control command
1357 *
1358 * @param - chassisControl command byte
1359 *
1360 * @return Success or InvalidFieldRequest.
1361 */
Jason M. Bills664e1c32020-01-30 16:02:39 -08001362ipmi::RspType<> ipmiChassisControl(ipmi::Context::ptr& ctx,
1363 uint8_t chassisControl)
vishwa36993272015-11-20 12:43:49 -06001364{
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001365 int rc = 0;
anil kumar appanadafff5f2019-04-27 18:06:00 +00001366 switch (chassisControl)
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001367 {
1368 case CMD_POWER_ON:
Jason M. Bills664e1c32020-01-30 16:02:39 -08001369 rc = initiateHostStateTransition(ctx, State::Host::Transition::On);
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001370 break;
1371 case CMD_POWER_OFF:
Jason M. Billsc2c3a402020-01-30 16:22:24 -08001372 rc = initiateChassisStateTransition(
1373 ctx, State::Chassis::Transition::Off);
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001374 break;
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001375 case CMD_HARD_RESET:
Jason M. Bills664e1c32020-01-30 16:02:39 -08001376 rc = initiateHostStateTransition(
1377 ctx, State::Host::Transition::ForceWarmReboot);
Chanh Nguyend0a7fcd2021-07-16 22:59:28 +07001378 break;
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001379 case CMD_POWER_CYCLE:
Jason M. Bills664e1c32020-01-30 16:02:39 -08001380 rc = initiateHostStateTransition(ctx,
1381 State::Host::Transition::Reboot);
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001382 break;
Vishwanatha Subbanna8b26d352017-08-04 18:35:18 +05301383 case CMD_SOFT_OFF_VIA_OVER_TEMP:
Jason M. Bills664e1c32020-01-30 16:02:39 -08001384 rc = initiateHostStateTransition(ctx, State::Host::Transition::Off);
Vishwanatha Subbanna8b26d352017-08-04 18:35:18 +05301385 break;
Kuiying Wang6b0ceaa2019-11-05 15:13:40 +08001386 case CMD_PULSE_DIAGNOSTIC_INTR:
Vernon Mauery9bb4a382021-11-05 12:46:19 -07001387 rc = setNmiProperty(ctx, true);
Kuiying Wang6b0ceaa2019-11-05 15:13:40 +08001388 break;
1389
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001390 default:
1391 {
Aditya Saripalli5fb14602017-11-09 14:46:27 +05301392 log<level::ERR>("Invalid Chassis Control command",
anil kumar appanadafff5f2019-04-27 18:06:00 +00001393 entry("CMD=0x%X", chassisControl));
1394 return ipmi::responseInvalidFieldRequest();
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001395 }
1396 }
vishwa36993272015-11-20 12:43:49 -06001397
anil kumar appanadafff5f2019-04-27 18:06:00 +00001398 return ((rc < 0) ? ipmi::responseUnspecifiedError()
1399 : ipmi::responseSuccess());
vishwa36993272015-11-20 12:43:49 -06001400}
1401
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001402/** @brief Return D-Bus connection string to enclosure identify LED object
1403 *
1404 * @param[in, out] connection - connection to D-Bus object
1405 * @return a IPMI return code
1406 */
1407std::string getEnclosureIdentifyConnection()
Tom Joseph5110c122018-03-23 17:55:40 +05301408{
Tom Joseph5110c122018-03-23 17:55:40 +05301409 // lookup enclosure_identify group owner(s) in mapper
George Liu3e3cc352023-07-26 15:59:31 +08001410 try
Tom Joseph5110c122018-03-23 17:55:40 +05301411 {
George Liu3e3cc352023-07-26 15:59:31 +08001412 return ipmi::getService(*getSdBus(), "xyz.openbmc_project.Led.Group",
1413 identify_led_object_name);
1414 }
1415 catch (const std::exception& e)
1416 {
1417 log<level::ERR>("Chassis Identify: Error communicating to mapper.",
1418 entry("ERROR=%s", e.what()));
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001419 elog<InternalFailure>();
Tom Joseph5110c122018-03-23 17:55:40 +05301420 }
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001421}
Tom Joseph5110c122018-03-23 17:55:40 +05301422
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001423/** @brief Turn On/Off enclosure identify LED
1424 *
1425 * @param[in] flag - true to turn on LED, false to turn off
1426 * @return a IPMI return code
1427 */
1428void enclosureIdentifyLed(bool flag)
1429{
1430 using namespace chassis::internal;
George Liu3e3cc352023-07-26 15:59:31 +08001431 try
1432 {
1433 std::string connection = getEnclosureIdentifyConnection();
1434
1435 auto msg = std::string("enclosureIdentifyLed(") +
1436 boost::lexical_cast<std::string>(flag) + ")";
1437 log<level::DEBUG>(msg.c_str());
1438
1439 ipmi::setDbusProperty(*getSdBus(), connection, identify_led_object_name,
1440 "xyz.openbmc_project.Led.Group", "Asserted",
1441 flag);
1442 }
1443 catch (const std::exception& e)
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001444 {
1445 log<level::ERR>("Chassis Identify: Error Setting State On/Off\n",
George Liu3e3cc352023-07-26 15:59:31 +08001446 entry("LED_STATE=%d", flag),
1447 entry("ERROR=%s", e.what()));
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001448 elog<InternalFailure>();
1449 }
1450}
1451
1452/** @brief Callback method to turn off LED
1453 */
1454void enclosureIdentifyLedOff()
1455{
1456 try
1457 {
Yong Lif4e38512019-05-21 14:46:55 +08001458 chassisIDState = ChassisIDState::off;
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001459 enclosureIdentifyLed(false);
1460 }
1461 catch (const InternalFailure& e)
1462 {
1463 report<InternalFailure>();
1464 }
1465}
1466
1467/** @brief Create timer to turn on and off the enclosure LED
1468 */
1469void createIdentifyTimer()
1470{
1471 if (!identifyTimer)
1472 {
Vernon Mauery1181af72018-10-08 12:05:00 -07001473 identifyTimer =
1474 std::make_unique<phosphor::Timer>(enclosureIdentifyLedOff);
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001475 }
1476}
1477
Vernon Mauery400cc782018-10-09 13:49:53 -07001478ipmi::RspType<> ipmiChassisIdentify(std::optional<uint8_t> interval,
1479 std::optional<uint8_t> force)
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001480{
Vernon Mauery400cc782018-10-09 13:49:53 -07001481 uint8_t identifyInterval = interval.value_or(DEFAULT_IDENTIFY_TIME_OUT);
1482 bool forceIdentify = force.value_or(0) & 0x01;
Tom Josephbed26992018-07-31 23:00:24 +05301483
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001484 if (identifyInterval || forceIdentify)
1485 {
Vernon Mauery400cc782018-10-09 13:49:53 -07001486 // stop the timer if already started;
1487 // for force identify we should not turn off LED
Vernon Mauery1181af72018-10-08 12:05:00 -07001488 identifyTimer->stop();
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001489 try
Tom Joseph5110c122018-03-23 17:55:40 +05301490 {
Yong Lif4e38512019-05-21 14:46:55 +08001491 chassisIDState = ChassisIDState::temporaryOn;
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001492 enclosureIdentifyLed(true);
1493 }
1494 catch (const InternalFailure& e)
1495 {
1496 report<InternalFailure>();
Vernon Mauery400cc782018-10-09 13:49:53 -07001497 return ipmi::responseResponseError();
Tom Joseph5110c122018-03-23 17:55:40 +05301498 }
1499
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001500 if (forceIdentify)
Tom Joseph5110c122018-03-23 17:55:40 +05301501 {
Yong Lif4e38512019-05-21 14:46:55 +08001502 chassisIDState = ChassisIDState::indefiniteOn;
Vernon Mauery400cc782018-10-09 13:49:53 -07001503 return ipmi::responseSuccess();
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001504 }
1505 // start the timer
1506 auto time = std::chrono::duration_cast<std::chrono::microseconds>(
Patrick Venture0b02be92018-08-31 11:55:55 -07001507 std::chrono::seconds(identifyInterval));
Vernon Mauery1181af72018-10-08 12:05:00 -07001508 identifyTimer->start(time);
Tom Joseph5110c122018-03-23 17:55:40 +05301509 }
Tom Josephbed26992018-07-31 23:00:24 +05301510 else if (!identifyInterval)
1511 {
Vernon Mauery1181af72018-10-08 12:05:00 -07001512 identifyTimer->stop();
Tom Josephbed26992018-07-31 23:00:24 +05301513 enclosureIdentifyLedOff();
1514 }
Vernon Mauery400cc782018-10-09 13:49:53 -07001515 return ipmi::responseSuccess();
Tom Joseph5110c122018-03-23 17:55:40 +05301516}
1517
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001518namespace boot_options
1519{
1520
1521using namespace sdbusplus::xyz::openbmc_project::Control::Boot::server;
1522using IpmiValue = uint8_t;
1523constexpr auto ipmiDefault = 0;
1524
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001525std::map<IpmiValue, Type::Types> typeIpmiToDbus = {{0x00, Type::Types::Legacy},
1526 {0x01, Type::Types::EFI}};
1527
Patrick Venture0b02be92018-08-31 11:55:55 -07001528std::map<IpmiValue, Source::Sources> sourceIpmiToDbus = {
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001529 {0x01, Source::Sources::Network},
1530 {0x02, Source::Sources::Disk},
1531 {0x05, Source::Sources::ExternalMedia},
Jia, chunhui67c5e5d2019-05-06 11:29:54 +08001532 {0x0f, Source::Sources::RemovableMedia},
Patrick Venture0b02be92018-08-31 11:55:55 -07001533 {ipmiDefault, Source::Sources::Default}};
shgoupfd84fbbf2015-12-17 10:05:51 +08001534
Patrick Venture0b02be92018-08-31 11:55:55 -07001535std::map<IpmiValue, Mode::Modes> modeIpmiToDbus = {
Yong Li5833cb62019-10-30 13:27:12 +08001536#ifdef ENABLE_BOOT_FLAG_SAFE_MODE_SUPPORT
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001537 {0x03, Mode::Modes::Safe},
Yong Li5833cb62019-10-30 13:27:12 +08001538#endif // ENABLE_BOOT_SAFE_MODE_SUPPORT
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001539 {0x06, Mode::Modes::Setup},
Patrick Venture0b02be92018-08-31 11:55:55 -07001540 {ipmiDefault, Mode::Modes::Regular}};
shgoupfd84fbbf2015-12-17 10:05:51 +08001541
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001542std::map<Type::Types, IpmiValue> typeDbusToIpmi = {{Type::Types::Legacy, 0x00},
1543 {Type::Types::EFI, 0x01}};
1544
Patrick Venture0b02be92018-08-31 11:55:55 -07001545std::map<Source::Sources, IpmiValue> sourceDbusToIpmi = {
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001546 {Source::Sources::Network, 0x01},
1547 {Source::Sources::Disk, 0x02},
1548 {Source::Sources::ExternalMedia, 0x05},
Jia, chunhui67c5e5d2019-05-06 11:29:54 +08001549 {Source::Sources::RemovableMedia, 0x0f},
Patrick Venture0b02be92018-08-31 11:55:55 -07001550 {Source::Sources::Default, ipmiDefault}};
shgoupfd84fbbf2015-12-17 10:05:51 +08001551
Patrick Venture0b02be92018-08-31 11:55:55 -07001552std::map<Mode::Modes, IpmiValue> modeDbusToIpmi = {
Yong Li5833cb62019-10-30 13:27:12 +08001553#ifdef ENABLE_BOOT_FLAG_SAFE_MODE_SUPPORT
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001554 {Mode::Modes::Safe, 0x03},
Yong Li5833cb62019-10-30 13:27:12 +08001555#endif // ENABLE_BOOT_SAFE_MODE_SUPPORT
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001556 {Mode::Modes::Setup, 0x06},
Patrick Venture0b02be92018-08-31 11:55:55 -07001557 {Mode::Modes::Regular, ipmiDefault}};
shgoupfd84fbbf2015-12-17 10:05:51 +08001558
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001559} // namespace boot_options
shgoupfd84fbbf2015-12-17 10:05:51 +08001560
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001561/** @brief Get the property value for boot source
1562 * @param[in] ctx - context pointer
1563 * @param[out] source - boot source value
1564 * @return On failure return IPMI error.
1565 */
1566static ipmi::Cc getBootSource(ipmi::Context::ptr& ctx, Source::Sources& source)
1567{
1568 using namespace chassis::internal;
1569 std::string result;
1570 std::string service;
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05001571 boost::system::error_code ec = getService(ctx, bootSourceIntf,
1572 bootSettingsPath, service);
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001573 if (!ec)
1574 {
1575 ec = ipmi::getDbusProperty(ctx, service, bootSettingsPath,
1576 bootSourceIntf, "BootSource", result);
1577 if (!ec)
1578 {
1579 source = Source::convertSourcesFromString(result);
1580 return ipmi::ccSuccess;
1581 }
1582 }
1583 log<level::ERR>("Error in BootSource Get",
1584 entry("ERROR=%s", ec.message().c_str()));
1585 return ipmi::ccUnspecifiedError;
1586}
1587
Marri Devender Rao81719702018-05-07 00:53:48 -05001588/** @brief Set the property value for boot source
Konstantin Aladysheve76a61a2021-03-18 22:19:13 +03001589 * @param[in] ctx - context pointer
Marri Devender Rao81719702018-05-07 00:53:48 -05001590 * @param[in] source - boot source value
1591 * @return On failure return IPMI error.
1592 */
Jayaprakash Mutyala6088e9f2021-07-14 07:40:29 +00001593static ipmi::Cc setBootSource(ipmi::Context::ptr& ctx,
1594 const Source::Sources& source)
Marri Devender Rao81719702018-05-07 00:53:48 -05001595{
1596 using namespace chassis::internal;
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001597 std::string service;
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05001598 boost::system::error_code ec = getService(ctx, bootSourceIntf,
1599 bootSettingsPath, service);
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001600 if (!ec)
Marri Devender Rao81719702018-05-07 00:53:48 -05001601 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001602 ec = ipmi::setDbusProperty(ctx, service, bootSettingsPath,
1603 bootSourceIntf, "BootSource",
1604 convertForMessage(source));
1605 if (!ec)
1606 {
1607 return ipmi::ccSuccess;
1608 }
Marri Devender Rao81719702018-05-07 00:53:48 -05001609 }
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001610 log<level::ERR>("Error in BootSource Set",
1611 entry("ERROR=%s", ec.message().c_str()));
1612 return ipmi::ccUnspecifiedError;
1613}
1614
1615/** @brief Get the property value for boot mode
1616 * @param[in] ctx - context pointer
1617 * @param[out] mode - boot mode value
1618 * @return On failure return IPMI error.
1619 */
1620static ipmi::Cc getBootMode(ipmi::Context::ptr& ctx, Mode::Modes& mode)
1621{
1622 using namespace chassis::internal;
1623 std::string result;
1624 std::string service;
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05001625 boost::system::error_code ec = getService(ctx, bootModeIntf,
1626 bootSettingsPath, service);
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001627 if (!ec)
1628 {
1629 ec = ipmi::getDbusProperty(ctx, service, bootSettingsPath, bootModeIntf,
1630 "BootMode", result);
1631 if (!ec)
1632 {
1633 mode = Mode::convertModesFromString(result);
1634 return ipmi::ccSuccess;
1635 }
1636 }
1637 log<level::ERR>("Error in BootMode Get",
1638 entry("ERROR=%s", ec.message().c_str()));
1639 return ipmi::ccUnspecifiedError;
Marri Devender Rao81719702018-05-07 00:53:48 -05001640}
1641
Patrick Venture0b02be92018-08-31 11:55:55 -07001642/** @brief Set the property value for boot mode
Konstantin Aladysheve76a61a2021-03-18 22:19:13 +03001643 * @param[in] ctx - context pointer
Marri Devender Rao81719702018-05-07 00:53:48 -05001644 * @param[in] mode - boot mode value
1645 * @return On failure return IPMI error.
1646 */
Konstantin Aladysheve76a61a2021-03-18 22:19:13 +03001647static ipmi::Cc setBootMode(ipmi::Context::ptr& ctx, const Mode::Modes& mode)
Marri Devender Rao81719702018-05-07 00:53:48 -05001648{
1649 using namespace chassis::internal;
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001650 std::string service;
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05001651 boost::system::error_code ec = getService(ctx, bootModeIntf,
1652 bootSettingsPath, service);
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001653 if (!ec)
Marri Devender Rao81719702018-05-07 00:53:48 -05001654 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001655 ec = ipmi::setDbusProperty(ctx, service, bootSettingsPath, bootModeIntf,
1656 "BootMode", convertForMessage(mode));
1657 if (!ec)
1658 {
1659 return ipmi::ccSuccess;
1660 }
Marri Devender Rao81719702018-05-07 00:53:48 -05001661 }
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001662 log<level::ERR>("Error in BootMode Set",
1663 entry("ERROR=%s", ec.message().c_str()));
1664 return ipmi::ccUnspecifiedError;
1665}
1666
1667/** @brief Get the property value for boot type
1668 * @param[in] ctx - context pointer
1669 * @param[out] type - boot type value
1670 * @return On failure return IPMI error.
1671 */
1672static ipmi::Cc getBootType(ipmi::Context::ptr& ctx, Type::Types& type)
1673{
1674 using namespace chassis::internal;
1675 std::string result;
1676 std::string service;
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05001677 boost::system::error_code ec = getService(ctx, bootTypeIntf,
1678 bootSettingsPath, service);
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001679
1680 // Don't throw error if BootType interface is not present.
1681 // This interface is not relevant for some Host architectures
1682 // (for example POWER). In this case we don't won't IPMI to
1683 // return an error, but simply return bootType as EFI.
1684 type = Type::Types::EFI;
1685 if (!ec)
1686 {
1687 ec = ipmi::getDbusProperty(ctx, service, bootSettingsPath, bootTypeIntf,
1688 "BootType", result);
1689 if (ec)
1690 {
1691 log<level::ERR>("Error in BootType Get",
1692 entry("ERROR=%s", ec.message().c_str()));
1693 return ipmi::ccUnspecifiedError;
1694 }
1695 type = Type::convertTypesFromString(result);
1696 }
1697
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00001698 return ipmi::ccSuccess;
Marri Devender Rao81719702018-05-07 00:53:48 -05001699}
1700
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001701/** @brief Set the property value for boot type
Konstantin Aladysheve76a61a2021-03-18 22:19:13 +03001702 * @param[in] ctx - context pointer
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001703 * @param[in] type - boot type value
1704 * @return On failure return IPMI error.
1705 */
Konstantin Aladysheve76a61a2021-03-18 22:19:13 +03001706static ipmi::Cc setBootType(ipmi::Context::ptr& ctx, const Type::Types& type)
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001707{
1708 using namespace chassis::internal;
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001709 std::string service;
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05001710 boost::system::error_code ec = getService(ctx, bootTypeIntf,
1711 bootSettingsPath, service);
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001712 if (!ec)
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001713 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001714 ec = ipmi::setDbusProperty(ctx, service, bootSettingsPath, bootTypeIntf,
1715 "BootType", convertForMessage(type));
1716 if (ec)
1717 {
1718 log<level::ERR>("Error in BootType Set",
1719 entry("ERROR=%s", ec.message().c_str()));
1720 return ipmi::ccUnspecifiedError;
1721 }
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001722 }
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001723 // Don't throw error if BootType interface is not present.
1724 // This interface is not relevant for some Host architectures
1725 // (for example POWER). In this case we don't won't IPMI to
1726 // return an error, but want to just skip this function.
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001727 return ipmi::ccSuccess;
1728}
1729
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001730/** @brief Get the property value for boot override enable
1731 * @param[in] ctx - context pointer
1732 * @param[out] enable - boot override enable
1733 * @return On failure return IPMI error.
1734 */
1735static ipmi::Cc getBootEnable(ipmi::Context::ptr& ctx, bool& enable)
1736{
1737 using namespace chassis::internal;
1738 std::string result;
1739 std::string service;
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05001740 boost::system::error_code ec = getService(ctx, bootEnableIntf,
1741 bootSettingsPath, service);
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001742 if (!ec)
1743 {
1744 ec = ipmi::getDbusProperty(ctx, service, bootSettingsPath,
1745 bootEnableIntf, "Enabled", enable);
1746 if (!ec)
1747 {
1748 return ipmi::ccSuccess;
1749 }
1750 }
1751 log<level::ERR>("Error in Boot Override Enable Get",
1752 entry("ERROR=%s", ec.message().c_str()));
1753 return ipmi::ccUnspecifiedError;
1754}
1755
1756/** @brief Set the property value for boot override enable
1757 * @param[in] ctx - context pointer
1758 * @param[in] enable - boot override enable
1759 * @return On failure return IPMI error.
1760 */
1761static ipmi::Cc setBootEnable(ipmi::Context::ptr& ctx, const bool& enable)
1762{
1763 using namespace chassis::internal;
1764 std::string service;
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05001765 boost::system::error_code ec = getService(ctx, bootEnableIntf,
1766 bootSettingsPath, service);
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001767 if (!ec)
1768 {
1769 ec = ipmi::setDbusProperty(ctx, service, bootSettingsPath,
1770 bootEnableIntf, "Enabled", enable);
1771 if (!ec)
1772 {
1773 return ipmi::ccSuccess;
1774 }
1775 }
1776 log<level::ERR>("Error in Boot Source Override Enable Set",
1777 entry("ERROR=%s", ec.message().c_str()));
1778 return ipmi::ccUnspecifiedError;
1779}
1780
1781/** @brief Get the property value for boot override one-time
1782 * @param[in] ctx - context pointer
1783 * @param[out] onetime - boot override one-time
1784 * @return On failure return IPMI error.
1785 */
1786static ipmi::Cc getBootOneTime(ipmi::Context::ptr& ctx, bool& onetime)
1787{
1788 using namespace chassis::internal;
1789 std::string result;
1790 std::string service;
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05001791 boost::system::error_code ec = getService(ctx, bootOneTimeIntf,
1792 bootSettingsOneTimePath, service);
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001793 if (!ec)
1794 {
1795 ec = ipmi::getDbusProperty(ctx, service, bootSettingsOneTimePath,
1796 bootOneTimeIntf, "Enabled", onetime);
1797 if (!ec)
1798 {
1799 return ipmi::ccSuccess;
1800 }
1801 }
1802 log<level::ERR>("Error in Boot Override OneTime Get",
1803 entry("ERROR=%s", ec.message().c_str()));
1804 return ipmi::ccUnspecifiedError;
1805}
1806
1807/** @brief Set the property value for boot override one-time
1808 * @param[in] ctx - context pointer
1809 * @param[in] onetime - boot override one-time
1810 * @return On failure return IPMI error.
1811 */
1812static ipmi::Cc setBootOneTime(ipmi::Context::ptr& ctx, const bool& onetime)
1813{
1814 using namespace chassis::internal;
1815 std::string service;
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05001816 boost::system::error_code ec = getService(ctx, bootOneTimeIntf,
1817 bootSettingsOneTimePath, service);
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001818 if (!ec)
1819 {
1820 ec = ipmi::setDbusProperty(ctx, service, bootSettingsOneTimePath,
1821 bootOneTimeIntf, "Enabled", onetime);
1822 if (!ec)
1823 {
1824 return ipmi::ccSuccess;
1825 }
1826 }
1827 log<level::ERR>("Error in Boot Source Override OneTime Set",
1828 entry("ERROR=%s", ec.message().c_str()));
1829 return ipmi::ccUnspecifiedError;
1830}
1831
huangheab369282020-10-10 14:40:00 +08001832static constexpr uint8_t setComplete = 0x0;
1833static constexpr uint8_t setInProgress = 0x1;
1834static uint8_t transferStatus = setComplete;
Chen Yugang86ac4992021-06-25 08:14:52 +08001835static uint8_t bootFlagValidBitClr = 0;
Hieu Huynh38ffafc2021-05-14 08:40:14 +00001836static uint5_t bootInitiatorAckData = 0x0;
Hieu Huynh1982a3f2021-09-21 03:06:45 +00001837static bool cmosClear = false;
huangheab369282020-10-10 14:40:00 +08001838
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00001839/** @brief implements the Get Chassis system boot option
Konstantin Aladysheve76a61a2021-03-18 22:19:13 +03001840 * @param ctx - context pointer
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00001841 * @param bootOptionParameter - boot option parameter selector
1842 * @param reserved1 - reserved bit
1843 * @param setSelector - selects a particular block or set of parameters
1844 * under the given parameter selector
1845 * write as 00h if parameter doesn't use a setSelector
1846 * @param blockSelector- selects a particular block within a set of
1847 * parameters write as 00h if parameter doesn't use a
1848 * blockSelector
1849 *
1850 * @return IPMI completion code plus response data
1851 * @return Payload contains below parameters:
1852 * version - parameter version
1853 * bootOptionParameter - boot option parameter selector
Patrick Venture8b1c3032020-09-15 09:43:03 -07001854 * parmIndicator - parameter valid/invalid indicator
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00001855 * data - configuration parameter data
1856 */
1857ipmi::RspType<ipmi::message::Payload>
Konstantin Aladysheve76a61a2021-03-18 22:19:13 +03001858 ipmiChassisGetSysBootOptions(ipmi::Context::ptr ctx,
1859 uint7_t bootOptionParameter, bool reserved1,
Willy Tu11d68892022-01-20 10:37:34 -08001860 [[maybe_unused]] uint8_t setSelector,
1861 [[maybe_unused]] uint8_t blockSelector)
Adriana Kobylak40814c62015-10-27 15:58:44 -05001862{
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001863 ipmi::Cc rc;
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00001864 if (reserved1)
1865 {
1866 return ipmi::responseInvalidFieldRequest();
1867 }
1868
1869 constexpr uint4_t version = 0x01;
1870 ipmi::message::Payload response;
1871 response.pack(version, uint4_t{});
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001872 using namespace boot_options;
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00001873
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001874 IpmiValue bootOption = ipmiDefault;
Adriana Kobylak40814c62015-10-27 15:58:44 -05001875
William A. Kennington III7a0e5df2021-05-19 13:31:29 -07001876 if (types::enum_cast<BootOptionParameter>(bootOptionParameter) ==
1877 BootOptionParameter::setInProgress)
huangheab369282020-10-10 14:40:00 +08001878 {
1879 response.pack(bootOptionParameter, reserved1, transferStatus);
1880 return ipmi::responseSuccess(std::move(response));
1881 }
1882
William A. Kennington III7a0e5df2021-05-19 13:31:29 -07001883 if (types::enum_cast<BootOptionParameter>(bootOptionParameter) ==
1884 BootOptionParameter::bootInfo)
John Wang0213f902020-12-28 14:49:57 +08001885 {
1886 constexpr uint8_t writeMask = 0;
Hieu Huynh38ffafc2021-05-14 08:40:14 +00001887 response.pack(bootOptionParameter, reserved1, writeMask,
1888 bootInitiatorAckData);
John Wang0213f902020-12-28 14:49:57 +08001889 return ipmi::responseSuccess(std::move(response));
1890 }
1891
Chen Yugang86ac4992021-06-25 08:14:52 +08001892 if (types::enum_cast<BootOptionParameter>(bootOptionParameter) ==
1893 BootOptionParameter::bootFlagValidClr)
1894 {
1895 response.pack(bootOptionParameter, reserved1,
1896 uint5_t{bootFlagValidBitClr}, uint3_t{});
1897 return ipmi::responseSuccess(std::move(response));
1898 }
1899
shgoupfd84fbbf2015-12-17 10:05:51 +08001900 /*
1901 * Parameter #5 means boot flags. Please refer to 28.13 of ipmi doc.
1902 * This is the only parameter used by petitboot.
1903 */
William A. Kennington III7a0e5df2021-05-19 13:31:29 -07001904 if (types::enum_cast<BootOptionParameter>(bootOptionParameter) ==
1905 BootOptionParameter::bootFlags)
Patrick Venture0b02be92018-08-31 11:55:55 -07001906 {
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001907 using namespace chassis::internal;
1908 using namespace chassis::internal::cache;
shgoupfd84fbbf2015-12-17 10:05:51 +08001909
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001910 try
ratagupta6f6bff2016-04-04 06:20:11 -05001911 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001912 Source::Sources bootSource;
1913 rc = getBootSource(ctx, bootSource);
1914 if (rc != ipmi::ccSuccess)
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001915 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001916 return ipmi::response(rc);
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001917 }
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001918
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001919 Type::Types bootType;
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001920 rc = getBootType(ctx, bootType);
1921 if (rc != ipmi::ccSuccess)
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001922 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001923 return ipmi::response(rc);
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001924 }
1925
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001926 Mode::Modes bootMode;
1927 rc = getBootMode(ctx, bootMode);
1928 if (rc != ipmi::ccSuccess)
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001929 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001930 return ipmi::response(rc);
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001931 }
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001932
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001933 bootOption = sourceDbusToIpmi.at(bootSource);
1934 if ((Mode::Modes::Regular == bootMode) &&
1935 (Source::Sources::Default == bootSource))
1936 {
1937 bootOption = ipmiDefault;
1938 }
1939 else if (Source::Sources::Default == bootSource)
1940 {
1941 bootOption = modeDbusToIpmi.at(bootMode);
1942 }
ratagupta6f6bff2016-04-04 06:20:11 -05001943
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001944 IpmiValue biosBootType = typeDbusToIpmi.at(bootType);
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001945
1946 bool oneTimeEnabled;
1947 rc = getBootOneTime(ctx, oneTimeEnabled);
1948 if (rc != ipmi::ccSuccess)
1949 {
1950 return ipmi::response(rc);
1951 }
1952
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001953 uint1_t permanent = oneTimeEnabled ? 0 : 1;
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001954
1955 bool valid;
1956 rc = getBootEnable(ctx, valid);
1957 if (rc != ipmi::ccSuccess)
1958 {
1959 return ipmi::response(rc);
1960 }
1961
1962 uint1_t validFlag = valid ? 1 : 0;
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001963
1964 response.pack(bootOptionParameter, reserved1, uint5_t{},
1965 uint1_t{biosBootType}, uint1_t{permanent},
1966 uint1_t{validFlag}, uint2_t{}, uint4_t{bootOption},
Hieu Huynh1982a3f2021-09-21 03:06:45 +00001967 uint1_t{}, cmosClear, uint8_t{}, uint8_t{},
1968 uint8_t{});
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00001969 return ipmi::responseSuccess(std::move(response));
ratagupta6f6bff2016-04-04 06:20:11 -05001970 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -05001971 catch (const InternalFailure& e)
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001972 {
James Feist225dec82019-11-26 16:25:06 -08001973 cache::objectsPtr.reset();
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001974 report<InternalFailure>();
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00001975 return ipmi::responseUnspecifiedError();
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001976 }
Patrick Venture0b02be92018-08-31 11:55:55 -07001977 }
Patrick Venture0b02be92018-08-31 11:55:55 -07001978 else
1979 {
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00001980 if ((bootOptionParameter >= oemParmStart) &&
1981 (bootOptionParameter <= oemParmEnd))
1982 {
William A. Kennington III7a0e5df2021-05-19 13:31:29 -07001983 if (types::enum_cast<BootOptionParameter>(bootOptionParameter) ==
1984 BootOptionParameter::opalNetworkSettings)
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00001985 {
1986 response.pack(bootOptionParameter, reserved1);
1987 int ret = getHostNetworkData(response);
1988 if (ret < 0)
1989 {
1990 response.trailingOk = true;
1991 log<level::ERR>(
1992 "getHostNetworkData failed for GetSysBootOptions.");
1993 return ipmi::responseUnspecifiedError();
1994 }
1995 else
1996 {
1997 return ipmi::responseSuccess(std::move(response));
1998 }
1999 }
Jayaprakash Mutyala43a88102021-08-04 16:41:58 +00002000 else
2001 {
2002 log<level::ERR>(
2003 "ipmiChassisGetSysBootOptions: Unsupported parameter",
2004 entry("PARAM=0x%x",
2005 static_cast<uint8_t>(bootOptionParameter)));
2006 return ipmi::responseParmNotSupported();
2007 }
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00002008 }
2009 else
2010 {
2011 log<level::ERR>(
2012 "ipmiChassisGetSysBootOptions: Unsupported parameter",
2013 entry("PARAM=0x%x", static_cast<uint8_t>(bootOptionParameter)));
Jayaprakash Mutyala6088e9f2021-07-14 07:40:29 +00002014 return ipmi::responseParmNotSupported();
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00002015 }
shgoupfd84fbbf2015-12-17 10:05:51 +08002016 }
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00002017 return ipmi::responseUnspecifiedError();
shgoupfd84fbbf2015-12-17 10:05:51 +08002018}
2019
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002020ipmi::RspType<> ipmiChassisSetSysBootOptions(ipmi::Context::ptr ctx,
Willy Tu11d68892022-01-20 10:37:34 -08002021 uint7_t parameterSelector, bool,
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002022 ipmi::message::Payload& data)
shgoupfd84fbbf2015-12-17 10:05:51 +08002023{
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05002024 using namespace boot_options;
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002025 ipmi::Cc rc;
shgoupfd84fbbf2015-12-17 10:05:51 +08002026
William A. Kennington III7a0e5df2021-05-19 13:31:29 -07002027 if (types::enum_cast<BootOptionParameter>(parameterSelector) ==
2028 BootOptionParameter::setInProgress)
huangheab369282020-10-10 14:40:00 +08002029 {
2030 uint2_t setInProgressFlag;
2031 uint6_t rsvd;
2032 if (data.unpack(setInProgressFlag, rsvd) != 0 || !data.fullyUnpacked())
2033 {
2034 return ipmi::responseReqDataLenInvalid();
2035 }
2036 if (rsvd)
2037 {
2038 return ipmi::responseInvalidFieldRequest();
2039 }
2040 if ((transferStatus == setInProgress) &&
2041 (static_cast<uint8_t>(setInProgressFlag) != setComplete))
2042 {
2043 return ipmi::response(IPMI_CC_FAIL_SET_IN_PROGRESS);
2044 }
2045 transferStatus = static_cast<uint8_t>(setInProgressFlag);
2046 return ipmi::responseSuccess();
2047 }
2048
shgoupfd84fbbf2015-12-17 10:05:51 +08002049 /* 000101
2050 * Parameter #5 means boot flags. Please refer to 28.13 of ipmi doc.
2051 * This is the only parameter used by petitboot.
2052 */
Ratan Guptafd28dd72016-08-01 04:58:01 -05002053
William A. Kennington III7a0e5df2021-05-19 13:31:29 -07002054 if (types::enum_cast<BootOptionParameter>(parameterSelector) ==
2055 BootOptionParameter::bootFlags)
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05002056 {
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002057 uint5_t rsvd;
2058 bool validFlag;
2059 bool permanent;
2060 bool biosBootType;
2061 bool lockOutResetButton;
2062 bool screenBlank;
2063 uint4_t bootDeviceSelector;
2064 bool lockKeyboard;
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002065 uint8_t data3;
2066 uint4_t biosInfo;
2067 uint4_t rsvd1;
2068 uint5_t deviceInstance;
2069 uint3_t rsvd2;
2070
2071 if (data.unpack(rsvd, biosBootType, permanent, validFlag,
2072 lockOutResetButton, screenBlank, bootDeviceSelector,
2073 lockKeyboard, cmosClear, data3, biosInfo, rsvd1,
2074 deviceInstance, rsvd2) != 0 ||
2075 !data.fullyUnpacked())
2076 {
2077 return ipmi::responseReqDataLenInvalid();
2078 }
2079 if (rsvd || rsvd1 || rsvd2)
2080 {
2081 return ipmi::responseInvalidFieldRequest();
2082 }
2083
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05002084 using namespace chassis::internal;
2085 using namespace chassis::internal::cache;
shgoupfd84fbbf2015-12-17 10:05:51 +08002086
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05002087 try
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05002088 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03002089 rc = setBootOneTime(ctx, !permanent);
2090 if (rc != ipmi::ccSuccess)
Konstantin Aladyshev69e8e842021-06-18 17:01:18 +03002091 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03002092 return ipmi::response(rc);
2093 }
Vernon Maueryafd45db2021-07-29 16:27:25 +00002094
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03002095 rc = setBootEnable(ctx, validFlag);
2096 if (rc != ipmi::ccSuccess)
2097 {
2098 return ipmi::response(rc);
Tom Joseph57e8eb72017-09-25 18:05:02 +05302099 }
2100
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002101 auto modeItr =
2102 modeIpmiToDbus.find(static_cast<uint8_t>(bootDeviceSelector));
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03002103 auto typeItr =
2104 typeIpmiToDbus.find(static_cast<uint8_t>(biosBootType));
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002105 auto sourceItr =
2106 sourceIpmiToDbus.find(static_cast<uint8_t>(bootDeviceSelector));
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05002107 if (sourceIpmiToDbus.end() != sourceItr)
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05002108 {
Konstantin Aladysheve76a61a2021-03-18 22:19:13 +03002109 rc = setBootSource(ctx, sourceItr->second);
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002110 if (rc != ipmi::ccSuccess)
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05002111 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03002112 return ipmi::response(rc);
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05002113 }
Marri Devender Rao54fa1302018-05-07 01:06:23 -05002114 // If a set boot device is mapping to a boot source, then reset
2115 // the boot mode D-Bus property to default.
2116 // This way the ipmid code can determine which property is not
2117 // at the default value
Patrick Venture0b02be92018-08-31 11:55:55 -07002118 if (sourceItr->second != Source::Sources::Default)
Marri Devender Rao54fa1302018-05-07 01:06:23 -05002119 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03002120 rc = setBootMode(ctx, Mode::Modes::Regular);
2121 if (rc != ipmi::ccSuccess)
2122 {
2123 return ipmi::response(rc);
2124 }
Marri Devender Rao54fa1302018-05-07 01:06:23 -05002125 }
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05002126 }
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03002127
2128 if (typeIpmiToDbus.end() != typeItr)
2129 {
Konstantin Aladysheve76a61a2021-03-18 22:19:13 +03002130 rc = setBootType(ctx, typeItr->second);
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03002131 if (rc != ipmi::ccSuccess)
2132 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03002133 return ipmi::response(rc);
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03002134 }
2135 }
2136
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05002137 if (modeIpmiToDbus.end() != modeItr)
2138 {
Konstantin Aladysheve76a61a2021-03-18 22:19:13 +03002139 rc = setBootMode(ctx, modeItr->second);
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002140 if (rc != ipmi::ccSuccess)
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05002141 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03002142 return ipmi::response(rc);
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05002143 }
Marri Devender Rao54fa1302018-05-07 01:06:23 -05002144 // If a set boot device is mapping to a boot mode, then reset
2145 // the boot source D-Bus property to default.
2146 // This way the ipmid code can determine which property is not
2147 // at the default value
Patrick Venture0b02be92018-08-31 11:55:55 -07002148 if (modeItr->second != Mode::Modes::Regular)
Marri Devender Rao54fa1302018-05-07 01:06:23 -05002149 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03002150 rc = setBootSource(ctx, Source::Sources::Default);
2151 if (rc != ipmi::ccSuccess)
2152 {
2153 return ipmi::response(rc);
2154 }
Marri Devender Rao54fa1302018-05-07 01:06:23 -05002155 }
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05002156 }
Jia, chunhui67c5e5d2019-05-06 11:29:54 +08002157 if ((modeIpmiToDbus.end() == modeItr) &&
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03002158 (typeIpmiToDbus.end() == typeItr) &&
Jia, chunhui67c5e5d2019-05-06 11:29:54 +08002159 (sourceIpmiToDbus.end() == sourceItr))
2160 {
2161 // return error if boot option is not supported
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002162 log<level::ERR>(
2163 "ipmiChassisSetSysBootOptions: Boot option not supported");
2164 return ipmi::responseInvalidFieldRequest();
Jia, chunhui67c5e5d2019-05-06 11:29:54 +08002165 }
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05002166 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -05002167 catch (const sdbusplus::exception_t& e)
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05002168 {
James Feist225dec82019-11-26 16:25:06 -08002169 objectsPtr.reset();
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05002170 report<InternalFailure>();
Aditya Saripalli5fb14602017-11-09 14:46:27 +05302171 log<level::ERR>(
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002172 "ipmiChassisSetSysBootOptions: Error in setting Boot "
2173 "flag parameters");
2174 return ipmi::responseUnspecifiedError();
Ratan Guptafd28dd72016-08-01 04:58:01 -05002175 }
Patrick Venture0b02be92018-08-31 11:55:55 -07002176 }
William A. Kennington III7a0e5df2021-05-19 13:31:29 -07002177 else if (types::enum_cast<BootOptionParameter>(parameterSelector) ==
2178 BootOptionParameter::bootInfo)
Patrick Venture0b02be92018-08-31 11:55:55 -07002179 {
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002180 uint8_t writeMak;
Hieu Huynh38ffafc2021-05-14 08:40:14 +00002181 uint5_t bootInfoAck;
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002182 uint3_t rsvd;
2183
Hieu Huynh38ffafc2021-05-14 08:40:14 +00002184 if (data.unpack(writeMak, bootInfoAck, rsvd) != 0 ||
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002185 !data.fullyUnpacked())
2186 {
2187 return ipmi::responseReqDataLenInvalid();
2188 }
2189 if (rsvd)
2190 {
2191 return ipmi::responseInvalidFieldRequest();
2192 }
Hieu Huynh38ffafc2021-05-14 08:40:14 +00002193 bootInitiatorAckData &= ~writeMak;
2194 bootInitiatorAckData |= (writeMak & bootInfoAck);
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002195 log<level::INFO>("ipmiChassisSetSysBootOptions: bootInfo parameter set "
2196 "successfully");
2197 data.trailingOk = true;
2198 return ipmi::responseSuccess();
Patrick Venture0b02be92018-08-31 11:55:55 -07002199 }
Chen Yugang86ac4992021-06-25 08:14:52 +08002200 else if (types::enum_cast<BootOptionParameter>(parameterSelector) ==
2201 BootOptionParameter::bootFlagValidClr)
2202 {
2203 uint5_t bootFlagValidClr;
2204 uint3_t rsvd;
2205
2206 if (data.unpack(bootFlagValidClr, rsvd) != 0 || !data.fullyUnpacked())
2207 {
2208 return ipmi::responseReqDataLenInvalid();
2209 }
2210 if (rsvd)
2211 {
2212 return ipmi::responseInvalidFieldRequest();
2213 }
2214 // store boot flag valid bits clear value
2215 bootFlagValidBitClr = static_cast<uint8_t>(bootFlagValidClr);
2216 log<level::INFO>(
2217 "ipmiChassisSetSysBootOptions: bootFlagValidBits parameter set "
2218 "successfully",
2219 entry("value=0x%x", bootFlagValidBitClr));
2220 return ipmi::responseSuccess();
2221 }
Patrick Venture0b02be92018-08-31 11:55:55 -07002222 else
2223 {
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002224 if ((parameterSelector >= static_cast<uint7_t>(oemParmStart)) &&
2225 (parameterSelector <= static_cast<uint7_t>(oemParmEnd)))
2226 {
William A. Kennington III7a0e5df2021-05-19 13:31:29 -07002227 if (types::enum_cast<BootOptionParameter>(parameterSelector) ==
2228 BootOptionParameter::opalNetworkSettings)
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002229 {
2230 ipmi::Cc ret = setHostNetworkData(data);
2231 if (ret != ipmi::ccSuccess)
2232 {
2233 log<level::ERR>("ipmiChassisSetSysBootOptions: Error in "
2234 "setHostNetworkData");
2235 data.trailingOk = true;
2236 return ipmi::response(ret);
2237 }
2238 data.trailingOk = true;
2239 return ipmi::responseSuccess();
2240 }
2241 else
2242 {
2243 log<level::ERR>(
2244 "ipmiChassisSetSysBootOptions: Unsupported parameters",
2245 entry("PARAM=0x%x",
2246 static_cast<uint8_t>(parameterSelector)));
2247 data.trailingOk = true;
2248 return ipmi::responseParmNotSupported();
2249 }
2250 }
2251 data.trailingOk = true;
2252 return ipmi::responseParmNotSupported();
Adriana Kobylak40814c62015-10-27 15:58:44 -05002253 }
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002254 return ipmi::responseSuccess();
Adriana Kobylak40814c62015-10-27 15:58:44 -05002255}
2256
anil kumar appanaa5a76eb2019-04-30 14:57:24 +00002257/** @brief implements Get POH counter command
2258 * @parameter
2259 * - none
2260 * @returns IPMI completion code plus response data
2261 * - minPerCount - Minutes per count
2262 * - counterReading - counter reading
2263 */
2264ipmi::RspType<uint8_t, // Minutes per count
2265 uint32_t // Counter reading
2266 >
2267 ipmiGetPOHCounter()
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -05002268{
2269 // sd_bus error
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -05002270 try
2271 {
anil kumar appanaa5a76eb2019-04-30 14:57:24 +00002272 return ipmi::responseSuccess(static_cast<uint8_t>(poh::minutesPerCount),
2273 getPOHCounter());
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -05002274 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -05002275 catch (const std::exception& e)
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -05002276 {
2277 log<level::ERR>(e.what());
anil kumar appanaa5a76eb2019-04-30 14:57:24 +00002278 return ipmi::responseUnspecifiedError();
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -05002279 }
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -05002280}
2281
Jason M. Billsbc996a32019-06-17 15:46:37 -07002282ipmi::RspType<uint3_t, // policy support
2283 uint5_t // reserved
2284 >
Vernon Mauerye278ead2018-10-09 09:23:43 -07002285 ipmiChassisSetPowerRestorePolicy(boost::asio::yield_context yield,
Jason M. Billsbc996a32019-06-17 15:46:37 -07002286 uint3_t policy, uint5_t reserved)
Yong Lic6713cf2018-09-12 12:35:13 +08002287{
Yong Lic6713cf2018-09-12 12:35:13 +08002288 power_policy::DbusValue value =
2289 power_policy::RestorePolicy::Policy::AlwaysOff;
2290
Jason M. Billsbc996a32019-06-17 15:46:37 -07002291 if (reserved || (policy > power_policy::noChange))
Yong Lic6713cf2018-09-12 12:35:13 +08002292 {
Vernon Mauerye278ead2018-10-09 09:23:43 -07002293 phosphor::logging::log<level::ERR>(
2294 "Reserved request parameter",
2295 entry("REQ=0x%x", static_cast<int>(policy)));
Jason M. Billsbc996a32019-06-17 15:46:37 -07002296 return ipmi::responseInvalidFieldRequest();
Yong Lic6713cf2018-09-12 12:35:13 +08002297 }
2298
Vernon Mauerye278ead2018-10-09 09:23:43 -07002299 if (policy == power_policy::noChange)
Yong Lic6713cf2018-09-12 12:35:13 +08002300 {
2301 // just return the supported policy
Jason M. Billsbc996a32019-06-17 15:46:37 -07002302 return ipmi::responseSuccess(power_policy::allSupport, reserved);
Yong Lic6713cf2018-09-12 12:35:13 +08002303 }
2304
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05002305 for (const auto& it : power_policy::dbusToIpmi)
Yong Lic6713cf2018-09-12 12:35:13 +08002306 {
Vernon Mauerye278ead2018-10-09 09:23:43 -07002307 if (it.second == policy)
Yong Lic6713cf2018-09-12 12:35:13 +08002308 {
2309 value = it.first;
2310 break;
2311 }
2312 }
2313
2314 try
2315 {
James Feist225dec82019-11-26 16:25:06 -08002316 settings::Objects& objects = chassis::internal::cache::getObjects();
Yong Lic6713cf2018-09-12 12:35:13 +08002317 const settings::Path& powerRestoreSetting =
James Feist225dec82019-11-26 16:25:06 -08002318 objects.map.at(chassis::internal::powerRestoreIntf).front();
Vernon Mauery16b86932019-05-01 08:36:11 -07002319 std::variant<std::string> property = convertForMessage(value);
Yong Lic6713cf2018-09-12 12:35:13 +08002320
Vernon Mauerye278ead2018-10-09 09:23:43 -07002321 auto sdbusp = getSdBus();
2322 boost::system::error_code ec;
2323 sdbusp->yield_method_call<void>(
2324 yield, ec,
James Feist225dec82019-11-26 16:25:06 -08002325 objects
Yong Lic6713cf2018-09-12 12:35:13 +08002326 .service(powerRestoreSetting,
2327 chassis::internal::powerRestoreIntf)
2328 .c_str(),
Vernon Mauerye278ead2018-10-09 09:23:43 -07002329 powerRestoreSetting, ipmi::PROP_INTF, "Set",
2330 chassis::internal::powerRestoreIntf, "PowerRestorePolicy",
2331 property);
2332 if (ec)
Yong Lic6713cf2018-09-12 12:35:13 +08002333 {
2334 phosphor::logging::log<level::ERR>("Unspecified Error");
Vernon Mauerye278ead2018-10-09 09:23:43 -07002335 return ipmi::responseUnspecifiedError();
Yong Lic6713cf2018-09-12 12:35:13 +08002336 }
2337 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -05002338 catch (const InternalFailure& e)
Yong Lic6713cf2018-09-12 12:35:13 +08002339 {
James Feist225dec82019-11-26 16:25:06 -08002340 chassis::internal::cache::objectsPtr.reset();
Yong Lic6713cf2018-09-12 12:35:13 +08002341 report<InternalFailure>();
Vernon Mauerye278ead2018-10-09 09:23:43 -07002342 return ipmi::responseUnspecifiedError();
Yong Lic6713cf2018-09-12 12:35:13 +08002343 }
2344
Jason M. Billsbc996a32019-06-17 15:46:37 -07002345 return ipmi::responseSuccess(power_policy::allSupport, reserved);
Yong Lic6713cf2018-09-12 12:35:13 +08002346}
2347
Willy Tu11d68892022-01-20 10:37:34 -08002348ipmi::RspType<> ipmiSetFrontPanelButtonEnables(ipmi::Context::ptr ctx,
2349 bool disablePowerButton,
2350 bool disableResetButton, bool,
2351 bool, uint4_t)
Kuiying Wang21addc52019-01-04 10:50:21 +08002352{
2353 using namespace chassis::internal;
2354
2355 // set power button Enabled property
2356 bool success = setButtonEnabled(ctx, powerButtonPath, powerButtonIntf,
2357 !disablePowerButton);
2358
2359 // set reset button Enabled property
2360 success &= setButtonEnabled(ctx, resetButtonPath, resetButtonIntf,
2361 !disableResetButton);
2362
2363 if (!success)
2364 {
2365 // not all buttons were successfully set
2366 return ipmi::responseUnspecifiedError();
2367 }
2368 return ipmi::responseSuccess();
2369}
2370
Adriana Kobylak40814c62015-10-27 15:58:44 -05002371void register_netfn_chassis_functions()
2372{
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05002373 createIdentifyTimer();
2374
Tom05732372016-09-06 17:21:23 +05302375 // Get Chassis Capabilities
anil kumar appana43263c62019-05-27 12:45:04 +00002376 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis,
2377 ipmi::chassis::cmdGetChassisCapabilities,
2378 ipmi::Privilege::User, ipmiGetChassisCap);
Nan Li8d15fb42016-08-16 22:29:40 +08002379
Kuiying Wang21addc52019-01-04 10:50:21 +08002380 // Set Front Panel Button Enables
2381 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis,
2382 ipmi::chassis::cmdSetFrontPanelButtonEnables,
2383 ipmi::Privilege::Admin,
2384 ipmiSetFrontPanelButtonEnables);
2385
Yong Liae4b0402018-11-02 11:12:14 +08002386 // Set Chassis Capabilities
anil kumar appana894d0222019-05-27 16:32:14 +00002387 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis,
2388 ipmi::chassis::cmdSetChassisCapabilities,
2389 ipmi::Privilege::User, ipmiSetChassisCap);
Yong Liae4b0402018-11-02 11:12:14 +08002390
Tom05732372016-09-06 17:21:23 +05302391 // <Get System Boot Options>
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00002392 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis,
2393 ipmi::chassis::cmdGetSystemBootOptions,
2394 ipmi::Privilege::Operator,
2395 ipmiChassisGetSysBootOptions);
Adriana Kobylak40814c62015-10-27 15:58:44 -05002396
Tom05732372016-09-06 17:21:23 +05302397 // <Get Chassis Status>
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07002398 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis,
2399 ipmi::chassis::cmdGetChassisStatus,
2400 ipmi::Privilege::User, ipmiGetChassisStatus);
Nan Lifdd8ec52016-08-28 03:57:40 +08002401
Vijay Khemka074f64d2020-03-03 15:08:43 -08002402 // <Chassis Get System Restart Cause>
2403 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis,
2404 ipmi::chassis::cmdGetSystemRestartCause,
2405 ipmi::Privilege::User, ipmiGetSystemRestartCause);
2406
Tom05732372016-09-06 17:21:23 +05302407 // <Chassis Control>
anil kumar appanadafff5f2019-04-27 18:06:00 +00002408 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis,
2409 ipmi::chassis::cmdChassisControl,
2410 ipmi::Privilege::Operator, ipmiChassisControl);
shgoupfd84fbbf2015-12-17 10:05:51 +08002411
Tom Joseph5110c122018-03-23 17:55:40 +05302412 // <Chassis Identify>
Vernon Mauery400cc782018-10-09 13:49:53 -07002413 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis,
2414 ipmi::chassis::cmdChassisIdentify,
2415 ipmi::Privilege::Operator, ipmiChassisIdentify);
Tom Joseph5110c122018-03-23 17:55:40 +05302416
Tom05732372016-09-06 17:21:23 +05302417 // <Set System Boot Options>
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002418 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis,
2419 ipmi::chassis::cmdSetSystemBootOptions,
2420 ipmi::Privilege::Operator,
2421 ipmiChassisSetSysBootOptions);
2422
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -05002423 // <Get POH Counter>
anil kumar appanaa5a76eb2019-04-30 14:57:24 +00002424 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis,
2425 ipmi::chassis::cmdGetPohCounter,
2426 ipmi::Privilege::User, ipmiGetPOHCounter);
Yong Lic6713cf2018-09-12 12:35:13 +08002427
2428 // <Set Power Restore Policy>
Vernon Mauerye278ead2018-10-09 09:23:43 -07002429 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis,
2430 ipmi::chassis::cmdSetPowerRestorePolicy,
2431 ipmi::Privilege::Operator,
2432 ipmiChassisSetPowerRestorePolicy);
vishwa36993272015-11-20 12:43:49 -06002433}