blob: d4f2cf70115b2b4786b3de7eb52274002df925f0 [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>
Vernon Mauery38108d92024-03-11 12:53:55 -070014#include <phosphor-logging/lg2.hpp>
Patrick Venture3a5071a2018-09-12 13:27:42 -070015#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;
43
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +000044constexpr size_t sizeVersion = 2;
Tom Joseph5110c122018-03-23 17:55:40 +053045constexpr size_t DEFAULT_IDENTIFY_TIME_OUT = 15;
Ratan Gupta6ec7daa2017-07-15 14:13:01 +053046
Patrick Venture0b02be92018-08-31 11:55:55 -070047// PetiBoot-Specific
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +000048static constexpr uint8_t netConfInitialBytes[] = {0x80, 0x21, 0x70, 0x62,
49 0x21, 0x00, 0x01, 0x06};
50static constexpr uint8_t oemParmStart = 96;
51static constexpr uint8_t oemParmEnd = 127;
Ratan Guptafd28dd72016-08-01 04:58:01 -050052
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +000053static constexpr size_t cookieOffset = 1;
54static constexpr size_t versionOffset = 5;
55static constexpr size_t addrSizeOffset = 8;
56static constexpr size_t macOffset = 9;
57static constexpr size_t addrTypeOffset = 16;
58static constexpr size_t ipAddrOffset = 17;
ratagupta6f6bff2016-04-04 06:20:11 -050059
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +000060namespace ipmi
61{
62constexpr Cc ccParmNotSupported = 0x80;
63
64static inline auto responseParmNotSupported()
65{
66 return response(ccParmNotSupported);
67}
68} // namespace ipmi
69
Adriana Kobylak40814c62015-10-27 15:58:44 -050070void register_netfn_chassis_functions() __attribute__((constructor));
71
shgoupfd84fbbf2015-12-17 10:05:51 +080072// Host settings in dbus
73// Service name should be referenced by connection name got via object mapper
Patrick Venture0b02be92018-08-31 11:55:55 -070074const char* settings_object_name = "/org/openbmc/settings/host0";
75const char* settings_intf_name = "org.freedesktop.DBus.Properties";
Patrick Venture0b02be92018-08-31 11:55:55 -070076const char* identify_led_object_name =
Tom Joseph5110c122018-03-23 17:55:40 +053077 "/xyz/openbmc_project/led/groups/enclosure_identify";
shgoupfd84fbbf2015-12-17 10:05:51 +080078
Ratan Guptadcb10672017-07-10 10:33:50 +053079constexpr auto SETTINGS_ROOT = "/";
80constexpr auto SETTINGS_MATCH = "host0";
Ratan Guptadcb10672017-07-10 10:33:50 +053081
82constexpr auto IP_INTERFACE = "xyz.openbmc_project.Network.IP";
83constexpr auto MAC_INTERFACE = "xyz.openbmc_project.Network.MACAddress";
84
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -050085static constexpr auto chassisStateRoot = "/xyz/openbmc_project/state";
86static constexpr auto chassisPOHStateIntf =
Patrick Venture0b02be92018-08-31 11:55:55 -070087 "xyz.openbmc_project.State.PowerOnHours";
Patrick Williams7345ac42021-04-30 20:57:39 -050088static constexpr auto pohCounterProperty = "POHCounter";
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -050089static constexpr auto match = "chassis0";
Yong Liae4b0402018-11-02 11:12:14 +080090const static constexpr char chassisCapIntf[] =
91 "xyz.openbmc_project.Control.ChassisCapabilities";
Karthick Sundarrajan86d8bd72019-11-26 12:48:50 -080092const static constexpr char chassisIntrusionProp[] = "ChassisIntrusionEnabled";
93const static constexpr char chassisFrontPanelLockoutProp[] =
94 "ChassisFrontPanelLockoutEnabled";
95const static constexpr char chassisNMIProp[] = "ChassisNMIEnabled";
96const static constexpr char chassisPowerInterlockProp[] =
97 "ChassisPowerInterlockEnabled";
Yong Liae4b0402018-11-02 11:12:14 +080098const static constexpr char chassisFRUDevAddrProp[] = "FRUDeviceAddress";
99const static constexpr char chassisSDRDevAddrProp[] = "SDRDeviceAddress";
100const static constexpr char chassisSELDevAddrProp[] = "SELDeviceAddress";
101const static constexpr char chassisSMDevAddrProp[] = "SMDeviceAddress";
102const static constexpr char chassisBridgeDevAddrProp[] = "BridgeDeviceAddress";
Yong Liae4b0402018-11-02 11:12:14 +0800103static constexpr uint8_t chassisCapAddrMask = 0xfe;
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700104static constexpr const char* powerButtonIntf =
105 "xyz.openbmc_project.Chassis.Buttons.Power";
106static constexpr const char* powerButtonPath =
107 "/xyz/openbmc_project/Chassis/Buttons/Power0";
108static constexpr const char* resetButtonIntf =
109 "xyz.openbmc_project.Chassis.Buttons.Reset";
110static constexpr const char* resetButtonPath =
111 "/xyz/openbmc_project/Chassis/Buttons/Reset0";
Ratan Guptadcb10672017-07-10 10:33:50 +0530112
Vishwanatha Subbannab12b0c02017-03-07 18:17:19 +0530113// Phosphor Host State manager
Willy Tu523e2d12023-09-05 11:36:48 -0700114namespace State = sdbusplus::server::xyz::openbmc_project::state;
Vernon Mauery185b9f82018-07-20 10:52:36 -0700115namespace fs = std::filesystem;
Andrew Geisslera6e3a302017-05-31 19:34:00 -0500116
Ratan Guptadcb10672017-07-10 10:33:50 +0530117using namespace phosphor::logging;
Willy Tu523e2d12023-09-05 11:36:48 -0700118using namespace sdbusplus::error::xyz::openbmc_project::common;
119using namespace sdbusplus::server::xyz::openbmc_project::control::boot;
William A. Kennington III4c008022018-10-12 17:18:14 -0700120
Deepak Kodihalli8cc19362017-07-21 11:18:38 -0500121namespace chassis
122{
123namespace internal
124{
125
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +0300126constexpr auto bootSettingsPath = "/xyz/openbmc_project/control/host0/boot";
127constexpr auto bootEnableIntf = "xyz.openbmc_project.Object.Enable";
Deepak Kodihalli8cc19362017-07-21 11:18:38 -0500128constexpr auto bootModeIntf = "xyz.openbmc_project.Control.Boot.Mode";
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +0300129constexpr auto bootTypeIntf = "xyz.openbmc_project.Control.Boot.Type";
Deepak Kodihalli8cc19362017-07-21 11:18:38 -0500130constexpr auto bootSourceIntf = "xyz.openbmc_project.Control.Boot.Source";
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +0300131constexpr auto bootSettingsOneTimePath =
132 "/xyz/openbmc_project/control/host0/boot/one_time";
133constexpr auto bootOneTimeIntf = "xyz.openbmc_project.Object.Enable";
134
Deepak Kodihalli18b70d12017-07-21 13:36:33 -0500135constexpr auto powerRestoreIntf =
136 "xyz.openbmc_project.Control.Power.RestorePolicy";
Patrick Williams5d82f472022-07-22 19:26:53 -0500137sdbusplus::bus_t dbus(ipmid_get_sd_bus_connection());
Deepak Kodihalli8cc19362017-07-21 11:18:38 -0500138
139namespace cache
140{
141
James Feist225dec82019-11-26 16:25:06 -0800142std::unique_ptr<settings::Objects> objectsPtr = nullptr;
143
144settings::Objects& getObjects()
145{
146 if (objectsPtr == nullptr)
147 {
148 objectsPtr = std::make_unique<settings::Objects>(
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +0300149 dbus, std::vector<std::string>{bootModeIntf, bootTypeIntf,
150 bootSourceIntf, powerRestoreIntf});
James Feist225dec82019-11-26 16:25:06 -0800151 }
152 return *objectsPtr;
153}
Deepak Kodihalli8cc19362017-07-21 11:18:38 -0500154
155} // namespace cache
156} // namespace internal
157} // namespace chassis
158
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -0500159namespace poh
160{
161
162constexpr auto minutesPerCount = 60;
163
164} // namespace poh
165
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000166int getHostNetworkData(ipmi::message::Payload& payload)
Ratan Guptafd28dd72016-08-01 04:58:01 -0500167{
Ratan Guptadcb10672017-07-10 10:33:50 +0530168 ipmi::PropertyMap properties;
169 int rc = 0;
Ratan Gupta8c31d232017-08-13 05:49:43 +0530170 uint8_t addrSize = ipmi::network::IPV4_ADDRESS_SIZE_BYTE;
Ratan Guptafd28dd72016-08-01 04:58:01 -0500171
Ratan Guptadcb10672017-07-10 10:33:50 +0530172 try
173 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700174 // TODO There may be cases where an interface is implemented by multiple
Ratan Guptadcb10672017-07-10 10:33:50 +0530175 // objects,to handle such cases we are interested on that object
176 // which are on interested busname.
177 // Currenlty mapper doesn't give the readable busname(gives busid)
178 // so we can't match with bus name so giving some object specific info
179 // as SETTINGS_MATCH.
180 // Later SETTINGS_MATCH will be replaced with busname.
Ratan Guptafd28dd72016-08-01 04:58:01 -0500181
Patrick Williams5d82f472022-07-22 19:26:53 -0500182 sdbusplus::bus_t bus(ipmid_get_sd_bus_connection());
Ratan Guptadcb10672017-07-10 10:33:50 +0530183
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530184 auto ipObjectInfo = ipmi::getDbusObject(bus, IP_INTERFACE,
185 SETTINGS_ROOT, SETTINGS_MATCH);
186
187 auto macObjectInfo = ipmi::getDbusObject(bus, MAC_INTERFACE,
188 SETTINGS_ROOT, SETTINGS_MATCH);
189
Patrick Venture0b02be92018-08-31 11:55:55 -0700190 properties = ipmi::getAllDbusProperties(
191 bus, ipObjectInfo.second, ipObjectInfo.first, IP_INTERFACE);
Patrick Williams1318a5e2024-08-16 15:19:54 -0400192 auto variant = ipmi::getDbusProperty(
193 bus, macObjectInfo.second, macObjectInfo.first, MAC_INTERFACE,
194 "MACAddress");
Ratan Guptadcb10672017-07-10 10:33:50 +0530195
Vernon Maueryf442e112019-04-09 11:44:36 -0700196 auto ipAddress = std::get<std::string>(properties["Address"]);
Ratan Guptad70f4532017-08-04 02:07:31 +0530197
Vernon Maueryf442e112019-04-09 11:44:36 -0700198 auto gateway = std::get<std::string>(properties["Gateway"]);
Ratan Guptad70f4532017-08-04 02:07:31 +0530199
Vernon Maueryf442e112019-04-09 11:44:36 -0700200 auto prefix = std::get<uint8_t>(properties["PrefixLength"]);
Ratan Guptad70f4532017-08-04 02:07:31 +0530201
Patrick Venture0b02be92018-08-31 11:55:55 -0700202 uint8_t isStatic =
Vernon Maueryf442e112019-04-09 11:44:36 -0700203 (std::get<std::string>(properties["Origin"]) ==
Patrick Venture0b02be92018-08-31 11:55:55 -0700204 "xyz.openbmc_project.Network.IP.AddressOrigin.Static")
205 ? 1
206 : 0;
Ratan Guptad70f4532017-08-04 02:07:31 +0530207
Vernon Maueryf442e112019-04-09 11:44:36 -0700208 auto MACAddress = std::get<std::string>(variant);
Ratan Guptacc8feb42017-07-25 21:52:10 +0530209
Ratan Guptad70f4532017-08-04 02:07:31 +0530210 // it is expected here that we should get the valid data
211 // but we may also get the default values.
212 // Validation of the data is done by settings.
213 //
214 // if mac address is default mac address then
215 // don't send blank override.
Ratan Gupta8c31d232017-08-13 05:49:43 +0530216 if ((MACAddress == ipmi::network::DEFAULT_MAC_ADDRESS))
Ratan Guptad70f4532017-08-04 02:07:31 +0530217 {
Ratan Guptad70f4532017-08-04 02:07:31 +0530218 rc = -1;
219 return rc;
220 }
221 // if addr is static then ipaddress,gateway,prefix
222 // should not be default one,don't send blank override.
223 if (isStatic)
224 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700225 if ((ipAddress == ipmi::network::DEFAULT_ADDRESS) ||
226 (gateway == ipmi::network::DEFAULT_ADDRESS) || (!prefix))
Ratan Guptad70f4532017-08-04 02:07:31 +0530227 {
Ratan Guptad70f4532017-08-04 02:07:31 +0530228 rc = -1;
229 return rc;
230 }
231 }
232
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000233 std::string token;
234 std::stringstream ss(MACAddress);
Ratan Guptadcb10672017-07-10 10:33:50 +0530235
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000236 // First pack macOffset no of bytes in payload.
237 // Latter this PetiBoot-Specific data will be populated.
238 std::vector<uint8_t> payloadInitialBytes(macOffset);
239 payload.pack(payloadInitialBytes);
Ratan Guptadcb10672017-07-10 10:33:50 +0530240
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000241 while (std::getline(ss, token, ':'))
242 {
243 payload.pack(stoi(token, nullptr, 16));
244 }
245
246 payload.pack(0x00);
247
248 payload.pack(isStatic);
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530249
Vernon Maueryf442e112019-04-09 11:44:36 -0700250 uint8_t addressFamily = (std::get<std::string>(properties["Type"]) ==
251 "xyz.openbmc_project.Network.IP.Protocol.IPv4")
252 ? AF_INET
253 : AF_INET6;
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530254
Patrick Venture0b02be92018-08-31 11:55:55 -0700255 addrSize = (addressFamily == AF_INET)
256 ? ipmi::network::IPV4_ADDRESS_SIZE_BYTE
257 : ipmi::network::IPV6_ADDRESS_SIZE_BYTE;
Ratan Guptadcb10672017-07-10 10:33:50 +0530258
259 // ipaddress and gateway would be in IPv4 format
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000260 std::vector<uint8_t> addrInBinary(addrSize);
Ratan Guptad70f4532017-08-04 02:07:31 +0530261 inet_pton(addressFamily, ipAddress.c_str(),
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000262 reinterpret_cast<void*>(addrInBinary.data()));
Ratan Guptadcb10672017-07-10 10:33:50 +0530263
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000264 payload.pack(addrInBinary);
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530265
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000266 payload.pack(prefix);
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530267
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000268 std::vector<uint8_t> gatewayDetails(addrSize);
Ratan Guptad70f4532017-08-04 02:07:31 +0530269 inet_pton(addressFamily, gateway.c_str(),
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000270 reinterpret_cast<void*>(gatewayDetails.data()));
271 payload.pack(gatewayDetails);
Ratan Guptadcb10672017-07-10 10:33:50 +0530272 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -0500273 catch (const InternalFailure& e)
Ratan Guptadcb10672017-07-10 10:33:50 +0530274 {
275 commit<InternalFailure>();
Ratan Guptadcb10672017-07-10 10:33:50 +0530276 rc = -1;
Ratan Guptafd28dd72016-08-01 04:58:01 -0500277 return rc;
278 }
279
Patrick Venture0b02be92018-08-31 11:55:55 -0700280 // PetiBoot-Specific
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000281 // If success then copy the first 9 bytes to the payload message
282 // payload first 2 bytes contain the parameter values. Skip that 2 bytes.
283 uint8_t skipFirstTwoBytes = 2;
284 size_t payloadSize = payload.size();
285 uint8_t* configDataStartingAddress = payload.data() + skipFirstTwoBytes;
Ratan Guptafd28dd72016-08-01 04:58:01 -0500286
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000287 if (payloadSize < skipFirstTwoBytes + sizeof(netConfInitialBytes))
288 {
Vernon Mauery38108d92024-03-11 12:53:55 -0700289 lg2::error("Invalid net config");
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000290 rc = -1;
291 return rc;
292 }
293 std::copy(netConfInitialBytes,
294 netConfInitialBytes + sizeof(netConfInitialBytes),
295 configDataStartingAddress);
296
297 if (payloadSize < skipFirstTwoBytes + addrSizeOffset + sizeof(addrSize))
298 {
Vernon Mauery38108d92024-03-11 12:53:55 -0700299 lg2::error("Invalid length of address size");
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000300 rc = -1;
301 return rc;
302 }
303 std::copy(&addrSize, &(addrSize) + sizeof(addrSize),
304 configDataStartingAddress + addrSizeOffset);
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530305
Ratan Guptafd28dd72016-08-01 04:58:01 -0500306#ifdef _IPMI_DEBUG_
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700307 std::printf("\n===Printing the IPMI Formatted Data========\n");
Ratan Guptafd28dd72016-08-01 04:58:01 -0500308
Ratan Guptadcb10672017-07-10 10:33:50 +0530309 for (uint8_t pos = 0; pos < index; pos++)
310 {
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000311 std::printf("%02x ", payloadStartingAddress[pos]);
Ratan Guptadcb10672017-07-10 10:33:50 +0530312 }
Ratan Guptafd28dd72016-08-01 04:58:01 -0500313#endif
314
Ratan Guptafd28dd72016-08-01 04:58:01 -0500315 return rc;
316}
317
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530318/** @brief convert IPv4 and IPv6 addresses from binary to text form.
319 * @param[in] family - IPv4/Ipv6
320 * @param[in] data - req data pointer.
321 * @param[in] offset - offset in the data.
322 * @param[in] addrSize - size of the data which needs to be read from offset.
323 * @returns address in text form.
324 */
325
Patrick Venture0b02be92018-08-31 11:55:55 -0700326std::string getAddrStr(uint8_t family, uint8_t* data, uint8_t offset,
327 uint8_t addrSize)
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530328{
329 char ipAddr[INET6_ADDRSTRLEN] = {};
330
Patrick Venture0b02be92018-08-31 11:55:55 -0700331 switch (family)
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530332 {
333 case AF_INET:
334 {
Patrick Williams99db6882024-12-18 11:20:17 -0500335 struct sockaddr_in addr4{};
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700336 std::memcpy(&addr4.sin_addr.s_addr, &data[offset], addrSize);
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530337
Patrick Venture0b02be92018-08-31 11:55:55 -0700338 inet_ntop(AF_INET, &addr4.sin_addr, ipAddr, INET_ADDRSTRLEN);
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530339
340 break;
341 }
342 case AF_INET6:
343 {
Patrick Williams99db6882024-12-18 11:20:17 -0500344 struct sockaddr_in6 addr6{};
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700345 std::memcpy(&addr6.sin6_addr.s6_addr, &data[offset], addrSize);
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530346
Patrick Venture0b02be92018-08-31 11:55:55 -0700347 inet_ntop(AF_INET6, &addr6.sin6_addr, ipAddr, INET6_ADDRSTRLEN);
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530348
349 break;
350 }
351 default:
352 {
353 return {};
354 }
355 }
356
357 return ipAddr;
358}
359
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000360ipmi::Cc setHostNetworkData(ipmi::message::Payload& data)
Ratan Guptafd28dd72016-08-01 04:58:01 -0500361{
Ratan Guptadcb10672017-07-10 10:33:50 +0530362 using namespace std::string_literals;
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000363 std::string hostNetworkConfig;
364 std::string mac("00:00:00:00:00:00");
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530365 std::string ipAddress, gateway;
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000366 std::string addrOrigin{0};
Patrick Venture0b02be92018-08-31 11:55:55 -0700367 uint8_t addrSize{0};
Ratan Guptadcb10672017-07-10 10:33:50 +0530368 std::string addressOrigin =
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530369 "xyz.openbmc_project.Network.IP.AddressOrigin.DHCP";
Patrick Venture0b02be92018-08-31 11:55:55 -0700370 std::string addressType = "xyz.openbmc_project.Network.IP.Protocol.IPv4";
371 uint8_t prefix{0};
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530372 uint8_t family = AF_INET;
Ratan Guptafd28dd72016-08-01 04:58:01 -0500373
Patrick Venture0b02be92018-08-31 11:55:55 -0700374 // cookie starts from second byte
Ratan Guptafd28dd72016-08-01 04:58:01 -0500375 // version starts from sixth byte
376
Ratan Guptadcb10672017-07-10 10:33:50 +0530377 try
Ratan Guptafd28dd72016-08-01 04:58:01 -0500378 {
Ratan Guptadcb10672017-07-10 10:33:50 +0530379 do
380 {
381 // cookie == 0x21 0x70 0x62 0x21
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000382 data.trailingOk = true;
383 auto msgLen = data.size();
384 std::vector<uint8_t> msgPayloadBytes(msgLen);
385 if (data.unpack(msgPayloadBytes) != 0 || !data.fullyUnpacked())
Ratan Guptadcb10672017-07-10 10:33:50 +0530386 {
Vernon Mauery38108d92024-03-11 12:53:55 -0700387 lg2::error("Error in unpacking message of setHostNetworkData");
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000388 return ipmi::ccReqDataLenInvalid;
389 }
390
391 uint8_t* msgPayloadStartingPos = msgPayloadBytes.data();
392 constexpr size_t cookieSize = 4;
393 if (msgLen < cookieOffset + cookieSize)
394 {
Vernon Mauery38108d92024-03-11 12:53:55 -0700395 lg2::error("Error in cookie getting of setHostNetworkData");
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000396 return ipmi::ccReqDataLenInvalid;
397 }
398 if (std::equal(msgPayloadStartingPos + cookieOffset,
399 msgPayloadStartingPos + cookieOffset + cookieSize,
400 (netConfInitialBytes + cookieOffset)) != 0)
401 {
402 // all cookie == 0
403 if (std::all_of(msgPayloadStartingPos + cookieOffset,
404 msgPayloadStartingPos + cookieOffset +
405 cookieSize,
406 [](int i) { return i == 0; }) == true)
Ratan Guptadcb10672017-07-10 10:33:50 +0530407 {
408 // need to zero out the network settings.
409 break;
410 }
411
Vernon Mauery38108d92024-03-11 12:53:55 -0700412 lg2::error("Invalid Cookie");
Ratan Guptadcb10672017-07-10 10:33:50 +0530413 elog<InternalFailure>();
414 }
415
416 // vesion == 0x00 0x01
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000417 if (msgLen < versionOffset + sizeVersion)
Ratan Guptadcb10672017-07-10 10:33:50 +0530418 {
Vernon Mauery38108d92024-03-11 12:53:55 -0700419 lg2::error("Error in version getting of setHostNetworkData");
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000420 return ipmi::ccReqDataLenInvalid;
421 }
422 if (std::equal(msgPayloadStartingPos + versionOffset,
423 msgPayloadStartingPos + versionOffset + sizeVersion,
424 (netConfInitialBytes + versionOffset)) != 0)
425 {
Vernon Mauery38108d92024-03-11 12:53:55 -0700426 lg2::error("Invalid Version");
Ratan Guptadcb10672017-07-10 10:33:50 +0530427 elog<InternalFailure>();
428 }
429
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000430 if (msgLen < macOffset + 6)
431 {
Vernon Mauery38108d92024-03-11 12:53:55 -0700432 lg2::error(
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000433 "Error in mac address getting of setHostNetworkData");
434 return ipmi::ccReqDataLenInvalid;
435 }
436 std::stringstream result;
437 std::copy((msgPayloadStartingPos + macOffset),
438 (msgPayloadStartingPos + macOffset + 5),
439 std::ostream_iterator<int>(result, ":"));
440 mac = result.str();
Ratan Guptadcb10672017-07-10 10:33:50 +0530441
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000442 if (msgLen < addrTypeOffset + sizeof(decltype(addrOrigin)))
443 {
Vernon Mauery38108d92024-03-11 12:53:55 -0700444 lg2::error(
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000445 "Error in original address getting of setHostNetworkData");
446 return ipmi::ccReqDataLenInvalid;
447 }
448 std::copy(msgPayloadStartingPos + addrTypeOffset,
449 msgPayloadStartingPos + addrTypeOffset +
450 sizeof(decltype(addrOrigin)),
451 std::ostream_iterator<int>(result, ""));
452 addrOrigin = result.str();
Ratan Guptadcb10672017-07-10 10:33:50 +0530453
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000454 if (!addrOrigin.empty())
Ratan Guptadcb10672017-07-10 10:33:50 +0530455 {
456 addressOrigin =
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530457 "xyz.openbmc_project.Network.IP.AddressOrigin.Static";
Ratan Guptadcb10672017-07-10 10:33:50 +0530458 }
459
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000460 if (msgLen < addrSizeOffset + sizeof(decltype(addrSize)))
461 {
Vernon Mauery38108d92024-03-11 12:53:55 -0700462 lg2::error(
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000463 "Error in address size getting of setHostNetworkData");
464 return ipmi::ccReqDataLenInvalid;
465 }
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530466 // Get the address size
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000467 std::copy(msgPayloadStartingPos + addrSizeOffset,
468 (msgPayloadStartingPos + addrSizeOffset +
469 sizeof(decltype(addrSize))),
470 &addrSize);
Ratan Guptadcb10672017-07-10 10:33:50 +0530471
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000472 uint8_t prefixOffset = ipAddrOffset + addrSize;
473 if (msgLen < prefixOffset + sizeof(decltype(prefix)))
474 {
Vernon Mauery38108d92024-03-11 12:53:55 -0700475 lg2::error("Error in prefix getting of setHostNetworkData");
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000476 return ipmi::ccReqDataLenInvalid;
477 }
William A. Kennington III4c521022023-07-28 13:07:30 -0700478 // std::copy(msgPayloadStartingPos + prefixOffset,
479 // msgPayloadStartingPos + prefixOffset +
480 // sizeof(decltype(prefix)),
481 // &prefix);
482 // Workaround compiler misdetecting out of bounds memcpy
483 prefix = msgPayloadStartingPos[prefixOffset];
Ratan Guptadcb10672017-07-10 10:33:50 +0530484
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530485 uint8_t gatewayOffset = prefixOffset + sizeof(decltype(prefix));
Ratan Gupta8c31d232017-08-13 05:49:43 +0530486 if (addrSize != ipmi::network::IPV4_ADDRESS_SIZE_BYTE)
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530487 {
488 addressType = "xyz.openbmc_project.Network.IP.Protocol.IPv6";
489 family = AF_INET6;
490 }
491
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000492 if (msgLen < ipAddrOffset + addrSize)
493 {
Vernon Mauery38108d92024-03-11 12:53:55 -0700494 lg2::error("Error in IP address getting of setHostNetworkData");
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000495 return ipmi::ccReqDataLenInvalid;
496 }
497 ipAddress = getAddrStr(family, msgPayloadStartingPos, ipAddrOffset,
498 addrSize);
Ratan Guptad70f4532017-08-04 02:07:31 +0530499
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000500 if (msgLen < gatewayOffset + addrSize)
501 {
Vernon Mauery38108d92024-03-11 12:53:55 -0700502 lg2::error(
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000503 "Error in gateway address getting of setHostNetworkData");
504 return ipmi::ccReqDataLenInvalid;
505 }
506 gateway = getAddrStr(family, msgPayloadStartingPos, gatewayOffset,
507 addrSize);
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530508
Patrick Venture0b02be92018-08-31 11:55:55 -0700509 } while (0);
Ratan Guptadcb10672017-07-10 10:33:50 +0530510
Patrick Venture0b02be92018-08-31 11:55:55 -0700511 // Cookie == 0 or it is a valid cookie
Patrick Williams1318a5e2024-08-16 15:19:54 -0400512 hostNetworkConfig +=
513 "ipaddress="s + ipAddress + ",prefix="s + std::to_string(prefix) +
514 ",gateway="s + gateway + ",mac="s + mac + ",addressOrigin="s +
515 addressOrigin;
Ratan Guptafd28dd72016-08-01 04:58:01 -0500516
Patrick Williams5d82f472022-07-22 19:26:53 -0500517 sdbusplus::bus_t bus(ipmid_get_sd_bus_connection());
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530518
519 auto ipObjectInfo = ipmi::getDbusObject(bus, IP_INTERFACE,
520 SETTINGS_ROOT, SETTINGS_MATCH);
521 auto macObjectInfo = ipmi::getDbusObject(bus, MAC_INTERFACE,
522 SETTINGS_ROOT, SETTINGS_MATCH);
Ratan Guptadcb10672017-07-10 10:33:50 +0530523 // set the dbus property
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530524 ipmi::setDbusProperty(bus, ipObjectInfo.second, ipObjectInfo.first,
Patrick Venture0b02be92018-08-31 11:55:55 -0700525 IP_INTERFACE, "Address", std::string(ipAddress));
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530526 ipmi::setDbusProperty(bus, ipObjectInfo.second, ipObjectInfo.first,
Patrick Venture0b02be92018-08-31 11:55:55 -0700527 IP_INTERFACE, "PrefixLength", prefix);
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530528 ipmi::setDbusProperty(bus, ipObjectInfo.second, ipObjectInfo.first,
Patrick Venture0b02be92018-08-31 11:55:55 -0700529 IP_INTERFACE, "Origin", addressOrigin);
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530530 ipmi::setDbusProperty(bus, ipObjectInfo.second, ipObjectInfo.first,
Patrick Venture0b02be92018-08-31 11:55:55 -0700531 IP_INTERFACE, "Gateway", std::string(gateway));
532 ipmi::setDbusProperty(
533 bus, ipObjectInfo.second, ipObjectInfo.first, IP_INTERFACE, "Type",
534 std::string("xyz.openbmc_project.Network.IP.Protocol.IPv4"));
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530535 ipmi::setDbusProperty(bus, macObjectInfo.second, macObjectInfo.first,
Patrick Venture0b02be92018-08-31 11:55:55 -0700536 MAC_INTERFACE, "MACAddress", std::string(mac));
Ratan Guptafd28dd72016-08-01 04:58:01 -0500537
Vernon Mauery38108d92024-03-11 12:53:55 -0700538 lg2::debug("Network configuration changed: {NETWORKCONFIG}",
539 "NETWORKCONFIG", hostNetworkConfig);
Ratan Guptafd28dd72016-08-01 04:58:01 -0500540 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -0500541 catch (const sdbusplus::exception_t& e)
Ratan Guptadcb10672017-07-10 10:33:50 +0530542 {
543 commit<InternalFailure>();
Vernon Mauery38108d92024-03-11 12:53:55 -0700544 lg2::error("Error in ipmiChassisSetSysBootOptions call");
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000545 return ipmi::ccUnspecifiedError;
Ratan Guptadcb10672017-07-10 10:33:50 +0530546 }
547
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000548 return ipmi::ccSuccess;
Ratan Guptafd28dd72016-08-01 04:58:01 -0500549}
550
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -0500551uint32_t getPOHCounter()
552{
Patrick Williams5d82f472022-07-22 19:26:53 -0500553 sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()};
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -0500554
Patrick Williams1318a5e2024-08-16 15:19:54 -0400555 auto chassisStateObj =
556 ipmi::getDbusObject(bus, chassisPOHStateIntf, chassisStateRoot, match);
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -0500557
Patrick Williams1318a5e2024-08-16 15:19:54 -0400558 auto service =
559 ipmi::getService(bus, chassisPOHStateIntf, chassisStateObj.first);
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -0500560
Patrick Williams1318a5e2024-08-16 15:19:54 -0400561 auto propValue =
562 ipmi::getDbusProperty(bus, service, chassisStateObj.first,
563 chassisPOHStateIntf, pohCounterProperty);
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -0500564
Vernon Maueryf442e112019-04-09 11:44:36 -0700565 return std::get<uint32_t>(propValue);
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -0500566}
567
anil kumar appana43263c62019-05-27 12:45:04 +0000568/** @brief Implements the get chassis capabilities command
569 *
570 * @returns IPMI completion code plus response data
571 * chassisCapFlags - chassis capability flag
572 * chassisFRUInfoDevAddr - chassis FRU info Device Address
573 * chassisSDRDevAddr - chassis SDR device address
574 * chassisSELDevAddr - chassis SEL device address
575 * chassisSMDevAddr - chassis system management device address
576 * chassisBridgeDevAddr - chassis bridge device address
577 */
Karthick Sundarrajan86d8bd72019-11-26 12:48:50 -0800578ipmi::RspType<bool, // chassis intrusion sensor
579 bool, // chassis Front panel lockout
580 bool, // chassis NMI
581 bool, // chassis power interlock
582 uint4_t, // reserved
anil kumar appana43263c62019-05-27 12:45:04 +0000583 uint8_t, // chassis FRU info Device Address
584 uint8_t, // chassis SDR device address
585 uint8_t, // chassis SEL device address
586 uint8_t, // chassis system management device address
587 uint8_t // chassis bridge device address
588 >
589 ipmiGetChassisCap()
Nan Li8d15fb42016-08-16 22:29:40 +0800590{
anil kumar appana43263c62019-05-27 12:45:04 +0000591 ipmi::PropertyMap properties;
Yong Liae4b0402018-11-02 11:12:14 +0800592 try
593 {
Patrick Williams5d82f472022-07-22 19:26:53 -0500594 sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()};
Nan Li8d15fb42016-08-16 22:29:40 +0800595
Yong Liae4b0402018-11-02 11:12:14 +0800596 ipmi::DbusObjectInfo chassisCapObject =
597 ipmi::getDbusObject(bus, chassisCapIntf);
Nan Li8d15fb42016-08-16 22:29:40 +0800598
Yong Liae4b0402018-11-02 11:12:14 +0800599 // capabilities flags
600 // [7..4] - reserved
601 // [3] – 1b = provides power interlock (IPM 1.5)
602 // [2] – 1b = provides Diagnostic Interrupt (FP NMI)
603 // [1] – 1b = provides “Front Panel Lockout” (indicates that the chassis
604 // has capabilities
605 // to lock out external power control and reset button or
606 // front panel interfaces and/or detect tampering with those
607 // interfaces).
608 // [0] -1b = Chassis provides intrusion (physical security) sensor.
609 // set to default value 0x0.
Nan Li8d15fb42016-08-16 22:29:40 +0800610
Patrick Williams1318a5e2024-08-16 15:19:54 -0400611 properties =
612 ipmi::getAllDbusProperties(bus, chassisCapObject.second,
613 chassisCapObject.first, chassisCapIntf);
Yong Liae4b0402018-11-02 11:12:14 +0800614 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -0500615 catch (const std::exception& e)
Yong Liae4b0402018-11-02 11:12:14 +0800616 {
Vernon Mauery38108d92024-03-11 12:53:55 -0700617 lg2::error("Failed to fetch Chassis Capability properties: {ERROR}",
618 "ERROR", e);
anil kumar appana43263c62019-05-27 12:45:04 +0000619 return ipmi::responseUnspecifiedError();
Yong Liae4b0402018-11-02 11:12:14 +0800620 }
621
Karthick Sundarrajan86d8bd72019-11-26 12:48:50 -0800622 bool* chassisIntrusionFlag =
623 std::get_if<bool>(&properties[chassisIntrusionProp]);
624 if (chassisIntrusionFlag == nullptr)
anil kumar appana43263c62019-05-27 12:45:04 +0000625 {
Vernon Mauery38108d92024-03-11 12:53:55 -0700626 lg2::error("Error to get chassis Intrusion flags");
Karthick Sundarrajan86d8bd72019-11-26 12:48:50 -0800627 return ipmi::responseUnspecifiedError();
628 }
629 bool* chassisFrontPanelFlag =
630 std::get_if<bool>(&properties[chassisFrontPanelLockoutProp]);
631 if (chassisFrontPanelFlag == nullptr)
632 {
Vernon Mauery38108d92024-03-11 12:53:55 -0700633 lg2::error("Error to get chassis intrusion flags");
Karthick Sundarrajan86d8bd72019-11-26 12:48:50 -0800634 return ipmi::responseUnspecifiedError();
635 }
636 bool* chassisNMIFlag = std::get_if<bool>(&properties[chassisNMIProp]);
637 if (chassisNMIFlag == nullptr)
638 {
Vernon Mauery38108d92024-03-11 12:53:55 -0700639 lg2::error("Error to get chassis NMI flags");
Karthick Sundarrajan86d8bd72019-11-26 12:48:50 -0800640 return ipmi::responseUnspecifiedError();
641 }
642 bool* chassisPowerInterlockFlag =
643 std::get_if<bool>(&properties[chassisPowerInterlockProp]);
644 if (chassisPowerInterlockFlag == nullptr)
645 {
Vernon Mauery38108d92024-03-11 12:53:55 -0700646 lg2::error("Error to get chassis power interlock flags");
anil kumar appana43263c62019-05-27 12:45:04 +0000647 return ipmi::responseUnspecifiedError();
648 }
649 uint8_t* chassisFRUInfoDevAddr =
650 std::get_if<uint8_t>(&properties[chassisFRUDevAddrProp]);
651 if (chassisFRUInfoDevAddr == nullptr)
652 {
Vernon Mauery38108d92024-03-11 12:53:55 -0700653 lg2::error("Error to get chassis FRU info device address");
anil kumar appana43263c62019-05-27 12:45:04 +0000654 return ipmi::responseUnspecifiedError();
655 }
656 uint8_t* chassisSDRDevAddr =
657 std::get_if<uint8_t>(&properties[chassisSDRDevAddrProp]);
658 if (chassisSDRDevAddr == nullptr)
659 {
Vernon Mauery38108d92024-03-11 12:53:55 -0700660 lg2::error("Error to get chassis SDR device address");
anil kumar appana43263c62019-05-27 12:45:04 +0000661 return ipmi::responseUnspecifiedError();
662 }
663 uint8_t* chassisSELDevAddr =
664 std::get_if<uint8_t>(&properties[chassisSELDevAddrProp]);
665 if (chassisSELDevAddr == nullptr)
666 {
Vernon Mauery38108d92024-03-11 12:53:55 -0700667 lg2::error("Error to get chassis SEL device address");
anil kumar appana43263c62019-05-27 12:45:04 +0000668 return ipmi::responseUnspecifiedError();
669 }
670 uint8_t* chassisSMDevAddr =
671 std::get_if<uint8_t>(&properties[chassisSMDevAddrProp]);
672 if (chassisSMDevAddr == nullptr)
673 {
Vernon Mauery38108d92024-03-11 12:53:55 -0700674 lg2::error("Error to get chassis SM device address");
anil kumar appana43263c62019-05-27 12:45:04 +0000675 return ipmi::responseUnspecifiedError();
676 }
677 uint8_t* chassisBridgeDevAddr =
678 std::get_if<uint8_t>(&properties[chassisBridgeDevAddrProp]);
679 if (chassisBridgeDevAddr == nullptr)
680 {
Vernon Mauery38108d92024-03-11 12:53:55 -0700681 lg2::error("Error to get chassis bridge device address");
anil kumar appana43263c62019-05-27 12:45:04 +0000682 return ipmi::responseUnspecifiedError();
683 }
684
Patrick Williams1318a5e2024-08-16 15:19:54 -0400685 return ipmi::responseSuccess(
686 *chassisIntrusionFlag, *chassisFrontPanelFlag, *chassisNMIFlag,
687 *chassisPowerInterlockFlag, 0, *chassisFRUInfoDevAddr,
688 *chassisSDRDevAddr, *chassisSELDevAddr, *chassisSMDevAddr,
689 *chassisBridgeDevAddr);
Yong Liae4b0402018-11-02 11:12:14 +0800690}
691
anil kumar appana894d0222019-05-27 16:32:14 +0000692/** @brief implements set chassis capalibities command
693 * @param intrusion - chassis intrusion
694 * @param fpLockout - frontpannel lockout
695 * @param reserved1 - skip one bit
696 * @param fruDeviceAddr - chassis FRU info Device Address
697 * @param sdrDeviceAddr - chassis SDR device address
698 * @param selDeviceAddr - chassis SEL device address
699 * @param smDeviceAddr - chassis system management device address
700 * @param bridgeDeviceAddr - chassis bridge device address
701 *
702 * @returns IPMI completion code
703 */
Patrick Williams1318a5e2024-08-16 15:19:54 -0400704ipmi::RspType<> ipmiSetChassisCap(
705 bool intrusion, bool fpLockout, uint6_t reserved1,
anil kumar appana894d0222019-05-27 16:32:14 +0000706
Patrick Williams1318a5e2024-08-16 15:19:54 -0400707 uint8_t fruDeviceAddr,
anil kumar appana894d0222019-05-27 16:32:14 +0000708
Patrick Williams1318a5e2024-08-16 15:19:54 -0400709 uint8_t sdrDeviceAddr,
anil kumar appana894d0222019-05-27 16:32:14 +0000710
Patrick Williams1318a5e2024-08-16 15:19:54 -0400711 uint8_t selDeviceAddr,
anil kumar appana894d0222019-05-27 16:32:14 +0000712
Patrick Williams1318a5e2024-08-16 15:19:54 -0400713 uint8_t smDeviceAddr,
anil kumar appana894d0222019-05-27 16:32:14 +0000714
Patrick Williams1318a5e2024-08-16 15:19:54 -0400715 uint8_t bridgeDeviceAddr)
Yong Liae4b0402018-11-02 11:12:14 +0800716{
Yong Liae4b0402018-11-02 11:12:14 +0800717 // check input data
anil kumar appana894d0222019-05-27 16:32:14 +0000718 if (reserved1 != 0)
Yong Liae4b0402018-11-02 11:12:14 +0800719 {
Vernon Mauery38108d92024-03-11 12:53:55 -0700720 lg2::error("Unsupported request parameter");
anil kumar appana894d0222019-05-27 16:32:14 +0000721 return ipmi::responseInvalidFieldRequest();
Yong Liae4b0402018-11-02 11:12:14 +0800722 }
723
anil kumar appana894d0222019-05-27 16:32:14 +0000724 if ((fruDeviceAddr & ~chassisCapAddrMask) != 0)
Yong Liae4b0402018-11-02 11:12:14 +0800725 {
Vernon Mauery38108d92024-03-11 12:53:55 -0700726 lg2::error("Unsupported request parameter(FRU Addr) for REQ={REQ}",
727 "REQ", lg2::hex, fruDeviceAddr);
anil kumar appana894d0222019-05-27 16:32:14 +0000728 return ipmi::responseInvalidFieldRequest();
Yong Liae4b0402018-11-02 11:12:14 +0800729 }
anil kumar appana894d0222019-05-27 16:32:14 +0000730 if ((sdrDeviceAddr & ~chassisCapAddrMask) != 0)
Yong Liae4b0402018-11-02 11:12:14 +0800731 {
Vernon Mauery38108d92024-03-11 12:53:55 -0700732 lg2::error("Unsupported request parameter(SDR Addr) for REQ={REQ}",
733 "REQ", lg2::hex, sdrDeviceAddr);
anil kumar appana894d0222019-05-27 16:32:14 +0000734 return ipmi::responseInvalidFieldRequest();
Yong Liae4b0402018-11-02 11:12:14 +0800735 }
736
anil kumar appana894d0222019-05-27 16:32:14 +0000737 if ((selDeviceAddr & ~chassisCapAddrMask) != 0)
Yong Liae4b0402018-11-02 11:12:14 +0800738 {
Vernon Mauery38108d92024-03-11 12:53:55 -0700739 lg2::error("Unsupported request parameter(SEL Addr) for REQ={REQ}",
740 "REQ", lg2::hex, selDeviceAddr);
anil kumar appana894d0222019-05-27 16:32:14 +0000741 return ipmi::responseInvalidFieldRequest();
Yong Liae4b0402018-11-02 11:12:14 +0800742 }
743
anil kumar appana894d0222019-05-27 16:32:14 +0000744 if ((smDeviceAddr & ~chassisCapAddrMask) != 0)
Yong Liae4b0402018-11-02 11:12:14 +0800745 {
Vernon Mauery38108d92024-03-11 12:53:55 -0700746 lg2::error("Unsupported request parameter(SM Addr) for REQ={REQ}",
747 "REQ", lg2::hex, smDeviceAddr);
anil kumar appana894d0222019-05-27 16:32:14 +0000748 return ipmi::responseInvalidFieldRequest();
Yong Liae4b0402018-11-02 11:12:14 +0800749 }
750
anil kumar appana894d0222019-05-27 16:32:14 +0000751 if ((bridgeDeviceAddr & ~chassisCapAddrMask) != 0)
Yong Liae4b0402018-11-02 11:12:14 +0800752 {
Vernon Mauery38108d92024-03-11 12:53:55 -0700753 lg2::error("Unsupported request parameter(Bridge Addr) for REQ={REQ}",
754 "REQ", lg2::hex, bridgeDeviceAddr);
anil kumar appana894d0222019-05-27 16:32:14 +0000755 return ipmi::responseInvalidFieldRequest();
Yong Liae4b0402018-11-02 11:12:14 +0800756 }
757
758 try
759 {
Patrick Williams5d82f472022-07-22 19:26:53 -0500760 sdbusplus::bus_t bus(ipmid_get_sd_bus_connection());
Yong Liae4b0402018-11-02 11:12:14 +0800761 ipmi::DbusObjectInfo chassisCapObject =
762 ipmi::getDbusObject(bus, chassisCapIntf);
763
764 ipmi::setDbusProperty(bus, chassisCapObject.second,
765 chassisCapObject.first, chassisCapIntf,
Karthick Sundarrajan86d8bd72019-11-26 12:48:50 -0800766 chassisIntrusionProp, intrusion);
767
768 ipmi::setDbusProperty(bus, chassisCapObject.second,
769 chassisCapObject.first, chassisCapIntf,
770 chassisFrontPanelLockoutProp, fpLockout);
Yong Liae4b0402018-11-02 11:12:14 +0800771
772 ipmi::setDbusProperty(bus, chassisCapObject.second,
773 chassisCapObject.first, chassisCapIntf,
anil kumar appana894d0222019-05-27 16:32:14 +0000774 chassisFRUDevAddrProp, fruDeviceAddr);
Yong Liae4b0402018-11-02 11:12:14 +0800775
776 ipmi::setDbusProperty(bus, chassisCapObject.second,
777 chassisCapObject.first, chassisCapIntf,
anil kumar appana894d0222019-05-27 16:32:14 +0000778 chassisSDRDevAddrProp, sdrDeviceAddr);
Yong Liae4b0402018-11-02 11:12:14 +0800779
780 ipmi::setDbusProperty(bus, chassisCapObject.second,
781 chassisCapObject.first, chassisCapIntf,
anil kumar appana894d0222019-05-27 16:32:14 +0000782 chassisSELDevAddrProp, selDeviceAddr);
Yong Liae4b0402018-11-02 11:12:14 +0800783
784 ipmi::setDbusProperty(bus, chassisCapObject.second,
785 chassisCapObject.first, chassisCapIntf,
anil kumar appana894d0222019-05-27 16:32:14 +0000786 chassisSMDevAddrProp, smDeviceAddr);
Yong Liae4b0402018-11-02 11:12:14 +0800787
788 ipmi::setDbusProperty(bus, chassisCapObject.second,
789 chassisCapObject.first, chassisCapIntf,
anil kumar appana894d0222019-05-27 16:32:14 +0000790 chassisBridgeDevAddrProp, bridgeDeviceAddr);
Yong Liae4b0402018-11-02 11:12:14 +0800791 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -0500792 catch (const std::exception& e)
Yong Liae4b0402018-11-02 11:12:14 +0800793 {
Vernon Mauery38108d92024-03-11 12:53:55 -0700794 lg2::error("Failed to set chassis capability properties: {ERR}", "ERR",
795 e);
anil kumar appana894d0222019-05-27 16:32:14 +0000796 return ipmi::responseUnspecifiedError();
Yong Liae4b0402018-11-02 11:12:14 +0800797 }
anil kumar appana894d0222019-05-27 16:32:14 +0000798 return ipmi::responseSuccess();
Nan Li8d15fb42016-08-16 22:29:40 +0800799}
800
Vishwanatha Subbannab12b0c02017-03-07 18:17:19 +0530801//------------------------------------------
802// Calls into Host State Manager Dbus object
803//------------------------------------------
Jason M. Bills664e1c32020-01-30 16:02:39 -0800804int initiateHostStateTransition(ipmi::Context::ptr& ctx,
805 State::Host::Transition transition)
vishwa36993272015-11-20 12:43:49 -0600806{
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500807 // OpenBMC Host State Manager dbus framework
Jason M. Bills664e1c32020-01-30 16:02:39 -0800808 constexpr auto hostStatePath = "/xyz/openbmc_project/state/host0";
809 constexpr auto hostStateIntf = "xyz.openbmc_project.State.Host";
Vishwanatha Subbannab12b0c02017-03-07 18:17:19 +0530810
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500811 // Convert to string equivalent of the passed in transition enum.
Willy Tu523e2d12023-09-05 11:36:48 -0700812 auto request =
813 sdbusplus::common::xyz::openbmc_project::state::convertForMessage(
814 transition);
Vishwanatha Subbannab12b0c02017-03-07 18:17:19 +0530815
Jason M. Bills664e1c32020-01-30 16:02:39 -0800816 std::string service;
Patrick Williams1318a5e2024-08-16 15:19:54 -0400817 boost::system::error_code ec =
818 ipmi::getService(ctx, hostStateIntf, hostStatePath, service);
Jason M. Bills664e1c32020-01-30 16:02:39 -0800819
820 if (!ec)
821 {
822 ec = ipmi::setDbusProperty(ctx, service, hostStatePath, hostStateIntf,
823 "RequestedHostTransition", request);
824 }
825 if (ec)
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500826 {
Vernon Mauery38108d92024-03-11 12:53:55 -0700827 lg2::error(
828 "Failed to initiate transition for request {REQUEST}: {EXCEPTION}",
829 "REQUEST", request, "EXCEPTION", ec.message());
Jason M. Bills664e1c32020-01-30 16:02:39 -0800830 return -1;
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500831 }
Vernon Mauery38108d92024-03-11 12:53:55 -0700832 lg2::info(
833 "Transition request {REQUEST} initiated successfully by user {USERID}",
834 "REQUEST", request, "USERID", ctx->userId);
Jason M. Bills664e1c32020-01-30 16:02:39 -0800835 return 0;
vishwa36993272015-11-20 12:43:49 -0600836}
837
Kuiying Wang6b0ceaa2019-11-05 15:13:40 +0800838//------------------------------------------
Jason M. Billsad588bf2020-01-30 16:18:33 -0800839// Calls into Chassis State Manager Dbus object
840//------------------------------------------
841int initiateChassisStateTransition(ipmi::Context::ptr& ctx,
842 State::Chassis::Transition transition)
843{
844 // OpenBMC Chassis State Manager dbus framework
845 constexpr auto chassisStatePath = "/xyz/openbmc_project/state/chassis0";
846 constexpr auto chassisStateIntf = "xyz.openbmc_project.State.Chassis";
847
848 std::string service;
Patrick Williams1318a5e2024-08-16 15:19:54 -0400849 boost::system::error_code ec =
850 ipmi::getService(ctx, chassisStateIntf, chassisStatePath, service);
Jason M. Billsad588bf2020-01-30 16:18:33 -0800851
852 // Convert to string equivalent of the passed in transition enum.
Willy Tu523e2d12023-09-05 11:36:48 -0700853 auto request =
854 sdbusplus::common::xyz::openbmc_project::state::convertForMessage(
855 transition);
Jason M. Billsad588bf2020-01-30 16:18:33 -0800856
857 if (!ec)
858 {
859 ec = ipmi::setDbusProperty(ctx, service, chassisStatePath,
860 chassisStateIntf, "RequestedPowerTransition",
861 request);
862 }
863 if (ec)
864 {
Vernon Mauery38108d92024-03-11 12:53:55 -0700865 lg2::error("Failed to initiate transition {REQUEST}: {EXCEPTION}",
866 "REQUEST", request, "EXCEPTION", ec.message());
867
Jason M. Billsad588bf2020-01-30 16:18:33 -0800868 return -1;
869 }
870
871 return 0;
872}
873
874//------------------------------------------
Zev Weiss337a0972024-03-08 08:31:15 +0000875// Trigger an NMI on the host via dbus
Kuiying Wang6b0ceaa2019-11-05 15:13:40 +0800876//------------------------------------------
Zev Weiss337a0972024-03-08 08:31:15 +0000877static int doNmi(ipmi::Context::ptr& ctx)
Kuiying Wang6b0ceaa2019-11-05 15:13:40 +0800878{
Zev Weiss337a0972024-03-08 08:31:15 +0000879 constexpr const char* nmiIntfName = "xyz.openbmc_project.Control.Host.NMI";
880 ipmi::DbusObjectInfo nmiObj{};
881 boost::system::error_code ec;
Kuiying Wang6b0ceaa2019-11-05 15:13:40 +0800882
Zev Weiss337a0972024-03-08 08:31:15 +0000883 ec = ipmi::getDbusObject(ctx, nmiIntfName, nmiObj);
Vernon Mauery9bb4a382021-11-05 12:46:19 -0700884 if (ec)
Kuiying Wang6b0ceaa2019-11-05 15:13:40 +0800885 {
Vernon Mauery38108d92024-03-11 12:53:55 -0700886 lg2::error("Failed to find NMI service: {ERROR}", "ERROR",
887 ec.message());
Zev Weiss337a0972024-03-08 08:31:15 +0000888 return -1;
889 }
890
891 ctx->bus->yield_method_call<void>(ctx->yield, ec, nmiObj.second,
892 nmiObj.first, nmiIntfName, "NMI");
893 if (ec)
894 {
Vernon Mauery38108d92024-03-11 12:53:55 -0700895 lg2::error("NMI call failed: {ERROR}", "ERROR", ec.message());
Zev Weiss337a0972024-03-08 08:31:15 +0000896 elog<InternalFailure>();
Kuiying Wang6b0ceaa2019-11-05 15:13:40 +0800897 return -1;
898 }
899
900 return 0;
901}
902
Deepak Kodihalli18b70d12017-07-21 13:36:33 -0500903namespace power_policy
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500904{
Nan Lifdd8ec52016-08-28 03:57:40 +0800905
Willy Tu523e2d12023-09-05 11:36:48 -0700906using namespace sdbusplus::server::xyz::openbmc_project::control::power;
Deepak Kodihalli18b70d12017-07-21 13:36:33 -0500907using IpmiValue = uint8_t;
908using DbusValue = RestorePolicy::Policy;
Nan Lifdd8ec52016-08-28 03:57:40 +0800909
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700910const std::map<DbusValue, IpmiValue> dbusToIpmi = {
Deepak Kodihalli18b70d12017-07-21 13:36:33 -0500911 {RestorePolicy::Policy::AlwaysOff, 0x00},
912 {RestorePolicy::Policy::Restore, 0x01},
George Liue561d3e2024-02-04 15:19:30 +0800913 {RestorePolicy::Policy::AlwaysOn, 0x02},
914 {RestorePolicy::Policy::None, 0x03}};
Nan Lifdd8ec52016-08-28 03:57:40 +0800915
Yong Lic6713cf2018-09-12 12:35:13 +0800916static constexpr uint8_t noChange = 0x03;
917static constexpr uint8_t allSupport = 0x01 | 0x02 | 0x04;
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700918
919/* helper function for Get Chassis Status Command
920 */
921std::optional<uint2_t> getPowerRestorePolicy()
922{
923 uint2_t restorePolicy = 0;
924 using namespace chassis::internal;
925
James Feist225dec82019-11-26 16:25:06 -0800926 settings::Objects& objects = cache::getObjects();
927
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700928 try
929 {
930 const auto& powerRestoreSetting =
James Feist225dec82019-11-26 16:25:06 -0800931 objects.map.at(powerRestoreIntf).front();
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700932 ipmi::Value result = ipmi::getDbusProperty(
933 *getSdBus(),
James Feist225dec82019-11-26 16:25:06 -0800934 objects.service(powerRestoreSetting, powerRestoreIntf).c_str(),
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700935 powerRestoreSetting.c_str(), powerRestoreIntf,
936 "PowerRestorePolicy");
937 auto powerRestore = RestorePolicy::convertPolicyFromString(
938 std::get<std::string>(result));
939 restorePolicy = dbusToIpmi.at(powerRestore);
940 }
941 catch (const std::exception& e)
942 {
Vernon Mauery38108d92024-03-11 12:53:55 -0700943 lg2::error(
944 "Failed to fetch pgood property ({PATH}/{INTERFACE}): {ERROR}",
945 "PATH", objects.map.at(powerRestoreIntf).front(), "INTERFACE",
946 powerRestoreIntf, "ERROR", e);
James Feist225dec82019-11-26 16:25:06 -0800947 cache::objectsPtr.reset();
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700948 return std::nullopt;
949 }
950 return std::make_optional(restorePolicy);
951}
952
953/*
954 * getPowerStatus
955 * helper function for Get Chassis Status Command
956 * return - optional value for pgood (no value on error)
957 */
958std::optional<bool> getPowerStatus()
959{
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700960 bool powerGood = false;
961 std::shared_ptr<sdbusplus::asio::connection> busp = getSdBus();
962 try
963 {
Jason M. Bills3de424c2019-05-21 09:57:16 -0700964 constexpr const char* chassisStatePath =
965 "/xyz/openbmc_project/state/chassis0";
966 constexpr const char* chassisStateIntf =
967 "xyz.openbmc_project.State.Chassis";
Patrick Williams1318a5e2024-08-16 15:19:54 -0400968 auto service =
969 ipmi::getService(*busp, chassisStateIntf, chassisStatePath);
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700970
Jason M. Bills3de424c2019-05-21 09:57:16 -0700971 ipmi::Value powerState =
972 ipmi::getDbusProperty(*busp, service, chassisStatePath,
973 chassisStateIntf, "CurrentPowerState");
974 powerGood = std::get<std::string>(powerState) ==
975 "xyz.openbmc_project.State.Chassis.PowerState.On";
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700976 }
977 catch (const std::exception& e)
978 {
979 try
980 {
981 // FIXME: some legacy modules use the older path; try that next
982 constexpr const char* legacyPwrCtrlObj =
983 "/org/openbmc/control/power0";
984 constexpr const char* legacyPwrCtrlIntf =
985 "org.openbmc.control.Power";
Patrick Williams1318a5e2024-08-16 15:19:54 -0400986 auto service =
987 ipmi::getService(*busp, legacyPwrCtrlIntf, legacyPwrCtrlObj);
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700988
989 ipmi::Value variant = ipmi::getDbusProperty(
990 *busp, service, legacyPwrCtrlObj, legacyPwrCtrlIntf, "pgood");
991 powerGood = static_cast<bool>(std::get<int>(variant));
992 }
993 catch (const std::exception& e)
994 {
Vernon Mauery38108d92024-03-11 12:53:55 -0700995 lg2::error("Failed to fetch pgood property: {ERROR}", "ERROR", e);
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700996 return std::nullopt;
997 }
998 }
999 return std::make_optional(powerGood);
1000}
1001
Yong Li70ce7352019-05-16 21:15:27 +08001002/*
1003 * getACFailStatus
1004 * helper function for Get Chassis Status Command
1005 * return - bool value for ACFail (false on error)
1006 */
1007bool getACFailStatus()
1008{
1009 constexpr const char* powerControlObj =
1010 "/xyz/openbmc_project/Chassis/Control/Power0";
1011 constexpr const char* powerControlIntf =
1012 "xyz.openbmc_project.Chassis.Control.Power";
1013 bool acFail = false;
1014 std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus();
1015 try
1016 {
Patrick Williams1318a5e2024-08-16 15:19:54 -04001017 auto service =
1018 ipmi::getService(*bus, powerControlIntf, powerControlObj);
Yong Li70ce7352019-05-16 21:15:27 +08001019
1020 ipmi::Value variant = ipmi::getDbusProperty(
1021 *bus, service, powerControlObj, powerControlIntf, "PFail");
1022 acFail = std::get<bool>(variant);
1023 }
1024 catch (const std::exception& e)
1025 {
Vernon Mauery38108d92024-03-11 12:53:55 -07001026 lg2::error(
1027 "Failed to fetch PFail property ({PATH}/{INTERFAC}): {ERROR}",
1028 "PATH", powerControlObj, "INTERFACE", powerControlIntf, "ERROR", e);
Yong Li70ce7352019-05-16 21:15:27 +08001029 }
1030 return acFail;
1031}
Deepak Kodihalli18b70d12017-07-21 13:36:33 -05001032} // namespace power_policy
Nan Lifdd8ec52016-08-28 03:57:40 +08001033
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001034static std::optional<bool> getButtonEnabled(const std::string& buttonPath,
1035 const std::string& buttonIntf)
1036{
1037 std::shared_ptr<sdbusplus::asio::connection> busp = getSdBus();
1038 bool buttonDisabled = false;
1039 try
1040 {
1041 auto service = ipmi::getService(*busp, buttonIntf, buttonPath);
1042 ipmi::Value enabled = ipmi::getDbusProperty(*busp, service, buttonPath,
1043 buttonIntf, "Enabled");
1044 buttonDisabled = !std::get<bool>(enabled);
1045 }
Patrick Williams5d82f472022-07-22 19:26:53 -05001046 catch (const sdbusplus::exception_t& e)
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001047 {
Vernon Mauery38108d92024-03-11 12:53:55 -07001048 lg2::error("Fail to get button Enabled property ({PATH}): {ERROR}",
1049 "PATH", buttonPath, "ERROR", e);
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001050 return std::nullopt;
1051 }
1052 return std::make_optional(buttonDisabled);
1053}
1054
Kuiying Wang21addc52019-01-04 10:50:21 +08001055static bool setButtonEnabled(ipmi::Context::ptr& ctx,
1056 const std::string& buttonPath,
1057 const std::string& buttonIntf, bool enable)
1058{
1059 std::string service;
1060 boost::system::error_code ec;
1061 ec = ipmi::getService(ctx, buttonIntf, buttonPath, service);
1062 if (!ec)
1063 {
1064 ec = ipmi::setDbusProperty(ctx, service, buttonPath, buttonIntf,
1065 "Enabled", enable);
1066 }
1067 if (ec)
1068 {
Vernon Mauery38108d92024-03-11 12:53:55 -07001069 lg2::error(
1070 "Fail to set button Enabled property ({SERVICE}:{PATH}): {ERROR}",
1071 "SERVICE", service, "PATH", buttonPath, "ERROR", ec.message());
Kuiying Wang21addc52019-01-04 10:50:21 +08001072 return false;
1073 }
1074 return true;
1075}
1076
Chau Ly9e666cd2023-03-06 08:46:14 +00001077static std::optional<bool> getChassisIntrusionStatus(ipmi::Context::ptr& ctx)
1078{
1079 constexpr const char* chassisIntrusionPath =
1080 "/xyz/openbmc_project/Chassis/Intrusion";
1081 constexpr const char* chassisIntrusionInf =
1082 "xyz.openbmc_project.Chassis.Intrusion";
1083
1084 std::string service;
1085 boost::system::error_code ec = ipmi::getService(
1086 ctx, chassisIntrusionInf, chassisIntrusionPath, service);
1087 if (!ec)
1088 {
1089 std::string chassisIntrusionStr;
1090 ec = ipmi::getDbusProperty<std::string>(
1091 ctx, service, chassisIntrusionPath, chassisIntrusionInf, "Status",
1092 chassisIntrusionStr);
1093 if (!ec)
1094 {
Patrick Williams1318a5e2024-08-16 15:19:54 -04001095 bool ret =
1096 (chassisIntrusionStr == "HardwareIntrusion") ? true : false;
Chau Ly9e666cd2023-03-06 08:46:14 +00001097 return std::make_optional(ret);
1098 }
1099 }
Vernon Mauery38108d92024-03-11 12:53:55 -07001100 lg2::error("Fail to get Chassis Intrusion Status property "
1101 "({PATH}/{INTERFACE}): {ERROR}",
1102 "PATH", chassisIntrusionPath, "INTERFACE", chassisIntrusionInf,
1103 "ERROR", ec.message());
Chau Ly9e666cd2023-03-06 08:46:14 +00001104 return std::nullopt;
1105}
1106
Nan Lifdd8ec52016-08-28 03:57:40 +08001107//----------------------------------------------------------------------
1108// Get Chassis Status commands
1109//----------------------------------------------------------------------
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001110ipmi::RspType<bool, // Power is on
1111 bool, // Power overload
1112 bool, // Interlock
1113 bool, // power fault
1114 bool, // power control fault
1115 uint2_t, // power restore policy
1116 bool, // reserved
1117
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05001118 bool, // AC failed
1119 bool, // last power down caused by a Power overload
1120 bool, // last power down caused by a power interlock
1121 bool, // last power down caused by power fault
Patrick Williams99db6882024-12-18 11:20:17 -05001122 bool, // last ‘Power is on’ state was entered via IPMI command
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001123 uint3_t, // reserved
1124
1125 bool, // Chassis intrusion active
1126 bool, // Front Panel Lockout active
1127 bool, // Drive Fault
1128 bool, // Cooling/fan fault detected
1129 uint2_t, // Chassis Identify State
1130 bool, // Chassis Identify command and state info supported
1131 bool, // reserved
1132
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05001133 bool, // Power off button disabled
1134 bool, // Reset button disabled
1135 bool, // Diagnostic Interrupt button disabled
1136 bool, // Standby (sleep) button disabled
1137 bool, // Power off button disable allowed
1138 bool, // Reset button disable allowed
1139 bool, // Diagnostic Interrupt button disable allowed
1140 bool // Standby (sleep) button disable allowed
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001141 >
Chau Ly9e666cd2023-03-06 08:46:14 +00001142 ipmiGetChassisStatus(ipmi::Context::ptr& ctx)
Nan Lifdd8ec52016-08-28 03:57:40 +08001143{
Deepak Kodihalli18b70d12017-07-21 13:36:33 -05001144 using namespace chassis::internal;
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001145 std::optional<uint2_t> restorePolicy =
1146 power_policy::getPowerRestorePolicy();
1147 std::optional<bool> powerGood = power_policy::getPowerStatus();
1148 if (!restorePolicy || !powerGood)
Deepak Kodihalli18b70d12017-07-21 13:36:33 -05001149 {
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001150 return ipmi::responseUnspecifiedError();
Deepak Kodihalli18b70d12017-07-21 13:36:33 -05001151 }
Nan Lifdd8ec52016-08-28 03:57:40 +08001152
1153 // Front Panel Button Capabilities and disable/enable status(Optional)
Patrick Williams1318a5e2024-08-16 15:19:54 -04001154 std::optional<bool> powerButtonReading =
1155 getButtonEnabled(powerButtonPath, powerButtonIntf);
Vernon Mauery6d5b2f72019-05-16 14:48:47 -07001156 // allow disable if the interface is present
1157 bool powerButtonDisableAllow = static_cast<bool>(powerButtonReading);
1158 // default return the button is enabled (not disabled)
1159 bool powerButtonDisabled = false;
1160 if (powerButtonDisableAllow)
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001161 {
Vernon Mauery6d5b2f72019-05-16 14:48:47 -07001162 // return the real value of the button status, if present
1163 powerButtonDisabled = *powerButtonReading;
1164 }
1165
Patrick Williams1318a5e2024-08-16 15:19:54 -04001166 std::optional<bool> resetButtonReading =
1167 getButtonEnabled(resetButtonPath, resetButtonIntf);
Vernon Mauery6d5b2f72019-05-16 14:48:47 -07001168 // allow disable if the interface is present
1169 bool resetButtonDisableAllow = static_cast<bool>(resetButtonReading);
1170 // default return the button is enabled (not disabled)
1171 bool resetButtonDisabled = false;
1172 if (resetButtonDisableAllow)
1173 {
1174 // return the real value of the button status, if present
1175 resetButtonDisabled = *resetButtonReading;
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001176 }
Nan Lifdd8ec52016-08-28 03:57:40 +08001177
Yong Li70ce7352019-05-16 21:15:27 +08001178 bool powerDownAcFailed = power_policy::getACFailStatus();
1179
Chau Ly9e666cd2023-03-06 08:46:14 +00001180 bool chassisIntrusionActive = false;
1181 std::optional<bool> chassisIntrusionStatus = getChassisIntrusionStatus(ctx);
1182 if (chassisIntrusionStatus)
1183 {
1184 chassisIntrusionActive = chassisIntrusionStatus.value();
1185 }
1186
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001187 // This response has a lot of hard-coded, unsupported fields
1188 // They are set to false or 0
1189 constexpr bool powerOverload = false;
1190 constexpr bool chassisInterlock = false;
1191 constexpr bool powerFault = false;
1192 constexpr bool powerControlFault = false;
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001193 constexpr bool powerDownOverload = false;
1194 constexpr bool powerDownInterlock = false;
1195 constexpr bool powerDownPowerFault = false;
1196 constexpr bool powerStatusIPMI = false;
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001197 constexpr bool frontPanelLockoutActive = false;
1198 constexpr bool driveFault = false;
1199 constexpr bool coolingFanFault = false;
1200 // chassisIdentifySupport set because this command is implemented
1201 constexpr bool chassisIdentifySupport = true;
William A. Kennington III7a0e5df2021-05-19 13:31:29 -07001202 uint2_t chassisIdentifyState = types::enum_cast<uint2_t>(chassisIDState);
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001203 constexpr bool diagButtonDisabled = false;
1204 constexpr bool sleepButtonDisabled = false;
1205 constexpr bool diagButtonDisableAllow = false;
1206 constexpr bool sleepButtonDisableAllow = false;
1207
1208 return ipmi::responseSuccess(
1209 *powerGood, powerOverload, chassisInterlock, powerFault,
1210 powerControlFault, *restorePolicy,
1211 false, // reserved
1212
1213 powerDownAcFailed, powerDownOverload, powerDownInterlock,
1214 powerDownPowerFault, powerStatusIPMI,
1215 uint3_t(0), // reserved
1216
1217 chassisIntrusionActive, frontPanelLockoutActive, driveFault,
1218 coolingFanFault, chassisIdentifyState, chassisIdentifySupport,
1219 false, // reserved
1220
Vernon Mauery6d5b2f72019-05-16 14:48:47 -07001221 powerButtonDisabled, resetButtonDisabled, diagButtonDisabled,
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001222 sleepButtonDisabled, powerButtonDisableAllow, resetButtonDisableAllow,
1223 diagButtonDisableAllow, sleepButtonDisableAllow);
Nan Lifdd8ec52016-08-28 03:57:40 +08001224}
Chris Austen7888c4d2015-12-03 15:26:20 -06001225
Vijay Khemka074f64d2020-03-03 15:08:43 -08001226enum class IpmiRestartCause
1227{
1228 Unknown = 0x0,
1229 RemoteCommand = 0x1,
1230 ResetButton = 0x2,
1231 PowerButton = 0x3,
1232 WatchdogTimer = 0x4,
1233 PowerPolicyAlwaysOn = 0x6,
1234 PowerPolicyPreviousState = 0x7,
1235 SoftReset = 0xa,
1236};
1237
1238static IpmiRestartCause
1239 restartCauseToIpmiRestartCause(State::Host::RestartCause cause)
1240{
1241 switch (cause)
1242 {
1243 case State::Host::RestartCause::Unknown:
1244 {
1245 return IpmiRestartCause::Unknown;
1246 }
1247 case State::Host::RestartCause::RemoteCommand:
1248 {
1249 return IpmiRestartCause::RemoteCommand;
1250 }
1251 case State::Host::RestartCause::ResetButton:
1252 {
1253 return IpmiRestartCause::ResetButton;
1254 }
1255 case State::Host::RestartCause::PowerButton:
1256 {
1257 return IpmiRestartCause::PowerButton;
1258 }
1259 case State::Host::RestartCause::WatchdogTimer:
1260 {
1261 return IpmiRestartCause::WatchdogTimer;
1262 }
1263 case State::Host::RestartCause::PowerPolicyAlwaysOn:
1264 {
1265 return IpmiRestartCause::PowerPolicyAlwaysOn;
1266 }
1267 case State::Host::RestartCause::PowerPolicyPreviousState:
1268 {
1269 return IpmiRestartCause::PowerPolicyPreviousState;
1270 }
1271 case State::Host::RestartCause::SoftReset:
1272 {
1273 return IpmiRestartCause::SoftReset;
1274 }
1275 default:
1276 {
1277 return IpmiRestartCause::Unknown;
1278 }
1279 }
1280}
1281
1282/*
1283 * getRestartCause
1284 * helper function for Get Host restart cause Command
1285 * return - optional value for RestartCause (no value on error)
1286 */
1287static std::optional<uint4_t> getRestartCause(ipmi::Context::ptr ctx)
1288{
okashanyced0ddf2023-05-18 18:35:09 +00001289 constexpr const char* restartCausePath = "/xyz/openbmc_project/state/host0";
1290 constexpr const char* restartCauseIntf = "xyz.openbmc_project.State.Host";
Vijay Khemka074f64d2020-03-03 15:08:43 -08001291
1292 std::string service;
Patrick Williams1318a5e2024-08-16 15:19:54 -04001293 boost::system::error_code ec =
1294 ipmi::getService(ctx, restartCauseIntf, restartCausePath, service);
Vijay Khemka074f64d2020-03-03 15:08:43 -08001295 if (!ec)
1296 {
1297 std::string restartCauseStr;
1298 ec = ipmi::getDbusProperty<std::string>(
1299 ctx, service, restartCausePath, restartCauseIntf, "RestartCause",
1300 restartCauseStr);
1301 if (!ec)
1302 {
1303 auto cause =
1304 State::Host::convertRestartCauseFromString(restartCauseStr);
William A. Kennington III7a0e5df2021-05-19 13:31:29 -07001305 return types::enum_cast<uint4_t>(
1306 restartCauseToIpmiRestartCause(cause));
Vijay Khemka074f64d2020-03-03 15:08:43 -08001307 }
1308 }
1309
Vernon Mauery38108d92024-03-11 12:53:55 -07001310 lg2::error(
1311 "Failed to fetch RestartCause property ({PATH}/{INTERFACE}): {ERROR}",
1312 "ERROR", ec.message(), "PATH", restartCausePath, "INTERFACE",
1313 restartCauseIntf);
Vijay Khemka074f64d2020-03-03 15:08:43 -08001314 return std::nullopt;
1315}
1316
1317ipmi::RspType<uint4_t, // Restart Cause
1318 uint4_t, // reserved
1319 uint8_t // channel number (not supported)
1320 >
1321 ipmiGetSystemRestartCause(ipmi::Context::ptr ctx)
1322{
1323 std::optional<uint4_t> cause = getRestartCause(ctx);
1324 if (!cause)
1325 {
1326 return ipmi::responseUnspecifiedError();
1327 }
1328
Vernon Mauery916d4232021-03-29 13:42:16 -07001329 constexpr uint4_t reserved = 0;
1330 auto channel = static_cast<uint8_t>(ctx->channel);
1331 return ipmi::responseSuccess(cause.value(), reserved, channel);
Vijay Khemka074f64d2020-03-03 15:08:43 -08001332}
anil kumar appanadafff5f2019-04-27 18:06:00 +00001333/** @brief Implementation of chassis control command
1334 *
1335 * @param - chassisControl command byte
1336 *
1337 * @return Success or InvalidFieldRequest.
1338 */
Jason M. Bills664e1c32020-01-30 16:02:39 -08001339ipmi::RspType<> ipmiChassisControl(ipmi::Context::ptr& ctx,
1340 uint8_t chassisControl)
vishwa36993272015-11-20 12:43:49 -06001341{
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001342 int rc = 0;
anil kumar appanadafff5f2019-04-27 18:06:00 +00001343 switch (chassisControl)
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001344 {
1345 case CMD_POWER_ON:
Jason M. Bills664e1c32020-01-30 16:02:39 -08001346 rc = initiateHostStateTransition(ctx, State::Host::Transition::On);
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001347 break;
1348 case CMD_POWER_OFF:
Jason M. Billsc2c3a402020-01-30 16:22:24 -08001349 rc = initiateChassisStateTransition(
1350 ctx, State::Chassis::Transition::Off);
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001351 break;
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001352 case CMD_HARD_RESET:
Jason M. Bills664e1c32020-01-30 16:02:39 -08001353 rc = initiateHostStateTransition(
1354 ctx, State::Host::Transition::ForceWarmReboot);
Chanh Nguyend0a7fcd2021-07-16 22:59:28 +07001355 break;
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001356 case CMD_POWER_CYCLE:
Jason M. Bills664e1c32020-01-30 16:02:39 -08001357 rc = initiateHostStateTransition(ctx,
1358 State::Host::Transition::Reboot);
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001359 break;
Vishwanatha Subbanna8b26d352017-08-04 18:35:18 +05301360 case CMD_SOFT_OFF_VIA_OVER_TEMP:
Jason M. Bills664e1c32020-01-30 16:02:39 -08001361 rc = initiateHostStateTransition(ctx, State::Host::Transition::Off);
Vishwanatha Subbanna8b26d352017-08-04 18:35:18 +05301362 break;
Kuiying Wang6b0ceaa2019-11-05 15:13:40 +08001363 case CMD_PULSE_DIAGNOSTIC_INTR:
Zev Weiss337a0972024-03-08 08:31:15 +00001364 rc = doNmi(ctx);
Kuiying Wang6b0ceaa2019-11-05 15:13:40 +08001365 break;
1366
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001367 default:
1368 {
Vernon Mauery38108d92024-03-11 12:53:55 -07001369 lg2::error("Invalid Chassis Control command: {CMD}", "CMD",
1370 lg2::hex, chassisControl);
anil kumar appanadafff5f2019-04-27 18:06:00 +00001371 return ipmi::responseInvalidFieldRequest();
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001372 }
1373 }
vishwa36993272015-11-20 12:43:49 -06001374
anil kumar appanadafff5f2019-04-27 18:06:00 +00001375 return ((rc < 0) ? ipmi::responseUnspecifiedError()
1376 : ipmi::responseSuccess());
vishwa36993272015-11-20 12:43:49 -06001377}
1378
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001379/** @brief Return D-Bus connection string to enclosure identify LED object
1380 *
1381 * @param[in, out] connection - connection to D-Bus object
1382 * @return a IPMI return code
1383 */
1384std::string getEnclosureIdentifyConnection()
Tom Joseph5110c122018-03-23 17:55:40 +05301385{
Tom Joseph5110c122018-03-23 17:55:40 +05301386 // lookup enclosure_identify group owner(s) in mapper
George Liu3e3cc352023-07-26 15:59:31 +08001387 try
Tom Joseph5110c122018-03-23 17:55:40 +05301388 {
George Liu3e3cc352023-07-26 15:59:31 +08001389 return ipmi::getService(*getSdBus(), "xyz.openbmc_project.Led.Group",
1390 identify_led_object_name);
1391 }
1392 catch (const std::exception& e)
1393 {
Vernon Mauery38108d92024-03-11 12:53:55 -07001394 lg2::error("Chassis Identify: Error communicating to mapper: {ERROR}",
1395 "ERROR", e);
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001396 elog<InternalFailure>();
Tom Joseph5110c122018-03-23 17:55:40 +05301397 }
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001398}
Tom Joseph5110c122018-03-23 17:55:40 +05301399
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001400/** @brief Turn On/Off enclosure identify LED
1401 *
1402 * @param[in] flag - true to turn on LED, false to turn off
1403 * @return a IPMI return code
1404 */
1405void enclosureIdentifyLed(bool flag)
1406{
1407 using namespace chassis::internal;
George Liu3e3cc352023-07-26 15:59:31 +08001408 try
1409 {
1410 std::string connection = getEnclosureIdentifyConnection();
1411
1412 auto msg = std::string("enclosureIdentifyLed(") +
1413 boost::lexical_cast<std::string>(flag) + ")";
Vernon Mauery38108d92024-03-11 12:53:55 -07001414 lg2::debug(msg.c_str());
George Liu3e3cc352023-07-26 15:59:31 +08001415
1416 ipmi::setDbusProperty(*getSdBus(), connection, identify_led_object_name,
1417 "xyz.openbmc_project.Led.Group", "Asserted",
1418 flag);
1419 }
1420 catch (const std::exception& e)
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001421 {
Vernon Mauery38108d92024-03-11 12:53:55 -07001422 lg2::error("Chassis Identify: Error Setting State {LED_STATE}: {ERROR}",
1423 "LED_STATE", flag, "ERROR", e);
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001424 elog<InternalFailure>();
1425 }
1426}
1427
1428/** @brief Callback method to turn off LED
1429 */
1430void enclosureIdentifyLedOff()
1431{
1432 try
1433 {
Yong Lif4e38512019-05-21 14:46:55 +08001434 chassisIDState = ChassisIDState::off;
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001435 enclosureIdentifyLed(false);
1436 }
1437 catch (const InternalFailure& e)
1438 {
1439 report<InternalFailure>();
1440 }
1441}
1442
1443/** @brief Create timer to turn on and off the enclosure LED
1444 */
1445void createIdentifyTimer()
1446{
1447 if (!identifyTimer)
1448 {
Vernon Mauery1181af72018-10-08 12:05:00 -07001449 identifyTimer =
Patrick Williams95655222023-12-05 12:45:02 -06001450 std::make_unique<sdbusplus::Timer>(enclosureIdentifyLedOff);
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001451 }
1452}
1453
Vernon Mauery400cc782018-10-09 13:49:53 -07001454ipmi::RspType<> ipmiChassisIdentify(std::optional<uint8_t> interval,
1455 std::optional<uint8_t> force)
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001456{
Vernon Mauery400cc782018-10-09 13:49:53 -07001457 uint8_t identifyInterval = interval.value_or(DEFAULT_IDENTIFY_TIME_OUT);
1458 bool forceIdentify = force.value_or(0) & 0x01;
Tom Josephbed26992018-07-31 23:00:24 +05301459
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001460 if (identifyInterval || forceIdentify)
1461 {
Vernon Mauery400cc782018-10-09 13:49:53 -07001462 // stop the timer if already started;
1463 // for force identify we should not turn off LED
Vernon Mauery1181af72018-10-08 12:05:00 -07001464 identifyTimer->stop();
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001465 try
Tom Joseph5110c122018-03-23 17:55:40 +05301466 {
Yong Lif4e38512019-05-21 14:46:55 +08001467 chassisIDState = ChassisIDState::temporaryOn;
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001468 enclosureIdentifyLed(true);
1469 }
1470 catch (const InternalFailure& e)
1471 {
1472 report<InternalFailure>();
Vernon Mauery400cc782018-10-09 13:49:53 -07001473 return ipmi::responseResponseError();
Tom Joseph5110c122018-03-23 17:55:40 +05301474 }
1475
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001476 if (forceIdentify)
Tom Joseph5110c122018-03-23 17:55:40 +05301477 {
Yong Lif4e38512019-05-21 14:46:55 +08001478 chassisIDState = ChassisIDState::indefiniteOn;
Vernon Mauery400cc782018-10-09 13:49:53 -07001479 return ipmi::responseSuccess();
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001480 }
1481 // start the timer
1482 auto time = std::chrono::duration_cast<std::chrono::microseconds>(
Patrick Venture0b02be92018-08-31 11:55:55 -07001483 std::chrono::seconds(identifyInterval));
Vernon Mauery1181af72018-10-08 12:05:00 -07001484 identifyTimer->start(time);
Tom Joseph5110c122018-03-23 17:55:40 +05301485 }
Tom Josephbed26992018-07-31 23:00:24 +05301486 else if (!identifyInterval)
1487 {
Vernon Mauery1181af72018-10-08 12:05:00 -07001488 identifyTimer->stop();
Tom Josephbed26992018-07-31 23:00:24 +05301489 enclosureIdentifyLedOff();
1490 }
Vernon Mauery400cc782018-10-09 13:49:53 -07001491 return ipmi::responseSuccess();
Tom Joseph5110c122018-03-23 17:55:40 +05301492}
1493
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001494namespace boot_options
1495{
1496
Willy Tu523e2d12023-09-05 11:36:48 -07001497using namespace sdbusplus::server::xyz::openbmc_project::control::boot;
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001498using IpmiValue = uint8_t;
1499constexpr auto ipmiDefault = 0;
1500
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001501std::map<IpmiValue, Type::Types> typeIpmiToDbus = {{0x00, Type::Types::Legacy},
1502 {0x01, Type::Types::EFI}};
1503
Patrick Venture0b02be92018-08-31 11:55:55 -07001504std::map<IpmiValue, Source::Sources> sourceIpmiToDbus = {
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001505 {0x01, Source::Sources::Network},
1506 {0x02, Source::Sources::Disk},
1507 {0x05, Source::Sources::ExternalMedia},
Jia, chunhui67c5e5d2019-05-06 11:29:54 +08001508 {0x0f, Source::Sources::RemovableMedia},
Patrick Venture0b02be92018-08-31 11:55:55 -07001509 {ipmiDefault, Source::Sources::Default}};
shgoupfd84fbbf2015-12-17 10:05:51 +08001510
Patrick Venture0b02be92018-08-31 11:55:55 -07001511std::map<IpmiValue, Mode::Modes> modeIpmiToDbus = {
Yong Li5833cb62019-10-30 13:27:12 +08001512#ifdef ENABLE_BOOT_FLAG_SAFE_MODE_SUPPORT
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001513 {0x03, Mode::Modes::Safe},
Yong Li5833cb62019-10-30 13:27:12 +08001514#endif // ENABLE_BOOT_SAFE_MODE_SUPPORT
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001515 {0x06, Mode::Modes::Setup},
Patrick Venture0b02be92018-08-31 11:55:55 -07001516 {ipmiDefault, Mode::Modes::Regular}};
shgoupfd84fbbf2015-12-17 10:05:51 +08001517
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001518std::map<Type::Types, IpmiValue> typeDbusToIpmi = {{Type::Types::Legacy, 0x00},
1519 {Type::Types::EFI, 0x01}};
1520
Patrick Venture0b02be92018-08-31 11:55:55 -07001521std::map<Source::Sources, IpmiValue> sourceDbusToIpmi = {
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001522 {Source::Sources::Network, 0x01},
1523 {Source::Sources::Disk, 0x02},
1524 {Source::Sources::ExternalMedia, 0x05},
Jia, chunhui67c5e5d2019-05-06 11:29:54 +08001525 {Source::Sources::RemovableMedia, 0x0f},
Patrick Venture0b02be92018-08-31 11:55:55 -07001526 {Source::Sources::Default, ipmiDefault}};
shgoupfd84fbbf2015-12-17 10:05:51 +08001527
Patrick Venture0b02be92018-08-31 11:55:55 -07001528std::map<Mode::Modes, IpmiValue> modeDbusToIpmi = {
Yong Li5833cb62019-10-30 13:27:12 +08001529#ifdef ENABLE_BOOT_FLAG_SAFE_MODE_SUPPORT
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001530 {Mode::Modes::Safe, 0x03},
Yong Li5833cb62019-10-30 13:27:12 +08001531#endif // ENABLE_BOOT_SAFE_MODE_SUPPORT
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001532 {Mode::Modes::Setup, 0x06},
Patrick Venture0b02be92018-08-31 11:55:55 -07001533 {Mode::Modes::Regular, ipmiDefault}};
shgoupfd84fbbf2015-12-17 10:05:51 +08001534
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001535} // namespace boot_options
shgoupfd84fbbf2015-12-17 10:05:51 +08001536
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001537/** @brief Get the property value for boot source
1538 * @param[in] ctx - context pointer
1539 * @param[out] source - boot source value
1540 * @return On failure return IPMI error.
1541 */
1542static ipmi::Cc getBootSource(ipmi::Context::ptr& ctx, Source::Sources& source)
1543{
1544 using namespace chassis::internal;
1545 std::string result;
1546 std::string service;
Patrick Williams1318a5e2024-08-16 15:19:54 -04001547 boost::system::error_code ec =
1548 getService(ctx, bootSourceIntf, bootSettingsPath, service);
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001549 if (!ec)
1550 {
1551 ec = ipmi::getDbusProperty(ctx, service, bootSettingsPath,
1552 bootSourceIntf, "BootSource", result);
1553 if (!ec)
1554 {
1555 source = Source::convertSourcesFromString(result);
1556 return ipmi::ccSuccess;
1557 }
1558 }
Vernon Mauery38108d92024-03-11 12:53:55 -07001559 lg2::error("Error in BootSource Get: {ERROR}", "ERROR", ec.message());
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001560 return ipmi::ccUnspecifiedError;
1561}
1562
Marri Devender Rao81719702018-05-07 00:53:48 -05001563/** @brief Set the property value for boot source
Konstantin Aladysheve76a61a2021-03-18 22:19:13 +03001564 * @param[in] ctx - context pointer
Marri Devender Rao81719702018-05-07 00:53:48 -05001565 * @param[in] source - boot source value
1566 * @return On failure return IPMI error.
1567 */
Jayaprakash Mutyala6088e9f2021-07-14 07:40:29 +00001568static ipmi::Cc setBootSource(ipmi::Context::ptr& ctx,
1569 const Source::Sources& source)
Marri Devender Rao81719702018-05-07 00:53:48 -05001570{
1571 using namespace chassis::internal;
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001572 std::string service;
Patrick Williams1318a5e2024-08-16 15:19:54 -04001573 boost::system::error_code ec =
1574 getService(ctx, bootSourceIntf, bootSettingsPath, service);
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001575 if (!ec)
Marri Devender Rao81719702018-05-07 00:53:48 -05001576 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001577 ec = ipmi::setDbusProperty(ctx, service, bootSettingsPath,
1578 bootSourceIntf, "BootSource",
1579 convertForMessage(source));
1580 if (!ec)
1581 {
1582 return ipmi::ccSuccess;
1583 }
Marri Devender Rao81719702018-05-07 00:53:48 -05001584 }
Vernon Mauery38108d92024-03-11 12:53:55 -07001585 lg2::error("Error in BootSource Set: {ERROR}", "ERROR", ec.message());
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001586 return ipmi::ccUnspecifiedError;
1587}
1588
1589/** @brief Get the property value for boot mode
1590 * @param[in] ctx - context pointer
1591 * @param[out] mode - boot mode value
1592 * @return On failure return IPMI error.
1593 */
1594static ipmi::Cc getBootMode(ipmi::Context::ptr& ctx, Mode::Modes& mode)
1595{
1596 using namespace chassis::internal;
1597 std::string result;
1598 std::string service;
Patrick Williams1318a5e2024-08-16 15:19:54 -04001599 boost::system::error_code ec =
1600 getService(ctx, bootModeIntf, bootSettingsPath, service);
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001601 if (!ec)
1602 {
1603 ec = ipmi::getDbusProperty(ctx, service, bootSettingsPath, bootModeIntf,
1604 "BootMode", result);
1605 if (!ec)
1606 {
1607 mode = Mode::convertModesFromString(result);
1608 return ipmi::ccSuccess;
1609 }
1610 }
Vernon Mauery38108d92024-03-11 12:53:55 -07001611 lg2::error("Error in BootMode Get: {ERROR}", "ERROR", ec.message());
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001612 return ipmi::ccUnspecifiedError;
Marri Devender Rao81719702018-05-07 00:53:48 -05001613}
1614
Patrick Venture0b02be92018-08-31 11:55:55 -07001615/** @brief Set the property value for boot mode
Konstantin Aladysheve76a61a2021-03-18 22:19:13 +03001616 * @param[in] ctx - context pointer
Marri Devender Rao81719702018-05-07 00:53:48 -05001617 * @param[in] mode - boot mode value
1618 * @return On failure return IPMI error.
1619 */
Konstantin Aladysheve76a61a2021-03-18 22:19:13 +03001620static ipmi::Cc setBootMode(ipmi::Context::ptr& ctx, const Mode::Modes& mode)
Marri Devender Rao81719702018-05-07 00:53:48 -05001621{
1622 using namespace chassis::internal;
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001623 std::string service;
Patrick Williams1318a5e2024-08-16 15:19:54 -04001624 boost::system::error_code ec =
1625 getService(ctx, bootModeIntf, bootSettingsPath, service);
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001626 if (!ec)
Marri Devender Rao81719702018-05-07 00:53:48 -05001627 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001628 ec = ipmi::setDbusProperty(ctx, service, bootSettingsPath, bootModeIntf,
1629 "BootMode", convertForMessage(mode));
1630 if (!ec)
1631 {
1632 return ipmi::ccSuccess;
1633 }
Marri Devender Rao81719702018-05-07 00:53:48 -05001634 }
Vernon Mauery38108d92024-03-11 12:53:55 -07001635 lg2::error("Error in BootMode Set: {ERROR}", "ERROR", ec.message());
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001636 return ipmi::ccUnspecifiedError;
1637}
1638
1639/** @brief Get the property value for boot type
1640 * @param[in] ctx - context pointer
1641 * @param[out] type - boot type value
1642 * @return On failure return IPMI error.
1643 */
1644static ipmi::Cc getBootType(ipmi::Context::ptr& ctx, Type::Types& type)
1645{
1646 using namespace chassis::internal;
1647 std::string result;
1648 std::string service;
Patrick Williams1318a5e2024-08-16 15:19:54 -04001649 boost::system::error_code ec =
1650 getService(ctx, bootTypeIntf, bootSettingsPath, service);
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001651
1652 // Don't throw error if BootType interface is not present.
1653 // This interface is not relevant for some Host architectures
1654 // (for example POWER). In this case we don't won't IPMI to
1655 // return an error, but simply return bootType as EFI.
1656 type = Type::Types::EFI;
1657 if (!ec)
1658 {
1659 ec = ipmi::getDbusProperty(ctx, service, bootSettingsPath, bootTypeIntf,
1660 "BootType", result);
1661 if (ec)
1662 {
Vernon Mauery38108d92024-03-11 12:53:55 -07001663 lg2::error("Error in BootType Get: {ERROR}", "ERROR", ec.message());
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001664 return ipmi::ccUnspecifiedError;
1665 }
1666 type = Type::convertTypesFromString(result);
1667 }
1668
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00001669 return ipmi::ccSuccess;
Marri Devender Rao81719702018-05-07 00:53:48 -05001670}
1671
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001672/** @brief Set the property value for boot type
Konstantin Aladysheve76a61a2021-03-18 22:19:13 +03001673 * @param[in] ctx - context pointer
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001674 * @param[in] type - boot type value
1675 * @return On failure return IPMI error.
1676 */
Konstantin Aladysheve76a61a2021-03-18 22:19:13 +03001677static ipmi::Cc setBootType(ipmi::Context::ptr& ctx, const Type::Types& type)
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001678{
1679 using namespace chassis::internal;
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001680 std::string service;
Patrick Williams1318a5e2024-08-16 15:19:54 -04001681 boost::system::error_code ec =
1682 getService(ctx, bootTypeIntf, bootSettingsPath, service);
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001683 if (!ec)
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001684 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001685 ec = ipmi::setDbusProperty(ctx, service, bootSettingsPath, bootTypeIntf,
1686 "BootType", convertForMessage(type));
1687 if (ec)
1688 {
Vernon Mauery38108d92024-03-11 12:53:55 -07001689 lg2::error("Error in BootType Set: {ERROR}", "ERROR", ec.message());
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001690 return ipmi::ccUnspecifiedError;
1691 }
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001692 }
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001693 // Don't throw error if BootType interface is not present.
1694 // This interface is not relevant for some Host architectures
1695 // (for example POWER). In this case we don't won't IPMI to
1696 // return an error, but want to just skip this function.
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001697 return ipmi::ccSuccess;
1698}
1699
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001700/** @brief Get the property value for boot override enable
1701 * @param[in] ctx - context pointer
1702 * @param[out] enable - boot override enable
1703 * @return On failure return IPMI error.
1704 */
1705static ipmi::Cc getBootEnable(ipmi::Context::ptr& ctx, bool& enable)
1706{
1707 using namespace chassis::internal;
1708 std::string result;
1709 std::string service;
Patrick Williams1318a5e2024-08-16 15:19:54 -04001710 boost::system::error_code ec =
1711 getService(ctx, bootEnableIntf, bootSettingsPath, service);
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001712 if (!ec)
1713 {
1714 ec = ipmi::getDbusProperty(ctx, service, bootSettingsPath,
1715 bootEnableIntf, "Enabled", enable);
1716 if (!ec)
1717 {
1718 return ipmi::ccSuccess;
1719 }
1720 }
Vernon Mauery38108d92024-03-11 12:53:55 -07001721 lg2::error("Error in Boot Override Enable Get: {ERROR}", "ERROR",
1722 ec.message());
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001723 return ipmi::ccUnspecifiedError;
1724}
1725
1726/** @brief Set the property value for boot override enable
1727 * @param[in] ctx - context pointer
1728 * @param[in] enable - boot override enable
1729 * @return On failure return IPMI error.
1730 */
1731static ipmi::Cc setBootEnable(ipmi::Context::ptr& ctx, const bool& enable)
1732{
1733 using namespace chassis::internal;
1734 std::string service;
Patrick Williams1318a5e2024-08-16 15:19:54 -04001735 boost::system::error_code ec =
1736 getService(ctx, bootEnableIntf, bootSettingsPath, service);
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001737 if (!ec)
1738 {
1739 ec = ipmi::setDbusProperty(ctx, service, bootSettingsPath,
1740 bootEnableIntf, "Enabled", enable);
1741 if (!ec)
1742 {
1743 return ipmi::ccSuccess;
1744 }
1745 }
Vernon Mauery38108d92024-03-11 12:53:55 -07001746 lg2::error("Error in Boot Source Override Enable Set: {ERROR}", "ERROR",
1747 ec.message());
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001748 return ipmi::ccUnspecifiedError;
1749}
1750
1751/** @brief Get the property value for boot override one-time
1752 * @param[in] ctx - context pointer
1753 * @param[out] onetime - boot override one-time
1754 * @return On failure return IPMI error.
1755 */
1756static ipmi::Cc getBootOneTime(ipmi::Context::ptr& ctx, bool& onetime)
1757{
1758 using namespace chassis::internal;
1759 std::string result;
1760 std::string service;
Patrick Williams1318a5e2024-08-16 15:19:54 -04001761 boost::system::error_code ec =
1762 getService(ctx, bootOneTimeIntf, bootSettingsOneTimePath, service);
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001763 if (!ec)
1764 {
1765 ec = ipmi::getDbusProperty(ctx, service, bootSettingsOneTimePath,
1766 bootOneTimeIntf, "Enabled", onetime);
1767 if (!ec)
1768 {
1769 return ipmi::ccSuccess;
1770 }
1771 }
Vernon Mauery38108d92024-03-11 12:53:55 -07001772 lg2::error("Error in Boot Override OneTime Get: {ERROR}", "ERROR",
1773 ec.message());
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001774 return ipmi::ccUnspecifiedError;
1775}
1776
1777/** @brief Set the property value for boot override one-time
1778 * @param[in] ctx - context pointer
1779 * @param[in] onetime - boot override one-time
1780 * @return On failure return IPMI error.
1781 */
1782static ipmi::Cc setBootOneTime(ipmi::Context::ptr& ctx, const bool& onetime)
1783{
1784 using namespace chassis::internal;
1785 std::string service;
Patrick Williams1318a5e2024-08-16 15:19:54 -04001786 boost::system::error_code ec =
1787 getService(ctx, bootOneTimeIntf, bootSettingsOneTimePath, service);
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001788 if (!ec)
1789 {
1790 ec = ipmi::setDbusProperty(ctx, service, bootSettingsOneTimePath,
1791 bootOneTimeIntf, "Enabled", onetime);
1792 if (!ec)
1793 {
1794 return ipmi::ccSuccess;
1795 }
1796 }
Vernon Mauery38108d92024-03-11 12:53:55 -07001797 lg2::error("Error in Boot Source Override OneTime Set: {ERROR}", "ERROR",
1798 ec.message());
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001799 return ipmi::ccUnspecifiedError;
1800}
1801
huangheab369282020-10-10 14:40:00 +08001802static constexpr uint8_t setComplete = 0x0;
1803static constexpr uint8_t setInProgress = 0x1;
1804static uint8_t transferStatus = setComplete;
Chen Yugang86ac4992021-06-25 08:14:52 +08001805static uint8_t bootFlagValidBitClr = 0;
Hieu Huynh38ffafc2021-05-14 08:40:14 +00001806static uint5_t bootInitiatorAckData = 0x0;
Hieu Huynh1982a3f2021-09-21 03:06:45 +00001807static bool cmosClear = false;
huangheab369282020-10-10 14:40:00 +08001808
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00001809/** @brief implements the Get Chassis system boot option
Konstantin Aladysheve76a61a2021-03-18 22:19:13 +03001810 * @param ctx - context pointer
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00001811 * @param bootOptionParameter - boot option parameter selector
1812 * @param reserved1 - reserved bit
1813 * @param setSelector - selects a particular block or set of parameters
1814 * under the given parameter selector
1815 * write as 00h if parameter doesn't use a setSelector
1816 * @param blockSelector- selects a particular block within a set of
1817 * parameters write as 00h if parameter doesn't use a
1818 * blockSelector
1819 *
1820 * @return IPMI completion code plus response data
1821 * @return Payload contains below parameters:
1822 * version - parameter version
1823 * bootOptionParameter - boot option parameter selector
Patrick Venture8b1c3032020-09-15 09:43:03 -07001824 * parmIndicator - parameter valid/invalid indicator
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00001825 * data - configuration parameter data
1826 */
Patrick Williams1318a5e2024-08-16 15:19:54 -04001827ipmi::RspType<ipmi::message::Payload> ipmiChassisGetSysBootOptions(
1828 ipmi::Context::ptr ctx, uint7_t bootOptionParameter, bool reserved1,
1829 [[maybe_unused]] uint8_t setSelector,
1830 [[maybe_unused]] uint8_t blockSelector)
Adriana Kobylak40814c62015-10-27 15:58:44 -05001831{
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001832 ipmi::Cc rc;
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00001833 if (reserved1)
1834 {
1835 return ipmi::responseInvalidFieldRequest();
1836 }
1837
1838 constexpr uint4_t version = 0x01;
1839 ipmi::message::Payload response;
1840 response.pack(version, uint4_t{});
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001841 using namespace boot_options;
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00001842
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001843 IpmiValue bootOption = ipmiDefault;
Adriana Kobylak40814c62015-10-27 15:58:44 -05001844
William A. Kennington III7a0e5df2021-05-19 13:31:29 -07001845 if (types::enum_cast<BootOptionParameter>(bootOptionParameter) ==
1846 BootOptionParameter::setInProgress)
huangheab369282020-10-10 14:40:00 +08001847 {
1848 response.pack(bootOptionParameter, reserved1, transferStatus);
1849 return ipmi::responseSuccess(std::move(response));
1850 }
1851
William A. Kennington III7a0e5df2021-05-19 13:31:29 -07001852 if (types::enum_cast<BootOptionParameter>(bootOptionParameter) ==
1853 BootOptionParameter::bootInfo)
John Wang0213f902020-12-28 14:49:57 +08001854 {
1855 constexpr uint8_t writeMask = 0;
Hieu Huynh38ffafc2021-05-14 08:40:14 +00001856 response.pack(bootOptionParameter, reserved1, writeMask,
1857 bootInitiatorAckData);
John Wang0213f902020-12-28 14:49:57 +08001858 return ipmi::responseSuccess(std::move(response));
1859 }
1860
Chen Yugang86ac4992021-06-25 08:14:52 +08001861 if (types::enum_cast<BootOptionParameter>(bootOptionParameter) ==
1862 BootOptionParameter::bootFlagValidClr)
1863 {
1864 response.pack(bootOptionParameter, reserved1,
1865 uint5_t{bootFlagValidBitClr}, uint3_t{});
1866 return ipmi::responseSuccess(std::move(response));
1867 }
1868
shgoupfd84fbbf2015-12-17 10:05:51 +08001869 /*
1870 * Parameter #5 means boot flags. Please refer to 28.13 of ipmi doc.
1871 * This is the only parameter used by petitboot.
1872 */
William A. Kennington III7a0e5df2021-05-19 13:31:29 -07001873 if (types::enum_cast<BootOptionParameter>(bootOptionParameter) ==
1874 BootOptionParameter::bootFlags)
Patrick Venture0b02be92018-08-31 11:55:55 -07001875 {
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001876 using namespace chassis::internal;
1877 using namespace chassis::internal::cache;
shgoupfd84fbbf2015-12-17 10:05:51 +08001878
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001879 try
ratagupta6f6bff2016-04-04 06:20:11 -05001880 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001881 Source::Sources bootSource;
1882 rc = getBootSource(ctx, bootSource);
1883 if (rc != ipmi::ccSuccess)
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001884 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001885 return ipmi::response(rc);
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001886 }
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001887
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001888 Type::Types bootType;
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001889 rc = getBootType(ctx, bootType);
1890 if (rc != ipmi::ccSuccess)
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001891 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001892 return ipmi::response(rc);
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001893 }
1894
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001895 Mode::Modes bootMode;
1896 rc = getBootMode(ctx, bootMode);
1897 if (rc != ipmi::ccSuccess)
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001898 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001899 return ipmi::response(rc);
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001900 }
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001901
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001902 bootOption = sourceDbusToIpmi.at(bootSource);
1903 if ((Mode::Modes::Regular == bootMode) &&
1904 (Source::Sources::Default == bootSource))
1905 {
1906 bootOption = ipmiDefault;
1907 }
1908 else if (Source::Sources::Default == bootSource)
1909 {
1910 bootOption = modeDbusToIpmi.at(bootMode);
1911 }
ratagupta6f6bff2016-04-04 06:20:11 -05001912
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001913 IpmiValue biosBootType = typeDbusToIpmi.at(bootType);
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001914
1915 bool oneTimeEnabled;
1916 rc = getBootOneTime(ctx, oneTimeEnabled);
1917 if (rc != ipmi::ccSuccess)
1918 {
1919 return ipmi::response(rc);
1920 }
1921
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001922 uint1_t permanent = oneTimeEnabled ? 0 : 1;
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001923
1924 bool valid;
1925 rc = getBootEnable(ctx, valid);
1926 if (rc != ipmi::ccSuccess)
1927 {
1928 return ipmi::response(rc);
1929 }
1930
1931 uint1_t validFlag = valid ? 1 : 0;
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001932
1933 response.pack(bootOptionParameter, reserved1, uint5_t{},
1934 uint1_t{biosBootType}, uint1_t{permanent},
1935 uint1_t{validFlag}, uint2_t{}, uint4_t{bootOption},
Hieu Huynh1982a3f2021-09-21 03:06:45 +00001936 uint1_t{}, cmosClear, uint8_t{}, uint8_t{},
1937 uint8_t{});
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00001938 return ipmi::responseSuccess(std::move(response));
ratagupta6f6bff2016-04-04 06:20:11 -05001939 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -05001940 catch (const InternalFailure& e)
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001941 {
James Feist225dec82019-11-26 16:25:06 -08001942 cache::objectsPtr.reset();
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001943 report<InternalFailure>();
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00001944 return ipmi::responseUnspecifiedError();
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001945 }
Patrick Venture0b02be92018-08-31 11:55:55 -07001946 }
Patrick Venture0b02be92018-08-31 11:55:55 -07001947 else
1948 {
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00001949 if ((bootOptionParameter >= oemParmStart) &&
1950 (bootOptionParameter <= oemParmEnd))
1951 {
William A. Kennington III7a0e5df2021-05-19 13:31:29 -07001952 if (types::enum_cast<BootOptionParameter>(bootOptionParameter) ==
1953 BootOptionParameter::opalNetworkSettings)
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00001954 {
1955 response.pack(bootOptionParameter, reserved1);
1956 int ret = getHostNetworkData(response);
1957 if (ret < 0)
1958 {
1959 response.trailingOk = true;
Vernon Mauery38108d92024-03-11 12:53:55 -07001960 lg2::error(
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00001961 "getHostNetworkData failed for GetSysBootOptions.");
1962 return ipmi::responseUnspecifiedError();
1963 }
1964 else
1965 {
1966 return ipmi::responseSuccess(std::move(response));
1967 }
1968 }
Jayaprakash Mutyala43a88102021-08-04 16:41:58 +00001969 else
1970 {
Vernon Mauery38108d92024-03-11 12:53:55 -07001971 lg2::error(
1972 "ipmiChassisGetSysBootOptions: Unsupported parameter {PARAM}",
1973 "PARAM", lg2::hex,
1974 static_cast<uint8_t>(bootOptionParameter));
Jayaprakash Mutyala43a88102021-08-04 16:41:58 +00001975 return ipmi::responseParmNotSupported();
1976 }
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00001977 }
1978 else
1979 {
Vernon Mauery38108d92024-03-11 12:53:55 -07001980 lg2::error(
1981 "ipmiChassisGetSysBootOptions: Unsupported parameter {PARAM}",
1982 "PARAM", lg2::hex, static_cast<uint8_t>(bootOptionParameter));
Jayaprakash Mutyala6088e9f2021-07-14 07:40:29 +00001983 return ipmi::responseParmNotSupported();
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00001984 }
shgoupfd84fbbf2015-12-17 10:05:51 +08001985 }
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00001986 return ipmi::responseUnspecifiedError();
shgoupfd84fbbf2015-12-17 10:05:51 +08001987}
1988
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00001989ipmi::RspType<> ipmiChassisSetSysBootOptions(ipmi::Context::ptr ctx,
Willy Tu11d68892022-01-20 10:37:34 -08001990 uint7_t parameterSelector, bool,
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00001991 ipmi::message::Payload& data)
shgoupfd84fbbf2015-12-17 10:05:51 +08001992{
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001993 using namespace boot_options;
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00001994 ipmi::Cc rc;
shgoupfd84fbbf2015-12-17 10:05:51 +08001995
William A. Kennington III7a0e5df2021-05-19 13:31:29 -07001996 if (types::enum_cast<BootOptionParameter>(parameterSelector) ==
1997 BootOptionParameter::setInProgress)
huangheab369282020-10-10 14:40:00 +08001998 {
1999 uint2_t setInProgressFlag;
2000 uint6_t rsvd;
2001 if (data.unpack(setInProgressFlag, rsvd) != 0 || !data.fullyUnpacked())
2002 {
2003 return ipmi::responseReqDataLenInvalid();
2004 }
2005 if (rsvd)
2006 {
2007 return ipmi::responseInvalidFieldRequest();
2008 }
2009 if ((transferStatus == setInProgress) &&
2010 (static_cast<uint8_t>(setInProgressFlag) != setComplete))
2011 {
2012 return ipmi::response(IPMI_CC_FAIL_SET_IN_PROGRESS);
2013 }
2014 transferStatus = static_cast<uint8_t>(setInProgressFlag);
2015 return ipmi::responseSuccess();
2016 }
2017
shgoupfd84fbbf2015-12-17 10:05:51 +08002018 /* 000101
2019 * Parameter #5 means boot flags. Please refer to 28.13 of ipmi doc.
2020 * This is the only parameter used by petitboot.
2021 */
Ratan Guptafd28dd72016-08-01 04:58:01 -05002022
William A. Kennington III7a0e5df2021-05-19 13:31:29 -07002023 if (types::enum_cast<BootOptionParameter>(parameterSelector) ==
2024 BootOptionParameter::bootFlags)
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05002025 {
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002026 uint5_t rsvd;
2027 bool validFlag;
2028 bool permanent;
2029 bool biosBootType;
2030 bool lockOutResetButton;
2031 bool screenBlank;
2032 uint4_t bootDeviceSelector;
2033 bool lockKeyboard;
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002034 uint8_t data3;
2035 uint4_t biosInfo;
2036 uint4_t rsvd1;
2037 uint5_t deviceInstance;
2038 uint3_t rsvd2;
2039
2040 if (data.unpack(rsvd, biosBootType, permanent, validFlag,
2041 lockOutResetButton, screenBlank, bootDeviceSelector,
2042 lockKeyboard, cmosClear, data3, biosInfo, rsvd1,
2043 deviceInstance, rsvd2) != 0 ||
2044 !data.fullyUnpacked())
2045 {
2046 return ipmi::responseReqDataLenInvalid();
2047 }
2048 if (rsvd || rsvd1 || rsvd2)
2049 {
2050 return ipmi::responseInvalidFieldRequest();
2051 }
2052
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05002053 using namespace chassis::internal;
2054 using namespace chassis::internal::cache;
shgoupfd84fbbf2015-12-17 10:05:51 +08002055
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05002056 try
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05002057 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03002058 rc = setBootOneTime(ctx, !permanent);
2059 if (rc != ipmi::ccSuccess)
Konstantin Aladyshev69e8e842021-06-18 17:01:18 +03002060 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03002061 return ipmi::response(rc);
2062 }
Vernon Maueryafd45db2021-07-29 16:27:25 +00002063
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03002064 rc = setBootEnable(ctx, validFlag);
2065 if (rc != ipmi::ccSuccess)
2066 {
2067 return ipmi::response(rc);
Tom Joseph57e8eb72017-09-25 18:05:02 +05302068 }
2069
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002070 auto modeItr =
2071 modeIpmiToDbus.find(static_cast<uint8_t>(bootDeviceSelector));
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03002072 auto typeItr =
2073 typeIpmiToDbus.find(static_cast<uint8_t>(biosBootType));
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002074 auto sourceItr =
2075 sourceIpmiToDbus.find(static_cast<uint8_t>(bootDeviceSelector));
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05002076 if (sourceIpmiToDbus.end() != sourceItr)
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05002077 {
Konstantin Aladysheve76a61a2021-03-18 22:19:13 +03002078 rc = setBootSource(ctx, sourceItr->second);
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002079 if (rc != ipmi::ccSuccess)
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05002080 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03002081 return ipmi::response(rc);
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05002082 }
Marri Devender Rao54fa1302018-05-07 01:06:23 -05002083 // If a set boot device is mapping to a boot source, then reset
2084 // the boot mode D-Bus property to default.
2085 // This way the ipmid code can determine which property is not
2086 // at the default value
Patrick Venture0b02be92018-08-31 11:55:55 -07002087 if (sourceItr->second != Source::Sources::Default)
Marri Devender Rao54fa1302018-05-07 01:06:23 -05002088 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03002089 rc = setBootMode(ctx, Mode::Modes::Regular);
2090 if (rc != ipmi::ccSuccess)
2091 {
2092 return ipmi::response(rc);
2093 }
Marri Devender Rao54fa1302018-05-07 01:06:23 -05002094 }
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05002095 }
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03002096
2097 if (typeIpmiToDbus.end() != typeItr)
2098 {
Konstantin Aladysheve76a61a2021-03-18 22:19:13 +03002099 rc = setBootType(ctx, typeItr->second);
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03002100 if (rc != ipmi::ccSuccess)
2101 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03002102 return ipmi::response(rc);
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03002103 }
2104 }
2105
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05002106 if (modeIpmiToDbus.end() != modeItr)
2107 {
Konstantin Aladysheve76a61a2021-03-18 22:19:13 +03002108 rc = setBootMode(ctx, modeItr->second);
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002109 if (rc != ipmi::ccSuccess)
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05002110 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03002111 return ipmi::response(rc);
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05002112 }
Marri Devender Rao54fa1302018-05-07 01:06:23 -05002113 // If a set boot device is mapping to a boot mode, then reset
2114 // the boot source D-Bus property to default.
2115 // This way the ipmid code can determine which property is not
2116 // at the default value
Patrick Venture0b02be92018-08-31 11:55:55 -07002117 if (modeItr->second != Mode::Modes::Regular)
Marri Devender Rao54fa1302018-05-07 01:06:23 -05002118 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03002119 rc = setBootSource(ctx, Source::Sources::Default);
2120 if (rc != ipmi::ccSuccess)
2121 {
2122 return ipmi::response(rc);
2123 }
Marri Devender Rao54fa1302018-05-07 01:06:23 -05002124 }
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05002125 }
Jia, chunhui67c5e5d2019-05-06 11:29:54 +08002126 if ((modeIpmiToDbus.end() == modeItr) &&
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03002127 (typeIpmiToDbus.end() == typeItr) &&
Jia, chunhui67c5e5d2019-05-06 11:29:54 +08002128 (sourceIpmiToDbus.end() == sourceItr))
2129 {
2130 // return error if boot option is not supported
Vernon Mauery38108d92024-03-11 12:53:55 -07002131 lg2::error(
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002132 "ipmiChassisSetSysBootOptions: Boot option not supported");
2133 return ipmi::responseInvalidFieldRequest();
Jia, chunhui67c5e5d2019-05-06 11:29:54 +08002134 }
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05002135 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -05002136 catch (const sdbusplus::exception_t& e)
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05002137 {
James Feist225dec82019-11-26 16:25:06 -08002138 objectsPtr.reset();
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05002139 report<InternalFailure>();
Vernon Mauery38108d92024-03-11 12:53:55 -07002140 lg2::error("ipmiChassisSetSysBootOptions: Error in setting Boot "
2141 "flag parameters");
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002142 return ipmi::responseUnspecifiedError();
Ratan Guptafd28dd72016-08-01 04:58:01 -05002143 }
Patrick Venture0b02be92018-08-31 11:55:55 -07002144 }
William A. Kennington III7a0e5df2021-05-19 13:31:29 -07002145 else if (types::enum_cast<BootOptionParameter>(parameterSelector) ==
2146 BootOptionParameter::bootInfo)
Patrick Venture0b02be92018-08-31 11:55:55 -07002147 {
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002148 uint8_t writeMak;
Hieu Huynh38ffafc2021-05-14 08:40:14 +00002149 uint5_t bootInfoAck;
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002150 uint3_t rsvd;
2151
Hieu Huynh38ffafc2021-05-14 08:40:14 +00002152 if (data.unpack(writeMak, bootInfoAck, rsvd) != 0 ||
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002153 !data.fullyUnpacked())
2154 {
2155 return ipmi::responseReqDataLenInvalid();
2156 }
2157 if (rsvd)
2158 {
2159 return ipmi::responseInvalidFieldRequest();
2160 }
Hieu Huynh38ffafc2021-05-14 08:40:14 +00002161 bootInitiatorAckData &= ~writeMak;
2162 bootInitiatorAckData |= (writeMak & bootInfoAck);
Vernon Mauery38108d92024-03-11 12:53:55 -07002163 lg2::info("ipmiChassisSetSysBootOptions: bootInfo parameter set "
2164 "successfully");
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002165 data.trailingOk = true;
2166 return ipmi::responseSuccess();
Patrick Venture0b02be92018-08-31 11:55:55 -07002167 }
Chen Yugang86ac4992021-06-25 08:14:52 +08002168 else if (types::enum_cast<BootOptionParameter>(parameterSelector) ==
2169 BootOptionParameter::bootFlagValidClr)
2170 {
2171 uint5_t bootFlagValidClr;
2172 uint3_t rsvd;
2173
2174 if (data.unpack(bootFlagValidClr, rsvd) != 0 || !data.fullyUnpacked())
2175 {
2176 return ipmi::responseReqDataLenInvalid();
2177 }
2178 if (rsvd)
2179 {
2180 return ipmi::responseInvalidFieldRequest();
2181 }
2182 // store boot flag valid bits clear value
2183 bootFlagValidBitClr = static_cast<uint8_t>(bootFlagValidClr);
Vernon Mauery38108d92024-03-11 12:53:55 -07002184 lg2::info(
Chen Yugang86ac4992021-06-25 08:14:52 +08002185 "ipmiChassisSetSysBootOptions: bootFlagValidBits parameter set "
Vernon Mauery38108d92024-03-11 12:53:55 -07002186 "successfully to {VALUE}",
2187 "VALUE", lg2::hex, bootFlagValidBitClr);
Chen Yugang86ac4992021-06-25 08:14:52 +08002188 return ipmi::responseSuccess();
2189 }
Patrick Venture0b02be92018-08-31 11:55:55 -07002190 else
2191 {
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002192 if ((parameterSelector >= static_cast<uint7_t>(oemParmStart)) &&
2193 (parameterSelector <= static_cast<uint7_t>(oemParmEnd)))
2194 {
William A. Kennington III7a0e5df2021-05-19 13:31:29 -07002195 if (types::enum_cast<BootOptionParameter>(parameterSelector) ==
2196 BootOptionParameter::opalNetworkSettings)
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002197 {
2198 ipmi::Cc ret = setHostNetworkData(data);
2199 if (ret != ipmi::ccSuccess)
2200 {
Vernon Mauery38108d92024-03-11 12:53:55 -07002201 lg2::error("ipmiChassisSetSysBootOptions: Error in "
2202 "setHostNetworkData");
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002203 data.trailingOk = true;
2204 return ipmi::response(ret);
2205 }
2206 data.trailingOk = true;
2207 return ipmi::responseSuccess();
2208 }
2209 else
2210 {
Vernon Mauery38108d92024-03-11 12:53:55 -07002211 lg2::error(
2212 "ipmiChassisSetSysBootOptions: Unsupported param: {PARAM}",
2213 "PARAM", lg2::hex, static_cast<uint8_t>(parameterSelector));
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002214 data.trailingOk = true;
2215 return ipmi::responseParmNotSupported();
2216 }
2217 }
2218 data.trailingOk = true;
2219 return ipmi::responseParmNotSupported();
Adriana Kobylak40814c62015-10-27 15:58:44 -05002220 }
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002221 return ipmi::responseSuccess();
Adriana Kobylak40814c62015-10-27 15:58:44 -05002222}
2223
anil kumar appanaa5a76eb2019-04-30 14:57:24 +00002224/** @brief implements Get POH counter command
2225 * @parameter
2226 * - none
2227 * @returns IPMI completion code plus response data
2228 * - minPerCount - Minutes per count
2229 * - counterReading - counter reading
2230 */
2231ipmi::RspType<uint8_t, // Minutes per count
2232 uint32_t // Counter reading
2233 >
2234 ipmiGetPOHCounter()
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -05002235{
2236 // sd_bus error
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -05002237 try
2238 {
anil kumar appanaa5a76eb2019-04-30 14:57:24 +00002239 return ipmi::responseSuccess(static_cast<uint8_t>(poh::minutesPerCount),
2240 getPOHCounter());
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -05002241 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -05002242 catch (const std::exception& e)
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -05002243 {
Vernon Mauery38108d92024-03-11 12:53:55 -07002244 lg2::error("getPOHCounter error: {ERROR}", "ERROR", e);
anil kumar appanaa5a76eb2019-04-30 14:57:24 +00002245 return ipmi::responseUnspecifiedError();
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -05002246 }
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -05002247}
2248
Jason M. Billsbc996a32019-06-17 15:46:37 -07002249ipmi::RspType<uint3_t, // policy support
2250 uint5_t // reserved
2251 >
Vernon Mauerye278ead2018-10-09 09:23:43 -07002252 ipmiChassisSetPowerRestorePolicy(boost::asio::yield_context yield,
Jason M. Billsbc996a32019-06-17 15:46:37 -07002253 uint3_t policy, uint5_t reserved)
Yong Lic6713cf2018-09-12 12:35:13 +08002254{
Yong Lic6713cf2018-09-12 12:35:13 +08002255 power_policy::DbusValue value =
2256 power_policy::RestorePolicy::Policy::AlwaysOff;
2257
Jason M. Billsbc996a32019-06-17 15:46:37 -07002258 if (reserved || (policy > power_policy::noChange))
Yong Lic6713cf2018-09-12 12:35:13 +08002259 {
Vernon Mauery38108d92024-03-11 12:53:55 -07002260 lg2::error("Reserved request parameter: {REQ}", "REQ", lg2::hex,
2261 static_cast<int>(policy));
Jason M. Billsbc996a32019-06-17 15:46:37 -07002262 return ipmi::responseInvalidFieldRequest();
Yong Lic6713cf2018-09-12 12:35:13 +08002263 }
2264
Vernon Mauerye278ead2018-10-09 09:23:43 -07002265 if (policy == power_policy::noChange)
Yong Lic6713cf2018-09-12 12:35:13 +08002266 {
2267 // just return the supported policy
Jason M. Billsbc996a32019-06-17 15:46:37 -07002268 return ipmi::responseSuccess(power_policy::allSupport, reserved);
Yong Lic6713cf2018-09-12 12:35:13 +08002269 }
2270
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05002271 for (const auto& it : power_policy::dbusToIpmi)
Yong Lic6713cf2018-09-12 12:35:13 +08002272 {
Vernon Mauerye278ead2018-10-09 09:23:43 -07002273 if (it.second == policy)
Yong Lic6713cf2018-09-12 12:35:13 +08002274 {
2275 value = it.first;
2276 break;
2277 }
2278 }
2279
2280 try
2281 {
James Feist225dec82019-11-26 16:25:06 -08002282 settings::Objects& objects = chassis::internal::cache::getObjects();
Yong Lic6713cf2018-09-12 12:35:13 +08002283 const settings::Path& powerRestoreSetting =
James Feist225dec82019-11-26 16:25:06 -08002284 objects.map.at(chassis::internal::powerRestoreIntf).front();
Vernon Mauery16b86932019-05-01 08:36:11 -07002285 std::variant<std::string> property = convertForMessage(value);
Yong Lic6713cf2018-09-12 12:35:13 +08002286
Vernon Mauerye278ead2018-10-09 09:23:43 -07002287 auto sdbusp = getSdBus();
2288 boost::system::error_code ec;
2289 sdbusp->yield_method_call<void>(
2290 yield, ec,
James Feist225dec82019-11-26 16:25:06 -08002291 objects
Yong Lic6713cf2018-09-12 12:35:13 +08002292 .service(powerRestoreSetting,
2293 chassis::internal::powerRestoreIntf)
2294 .c_str(),
Vernon Mauerye278ead2018-10-09 09:23:43 -07002295 powerRestoreSetting, ipmi::PROP_INTF, "Set",
2296 chassis::internal::powerRestoreIntf, "PowerRestorePolicy",
2297 property);
2298 if (ec)
Yong Lic6713cf2018-09-12 12:35:13 +08002299 {
Vernon Mauery38108d92024-03-11 12:53:55 -07002300 lg2::error("Unspecified Error");
Vernon Mauerye278ead2018-10-09 09:23:43 -07002301 return ipmi::responseUnspecifiedError();
Yong Lic6713cf2018-09-12 12:35:13 +08002302 }
2303 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -05002304 catch (const InternalFailure& e)
Yong Lic6713cf2018-09-12 12:35:13 +08002305 {
James Feist225dec82019-11-26 16:25:06 -08002306 chassis::internal::cache::objectsPtr.reset();
Yong Lic6713cf2018-09-12 12:35:13 +08002307 report<InternalFailure>();
Vernon Mauerye278ead2018-10-09 09:23:43 -07002308 return ipmi::responseUnspecifiedError();
Yong Lic6713cf2018-09-12 12:35:13 +08002309 }
2310
Jason M. Billsbc996a32019-06-17 15:46:37 -07002311 return ipmi::responseSuccess(power_policy::allSupport, reserved);
Yong Lic6713cf2018-09-12 12:35:13 +08002312}
2313
Patrick Williams1318a5e2024-08-16 15:19:54 -04002314ipmi::RspType<> ipmiSetFrontPanelButtonEnables(
2315 ipmi::Context::ptr ctx, bool disablePowerButton, bool disableResetButton,
2316 bool, bool, uint4_t)
Kuiying Wang21addc52019-01-04 10:50:21 +08002317{
2318 using namespace chassis::internal;
2319
2320 // set power button Enabled property
2321 bool success = setButtonEnabled(ctx, powerButtonPath, powerButtonIntf,
2322 !disablePowerButton);
2323
2324 // set reset button Enabled property
2325 success &= setButtonEnabled(ctx, resetButtonPath, resetButtonIntf,
2326 !disableResetButton);
2327
2328 if (!success)
2329 {
2330 // not all buttons were successfully set
2331 return ipmi::responseUnspecifiedError();
2332 }
2333 return ipmi::responseSuccess();
2334}
2335
Adriana Kobylak40814c62015-10-27 15:58:44 -05002336void register_netfn_chassis_functions()
2337{
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05002338 createIdentifyTimer();
2339
Tom05732372016-09-06 17:21:23 +05302340 // Get Chassis Capabilities
anil kumar appana43263c62019-05-27 12:45:04 +00002341 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis,
2342 ipmi::chassis::cmdGetChassisCapabilities,
2343 ipmi::Privilege::User, ipmiGetChassisCap);
Nan Li8d15fb42016-08-16 22:29:40 +08002344
Kuiying Wang21addc52019-01-04 10:50:21 +08002345 // Set Front Panel Button Enables
2346 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis,
2347 ipmi::chassis::cmdSetFrontPanelButtonEnables,
2348 ipmi::Privilege::Admin,
2349 ipmiSetFrontPanelButtonEnables);
2350
Yong Liae4b0402018-11-02 11:12:14 +08002351 // Set Chassis Capabilities
anil kumar appana894d0222019-05-27 16:32:14 +00002352 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis,
2353 ipmi::chassis::cmdSetChassisCapabilities,
2354 ipmi::Privilege::User, ipmiSetChassisCap);
Yong Liae4b0402018-11-02 11:12:14 +08002355
Tom05732372016-09-06 17:21:23 +05302356 // <Get System Boot Options>
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00002357 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis,
2358 ipmi::chassis::cmdGetSystemBootOptions,
2359 ipmi::Privilege::Operator,
2360 ipmiChassisGetSysBootOptions);
Adriana Kobylak40814c62015-10-27 15:58:44 -05002361
Tom05732372016-09-06 17:21:23 +05302362 // <Get Chassis Status>
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07002363 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis,
2364 ipmi::chassis::cmdGetChassisStatus,
2365 ipmi::Privilege::User, ipmiGetChassisStatus);
Nan Lifdd8ec52016-08-28 03:57:40 +08002366
Vijay Khemka074f64d2020-03-03 15:08:43 -08002367 // <Chassis Get System Restart Cause>
2368 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis,
2369 ipmi::chassis::cmdGetSystemRestartCause,
2370 ipmi::Privilege::User, ipmiGetSystemRestartCause);
2371
Tom05732372016-09-06 17:21:23 +05302372 // <Chassis Control>
anil kumar appanadafff5f2019-04-27 18:06:00 +00002373 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis,
2374 ipmi::chassis::cmdChassisControl,
2375 ipmi::Privilege::Operator, ipmiChassisControl);
shgoupfd84fbbf2015-12-17 10:05:51 +08002376
Tom Joseph5110c122018-03-23 17:55:40 +05302377 // <Chassis Identify>
Vernon Mauery400cc782018-10-09 13:49:53 -07002378 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis,
2379 ipmi::chassis::cmdChassisIdentify,
2380 ipmi::Privilege::Operator, ipmiChassisIdentify);
Tom Joseph5110c122018-03-23 17:55:40 +05302381
Tom05732372016-09-06 17:21:23 +05302382 // <Set System Boot Options>
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002383 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis,
2384 ipmi::chassis::cmdSetSystemBootOptions,
2385 ipmi::Privilege::Operator,
2386 ipmiChassisSetSysBootOptions);
2387
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -05002388 // <Get POH Counter>
anil kumar appanaa5a76eb2019-04-30 14:57:24 +00002389 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis,
2390 ipmi::chassis::cmdGetPohCounter,
2391 ipmi::Privilege::User, ipmiGetPOHCounter);
Yong Lic6713cf2018-09-12 12:35:13 +08002392
2393 // <Set Power Restore Policy>
Vernon Mauerye278ead2018-10-09 09:23:43 -07002394 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis,
2395 ipmi::chassis::cmdSetPowerRestorePolicy,
2396 ipmi::Privilege::Operator,
2397 ipmiChassisSetPowerRestorePolicy);
vishwa36993272015-11-20 12:43:49 -06002398}