blob: 553bbe017788f48d5bae04983c482469a3fef6d6 [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
Patrick Williams95655222023-12-05 12:45:02 -060040std::unique_ptr<sdbusplus::Timer> identifyTimer
Lei YU4b0ddb62019-01-25 16:43:50 +080041 __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
Willy Tu523e2d12023-09-05 11:36:48 -0700122namespace State = sdbusplus::server::xyz::openbmc_project::state;
Vernon Mauery185b9f82018-07-20 10:52:36 -0700123namespace fs = std::filesystem;
Andrew Geisslera6e3a302017-05-31 19:34:00 -0500124
Ratan Guptadcb10672017-07-10 10:33:50 +0530125using namespace phosphor::logging;
Willy Tu523e2d12023-09-05 11:36:48 -0700126using namespace sdbusplus::error::xyz::openbmc_project::common;
127using namespace sdbusplus::server::xyz::openbmc_project::control::boot;
William A. Kennington III4c008022018-10-12 17:18:14 -0700128
Deepak Kodihalli8cc19362017-07-21 11:18:38 -0500129namespace chassis
130{
131namespace internal
132{
133
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +0300134constexpr auto bootSettingsPath = "/xyz/openbmc_project/control/host0/boot";
135constexpr auto bootEnableIntf = "xyz.openbmc_project.Object.Enable";
Deepak Kodihalli8cc19362017-07-21 11:18:38 -0500136constexpr auto bootModeIntf = "xyz.openbmc_project.Control.Boot.Mode";
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +0300137constexpr auto bootTypeIntf = "xyz.openbmc_project.Control.Boot.Type";
Deepak Kodihalli8cc19362017-07-21 11:18:38 -0500138constexpr auto bootSourceIntf = "xyz.openbmc_project.Control.Boot.Source";
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +0300139constexpr auto bootSettingsOneTimePath =
140 "/xyz/openbmc_project/control/host0/boot/one_time";
141constexpr auto bootOneTimeIntf = "xyz.openbmc_project.Object.Enable";
142
Deepak Kodihalli18b70d12017-07-21 13:36:33 -0500143constexpr auto powerRestoreIntf =
144 "xyz.openbmc_project.Control.Power.RestorePolicy";
Patrick Williams5d82f472022-07-22 19:26:53 -0500145sdbusplus::bus_t dbus(ipmid_get_sd_bus_connection());
Deepak Kodihalli8cc19362017-07-21 11:18:38 -0500146
147namespace cache
148{
149
James Feist225dec82019-11-26 16:25:06 -0800150std::unique_ptr<settings::Objects> objectsPtr = nullptr;
151
152settings::Objects& getObjects()
153{
154 if (objectsPtr == nullptr)
155 {
156 objectsPtr = std::make_unique<settings::Objects>(
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +0300157 dbus, std::vector<std::string>{bootModeIntf, bootTypeIntf,
158 bootSourceIntf, powerRestoreIntf});
James Feist225dec82019-11-26 16:25:06 -0800159 }
160 return *objectsPtr;
161}
Deepak Kodihalli8cc19362017-07-21 11:18:38 -0500162
163} // namespace cache
164} // namespace internal
165} // namespace chassis
166
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -0500167namespace poh
168{
169
170constexpr auto minutesPerCount = 60;
171
172} // namespace poh
173
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000174int getHostNetworkData(ipmi::message::Payload& payload)
Ratan Guptafd28dd72016-08-01 04:58:01 -0500175{
Ratan Guptadcb10672017-07-10 10:33:50 +0530176 ipmi::PropertyMap properties;
177 int rc = 0;
Ratan Gupta8c31d232017-08-13 05:49:43 +0530178 uint8_t addrSize = ipmi::network::IPV4_ADDRESS_SIZE_BYTE;
Ratan Guptafd28dd72016-08-01 04:58:01 -0500179
Ratan Guptadcb10672017-07-10 10:33:50 +0530180 try
181 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700182 // TODO There may be cases where an interface is implemented by multiple
Ratan Guptadcb10672017-07-10 10:33:50 +0530183 // objects,to handle such cases we are interested on that object
184 // which are on interested busname.
185 // Currenlty mapper doesn't give the readable busname(gives busid)
186 // so we can't match with bus name so giving some object specific info
187 // as SETTINGS_MATCH.
188 // Later SETTINGS_MATCH will be replaced with busname.
Ratan Guptafd28dd72016-08-01 04:58:01 -0500189
Patrick Williams5d82f472022-07-22 19:26:53 -0500190 sdbusplus::bus_t bus(ipmid_get_sd_bus_connection());
Ratan Guptadcb10672017-07-10 10:33:50 +0530191
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530192 auto ipObjectInfo = ipmi::getDbusObject(bus, IP_INTERFACE,
193 SETTINGS_ROOT, SETTINGS_MATCH);
194
195 auto macObjectInfo = ipmi::getDbusObject(bus, MAC_INTERFACE,
196 SETTINGS_ROOT, SETTINGS_MATCH);
197
Patrick Venture0b02be92018-08-31 11:55:55 -0700198 properties = ipmi::getAllDbusProperties(
199 bus, ipObjectInfo.second, ipObjectInfo.first, IP_INTERFACE);
200 auto variant = ipmi::getDbusProperty(bus, macObjectInfo.second,
201 macObjectInfo.first, MAC_INTERFACE,
202 "MACAddress");
Ratan Guptadcb10672017-07-10 10:33:50 +0530203
Vernon Maueryf442e112019-04-09 11:44:36 -0700204 auto ipAddress = std::get<std::string>(properties["Address"]);
Ratan Guptad70f4532017-08-04 02:07:31 +0530205
Vernon Maueryf442e112019-04-09 11:44:36 -0700206 auto gateway = std::get<std::string>(properties["Gateway"]);
Ratan Guptad70f4532017-08-04 02:07:31 +0530207
Vernon Maueryf442e112019-04-09 11:44:36 -0700208 auto prefix = std::get<uint8_t>(properties["PrefixLength"]);
Ratan Guptad70f4532017-08-04 02:07:31 +0530209
Patrick Venture0b02be92018-08-31 11:55:55 -0700210 uint8_t isStatic =
Vernon Maueryf442e112019-04-09 11:44:36 -0700211 (std::get<std::string>(properties["Origin"]) ==
Patrick Venture0b02be92018-08-31 11:55:55 -0700212 "xyz.openbmc_project.Network.IP.AddressOrigin.Static")
213 ? 1
214 : 0;
Ratan Guptad70f4532017-08-04 02:07:31 +0530215
Vernon Maueryf442e112019-04-09 11:44:36 -0700216 auto MACAddress = std::get<std::string>(variant);
Ratan Guptacc8feb42017-07-25 21:52:10 +0530217
Ratan Guptad70f4532017-08-04 02:07:31 +0530218 // it is expected here that we should get the valid data
219 // but we may also get the default values.
220 // Validation of the data is done by settings.
221 //
222 // if mac address is default mac address then
223 // don't send blank override.
Ratan Gupta8c31d232017-08-13 05:49:43 +0530224 if ((MACAddress == ipmi::network::DEFAULT_MAC_ADDRESS))
Ratan Guptad70f4532017-08-04 02:07:31 +0530225 {
Ratan Guptad70f4532017-08-04 02:07:31 +0530226 rc = -1;
227 return rc;
228 }
229 // if addr is static then ipaddress,gateway,prefix
230 // should not be default one,don't send blank override.
231 if (isStatic)
232 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700233 if ((ipAddress == ipmi::network::DEFAULT_ADDRESS) ||
234 (gateway == ipmi::network::DEFAULT_ADDRESS) || (!prefix))
Ratan Guptad70f4532017-08-04 02:07:31 +0530235 {
Ratan Guptad70f4532017-08-04 02:07:31 +0530236 rc = -1;
237 return rc;
238 }
239 }
240
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000241 std::string token;
242 std::stringstream ss(MACAddress);
Ratan Guptadcb10672017-07-10 10:33:50 +0530243
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000244 // First pack macOffset no of bytes in payload.
245 // Latter this PetiBoot-Specific data will be populated.
246 std::vector<uint8_t> payloadInitialBytes(macOffset);
247 payload.pack(payloadInitialBytes);
Ratan Guptadcb10672017-07-10 10:33:50 +0530248
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000249 while (std::getline(ss, token, ':'))
250 {
251 payload.pack(stoi(token, nullptr, 16));
252 }
253
254 payload.pack(0x00);
255
256 payload.pack(isStatic);
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530257
Vernon Maueryf442e112019-04-09 11:44:36 -0700258 uint8_t addressFamily = (std::get<std::string>(properties["Type"]) ==
259 "xyz.openbmc_project.Network.IP.Protocol.IPv4")
260 ? AF_INET
261 : AF_INET6;
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530262
Patrick Venture0b02be92018-08-31 11:55:55 -0700263 addrSize = (addressFamily == AF_INET)
264 ? ipmi::network::IPV4_ADDRESS_SIZE_BYTE
265 : ipmi::network::IPV6_ADDRESS_SIZE_BYTE;
Ratan Guptadcb10672017-07-10 10:33:50 +0530266
267 // ipaddress and gateway would be in IPv4 format
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000268 std::vector<uint8_t> addrInBinary(addrSize);
Ratan Guptad70f4532017-08-04 02:07:31 +0530269 inet_pton(addressFamily, ipAddress.c_str(),
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000270 reinterpret_cast<void*>(addrInBinary.data()));
Ratan Guptadcb10672017-07-10 10:33:50 +0530271
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000272 payload.pack(addrInBinary);
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530273
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000274 payload.pack(prefix);
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530275
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000276 std::vector<uint8_t> gatewayDetails(addrSize);
Ratan Guptad70f4532017-08-04 02:07:31 +0530277 inet_pton(addressFamily, gateway.c_str(),
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000278 reinterpret_cast<void*>(gatewayDetails.data()));
279 payload.pack(gatewayDetails);
Ratan Guptadcb10672017-07-10 10:33:50 +0530280 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -0500281 catch (const InternalFailure& e)
Ratan Guptadcb10672017-07-10 10:33:50 +0530282 {
283 commit<InternalFailure>();
Ratan Guptadcb10672017-07-10 10:33:50 +0530284 rc = -1;
Ratan Guptafd28dd72016-08-01 04:58:01 -0500285 return rc;
286 }
287
Patrick Venture0b02be92018-08-31 11:55:55 -0700288 // PetiBoot-Specific
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000289 // If success then copy the first 9 bytes to the payload message
290 // payload first 2 bytes contain the parameter values. Skip that 2 bytes.
291 uint8_t skipFirstTwoBytes = 2;
292 size_t payloadSize = payload.size();
293 uint8_t* configDataStartingAddress = payload.data() + skipFirstTwoBytes;
Ratan Guptafd28dd72016-08-01 04:58:01 -0500294
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000295 if (payloadSize < skipFirstTwoBytes + sizeof(netConfInitialBytes))
296 {
297 log<level::ERR>("Invalid net config ");
298 rc = -1;
299 return rc;
300 }
301 std::copy(netConfInitialBytes,
302 netConfInitialBytes + sizeof(netConfInitialBytes),
303 configDataStartingAddress);
304
305 if (payloadSize < skipFirstTwoBytes + addrSizeOffset + sizeof(addrSize))
306 {
307 log<level::ERR>("Invalid length of address size");
308 rc = -1;
309 return rc;
310 }
311 std::copy(&addrSize, &(addrSize) + sizeof(addrSize),
312 configDataStartingAddress + addrSizeOffset);
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530313
Ratan Guptafd28dd72016-08-01 04:58:01 -0500314#ifdef _IPMI_DEBUG_
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700315 std::printf("\n===Printing the IPMI Formatted Data========\n");
Ratan Guptafd28dd72016-08-01 04:58:01 -0500316
Ratan Guptadcb10672017-07-10 10:33:50 +0530317 for (uint8_t pos = 0; pos < index; pos++)
318 {
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000319 std::printf("%02x ", payloadStartingAddress[pos]);
Ratan Guptadcb10672017-07-10 10:33:50 +0530320 }
Ratan Guptafd28dd72016-08-01 04:58:01 -0500321#endif
322
Ratan Guptafd28dd72016-08-01 04:58:01 -0500323 return rc;
324}
325
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530326/** @brief convert IPv4 and IPv6 addresses from binary to text form.
327 * @param[in] family - IPv4/Ipv6
328 * @param[in] data - req data pointer.
329 * @param[in] offset - offset in the data.
330 * @param[in] addrSize - size of the data which needs to be read from offset.
331 * @returns address in text form.
332 */
333
Patrick Venture0b02be92018-08-31 11:55:55 -0700334std::string getAddrStr(uint8_t family, uint8_t* data, uint8_t offset,
335 uint8_t addrSize)
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530336{
337 char ipAddr[INET6_ADDRSTRLEN] = {};
338
Patrick Venture0b02be92018-08-31 11:55:55 -0700339 switch (family)
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530340 {
341 case AF_INET:
342 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700343 struct sockaddr_in addr4
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -0500344 {};
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700345 std::memcpy(&addr4.sin_addr.s_addr, &data[offset], addrSize);
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530346
Patrick Venture0b02be92018-08-31 11:55:55 -0700347 inet_ntop(AF_INET, &addr4.sin_addr, ipAddr, INET_ADDRSTRLEN);
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530348
349 break;
350 }
351 case AF_INET6:
352 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700353 struct sockaddr_in6 addr6
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -0500354 {};
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700355 std::memcpy(&addr6.sin6_addr.s6_addr, &data[offset], addrSize);
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530356
Patrick Venture0b02be92018-08-31 11:55:55 -0700357 inet_ntop(AF_INET6, &addr6.sin6_addr, ipAddr, INET6_ADDRSTRLEN);
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530358
359 break;
360 }
361 default:
362 {
363 return {};
364 }
365 }
366
367 return ipAddr;
368}
369
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000370ipmi::Cc setHostNetworkData(ipmi::message::Payload& data)
Ratan Guptafd28dd72016-08-01 04:58:01 -0500371{
Ratan Guptadcb10672017-07-10 10:33:50 +0530372 using namespace std::string_literals;
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000373 std::string hostNetworkConfig;
374 std::string mac("00:00:00:00:00:00");
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530375 std::string ipAddress, gateway;
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000376 std::string addrOrigin{0};
Patrick Venture0b02be92018-08-31 11:55:55 -0700377 uint8_t addrSize{0};
Ratan Guptadcb10672017-07-10 10:33:50 +0530378 std::string addressOrigin =
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530379 "xyz.openbmc_project.Network.IP.AddressOrigin.DHCP";
Patrick Venture0b02be92018-08-31 11:55:55 -0700380 std::string addressType = "xyz.openbmc_project.Network.IP.Protocol.IPv4";
381 uint8_t prefix{0};
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530382 uint8_t family = AF_INET;
Ratan Guptafd28dd72016-08-01 04:58:01 -0500383
Patrick Venture0b02be92018-08-31 11:55:55 -0700384 // cookie starts from second byte
Ratan Guptafd28dd72016-08-01 04:58:01 -0500385 // version starts from sixth byte
386
Ratan Guptadcb10672017-07-10 10:33:50 +0530387 try
Ratan Guptafd28dd72016-08-01 04:58:01 -0500388 {
Ratan Guptadcb10672017-07-10 10:33:50 +0530389 do
390 {
391 // cookie == 0x21 0x70 0x62 0x21
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000392 data.trailingOk = true;
393 auto msgLen = data.size();
394 std::vector<uint8_t> msgPayloadBytes(msgLen);
395 if (data.unpack(msgPayloadBytes) != 0 || !data.fullyUnpacked())
Ratan Guptadcb10672017-07-10 10:33:50 +0530396 {
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000397 log<level::ERR>(
398 "Error in unpacking message of setHostNetworkData");
399 return ipmi::ccReqDataLenInvalid;
400 }
401
402 uint8_t* msgPayloadStartingPos = msgPayloadBytes.data();
403 constexpr size_t cookieSize = 4;
404 if (msgLen < cookieOffset + cookieSize)
405 {
406 log<level::ERR>(
407 "Error in cookie getting of setHostNetworkData");
408 return ipmi::ccReqDataLenInvalid;
409 }
410 if (std::equal(msgPayloadStartingPos + cookieOffset,
411 msgPayloadStartingPos + cookieOffset + cookieSize,
412 (netConfInitialBytes + cookieOffset)) != 0)
413 {
414 // all cookie == 0
415 if (std::all_of(msgPayloadStartingPos + cookieOffset,
416 msgPayloadStartingPos + cookieOffset +
417 cookieSize,
418 [](int i) { return i == 0; }) == true)
Ratan Guptadcb10672017-07-10 10:33:50 +0530419 {
420 // need to zero out the network settings.
421 break;
422 }
423
424 log<level::ERR>("Invalid Cookie");
425 elog<InternalFailure>();
426 }
427
428 // vesion == 0x00 0x01
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000429 if (msgLen < versionOffset + sizeVersion)
Ratan Guptadcb10672017-07-10 10:33:50 +0530430 {
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000431 log<level::ERR>(
432 "Error in version getting of setHostNetworkData");
433 return ipmi::ccReqDataLenInvalid;
434 }
435 if (std::equal(msgPayloadStartingPos + versionOffset,
436 msgPayloadStartingPos + versionOffset + sizeVersion,
437 (netConfInitialBytes + versionOffset)) != 0)
438 {
Ratan Guptadcb10672017-07-10 10:33:50 +0530439 log<level::ERR>("Invalid Version");
440 elog<InternalFailure>();
441 }
442
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000443 if (msgLen < macOffset + 6)
444 {
445 log<level::ERR>(
446 "Error in mac address getting of setHostNetworkData");
447 return ipmi::ccReqDataLenInvalid;
448 }
449 std::stringstream result;
450 std::copy((msgPayloadStartingPos + macOffset),
451 (msgPayloadStartingPos + macOffset + 5),
452 std::ostream_iterator<int>(result, ":"));
453 mac = result.str();
Ratan Guptadcb10672017-07-10 10:33:50 +0530454
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000455 if (msgLen < addrTypeOffset + sizeof(decltype(addrOrigin)))
456 {
457 log<level::ERR>(
458 "Error in original address getting of setHostNetworkData");
459 return ipmi::ccReqDataLenInvalid;
460 }
461 std::copy(msgPayloadStartingPos + addrTypeOffset,
462 msgPayloadStartingPos + addrTypeOffset +
463 sizeof(decltype(addrOrigin)),
464 std::ostream_iterator<int>(result, ""));
465 addrOrigin = result.str();
Ratan Guptadcb10672017-07-10 10:33:50 +0530466
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000467 if (!addrOrigin.empty())
Ratan Guptadcb10672017-07-10 10:33:50 +0530468 {
469 addressOrigin =
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530470 "xyz.openbmc_project.Network.IP.AddressOrigin.Static";
Ratan Guptadcb10672017-07-10 10:33:50 +0530471 }
472
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000473 if (msgLen < addrSizeOffset + sizeof(decltype(addrSize)))
474 {
475 log<level::ERR>(
476 "Error in address size getting of setHostNetworkData");
477 return ipmi::ccReqDataLenInvalid;
478 }
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530479 // Get the address size
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000480 std::copy(msgPayloadStartingPos + addrSizeOffset,
481 (msgPayloadStartingPos + addrSizeOffset +
482 sizeof(decltype(addrSize))),
483 &addrSize);
Ratan Guptadcb10672017-07-10 10:33:50 +0530484
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000485 uint8_t prefixOffset = ipAddrOffset + addrSize;
486 if (msgLen < prefixOffset + sizeof(decltype(prefix)))
487 {
488 log<level::ERR>(
489 "Error in prefix getting of setHostNetworkData");
490 return ipmi::ccReqDataLenInvalid;
491 }
William A. Kennington III4c521022023-07-28 13:07:30 -0700492 // std::copy(msgPayloadStartingPos + prefixOffset,
493 // msgPayloadStartingPos + prefixOffset +
494 // sizeof(decltype(prefix)),
495 // &prefix);
496 // Workaround compiler misdetecting out of bounds memcpy
497 prefix = msgPayloadStartingPos[prefixOffset];
Ratan Guptadcb10672017-07-10 10:33:50 +0530498
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530499 uint8_t gatewayOffset = prefixOffset + sizeof(decltype(prefix));
Ratan Gupta8c31d232017-08-13 05:49:43 +0530500 if (addrSize != ipmi::network::IPV4_ADDRESS_SIZE_BYTE)
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530501 {
502 addressType = "xyz.openbmc_project.Network.IP.Protocol.IPv6";
503 family = AF_INET6;
504 }
505
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000506 if (msgLen < ipAddrOffset + addrSize)
507 {
508 log<level::ERR>(
509 "Error in IP address getting of setHostNetworkData");
510 return ipmi::ccReqDataLenInvalid;
511 }
512 ipAddress = getAddrStr(family, msgPayloadStartingPos, ipAddrOffset,
513 addrSize);
Ratan Guptad70f4532017-08-04 02:07:31 +0530514
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000515 if (msgLen < gatewayOffset + addrSize)
516 {
517 log<level::ERR>(
518 "Error in gateway address getting of setHostNetworkData");
519 return ipmi::ccReqDataLenInvalid;
520 }
521 gateway = getAddrStr(family, msgPayloadStartingPos, gatewayOffset,
522 addrSize);
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530523
Patrick Venture0b02be92018-08-31 11:55:55 -0700524 } while (0);
Ratan Guptadcb10672017-07-10 10:33:50 +0530525
Patrick Venture0b02be92018-08-31 11:55:55 -0700526 // Cookie == 0 or it is a valid cookie
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000527 hostNetworkConfig += "ipaddress="s + ipAddress + ",prefix="s +
528 std::to_string(prefix) + ",gateway="s + gateway +
529 ",mac="s + mac + ",addressOrigin="s +
530 addressOrigin;
Ratan Guptafd28dd72016-08-01 04:58:01 -0500531
Patrick Williams5d82f472022-07-22 19:26:53 -0500532 sdbusplus::bus_t bus(ipmid_get_sd_bus_connection());
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530533
534 auto ipObjectInfo = ipmi::getDbusObject(bus, IP_INTERFACE,
535 SETTINGS_ROOT, SETTINGS_MATCH);
536 auto macObjectInfo = ipmi::getDbusObject(bus, MAC_INTERFACE,
537 SETTINGS_ROOT, SETTINGS_MATCH);
Ratan Guptadcb10672017-07-10 10:33:50 +0530538 // set the dbus property
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530539 ipmi::setDbusProperty(bus, ipObjectInfo.second, ipObjectInfo.first,
Patrick Venture0b02be92018-08-31 11:55:55 -0700540 IP_INTERFACE, "Address", std::string(ipAddress));
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530541 ipmi::setDbusProperty(bus, ipObjectInfo.second, ipObjectInfo.first,
Patrick Venture0b02be92018-08-31 11:55:55 -0700542 IP_INTERFACE, "PrefixLength", prefix);
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530543 ipmi::setDbusProperty(bus, ipObjectInfo.second, ipObjectInfo.first,
Patrick Venture0b02be92018-08-31 11:55:55 -0700544 IP_INTERFACE, "Origin", addressOrigin);
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530545 ipmi::setDbusProperty(bus, ipObjectInfo.second, ipObjectInfo.first,
Patrick Venture0b02be92018-08-31 11:55:55 -0700546 IP_INTERFACE, "Gateway", std::string(gateway));
547 ipmi::setDbusProperty(
548 bus, ipObjectInfo.second, ipObjectInfo.first, IP_INTERFACE, "Type",
549 std::string("xyz.openbmc_project.Network.IP.Protocol.IPv4"));
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530550 ipmi::setDbusProperty(bus, macObjectInfo.second, macObjectInfo.first,
Patrick Venture0b02be92018-08-31 11:55:55 -0700551 MAC_INTERFACE, "MACAddress", std::string(mac));
Ratan Guptafd28dd72016-08-01 04:58:01 -0500552
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000553 log<level::DEBUG>("Network configuration changed",
554 entry("NETWORKCONFIG=%s", hostNetworkConfig.c_str()));
Ratan Guptafd28dd72016-08-01 04:58:01 -0500555 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -0500556 catch (const sdbusplus::exception_t& e)
Ratan Guptadcb10672017-07-10 10:33:50 +0530557 {
558 commit<InternalFailure>();
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000559 log<level::ERR>("Error in ipmiChassisSetSysBootOptions call");
560 return ipmi::ccUnspecifiedError;
Ratan Guptadcb10672017-07-10 10:33:50 +0530561 }
562
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000563 return ipmi::ccSuccess;
Ratan Guptafd28dd72016-08-01 04:58:01 -0500564}
565
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -0500566uint32_t getPOHCounter()
567{
Patrick Williams5d82f472022-07-22 19:26:53 -0500568 sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()};
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -0500569
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -0500570 auto chassisStateObj = ipmi::getDbusObject(bus, chassisPOHStateIntf,
571 chassisStateRoot, match);
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -0500572
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -0500573 auto service = ipmi::getService(bus, chassisPOHStateIntf,
574 chassisStateObj.first);
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -0500575
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -0500576 auto propValue = ipmi::getDbusProperty(bus, service, chassisStateObj.first,
577 chassisPOHStateIntf,
578 pohCounterProperty);
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -0500579
Vernon Maueryf442e112019-04-09 11:44:36 -0700580 return std::get<uint32_t>(propValue);
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -0500581}
582
anil kumar appana43263c62019-05-27 12:45:04 +0000583/** @brief Implements the get chassis capabilities command
584 *
585 * @returns IPMI completion code plus response data
586 * chassisCapFlags - chassis capability flag
587 * chassisFRUInfoDevAddr - chassis FRU info Device Address
588 * chassisSDRDevAddr - chassis SDR device address
589 * chassisSELDevAddr - chassis SEL device address
590 * chassisSMDevAddr - chassis system management device address
591 * chassisBridgeDevAddr - chassis bridge device address
592 */
Karthick Sundarrajan86d8bd72019-11-26 12:48:50 -0800593ipmi::RspType<bool, // chassis intrusion sensor
594 bool, // chassis Front panel lockout
595 bool, // chassis NMI
596 bool, // chassis power interlock
597 uint4_t, // reserved
anil kumar appana43263c62019-05-27 12:45:04 +0000598 uint8_t, // chassis FRU info Device Address
599 uint8_t, // chassis SDR device address
600 uint8_t, // chassis SEL device address
601 uint8_t, // chassis system management device address
602 uint8_t // chassis bridge device address
603 >
604 ipmiGetChassisCap()
Nan Li8d15fb42016-08-16 22:29:40 +0800605{
anil kumar appana43263c62019-05-27 12:45:04 +0000606 ipmi::PropertyMap properties;
Yong Liae4b0402018-11-02 11:12:14 +0800607 try
608 {
Patrick Williams5d82f472022-07-22 19:26:53 -0500609 sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()};
Nan Li8d15fb42016-08-16 22:29:40 +0800610
Yong Liae4b0402018-11-02 11:12:14 +0800611 ipmi::DbusObjectInfo chassisCapObject =
612 ipmi::getDbusObject(bus, chassisCapIntf);
Nan Li8d15fb42016-08-16 22:29:40 +0800613
Yong Liae4b0402018-11-02 11:12:14 +0800614 // capabilities flags
615 // [7..4] - reserved
616 // [3] – 1b = provides power interlock (IPM 1.5)
617 // [2] – 1b = provides Diagnostic Interrupt (FP NMI)
618 // [1] – 1b = provides “Front Panel Lockout” (indicates that the chassis
619 // has capabilities
620 // to lock out external power control and reset button or
621 // front panel interfaces and/or detect tampering with those
622 // interfaces).
623 // [0] -1b = Chassis provides intrusion (physical security) sensor.
624 // set to default value 0x0.
Nan Li8d15fb42016-08-16 22:29:40 +0800625
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -0500626 properties = ipmi::getAllDbusProperties(bus, chassisCapObject.second,
627 chassisCapObject.first,
628 chassisCapIntf);
Yong Liae4b0402018-11-02 11:12:14 +0800629 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -0500630 catch (const std::exception& e)
Yong Liae4b0402018-11-02 11:12:14 +0800631 {
anil kumar appana43263c62019-05-27 12:45:04 +0000632 log<level::ERR>("Failed to fetch Chassis Capability properties",
633 entry("ERROR=%s", e.what()));
634 return ipmi::responseUnspecifiedError();
Yong Liae4b0402018-11-02 11:12:14 +0800635 }
636
Karthick Sundarrajan86d8bd72019-11-26 12:48:50 -0800637 bool* chassisIntrusionFlag =
638 std::get_if<bool>(&properties[chassisIntrusionProp]);
639 if (chassisIntrusionFlag == nullptr)
anil kumar appana43263c62019-05-27 12:45:04 +0000640 {
Karthick Sundarrajan86d8bd72019-11-26 12:48:50 -0800641 log<level::ERR>("Error to get chassis Intrusion flags");
642 return ipmi::responseUnspecifiedError();
643 }
644 bool* chassisFrontPanelFlag =
645 std::get_if<bool>(&properties[chassisFrontPanelLockoutProp]);
646 if (chassisFrontPanelFlag == nullptr)
647 {
648 log<level::ERR>("Error to get chassis intrusion flags");
649 return ipmi::responseUnspecifiedError();
650 }
651 bool* chassisNMIFlag = std::get_if<bool>(&properties[chassisNMIProp]);
652 if (chassisNMIFlag == nullptr)
653 {
654 log<level::ERR>("Error to get chassis NMI flags");
655 return ipmi::responseUnspecifiedError();
656 }
657 bool* chassisPowerInterlockFlag =
658 std::get_if<bool>(&properties[chassisPowerInterlockProp]);
659 if (chassisPowerInterlockFlag == nullptr)
660 {
661 log<level::ERR>("Error to get chassis power interlock flags");
anil kumar appana43263c62019-05-27 12:45:04 +0000662 return ipmi::responseUnspecifiedError();
663 }
664 uint8_t* chassisFRUInfoDevAddr =
665 std::get_if<uint8_t>(&properties[chassisFRUDevAddrProp]);
666 if (chassisFRUInfoDevAddr == nullptr)
667 {
668 log<level::ERR>("Error to get chassis FRU info device address");
669 return ipmi::responseUnspecifiedError();
670 }
671 uint8_t* chassisSDRDevAddr =
672 std::get_if<uint8_t>(&properties[chassisSDRDevAddrProp]);
673 if (chassisSDRDevAddr == nullptr)
674 {
675 log<level::ERR>("Error to get chassis SDR device address");
676 return ipmi::responseUnspecifiedError();
677 }
678 uint8_t* chassisSELDevAddr =
679 std::get_if<uint8_t>(&properties[chassisSELDevAddrProp]);
680 if (chassisSELDevAddr == nullptr)
681 {
682 log<level::ERR>("Error to get chassis SEL device address");
683 return ipmi::responseUnspecifiedError();
684 }
685 uint8_t* chassisSMDevAddr =
686 std::get_if<uint8_t>(&properties[chassisSMDevAddrProp]);
687 if (chassisSMDevAddr == nullptr)
688 {
689 log<level::ERR>("Error to get chassis SM device address");
690 return ipmi::responseUnspecifiedError();
691 }
692 uint8_t* chassisBridgeDevAddr =
693 std::get_if<uint8_t>(&properties[chassisBridgeDevAddrProp]);
694 if (chassisBridgeDevAddr == nullptr)
695 {
696 log<level::ERR>("Error to get chassis bridge device address");
697 return ipmi::responseUnspecifiedError();
698 }
699
Karthick Sundarrajan86d8bd72019-11-26 12:48:50 -0800700 return ipmi::responseSuccess(*chassisIntrusionFlag, *chassisFrontPanelFlag,
701 *chassisNMIFlag, *chassisPowerInterlockFlag, 0,
702 *chassisFRUInfoDevAddr, *chassisSDRDevAddr,
703 *chassisSELDevAddr, *chassisSMDevAddr,
704 *chassisBridgeDevAddr);
Yong Liae4b0402018-11-02 11:12:14 +0800705}
706
anil kumar appana894d0222019-05-27 16:32:14 +0000707/** @brief implements set chassis capalibities command
708 * @param intrusion - chassis intrusion
709 * @param fpLockout - frontpannel lockout
710 * @param reserved1 - skip one bit
711 * @param fruDeviceAddr - chassis FRU info Device Address
712 * @param sdrDeviceAddr - chassis SDR device address
713 * @param selDeviceAddr - chassis SEL device address
714 * @param smDeviceAddr - chassis system management device address
715 * @param bridgeDeviceAddr - chassis bridge device address
716 *
717 * @returns IPMI completion code
718 */
719ipmi::RspType<> ipmiSetChassisCap(bool intrusion, bool fpLockout,
720 uint6_t reserved1,
721
722 uint8_t fruDeviceAddr,
723
724 uint8_t sdrDeviceAddr,
725
726 uint8_t selDeviceAddr,
727
728 uint8_t smDeviceAddr,
729
730 uint8_t bridgeDeviceAddr)
Yong Liae4b0402018-11-02 11:12:14 +0800731{
Yong Liae4b0402018-11-02 11:12:14 +0800732 // check input data
anil kumar appana894d0222019-05-27 16:32:14 +0000733 if (reserved1 != 0)
Yong Liae4b0402018-11-02 11:12:14 +0800734 {
anil kumar appana894d0222019-05-27 16:32:14 +0000735 log<level::ERR>("Unsupported request parameter");
736 return ipmi::responseInvalidFieldRequest();
Yong Liae4b0402018-11-02 11:12:14 +0800737 }
738
anil kumar appana894d0222019-05-27 16:32:14 +0000739 if ((fruDeviceAddr & ~chassisCapAddrMask) != 0)
Yong Liae4b0402018-11-02 11:12:14 +0800740 {
741 log<level::ERR>("Unsupported request parameter(FRU Addr)",
anil kumar appana894d0222019-05-27 16:32:14 +0000742 entry("REQ=0x%x", fruDeviceAddr));
743 return ipmi::responseInvalidFieldRequest();
Yong Liae4b0402018-11-02 11:12:14 +0800744 }
anil kumar appana894d0222019-05-27 16:32:14 +0000745 if ((sdrDeviceAddr & ~chassisCapAddrMask) != 0)
Yong Liae4b0402018-11-02 11:12:14 +0800746 {
747 log<level::ERR>("Unsupported request parameter(SDR Addr)",
anil kumar appana894d0222019-05-27 16:32:14 +0000748 entry("REQ=0x%x", sdrDeviceAddr));
749 return ipmi::responseInvalidFieldRequest();
Yong Liae4b0402018-11-02 11:12:14 +0800750 }
751
anil kumar appana894d0222019-05-27 16:32:14 +0000752 if ((selDeviceAddr & ~chassisCapAddrMask) != 0)
Yong Liae4b0402018-11-02 11:12:14 +0800753 {
754 log<level::ERR>("Unsupported request parameter(SEL Addr)",
anil kumar appana894d0222019-05-27 16:32:14 +0000755 entry("REQ=0x%x", selDeviceAddr));
756 return ipmi::responseInvalidFieldRequest();
Yong Liae4b0402018-11-02 11:12:14 +0800757 }
758
anil kumar appana894d0222019-05-27 16:32:14 +0000759 if ((smDeviceAddr & ~chassisCapAddrMask) != 0)
Yong Liae4b0402018-11-02 11:12:14 +0800760 {
anil kumar appana894d0222019-05-27 16:32:14 +0000761 log<level::ERR>("Unsupported request parameter(SM Addr)",
762 entry("REQ=0x%x", smDeviceAddr));
763 return ipmi::responseInvalidFieldRequest();
Yong Liae4b0402018-11-02 11:12:14 +0800764 }
765
anil kumar appana894d0222019-05-27 16:32:14 +0000766 if ((bridgeDeviceAddr & ~chassisCapAddrMask) != 0)
Yong Liae4b0402018-11-02 11:12:14 +0800767 {
768 log<level::ERR>("Unsupported request parameter(Bridge Addr)",
anil kumar appana894d0222019-05-27 16:32:14 +0000769 entry("REQ=0x%x", bridgeDeviceAddr));
770 return ipmi::responseInvalidFieldRequest();
Yong Liae4b0402018-11-02 11:12:14 +0800771 }
772
773 try
774 {
Patrick Williams5d82f472022-07-22 19:26:53 -0500775 sdbusplus::bus_t bus(ipmid_get_sd_bus_connection());
Yong Liae4b0402018-11-02 11:12:14 +0800776 ipmi::DbusObjectInfo chassisCapObject =
777 ipmi::getDbusObject(bus, chassisCapIntf);
778
779 ipmi::setDbusProperty(bus, chassisCapObject.second,
780 chassisCapObject.first, chassisCapIntf,
Karthick Sundarrajan86d8bd72019-11-26 12:48:50 -0800781 chassisIntrusionProp, intrusion);
782
783 ipmi::setDbusProperty(bus, chassisCapObject.second,
784 chassisCapObject.first, chassisCapIntf,
785 chassisFrontPanelLockoutProp, fpLockout);
Yong Liae4b0402018-11-02 11:12:14 +0800786
787 ipmi::setDbusProperty(bus, chassisCapObject.second,
788 chassisCapObject.first, chassisCapIntf,
anil kumar appana894d0222019-05-27 16:32:14 +0000789 chassisFRUDevAddrProp, fruDeviceAddr);
Yong Liae4b0402018-11-02 11:12:14 +0800790
791 ipmi::setDbusProperty(bus, chassisCapObject.second,
792 chassisCapObject.first, chassisCapIntf,
anil kumar appana894d0222019-05-27 16:32:14 +0000793 chassisSDRDevAddrProp, sdrDeviceAddr);
Yong Liae4b0402018-11-02 11:12:14 +0800794
795 ipmi::setDbusProperty(bus, chassisCapObject.second,
796 chassisCapObject.first, chassisCapIntf,
anil kumar appana894d0222019-05-27 16:32:14 +0000797 chassisSELDevAddrProp, selDeviceAddr);
Yong Liae4b0402018-11-02 11:12:14 +0800798
799 ipmi::setDbusProperty(bus, chassisCapObject.second,
800 chassisCapObject.first, chassisCapIntf,
anil kumar appana894d0222019-05-27 16:32:14 +0000801 chassisSMDevAddrProp, smDeviceAddr);
Yong Liae4b0402018-11-02 11:12:14 +0800802
803 ipmi::setDbusProperty(bus, chassisCapObject.second,
804 chassisCapObject.first, chassisCapIntf,
anil kumar appana894d0222019-05-27 16:32:14 +0000805 chassisBridgeDevAddrProp, bridgeDeviceAddr);
Yong Liae4b0402018-11-02 11:12:14 +0800806 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -0500807 catch (const std::exception& e)
Yong Liae4b0402018-11-02 11:12:14 +0800808 {
809 log<level::ERR>(e.what());
anil kumar appana894d0222019-05-27 16:32:14 +0000810 return ipmi::responseUnspecifiedError();
Yong Liae4b0402018-11-02 11:12:14 +0800811 }
anil kumar appana894d0222019-05-27 16:32:14 +0000812 return ipmi::responseSuccess();
Nan Li8d15fb42016-08-16 22:29:40 +0800813}
814
Vishwanatha Subbannab12b0c02017-03-07 18:17:19 +0530815//------------------------------------------
816// Calls into Host State Manager Dbus object
817//------------------------------------------
Jason M. Bills664e1c32020-01-30 16:02:39 -0800818int initiateHostStateTransition(ipmi::Context::ptr& ctx,
819 State::Host::Transition transition)
vishwa36993272015-11-20 12:43:49 -0600820{
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500821 // OpenBMC Host State Manager dbus framework
Jason M. Bills664e1c32020-01-30 16:02:39 -0800822 constexpr auto hostStatePath = "/xyz/openbmc_project/state/host0";
823 constexpr auto hostStateIntf = "xyz.openbmc_project.State.Host";
Vishwanatha Subbannab12b0c02017-03-07 18:17:19 +0530824
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500825 // Convert to string equivalent of the passed in transition enum.
Willy Tu523e2d12023-09-05 11:36:48 -0700826 auto request =
827 sdbusplus::common::xyz::openbmc_project::state::convertForMessage(
828 transition);
Vishwanatha Subbannab12b0c02017-03-07 18:17:19 +0530829
Jason M. Bills664e1c32020-01-30 16:02:39 -0800830 std::string service;
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -0500831 boost::system::error_code ec = ipmi::getService(ctx, hostStateIntf,
832 hostStatePath, service);
Jason M. Bills664e1c32020-01-30 16:02:39 -0800833
834 if (!ec)
835 {
836 ec = ipmi::setDbusProperty(ctx, service, hostStatePath, hostStateIntf,
837 "RequestedHostTransition", request);
838 }
839 if (ec)
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500840 {
841 log<level::ERR>("Failed to initiate transition",
Jason M. Bills664e1c32020-01-30 16:02:39 -0800842 entry("EXCEPTION=%s, REQUEST=%s", ec.message().c_str(),
843 request.c_str()));
844 return -1;
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500845 }
Jason M. Bills664e1c32020-01-30 16:02:39 -0800846 log<level::INFO>(
847 "Transition request initiated successfully",
848 entry("USERID=%d, REQUEST=%s", ctx->userId, request.c_str()));
849 return 0;
vishwa36993272015-11-20 12:43:49 -0600850}
851
Kuiying Wang6b0ceaa2019-11-05 15:13:40 +0800852//------------------------------------------
Jason M. Billsad588bf2020-01-30 16:18:33 -0800853// Calls into Chassis State Manager Dbus object
854//------------------------------------------
855int initiateChassisStateTransition(ipmi::Context::ptr& ctx,
856 State::Chassis::Transition transition)
857{
858 // OpenBMC Chassis State Manager dbus framework
859 constexpr auto chassisStatePath = "/xyz/openbmc_project/state/chassis0";
860 constexpr auto chassisStateIntf = "xyz.openbmc_project.State.Chassis";
861
862 std::string service;
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -0500863 boost::system::error_code ec = ipmi::getService(ctx, chassisStateIntf,
864 chassisStatePath, service);
Jason M. Billsad588bf2020-01-30 16:18:33 -0800865
866 // Convert to string equivalent of the passed in transition enum.
Willy Tu523e2d12023-09-05 11:36:48 -0700867 auto request =
868 sdbusplus::common::xyz::openbmc_project::state::convertForMessage(
869 transition);
Jason M. Billsad588bf2020-01-30 16:18:33 -0800870
871 if (!ec)
872 {
873 ec = ipmi::setDbusProperty(ctx, service, chassisStatePath,
874 chassisStateIntf, "RequestedPowerTransition",
875 request);
876 }
877 if (ec)
878 {
879 log<level::ERR>("Failed to initiate transition",
880 entry("EXCEPTION=%s, REQUEST=%s", ec.message().c_str(),
881 request.c_str()));
882 return -1;
883 }
884
885 return 0;
886}
887
888//------------------------------------------
Kuiying Wang6b0ceaa2019-11-05 15:13:40 +0800889// Set Enabled property to inform NMI source
890// handling to trigger a NMI_OUT BSOD.
891//------------------------------------------
Vernon Mauery9bb4a382021-11-05 12:46:19 -0700892int setNmiProperty(ipmi::Context::ptr& ctx, const bool value)
Kuiying Wang6b0ceaa2019-11-05 15:13:40 +0800893{
894 constexpr const char* nmiSourceObjPath =
895 "/xyz/openbmc_project/Chassis/Control/NMISource";
896 constexpr const char* nmiSourceIntf =
897 "xyz.openbmc_project.Chassis.Control.NMISource";
898 std::string bmcSourceSignal = "xyz.openbmc_project.Chassis.Control."
899 "NMISource.BMCSourceSignal.ChassisCmd";
Kuiying Wang6b0ceaa2019-11-05 15:13:40 +0800900
Vernon Mauery9bb4a382021-11-05 12:46:19 -0700901 std::string service;
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -0500902 boost::system::error_code ec = ipmi::getService(ctx, nmiSourceIntf,
903 nmiSourceObjPath, service);
Vernon Mauery9bb4a382021-11-05 12:46:19 -0700904 if (!ec)
Kuiying Wang6b0ceaa2019-11-05 15:13:40 +0800905 {
Vernon Mauery9bb4a382021-11-05 12:46:19 -0700906 ec = ipmi::setDbusProperty(ctx, service, nmiSourceObjPath,
907 nmiSourceIntf, "BMCSource", bmcSourceSignal);
Kuiying Wang6b0ceaa2019-11-05 15:13:40 +0800908 }
Vernon Mauery9bb4a382021-11-05 12:46:19 -0700909 if (!ec)
910 {
911 ec = ipmi::setDbusProperty(ctx, service, nmiSourceObjPath,
912 nmiSourceIntf, "Enabled", value);
913 }
914 if (ec)
Kuiying Wang6b0ceaa2019-11-05 15:13:40 +0800915 {
916 log<level::ERR>("Failed to trigger NMI_OUT",
Vernon Mauery9bb4a382021-11-05 12:46:19 -0700917 entry("EXCEPTION=%s", ec.message().c_str()));
Kuiying Wang6b0ceaa2019-11-05 15:13:40 +0800918 return -1;
919 }
920
921 return 0;
922}
923
Deepak Kodihalli18b70d12017-07-21 13:36:33 -0500924namespace power_policy
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500925{
Nan Lifdd8ec52016-08-28 03:57:40 +0800926
Willy Tu523e2d12023-09-05 11:36:48 -0700927using namespace sdbusplus::server::xyz::openbmc_project::control::power;
Deepak Kodihalli18b70d12017-07-21 13:36:33 -0500928using IpmiValue = uint8_t;
929using DbusValue = RestorePolicy::Policy;
Nan Lifdd8ec52016-08-28 03:57:40 +0800930
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700931const std::map<DbusValue, IpmiValue> dbusToIpmi = {
Deepak Kodihalli18b70d12017-07-21 13:36:33 -0500932 {RestorePolicy::Policy::AlwaysOff, 0x00},
933 {RestorePolicy::Policy::Restore, 0x01},
Patrick Venture0b02be92018-08-31 11:55:55 -0700934 {RestorePolicy::Policy::AlwaysOn, 0x02}};
Nan Lifdd8ec52016-08-28 03:57:40 +0800935
Yong Lic6713cf2018-09-12 12:35:13 +0800936static constexpr uint8_t noChange = 0x03;
937static constexpr uint8_t allSupport = 0x01 | 0x02 | 0x04;
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700938
939/* helper function for Get Chassis Status Command
940 */
941std::optional<uint2_t> getPowerRestorePolicy()
942{
943 uint2_t restorePolicy = 0;
944 using namespace chassis::internal;
945
James Feist225dec82019-11-26 16:25:06 -0800946 settings::Objects& objects = cache::getObjects();
947
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700948 try
949 {
950 const auto& powerRestoreSetting =
James Feist225dec82019-11-26 16:25:06 -0800951 objects.map.at(powerRestoreIntf).front();
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700952 ipmi::Value result = ipmi::getDbusProperty(
953 *getSdBus(),
James Feist225dec82019-11-26 16:25:06 -0800954 objects.service(powerRestoreSetting, powerRestoreIntf).c_str(),
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700955 powerRestoreSetting.c_str(), powerRestoreIntf,
956 "PowerRestorePolicy");
957 auto powerRestore = RestorePolicy::convertPolicyFromString(
958 std::get<std::string>(result));
959 restorePolicy = dbusToIpmi.at(powerRestore);
960 }
961 catch (const std::exception& e)
962 {
963 log<level::ERR>(
964 "Failed to fetch pgood property", entry("ERROR=%s", e.what()),
James Feist225dec82019-11-26 16:25:06 -0800965 entry("PATH=%s", objects.map.at(powerRestoreIntf).front().c_str()),
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700966 entry("INTERFACE=%s", powerRestoreIntf));
James Feist225dec82019-11-26 16:25:06 -0800967 cache::objectsPtr.reset();
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700968 return std::nullopt;
969 }
970 return std::make_optional(restorePolicy);
971}
972
973/*
974 * getPowerStatus
975 * helper function for Get Chassis Status Command
976 * return - optional value for pgood (no value on error)
977 */
978std::optional<bool> getPowerStatus()
979{
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700980 bool powerGood = false;
981 std::shared_ptr<sdbusplus::asio::connection> busp = getSdBus();
982 try
983 {
Jason M. Bills3de424c2019-05-21 09:57:16 -0700984 constexpr const char* chassisStatePath =
985 "/xyz/openbmc_project/state/chassis0";
986 constexpr const char* chassisStateIntf =
987 "xyz.openbmc_project.State.Chassis";
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -0500988 auto service = ipmi::getService(*busp, chassisStateIntf,
989 chassisStatePath);
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700990
Jason M. Bills3de424c2019-05-21 09:57:16 -0700991 ipmi::Value powerState =
992 ipmi::getDbusProperty(*busp, service, chassisStatePath,
993 chassisStateIntf, "CurrentPowerState");
994 powerGood = std::get<std::string>(powerState) ==
995 "xyz.openbmc_project.State.Chassis.PowerState.On";
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700996 }
997 catch (const std::exception& e)
998 {
999 try
1000 {
1001 // FIXME: some legacy modules use the older path; try that next
1002 constexpr const char* legacyPwrCtrlObj =
1003 "/org/openbmc/control/power0";
1004 constexpr const char* legacyPwrCtrlIntf =
1005 "org.openbmc.control.Power";
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05001006 auto service = ipmi::getService(*busp, legacyPwrCtrlIntf,
1007 legacyPwrCtrlObj);
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001008
1009 ipmi::Value variant = ipmi::getDbusProperty(
1010 *busp, service, legacyPwrCtrlObj, legacyPwrCtrlIntf, "pgood");
1011 powerGood = static_cast<bool>(std::get<int>(variant));
1012 }
1013 catch (const std::exception& e)
1014 {
1015 log<level::ERR>("Failed to fetch pgood property",
Jason M. Bills3de424c2019-05-21 09:57:16 -07001016 entry("ERROR=%s", e.what()));
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001017 return std::nullopt;
1018 }
1019 }
1020 return std::make_optional(powerGood);
1021}
1022
Yong Li70ce7352019-05-16 21:15:27 +08001023/*
1024 * getACFailStatus
1025 * helper function for Get Chassis Status Command
1026 * return - bool value for ACFail (false on error)
1027 */
1028bool getACFailStatus()
1029{
1030 constexpr const char* powerControlObj =
1031 "/xyz/openbmc_project/Chassis/Control/Power0";
1032 constexpr const char* powerControlIntf =
1033 "xyz.openbmc_project.Chassis.Control.Power";
1034 bool acFail = false;
1035 std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus();
1036 try
1037 {
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05001038 auto service = ipmi::getService(*bus, powerControlIntf,
1039 powerControlObj);
Yong Li70ce7352019-05-16 21:15:27 +08001040
1041 ipmi::Value variant = ipmi::getDbusProperty(
1042 *bus, service, powerControlObj, powerControlIntf, "PFail");
1043 acFail = std::get<bool>(variant);
1044 }
1045 catch (const std::exception& e)
1046 {
1047 log<level::ERR>("Failed to fetch PFail property",
1048 entry("ERROR=%s", e.what()),
1049 entry("PATH=%s", powerControlObj),
1050 entry("INTERFACE=%s", powerControlIntf));
1051 }
1052 return acFail;
1053}
Deepak Kodihalli18b70d12017-07-21 13:36:33 -05001054} // namespace power_policy
Nan Lifdd8ec52016-08-28 03:57:40 +08001055
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001056static std::optional<bool> getButtonEnabled(const std::string& buttonPath,
1057 const std::string& buttonIntf)
1058{
1059 std::shared_ptr<sdbusplus::asio::connection> busp = getSdBus();
1060 bool buttonDisabled = false;
1061 try
1062 {
1063 auto service = ipmi::getService(*busp, buttonIntf, buttonPath);
1064 ipmi::Value enabled = ipmi::getDbusProperty(*busp, service, buttonPath,
1065 buttonIntf, "Enabled");
1066 buttonDisabled = !std::get<bool>(enabled);
1067 }
Patrick Williams5d82f472022-07-22 19:26:53 -05001068 catch (const sdbusplus::exception_t& e)
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001069 {
1070 log<level::ERR>("Fail to get button Enabled property",
1071 entry("PATH=%s", buttonPath.c_str()),
1072 entry("ERROR=%s", e.what()));
1073 return std::nullopt;
1074 }
1075 return std::make_optional(buttonDisabled);
1076}
1077
Kuiying Wang21addc52019-01-04 10:50:21 +08001078static bool setButtonEnabled(ipmi::Context::ptr& ctx,
1079 const std::string& buttonPath,
1080 const std::string& buttonIntf, bool enable)
1081{
1082 std::string service;
1083 boost::system::error_code ec;
1084 ec = ipmi::getService(ctx, buttonIntf, buttonPath, service);
1085 if (!ec)
1086 {
1087 ec = ipmi::setDbusProperty(ctx, service, buttonPath, buttonIntf,
1088 "Enabled", enable);
1089 }
1090 if (ec)
1091 {
1092 log<level::ERR>("Fail to set button Enabled property",
1093 entry("SERVICE=%s", service.c_str()),
1094 entry("PATH=%s", buttonPath.c_str()),
1095 entry("ERROR=%s", ec.message().c_str()));
1096 return false;
1097 }
1098 return true;
1099}
1100
Chau Ly9e666cd2023-03-06 08:46:14 +00001101static std::optional<bool> getChassisIntrusionStatus(ipmi::Context::ptr& ctx)
1102{
1103 constexpr const char* chassisIntrusionPath =
1104 "/xyz/openbmc_project/Chassis/Intrusion";
1105 constexpr const char* chassisIntrusionInf =
1106 "xyz.openbmc_project.Chassis.Intrusion";
1107
1108 std::string service;
1109 boost::system::error_code ec = ipmi::getService(
1110 ctx, chassisIntrusionInf, chassisIntrusionPath, service);
1111 if (!ec)
1112 {
1113 std::string chassisIntrusionStr;
1114 ec = ipmi::getDbusProperty<std::string>(
1115 ctx, service, chassisIntrusionPath, chassisIntrusionInf, "Status",
1116 chassisIntrusionStr);
1117 if (!ec)
1118 {
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05001119 bool ret = (chassisIntrusionStr == "HardwareIntrusion") ? true
1120 : false;
Chau Ly9e666cd2023-03-06 08:46:14 +00001121 return std::make_optional(ret);
1122 }
1123 }
1124 log<level::ERR>("Fail to get Chassis Intrusion Status property",
1125 entry("PATH=%s", chassisIntrusionPath),
1126 entry("INTERFACE=%s", chassisIntrusionInf),
1127 entry("ERROR=%s", ec.message().c_str()));
1128 return std::nullopt;
1129}
1130
Nan Lifdd8ec52016-08-28 03:57:40 +08001131//----------------------------------------------------------------------
1132// Get Chassis Status commands
1133//----------------------------------------------------------------------
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001134ipmi::RspType<bool, // Power is on
1135 bool, // Power overload
1136 bool, // Interlock
1137 bool, // power fault
1138 bool, // power control fault
1139 uint2_t, // power restore policy
1140 bool, // reserved
1141
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05001142 bool, // AC failed
1143 bool, // last power down caused by a Power overload
1144 bool, // last power down caused by a power interlock
1145 bool, // last power down caused by power fault
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001146 bool, // last ‘Power is on’ state was entered via IPMI command
1147 uint3_t, // reserved
1148
1149 bool, // Chassis intrusion active
1150 bool, // Front Panel Lockout active
1151 bool, // Drive Fault
1152 bool, // Cooling/fan fault detected
1153 uint2_t, // Chassis Identify State
1154 bool, // Chassis Identify command and state info supported
1155 bool, // reserved
1156
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05001157 bool, // Power off button disabled
1158 bool, // Reset button disabled
1159 bool, // Diagnostic Interrupt button disabled
1160 bool, // Standby (sleep) button disabled
1161 bool, // Power off button disable allowed
1162 bool, // Reset button disable allowed
1163 bool, // Diagnostic Interrupt button disable allowed
1164 bool // Standby (sleep) button disable allowed
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001165 >
Chau Ly9e666cd2023-03-06 08:46:14 +00001166 ipmiGetChassisStatus(ipmi::Context::ptr& ctx)
Nan Lifdd8ec52016-08-28 03:57:40 +08001167{
Deepak Kodihalli18b70d12017-07-21 13:36:33 -05001168 using namespace chassis::internal;
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001169 std::optional<uint2_t> restorePolicy =
1170 power_policy::getPowerRestorePolicy();
1171 std::optional<bool> powerGood = power_policy::getPowerStatus();
1172 if (!restorePolicy || !powerGood)
Deepak Kodihalli18b70d12017-07-21 13:36:33 -05001173 {
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001174 return ipmi::responseUnspecifiedError();
Deepak Kodihalli18b70d12017-07-21 13:36:33 -05001175 }
Nan Lifdd8ec52016-08-28 03:57:40 +08001176
1177 // Front Panel Button Capabilities and disable/enable status(Optional)
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05001178 std::optional<bool> powerButtonReading = getButtonEnabled(powerButtonPath,
1179 powerButtonIntf);
Vernon Mauery6d5b2f72019-05-16 14:48:47 -07001180 // allow disable if the interface is present
1181 bool powerButtonDisableAllow = static_cast<bool>(powerButtonReading);
1182 // default return the button is enabled (not disabled)
1183 bool powerButtonDisabled = false;
1184 if (powerButtonDisableAllow)
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001185 {
Vernon Mauery6d5b2f72019-05-16 14:48:47 -07001186 // return the real value of the button status, if present
1187 powerButtonDisabled = *powerButtonReading;
1188 }
1189
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05001190 std::optional<bool> resetButtonReading = getButtonEnabled(resetButtonPath,
1191 resetButtonIntf);
Vernon Mauery6d5b2f72019-05-16 14:48:47 -07001192 // allow disable if the interface is present
1193 bool resetButtonDisableAllow = static_cast<bool>(resetButtonReading);
1194 // default return the button is enabled (not disabled)
1195 bool resetButtonDisabled = false;
1196 if (resetButtonDisableAllow)
1197 {
1198 // return the real value of the button status, if present
1199 resetButtonDisabled = *resetButtonReading;
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001200 }
Nan Lifdd8ec52016-08-28 03:57:40 +08001201
Yong Li70ce7352019-05-16 21:15:27 +08001202 bool powerDownAcFailed = power_policy::getACFailStatus();
1203
Chau Ly9e666cd2023-03-06 08:46:14 +00001204 bool chassisIntrusionActive = false;
1205 std::optional<bool> chassisIntrusionStatus = getChassisIntrusionStatus(ctx);
1206 if (chassisIntrusionStatus)
1207 {
1208 chassisIntrusionActive = chassisIntrusionStatus.value();
1209 }
1210
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001211 // This response has a lot of hard-coded, unsupported fields
1212 // They are set to false or 0
1213 constexpr bool powerOverload = false;
1214 constexpr bool chassisInterlock = false;
1215 constexpr bool powerFault = false;
1216 constexpr bool powerControlFault = false;
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001217 constexpr bool powerDownOverload = false;
1218 constexpr bool powerDownInterlock = false;
1219 constexpr bool powerDownPowerFault = false;
1220 constexpr bool powerStatusIPMI = false;
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001221 constexpr bool frontPanelLockoutActive = false;
1222 constexpr bool driveFault = false;
1223 constexpr bool coolingFanFault = false;
1224 // chassisIdentifySupport set because this command is implemented
1225 constexpr bool chassisIdentifySupport = true;
William A. Kennington III7a0e5df2021-05-19 13:31:29 -07001226 uint2_t chassisIdentifyState = types::enum_cast<uint2_t>(chassisIDState);
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001227 constexpr bool diagButtonDisabled = false;
1228 constexpr bool sleepButtonDisabled = false;
1229 constexpr bool diagButtonDisableAllow = false;
1230 constexpr bool sleepButtonDisableAllow = false;
1231
1232 return ipmi::responseSuccess(
1233 *powerGood, powerOverload, chassisInterlock, powerFault,
1234 powerControlFault, *restorePolicy,
1235 false, // reserved
1236
1237 powerDownAcFailed, powerDownOverload, powerDownInterlock,
1238 powerDownPowerFault, powerStatusIPMI,
1239 uint3_t(0), // reserved
1240
1241 chassisIntrusionActive, frontPanelLockoutActive, driveFault,
1242 coolingFanFault, chassisIdentifyState, chassisIdentifySupport,
1243 false, // reserved
1244
Vernon Mauery6d5b2f72019-05-16 14:48:47 -07001245 powerButtonDisabled, resetButtonDisabled, diagButtonDisabled,
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001246 sleepButtonDisabled, powerButtonDisableAllow, resetButtonDisableAllow,
1247 diagButtonDisableAllow, sleepButtonDisableAllow);
Nan Lifdd8ec52016-08-28 03:57:40 +08001248}
Chris Austen7888c4d2015-12-03 15:26:20 -06001249
Vijay Khemka074f64d2020-03-03 15:08:43 -08001250enum class IpmiRestartCause
1251{
1252 Unknown = 0x0,
1253 RemoteCommand = 0x1,
1254 ResetButton = 0x2,
1255 PowerButton = 0x3,
1256 WatchdogTimer = 0x4,
1257 PowerPolicyAlwaysOn = 0x6,
1258 PowerPolicyPreviousState = 0x7,
1259 SoftReset = 0xa,
1260};
1261
1262static IpmiRestartCause
1263 restartCauseToIpmiRestartCause(State::Host::RestartCause cause)
1264{
1265 switch (cause)
1266 {
1267 case State::Host::RestartCause::Unknown:
1268 {
1269 return IpmiRestartCause::Unknown;
1270 }
1271 case State::Host::RestartCause::RemoteCommand:
1272 {
1273 return IpmiRestartCause::RemoteCommand;
1274 }
1275 case State::Host::RestartCause::ResetButton:
1276 {
1277 return IpmiRestartCause::ResetButton;
1278 }
1279 case State::Host::RestartCause::PowerButton:
1280 {
1281 return IpmiRestartCause::PowerButton;
1282 }
1283 case State::Host::RestartCause::WatchdogTimer:
1284 {
1285 return IpmiRestartCause::WatchdogTimer;
1286 }
1287 case State::Host::RestartCause::PowerPolicyAlwaysOn:
1288 {
1289 return IpmiRestartCause::PowerPolicyAlwaysOn;
1290 }
1291 case State::Host::RestartCause::PowerPolicyPreviousState:
1292 {
1293 return IpmiRestartCause::PowerPolicyPreviousState;
1294 }
1295 case State::Host::RestartCause::SoftReset:
1296 {
1297 return IpmiRestartCause::SoftReset;
1298 }
1299 default:
1300 {
1301 return IpmiRestartCause::Unknown;
1302 }
1303 }
1304}
1305
1306/*
1307 * getRestartCause
1308 * helper function for Get Host restart cause Command
1309 * return - optional value for RestartCause (no value on error)
1310 */
1311static std::optional<uint4_t> getRestartCause(ipmi::Context::ptr ctx)
1312{
1313 constexpr const char* restartCausePath =
1314 "/xyz/openbmc_project/control/host0/restart_cause";
1315 constexpr const char* restartCauseIntf =
1316 "xyz.openbmc_project.Control.Host.RestartCause";
1317
1318 std::string service;
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05001319 boost::system::error_code ec = ipmi::getService(ctx, restartCauseIntf,
1320 restartCausePath, service);
Vijay Khemka074f64d2020-03-03 15:08:43 -08001321 if (!ec)
1322 {
1323 std::string restartCauseStr;
1324 ec = ipmi::getDbusProperty<std::string>(
1325 ctx, service, restartCausePath, restartCauseIntf, "RestartCause",
1326 restartCauseStr);
1327 if (!ec)
1328 {
1329 auto cause =
1330 State::Host::convertRestartCauseFromString(restartCauseStr);
William A. Kennington III7a0e5df2021-05-19 13:31:29 -07001331 return types::enum_cast<uint4_t>(
1332 restartCauseToIpmiRestartCause(cause));
Vijay Khemka074f64d2020-03-03 15:08:43 -08001333 }
1334 }
1335
1336 log<level::ERR>("Failed to fetch RestartCause property",
1337 entry("ERROR=%s", ec.message().c_str()),
1338 entry("PATH=%s", restartCausePath),
1339 entry("INTERFACE=%s", restartCauseIntf));
1340 return std::nullopt;
1341}
1342
1343ipmi::RspType<uint4_t, // Restart Cause
1344 uint4_t, // reserved
1345 uint8_t // channel number (not supported)
1346 >
1347 ipmiGetSystemRestartCause(ipmi::Context::ptr ctx)
1348{
1349 std::optional<uint4_t> cause = getRestartCause(ctx);
1350 if (!cause)
1351 {
1352 return ipmi::responseUnspecifiedError();
1353 }
1354
Vernon Mauery916d4232021-03-29 13:42:16 -07001355 constexpr uint4_t reserved = 0;
1356 auto channel = static_cast<uint8_t>(ctx->channel);
1357 return ipmi::responseSuccess(cause.value(), reserved, channel);
Vijay Khemka074f64d2020-03-03 15:08:43 -08001358}
anil kumar appanadafff5f2019-04-27 18:06:00 +00001359/** @brief Implementation of chassis control command
1360 *
1361 * @param - chassisControl command byte
1362 *
1363 * @return Success or InvalidFieldRequest.
1364 */
Jason M. Bills664e1c32020-01-30 16:02:39 -08001365ipmi::RspType<> ipmiChassisControl(ipmi::Context::ptr& ctx,
1366 uint8_t chassisControl)
vishwa36993272015-11-20 12:43:49 -06001367{
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001368 int rc = 0;
anil kumar appanadafff5f2019-04-27 18:06:00 +00001369 switch (chassisControl)
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001370 {
1371 case CMD_POWER_ON:
Jason M. Bills664e1c32020-01-30 16:02:39 -08001372 rc = initiateHostStateTransition(ctx, State::Host::Transition::On);
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001373 break;
1374 case CMD_POWER_OFF:
Jason M. Billsc2c3a402020-01-30 16:22:24 -08001375 rc = initiateChassisStateTransition(
1376 ctx, State::Chassis::Transition::Off);
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001377 break;
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001378 case CMD_HARD_RESET:
Jason M. Bills664e1c32020-01-30 16:02:39 -08001379 rc = initiateHostStateTransition(
1380 ctx, State::Host::Transition::ForceWarmReboot);
Chanh Nguyend0a7fcd2021-07-16 22:59:28 +07001381 break;
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001382 case CMD_POWER_CYCLE:
Jason M. Bills664e1c32020-01-30 16:02:39 -08001383 rc = initiateHostStateTransition(ctx,
1384 State::Host::Transition::Reboot);
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001385 break;
Vishwanatha Subbanna8b26d352017-08-04 18:35:18 +05301386 case CMD_SOFT_OFF_VIA_OVER_TEMP:
Jason M. Bills664e1c32020-01-30 16:02:39 -08001387 rc = initiateHostStateTransition(ctx, State::Host::Transition::Off);
Vishwanatha Subbanna8b26d352017-08-04 18:35:18 +05301388 break;
Kuiying Wang6b0ceaa2019-11-05 15:13:40 +08001389 case CMD_PULSE_DIAGNOSTIC_INTR:
Vernon Mauery9bb4a382021-11-05 12:46:19 -07001390 rc = setNmiProperty(ctx, true);
Kuiying Wang6b0ceaa2019-11-05 15:13:40 +08001391 break;
1392
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001393 default:
1394 {
Aditya Saripalli5fb14602017-11-09 14:46:27 +05301395 log<level::ERR>("Invalid Chassis Control command",
anil kumar appanadafff5f2019-04-27 18:06:00 +00001396 entry("CMD=0x%X", chassisControl));
1397 return ipmi::responseInvalidFieldRequest();
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001398 }
1399 }
vishwa36993272015-11-20 12:43:49 -06001400
anil kumar appanadafff5f2019-04-27 18:06:00 +00001401 return ((rc < 0) ? ipmi::responseUnspecifiedError()
1402 : ipmi::responseSuccess());
vishwa36993272015-11-20 12:43:49 -06001403}
1404
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001405/** @brief Return D-Bus connection string to enclosure identify LED object
1406 *
1407 * @param[in, out] connection - connection to D-Bus object
1408 * @return a IPMI return code
1409 */
1410std::string getEnclosureIdentifyConnection()
Tom Joseph5110c122018-03-23 17:55:40 +05301411{
Tom Joseph5110c122018-03-23 17:55:40 +05301412 // lookup enclosure_identify group owner(s) in mapper
George Liu3e3cc352023-07-26 15:59:31 +08001413 try
Tom Joseph5110c122018-03-23 17:55:40 +05301414 {
George Liu3e3cc352023-07-26 15:59:31 +08001415 return ipmi::getService(*getSdBus(), "xyz.openbmc_project.Led.Group",
1416 identify_led_object_name);
1417 }
1418 catch (const std::exception& e)
1419 {
1420 log<level::ERR>("Chassis Identify: Error communicating to mapper.",
1421 entry("ERROR=%s", e.what()));
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001422 elog<InternalFailure>();
Tom Joseph5110c122018-03-23 17:55:40 +05301423 }
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001424}
Tom Joseph5110c122018-03-23 17:55:40 +05301425
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001426/** @brief Turn On/Off enclosure identify LED
1427 *
1428 * @param[in] flag - true to turn on LED, false to turn off
1429 * @return a IPMI return code
1430 */
1431void enclosureIdentifyLed(bool flag)
1432{
1433 using namespace chassis::internal;
George Liu3e3cc352023-07-26 15:59:31 +08001434 try
1435 {
1436 std::string connection = getEnclosureIdentifyConnection();
1437
1438 auto msg = std::string("enclosureIdentifyLed(") +
1439 boost::lexical_cast<std::string>(flag) + ")";
1440 log<level::DEBUG>(msg.c_str());
1441
1442 ipmi::setDbusProperty(*getSdBus(), connection, identify_led_object_name,
1443 "xyz.openbmc_project.Led.Group", "Asserted",
1444 flag);
1445 }
1446 catch (const std::exception& e)
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001447 {
1448 log<level::ERR>("Chassis Identify: Error Setting State On/Off\n",
George Liu3e3cc352023-07-26 15:59:31 +08001449 entry("LED_STATE=%d", flag),
1450 entry("ERROR=%s", e.what()));
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001451 elog<InternalFailure>();
1452 }
1453}
1454
1455/** @brief Callback method to turn off LED
1456 */
1457void enclosureIdentifyLedOff()
1458{
1459 try
1460 {
Yong Lif4e38512019-05-21 14:46:55 +08001461 chassisIDState = ChassisIDState::off;
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001462 enclosureIdentifyLed(false);
1463 }
1464 catch (const InternalFailure& e)
1465 {
1466 report<InternalFailure>();
1467 }
1468}
1469
1470/** @brief Create timer to turn on and off the enclosure LED
1471 */
1472void createIdentifyTimer()
1473{
1474 if (!identifyTimer)
1475 {
Vernon Mauery1181af72018-10-08 12:05:00 -07001476 identifyTimer =
Patrick Williams95655222023-12-05 12:45:02 -06001477 std::make_unique<sdbusplus::Timer>(enclosureIdentifyLedOff);
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001478 }
1479}
1480
Vernon Mauery400cc782018-10-09 13:49:53 -07001481ipmi::RspType<> ipmiChassisIdentify(std::optional<uint8_t> interval,
1482 std::optional<uint8_t> force)
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001483{
Vernon Mauery400cc782018-10-09 13:49:53 -07001484 uint8_t identifyInterval = interval.value_or(DEFAULT_IDENTIFY_TIME_OUT);
1485 bool forceIdentify = force.value_or(0) & 0x01;
Tom Josephbed26992018-07-31 23:00:24 +05301486
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001487 if (identifyInterval || forceIdentify)
1488 {
Vernon Mauery400cc782018-10-09 13:49:53 -07001489 // stop the timer if already started;
1490 // for force identify we should not turn off LED
Vernon Mauery1181af72018-10-08 12:05:00 -07001491 identifyTimer->stop();
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001492 try
Tom Joseph5110c122018-03-23 17:55:40 +05301493 {
Yong Lif4e38512019-05-21 14:46:55 +08001494 chassisIDState = ChassisIDState::temporaryOn;
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001495 enclosureIdentifyLed(true);
1496 }
1497 catch (const InternalFailure& e)
1498 {
1499 report<InternalFailure>();
Vernon Mauery400cc782018-10-09 13:49:53 -07001500 return ipmi::responseResponseError();
Tom Joseph5110c122018-03-23 17:55:40 +05301501 }
1502
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001503 if (forceIdentify)
Tom Joseph5110c122018-03-23 17:55:40 +05301504 {
Yong Lif4e38512019-05-21 14:46:55 +08001505 chassisIDState = ChassisIDState::indefiniteOn;
Vernon Mauery400cc782018-10-09 13:49:53 -07001506 return ipmi::responseSuccess();
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001507 }
1508 // start the timer
1509 auto time = std::chrono::duration_cast<std::chrono::microseconds>(
Patrick Venture0b02be92018-08-31 11:55:55 -07001510 std::chrono::seconds(identifyInterval));
Vernon Mauery1181af72018-10-08 12:05:00 -07001511 identifyTimer->start(time);
Tom Joseph5110c122018-03-23 17:55:40 +05301512 }
Tom Josephbed26992018-07-31 23:00:24 +05301513 else if (!identifyInterval)
1514 {
Vernon Mauery1181af72018-10-08 12:05:00 -07001515 identifyTimer->stop();
Tom Josephbed26992018-07-31 23:00:24 +05301516 enclosureIdentifyLedOff();
1517 }
Vernon Mauery400cc782018-10-09 13:49:53 -07001518 return ipmi::responseSuccess();
Tom Joseph5110c122018-03-23 17:55:40 +05301519}
1520
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001521namespace boot_options
1522{
1523
Willy Tu523e2d12023-09-05 11:36:48 -07001524using namespace sdbusplus::server::xyz::openbmc_project::control::boot;
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001525using IpmiValue = uint8_t;
1526constexpr auto ipmiDefault = 0;
1527
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001528std::map<IpmiValue, Type::Types> typeIpmiToDbus = {{0x00, Type::Types::Legacy},
1529 {0x01, Type::Types::EFI}};
1530
Patrick Venture0b02be92018-08-31 11:55:55 -07001531std::map<IpmiValue, Source::Sources> sourceIpmiToDbus = {
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001532 {0x01, Source::Sources::Network},
1533 {0x02, Source::Sources::Disk},
1534 {0x05, Source::Sources::ExternalMedia},
Jia, chunhui67c5e5d2019-05-06 11:29:54 +08001535 {0x0f, Source::Sources::RemovableMedia},
Patrick Venture0b02be92018-08-31 11:55:55 -07001536 {ipmiDefault, Source::Sources::Default}};
shgoupfd84fbbf2015-12-17 10:05:51 +08001537
Patrick Venture0b02be92018-08-31 11:55:55 -07001538std::map<IpmiValue, Mode::Modes> modeIpmiToDbus = {
Yong Li5833cb62019-10-30 13:27:12 +08001539#ifdef ENABLE_BOOT_FLAG_SAFE_MODE_SUPPORT
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001540 {0x03, Mode::Modes::Safe},
Yong Li5833cb62019-10-30 13:27:12 +08001541#endif // ENABLE_BOOT_SAFE_MODE_SUPPORT
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001542 {0x06, Mode::Modes::Setup},
Patrick Venture0b02be92018-08-31 11:55:55 -07001543 {ipmiDefault, Mode::Modes::Regular}};
shgoupfd84fbbf2015-12-17 10:05:51 +08001544
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001545std::map<Type::Types, IpmiValue> typeDbusToIpmi = {{Type::Types::Legacy, 0x00},
1546 {Type::Types::EFI, 0x01}};
1547
Patrick Venture0b02be92018-08-31 11:55:55 -07001548std::map<Source::Sources, IpmiValue> sourceDbusToIpmi = {
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001549 {Source::Sources::Network, 0x01},
1550 {Source::Sources::Disk, 0x02},
1551 {Source::Sources::ExternalMedia, 0x05},
Jia, chunhui67c5e5d2019-05-06 11:29:54 +08001552 {Source::Sources::RemovableMedia, 0x0f},
Patrick Venture0b02be92018-08-31 11:55:55 -07001553 {Source::Sources::Default, ipmiDefault}};
shgoupfd84fbbf2015-12-17 10:05:51 +08001554
Patrick Venture0b02be92018-08-31 11:55:55 -07001555std::map<Mode::Modes, IpmiValue> modeDbusToIpmi = {
Yong Li5833cb62019-10-30 13:27:12 +08001556#ifdef ENABLE_BOOT_FLAG_SAFE_MODE_SUPPORT
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001557 {Mode::Modes::Safe, 0x03},
Yong Li5833cb62019-10-30 13:27:12 +08001558#endif // ENABLE_BOOT_SAFE_MODE_SUPPORT
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001559 {Mode::Modes::Setup, 0x06},
Patrick Venture0b02be92018-08-31 11:55:55 -07001560 {Mode::Modes::Regular, ipmiDefault}};
shgoupfd84fbbf2015-12-17 10:05:51 +08001561
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001562} // namespace boot_options
shgoupfd84fbbf2015-12-17 10:05:51 +08001563
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001564/** @brief Get the property value for boot source
1565 * @param[in] ctx - context pointer
1566 * @param[out] source - boot source value
1567 * @return On failure return IPMI error.
1568 */
1569static ipmi::Cc getBootSource(ipmi::Context::ptr& ctx, Source::Sources& source)
1570{
1571 using namespace chassis::internal;
1572 std::string result;
1573 std::string service;
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05001574 boost::system::error_code ec = getService(ctx, bootSourceIntf,
1575 bootSettingsPath, service);
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001576 if (!ec)
1577 {
1578 ec = ipmi::getDbusProperty(ctx, service, bootSettingsPath,
1579 bootSourceIntf, "BootSource", result);
1580 if (!ec)
1581 {
1582 source = Source::convertSourcesFromString(result);
1583 return ipmi::ccSuccess;
1584 }
1585 }
1586 log<level::ERR>("Error in BootSource Get",
1587 entry("ERROR=%s", ec.message().c_str()));
1588 return ipmi::ccUnspecifiedError;
1589}
1590
Marri Devender Rao81719702018-05-07 00:53:48 -05001591/** @brief Set the property value for boot source
Konstantin Aladysheve76a61a2021-03-18 22:19:13 +03001592 * @param[in] ctx - context pointer
Marri Devender Rao81719702018-05-07 00:53:48 -05001593 * @param[in] source - boot source value
1594 * @return On failure return IPMI error.
1595 */
Jayaprakash Mutyala6088e9f2021-07-14 07:40:29 +00001596static ipmi::Cc setBootSource(ipmi::Context::ptr& ctx,
1597 const Source::Sources& source)
Marri Devender Rao81719702018-05-07 00:53:48 -05001598{
1599 using namespace chassis::internal;
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001600 std::string service;
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05001601 boost::system::error_code ec = getService(ctx, bootSourceIntf,
1602 bootSettingsPath, service);
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001603 if (!ec)
Marri Devender Rao81719702018-05-07 00:53:48 -05001604 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001605 ec = ipmi::setDbusProperty(ctx, service, bootSettingsPath,
1606 bootSourceIntf, "BootSource",
1607 convertForMessage(source));
1608 if (!ec)
1609 {
1610 return ipmi::ccSuccess;
1611 }
Marri Devender Rao81719702018-05-07 00:53:48 -05001612 }
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001613 log<level::ERR>("Error in BootSource Set",
1614 entry("ERROR=%s", ec.message().c_str()));
1615 return ipmi::ccUnspecifiedError;
1616}
1617
1618/** @brief Get the property value for boot mode
1619 * @param[in] ctx - context pointer
1620 * @param[out] mode - boot mode value
1621 * @return On failure return IPMI error.
1622 */
1623static ipmi::Cc getBootMode(ipmi::Context::ptr& ctx, Mode::Modes& mode)
1624{
1625 using namespace chassis::internal;
1626 std::string result;
1627 std::string service;
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05001628 boost::system::error_code ec = getService(ctx, bootModeIntf,
1629 bootSettingsPath, service);
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001630 if (!ec)
1631 {
1632 ec = ipmi::getDbusProperty(ctx, service, bootSettingsPath, bootModeIntf,
1633 "BootMode", result);
1634 if (!ec)
1635 {
1636 mode = Mode::convertModesFromString(result);
1637 return ipmi::ccSuccess;
1638 }
1639 }
1640 log<level::ERR>("Error in BootMode Get",
1641 entry("ERROR=%s", ec.message().c_str()));
1642 return ipmi::ccUnspecifiedError;
Marri Devender Rao81719702018-05-07 00:53:48 -05001643}
1644
Patrick Venture0b02be92018-08-31 11:55:55 -07001645/** @brief Set the property value for boot mode
Konstantin Aladysheve76a61a2021-03-18 22:19:13 +03001646 * @param[in] ctx - context pointer
Marri Devender Rao81719702018-05-07 00:53:48 -05001647 * @param[in] mode - boot mode value
1648 * @return On failure return IPMI error.
1649 */
Konstantin Aladysheve76a61a2021-03-18 22:19:13 +03001650static ipmi::Cc setBootMode(ipmi::Context::ptr& ctx, const Mode::Modes& mode)
Marri Devender Rao81719702018-05-07 00:53:48 -05001651{
1652 using namespace chassis::internal;
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001653 std::string service;
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05001654 boost::system::error_code ec = getService(ctx, bootModeIntf,
1655 bootSettingsPath, service);
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001656 if (!ec)
Marri Devender Rao81719702018-05-07 00:53:48 -05001657 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001658 ec = ipmi::setDbusProperty(ctx, service, bootSettingsPath, bootModeIntf,
1659 "BootMode", convertForMessage(mode));
1660 if (!ec)
1661 {
1662 return ipmi::ccSuccess;
1663 }
Marri Devender Rao81719702018-05-07 00:53:48 -05001664 }
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001665 log<level::ERR>("Error in BootMode Set",
1666 entry("ERROR=%s", ec.message().c_str()));
1667 return ipmi::ccUnspecifiedError;
1668}
1669
1670/** @brief Get the property value for boot type
1671 * @param[in] ctx - context pointer
1672 * @param[out] type - boot type value
1673 * @return On failure return IPMI error.
1674 */
1675static ipmi::Cc getBootType(ipmi::Context::ptr& ctx, Type::Types& type)
1676{
1677 using namespace chassis::internal;
1678 std::string result;
1679 std::string service;
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05001680 boost::system::error_code ec = getService(ctx, bootTypeIntf,
1681 bootSettingsPath, service);
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001682
1683 // Don't throw error if BootType interface is not present.
1684 // This interface is not relevant for some Host architectures
1685 // (for example POWER). In this case we don't won't IPMI to
1686 // return an error, but simply return bootType as EFI.
1687 type = Type::Types::EFI;
1688 if (!ec)
1689 {
1690 ec = ipmi::getDbusProperty(ctx, service, bootSettingsPath, bootTypeIntf,
1691 "BootType", result);
1692 if (ec)
1693 {
1694 log<level::ERR>("Error in BootType Get",
1695 entry("ERROR=%s", ec.message().c_str()));
1696 return ipmi::ccUnspecifiedError;
1697 }
1698 type = Type::convertTypesFromString(result);
1699 }
1700
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00001701 return ipmi::ccSuccess;
Marri Devender Rao81719702018-05-07 00:53:48 -05001702}
1703
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001704/** @brief Set the property value for boot type
Konstantin Aladysheve76a61a2021-03-18 22:19:13 +03001705 * @param[in] ctx - context pointer
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001706 * @param[in] type - boot type value
1707 * @return On failure return IPMI error.
1708 */
Konstantin Aladysheve76a61a2021-03-18 22:19:13 +03001709static ipmi::Cc setBootType(ipmi::Context::ptr& ctx, const Type::Types& type)
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001710{
1711 using namespace chassis::internal;
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001712 std::string service;
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05001713 boost::system::error_code ec = getService(ctx, bootTypeIntf,
1714 bootSettingsPath, service);
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001715 if (!ec)
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001716 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001717 ec = ipmi::setDbusProperty(ctx, service, bootSettingsPath, bootTypeIntf,
1718 "BootType", convertForMessage(type));
1719 if (ec)
1720 {
1721 log<level::ERR>("Error in BootType Set",
1722 entry("ERROR=%s", ec.message().c_str()));
1723 return ipmi::ccUnspecifiedError;
1724 }
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001725 }
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001726 // Don't throw error if BootType interface is not present.
1727 // This interface is not relevant for some Host architectures
1728 // (for example POWER). In this case we don't won't IPMI to
1729 // return an error, but want to just skip this function.
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001730 return ipmi::ccSuccess;
1731}
1732
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001733/** @brief Get the property value for boot override enable
1734 * @param[in] ctx - context pointer
1735 * @param[out] enable - boot override enable
1736 * @return On failure return IPMI error.
1737 */
1738static ipmi::Cc getBootEnable(ipmi::Context::ptr& ctx, bool& enable)
1739{
1740 using namespace chassis::internal;
1741 std::string result;
1742 std::string service;
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05001743 boost::system::error_code ec = getService(ctx, bootEnableIntf,
1744 bootSettingsPath, service);
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001745 if (!ec)
1746 {
1747 ec = ipmi::getDbusProperty(ctx, service, bootSettingsPath,
1748 bootEnableIntf, "Enabled", enable);
1749 if (!ec)
1750 {
1751 return ipmi::ccSuccess;
1752 }
1753 }
1754 log<level::ERR>("Error in Boot Override Enable Get",
1755 entry("ERROR=%s", ec.message().c_str()));
1756 return ipmi::ccUnspecifiedError;
1757}
1758
1759/** @brief Set the property value for boot override enable
1760 * @param[in] ctx - context pointer
1761 * @param[in] enable - boot override enable
1762 * @return On failure return IPMI error.
1763 */
1764static ipmi::Cc setBootEnable(ipmi::Context::ptr& ctx, const bool& enable)
1765{
1766 using namespace chassis::internal;
1767 std::string service;
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05001768 boost::system::error_code ec = getService(ctx, bootEnableIntf,
1769 bootSettingsPath, service);
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001770 if (!ec)
1771 {
1772 ec = ipmi::setDbusProperty(ctx, service, bootSettingsPath,
1773 bootEnableIntf, "Enabled", enable);
1774 if (!ec)
1775 {
1776 return ipmi::ccSuccess;
1777 }
1778 }
1779 log<level::ERR>("Error in Boot Source Override Enable Set",
1780 entry("ERROR=%s", ec.message().c_str()));
1781 return ipmi::ccUnspecifiedError;
1782}
1783
1784/** @brief Get the property value for boot override one-time
1785 * @param[in] ctx - context pointer
1786 * @param[out] onetime - boot override one-time
1787 * @return On failure return IPMI error.
1788 */
1789static ipmi::Cc getBootOneTime(ipmi::Context::ptr& ctx, bool& onetime)
1790{
1791 using namespace chassis::internal;
1792 std::string result;
1793 std::string service;
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05001794 boost::system::error_code ec = getService(ctx, bootOneTimeIntf,
1795 bootSettingsOneTimePath, service);
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001796 if (!ec)
1797 {
1798 ec = ipmi::getDbusProperty(ctx, service, bootSettingsOneTimePath,
1799 bootOneTimeIntf, "Enabled", onetime);
1800 if (!ec)
1801 {
1802 return ipmi::ccSuccess;
1803 }
1804 }
1805 log<level::ERR>("Error in Boot Override OneTime Get",
1806 entry("ERROR=%s", ec.message().c_str()));
1807 return ipmi::ccUnspecifiedError;
1808}
1809
1810/** @brief Set the property value for boot override one-time
1811 * @param[in] ctx - context pointer
1812 * @param[in] onetime - boot override one-time
1813 * @return On failure return IPMI error.
1814 */
1815static ipmi::Cc setBootOneTime(ipmi::Context::ptr& ctx, const bool& onetime)
1816{
1817 using namespace chassis::internal;
1818 std::string service;
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05001819 boost::system::error_code ec = getService(ctx, bootOneTimeIntf,
1820 bootSettingsOneTimePath, service);
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001821 if (!ec)
1822 {
1823 ec = ipmi::setDbusProperty(ctx, service, bootSettingsOneTimePath,
1824 bootOneTimeIntf, "Enabled", onetime);
1825 if (!ec)
1826 {
1827 return ipmi::ccSuccess;
1828 }
1829 }
1830 log<level::ERR>("Error in Boot Source Override OneTime Set",
1831 entry("ERROR=%s", ec.message().c_str()));
1832 return ipmi::ccUnspecifiedError;
1833}
1834
huangheab369282020-10-10 14:40:00 +08001835static constexpr uint8_t setComplete = 0x0;
1836static constexpr uint8_t setInProgress = 0x1;
1837static uint8_t transferStatus = setComplete;
Chen Yugang86ac4992021-06-25 08:14:52 +08001838static uint8_t bootFlagValidBitClr = 0;
Hieu Huynh38ffafc2021-05-14 08:40:14 +00001839static uint5_t bootInitiatorAckData = 0x0;
Hieu Huynh1982a3f2021-09-21 03:06:45 +00001840static bool cmosClear = false;
huangheab369282020-10-10 14:40:00 +08001841
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00001842/** @brief implements the Get Chassis system boot option
Konstantin Aladysheve76a61a2021-03-18 22:19:13 +03001843 * @param ctx - context pointer
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00001844 * @param bootOptionParameter - boot option parameter selector
1845 * @param reserved1 - reserved bit
1846 * @param setSelector - selects a particular block or set of parameters
1847 * under the given parameter selector
1848 * write as 00h if parameter doesn't use a setSelector
1849 * @param blockSelector- selects a particular block within a set of
1850 * parameters write as 00h if parameter doesn't use a
1851 * blockSelector
1852 *
1853 * @return IPMI completion code plus response data
1854 * @return Payload contains below parameters:
1855 * version - parameter version
1856 * bootOptionParameter - boot option parameter selector
Patrick Venture8b1c3032020-09-15 09:43:03 -07001857 * parmIndicator - parameter valid/invalid indicator
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00001858 * data - configuration parameter data
1859 */
1860ipmi::RspType<ipmi::message::Payload>
Konstantin Aladysheve76a61a2021-03-18 22:19:13 +03001861 ipmiChassisGetSysBootOptions(ipmi::Context::ptr ctx,
1862 uint7_t bootOptionParameter, bool reserved1,
Willy Tu11d68892022-01-20 10:37:34 -08001863 [[maybe_unused]] uint8_t setSelector,
1864 [[maybe_unused]] uint8_t blockSelector)
Adriana Kobylak40814c62015-10-27 15:58:44 -05001865{
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001866 ipmi::Cc rc;
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00001867 if (reserved1)
1868 {
1869 return ipmi::responseInvalidFieldRequest();
1870 }
1871
1872 constexpr uint4_t version = 0x01;
1873 ipmi::message::Payload response;
1874 response.pack(version, uint4_t{});
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001875 using namespace boot_options;
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00001876
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001877 IpmiValue bootOption = ipmiDefault;
Adriana Kobylak40814c62015-10-27 15:58:44 -05001878
William A. Kennington III7a0e5df2021-05-19 13:31:29 -07001879 if (types::enum_cast<BootOptionParameter>(bootOptionParameter) ==
1880 BootOptionParameter::setInProgress)
huangheab369282020-10-10 14:40:00 +08001881 {
1882 response.pack(bootOptionParameter, reserved1, transferStatus);
1883 return ipmi::responseSuccess(std::move(response));
1884 }
1885
William A. Kennington III7a0e5df2021-05-19 13:31:29 -07001886 if (types::enum_cast<BootOptionParameter>(bootOptionParameter) ==
1887 BootOptionParameter::bootInfo)
John Wang0213f902020-12-28 14:49:57 +08001888 {
1889 constexpr uint8_t writeMask = 0;
Hieu Huynh38ffafc2021-05-14 08:40:14 +00001890 response.pack(bootOptionParameter, reserved1, writeMask,
1891 bootInitiatorAckData);
John Wang0213f902020-12-28 14:49:57 +08001892 return ipmi::responseSuccess(std::move(response));
1893 }
1894
Chen Yugang86ac4992021-06-25 08:14:52 +08001895 if (types::enum_cast<BootOptionParameter>(bootOptionParameter) ==
1896 BootOptionParameter::bootFlagValidClr)
1897 {
1898 response.pack(bootOptionParameter, reserved1,
1899 uint5_t{bootFlagValidBitClr}, uint3_t{});
1900 return ipmi::responseSuccess(std::move(response));
1901 }
1902
shgoupfd84fbbf2015-12-17 10:05:51 +08001903 /*
1904 * Parameter #5 means boot flags. Please refer to 28.13 of ipmi doc.
1905 * This is the only parameter used by petitboot.
1906 */
William A. Kennington III7a0e5df2021-05-19 13:31:29 -07001907 if (types::enum_cast<BootOptionParameter>(bootOptionParameter) ==
1908 BootOptionParameter::bootFlags)
Patrick Venture0b02be92018-08-31 11:55:55 -07001909 {
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001910 using namespace chassis::internal;
1911 using namespace chassis::internal::cache;
shgoupfd84fbbf2015-12-17 10:05:51 +08001912
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001913 try
ratagupta6f6bff2016-04-04 06:20:11 -05001914 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001915 Source::Sources bootSource;
1916 rc = getBootSource(ctx, bootSource);
1917 if (rc != ipmi::ccSuccess)
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001918 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001919 return ipmi::response(rc);
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001920 }
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001921
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001922 Type::Types bootType;
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001923 rc = getBootType(ctx, bootType);
1924 if (rc != ipmi::ccSuccess)
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001925 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001926 return ipmi::response(rc);
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001927 }
1928
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001929 Mode::Modes bootMode;
1930 rc = getBootMode(ctx, bootMode);
1931 if (rc != ipmi::ccSuccess)
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001932 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001933 return ipmi::response(rc);
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001934 }
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001935
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001936 bootOption = sourceDbusToIpmi.at(bootSource);
1937 if ((Mode::Modes::Regular == bootMode) &&
1938 (Source::Sources::Default == bootSource))
1939 {
1940 bootOption = ipmiDefault;
1941 }
1942 else if (Source::Sources::Default == bootSource)
1943 {
1944 bootOption = modeDbusToIpmi.at(bootMode);
1945 }
ratagupta6f6bff2016-04-04 06:20:11 -05001946
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001947 IpmiValue biosBootType = typeDbusToIpmi.at(bootType);
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001948
1949 bool oneTimeEnabled;
1950 rc = getBootOneTime(ctx, oneTimeEnabled);
1951 if (rc != ipmi::ccSuccess)
1952 {
1953 return ipmi::response(rc);
1954 }
1955
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001956 uint1_t permanent = oneTimeEnabled ? 0 : 1;
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001957
1958 bool valid;
1959 rc = getBootEnable(ctx, valid);
1960 if (rc != ipmi::ccSuccess)
1961 {
1962 return ipmi::response(rc);
1963 }
1964
1965 uint1_t validFlag = valid ? 1 : 0;
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001966
1967 response.pack(bootOptionParameter, reserved1, uint5_t{},
1968 uint1_t{biosBootType}, uint1_t{permanent},
1969 uint1_t{validFlag}, uint2_t{}, uint4_t{bootOption},
Hieu Huynh1982a3f2021-09-21 03:06:45 +00001970 uint1_t{}, cmosClear, uint8_t{}, uint8_t{},
1971 uint8_t{});
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00001972 return ipmi::responseSuccess(std::move(response));
ratagupta6f6bff2016-04-04 06:20:11 -05001973 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -05001974 catch (const InternalFailure& e)
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001975 {
James Feist225dec82019-11-26 16:25:06 -08001976 cache::objectsPtr.reset();
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001977 report<InternalFailure>();
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00001978 return ipmi::responseUnspecifiedError();
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001979 }
Patrick Venture0b02be92018-08-31 11:55:55 -07001980 }
Patrick Venture0b02be92018-08-31 11:55:55 -07001981 else
1982 {
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00001983 if ((bootOptionParameter >= oemParmStart) &&
1984 (bootOptionParameter <= oemParmEnd))
1985 {
William A. Kennington III7a0e5df2021-05-19 13:31:29 -07001986 if (types::enum_cast<BootOptionParameter>(bootOptionParameter) ==
1987 BootOptionParameter::opalNetworkSettings)
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00001988 {
1989 response.pack(bootOptionParameter, reserved1);
1990 int ret = getHostNetworkData(response);
1991 if (ret < 0)
1992 {
1993 response.trailingOk = true;
1994 log<level::ERR>(
1995 "getHostNetworkData failed for GetSysBootOptions.");
1996 return ipmi::responseUnspecifiedError();
1997 }
1998 else
1999 {
2000 return ipmi::responseSuccess(std::move(response));
2001 }
2002 }
Jayaprakash Mutyala43a88102021-08-04 16:41:58 +00002003 else
2004 {
2005 log<level::ERR>(
2006 "ipmiChassisGetSysBootOptions: Unsupported parameter",
2007 entry("PARAM=0x%x",
2008 static_cast<uint8_t>(bootOptionParameter)));
2009 return ipmi::responseParmNotSupported();
2010 }
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00002011 }
2012 else
2013 {
2014 log<level::ERR>(
2015 "ipmiChassisGetSysBootOptions: Unsupported parameter",
2016 entry("PARAM=0x%x", static_cast<uint8_t>(bootOptionParameter)));
Jayaprakash Mutyala6088e9f2021-07-14 07:40:29 +00002017 return ipmi::responseParmNotSupported();
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00002018 }
shgoupfd84fbbf2015-12-17 10:05:51 +08002019 }
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00002020 return ipmi::responseUnspecifiedError();
shgoupfd84fbbf2015-12-17 10:05:51 +08002021}
2022
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002023ipmi::RspType<> ipmiChassisSetSysBootOptions(ipmi::Context::ptr ctx,
Willy Tu11d68892022-01-20 10:37:34 -08002024 uint7_t parameterSelector, bool,
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002025 ipmi::message::Payload& data)
shgoupfd84fbbf2015-12-17 10:05:51 +08002026{
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05002027 using namespace boot_options;
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002028 ipmi::Cc rc;
shgoupfd84fbbf2015-12-17 10:05:51 +08002029
William A. Kennington III7a0e5df2021-05-19 13:31:29 -07002030 if (types::enum_cast<BootOptionParameter>(parameterSelector) ==
2031 BootOptionParameter::setInProgress)
huangheab369282020-10-10 14:40:00 +08002032 {
2033 uint2_t setInProgressFlag;
2034 uint6_t rsvd;
2035 if (data.unpack(setInProgressFlag, rsvd) != 0 || !data.fullyUnpacked())
2036 {
2037 return ipmi::responseReqDataLenInvalid();
2038 }
2039 if (rsvd)
2040 {
2041 return ipmi::responseInvalidFieldRequest();
2042 }
2043 if ((transferStatus == setInProgress) &&
2044 (static_cast<uint8_t>(setInProgressFlag) != setComplete))
2045 {
2046 return ipmi::response(IPMI_CC_FAIL_SET_IN_PROGRESS);
2047 }
2048 transferStatus = static_cast<uint8_t>(setInProgressFlag);
2049 return ipmi::responseSuccess();
2050 }
2051
shgoupfd84fbbf2015-12-17 10:05:51 +08002052 /* 000101
2053 * Parameter #5 means boot flags. Please refer to 28.13 of ipmi doc.
2054 * This is the only parameter used by petitboot.
2055 */
Ratan Guptafd28dd72016-08-01 04:58:01 -05002056
William A. Kennington III7a0e5df2021-05-19 13:31:29 -07002057 if (types::enum_cast<BootOptionParameter>(parameterSelector) ==
2058 BootOptionParameter::bootFlags)
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05002059 {
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002060 uint5_t rsvd;
2061 bool validFlag;
2062 bool permanent;
2063 bool biosBootType;
2064 bool lockOutResetButton;
2065 bool screenBlank;
2066 uint4_t bootDeviceSelector;
2067 bool lockKeyboard;
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002068 uint8_t data3;
2069 uint4_t biosInfo;
2070 uint4_t rsvd1;
2071 uint5_t deviceInstance;
2072 uint3_t rsvd2;
2073
2074 if (data.unpack(rsvd, biosBootType, permanent, validFlag,
2075 lockOutResetButton, screenBlank, bootDeviceSelector,
2076 lockKeyboard, cmosClear, data3, biosInfo, rsvd1,
2077 deviceInstance, rsvd2) != 0 ||
2078 !data.fullyUnpacked())
2079 {
2080 return ipmi::responseReqDataLenInvalid();
2081 }
2082 if (rsvd || rsvd1 || rsvd2)
2083 {
2084 return ipmi::responseInvalidFieldRequest();
2085 }
2086
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05002087 using namespace chassis::internal;
2088 using namespace chassis::internal::cache;
shgoupfd84fbbf2015-12-17 10:05:51 +08002089
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05002090 try
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05002091 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03002092 rc = setBootOneTime(ctx, !permanent);
2093 if (rc != ipmi::ccSuccess)
Konstantin Aladyshev69e8e842021-06-18 17:01:18 +03002094 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03002095 return ipmi::response(rc);
2096 }
Vernon Maueryafd45db2021-07-29 16:27:25 +00002097
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03002098 rc = setBootEnable(ctx, validFlag);
2099 if (rc != ipmi::ccSuccess)
2100 {
2101 return ipmi::response(rc);
Tom Joseph57e8eb72017-09-25 18:05:02 +05302102 }
2103
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002104 auto modeItr =
2105 modeIpmiToDbus.find(static_cast<uint8_t>(bootDeviceSelector));
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03002106 auto typeItr =
2107 typeIpmiToDbus.find(static_cast<uint8_t>(biosBootType));
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002108 auto sourceItr =
2109 sourceIpmiToDbus.find(static_cast<uint8_t>(bootDeviceSelector));
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05002110 if (sourceIpmiToDbus.end() != sourceItr)
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05002111 {
Konstantin Aladysheve76a61a2021-03-18 22:19:13 +03002112 rc = setBootSource(ctx, sourceItr->second);
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002113 if (rc != ipmi::ccSuccess)
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05002114 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03002115 return ipmi::response(rc);
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05002116 }
Marri Devender Rao54fa1302018-05-07 01:06:23 -05002117 // If a set boot device is mapping to a boot source, then reset
2118 // the boot mode D-Bus property to default.
2119 // This way the ipmid code can determine which property is not
2120 // at the default value
Patrick Venture0b02be92018-08-31 11:55:55 -07002121 if (sourceItr->second != Source::Sources::Default)
Marri Devender Rao54fa1302018-05-07 01:06:23 -05002122 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03002123 rc = setBootMode(ctx, Mode::Modes::Regular);
2124 if (rc != ipmi::ccSuccess)
2125 {
2126 return ipmi::response(rc);
2127 }
Marri Devender Rao54fa1302018-05-07 01:06:23 -05002128 }
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05002129 }
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03002130
2131 if (typeIpmiToDbus.end() != typeItr)
2132 {
Konstantin Aladysheve76a61a2021-03-18 22:19:13 +03002133 rc = setBootType(ctx, typeItr->second);
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03002134 if (rc != ipmi::ccSuccess)
2135 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03002136 return ipmi::response(rc);
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03002137 }
2138 }
2139
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05002140 if (modeIpmiToDbus.end() != modeItr)
2141 {
Konstantin Aladysheve76a61a2021-03-18 22:19:13 +03002142 rc = setBootMode(ctx, modeItr->second);
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002143 if (rc != ipmi::ccSuccess)
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05002144 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03002145 return ipmi::response(rc);
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05002146 }
Marri Devender Rao54fa1302018-05-07 01:06:23 -05002147 // If a set boot device is mapping to a boot mode, then reset
2148 // the boot source D-Bus property to default.
2149 // This way the ipmid code can determine which property is not
2150 // at the default value
Patrick Venture0b02be92018-08-31 11:55:55 -07002151 if (modeItr->second != Mode::Modes::Regular)
Marri Devender Rao54fa1302018-05-07 01:06:23 -05002152 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03002153 rc = setBootSource(ctx, Source::Sources::Default);
2154 if (rc != ipmi::ccSuccess)
2155 {
2156 return ipmi::response(rc);
2157 }
Marri Devender Rao54fa1302018-05-07 01:06:23 -05002158 }
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05002159 }
Jia, chunhui67c5e5d2019-05-06 11:29:54 +08002160 if ((modeIpmiToDbus.end() == modeItr) &&
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03002161 (typeIpmiToDbus.end() == typeItr) &&
Jia, chunhui67c5e5d2019-05-06 11:29:54 +08002162 (sourceIpmiToDbus.end() == sourceItr))
2163 {
2164 // return error if boot option is not supported
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002165 log<level::ERR>(
2166 "ipmiChassisSetSysBootOptions: Boot option not supported");
2167 return ipmi::responseInvalidFieldRequest();
Jia, chunhui67c5e5d2019-05-06 11:29:54 +08002168 }
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05002169 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -05002170 catch (const sdbusplus::exception_t& e)
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05002171 {
James Feist225dec82019-11-26 16:25:06 -08002172 objectsPtr.reset();
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05002173 report<InternalFailure>();
Aditya Saripalli5fb14602017-11-09 14:46:27 +05302174 log<level::ERR>(
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002175 "ipmiChassisSetSysBootOptions: Error in setting Boot "
2176 "flag parameters");
2177 return ipmi::responseUnspecifiedError();
Ratan Guptafd28dd72016-08-01 04:58:01 -05002178 }
Patrick Venture0b02be92018-08-31 11:55:55 -07002179 }
William A. Kennington III7a0e5df2021-05-19 13:31:29 -07002180 else if (types::enum_cast<BootOptionParameter>(parameterSelector) ==
2181 BootOptionParameter::bootInfo)
Patrick Venture0b02be92018-08-31 11:55:55 -07002182 {
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002183 uint8_t writeMak;
Hieu Huynh38ffafc2021-05-14 08:40:14 +00002184 uint5_t bootInfoAck;
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002185 uint3_t rsvd;
2186
Hieu Huynh38ffafc2021-05-14 08:40:14 +00002187 if (data.unpack(writeMak, bootInfoAck, rsvd) != 0 ||
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002188 !data.fullyUnpacked())
2189 {
2190 return ipmi::responseReqDataLenInvalid();
2191 }
2192 if (rsvd)
2193 {
2194 return ipmi::responseInvalidFieldRequest();
2195 }
Hieu Huynh38ffafc2021-05-14 08:40:14 +00002196 bootInitiatorAckData &= ~writeMak;
2197 bootInitiatorAckData |= (writeMak & bootInfoAck);
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002198 log<level::INFO>("ipmiChassisSetSysBootOptions: bootInfo parameter set "
2199 "successfully");
2200 data.trailingOk = true;
2201 return ipmi::responseSuccess();
Patrick Venture0b02be92018-08-31 11:55:55 -07002202 }
Chen Yugang86ac4992021-06-25 08:14:52 +08002203 else if (types::enum_cast<BootOptionParameter>(parameterSelector) ==
2204 BootOptionParameter::bootFlagValidClr)
2205 {
2206 uint5_t bootFlagValidClr;
2207 uint3_t rsvd;
2208
2209 if (data.unpack(bootFlagValidClr, rsvd) != 0 || !data.fullyUnpacked())
2210 {
2211 return ipmi::responseReqDataLenInvalid();
2212 }
2213 if (rsvd)
2214 {
2215 return ipmi::responseInvalidFieldRequest();
2216 }
2217 // store boot flag valid bits clear value
2218 bootFlagValidBitClr = static_cast<uint8_t>(bootFlagValidClr);
2219 log<level::INFO>(
2220 "ipmiChassisSetSysBootOptions: bootFlagValidBits parameter set "
2221 "successfully",
2222 entry("value=0x%x", bootFlagValidBitClr));
2223 return ipmi::responseSuccess();
2224 }
Patrick Venture0b02be92018-08-31 11:55:55 -07002225 else
2226 {
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002227 if ((parameterSelector >= static_cast<uint7_t>(oemParmStart)) &&
2228 (parameterSelector <= static_cast<uint7_t>(oemParmEnd)))
2229 {
William A. Kennington III7a0e5df2021-05-19 13:31:29 -07002230 if (types::enum_cast<BootOptionParameter>(parameterSelector) ==
2231 BootOptionParameter::opalNetworkSettings)
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002232 {
2233 ipmi::Cc ret = setHostNetworkData(data);
2234 if (ret != ipmi::ccSuccess)
2235 {
2236 log<level::ERR>("ipmiChassisSetSysBootOptions: Error in "
2237 "setHostNetworkData");
2238 data.trailingOk = true;
2239 return ipmi::response(ret);
2240 }
2241 data.trailingOk = true;
2242 return ipmi::responseSuccess();
2243 }
2244 else
2245 {
2246 log<level::ERR>(
2247 "ipmiChassisSetSysBootOptions: Unsupported parameters",
2248 entry("PARAM=0x%x",
2249 static_cast<uint8_t>(parameterSelector)));
2250 data.trailingOk = true;
2251 return ipmi::responseParmNotSupported();
2252 }
2253 }
2254 data.trailingOk = true;
2255 return ipmi::responseParmNotSupported();
Adriana Kobylak40814c62015-10-27 15:58:44 -05002256 }
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002257 return ipmi::responseSuccess();
Adriana Kobylak40814c62015-10-27 15:58:44 -05002258}
2259
anil kumar appanaa5a76eb2019-04-30 14:57:24 +00002260/** @brief implements Get POH counter command
2261 * @parameter
2262 * - none
2263 * @returns IPMI completion code plus response data
2264 * - minPerCount - Minutes per count
2265 * - counterReading - counter reading
2266 */
2267ipmi::RspType<uint8_t, // Minutes per count
2268 uint32_t // Counter reading
2269 >
2270 ipmiGetPOHCounter()
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -05002271{
2272 // sd_bus error
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -05002273 try
2274 {
anil kumar appanaa5a76eb2019-04-30 14:57:24 +00002275 return ipmi::responseSuccess(static_cast<uint8_t>(poh::minutesPerCount),
2276 getPOHCounter());
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -05002277 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -05002278 catch (const std::exception& e)
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -05002279 {
2280 log<level::ERR>(e.what());
anil kumar appanaa5a76eb2019-04-30 14:57:24 +00002281 return ipmi::responseUnspecifiedError();
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -05002282 }
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -05002283}
2284
Jason M. Billsbc996a32019-06-17 15:46:37 -07002285ipmi::RspType<uint3_t, // policy support
2286 uint5_t // reserved
2287 >
Vernon Mauerye278ead2018-10-09 09:23:43 -07002288 ipmiChassisSetPowerRestorePolicy(boost::asio::yield_context yield,
Jason M. Billsbc996a32019-06-17 15:46:37 -07002289 uint3_t policy, uint5_t reserved)
Yong Lic6713cf2018-09-12 12:35:13 +08002290{
Yong Lic6713cf2018-09-12 12:35:13 +08002291 power_policy::DbusValue value =
2292 power_policy::RestorePolicy::Policy::AlwaysOff;
2293
Jason M. Billsbc996a32019-06-17 15:46:37 -07002294 if (reserved || (policy > power_policy::noChange))
Yong Lic6713cf2018-09-12 12:35:13 +08002295 {
Vernon Mauerye278ead2018-10-09 09:23:43 -07002296 phosphor::logging::log<level::ERR>(
2297 "Reserved request parameter",
2298 entry("REQ=0x%x", static_cast<int>(policy)));
Jason M. Billsbc996a32019-06-17 15:46:37 -07002299 return ipmi::responseInvalidFieldRequest();
Yong Lic6713cf2018-09-12 12:35:13 +08002300 }
2301
Vernon Mauerye278ead2018-10-09 09:23:43 -07002302 if (policy == power_policy::noChange)
Yong Lic6713cf2018-09-12 12:35:13 +08002303 {
2304 // just return the supported policy
Jason M. Billsbc996a32019-06-17 15:46:37 -07002305 return ipmi::responseSuccess(power_policy::allSupport, reserved);
Yong Lic6713cf2018-09-12 12:35:13 +08002306 }
2307
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05002308 for (const auto& it : power_policy::dbusToIpmi)
Yong Lic6713cf2018-09-12 12:35:13 +08002309 {
Vernon Mauerye278ead2018-10-09 09:23:43 -07002310 if (it.second == policy)
Yong Lic6713cf2018-09-12 12:35:13 +08002311 {
2312 value = it.first;
2313 break;
2314 }
2315 }
2316
2317 try
2318 {
James Feist225dec82019-11-26 16:25:06 -08002319 settings::Objects& objects = chassis::internal::cache::getObjects();
Yong Lic6713cf2018-09-12 12:35:13 +08002320 const settings::Path& powerRestoreSetting =
James Feist225dec82019-11-26 16:25:06 -08002321 objects.map.at(chassis::internal::powerRestoreIntf).front();
Vernon Mauery16b86932019-05-01 08:36:11 -07002322 std::variant<std::string> property = convertForMessage(value);
Yong Lic6713cf2018-09-12 12:35:13 +08002323
Vernon Mauerye278ead2018-10-09 09:23:43 -07002324 auto sdbusp = getSdBus();
2325 boost::system::error_code ec;
2326 sdbusp->yield_method_call<void>(
2327 yield, ec,
James Feist225dec82019-11-26 16:25:06 -08002328 objects
Yong Lic6713cf2018-09-12 12:35:13 +08002329 .service(powerRestoreSetting,
2330 chassis::internal::powerRestoreIntf)
2331 .c_str(),
Vernon Mauerye278ead2018-10-09 09:23:43 -07002332 powerRestoreSetting, ipmi::PROP_INTF, "Set",
2333 chassis::internal::powerRestoreIntf, "PowerRestorePolicy",
2334 property);
2335 if (ec)
Yong Lic6713cf2018-09-12 12:35:13 +08002336 {
2337 phosphor::logging::log<level::ERR>("Unspecified Error");
Vernon Mauerye278ead2018-10-09 09:23:43 -07002338 return ipmi::responseUnspecifiedError();
Yong Lic6713cf2018-09-12 12:35:13 +08002339 }
2340 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -05002341 catch (const InternalFailure& e)
Yong Lic6713cf2018-09-12 12:35:13 +08002342 {
James Feist225dec82019-11-26 16:25:06 -08002343 chassis::internal::cache::objectsPtr.reset();
Yong Lic6713cf2018-09-12 12:35:13 +08002344 report<InternalFailure>();
Vernon Mauerye278ead2018-10-09 09:23:43 -07002345 return ipmi::responseUnspecifiedError();
Yong Lic6713cf2018-09-12 12:35:13 +08002346 }
2347
Jason M. Billsbc996a32019-06-17 15:46:37 -07002348 return ipmi::responseSuccess(power_policy::allSupport, reserved);
Yong Lic6713cf2018-09-12 12:35:13 +08002349}
2350
Willy Tu11d68892022-01-20 10:37:34 -08002351ipmi::RspType<> ipmiSetFrontPanelButtonEnables(ipmi::Context::ptr ctx,
2352 bool disablePowerButton,
2353 bool disableResetButton, bool,
2354 bool, uint4_t)
Kuiying Wang21addc52019-01-04 10:50:21 +08002355{
2356 using namespace chassis::internal;
2357
2358 // set power button Enabled property
2359 bool success = setButtonEnabled(ctx, powerButtonPath, powerButtonIntf,
2360 !disablePowerButton);
2361
2362 // set reset button Enabled property
2363 success &= setButtonEnabled(ctx, resetButtonPath, resetButtonIntf,
2364 !disableResetButton);
2365
2366 if (!success)
2367 {
2368 // not all buttons were successfully set
2369 return ipmi::responseUnspecifiedError();
2370 }
2371 return ipmi::responseSuccess();
2372}
2373
Adriana Kobylak40814c62015-10-27 15:58:44 -05002374void register_netfn_chassis_functions()
2375{
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05002376 createIdentifyTimer();
2377
Tom05732372016-09-06 17:21:23 +05302378 // Get Chassis Capabilities
anil kumar appana43263c62019-05-27 12:45:04 +00002379 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis,
2380 ipmi::chassis::cmdGetChassisCapabilities,
2381 ipmi::Privilege::User, ipmiGetChassisCap);
Nan Li8d15fb42016-08-16 22:29:40 +08002382
Kuiying Wang21addc52019-01-04 10:50:21 +08002383 // Set Front Panel Button Enables
2384 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis,
2385 ipmi::chassis::cmdSetFrontPanelButtonEnables,
2386 ipmi::Privilege::Admin,
2387 ipmiSetFrontPanelButtonEnables);
2388
Yong Liae4b0402018-11-02 11:12:14 +08002389 // Set Chassis Capabilities
anil kumar appana894d0222019-05-27 16:32:14 +00002390 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis,
2391 ipmi::chassis::cmdSetChassisCapabilities,
2392 ipmi::Privilege::User, ipmiSetChassisCap);
Yong Liae4b0402018-11-02 11:12:14 +08002393
Tom05732372016-09-06 17:21:23 +05302394 // <Get System Boot Options>
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00002395 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis,
2396 ipmi::chassis::cmdGetSystemBootOptions,
2397 ipmi::Privilege::Operator,
2398 ipmiChassisGetSysBootOptions);
Adriana Kobylak40814c62015-10-27 15:58:44 -05002399
Tom05732372016-09-06 17:21:23 +05302400 // <Get Chassis Status>
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07002401 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis,
2402 ipmi::chassis::cmdGetChassisStatus,
2403 ipmi::Privilege::User, ipmiGetChassisStatus);
Nan Lifdd8ec52016-08-28 03:57:40 +08002404
Vijay Khemka074f64d2020-03-03 15:08:43 -08002405 // <Chassis Get System Restart Cause>
2406 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis,
2407 ipmi::chassis::cmdGetSystemRestartCause,
2408 ipmi::Privilege::User, ipmiGetSystemRestartCause);
2409
Tom05732372016-09-06 17:21:23 +05302410 // <Chassis Control>
anil kumar appanadafff5f2019-04-27 18:06:00 +00002411 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis,
2412 ipmi::chassis::cmdChassisControl,
2413 ipmi::Privilege::Operator, ipmiChassisControl);
shgoupfd84fbbf2015-12-17 10:05:51 +08002414
Tom Joseph5110c122018-03-23 17:55:40 +05302415 // <Chassis Identify>
Vernon Mauery400cc782018-10-09 13:49:53 -07002416 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis,
2417 ipmi::chassis::cmdChassisIdentify,
2418 ipmi::Privilege::Operator, ipmiChassisIdentify);
Tom Joseph5110c122018-03-23 17:55:40 +05302419
Tom05732372016-09-06 17:21:23 +05302420 // <Set System Boot Options>
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002421 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis,
2422 ipmi::chassis::cmdSetSystemBootOptions,
2423 ipmi::Privilege::Operator,
2424 ipmiChassisSetSysBootOptions);
2425
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -05002426 // <Get POH Counter>
anil kumar appanaa5a76eb2019-04-30 14:57:24 +00002427 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis,
2428 ipmi::chassis::cmdGetPohCounter,
2429 ipmi::Privilege::User, ipmiGetPOHCounter);
Yong Lic6713cf2018-09-12 12:35:13 +08002430
2431 // <Set Power Restore Policy>
Vernon Mauerye278ead2018-10-09 09:23:43 -07002432 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis,
2433 ipmi::chassis::cmdSetPowerRestorePolicy,
2434 ipmi::Privilege::Operator,
2435 ipmiChassisSetPowerRestorePolicy);
vishwa36993272015-11-20 12:43:49 -06002436}