blob: b366b2af8beb1edd548abaa336324e977fbaad4b [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>
Patrick Venture0b02be92018-08-31 11:55:55 -07008#include <netinet/in.h>
Patrick Venture0b02be92018-08-31 11:55:55 -07009
Vernon Mauerye08fbff2019-04-03 09:19:34 -070010#include <ipmid/api.hpp>
Vernon Mauery33250242019-03-12 16:49:26 -070011#include <ipmid/types.hpp>
Vernon Mauery6a98fe72019-03-11 15:57:48 -070012#include <ipmid/utils.hpp>
Patrick Venture3a5071a2018-09-12 13:27:42 -070013#include <phosphor-logging/elog-errors.hpp>
14#include <phosphor-logging/log.hpp>
15#include <sdbusplus/bus.hpp>
William A. Kennington III4c008022018-10-12 17:18:14 -070016#include <sdbusplus/message/types.hpp>
Patrick Venture3a5071a2018-09-12 13:27:42 -070017#include <sdbusplus/server/object.hpp>
Vernon Mauery1181af72018-10-08 12:05:00 -070018#include <sdbusplus/timer.hpp>
Vernon Mauerye278ead2018-10-09 09:23:43 -070019#include <settings.hpp>
Patrick Venture3a5071a2018-09-12 13:27:42 -070020#include <xyz/openbmc_project/Common/error.hpp>
21#include <xyz/openbmc_project/Control/Boot/Mode/server.hpp>
22#include <xyz/openbmc_project/Control/Boot/Source/server.hpp>
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +030023#include <xyz/openbmc_project/Control/Boot/Type/server.hpp>
Patrick Venture3a5071a2018-09-12 13:27:42 -070024#include <xyz/openbmc_project/Control/Power/RestorePolicy/server.hpp>
Jason M. Billsad588bf2020-01-30 16:18:33 -080025#include <xyz/openbmc_project/State/Chassis/server.hpp>
Patrick Venture3a5071a2018-09-12 13:27:42 -070026#include <xyz/openbmc_project/State/Host/server.hpp>
27#include <xyz/openbmc_project/State/PowerOnHours/server.hpp>
28
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -050029#include <array>
30#include <chrono>
31#include <cstring>
32#include <filesystem>
33#include <fstream>
34#include <future>
35#include <map>
36#include <sstream>
37#include <string>
38
Patrick Williams95655222023-12-05 12:45:02 -060039std::unique_ptr<sdbusplus::Timer> identifyTimer
Lei YU4b0ddb62019-01-25 16:43:50 +080040 __attribute__((init_priority(101)));
Marri Devender Rao6706c1c2018-05-14 00:29:38 -050041
Yong Lif4e38512019-05-21 14:46:55 +080042static ChassisIDState chassisIDState = ChassisIDState::reserved;
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +000043static constexpr uint8_t setParmVersion = 0x01;
Yong Lif4e38512019-05-21 14:46:55 +080044
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +000045constexpr size_t sizeVersion = 2;
Tom Joseph5110c122018-03-23 17:55:40 +053046constexpr size_t DEFAULT_IDENTIFY_TIME_OUT = 15;
Ratan Gupta6ec7daa2017-07-15 14:13:01 +053047
Patrick Venture0b02be92018-08-31 11:55:55 -070048// PetiBoot-Specific
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +000049static constexpr uint8_t netConfInitialBytes[] = {0x80, 0x21, 0x70, 0x62,
50 0x21, 0x00, 0x01, 0x06};
51static constexpr uint8_t oemParmStart = 96;
52static constexpr uint8_t oemParmEnd = 127;
Ratan Guptafd28dd72016-08-01 04:58:01 -050053
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +000054static constexpr size_t cookieOffset = 1;
55static constexpr size_t versionOffset = 5;
56static constexpr size_t addrSizeOffset = 8;
57static constexpr size_t macOffset = 9;
58static constexpr size_t addrTypeOffset = 16;
59static constexpr size_t ipAddrOffset = 17;
ratagupta6f6bff2016-04-04 06:20:11 -050060
Marri Devender Rao6706c1c2018-05-14 00:29:38 -050061static constexpr size_t encIdentifyObjectsSize = 1;
62static constexpr size_t chassisIdentifyReqLength = 2;
63static constexpr size_t identifyIntervalPos = 0;
64static constexpr size_t forceIdentifyPos = 1;
shgoupfd84fbbf2015-12-17 10:05:51 +080065
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +000066namespace ipmi
67{
68constexpr Cc ccParmNotSupported = 0x80;
69
70static inline auto responseParmNotSupported()
71{
72 return response(ccParmNotSupported);
73}
74} // namespace ipmi
75
Adriana Kobylak40814c62015-10-27 15:58:44 -050076void register_netfn_chassis_functions() __attribute__((constructor));
77
shgoupfd84fbbf2015-12-17 10:05:51 +080078// Host settings in dbus
79// Service name should be referenced by connection name got via object mapper
Patrick Venture0b02be92018-08-31 11:55:55 -070080const char* settings_object_name = "/org/openbmc/settings/host0";
81const char* settings_intf_name = "org.freedesktop.DBus.Properties";
Patrick Venture0b02be92018-08-31 11:55:55 -070082const char* identify_led_object_name =
Tom Joseph5110c122018-03-23 17:55:40 +053083 "/xyz/openbmc_project/led/groups/enclosure_identify";
shgoupfd84fbbf2015-12-17 10:05:51 +080084
Ratan Guptadcb10672017-07-10 10:33:50 +053085constexpr auto SETTINGS_ROOT = "/";
86constexpr auto SETTINGS_MATCH = "host0";
Ratan Guptadcb10672017-07-10 10:33:50 +053087
88constexpr auto IP_INTERFACE = "xyz.openbmc_project.Network.IP";
89constexpr auto MAC_INTERFACE = "xyz.openbmc_project.Network.MACAddress";
90
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -050091static constexpr auto chassisStateRoot = "/xyz/openbmc_project/state";
92static constexpr auto chassisPOHStateIntf =
Patrick Venture0b02be92018-08-31 11:55:55 -070093 "xyz.openbmc_project.State.PowerOnHours";
Patrick Williams7345ac42021-04-30 20:57:39 -050094static constexpr auto pohCounterProperty = "POHCounter";
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -050095static constexpr auto match = "chassis0";
Yong Liae4b0402018-11-02 11:12:14 +080096const static constexpr char chassisCapIntf[] =
97 "xyz.openbmc_project.Control.ChassisCapabilities";
Karthick Sundarrajan86d8bd72019-11-26 12:48:50 -080098const static constexpr char chassisIntrusionProp[] = "ChassisIntrusionEnabled";
99const static constexpr char chassisFrontPanelLockoutProp[] =
100 "ChassisFrontPanelLockoutEnabled";
101const static constexpr char chassisNMIProp[] = "ChassisNMIEnabled";
102const static constexpr char chassisPowerInterlockProp[] =
103 "ChassisPowerInterlockEnabled";
Yong Liae4b0402018-11-02 11:12:14 +0800104const static constexpr char chassisFRUDevAddrProp[] = "FRUDeviceAddress";
105const static constexpr char chassisSDRDevAddrProp[] = "SDRDeviceAddress";
106const static constexpr char chassisSELDevAddrProp[] = "SELDeviceAddress";
107const static constexpr char chassisSMDevAddrProp[] = "SMDeviceAddress";
108const static constexpr char chassisBridgeDevAddrProp[] = "BridgeDeviceAddress";
109static constexpr uint8_t chassisCapFlagMask = 0x0f;
110static constexpr uint8_t chassisCapAddrMask = 0xfe;
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700111static constexpr const char* powerButtonIntf =
112 "xyz.openbmc_project.Chassis.Buttons.Power";
113static constexpr const char* powerButtonPath =
114 "/xyz/openbmc_project/Chassis/Buttons/Power0";
115static constexpr const char* resetButtonIntf =
116 "xyz.openbmc_project.Chassis.Buttons.Reset";
117static constexpr const char* resetButtonPath =
118 "/xyz/openbmc_project/Chassis/Buttons/Reset0";
Ratan Guptadcb10672017-07-10 10:33:50 +0530119
Vishwanatha Subbannab12b0c02017-03-07 18:17:19 +0530120// Phosphor Host State manager
Willy Tu523e2d12023-09-05 11:36:48 -0700121namespace State = sdbusplus::server::xyz::openbmc_project::state;
Vernon Mauery185b9f82018-07-20 10:52:36 -0700122namespace fs = std::filesystem;
Andrew Geisslera6e3a302017-05-31 19:34:00 -0500123
Ratan Guptadcb10672017-07-10 10:33:50 +0530124using namespace phosphor::logging;
Willy Tu523e2d12023-09-05 11:36:48 -0700125using namespace sdbusplus::error::xyz::openbmc_project::common;
126using namespace sdbusplus::server::xyz::openbmc_project::control::boot;
William A. Kennington III4c008022018-10-12 17:18:14 -0700127
Deepak Kodihalli8cc19362017-07-21 11:18:38 -0500128namespace chassis
129{
130namespace internal
131{
132
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +0300133constexpr auto bootSettingsPath = "/xyz/openbmc_project/control/host0/boot";
134constexpr auto bootEnableIntf = "xyz.openbmc_project.Object.Enable";
Deepak Kodihalli8cc19362017-07-21 11:18:38 -0500135constexpr auto bootModeIntf = "xyz.openbmc_project.Control.Boot.Mode";
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +0300136constexpr auto bootTypeIntf = "xyz.openbmc_project.Control.Boot.Type";
Deepak Kodihalli8cc19362017-07-21 11:18:38 -0500137constexpr auto bootSourceIntf = "xyz.openbmc_project.Control.Boot.Source";
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +0300138constexpr auto bootSettingsOneTimePath =
139 "/xyz/openbmc_project/control/host0/boot/one_time";
140constexpr auto bootOneTimeIntf = "xyz.openbmc_project.Object.Enable";
141
Deepak Kodihalli18b70d12017-07-21 13:36:33 -0500142constexpr auto powerRestoreIntf =
143 "xyz.openbmc_project.Control.Power.RestorePolicy";
Patrick Williams5d82f472022-07-22 19:26:53 -0500144sdbusplus::bus_t dbus(ipmid_get_sd_bus_connection());
Deepak Kodihalli8cc19362017-07-21 11:18:38 -0500145
146namespace cache
147{
148
James Feist225dec82019-11-26 16:25:06 -0800149std::unique_ptr<settings::Objects> objectsPtr = nullptr;
150
151settings::Objects& getObjects()
152{
153 if (objectsPtr == nullptr)
154 {
155 objectsPtr = std::make_unique<settings::Objects>(
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +0300156 dbus, std::vector<std::string>{bootModeIntf, bootTypeIntf,
157 bootSourceIntf, powerRestoreIntf});
James Feist225dec82019-11-26 16:25:06 -0800158 }
159 return *objectsPtr;
160}
Deepak Kodihalli8cc19362017-07-21 11:18:38 -0500161
162} // namespace cache
163} // namespace internal
164} // namespace chassis
165
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -0500166namespace poh
167{
168
169constexpr auto minutesPerCount = 60;
170
171} // namespace poh
172
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000173int getHostNetworkData(ipmi::message::Payload& payload)
Ratan Guptafd28dd72016-08-01 04:58:01 -0500174{
Ratan Guptadcb10672017-07-10 10:33:50 +0530175 ipmi::PropertyMap properties;
176 int rc = 0;
Ratan Gupta8c31d232017-08-13 05:49:43 +0530177 uint8_t addrSize = ipmi::network::IPV4_ADDRESS_SIZE_BYTE;
Ratan Guptafd28dd72016-08-01 04:58:01 -0500178
Ratan Guptadcb10672017-07-10 10:33:50 +0530179 try
180 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700181 // TODO There may be cases where an interface is implemented by multiple
Ratan Guptadcb10672017-07-10 10:33:50 +0530182 // objects,to handle such cases we are interested on that object
183 // which are on interested busname.
184 // Currenlty mapper doesn't give the readable busname(gives busid)
185 // so we can't match with bus name so giving some object specific info
186 // as SETTINGS_MATCH.
187 // Later SETTINGS_MATCH will be replaced with busname.
Ratan Guptafd28dd72016-08-01 04:58:01 -0500188
Patrick Williams5d82f472022-07-22 19:26:53 -0500189 sdbusplus::bus_t bus(ipmid_get_sd_bus_connection());
Ratan Guptadcb10672017-07-10 10:33:50 +0530190
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530191 auto ipObjectInfo = ipmi::getDbusObject(bus, IP_INTERFACE,
192 SETTINGS_ROOT, SETTINGS_MATCH);
193
194 auto macObjectInfo = ipmi::getDbusObject(bus, MAC_INTERFACE,
195 SETTINGS_ROOT, SETTINGS_MATCH);
196
Patrick Venture0b02be92018-08-31 11:55:55 -0700197 properties = ipmi::getAllDbusProperties(
198 bus, ipObjectInfo.second, ipObjectInfo.first, IP_INTERFACE);
199 auto variant = ipmi::getDbusProperty(bus, macObjectInfo.second,
200 macObjectInfo.first, MAC_INTERFACE,
201 "MACAddress");
Ratan Guptadcb10672017-07-10 10:33:50 +0530202
Vernon Maueryf442e112019-04-09 11:44:36 -0700203 auto ipAddress = std::get<std::string>(properties["Address"]);
Ratan Guptad70f4532017-08-04 02:07:31 +0530204
Vernon Maueryf442e112019-04-09 11:44:36 -0700205 auto gateway = std::get<std::string>(properties["Gateway"]);
Ratan Guptad70f4532017-08-04 02:07:31 +0530206
Vernon Maueryf442e112019-04-09 11:44:36 -0700207 auto prefix = std::get<uint8_t>(properties["PrefixLength"]);
Ratan Guptad70f4532017-08-04 02:07:31 +0530208
Patrick Venture0b02be92018-08-31 11:55:55 -0700209 uint8_t isStatic =
Vernon Maueryf442e112019-04-09 11:44:36 -0700210 (std::get<std::string>(properties["Origin"]) ==
Patrick Venture0b02be92018-08-31 11:55:55 -0700211 "xyz.openbmc_project.Network.IP.AddressOrigin.Static")
212 ? 1
213 : 0;
Ratan Guptad70f4532017-08-04 02:07:31 +0530214
Vernon Maueryf442e112019-04-09 11:44:36 -0700215 auto MACAddress = std::get<std::string>(variant);
Ratan Guptacc8feb42017-07-25 21:52:10 +0530216
Ratan Guptad70f4532017-08-04 02:07:31 +0530217 // it is expected here that we should get the valid data
218 // but we may also get the default values.
219 // Validation of the data is done by settings.
220 //
221 // if mac address is default mac address then
222 // don't send blank override.
Ratan Gupta8c31d232017-08-13 05:49:43 +0530223 if ((MACAddress == ipmi::network::DEFAULT_MAC_ADDRESS))
Ratan Guptad70f4532017-08-04 02:07:31 +0530224 {
Ratan Guptad70f4532017-08-04 02:07:31 +0530225 rc = -1;
226 return rc;
227 }
228 // if addr is static then ipaddress,gateway,prefix
229 // should not be default one,don't send blank override.
230 if (isStatic)
231 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700232 if ((ipAddress == ipmi::network::DEFAULT_ADDRESS) ||
233 (gateway == ipmi::network::DEFAULT_ADDRESS) || (!prefix))
Ratan Guptad70f4532017-08-04 02:07:31 +0530234 {
Ratan Guptad70f4532017-08-04 02:07:31 +0530235 rc = -1;
236 return rc;
237 }
238 }
239
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000240 std::string token;
241 std::stringstream ss(MACAddress);
Ratan Guptadcb10672017-07-10 10:33:50 +0530242
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000243 // First pack macOffset no of bytes in payload.
244 // Latter this PetiBoot-Specific data will be populated.
245 std::vector<uint8_t> payloadInitialBytes(macOffset);
246 payload.pack(payloadInitialBytes);
Ratan Guptadcb10672017-07-10 10:33:50 +0530247
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000248 while (std::getline(ss, token, ':'))
249 {
250 payload.pack(stoi(token, nullptr, 16));
251 }
252
253 payload.pack(0x00);
254
255 payload.pack(isStatic);
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530256
Vernon Maueryf442e112019-04-09 11:44:36 -0700257 uint8_t addressFamily = (std::get<std::string>(properties["Type"]) ==
258 "xyz.openbmc_project.Network.IP.Protocol.IPv4")
259 ? AF_INET
260 : AF_INET6;
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530261
Patrick Venture0b02be92018-08-31 11:55:55 -0700262 addrSize = (addressFamily == AF_INET)
263 ? ipmi::network::IPV4_ADDRESS_SIZE_BYTE
264 : ipmi::network::IPV6_ADDRESS_SIZE_BYTE;
Ratan Guptadcb10672017-07-10 10:33:50 +0530265
266 // ipaddress and gateway would be in IPv4 format
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000267 std::vector<uint8_t> addrInBinary(addrSize);
Ratan Guptad70f4532017-08-04 02:07:31 +0530268 inet_pton(addressFamily, ipAddress.c_str(),
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000269 reinterpret_cast<void*>(addrInBinary.data()));
Ratan Guptadcb10672017-07-10 10:33:50 +0530270
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000271 payload.pack(addrInBinary);
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530272
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000273 payload.pack(prefix);
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530274
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000275 std::vector<uint8_t> gatewayDetails(addrSize);
Ratan Guptad70f4532017-08-04 02:07:31 +0530276 inet_pton(addressFamily, gateway.c_str(),
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000277 reinterpret_cast<void*>(gatewayDetails.data()));
278 payload.pack(gatewayDetails);
Ratan Guptadcb10672017-07-10 10:33:50 +0530279 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -0500280 catch (const InternalFailure& e)
Ratan Guptadcb10672017-07-10 10:33:50 +0530281 {
282 commit<InternalFailure>();
Ratan Guptadcb10672017-07-10 10:33:50 +0530283 rc = -1;
Ratan Guptafd28dd72016-08-01 04:58:01 -0500284 return rc;
285 }
286
Patrick Venture0b02be92018-08-31 11:55:55 -0700287 // PetiBoot-Specific
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000288 // If success then copy the first 9 bytes to the payload message
289 // payload first 2 bytes contain the parameter values. Skip that 2 bytes.
290 uint8_t skipFirstTwoBytes = 2;
291 size_t payloadSize = payload.size();
292 uint8_t* configDataStartingAddress = payload.data() + skipFirstTwoBytes;
Ratan Guptafd28dd72016-08-01 04:58:01 -0500293
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000294 if (payloadSize < skipFirstTwoBytes + sizeof(netConfInitialBytes))
295 {
296 log<level::ERR>("Invalid net config ");
297 rc = -1;
298 return rc;
299 }
300 std::copy(netConfInitialBytes,
301 netConfInitialBytes + sizeof(netConfInitialBytes),
302 configDataStartingAddress);
303
304 if (payloadSize < skipFirstTwoBytes + addrSizeOffset + sizeof(addrSize))
305 {
306 log<level::ERR>("Invalid length of address size");
307 rc = -1;
308 return rc;
309 }
310 std::copy(&addrSize, &(addrSize) + sizeof(addrSize),
311 configDataStartingAddress + addrSizeOffset);
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530312
Ratan Guptafd28dd72016-08-01 04:58:01 -0500313#ifdef _IPMI_DEBUG_
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700314 std::printf("\n===Printing the IPMI Formatted Data========\n");
Ratan Guptafd28dd72016-08-01 04:58:01 -0500315
Ratan Guptadcb10672017-07-10 10:33:50 +0530316 for (uint8_t pos = 0; pos < index; pos++)
317 {
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000318 std::printf("%02x ", payloadStartingAddress[pos]);
Ratan Guptadcb10672017-07-10 10:33:50 +0530319 }
Ratan Guptafd28dd72016-08-01 04:58:01 -0500320#endif
321
Ratan Guptafd28dd72016-08-01 04:58:01 -0500322 return rc;
323}
324
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530325/** @brief convert IPv4 and IPv6 addresses from binary to text form.
326 * @param[in] family - IPv4/Ipv6
327 * @param[in] data - req data pointer.
328 * @param[in] offset - offset in the data.
329 * @param[in] addrSize - size of the data which needs to be read from offset.
330 * @returns address in text form.
331 */
332
Patrick Venture0b02be92018-08-31 11:55:55 -0700333std::string getAddrStr(uint8_t family, uint8_t* data, uint8_t offset,
334 uint8_t addrSize)
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530335{
336 char ipAddr[INET6_ADDRSTRLEN] = {};
337
Patrick Venture0b02be92018-08-31 11:55:55 -0700338 switch (family)
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530339 {
340 case AF_INET:
341 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700342 struct sockaddr_in addr4
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -0500343 {};
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700344 std::memcpy(&addr4.sin_addr.s_addr, &data[offset], addrSize);
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530345
Patrick Venture0b02be92018-08-31 11:55:55 -0700346 inet_ntop(AF_INET, &addr4.sin_addr, ipAddr, INET_ADDRSTRLEN);
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530347
348 break;
349 }
350 case AF_INET6:
351 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700352 struct sockaddr_in6 addr6
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -0500353 {};
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700354 std::memcpy(&addr6.sin6_addr.s6_addr, &data[offset], addrSize);
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530355
Patrick Venture0b02be92018-08-31 11:55:55 -0700356 inet_ntop(AF_INET6, &addr6.sin6_addr, ipAddr, INET6_ADDRSTRLEN);
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530357
358 break;
359 }
360 default:
361 {
362 return {};
363 }
364 }
365
366 return ipAddr;
367}
368
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000369ipmi::Cc setHostNetworkData(ipmi::message::Payload& data)
Ratan Guptafd28dd72016-08-01 04:58:01 -0500370{
Ratan Guptadcb10672017-07-10 10:33:50 +0530371 using namespace std::string_literals;
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000372 std::string hostNetworkConfig;
373 std::string mac("00:00:00:00:00:00");
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530374 std::string ipAddress, gateway;
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000375 std::string addrOrigin{0};
Patrick Venture0b02be92018-08-31 11:55:55 -0700376 uint8_t addrSize{0};
Ratan Guptadcb10672017-07-10 10:33:50 +0530377 std::string addressOrigin =
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530378 "xyz.openbmc_project.Network.IP.AddressOrigin.DHCP";
Patrick Venture0b02be92018-08-31 11:55:55 -0700379 std::string addressType = "xyz.openbmc_project.Network.IP.Protocol.IPv4";
380 uint8_t prefix{0};
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530381 uint8_t family = AF_INET;
Ratan Guptafd28dd72016-08-01 04:58:01 -0500382
Patrick Venture0b02be92018-08-31 11:55:55 -0700383 // cookie starts from second byte
Ratan Guptafd28dd72016-08-01 04:58:01 -0500384 // version starts from sixth byte
385
Ratan Guptadcb10672017-07-10 10:33:50 +0530386 try
Ratan Guptafd28dd72016-08-01 04:58:01 -0500387 {
Ratan Guptadcb10672017-07-10 10:33:50 +0530388 do
389 {
390 // cookie == 0x21 0x70 0x62 0x21
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000391 data.trailingOk = true;
392 auto msgLen = data.size();
393 std::vector<uint8_t> msgPayloadBytes(msgLen);
394 if (data.unpack(msgPayloadBytes) != 0 || !data.fullyUnpacked())
Ratan Guptadcb10672017-07-10 10:33:50 +0530395 {
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000396 log<level::ERR>(
397 "Error in unpacking message of setHostNetworkData");
398 return ipmi::ccReqDataLenInvalid;
399 }
400
401 uint8_t* msgPayloadStartingPos = msgPayloadBytes.data();
402 constexpr size_t cookieSize = 4;
403 if (msgLen < cookieOffset + cookieSize)
404 {
405 log<level::ERR>(
406 "Error in cookie getting of setHostNetworkData");
407 return ipmi::ccReqDataLenInvalid;
408 }
409 if (std::equal(msgPayloadStartingPos + cookieOffset,
410 msgPayloadStartingPos + cookieOffset + cookieSize,
411 (netConfInitialBytes + cookieOffset)) != 0)
412 {
413 // all cookie == 0
414 if (std::all_of(msgPayloadStartingPos + cookieOffset,
415 msgPayloadStartingPos + cookieOffset +
416 cookieSize,
417 [](int i) { return i == 0; }) == true)
Ratan Guptadcb10672017-07-10 10:33:50 +0530418 {
419 // need to zero out the network settings.
420 break;
421 }
422
423 log<level::ERR>("Invalid Cookie");
424 elog<InternalFailure>();
425 }
426
427 // vesion == 0x00 0x01
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000428 if (msgLen < versionOffset + sizeVersion)
Ratan Guptadcb10672017-07-10 10:33:50 +0530429 {
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000430 log<level::ERR>(
431 "Error in version getting of setHostNetworkData");
432 return ipmi::ccReqDataLenInvalid;
433 }
434 if (std::equal(msgPayloadStartingPos + versionOffset,
435 msgPayloadStartingPos + versionOffset + sizeVersion,
436 (netConfInitialBytes + versionOffset)) != 0)
437 {
Ratan Guptadcb10672017-07-10 10:33:50 +0530438 log<level::ERR>("Invalid Version");
439 elog<InternalFailure>();
440 }
441
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000442 if (msgLen < macOffset + 6)
443 {
444 log<level::ERR>(
445 "Error in mac address getting of setHostNetworkData");
446 return ipmi::ccReqDataLenInvalid;
447 }
448 std::stringstream result;
449 std::copy((msgPayloadStartingPos + macOffset),
450 (msgPayloadStartingPos + macOffset + 5),
451 std::ostream_iterator<int>(result, ":"));
452 mac = result.str();
Ratan Guptadcb10672017-07-10 10:33:50 +0530453
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000454 if (msgLen < addrTypeOffset + sizeof(decltype(addrOrigin)))
455 {
456 log<level::ERR>(
457 "Error in original address getting of setHostNetworkData");
458 return ipmi::ccReqDataLenInvalid;
459 }
460 std::copy(msgPayloadStartingPos + addrTypeOffset,
461 msgPayloadStartingPos + addrTypeOffset +
462 sizeof(decltype(addrOrigin)),
463 std::ostream_iterator<int>(result, ""));
464 addrOrigin = result.str();
Ratan Guptadcb10672017-07-10 10:33:50 +0530465
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000466 if (!addrOrigin.empty())
Ratan Guptadcb10672017-07-10 10:33:50 +0530467 {
468 addressOrigin =
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530469 "xyz.openbmc_project.Network.IP.AddressOrigin.Static";
Ratan Guptadcb10672017-07-10 10:33:50 +0530470 }
471
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000472 if (msgLen < addrSizeOffset + sizeof(decltype(addrSize)))
473 {
474 log<level::ERR>(
475 "Error in address size getting of setHostNetworkData");
476 return ipmi::ccReqDataLenInvalid;
477 }
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530478 // Get the address size
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000479 std::copy(msgPayloadStartingPos + addrSizeOffset,
480 (msgPayloadStartingPos + addrSizeOffset +
481 sizeof(decltype(addrSize))),
482 &addrSize);
Ratan Guptadcb10672017-07-10 10:33:50 +0530483
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000484 uint8_t prefixOffset = ipAddrOffset + addrSize;
485 if (msgLen < prefixOffset + sizeof(decltype(prefix)))
486 {
487 log<level::ERR>(
488 "Error in prefix getting of setHostNetworkData");
489 return ipmi::ccReqDataLenInvalid;
490 }
William A. Kennington III4c521022023-07-28 13:07:30 -0700491 // std::copy(msgPayloadStartingPos + prefixOffset,
492 // msgPayloadStartingPos + prefixOffset +
493 // sizeof(decltype(prefix)),
494 // &prefix);
495 // Workaround compiler misdetecting out of bounds memcpy
496 prefix = msgPayloadStartingPos[prefixOffset];
Ratan Guptadcb10672017-07-10 10:33:50 +0530497
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530498 uint8_t gatewayOffset = prefixOffset + sizeof(decltype(prefix));
Ratan Gupta8c31d232017-08-13 05:49:43 +0530499 if (addrSize != ipmi::network::IPV4_ADDRESS_SIZE_BYTE)
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530500 {
501 addressType = "xyz.openbmc_project.Network.IP.Protocol.IPv6";
502 family = AF_INET6;
503 }
504
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000505 if (msgLen < ipAddrOffset + addrSize)
506 {
507 log<level::ERR>(
508 "Error in IP address getting of setHostNetworkData");
509 return ipmi::ccReqDataLenInvalid;
510 }
511 ipAddress = getAddrStr(family, msgPayloadStartingPos, ipAddrOffset,
512 addrSize);
Ratan Guptad70f4532017-08-04 02:07:31 +0530513
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000514 if (msgLen < gatewayOffset + addrSize)
515 {
516 log<level::ERR>(
517 "Error in gateway address getting of setHostNetworkData");
518 return ipmi::ccReqDataLenInvalid;
519 }
520 gateway = getAddrStr(family, msgPayloadStartingPos, gatewayOffset,
521 addrSize);
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530522
Patrick Venture0b02be92018-08-31 11:55:55 -0700523 } while (0);
Ratan Guptadcb10672017-07-10 10:33:50 +0530524
Patrick Venture0b02be92018-08-31 11:55:55 -0700525 // Cookie == 0 or it is a valid cookie
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000526 hostNetworkConfig += "ipaddress="s + ipAddress + ",prefix="s +
527 std::to_string(prefix) + ",gateway="s + gateway +
528 ",mac="s + mac + ",addressOrigin="s +
529 addressOrigin;
Ratan Guptafd28dd72016-08-01 04:58:01 -0500530
Patrick Williams5d82f472022-07-22 19:26:53 -0500531 sdbusplus::bus_t bus(ipmid_get_sd_bus_connection());
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530532
533 auto ipObjectInfo = ipmi::getDbusObject(bus, IP_INTERFACE,
534 SETTINGS_ROOT, SETTINGS_MATCH);
535 auto macObjectInfo = ipmi::getDbusObject(bus, MAC_INTERFACE,
536 SETTINGS_ROOT, SETTINGS_MATCH);
Ratan Guptadcb10672017-07-10 10:33:50 +0530537 // set the dbus property
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530538 ipmi::setDbusProperty(bus, ipObjectInfo.second, ipObjectInfo.first,
Patrick Venture0b02be92018-08-31 11:55:55 -0700539 IP_INTERFACE, "Address", std::string(ipAddress));
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530540 ipmi::setDbusProperty(bus, ipObjectInfo.second, ipObjectInfo.first,
Patrick Venture0b02be92018-08-31 11:55:55 -0700541 IP_INTERFACE, "PrefixLength", prefix);
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530542 ipmi::setDbusProperty(bus, ipObjectInfo.second, ipObjectInfo.first,
Patrick Venture0b02be92018-08-31 11:55:55 -0700543 IP_INTERFACE, "Origin", addressOrigin);
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530544 ipmi::setDbusProperty(bus, ipObjectInfo.second, ipObjectInfo.first,
Patrick Venture0b02be92018-08-31 11:55:55 -0700545 IP_INTERFACE, "Gateway", std::string(gateway));
546 ipmi::setDbusProperty(
547 bus, ipObjectInfo.second, ipObjectInfo.first, IP_INTERFACE, "Type",
548 std::string("xyz.openbmc_project.Network.IP.Protocol.IPv4"));
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530549 ipmi::setDbusProperty(bus, macObjectInfo.second, macObjectInfo.first,
Patrick Venture0b02be92018-08-31 11:55:55 -0700550 MAC_INTERFACE, "MACAddress", std::string(mac));
Ratan Guptafd28dd72016-08-01 04:58:01 -0500551
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000552 log<level::DEBUG>("Network configuration changed",
553 entry("NETWORKCONFIG=%s", hostNetworkConfig.c_str()));
Ratan Guptafd28dd72016-08-01 04:58:01 -0500554 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -0500555 catch (const sdbusplus::exception_t& e)
Ratan Guptadcb10672017-07-10 10:33:50 +0530556 {
557 commit<InternalFailure>();
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000558 log<level::ERR>("Error in ipmiChassisSetSysBootOptions call");
559 return ipmi::ccUnspecifiedError;
Ratan Guptadcb10672017-07-10 10:33:50 +0530560 }
561
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000562 return ipmi::ccSuccess;
Ratan Guptafd28dd72016-08-01 04:58:01 -0500563}
564
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -0500565uint32_t getPOHCounter()
566{
Patrick Williams5d82f472022-07-22 19:26:53 -0500567 sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()};
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -0500568
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -0500569 auto chassisStateObj = ipmi::getDbusObject(bus, chassisPOHStateIntf,
570 chassisStateRoot, match);
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -0500571
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -0500572 auto service = ipmi::getService(bus, chassisPOHStateIntf,
573 chassisStateObj.first);
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -0500574
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -0500575 auto propValue = ipmi::getDbusProperty(bus, service, chassisStateObj.first,
576 chassisPOHStateIntf,
577 pohCounterProperty);
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -0500578
Vernon Maueryf442e112019-04-09 11:44:36 -0700579 return std::get<uint32_t>(propValue);
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -0500580}
581
anil kumar appana43263c62019-05-27 12:45:04 +0000582/** @brief Implements the get chassis capabilities command
583 *
584 * @returns IPMI completion code plus response data
585 * chassisCapFlags - chassis capability flag
586 * chassisFRUInfoDevAddr - chassis FRU info Device Address
587 * chassisSDRDevAddr - chassis SDR device address
588 * chassisSELDevAddr - chassis SEL device address
589 * chassisSMDevAddr - chassis system management device address
590 * chassisBridgeDevAddr - chassis bridge device address
591 */
Karthick Sundarrajan86d8bd72019-11-26 12:48:50 -0800592ipmi::RspType<bool, // chassis intrusion sensor
593 bool, // chassis Front panel lockout
594 bool, // chassis NMI
595 bool, // chassis power interlock
596 uint4_t, // reserved
anil kumar appana43263c62019-05-27 12:45:04 +0000597 uint8_t, // chassis FRU info Device Address
598 uint8_t, // chassis SDR device address
599 uint8_t, // chassis SEL device address
600 uint8_t, // chassis system management device address
601 uint8_t // chassis bridge device address
602 >
603 ipmiGetChassisCap()
Nan Li8d15fb42016-08-16 22:29:40 +0800604{
anil kumar appana43263c62019-05-27 12:45:04 +0000605 ipmi::PropertyMap properties;
Yong Liae4b0402018-11-02 11:12:14 +0800606 try
607 {
Patrick Williams5d82f472022-07-22 19:26:53 -0500608 sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()};
Nan Li8d15fb42016-08-16 22:29:40 +0800609
Yong Liae4b0402018-11-02 11:12:14 +0800610 ipmi::DbusObjectInfo chassisCapObject =
611 ipmi::getDbusObject(bus, chassisCapIntf);
Nan Li8d15fb42016-08-16 22:29:40 +0800612
Yong Liae4b0402018-11-02 11:12:14 +0800613 // capabilities flags
614 // [7..4] - reserved
615 // [3] – 1b = provides power interlock (IPM 1.5)
616 // [2] – 1b = provides Diagnostic Interrupt (FP NMI)
617 // [1] – 1b = provides “Front Panel Lockout” (indicates that the chassis
618 // has capabilities
619 // to lock out external power control and reset button or
620 // front panel interfaces and/or detect tampering with those
621 // interfaces).
622 // [0] -1b = Chassis provides intrusion (physical security) sensor.
623 // set to default value 0x0.
Nan Li8d15fb42016-08-16 22:29:40 +0800624
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -0500625 properties = ipmi::getAllDbusProperties(bus, chassisCapObject.second,
626 chassisCapObject.first,
627 chassisCapIntf);
Yong Liae4b0402018-11-02 11:12:14 +0800628 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -0500629 catch (const std::exception& e)
Yong Liae4b0402018-11-02 11:12:14 +0800630 {
anil kumar appana43263c62019-05-27 12:45:04 +0000631 log<level::ERR>("Failed to fetch Chassis Capability properties",
632 entry("ERROR=%s", e.what()));
633 return ipmi::responseUnspecifiedError();
Yong Liae4b0402018-11-02 11:12:14 +0800634 }
635
Karthick Sundarrajan86d8bd72019-11-26 12:48:50 -0800636 bool* chassisIntrusionFlag =
637 std::get_if<bool>(&properties[chassisIntrusionProp]);
638 if (chassisIntrusionFlag == nullptr)
anil kumar appana43263c62019-05-27 12:45:04 +0000639 {
Karthick Sundarrajan86d8bd72019-11-26 12:48:50 -0800640 log<level::ERR>("Error to get chassis Intrusion flags");
641 return ipmi::responseUnspecifiedError();
642 }
643 bool* chassisFrontPanelFlag =
644 std::get_if<bool>(&properties[chassisFrontPanelLockoutProp]);
645 if (chassisFrontPanelFlag == nullptr)
646 {
647 log<level::ERR>("Error to get chassis intrusion flags");
648 return ipmi::responseUnspecifiedError();
649 }
650 bool* chassisNMIFlag = std::get_if<bool>(&properties[chassisNMIProp]);
651 if (chassisNMIFlag == nullptr)
652 {
653 log<level::ERR>("Error to get chassis NMI flags");
654 return ipmi::responseUnspecifiedError();
655 }
656 bool* chassisPowerInterlockFlag =
657 std::get_if<bool>(&properties[chassisPowerInterlockProp]);
658 if (chassisPowerInterlockFlag == nullptr)
659 {
660 log<level::ERR>("Error to get chassis power interlock flags");
anil kumar appana43263c62019-05-27 12:45:04 +0000661 return ipmi::responseUnspecifiedError();
662 }
663 uint8_t* chassisFRUInfoDevAddr =
664 std::get_if<uint8_t>(&properties[chassisFRUDevAddrProp]);
665 if (chassisFRUInfoDevAddr == nullptr)
666 {
667 log<level::ERR>("Error to get chassis FRU info device address");
668 return ipmi::responseUnspecifiedError();
669 }
670 uint8_t* chassisSDRDevAddr =
671 std::get_if<uint8_t>(&properties[chassisSDRDevAddrProp]);
672 if (chassisSDRDevAddr == nullptr)
673 {
674 log<level::ERR>("Error to get chassis SDR device address");
675 return ipmi::responseUnspecifiedError();
676 }
677 uint8_t* chassisSELDevAddr =
678 std::get_if<uint8_t>(&properties[chassisSELDevAddrProp]);
679 if (chassisSELDevAddr == nullptr)
680 {
681 log<level::ERR>("Error to get chassis SEL device address");
682 return ipmi::responseUnspecifiedError();
683 }
684 uint8_t* chassisSMDevAddr =
685 std::get_if<uint8_t>(&properties[chassisSMDevAddrProp]);
686 if (chassisSMDevAddr == nullptr)
687 {
688 log<level::ERR>("Error to get chassis SM device address");
689 return ipmi::responseUnspecifiedError();
690 }
691 uint8_t* chassisBridgeDevAddr =
692 std::get_if<uint8_t>(&properties[chassisBridgeDevAddrProp]);
693 if (chassisBridgeDevAddr == nullptr)
694 {
695 log<level::ERR>("Error to get chassis bridge device address");
696 return ipmi::responseUnspecifiedError();
697 }
698
Karthick Sundarrajan86d8bd72019-11-26 12:48:50 -0800699 return ipmi::responseSuccess(*chassisIntrusionFlag, *chassisFrontPanelFlag,
700 *chassisNMIFlag, *chassisPowerInterlockFlag, 0,
701 *chassisFRUInfoDevAddr, *chassisSDRDevAddr,
702 *chassisSELDevAddr, *chassisSMDevAddr,
703 *chassisBridgeDevAddr);
Yong Liae4b0402018-11-02 11:12:14 +0800704}
705
anil kumar appana894d0222019-05-27 16:32:14 +0000706/** @brief implements set chassis capalibities command
707 * @param intrusion - chassis intrusion
708 * @param fpLockout - frontpannel lockout
709 * @param reserved1 - skip one bit
710 * @param fruDeviceAddr - chassis FRU info Device Address
711 * @param sdrDeviceAddr - chassis SDR device address
712 * @param selDeviceAddr - chassis SEL device address
713 * @param smDeviceAddr - chassis system management device address
714 * @param bridgeDeviceAddr - chassis bridge device address
715 *
716 * @returns IPMI completion code
717 */
718ipmi::RspType<> ipmiSetChassisCap(bool intrusion, bool fpLockout,
719 uint6_t reserved1,
720
721 uint8_t fruDeviceAddr,
722
723 uint8_t sdrDeviceAddr,
724
725 uint8_t selDeviceAddr,
726
727 uint8_t smDeviceAddr,
728
729 uint8_t bridgeDeviceAddr)
Yong Liae4b0402018-11-02 11:12:14 +0800730{
Yong Liae4b0402018-11-02 11:12:14 +0800731 // check input data
anil kumar appana894d0222019-05-27 16:32:14 +0000732 if (reserved1 != 0)
Yong Liae4b0402018-11-02 11:12:14 +0800733 {
anil kumar appana894d0222019-05-27 16:32:14 +0000734 log<level::ERR>("Unsupported request parameter");
735 return ipmi::responseInvalidFieldRequest();
Yong Liae4b0402018-11-02 11:12:14 +0800736 }
737
anil kumar appana894d0222019-05-27 16:32:14 +0000738 if ((fruDeviceAddr & ~chassisCapAddrMask) != 0)
Yong Liae4b0402018-11-02 11:12:14 +0800739 {
740 log<level::ERR>("Unsupported request parameter(FRU Addr)",
anil kumar appana894d0222019-05-27 16:32:14 +0000741 entry("REQ=0x%x", fruDeviceAddr));
742 return ipmi::responseInvalidFieldRequest();
Yong Liae4b0402018-11-02 11:12:14 +0800743 }
anil kumar appana894d0222019-05-27 16:32:14 +0000744 if ((sdrDeviceAddr & ~chassisCapAddrMask) != 0)
Yong Liae4b0402018-11-02 11:12:14 +0800745 {
746 log<level::ERR>("Unsupported request parameter(SDR Addr)",
anil kumar appana894d0222019-05-27 16:32:14 +0000747 entry("REQ=0x%x", sdrDeviceAddr));
748 return ipmi::responseInvalidFieldRequest();
Yong Liae4b0402018-11-02 11:12:14 +0800749 }
750
anil kumar appana894d0222019-05-27 16:32:14 +0000751 if ((selDeviceAddr & ~chassisCapAddrMask) != 0)
Yong Liae4b0402018-11-02 11:12:14 +0800752 {
753 log<level::ERR>("Unsupported request parameter(SEL Addr)",
anil kumar appana894d0222019-05-27 16:32:14 +0000754 entry("REQ=0x%x", selDeviceAddr));
755 return ipmi::responseInvalidFieldRequest();
Yong Liae4b0402018-11-02 11:12:14 +0800756 }
757
anil kumar appana894d0222019-05-27 16:32:14 +0000758 if ((smDeviceAddr & ~chassisCapAddrMask) != 0)
Yong Liae4b0402018-11-02 11:12:14 +0800759 {
anil kumar appana894d0222019-05-27 16:32:14 +0000760 log<level::ERR>("Unsupported request parameter(SM Addr)",
761 entry("REQ=0x%x", smDeviceAddr));
762 return ipmi::responseInvalidFieldRequest();
Yong Liae4b0402018-11-02 11:12:14 +0800763 }
764
anil kumar appana894d0222019-05-27 16:32:14 +0000765 if ((bridgeDeviceAddr & ~chassisCapAddrMask) != 0)
Yong Liae4b0402018-11-02 11:12:14 +0800766 {
767 log<level::ERR>("Unsupported request parameter(Bridge Addr)",
anil kumar appana894d0222019-05-27 16:32:14 +0000768 entry("REQ=0x%x", bridgeDeviceAddr));
769 return ipmi::responseInvalidFieldRequest();
Yong Liae4b0402018-11-02 11:12:14 +0800770 }
771
772 try
773 {
Patrick Williams5d82f472022-07-22 19:26:53 -0500774 sdbusplus::bus_t bus(ipmid_get_sd_bus_connection());
Yong Liae4b0402018-11-02 11:12:14 +0800775 ipmi::DbusObjectInfo chassisCapObject =
776 ipmi::getDbusObject(bus, chassisCapIntf);
777
778 ipmi::setDbusProperty(bus, chassisCapObject.second,
779 chassisCapObject.first, chassisCapIntf,
Karthick Sundarrajan86d8bd72019-11-26 12:48:50 -0800780 chassisIntrusionProp, intrusion);
781
782 ipmi::setDbusProperty(bus, chassisCapObject.second,
783 chassisCapObject.first, chassisCapIntf,
784 chassisFrontPanelLockoutProp, fpLockout);
Yong Liae4b0402018-11-02 11:12:14 +0800785
786 ipmi::setDbusProperty(bus, chassisCapObject.second,
787 chassisCapObject.first, chassisCapIntf,
anil kumar appana894d0222019-05-27 16:32:14 +0000788 chassisFRUDevAddrProp, fruDeviceAddr);
Yong Liae4b0402018-11-02 11:12:14 +0800789
790 ipmi::setDbusProperty(bus, chassisCapObject.second,
791 chassisCapObject.first, chassisCapIntf,
anil kumar appana894d0222019-05-27 16:32:14 +0000792 chassisSDRDevAddrProp, sdrDeviceAddr);
Yong Liae4b0402018-11-02 11:12:14 +0800793
794 ipmi::setDbusProperty(bus, chassisCapObject.second,
795 chassisCapObject.first, chassisCapIntf,
anil kumar appana894d0222019-05-27 16:32:14 +0000796 chassisSELDevAddrProp, selDeviceAddr);
Yong Liae4b0402018-11-02 11:12:14 +0800797
798 ipmi::setDbusProperty(bus, chassisCapObject.second,
799 chassisCapObject.first, chassisCapIntf,
anil kumar appana894d0222019-05-27 16:32:14 +0000800 chassisSMDevAddrProp, smDeviceAddr);
Yong Liae4b0402018-11-02 11:12:14 +0800801
802 ipmi::setDbusProperty(bus, chassisCapObject.second,
803 chassisCapObject.first, chassisCapIntf,
anil kumar appana894d0222019-05-27 16:32:14 +0000804 chassisBridgeDevAddrProp, bridgeDeviceAddr);
Yong Liae4b0402018-11-02 11:12:14 +0800805 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -0500806 catch (const std::exception& e)
Yong Liae4b0402018-11-02 11:12:14 +0800807 {
808 log<level::ERR>(e.what());
anil kumar appana894d0222019-05-27 16:32:14 +0000809 return ipmi::responseUnspecifiedError();
Yong Liae4b0402018-11-02 11:12:14 +0800810 }
anil kumar appana894d0222019-05-27 16:32:14 +0000811 return ipmi::responseSuccess();
Nan Li8d15fb42016-08-16 22:29:40 +0800812}
813
Vishwanatha Subbannab12b0c02017-03-07 18:17:19 +0530814//------------------------------------------
815// Calls into Host State Manager Dbus object
816//------------------------------------------
Jason M. Bills664e1c32020-01-30 16:02:39 -0800817int initiateHostStateTransition(ipmi::Context::ptr& ctx,
818 State::Host::Transition transition)
vishwa36993272015-11-20 12:43:49 -0600819{
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500820 // OpenBMC Host State Manager dbus framework
Jason M. Bills664e1c32020-01-30 16:02:39 -0800821 constexpr auto hostStatePath = "/xyz/openbmc_project/state/host0";
822 constexpr auto hostStateIntf = "xyz.openbmc_project.State.Host";
Vishwanatha Subbannab12b0c02017-03-07 18:17:19 +0530823
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500824 // Convert to string equivalent of the passed in transition enum.
Willy Tu523e2d12023-09-05 11:36:48 -0700825 auto request =
826 sdbusplus::common::xyz::openbmc_project::state::convertForMessage(
827 transition);
Vishwanatha Subbannab12b0c02017-03-07 18:17:19 +0530828
Jason M. Bills664e1c32020-01-30 16:02:39 -0800829 std::string service;
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -0500830 boost::system::error_code ec = ipmi::getService(ctx, hostStateIntf,
831 hostStatePath, service);
Jason M. Bills664e1c32020-01-30 16:02:39 -0800832
833 if (!ec)
834 {
835 ec = ipmi::setDbusProperty(ctx, service, hostStatePath, hostStateIntf,
836 "RequestedHostTransition", request);
837 }
838 if (ec)
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500839 {
840 log<level::ERR>("Failed to initiate transition",
Jason M. Bills664e1c32020-01-30 16:02:39 -0800841 entry("EXCEPTION=%s, REQUEST=%s", ec.message().c_str(),
842 request.c_str()));
843 return -1;
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500844 }
Jason M. Bills664e1c32020-01-30 16:02:39 -0800845 log<level::INFO>(
846 "Transition request initiated successfully",
847 entry("USERID=%d, REQUEST=%s", ctx->userId, request.c_str()));
848 return 0;
vishwa36993272015-11-20 12:43:49 -0600849}
850
Kuiying Wang6b0ceaa2019-11-05 15:13:40 +0800851//------------------------------------------
Jason M. Billsad588bf2020-01-30 16:18:33 -0800852// Calls into Chassis State Manager Dbus object
853//------------------------------------------
854int initiateChassisStateTransition(ipmi::Context::ptr& ctx,
855 State::Chassis::Transition transition)
856{
857 // OpenBMC Chassis State Manager dbus framework
858 constexpr auto chassisStatePath = "/xyz/openbmc_project/state/chassis0";
859 constexpr auto chassisStateIntf = "xyz.openbmc_project.State.Chassis";
860
861 std::string service;
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -0500862 boost::system::error_code ec = ipmi::getService(ctx, chassisStateIntf,
863 chassisStatePath, service);
Jason M. Billsad588bf2020-01-30 16:18:33 -0800864
865 // Convert to string equivalent of the passed in transition enum.
Willy Tu523e2d12023-09-05 11:36:48 -0700866 auto request =
867 sdbusplus::common::xyz::openbmc_project::state::convertForMessage(
868 transition);
Jason M. Billsad588bf2020-01-30 16:18:33 -0800869
870 if (!ec)
871 {
872 ec = ipmi::setDbusProperty(ctx, service, chassisStatePath,
873 chassisStateIntf, "RequestedPowerTransition",
874 request);
875 }
876 if (ec)
877 {
878 log<level::ERR>("Failed to initiate transition",
879 entry("EXCEPTION=%s, REQUEST=%s", ec.message().c_str(),
880 request.c_str()));
881 return -1;
882 }
883
884 return 0;
885}
886
887//------------------------------------------
Zev Weiss337a0972024-03-08 08:31:15 +0000888// Trigger an NMI on the host via dbus
Kuiying Wang6b0ceaa2019-11-05 15:13:40 +0800889//------------------------------------------
Zev Weiss337a0972024-03-08 08:31:15 +0000890static int doNmi(ipmi::Context::ptr& ctx)
Kuiying Wang6b0ceaa2019-11-05 15:13:40 +0800891{
Zev Weiss337a0972024-03-08 08:31:15 +0000892 constexpr const char* nmiIntfName = "xyz.openbmc_project.Control.Host.NMI";
893 ipmi::DbusObjectInfo nmiObj{};
894 boost::system::error_code ec;
Kuiying Wang6b0ceaa2019-11-05 15:13:40 +0800895
Zev Weiss337a0972024-03-08 08:31:15 +0000896 ec = ipmi::getDbusObject(ctx, nmiIntfName, nmiObj);
Vernon Mauery9bb4a382021-11-05 12:46:19 -0700897 if (ec)
Kuiying Wang6b0ceaa2019-11-05 15:13:40 +0800898 {
Zev Weiss337a0972024-03-08 08:31:15 +0000899 log<level::ERR>("Failed to find NMI service",
900 entry("ERROR=%s", ec.message().c_str()));
901 return -1;
902 }
903
904 ctx->bus->yield_method_call<void>(ctx->yield, ec, nmiObj.second,
905 nmiObj.first, nmiIntfName, "NMI");
906 if (ec)
907 {
908 log<level::ERR>("NMI call failed",
909 entry("ERROR=%s", ec.message().c_str()));
910 elog<InternalFailure>();
Kuiying Wang6b0ceaa2019-11-05 15:13:40 +0800911 return -1;
912 }
913
914 return 0;
915}
916
Deepak Kodihalli18b70d12017-07-21 13:36:33 -0500917namespace power_policy
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500918{
Nan Lifdd8ec52016-08-28 03:57:40 +0800919
Willy Tu523e2d12023-09-05 11:36:48 -0700920using namespace sdbusplus::server::xyz::openbmc_project::control::power;
Deepak Kodihalli18b70d12017-07-21 13:36:33 -0500921using IpmiValue = uint8_t;
922using DbusValue = RestorePolicy::Policy;
Nan Lifdd8ec52016-08-28 03:57:40 +0800923
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700924const std::map<DbusValue, IpmiValue> dbusToIpmi = {
Deepak Kodihalli18b70d12017-07-21 13:36:33 -0500925 {RestorePolicy::Policy::AlwaysOff, 0x00},
926 {RestorePolicy::Policy::Restore, 0x01},
George Liue561d3e2024-02-04 15:19:30 +0800927 {RestorePolicy::Policy::AlwaysOn, 0x02},
928 {RestorePolicy::Policy::None, 0x03}};
Nan Lifdd8ec52016-08-28 03:57:40 +0800929
Yong Lic6713cf2018-09-12 12:35:13 +0800930static constexpr uint8_t noChange = 0x03;
931static constexpr uint8_t allSupport = 0x01 | 0x02 | 0x04;
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700932
933/* helper function for Get Chassis Status Command
934 */
935std::optional<uint2_t> getPowerRestorePolicy()
936{
937 uint2_t restorePolicy = 0;
938 using namespace chassis::internal;
939
James Feist225dec82019-11-26 16:25:06 -0800940 settings::Objects& objects = cache::getObjects();
941
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700942 try
943 {
944 const auto& powerRestoreSetting =
James Feist225dec82019-11-26 16:25:06 -0800945 objects.map.at(powerRestoreIntf).front();
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700946 ipmi::Value result = ipmi::getDbusProperty(
947 *getSdBus(),
James Feist225dec82019-11-26 16:25:06 -0800948 objects.service(powerRestoreSetting, powerRestoreIntf).c_str(),
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700949 powerRestoreSetting.c_str(), powerRestoreIntf,
950 "PowerRestorePolicy");
951 auto powerRestore = RestorePolicy::convertPolicyFromString(
952 std::get<std::string>(result));
953 restorePolicy = dbusToIpmi.at(powerRestore);
954 }
955 catch (const std::exception& e)
956 {
957 log<level::ERR>(
958 "Failed to fetch pgood property", entry("ERROR=%s", e.what()),
James Feist225dec82019-11-26 16:25:06 -0800959 entry("PATH=%s", objects.map.at(powerRestoreIntf).front().c_str()),
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700960 entry("INTERFACE=%s", powerRestoreIntf));
James Feist225dec82019-11-26 16:25:06 -0800961 cache::objectsPtr.reset();
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700962 return std::nullopt;
963 }
964 return std::make_optional(restorePolicy);
965}
966
967/*
968 * getPowerStatus
969 * helper function for Get Chassis Status Command
970 * return - optional value for pgood (no value on error)
971 */
972std::optional<bool> getPowerStatus()
973{
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700974 bool powerGood = false;
975 std::shared_ptr<sdbusplus::asio::connection> busp = getSdBus();
976 try
977 {
Jason M. Bills3de424c2019-05-21 09:57:16 -0700978 constexpr const char* chassisStatePath =
979 "/xyz/openbmc_project/state/chassis0";
980 constexpr const char* chassisStateIntf =
981 "xyz.openbmc_project.State.Chassis";
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -0500982 auto service = ipmi::getService(*busp, chassisStateIntf,
983 chassisStatePath);
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700984
Jason M. Bills3de424c2019-05-21 09:57:16 -0700985 ipmi::Value powerState =
986 ipmi::getDbusProperty(*busp, service, chassisStatePath,
987 chassisStateIntf, "CurrentPowerState");
988 powerGood = std::get<std::string>(powerState) ==
989 "xyz.openbmc_project.State.Chassis.PowerState.On";
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700990 }
991 catch (const std::exception& e)
992 {
993 try
994 {
995 // FIXME: some legacy modules use the older path; try that next
996 constexpr const char* legacyPwrCtrlObj =
997 "/org/openbmc/control/power0";
998 constexpr const char* legacyPwrCtrlIntf =
999 "org.openbmc.control.Power";
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05001000 auto service = ipmi::getService(*busp, legacyPwrCtrlIntf,
1001 legacyPwrCtrlObj);
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001002
1003 ipmi::Value variant = ipmi::getDbusProperty(
1004 *busp, service, legacyPwrCtrlObj, legacyPwrCtrlIntf, "pgood");
1005 powerGood = static_cast<bool>(std::get<int>(variant));
1006 }
1007 catch (const std::exception& e)
1008 {
1009 log<level::ERR>("Failed to fetch pgood property",
Jason M. Bills3de424c2019-05-21 09:57:16 -07001010 entry("ERROR=%s", e.what()));
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001011 return std::nullopt;
1012 }
1013 }
1014 return std::make_optional(powerGood);
1015}
1016
Yong Li70ce7352019-05-16 21:15:27 +08001017/*
1018 * getACFailStatus
1019 * helper function for Get Chassis Status Command
1020 * return - bool value for ACFail (false on error)
1021 */
1022bool getACFailStatus()
1023{
1024 constexpr const char* powerControlObj =
1025 "/xyz/openbmc_project/Chassis/Control/Power0";
1026 constexpr const char* powerControlIntf =
1027 "xyz.openbmc_project.Chassis.Control.Power";
1028 bool acFail = false;
1029 std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus();
1030 try
1031 {
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05001032 auto service = ipmi::getService(*bus, powerControlIntf,
1033 powerControlObj);
Yong Li70ce7352019-05-16 21:15:27 +08001034
1035 ipmi::Value variant = ipmi::getDbusProperty(
1036 *bus, service, powerControlObj, powerControlIntf, "PFail");
1037 acFail = std::get<bool>(variant);
1038 }
1039 catch (const std::exception& e)
1040 {
1041 log<level::ERR>("Failed to fetch PFail property",
1042 entry("ERROR=%s", e.what()),
1043 entry("PATH=%s", powerControlObj),
1044 entry("INTERFACE=%s", powerControlIntf));
1045 }
1046 return acFail;
1047}
Deepak Kodihalli18b70d12017-07-21 13:36:33 -05001048} // namespace power_policy
Nan Lifdd8ec52016-08-28 03:57:40 +08001049
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001050static std::optional<bool> getButtonEnabled(const std::string& buttonPath,
1051 const std::string& buttonIntf)
1052{
1053 std::shared_ptr<sdbusplus::asio::connection> busp = getSdBus();
1054 bool buttonDisabled = false;
1055 try
1056 {
1057 auto service = ipmi::getService(*busp, buttonIntf, buttonPath);
1058 ipmi::Value enabled = ipmi::getDbusProperty(*busp, service, buttonPath,
1059 buttonIntf, "Enabled");
1060 buttonDisabled = !std::get<bool>(enabled);
1061 }
Patrick Williams5d82f472022-07-22 19:26:53 -05001062 catch (const sdbusplus::exception_t& e)
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001063 {
1064 log<level::ERR>("Fail to get button Enabled property",
1065 entry("PATH=%s", buttonPath.c_str()),
1066 entry("ERROR=%s", e.what()));
1067 return std::nullopt;
1068 }
1069 return std::make_optional(buttonDisabled);
1070}
1071
Kuiying Wang21addc52019-01-04 10:50:21 +08001072static bool setButtonEnabled(ipmi::Context::ptr& ctx,
1073 const std::string& buttonPath,
1074 const std::string& buttonIntf, bool enable)
1075{
1076 std::string service;
1077 boost::system::error_code ec;
1078 ec = ipmi::getService(ctx, buttonIntf, buttonPath, service);
1079 if (!ec)
1080 {
1081 ec = ipmi::setDbusProperty(ctx, service, buttonPath, buttonIntf,
1082 "Enabled", enable);
1083 }
1084 if (ec)
1085 {
1086 log<level::ERR>("Fail to set button Enabled property",
1087 entry("SERVICE=%s", service.c_str()),
1088 entry("PATH=%s", buttonPath.c_str()),
1089 entry("ERROR=%s", ec.message().c_str()));
1090 return false;
1091 }
1092 return true;
1093}
1094
Chau Ly9e666cd2023-03-06 08:46:14 +00001095static std::optional<bool> getChassisIntrusionStatus(ipmi::Context::ptr& ctx)
1096{
1097 constexpr const char* chassisIntrusionPath =
1098 "/xyz/openbmc_project/Chassis/Intrusion";
1099 constexpr const char* chassisIntrusionInf =
1100 "xyz.openbmc_project.Chassis.Intrusion";
1101
1102 std::string service;
1103 boost::system::error_code ec = ipmi::getService(
1104 ctx, chassisIntrusionInf, chassisIntrusionPath, service);
1105 if (!ec)
1106 {
1107 std::string chassisIntrusionStr;
1108 ec = ipmi::getDbusProperty<std::string>(
1109 ctx, service, chassisIntrusionPath, chassisIntrusionInf, "Status",
1110 chassisIntrusionStr);
1111 if (!ec)
1112 {
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05001113 bool ret = (chassisIntrusionStr == "HardwareIntrusion") ? true
1114 : false;
Chau Ly9e666cd2023-03-06 08:46:14 +00001115 return std::make_optional(ret);
1116 }
1117 }
1118 log<level::ERR>("Fail to get Chassis Intrusion Status property",
1119 entry("PATH=%s", chassisIntrusionPath),
1120 entry("INTERFACE=%s", chassisIntrusionInf),
1121 entry("ERROR=%s", ec.message().c_str()));
1122 return std::nullopt;
1123}
1124
Nan Lifdd8ec52016-08-28 03:57:40 +08001125//----------------------------------------------------------------------
1126// Get Chassis Status commands
1127//----------------------------------------------------------------------
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001128ipmi::RspType<bool, // Power is on
1129 bool, // Power overload
1130 bool, // Interlock
1131 bool, // power fault
1132 bool, // power control fault
1133 uint2_t, // power restore policy
1134 bool, // reserved
1135
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05001136 bool, // AC failed
1137 bool, // last power down caused by a Power overload
1138 bool, // last power down caused by a power interlock
1139 bool, // last power down caused by power fault
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001140 bool, // last ‘Power is on’ state was entered via IPMI command
1141 uint3_t, // reserved
1142
1143 bool, // Chassis intrusion active
1144 bool, // Front Panel Lockout active
1145 bool, // Drive Fault
1146 bool, // Cooling/fan fault detected
1147 uint2_t, // Chassis Identify State
1148 bool, // Chassis Identify command and state info supported
1149 bool, // reserved
1150
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05001151 bool, // Power off button disabled
1152 bool, // Reset button disabled
1153 bool, // Diagnostic Interrupt button disabled
1154 bool, // Standby (sleep) button disabled
1155 bool, // Power off button disable allowed
1156 bool, // Reset button disable allowed
1157 bool, // Diagnostic Interrupt button disable allowed
1158 bool // Standby (sleep) button disable allowed
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001159 >
Chau Ly9e666cd2023-03-06 08:46:14 +00001160 ipmiGetChassisStatus(ipmi::Context::ptr& ctx)
Nan Lifdd8ec52016-08-28 03:57:40 +08001161{
Deepak Kodihalli18b70d12017-07-21 13:36:33 -05001162 using namespace chassis::internal;
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001163 std::optional<uint2_t> restorePolicy =
1164 power_policy::getPowerRestorePolicy();
1165 std::optional<bool> powerGood = power_policy::getPowerStatus();
1166 if (!restorePolicy || !powerGood)
Deepak Kodihalli18b70d12017-07-21 13:36:33 -05001167 {
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001168 return ipmi::responseUnspecifiedError();
Deepak Kodihalli18b70d12017-07-21 13:36:33 -05001169 }
Nan Lifdd8ec52016-08-28 03:57:40 +08001170
1171 // Front Panel Button Capabilities and disable/enable status(Optional)
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05001172 std::optional<bool> powerButtonReading = getButtonEnabled(powerButtonPath,
1173 powerButtonIntf);
Vernon Mauery6d5b2f72019-05-16 14:48:47 -07001174 // allow disable if the interface is present
1175 bool powerButtonDisableAllow = static_cast<bool>(powerButtonReading);
1176 // default return the button is enabled (not disabled)
1177 bool powerButtonDisabled = false;
1178 if (powerButtonDisableAllow)
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001179 {
Vernon Mauery6d5b2f72019-05-16 14:48:47 -07001180 // return the real value of the button status, if present
1181 powerButtonDisabled = *powerButtonReading;
1182 }
1183
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05001184 std::optional<bool> resetButtonReading = getButtonEnabled(resetButtonPath,
1185 resetButtonIntf);
Vernon Mauery6d5b2f72019-05-16 14:48:47 -07001186 // allow disable if the interface is present
1187 bool resetButtonDisableAllow = static_cast<bool>(resetButtonReading);
1188 // default return the button is enabled (not disabled)
1189 bool resetButtonDisabled = false;
1190 if (resetButtonDisableAllow)
1191 {
1192 // return the real value of the button status, if present
1193 resetButtonDisabled = *resetButtonReading;
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001194 }
Nan Lifdd8ec52016-08-28 03:57:40 +08001195
Yong Li70ce7352019-05-16 21:15:27 +08001196 bool powerDownAcFailed = power_policy::getACFailStatus();
1197
Chau Ly9e666cd2023-03-06 08:46:14 +00001198 bool chassisIntrusionActive = false;
1199 std::optional<bool> chassisIntrusionStatus = getChassisIntrusionStatus(ctx);
1200 if (chassisIntrusionStatus)
1201 {
1202 chassisIntrusionActive = chassisIntrusionStatus.value();
1203 }
1204
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001205 // This response has a lot of hard-coded, unsupported fields
1206 // They are set to false or 0
1207 constexpr bool powerOverload = false;
1208 constexpr bool chassisInterlock = false;
1209 constexpr bool powerFault = false;
1210 constexpr bool powerControlFault = false;
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001211 constexpr bool powerDownOverload = false;
1212 constexpr bool powerDownInterlock = false;
1213 constexpr bool powerDownPowerFault = false;
1214 constexpr bool powerStatusIPMI = false;
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001215 constexpr bool frontPanelLockoutActive = false;
1216 constexpr bool driveFault = false;
1217 constexpr bool coolingFanFault = false;
1218 // chassisIdentifySupport set because this command is implemented
1219 constexpr bool chassisIdentifySupport = true;
William A. Kennington III7a0e5df2021-05-19 13:31:29 -07001220 uint2_t chassisIdentifyState = types::enum_cast<uint2_t>(chassisIDState);
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001221 constexpr bool diagButtonDisabled = false;
1222 constexpr bool sleepButtonDisabled = false;
1223 constexpr bool diagButtonDisableAllow = false;
1224 constexpr bool sleepButtonDisableAllow = false;
1225
1226 return ipmi::responseSuccess(
1227 *powerGood, powerOverload, chassisInterlock, powerFault,
1228 powerControlFault, *restorePolicy,
1229 false, // reserved
1230
1231 powerDownAcFailed, powerDownOverload, powerDownInterlock,
1232 powerDownPowerFault, powerStatusIPMI,
1233 uint3_t(0), // reserved
1234
1235 chassisIntrusionActive, frontPanelLockoutActive, driveFault,
1236 coolingFanFault, chassisIdentifyState, chassisIdentifySupport,
1237 false, // reserved
1238
Vernon Mauery6d5b2f72019-05-16 14:48:47 -07001239 powerButtonDisabled, resetButtonDisabled, diagButtonDisabled,
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001240 sleepButtonDisabled, powerButtonDisableAllow, resetButtonDisableAllow,
1241 diagButtonDisableAllow, sleepButtonDisableAllow);
Nan Lifdd8ec52016-08-28 03:57:40 +08001242}
Chris Austen7888c4d2015-12-03 15:26:20 -06001243
Vijay Khemka074f64d2020-03-03 15:08:43 -08001244enum class IpmiRestartCause
1245{
1246 Unknown = 0x0,
1247 RemoteCommand = 0x1,
1248 ResetButton = 0x2,
1249 PowerButton = 0x3,
1250 WatchdogTimer = 0x4,
1251 PowerPolicyAlwaysOn = 0x6,
1252 PowerPolicyPreviousState = 0x7,
1253 SoftReset = 0xa,
1254};
1255
1256static IpmiRestartCause
1257 restartCauseToIpmiRestartCause(State::Host::RestartCause cause)
1258{
1259 switch (cause)
1260 {
1261 case State::Host::RestartCause::Unknown:
1262 {
1263 return IpmiRestartCause::Unknown;
1264 }
1265 case State::Host::RestartCause::RemoteCommand:
1266 {
1267 return IpmiRestartCause::RemoteCommand;
1268 }
1269 case State::Host::RestartCause::ResetButton:
1270 {
1271 return IpmiRestartCause::ResetButton;
1272 }
1273 case State::Host::RestartCause::PowerButton:
1274 {
1275 return IpmiRestartCause::PowerButton;
1276 }
1277 case State::Host::RestartCause::WatchdogTimer:
1278 {
1279 return IpmiRestartCause::WatchdogTimer;
1280 }
1281 case State::Host::RestartCause::PowerPolicyAlwaysOn:
1282 {
1283 return IpmiRestartCause::PowerPolicyAlwaysOn;
1284 }
1285 case State::Host::RestartCause::PowerPolicyPreviousState:
1286 {
1287 return IpmiRestartCause::PowerPolicyPreviousState;
1288 }
1289 case State::Host::RestartCause::SoftReset:
1290 {
1291 return IpmiRestartCause::SoftReset;
1292 }
1293 default:
1294 {
1295 return IpmiRestartCause::Unknown;
1296 }
1297 }
1298}
1299
1300/*
1301 * getRestartCause
1302 * helper function for Get Host restart cause Command
1303 * return - optional value for RestartCause (no value on error)
1304 */
1305static std::optional<uint4_t> getRestartCause(ipmi::Context::ptr ctx)
1306{
1307 constexpr const char* restartCausePath =
1308 "/xyz/openbmc_project/control/host0/restart_cause";
1309 constexpr const char* restartCauseIntf =
1310 "xyz.openbmc_project.Control.Host.RestartCause";
1311
1312 std::string service;
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05001313 boost::system::error_code ec = ipmi::getService(ctx, restartCauseIntf,
1314 restartCausePath, service);
Vijay Khemka074f64d2020-03-03 15:08:43 -08001315 if (!ec)
1316 {
1317 std::string restartCauseStr;
1318 ec = ipmi::getDbusProperty<std::string>(
1319 ctx, service, restartCausePath, restartCauseIntf, "RestartCause",
1320 restartCauseStr);
1321 if (!ec)
1322 {
1323 auto cause =
1324 State::Host::convertRestartCauseFromString(restartCauseStr);
William A. Kennington III7a0e5df2021-05-19 13:31:29 -07001325 return types::enum_cast<uint4_t>(
1326 restartCauseToIpmiRestartCause(cause));
Vijay Khemka074f64d2020-03-03 15:08:43 -08001327 }
1328 }
1329
1330 log<level::ERR>("Failed to fetch RestartCause property",
1331 entry("ERROR=%s", ec.message().c_str()),
1332 entry("PATH=%s", restartCausePath),
1333 entry("INTERFACE=%s", restartCauseIntf));
1334 return std::nullopt;
1335}
1336
1337ipmi::RspType<uint4_t, // Restart Cause
1338 uint4_t, // reserved
1339 uint8_t // channel number (not supported)
1340 >
1341 ipmiGetSystemRestartCause(ipmi::Context::ptr ctx)
1342{
1343 std::optional<uint4_t> cause = getRestartCause(ctx);
1344 if (!cause)
1345 {
1346 return ipmi::responseUnspecifiedError();
1347 }
1348
Vernon Mauery916d4232021-03-29 13:42:16 -07001349 constexpr uint4_t reserved = 0;
1350 auto channel = static_cast<uint8_t>(ctx->channel);
1351 return ipmi::responseSuccess(cause.value(), reserved, channel);
Vijay Khemka074f64d2020-03-03 15:08:43 -08001352}
anil kumar appanadafff5f2019-04-27 18:06:00 +00001353/** @brief Implementation of chassis control command
1354 *
1355 * @param - chassisControl command byte
1356 *
1357 * @return Success or InvalidFieldRequest.
1358 */
Jason M. Bills664e1c32020-01-30 16:02:39 -08001359ipmi::RspType<> ipmiChassisControl(ipmi::Context::ptr& ctx,
1360 uint8_t chassisControl)
vishwa36993272015-11-20 12:43:49 -06001361{
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001362 int rc = 0;
anil kumar appanadafff5f2019-04-27 18:06:00 +00001363 switch (chassisControl)
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001364 {
1365 case CMD_POWER_ON:
Jason M. Bills664e1c32020-01-30 16:02:39 -08001366 rc = initiateHostStateTransition(ctx, State::Host::Transition::On);
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001367 break;
1368 case CMD_POWER_OFF:
Jason M. Billsc2c3a402020-01-30 16:22:24 -08001369 rc = initiateChassisStateTransition(
1370 ctx, State::Chassis::Transition::Off);
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001371 break;
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001372 case CMD_HARD_RESET:
Jason M. Bills664e1c32020-01-30 16:02:39 -08001373 rc = initiateHostStateTransition(
1374 ctx, State::Host::Transition::ForceWarmReboot);
Chanh Nguyend0a7fcd2021-07-16 22:59:28 +07001375 break;
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001376 case CMD_POWER_CYCLE:
Jason M. Bills664e1c32020-01-30 16:02:39 -08001377 rc = initiateHostStateTransition(ctx,
1378 State::Host::Transition::Reboot);
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001379 break;
Vishwanatha Subbanna8b26d352017-08-04 18:35:18 +05301380 case CMD_SOFT_OFF_VIA_OVER_TEMP:
Jason M. Bills664e1c32020-01-30 16:02:39 -08001381 rc = initiateHostStateTransition(ctx, State::Host::Transition::Off);
Vishwanatha Subbanna8b26d352017-08-04 18:35:18 +05301382 break;
Kuiying Wang6b0ceaa2019-11-05 15:13:40 +08001383 case CMD_PULSE_DIAGNOSTIC_INTR:
Zev Weiss337a0972024-03-08 08:31:15 +00001384 rc = doNmi(ctx);
Kuiying Wang6b0ceaa2019-11-05 15:13:40 +08001385 break;
1386
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001387 default:
1388 {
Aditya Saripalli5fb14602017-11-09 14:46:27 +05301389 log<level::ERR>("Invalid Chassis Control command",
anil kumar appanadafff5f2019-04-27 18:06:00 +00001390 entry("CMD=0x%X", chassisControl));
1391 return ipmi::responseInvalidFieldRequest();
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001392 }
1393 }
vishwa36993272015-11-20 12:43:49 -06001394
anil kumar appanadafff5f2019-04-27 18:06:00 +00001395 return ((rc < 0) ? ipmi::responseUnspecifiedError()
1396 : ipmi::responseSuccess());
vishwa36993272015-11-20 12:43:49 -06001397}
1398
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001399/** @brief Return D-Bus connection string to enclosure identify LED object
1400 *
1401 * @param[in, out] connection - connection to D-Bus object
1402 * @return a IPMI return code
1403 */
1404std::string getEnclosureIdentifyConnection()
Tom Joseph5110c122018-03-23 17:55:40 +05301405{
Tom Joseph5110c122018-03-23 17:55:40 +05301406 // lookup enclosure_identify group owner(s) in mapper
George Liu3e3cc352023-07-26 15:59:31 +08001407 try
Tom Joseph5110c122018-03-23 17:55:40 +05301408 {
George Liu3e3cc352023-07-26 15:59:31 +08001409 return ipmi::getService(*getSdBus(), "xyz.openbmc_project.Led.Group",
1410 identify_led_object_name);
1411 }
1412 catch (const std::exception& e)
1413 {
1414 log<level::ERR>("Chassis Identify: Error communicating to mapper.",
1415 entry("ERROR=%s", e.what()));
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001416 elog<InternalFailure>();
Tom Joseph5110c122018-03-23 17:55:40 +05301417 }
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001418}
Tom Joseph5110c122018-03-23 17:55:40 +05301419
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001420/** @brief Turn On/Off enclosure identify LED
1421 *
1422 * @param[in] flag - true to turn on LED, false to turn off
1423 * @return a IPMI return code
1424 */
1425void enclosureIdentifyLed(bool flag)
1426{
1427 using namespace chassis::internal;
George Liu3e3cc352023-07-26 15:59:31 +08001428 try
1429 {
1430 std::string connection = getEnclosureIdentifyConnection();
1431
1432 auto msg = std::string("enclosureIdentifyLed(") +
1433 boost::lexical_cast<std::string>(flag) + ")";
1434 log<level::DEBUG>(msg.c_str());
1435
1436 ipmi::setDbusProperty(*getSdBus(), connection, identify_led_object_name,
1437 "xyz.openbmc_project.Led.Group", "Asserted",
1438 flag);
1439 }
1440 catch (const std::exception& e)
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001441 {
1442 log<level::ERR>("Chassis Identify: Error Setting State On/Off\n",
George Liu3e3cc352023-07-26 15:59:31 +08001443 entry("LED_STATE=%d", flag),
1444 entry("ERROR=%s", e.what()));
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001445 elog<InternalFailure>();
1446 }
1447}
1448
1449/** @brief Callback method to turn off LED
1450 */
1451void enclosureIdentifyLedOff()
1452{
1453 try
1454 {
Yong Lif4e38512019-05-21 14:46:55 +08001455 chassisIDState = ChassisIDState::off;
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001456 enclosureIdentifyLed(false);
1457 }
1458 catch (const InternalFailure& e)
1459 {
1460 report<InternalFailure>();
1461 }
1462}
1463
1464/** @brief Create timer to turn on and off the enclosure LED
1465 */
1466void createIdentifyTimer()
1467{
1468 if (!identifyTimer)
1469 {
Vernon Mauery1181af72018-10-08 12:05:00 -07001470 identifyTimer =
Patrick Williams95655222023-12-05 12:45:02 -06001471 std::make_unique<sdbusplus::Timer>(enclosureIdentifyLedOff);
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001472 }
1473}
1474
Vernon Mauery400cc782018-10-09 13:49:53 -07001475ipmi::RspType<> ipmiChassisIdentify(std::optional<uint8_t> interval,
1476 std::optional<uint8_t> force)
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001477{
Vernon Mauery400cc782018-10-09 13:49:53 -07001478 uint8_t identifyInterval = interval.value_or(DEFAULT_IDENTIFY_TIME_OUT);
1479 bool forceIdentify = force.value_or(0) & 0x01;
Tom Josephbed26992018-07-31 23:00:24 +05301480
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001481 if (identifyInterval || forceIdentify)
1482 {
Vernon Mauery400cc782018-10-09 13:49:53 -07001483 // stop the timer if already started;
1484 // for force identify we should not turn off LED
Vernon Mauery1181af72018-10-08 12:05:00 -07001485 identifyTimer->stop();
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001486 try
Tom Joseph5110c122018-03-23 17:55:40 +05301487 {
Yong Lif4e38512019-05-21 14:46:55 +08001488 chassisIDState = ChassisIDState::temporaryOn;
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001489 enclosureIdentifyLed(true);
1490 }
1491 catch (const InternalFailure& e)
1492 {
1493 report<InternalFailure>();
Vernon Mauery400cc782018-10-09 13:49:53 -07001494 return ipmi::responseResponseError();
Tom Joseph5110c122018-03-23 17:55:40 +05301495 }
1496
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001497 if (forceIdentify)
Tom Joseph5110c122018-03-23 17:55:40 +05301498 {
Yong Lif4e38512019-05-21 14:46:55 +08001499 chassisIDState = ChassisIDState::indefiniteOn;
Vernon Mauery400cc782018-10-09 13:49:53 -07001500 return ipmi::responseSuccess();
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001501 }
1502 // start the timer
1503 auto time = std::chrono::duration_cast<std::chrono::microseconds>(
Patrick Venture0b02be92018-08-31 11:55:55 -07001504 std::chrono::seconds(identifyInterval));
Vernon Mauery1181af72018-10-08 12:05:00 -07001505 identifyTimer->start(time);
Tom Joseph5110c122018-03-23 17:55:40 +05301506 }
Tom Josephbed26992018-07-31 23:00:24 +05301507 else if (!identifyInterval)
1508 {
Vernon Mauery1181af72018-10-08 12:05:00 -07001509 identifyTimer->stop();
Tom Josephbed26992018-07-31 23:00:24 +05301510 enclosureIdentifyLedOff();
1511 }
Vernon Mauery400cc782018-10-09 13:49:53 -07001512 return ipmi::responseSuccess();
Tom Joseph5110c122018-03-23 17:55:40 +05301513}
1514
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001515namespace boot_options
1516{
1517
Willy Tu523e2d12023-09-05 11:36:48 -07001518using namespace sdbusplus::server::xyz::openbmc_project::control::boot;
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001519using IpmiValue = uint8_t;
1520constexpr auto ipmiDefault = 0;
1521
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001522std::map<IpmiValue, Type::Types> typeIpmiToDbus = {{0x00, Type::Types::Legacy},
1523 {0x01, Type::Types::EFI}};
1524
Patrick Venture0b02be92018-08-31 11:55:55 -07001525std::map<IpmiValue, Source::Sources> sourceIpmiToDbus = {
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001526 {0x01, Source::Sources::Network},
1527 {0x02, Source::Sources::Disk},
1528 {0x05, Source::Sources::ExternalMedia},
Jia, chunhui67c5e5d2019-05-06 11:29:54 +08001529 {0x0f, Source::Sources::RemovableMedia},
Patrick Venture0b02be92018-08-31 11:55:55 -07001530 {ipmiDefault, Source::Sources::Default}};
shgoupfd84fbbf2015-12-17 10:05:51 +08001531
Patrick Venture0b02be92018-08-31 11:55:55 -07001532std::map<IpmiValue, Mode::Modes> modeIpmiToDbus = {
Yong Li5833cb62019-10-30 13:27:12 +08001533#ifdef ENABLE_BOOT_FLAG_SAFE_MODE_SUPPORT
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001534 {0x03, Mode::Modes::Safe},
Yong Li5833cb62019-10-30 13:27:12 +08001535#endif // ENABLE_BOOT_SAFE_MODE_SUPPORT
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001536 {0x06, Mode::Modes::Setup},
Patrick Venture0b02be92018-08-31 11:55:55 -07001537 {ipmiDefault, Mode::Modes::Regular}};
shgoupfd84fbbf2015-12-17 10:05:51 +08001538
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001539std::map<Type::Types, IpmiValue> typeDbusToIpmi = {{Type::Types::Legacy, 0x00},
1540 {Type::Types::EFI, 0x01}};
1541
Patrick Venture0b02be92018-08-31 11:55:55 -07001542std::map<Source::Sources, IpmiValue> sourceDbusToIpmi = {
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001543 {Source::Sources::Network, 0x01},
1544 {Source::Sources::Disk, 0x02},
1545 {Source::Sources::ExternalMedia, 0x05},
Jia, chunhui67c5e5d2019-05-06 11:29:54 +08001546 {Source::Sources::RemovableMedia, 0x0f},
Patrick Venture0b02be92018-08-31 11:55:55 -07001547 {Source::Sources::Default, ipmiDefault}};
shgoupfd84fbbf2015-12-17 10:05:51 +08001548
Patrick Venture0b02be92018-08-31 11:55:55 -07001549std::map<Mode::Modes, IpmiValue> modeDbusToIpmi = {
Yong Li5833cb62019-10-30 13:27:12 +08001550#ifdef ENABLE_BOOT_FLAG_SAFE_MODE_SUPPORT
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001551 {Mode::Modes::Safe, 0x03},
Yong Li5833cb62019-10-30 13:27:12 +08001552#endif // ENABLE_BOOT_SAFE_MODE_SUPPORT
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001553 {Mode::Modes::Setup, 0x06},
Patrick Venture0b02be92018-08-31 11:55:55 -07001554 {Mode::Modes::Regular, ipmiDefault}};
shgoupfd84fbbf2015-12-17 10:05:51 +08001555
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001556} // namespace boot_options
shgoupfd84fbbf2015-12-17 10:05:51 +08001557
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001558/** @brief Get the property value for boot source
1559 * @param[in] ctx - context pointer
1560 * @param[out] source - boot source value
1561 * @return On failure return IPMI error.
1562 */
1563static ipmi::Cc getBootSource(ipmi::Context::ptr& ctx, Source::Sources& source)
1564{
1565 using namespace chassis::internal;
1566 std::string result;
1567 std::string service;
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05001568 boost::system::error_code ec = getService(ctx, bootSourceIntf,
1569 bootSettingsPath, service);
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001570 if (!ec)
1571 {
1572 ec = ipmi::getDbusProperty(ctx, service, bootSettingsPath,
1573 bootSourceIntf, "BootSource", result);
1574 if (!ec)
1575 {
1576 source = Source::convertSourcesFromString(result);
1577 return ipmi::ccSuccess;
1578 }
1579 }
1580 log<level::ERR>("Error in BootSource Get",
1581 entry("ERROR=%s", ec.message().c_str()));
1582 return ipmi::ccUnspecifiedError;
1583}
1584
Marri Devender Rao81719702018-05-07 00:53:48 -05001585/** @brief Set the property value for boot source
Konstantin Aladysheve76a61a2021-03-18 22:19:13 +03001586 * @param[in] ctx - context pointer
Marri Devender Rao81719702018-05-07 00:53:48 -05001587 * @param[in] source - boot source value
1588 * @return On failure return IPMI error.
1589 */
Jayaprakash Mutyala6088e9f2021-07-14 07:40:29 +00001590static ipmi::Cc setBootSource(ipmi::Context::ptr& ctx,
1591 const Source::Sources& source)
Marri Devender Rao81719702018-05-07 00:53:48 -05001592{
1593 using namespace chassis::internal;
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001594 std::string service;
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05001595 boost::system::error_code ec = getService(ctx, bootSourceIntf,
1596 bootSettingsPath, service);
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001597 if (!ec)
Marri Devender Rao81719702018-05-07 00:53:48 -05001598 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001599 ec = ipmi::setDbusProperty(ctx, service, bootSettingsPath,
1600 bootSourceIntf, "BootSource",
1601 convertForMessage(source));
1602 if (!ec)
1603 {
1604 return ipmi::ccSuccess;
1605 }
Marri Devender Rao81719702018-05-07 00:53:48 -05001606 }
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001607 log<level::ERR>("Error in BootSource Set",
1608 entry("ERROR=%s", ec.message().c_str()));
1609 return ipmi::ccUnspecifiedError;
1610}
1611
1612/** @brief Get the property value for boot mode
1613 * @param[in] ctx - context pointer
1614 * @param[out] mode - boot mode value
1615 * @return On failure return IPMI error.
1616 */
1617static ipmi::Cc getBootMode(ipmi::Context::ptr& ctx, Mode::Modes& mode)
1618{
1619 using namespace chassis::internal;
1620 std::string result;
1621 std::string service;
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05001622 boost::system::error_code ec = getService(ctx, bootModeIntf,
1623 bootSettingsPath, service);
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001624 if (!ec)
1625 {
1626 ec = ipmi::getDbusProperty(ctx, service, bootSettingsPath, bootModeIntf,
1627 "BootMode", result);
1628 if (!ec)
1629 {
1630 mode = Mode::convertModesFromString(result);
1631 return ipmi::ccSuccess;
1632 }
1633 }
1634 log<level::ERR>("Error in BootMode Get",
1635 entry("ERROR=%s", ec.message().c_str()));
1636 return ipmi::ccUnspecifiedError;
Marri Devender Rao81719702018-05-07 00:53:48 -05001637}
1638
Patrick Venture0b02be92018-08-31 11:55:55 -07001639/** @brief Set the property value for boot mode
Konstantin Aladysheve76a61a2021-03-18 22:19:13 +03001640 * @param[in] ctx - context pointer
Marri Devender Rao81719702018-05-07 00:53:48 -05001641 * @param[in] mode - boot mode value
1642 * @return On failure return IPMI error.
1643 */
Konstantin Aladysheve76a61a2021-03-18 22:19:13 +03001644static ipmi::Cc setBootMode(ipmi::Context::ptr& ctx, const Mode::Modes& mode)
Marri Devender Rao81719702018-05-07 00:53:48 -05001645{
1646 using namespace chassis::internal;
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001647 std::string service;
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05001648 boost::system::error_code ec = getService(ctx, bootModeIntf,
1649 bootSettingsPath, service);
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001650 if (!ec)
Marri Devender Rao81719702018-05-07 00:53:48 -05001651 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001652 ec = ipmi::setDbusProperty(ctx, service, bootSettingsPath, bootModeIntf,
1653 "BootMode", convertForMessage(mode));
1654 if (!ec)
1655 {
1656 return ipmi::ccSuccess;
1657 }
Marri Devender Rao81719702018-05-07 00:53:48 -05001658 }
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001659 log<level::ERR>("Error in BootMode Set",
1660 entry("ERROR=%s", ec.message().c_str()));
1661 return ipmi::ccUnspecifiedError;
1662}
1663
1664/** @brief Get the property value for boot type
1665 * @param[in] ctx - context pointer
1666 * @param[out] type - boot type value
1667 * @return On failure return IPMI error.
1668 */
1669static ipmi::Cc getBootType(ipmi::Context::ptr& ctx, Type::Types& type)
1670{
1671 using namespace chassis::internal;
1672 std::string result;
1673 std::string service;
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05001674 boost::system::error_code ec = getService(ctx, bootTypeIntf,
1675 bootSettingsPath, service);
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001676
1677 // Don't throw error if BootType interface is not present.
1678 // This interface is not relevant for some Host architectures
1679 // (for example POWER). In this case we don't won't IPMI to
1680 // return an error, but simply return bootType as EFI.
1681 type = Type::Types::EFI;
1682 if (!ec)
1683 {
1684 ec = ipmi::getDbusProperty(ctx, service, bootSettingsPath, bootTypeIntf,
1685 "BootType", result);
1686 if (ec)
1687 {
1688 log<level::ERR>("Error in BootType Get",
1689 entry("ERROR=%s", ec.message().c_str()));
1690 return ipmi::ccUnspecifiedError;
1691 }
1692 type = Type::convertTypesFromString(result);
1693 }
1694
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00001695 return ipmi::ccSuccess;
Marri Devender Rao81719702018-05-07 00:53:48 -05001696}
1697
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001698/** @brief Set the property value for boot type
Konstantin Aladysheve76a61a2021-03-18 22:19:13 +03001699 * @param[in] ctx - context pointer
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001700 * @param[in] type - boot type value
1701 * @return On failure return IPMI error.
1702 */
Konstantin Aladysheve76a61a2021-03-18 22:19:13 +03001703static ipmi::Cc setBootType(ipmi::Context::ptr& ctx, const Type::Types& type)
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001704{
1705 using namespace chassis::internal;
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001706 std::string service;
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05001707 boost::system::error_code ec = getService(ctx, bootTypeIntf,
1708 bootSettingsPath, service);
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001709 if (!ec)
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001710 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001711 ec = ipmi::setDbusProperty(ctx, service, bootSettingsPath, bootTypeIntf,
1712 "BootType", convertForMessage(type));
1713 if (ec)
1714 {
1715 log<level::ERR>("Error in BootType Set",
1716 entry("ERROR=%s", ec.message().c_str()));
1717 return ipmi::ccUnspecifiedError;
1718 }
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001719 }
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001720 // Don't throw error if BootType interface is not present.
1721 // This interface is not relevant for some Host architectures
1722 // (for example POWER). In this case we don't won't IPMI to
1723 // return an error, but want to just skip this function.
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001724 return ipmi::ccSuccess;
1725}
1726
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001727/** @brief Get the property value for boot override enable
1728 * @param[in] ctx - context pointer
1729 * @param[out] enable - boot override enable
1730 * @return On failure return IPMI error.
1731 */
1732static ipmi::Cc getBootEnable(ipmi::Context::ptr& ctx, bool& enable)
1733{
1734 using namespace chassis::internal;
1735 std::string result;
1736 std::string service;
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05001737 boost::system::error_code ec = getService(ctx, bootEnableIntf,
1738 bootSettingsPath, service);
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001739 if (!ec)
1740 {
1741 ec = ipmi::getDbusProperty(ctx, service, bootSettingsPath,
1742 bootEnableIntf, "Enabled", enable);
1743 if (!ec)
1744 {
1745 return ipmi::ccSuccess;
1746 }
1747 }
1748 log<level::ERR>("Error in Boot Override Enable Get",
1749 entry("ERROR=%s", ec.message().c_str()));
1750 return ipmi::ccUnspecifiedError;
1751}
1752
1753/** @brief Set the property value for boot override enable
1754 * @param[in] ctx - context pointer
1755 * @param[in] enable - boot override enable
1756 * @return On failure return IPMI error.
1757 */
1758static ipmi::Cc setBootEnable(ipmi::Context::ptr& ctx, const bool& enable)
1759{
1760 using namespace chassis::internal;
1761 std::string service;
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05001762 boost::system::error_code ec = getService(ctx, bootEnableIntf,
1763 bootSettingsPath, service);
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001764 if (!ec)
1765 {
1766 ec = ipmi::setDbusProperty(ctx, service, bootSettingsPath,
1767 bootEnableIntf, "Enabled", enable);
1768 if (!ec)
1769 {
1770 return ipmi::ccSuccess;
1771 }
1772 }
1773 log<level::ERR>("Error in Boot Source Override Enable Set",
1774 entry("ERROR=%s", ec.message().c_str()));
1775 return ipmi::ccUnspecifiedError;
1776}
1777
1778/** @brief Get the property value for boot override one-time
1779 * @param[in] ctx - context pointer
1780 * @param[out] onetime - boot override one-time
1781 * @return On failure return IPMI error.
1782 */
1783static ipmi::Cc getBootOneTime(ipmi::Context::ptr& ctx, bool& onetime)
1784{
1785 using namespace chassis::internal;
1786 std::string result;
1787 std::string service;
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05001788 boost::system::error_code ec = getService(ctx, bootOneTimeIntf,
1789 bootSettingsOneTimePath, service);
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001790 if (!ec)
1791 {
1792 ec = ipmi::getDbusProperty(ctx, service, bootSettingsOneTimePath,
1793 bootOneTimeIntf, "Enabled", onetime);
1794 if (!ec)
1795 {
1796 return ipmi::ccSuccess;
1797 }
1798 }
1799 log<level::ERR>("Error in Boot Override OneTime Get",
1800 entry("ERROR=%s", ec.message().c_str()));
1801 return ipmi::ccUnspecifiedError;
1802}
1803
1804/** @brief Set the property value for boot override one-time
1805 * @param[in] ctx - context pointer
1806 * @param[in] onetime - boot override one-time
1807 * @return On failure return IPMI error.
1808 */
1809static ipmi::Cc setBootOneTime(ipmi::Context::ptr& ctx, const bool& onetime)
1810{
1811 using namespace chassis::internal;
1812 std::string service;
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05001813 boost::system::error_code ec = getService(ctx, bootOneTimeIntf,
1814 bootSettingsOneTimePath, service);
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001815 if (!ec)
1816 {
1817 ec = ipmi::setDbusProperty(ctx, service, bootSettingsOneTimePath,
1818 bootOneTimeIntf, "Enabled", onetime);
1819 if (!ec)
1820 {
1821 return ipmi::ccSuccess;
1822 }
1823 }
1824 log<level::ERR>("Error in Boot Source Override OneTime Set",
1825 entry("ERROR=%s", ec.message().c_str()));
1826 return ipmi::ccUnspecifiedError;
1827}
1828
huangheab369282020-10-10 14:40:00 +08001829static constexpr uint8_t setComplete = 0x0;
1830static constexpr uint8_t setInProgress = 0x1;
1831static uint8_t transferStatus = setComplete;
Chen Yugang86ac4992021-06-25 08:14:52 +08001832static uint8_t bootFlagValidBitClr = 0;
Hieu Huynh38ffafc2021-05-14 08:40:14 +00001833static uint5_t bootInitiatorAckData = 0x0;
Hieu Huynh1982a3f2021-09-21 03:06:45 +00001834static bool cmosClear = false;
huangheab369282020-10-10 14:40:00 +08001835
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00001836/** @brief implements the Get Chassis system boot option
Konstantin Aladysheve76a61a2021-03-18 22:19:13 +03001837 * @param ctx - context pointer
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00001838 * @param bootOptionParameter - boot option parameter selector
1839 * @param reserved1 - reserved bit
1840 * @param setSelector - selects a particular block or set of parameters
1841 * under the given parameter selector
1842 * write as 00h if parameter doesn't use a setSelector
1843 * @param blockSelector- selects a particular block within a set of
1844 * parameters write as 00h if parameter doesn't use a
1845 * blockSelector
1846 *
1847 * @return IPMI completion code plus response data
1848 * @return Payload contains below parameters:
1849 * version - parameter version
1850 * bootOptionParameter - boot option parameter selector
Patrick Venture8b1c3032020-09-15 09:43:03 -07001851 * parmIndicator - parameter valid/invalid indicator
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00001852 * data - configuration parameter data
1853 */
1854ipmi::RspType<ipmi::message::Payload>
Konstantin Aladysheve76a61a2021-03-18 22:19:13 +03001855 ipmiChassisGetSysBootOptions(ipmi::Context::ptr ctx,
1856 uint7_t bootOptionParameter, bool reserved1,
Willy Tu11d68892022-01-20 10:37:34 -08001857 [[maybe_unused]] uint8_t setSelector,
1858 [[maybe_unused]] uint8_t blockSelector)
Adriana Kobylak40814c62015-10-27 15:58:44 -05001859{
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001860 ipmi::Cc rc;
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00001861 if (reserved1)
1862 {
1863 return ipmi::responseInvalidFieldRequest();
1864 }
1865
1866 constexpr uint4_t version = 0x01;
1867 ipmi::message::Payload response;
1868 response.pack(version, uint4_t{});
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001869 using namespace boot_options;
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00001870
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001871 IpmiValue bootOption = ipmiDefault;
Adriana Kobylak40814c62015-10-27 15:58:44 -05001872
William A. Kennington III7a0e5df2021-05-19 13:31:29 -07001873 if (types::enum_cast<BootOptionParameter>(bootOptionParameter) ==
1874 BootOptionParameter::setInProgress)
huangheab369282020-10-10 14:40:00 +08001875 {
1876 response.pack(bootOptionParameter, reserved1, transferStatus);
1877 return ipmi::responseSuccess(std::move(response));
1878 }
1879
William A. Kennington III7a0e5df2021-05-19 13:31:29 -07001880 if (types::enum_cast<BootOptionParameter>(bootOptionParameter) ==
1881 BootOptionParameter::bootInfo)
John Wang0213f902020-12-28 14:49:57 +08001882 {
1883 constexpr uint8_t writeMask = 0;
Hieu Huynh38ffafc2021-05-14 08:40:14 +00001884 response.pack(bootOptionParameter, reserved1, writeMask,
1885 bootInitiatorAckData);
John Wang0213f902020-12-28 14:49:57 +08001886 return ipmi::responseSuccess(std::move(response));
1887 }
1888
Chen Yugang86ac4992021-06-25 08:14:52 +08001889 if (types::enum_cast<BootOptionParameter>(bootOptionParameter) ==
1890 BootOptionParameter::bootFlagValidClr)
1891 {
1892 response.pack(bootOptionParameter, reserved1,
1893 uint5_t{bootFlagValidBitClr}, uint3_t{});
1894 return ipmi::responseSuccess(std::move(response));
1895 }
1896
shgoupfd84fbbf2015-12-17 10:05:51 +08001897 /*
1898 * Parameter #5 means boot flags. Please refer to 28.13 of ipmi doc.
1899 * This is the only parameter used by petitboot.
1900 */
William A. Kennington III7a0e5df2021-05-19 13:31:29 -07001901 if (types::enum_cast<BootOptionParameter>(bootOptionParameter) ==
1902 BootOptionParameter::bootFlags)
Patrick Venture0b02be92018-08-31 11:55:55 -07001903 {
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001904 using namespace chassis::internal;
1905 using namespace chassis::internal::cache;
shgoupfd84fbbf2015-12-17 10:05:51 +08001906
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001907 try
ratagupta6f6bff2016-04-04 06:20:11 -05001908 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001909 Source::Sources bootSource;
1910 rc = getBootSource(ctx, bootSource);
1911 if (rc != ipmi::ccSuccess)
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001912 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001913 return ipmi::response(rc);
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001914 }
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001915
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001916 Type::Types bootType;
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001917 rc = getBootType(ctx, bootType);
1918 if (rc != ipmi::ccSuccess)
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001919 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001920 return ipmi::response(rc);
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001921 }
1922
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001923 Mode::Modes bootMode;
1924 rc = getBootMode(ctx, bootMode);
1925 if (rc != ipmi::ccSuccess)
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001926 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001927 return ipmi::response(rc);
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001928 }
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001929
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001930 bootOption = sourceDbusToIpmi.at(bootSource);
1931 if ((Mode::Modes::Regular == bootMode) &&
1932 (Source::Sources::Default == bootSource))
1933 {
1934 bootOption = ipmiDefault;
1935 }
1936 else if (Source::Sources::Default == bootSource)
1937 {
1938 bootOption = modeDbusToIpmi.at(bootMode);
1939 }
ratagupta6f6bff2016-04-04 06:20:11 -05001940
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001941 IpmiValue biosBootType = typeDbusToIpmi.at(bootType);
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001942
1943 bool oneTimeEnabled;
1944 rc = getBootOneTime(ctx, oneTimeEnabled);
1945 if (rc != ipmi::ccSuccess)
1946 {
1947 return ipmi::response(rc);
1948 }
1949
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001950 uint1_t permanent = oneTimeEnabled ? 0 : 1;
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001951
1952 bool valid;
1953 rc = getBootEnable(ctx, valid);
1954 if (rc != ipmi::ccSuccess)
1955 {
1956 return ipmi::response(rc);
1957 }
1958
1959 uint1_t validFlag = valid ? 1 : 0;
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001960
1961 response.pack(bootOptionParameter, reserved1, uint5_t{},
1962 uint1_t{biosBootType}, uint1_t{permanent},
1963 uint1_t{validFlag}, uint2_t{}, uint4_t{bootOption},
Hieu Huynh1982a3f2021-09-21 03:06:45 +00001964 uint1_t{}, cmosClear, uint8_t{}, uint8_t{},
1965 uint8_t{});
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00001966 return ipmi::responseSuccess(std::move(response));
ratagupta6f6bff2016-04-04 06:20:11 -05001967 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -05001968 catch (const InternalFailure& e)
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001969 {
James Feist225dec82019-11-26 16:25:06 -08001970 cache::objectsPtr.reset();
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001971 report<InternalFailure>();
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00001972 return ipmi::responseUnspecifiedError();
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001973 }
Patrick Venture0b02be92018-08-31 11:55:55 -07001974 }
Patrick Venture0b02be92018-08-31 11:55:55 -07001975 else
1976 {
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00001977 if ((bootOptionParameter >= oemParmStart) &&
1978 (bootOptionParameter <= oemParmEnd))
1979 {
William A. Kennington III7a0e5df2021-05-19 13:31:29 -07001980 if (types::enum_cast<BootOptionParameter>(bootOptionParameter) ==
1981 BootOptionParameter::opalNetworkSettings)
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00001982 {
1983 response.pack(bootOptionParameter, reserved1);
1984 int ret = getHostNetworkData(response);
1985 if (ret < 0)
1986 {
1987 response.trailingOk = true;
1988 log<level::ERR>(
1989 "getHostNetworkData failed for GetSysBootOptions.");
1990 return ipmi::responseUnspecifiedError();
1991 }
1992 else
1993 {
1994 return ipmi::responseSuccess(std::move(response));
1995 }
1996 }
Jayaprakash Mutyala43a88102021-08-04 16:41:58 +00001997 else
1998 {
1999 log<level::ERR>(
2000 "ipmiChassisGetSysBootOptions: Unsupported parameter",
2001 entry("PARAM=0x%x",
2002 static_cast<uint8_t>(bootOptionParameter)));
2003 return ipmi::responseParmNotSupported();
2004 }
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00002005 }
2006 else
2007 {
2008 log<level::ERR>(
2009 "ipmiChassisGetSysBootOptions: Unsupported parameter",
2010 entry("PARAM=0x%x", static_cast<uint8_t>(bootOptionParameter)));
Jayaprakash Mutyala6088e9f2021-07-14 07:40:29 +00002011 return ipmi::responseParmNotSupported();
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00002012 }
shgoupfd84fbbf2015-12-17 10:05:51 +08002013 }
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00002014 return ipmi::responseUnspecifiedError();
shgoupfd84fbbf2015-12-17 10:05:51 +08002015}
2016
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002017ipmi::RspType<> ipmiChassisSetSysBootOptions(ipmi::Context::ptr ctx,
Willy Tu11d68892022-01-20 10:37:34 -08002018 uint7_t parameterSelector, bool,
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002019 ipmi::message::Payload& data)
shgoupfd84fbbf2015-12-17 10:05:51 +08002020{
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05002021 using namespace boot_options;
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002022 ipmi::Cc rc;
shgoupfd84fbbf2015-12-17 10:05:51 +08002023
William A. Kennington III7a0e5df2021-05-19 13:31:29 -07002024 if (types::enum_cast<BootOptionParameter>(parameterSelector) ==
2025 BootOptionParameter::setInProgress)
huangheab369282020-10-10 14:40:00 +08002026 {
2027 uint2_t setInProgressFlag;
2028 uint6_t rsvd;
2029 if (data.unpack(setInProgressFlag, rsvd) != 0 || !data.fullyUnpacked())
2030 {
2031 return ipmi::responseReqDataLenInvalid();
2032 }
2033 if (rsvd)
2034 {
2035 return ipmi::responseInvalidFieldRequest();
2036 }
2037 if ((transferStatus == setInProgress) &&
2038 (static_cast<uint8_t>(setInProgressFlag) != setComplete))
2039 {
2040 return ipmi::response(IPMI_CC_FAIL_SET_IN_PROGRESS);
2041 }
2042 transferStatus = static_cast<uint8_t>(setInProgressFlag);
2043 return ipmi::responseSuccess();
2044 }
2045
shgoupfd84fbbf2015-12-17 10:05:51 +08002046 /* 000101
2047 * Parameter #5 means boot flags. Please refer to 28.13 of ipmi doc.
2048 * This is the only parameter used by petitboot.
2049 */
Ratan Guptafd28dd72016-08-01 04:58:01 -05002050
William A. Kennington III7a0e5df2021-05-19 13:31:29 -07002051 if (types::enum_cast<BootOptionParameter>(parameterSelector) ==
2052 BootOptionParameter::bootFlags)
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05002053 {
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002054 uint5_t rsvd;
2055 bool validFlag;
2056 bool permanent;
2057 bool biosBootType;
2058 bool lockOutResetButton;
2059 bool screenBlank;
2060 uint4_t bootDeviceSelector;
2061 bool lockKeyboard;
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002062 uint8_t data3;
2063 uint4_t biosInfo;
2064 uint4_t rsvd1;
2065 uint5_t deviceInstance;
2066 uint3_t rsvd2;
2067
2068 if (data.unpack(rsvd, biosBootType, permanent, validFlag,
2069 lockOutResetButton, screenBlank, bootDeviceSelector,
2070 lockKeyboard, cmosClear, data3, biosInfo, rsvd1,
2071 deviceInstance, rsvd2) != 0 ||
2072 !data.fullyUnpacked())
2073 {
2074 return ipmi::responseReqDataLenInvalid();
2075 }
2076 if (rsvd || rsvd1 || rsvd2)
2077 {
2078 return ipmi::responseInvalidFieldRequest();
2079 }
2080
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05002081 using namespace chassis::internal;
2082 using namespace chassis::internal::cache;
shgoupfd84fbbf2015-12-17 10:05:51 +08002083
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05002084 try
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05002085 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03002086 rc = setBootOneTime(ctx, !permanent);
2087 if (rc != ipmi::ccSuccess)
Konstantin Aladyshev69e8e842021-06-18 17:01:18 +03002088 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03002089 return ipmi::response(rc);
2090 }
Vernon Maueryafd45db2021-07-29 16:27:25 +00002091
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03002092 rc = setBootEnable(ctx, validFlag);
2093 if (rc != ipmi::ccSuccess)
2094 {
2095 return ipmi::response(rc);
Tom Joseph57e8eb72017-09-25 18:05:02 +05302096 }
2097
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002098 auto modeItr =
2099 modeIpmiToDbus.find(static_cast<uint8_t>(bootDeviceSelector));
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03002100 auto typeItr =
2101 typeIpmiToDbus.find(static_cast<uint8_t>(biosBootType));
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002102 auto sourceItr =
2103 sourceIpmiToDbus.find(static_cast<uint8_t>(bootDeviceSelector));
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05002104 if (sourceIpmiToDbus.end() != sourceItr)
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05002105 {
Konstantin Aladysheve76a61a2021-03-18 22:19:13 +03002106 rc = setBootSource(ctx, sourceItr->second);
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002107 if (rc != ipmi::ccSuccess)
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05002108 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03002109 return ipmi::response(rc);
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05002110 }
Marri Devender Rao54fa1302018-05-07 01:06:23 -05002111 // If a set boot device is mapping to a boot source, then reset
2112 // the boot mode D-Bus property to default.
2113 // This way the ipmid code can determine which property is not
2114 // at the default value
Patrick Venture0b02be92018-08-31 11:55:55 -07002115 if (sourceItr->second != Source::Sources::Default)
Marri Devender Rao54fa1302018-05-07 01:06:23 -05002116 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03002117 rc = setBootMode(ctx, Mode::Modes::Regular);
2118 if (rc != ipmi::ccSuccess)
2119 {
2120 return ipmi::response(rc);
2121 }
Marri Devender Rao54fa1302018-05-07 01:06:23 -05002122 }
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05002123 }
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03002124
2125 if (typeIpmiToDbus.end() != typeItr)
2126 {
Konstantin Aladysheve76a61a2021-03-18 22:19:13 +03002127 rc = setBootType(ctx, typeItr->second);
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03002128 if (rc != ipmi::ccSuccess)
2129 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03002130 return ipmi::response(rc);
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03002131 }
2132 }
2133
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05002134 if (modeIpmiToDbus.end() != modeItr)
2135 {
Konstantin Aladysheve76a61a2021-03-18 22:19:13 +03002136 rc = setBootMode(ctx, modeItr->second);
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002137 if (rc != ipmi::ccSuccess)
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05002138 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03002139 return ipmi::response(rc);
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05002140 }
Marri Devender Rao54fa1302018-05-07 01:06:23 -05002141 // If a set boot device is mapping to a boot mode, then reset
2142 // the boot source D-Bus property to default.
2143 // This way the ipmid code can determine which property is not
2144 // at the default value
Patrick Venture0b02be92018-08-31 11:55:55 -07002145 if (modeItr->second != Mode::Modes::Regular)
Marri Devender Rao54fa1302018-05-07 01:06:23 -05002146 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03002147 rc = setBootSource(ctx, Source::Sources::Default);
2148 if (rc != ipmi::ccSuccess)
2149 {
2150 return ipmi::response(rc);
2151 }
Marri Devender Rao54fa1302018-05-07 01:06:23 -05002152 }
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05002153 }
Jia, chunhui67c5e5d2019-05-06 11:29:54 +08002154 if ((modeIpmiToDbus.end() == modeItr) &&
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03002155 (typeIpmiToDbus.end() == typeItr) &&
Jia, chunhui67c5e5d2019-05-06 11:29:54 +08002156 (sourceIpmiToDbus.end() == sourceItr))
2157 {
2158 // return error if boot option is not supported
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002159 log<level::ERR>(
2160 "ipmiChassisSetSysBootOptions: Boot option not supported");
2161 return ipmi::responseInvalidFieldRequest();
Jia, chunhui67c5e5d2019-05-06 11:29:54 +08002162 }
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05002163 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -05002164 catch (const sdbusplus::exception_t& e)
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05002165 {
James Feist225dec82019-11-26 16:25:06 -08002166 objectsPtr.reset();
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05002167 report<InternalFailure>();
Aditya Saripalli5fb14602017-11-09 14:46:27 +05302168 log<level::ERR>(
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002169 "ipmiChassisSetSysBootOptions: Error in setting Boot "
2170 "flag parameters");
2171 return ipmi::responseUnspecifiedError();
Ratan Guptafd28dd72016-08-01 04:58:01 -05002172 }
Patrick Venture0b02be92018-08-31 11:55:55 -07002173 }
William A. Kennington III7a0e5df2021-05-19 13:31:29 -07002174 else if (types::enum_cast<BootOptionParameter>(parameterSelector) ==
2175 BootOptionParameter::bootInfo)
Patrick Venture0b02be92018-08-31 11:55:55 -07002176 {
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002177 uint8_t writeMak;
Hieu Huynh38ffafc2021-05-14 08:40:14 +00002178 uint5_t bootInfoAck;
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002179 uint3_t rsvd;
2180
Hieu Huynh38ffafc2021-05-14 08:40:14 +00002181 if (data.unpack(writeMak, bootInfoAck, rsvd) != 0 ||
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002182 !data.fullyUnpacked())
2183 {
2184 return ipmi::responseReqDataLenInvalid();
2185 }
2186 if (rsvd)
2187 {
2188 return ipmi::responseInvalidFieldRequest();
2189 }
Hieu Huynh38ffafc2021-05-14 08:40:14 +00002190 bootInitiatorAckData &= ~writeMak;
2191 bootInitiatorAckData |= (writeMak & bootInfoAck);
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002192 log<level::INFO>("ipmiChassisSetSysBootOptions: bootInfo parameter set "
2193 "successfully");
2194 data.trailingOk = true;
2195 return ipmi::responseSuccess();
Patrick Venture0b02be92018-08-31 11:55:55 -07002196 }
Chen Yugang86ac4992021-06-25 08:14:52 +08002197 else if (types::enum_cast<BootOptionParameter>(parameterSelector) ==
2198 BootOptionParameter::bootFlagValidClr)
2199 {
2200 uint5_t bootFlagValidClr;
2201 uint3_t rsvd;
2202
2203 if (data.unpack(bootFlagValidClr, rsvd) != 0 || !data.fullyUnpacked())
2204 {
2205 return ipmi::responseReqDataLenInvalid();
2206 }
2207 if (rsvd)
2208 {
2209 return ipmi::responseInvalidFieldRequest();
2210 }
2211 // store boot flag valid bits clear value
2212 bootFlagValidBitClr = static_cast<uint8_t>(bootFlagValidClr);
2213 log<level::INFO>(
2214 "ipmiChassisSetSysBootOptions: bootFlagValidBits parameter set "
2215 "successfully",
2216 entry("value=0x%x", bootFlagValidBitClr));
2217 return ipmi::responseSuccess();
2218 }
Patrick Venture0b02be92018-08-31 11:55:55 -07002219 else
2220 {
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002221 if ((parameterSelector >= static_cast<uint7_t>(oemParmStart)) &&
2222 (parameterSelector <= static_cast<uint7_t>(oemParmEnd)))
2223 {
William A. Kennington III7a0e5df2021-05-19 13:31:29 -07002224 if (types::enum_cast<BootOptionParameter>(parameterSelector) ==
2225 BootOptionParameter::opalNetworkSettings)
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002226 {
2227 ipmi::Cc ret = setHostNetworkData(data);
2228 if (ret != ipmi::ccSuccess)
2229 {
2230 log<level::ERR>("ipmiChassisSetSysBootOptions: Error in "
2231 "setHostNetworkData");
2232 data.trailingOk = true;
2233 return ipmi::response(ret);
2234 }
2235 data.trailingOk = true;
2236 return ipmi::responseSuccess();
2237 }
2238 else
2239 {
2240 log<level::ERR>(
2241 "ipmiChassisSetSysBootOptions: Unsupported parameters",
2242 entry("PARAM=0x%x",
2243 static_cast<uint8_t>(parameterSelector)));
2244 data.trailingOk = true;
2245 return ipmi::responseParmNotSupported();
2246 }
2247 }
2248 data.trailingOk = true;
2249 return ipmi::responseParmNotSupported();
Adriana Kobylak40814c62015-10-27 15:58:44 -05002250 }
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002251 return ipmi::responseSuccess();
Adriana Kobylak40814c62015-10-27 15:58:44 -05002252}
2253
anil kumar appanaa5a76eb2019-04-30 14:57:24 +00002254/** @brief implements Get POH counter command
2255 * @parameter
2256 * - none
2257 * @returns IPMI completion code plus response data
2258 * - minPerCount - Minutes per count
2259 * - counterReading - counter reading
2260 */
2261ipmi::RspType<uint8_t, // Minutes per count
2262 uint32_t // Counter reading
2263 >
2264 ipmiGetPOHCounter()
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -05002265{
2266 // sd_bus error
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -05002267 try
2268 {
anil kumar appanaa5a76eb2019-04-30 14:57:24 +00002269 return ipmi::responseSuccess(static_cast<uint8_t>(poh::minutesPerCount),
2270 getPOHCounter());
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -05002271 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -05002272 catch (const std::exception& e)
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -05002273 {
2274 log<level::ERR>(e.what());
anil kumar appanaa5a76eb2019-04-30 14:57:24 +00002275 return ipmi::responseUnspecifiedError();
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -05002276 }
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -05002277}
2278
Jason M. Billsbc996a32019-06-17 15:46:37 -07002279ipmi::RspType<uint3_t, // policy support
2280 uint5_t // reserved
2281 >
Vernon Mauerye278ead2018-10-09 09:23:43 -07002282 ipmiChassisSetPowerRestorePolicy(boost::asio::yield_context yield,
Jason M. Billsbc996a32019-06-17 15:46:37 -07002283 uint3_t policy, uint5_t reserved)
Yong Lic6713cf2018-09-12 12:35:13 +08002284{
Yong Lic6713cf2018-09-12 12:35:13 +08002285 power_policy::DbusValue value =
2286 power_policy::RestorePolicy::Policy::AlwaysOff;
2287
Jason M. Billsbc996a32019-06-17 15:46:37 -07002288 if (reserved || (policy > power_policy::noChange))
Yong Lic6713cf2018-09-12 12:35:13 +08002289 {
Vernon Mauerye278ead2018-10-09 09:23:43 -07002290 phosphor::logging::log<level::ERR>(
2291 "Reserved request parameter",
2292 entry("REQ=0x%x", static_cast<int>(policy)));
Jason M. Billsbc996a32019-06-17 15:46:37 -07002293 return ipmi::responseInvalidFieldRequest();
Yong Lic6713cf2018-09-12 12:35:13 +08002294 }
2295
Vernon Mauerye278ead2018-10-09 09:23:43 -07002296 if (policy == power_policy::noChange)
Yong Lic6713cf2018-09-12 12:35:13 +08002297 {
2298 // just return the supported policy
Jason M. Billsbc996a32019-06-17 15:46:37 -07002299 return ipmi::responseSuccess(power_policy::allSupport, reserved);
Yong Lic6713cf2018-09-12 12:35:13 +08002300 }
2301
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05002302 for (const auto& it : power_policy::dbusToIpmi)
Yong Lic6713cf2018-09-12 12:35:13 +08002303 {
Vernon Mauerye278ead2018-10-09 09:23:43 -07002304 if (it.second == policy)
Yong Lic6713cf2018-09-12 12:35:13 +08002305 {
2306 value = it.first;
2307 break;
2308 }
2309 }
2310
2311 try
2312 {
James Feist225dec82019-11-26 16:25:06 -08002313 settings::Objects& objects = chassis::internal::cache::getObjects();
Yong Lic6713cf2018-09-12 12:35:13 +08002314 const settings::Path& powerRestoreSetting =
James Feist225dec82019-11-26 16:25:06 -08002315 objects.map.at(chassis::internal::powerRestoreIntf).front();
Vernon Mauery16b86932019-05-01 08:36:11 -07002316 std::variant<std::string> property = convertForMessage(value);
Yong Lic6713cf2018-09-12 12:35:13 +08002317
Vernon Mauerye278ead2018-10-09 09:23:43 -07002318 auto sdbusp = getSdBus();
2319 boost::system::error_code ec;
2320 sdbusp->yield_method_call<void>(
2321 yield, ec,
James Feist225dec82019-11-26 16:25:06 -08002322 objects
Yong Lic6713cf2018-09-12 12:35:13 +08002323 .service(powerRestoreSetting,
2324 chassis::internal::powerRestoreIntf)
2325 .c_str(),
Vernon Mauerye278ead2018-10-09 09:23:43 -07002326 powerRestoreSetting, ipmi::PROP_INTF, "Set",
2327 chassis::internal::powerRestoreIntf, "PowerRestorePolicy",
2328 property);
2329 if (ec)
Yong Lic6713cf2018-09-12 12:35:13 +08002330 {
2331 phosphor::logging::log<level::ERR>("Unspecified Error");
Vernon Mauerye278ead2018-10-09 09:23:43 -07002332 return ipmi::responseUnspecifiedError();
Yong Lic6713cf2018-09-12 12:35:13 +08002333 }
2334 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -05002335 catch (const InternalFailure& e)
Yong Lic6713cf2018-09-12 12:35:13 +08002336 {
James Feist225dec82019-11-26 16:25:06 -08002337 chassis::internal::cache::objectsPtr.reset();
Yong Lic6713cf2018-09-12 12:35:13 +08002338 report<InternalFailure>();
Vernon Mauerye278ead2018-10-09 09:23:43 -07002339 return ipmi::responseUnspecifiedError();
Yong Lic6713cf2018-09-12 12:35:13 +08002340 }
2341
Jason M. Billsbc996a32019-06-17 15:46:37 -07002342 return ipmi::responseSuccess(power_policy::allSupport, reserved);
Yong Lic6713cf2018-09-12 12:35:13 +08002343}
2344
Willy Tu11d68892022-01-20 10:37:34 -08002345ipmi::RspType<> ipmiSetFrontPanelButtonEnables(ipmi::Context::ptr ctx,
2346 bool disablePowerButton,
2347 bool disableResetButton, bool,
2348 bool, uint4_t)
Kuiying Wang21addc52019-01-04 10:50:21 +08002349{
2350 using namespace chassis::internal;
2351
2352 // set power button Enabled property
2353 bool success = setButtonEnabled(ctx, powerButtonPath, powerButtonIntf,
2354 !disablePowerButton);
2355
2356 // set reset button Enabled property
2357 success &= setButtonEnabled(ctx, resetButtonPath, resetButtonIntf,
2358 !disableResetButton);
2359
2360 if (!success)
2361 {
2362 // not all buttons were successfully set
2363 return ipmi::responseUnspecifiedError();
2364 }
2365 return ipmi::responseSuccess();
2366}
2367
Adriana Kobylak40814c62015-10-27 15:58:44 -05002368void register_netfn_chassis_functions()
2369{
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05002370 createIdentifyTimer();
2371
Tom05732372016-09-06 17:21:23 +05302372 // Get Chassis Capabilities
anil kumar appana43263c62019-05-27 12:45:04 +00002373 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis,
2374 ipmi::chassis::cmdGetChassisCapabilities,
2375 ipmi::Privilege::User, ipmiGetChassisCap);
Nan Li8d15fb42016-08-16 22:29:40 +08002376
Kuiying Wang21addc52019-01-04 10:50:21 +08002377 // Set Front Panel Button Enables
2378 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis,
2379 ipmi::chassis::cmdSetFrontPanelButtonEnables,
2380 ipmi::Privilege::Admin,
2381 ipmiSetFrontPanelButtonEnables);
2382
Yong Liae4b0402018-11-02 11:12:14 +08002383 // Set Chassis Capabilities
anil kumar appana894d0222019-05-27 16:32:14 +00002384 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis,
2385 ipmi::chassis::cmdSetChassisCapabilities,
2386 ipmi::Privilege::User, ipmiSetChassisCap);
Yong Liae4b0402018-11-02 11:12:14 +08002387
Tom05732372016-09-06 17:21:23 +05302388 // <Get System Boot Options>
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00002389 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis,
2390 ipmi::chassis::cmdGetSystemBootOptions,
2391 ipmi::Privilege::Operator,
2392 ipmiChassisGetSysBootOptions);
Adriana Kobylak40814c62015-10-27 15:58:44 -05002393
Tom05732372016-09-06 17:21:23 +05302394 // <Get Chassis Status>
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07002395 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis,
2396 ipmi::chassis::cmdGetChassisStatus,
2397 ipmi::Privilege::User, ipmiGetChassisStatus);
Nan Lifdd8ec52016-08-28 03:57:40 +08002398
Vijay Khemka074f64d2020-03-03 15:08:43 -08002399 // <Chassis Get System Restart Cause>
2400 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis,
2401 ipmi::chassis::cmdGetSystemRestartCause,
2402 ipmi::Privilege::User, ipmiGetSystemRestartCause);
2403
Tom05732372016-09-06 17:21:23 +05302404 // <Chassis Control>
anil kumar appanadafff5f2019-04-27 18:06:00 +00002405 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis,
2406 ipmi::chassis::cmdChassisControl,
2407 ipmi::Privilege::Operator, ipmiChassisControl);
shgoupfd84fbbf2015-12-17 10:05:51 +08002408
Tom Joseph5110c122018-03-23 17:55:40 +05302409 // <Chassis Identify>
Vernon Mauery400cc782018-10-09 13:49:53 -07002410 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis,
2411 ipmi::chassis::cmdChassisIdentify,
2412 ipmi::Privilege::Operator, ipmiChassisIdentify);
Tom Joseph5110c122018-03-23 17:55:40 +05302413
Tom05732372016-09-06 17:21:23 +05302414 // <Set System Boot Options>
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002415 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis,
2416 ipmi::chassis::cmdSetSystemBootOptions,
2417 ipmi::Privilege::Operator,
2418 ipmiChassisSetSysBootOptions);
2419
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -05002420 // <Get POH Counter>
anil kumar appanaa5a76eb2019-04-30 14:57:24 +00002421 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis,
2422 ipmi::chassis::cmdGetPohCounter,
2423 ipmi::Privilege::User, ipmiGetPOHCounter);
Yong Lic6713cf2018-09-12 12:35:13 +08002424
2425 // <Set Power Restore Policy>
Vernon Mauerye278ead2018-10-09 09:23:43 -07002426 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis,
2427 ipmi::chassis::cmdSetPowerRestorePolicy,
2428 ipmi::Privilege::Operator,
2429 ipmiChassisSetPowerRestorePolicy);
vishwa36993272015-11-20 12:43:49 -06002430}