blob: 32344a78a1536806ac720a6be1d98462c73ef104 [file] [log] [blame]
Patrick Venture46470a32018-09-07 19:26:25 -07001#include "config.h"
2
3#include "chassishandler.hpp"
Patrick Venture0b02be92018-08-31 11:55:55 -07004
Patrick Venture0b02be92018-08-31 11:55:55 -07005#include <arpa/inet.h>
6#include <endian.h>
7#include <limits.h>
8#include <mapper.h>
9#include <netinet/in.h>
Patrick Venture0b02be92018-08-31 11:55:55 -070010
Ratan Guptafd28dd72016-08-01 04:58:01 -050011#include <array>
Patrick Venture0b02be92018-08-31 11:55:55 -070012#include <chrono>
Patrick Ventureb51bf9c2018-09-10 15:53:14 -070013#include <cstring>
Vernon Mauerybdda8002019-02-26 10:18:51 -080014#include <filesystem>
Andrew Geisslera6e3a302017-05-31 19:34:00 -050015#include <fstream>
Tom Joseph5110c122018-03-23 17:55:40 +053016#include <future>
Vernon Mauerye08fbff2019-04-03 09:19:34 -070017#include <ipmid/api.hpp>
Vernon Mauery33250242019-03-12 16:49:26 -070018#include <ipmid/types.hpp>
Vernon Mauery6a98fe72019-03-11 15:57:48 -070019#include <ipmid/utils.hpp>
Patrick Venture3a5071a2018-09-12 13:27:42 -070020#include <map>
21#include <phosphor-logging/elog-errors.hpp>
22#include <phosphor-logging/log.hpp>
23#include <sdbusplus/bus.hpp>
William A. Kennington III4c008022018-10-12 17:18:14 -070024#include <sdbusplus/message/types.hpp>
Patrick Venture3a5071a2018-09-12 13:27:42 -070025#include <sdbusplus/server/object.hpp>
Vernon Mauery1181af72018-10-08 12:05:00 -070026#include <sdbusplus/timer.hpp>
Vernon Mauerye278ead2018-10-09 09:23:43 -070027#include <settings.hpp>
Patrick Venture0b02be92018-08-31 11:55:55 -070028#include <sstream>
Patrick Venture3a5071a2018-09-12 13:27:42 -070029#include <string>
30#include <xyz/openbmc_project/Common/error.hpp>
31#include <xyz/openbmc_project/Control/Boot/Mode/server.hpp>
32#include <xyz/openbmc_project/Control/Boot/Source/server.hpp>
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +030033#include <xyz/openbmc_project/Control/Boot/Type/server.hpp>
Patrick Venture3a5071a2018-09-12 13:27:42 -070034#include <xyz/openbmc_project/Control/Power/RestorePolicy/server.hpp>
35#include <xyz/openbmc_project/State/Host/server.hpp>
36#include <xyz/openbmc_project/State/PowerOnHours/server.hpp>
37
Lei YU4b0ddb62019-01-25 16:43:50 +080038std::unique_ptr<phosphor::Timer> identifyTimer
39 __attribute__((init_priority(101)));
Marri Devender Rao6706c1c2018-05-14 00:29:38 -050040
Yong Lif4e38512019-05-21 14:46:55 +080041static ChassisIDState chassisIDState = ChassisIDState::reserved;
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +000042static constexpr uint8_t setParmVersion = 0x01;
Yong Lif4e38512019-05-21 14:46:55 +080043
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
Marri Devender Rao6706c1c2018-05-14 00:29:38 -050060static constexpr size_t encIdentifyObjectsSize = 1;
61static constexpr size_t chassisIdentifyReqLength = 2;
62static constexpr size_t identifyIntervalPos = 0;
63static constexpr size_t forceIdentifyPos = 1;
shgoupfd84fbbf2015-12-17 10:05:51 +080064
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +000065namespace ipmi
66{
67constexpr Cc ccParmNotSupported = 0x80;
68
69static inline auto responseParmNotSupported()
70{
71 return response(ccParmNotSupported);
72}
73} // namespace ipmi
74
Adriana Kobylak40814c62015-10-27 15:58:44 -050075void register_netfn_chassis_functions() __attribute__((constructor));
76
shgoupfd84fbbf2015-12-17 10:05:51 +080077// Host settings in dbus
78// Service name should be referenced by connection name got via object mapper
Patrick Venture0b02be92018-08-31 11:55:55 -070079const char* settings_object_name = "/org/openbmc/settings/host0";
80const char* settings_intf_name = "org.freedesktop.DBus.Properties";
Patrick Venture0b02be92018-08-31 11:55:55 -070081const char* identify_led_object_name =
Tom Joseph5110c122018-03-23 17:55:40 +053082 "/xyz/openbmc_project/led/groups/enclosure_identify";
shgoupfd84fbbf2015-12-17 10:05:51 +080083
Ratan Guptadcb10672017-07-10 10:33:50 +053084constexpr auto SETTINGS_ROOT = "/";
85constexpr auto SETTINGS_MATCH = "host0";
Ratan Guptadcb10672017-07-10 10:33:50 +053086
87constexpr auto IP_INTERFACE = "xyz.openbmc_project.Network.IP";
88constexpr auto MAC_INTERFACE = "xyz.openbmc_project.Network.MACAddress";
89
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -050090static constexpr auto chassisStateRoot = "/xyz/openbmc_project/state";
91static constexpr auto chassisPOHStateIntf =
Patrick Venture0b02be92018-08-31 11:55:55 -070092 "xyz.openbmc_project.State.PowerOnHours";
Patrick Williams7345ac42021-04-30 20:57:39 -050093static constexpr auto pohCounterProperty = "POHCounter";
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -050094static constexpr auto match = "chassis0";
Yong Liae4b0402018-11-02 11:12:14 +080095const static constexpr char chassisCapIntf[] =
96 "xyz.openbmc_project.Control.ChassisCapabilities";
Karthick Sundarrajan86d8bd72019-11-26 12:48:50 -080097const static constexpr char chassisIntrusionProp[] = "ChassisIntrusionEnabled";
98const static constexpr char chassisFrontPanelLockoutProp[] =
99 "ChassisFrontPanelLockoutEnabled";
100const static constexpr char chassisNMIProp[] = "ChassisNMIEnabled";
101const static constexpr char chassisPowerInterlockProp[] =
102 "ChassisPowerInterlockEnabled";
Yong Liae4b0402018-11-02 11:12:14 +0800103const static constexpr char chassisFRUDevAddrProp[] = "FRUDeviceAddress";
104const static constexpr char chassisSDRDevAddrProp[] = "SDRDeviceAddress";
105const static constexpr char chassisSELDevAddrProp[] = "SELDeviceAddress";
106const static constexpr char chassisSMDevAddrProp[] = "SMDeviceAddress";
107const static constexpr char chassisBridgeDevAddrProp[] = "BridgeDeviceAddress";
108static constexpr uint8_t chassisCapFlagMask = 0x0f;
109static constexpr uint8_t chassisCapAddrMask = 0xfe;
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700110static constexpr const char* powerButtonIntf =
111 "xyz.openbmc_project.Chassis.Buttons.Power";
112static constexpr const char* powerButtonPath =
113 "/xyz/openbmc_project/Chassis/Buttons/Power0";
114static constexpr const char* resetButtonIntf =
115 "xyz.openbmc_project.Chassis.Buttons.Reset";
116static constexpr const char* resetButtonPath =
117 "/xyz/openbmc_project/Chassis/Buttons/Reset0";
Ratan Guptadcb10672017-07-10 10:33:50 +0530118
Vishwanatha Subbannab12b0c02017-03-07 18:17:19 +0530119// Phosphor Host State manager
120namespace State = sdbusplus::xyz::openbmc_project::State::server;
121
Vernon Mauery185b9f82018-07-20 10:52:36 -0700122namespace fs = std::filesystem;
Andrew Geisslera6e3a302017-05-31 19:34:00 -0500123
Ratan Guptadcb10672017-07-10 10:33:50 +0530124using namespace phosphor::logging;
125using namespace sdbusplus::xyz::openbmc_project::Common::Error;
Marri Devender Rao81719702018-05-07 00:53:48 -0500126using namespace sdbusplus::xyz::openbmc_project::Control::Boot::server;
William A. Kennington III4c008022018-10-12 17:18:14 -0700127
Deepak Kodihalli8cc19362017-07-21 11:18:38 -0500128namespace chassis
129{
130namespace internal
131{
132
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +0300133constexpr auto bootSettingsPath = "/xyz/openbmc_project/control/host0/boot";
134constexpr auto bootEnableIntf = "xyz.openbmc_project.Object.Enable";
Deepak Kodihalli8cc19362017-07-21 11:18:38 -0500135constexpr auto bootModeIntf = "xyz.openbmc_project.Control.Boot.Mode";
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +0300136constexpr auto bootTypeIntf = "xyz.openbmc_project.Control.Boot.Type";
Deepak Kodihalli8cc19362017-07-21 11:18:38 -0500137constexpr auto bootSourceIntf = "xyz.openbmc_project.Control.Boot.Source";
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +0300138constexpr auto bootSettingsOneTimePath =
139 "/xyz/openbmc_project/control/host0/boot/one_time";
140constexpr auto bootOneTimeIntf = "xyz.openbmc_project.Object.Enable";
141
Deepak Kodihalli18b70d12017-07-21 13:36:33 -0500142constexpr auto powerRestoreIntf =
143 "xyz.openbmc_project.Control.Power.RestorePolicy";
Deepak Kodihalli8cc19362017-07-21 11:18:38 -0500144sdbusplus::bus::bus dbus(ipmid_get_sd_bus_connection());
145
146namespace cache
147{
148
James Feist225dec82019-11-26 16:25:06 -0800149std::unique_ptr<settings::Objects> objectsPtr = nullptr;
150
151settings::Objects& getObjects()
152{
153 if (objectsPtr == nullptr)
154 {
155 objectsPtr = std::make_unique<settings::Objects>(
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +0300156 dbus, std::vector<std::string>{bootModeIntf, bootTypeIntf,
157 bootSourceIntf, powerRestoreIntf});
James Feist225dec82019-11-26 16:25:06 -0800158 }
159 return *objectsPtr;
160}
Deepak Kodihalli8cc19362017-07-21 11:18:38 -0500161
162} // namespace cache
163} // namespace internal
164} // namespace chassis
165
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -0500166namespace poh
167{
168
169constexpr auto minutesPerCount = 60;
170
171} // namespace poh
172
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000173int getHostNetworkData(ipmi::message::Payload& payload)
Ratan Guptafd28dd72016-08-01 04:58:01 -0500174{
Ratan Guptadcb10672017-07-10 10:33:50 +0530175 ipmi::PropertyMap properties;
176 int rc = 0;
Ratan Gupta8c31d232017-08-13 05:49:43 +0530177 uint8_t addrSize = ipmi::network::IPV4_ADDRESS_SIZE_BYTE;
Ratan Guptafd28dd72016-08-01 04:58:01 -0500178
Ratan Guptadcb10672017-07-10 10:33:50 +0530179 try
180 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700181 // TODO There may be cases where an interface is implemented by multiple
Ratan Guptadcb10672017-07-10 10:33:50 +0530182 // objects,to handle such cases we are interested on that object
183 // which are on interested busname.
184 // Currenlty mapper doesn't give the readable busname(gives busid)
185 // so we can't match with bus name so giving some object specific info
186 // as SETTINGS_MATCH.
187 // Later SETTINGS_MATCH will be replaced with busname.
Ratan Guptafd28dd72016-08-01 04:58:01 -0500188
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530189 sdbusplus::bus::bus bus(ipmid_get_sd_bus_connection());
Ratan Guptadcb10672017-07-10 10:33:50 +0530190
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530191 auto ipObjectInfo = ipmi::getDbusObject(bus, IP_INTERFACE,
192 SETTINGS_ROOT, SETTINGS_MATCH);
193
194 auto macObjectInfo = ipmi::getDbusObject(bus, MAC_INTERFACE,
195 SETTINGS_ROOT, SETTINGS_MATCH);
196
Patrick Venture0b02be92018-08-31 11:55:55 -0700197 properties = ipmi::getAllDbusProperties(
198 bus, ipObjectInfo.second, ipObjectInfo.first, IP_INTERFACE);
199 auto variant = ipmi::getDbusProperty(bus, macObjectInfo.second,
200 macObjectInfo.first, MAC_INTERFACE,
201 "MACAddress");
Ratan Guptadcb10672017-07-10 10:33:50 +0530202
Vernon Maueryf442e112019-04-09 11:44:36 -0700203 auto ipAddress = std::get<std::string>(properties["Address"]);
Ratan Guptad70f4532017-08-04 02:07:31 +0530204
Vernon Maueryf442e112019-04-09 11:44:36 -0700205 auto gateway = std::get<std::string>(properties["Gateway"]);
Ratan Guptad70f4532017-08-04 02:07:31 +0530206
Vernon Maueryf442e112019-04-09 11:44:36 -0700207 auto prefix = std::get<uint8_t>(properties["PrefixLength"]);
Ratan Guptad70f4532017-08-04 02:07:31 +0530208
Patrick Venture0b02be92018-08-31 11:55:55 -0700209 uint8_t isStatic =
Vernon Maueryf442e112019-04-09 11:44:36 -0700210 (std::get<std::string>(properties["Origin"]) ==
Patrick Venture0b02be92018-08-31 11:55:55 -0700211 "xyz.openbmc_project.Network.IP.AddressOrigin.Static")
212 ? 1
213 : 0;
Ratan Guptad70f4532017-08-04 02:07:31 +0530214
Vernon Maueryf442e112019-04-09 11:44:36 -0700215 auto MACAddress = std::get<std::string>(variant);
Ratan Guptacc8feb42017-07-25 21:52:10 +0530216
Ratan Guptad70f4532017-08-04 02:07:31 +0530217 // it is expected here that we should get the valid data
218 // but we may also get the default values.
219 // Validation of the data is done by settings.
220 //
221 // if mac address is default mac address then
222 // don't send blank override.
Ratan Gupta8c31d232017-08-13 05:49:43 +0530223 if ((MACAddress == ipmi::network::DEFAULT_MAC_ADDRESS))
Ratan Guptad70f4532017-08-04 02:07:31 +0530224 {
Ratan Guptad70f4532017-08-04 02:07:31 +0530225 rc = -1;
226 return rc;
227 }
228 // if addr is static then ipaddress,gateway,prefix
229 // should not be default one,don't send blank override.
230 if (isStatic)
231 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700232 if ((ipAddress == ipmi::network::DEFAULT_ADDRESS) ||
233 (gateway == ipmi::network::DEFAULT_ADDRESS) || (!prefix))
Ratan Guptad70f4532017-08-04 02:07:31 +0530234 {
Ratan Guptad70f4532017-08-04 02:07:31 +0530235 rc = -1;
236 return rc;
237 }
238 }
239
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000240 std::string token;
241 std::stringstream ss(MACAddress);
Ratan Guptadcb10672017-07-10 10:33:50 +0530242
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000243 // First pack macOffset no of bytes in payload.
244 // Latter this PetiBoot-Specific data will be populated.
245 std::vector<uint8_t> payloadInitialBytes(macOffset);
246 payload.pack(payloadInitialBytes);
Ratan Guptadcb10672017-07-10 10:33:50 +0530247
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000248 while (std::getline(ss, token, ':'))
249 {
250 payload.pack(stoi(token, nullptr, 16));
251 }
252
253 payload.pack(0x00);
254
255 payload.pack(isStatic);
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530256
Vernon Maueryf442e112019-04-09 11:44:36 -0700257 uint8_t addressFamily = (std::get<std::string>(properties["Type"]) ==
258 "xyz.openbmc_project.Network.IP.Protocol.IPv4")
259 ? AF_INET
260 : AF_INET6;
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530261
Patrick Venture0b02be92018-08-31 11:55:55 -0700262 addrSize = (addressFamily == AF_INET)
263 ? ipmi::network::IPV4_ADDRESS_SIZE_BYTE
264 : ipmi::network::IPV6_ADDRESS_SIZE_BYTE;
Ratan Guptadcb10672017-07-10 10:33:50 +0530265
266 // ipaddress and gateway would be in IPv4 format
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000267 std::vector<uint8_t> addrInBinary(addrSize);
Ratan Guptad70f4532017-08-04 02:07:31 +0530268 inet_pton(addressFamily, ipAddress.c_str(),
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000269 reinterpret_cast<void*>(addrInBinary.data()));
Ratan Guptadcb10672017-07-10 10:33:50 +0530270
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000271 payload.pack(addrInBinary);
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530272
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000273 payload.pack(prefix);
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530274
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000275 std::vector<uint8_t> gatewayDetails(addrSize);
Ratan Guptad70f4532017-08-04 02:07:31 +0530276 inet_pton(addressFamily, gateway.c_str(),
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000277 reinterpret_cast<void*>(gatewayDetails.data()));
278 payload.pack(gatewayDetails);
Ratan Guptadcb10672017-07-10 10:33:50 +0530279 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -0500280 catch (const InternalFailure& e)
Ratan Guptadcb10672017-07-10 10:33:50 +0530281 {
282 commit<InternalFailure>();
Ratan Guptadcb10672017-07-10 10:33:50 +0530283 rc = -1;
Ratan Guptafd28dd72016-08-01 04:58:01 -0500284 return rc;
285 }
286
Patrick Venture0b02be92018-08-31 11:55:55 -0700287 // PetiBoot-Specific
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000288 // If success then copy the first 9 bytes to the payload message
289 // payload first 2 bytes contain the parameter values. Skip that 2 bytes.
290 uint8_t skipFirstTwoBytes = 2;
291 size_t payloadSize = payload.size();
292 uint8_t* configDataStartingAddress = payload.data() + skipFirstTwoBytes;
Ratan Guptafd28dd72016-08-01 04:58:01 -0500293
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000294 if (payloadSize < skipFirstTwoBytes + sizeof(netConfInitialBytes))
295 {
296 log<level::ERR>("Invalid net config ");
297 rc = -1;
298 return rc;
299 }
300 std::copy(netConfInitialBytes,
301 netConfInitialBytes + sizeof(netConfInitialBytes),
302 configDataStartingAddress);
303
304 if (payloadSize < skipFirstTwoBytes + addrSizeOffset + sizeof(addrSize))
305 {
306 log<level::ERR>("Invalid length of address size");
307 rc = -1;
308 return rc;
309 }
310 std::copy(&addrSize, &(addrSize) + sizeof(addrSize),
311 configDataStartingAddress + addrSizeOffset);
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530312
Ratan Guptafd28dd72016-08-01 04:58:01 -0500313#ifdef _IPMI_DEBUG_
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700314 std::printf("\n===Printing the IPMI Formatted Data========\n");
Ratan Guptafd28dd72016-08-01 04:58:01 -0500315
Ratan Guptadcb10672017-07-10 10:33:50 +0530316 for (uint8_t pos = 0; pos < index; pos++)
317 {
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +0000318 std::printf("%02x ", payloadStartingAddress[pos]);
Ratan Guptadcb10672017-07-10 10:33:50 +0530319 }
Ratan Guptafd28dd72016-08-01 04:58:01 -0500320#endif
321
Ratan Guptafd28dd72016-08-01 04:58:01 -0500322 return rc;
323}
324
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530325/** @brief convert IPv4 and IPv6 addresses from binary to text form.
326 * @param[in] family - IPv4/Ipv6
327 * @param[in] data - req data pointer.
328 * @param[in] offset - offset in the data.
329 * @param[in] addrSize - size of the data which needs to be read from offset.
330 * @returns address in text form.
331 */
332
Patrick Venture0b02be92018-08-31 11:55:55 -0700333std::string getAddrStr(uint8_t family, uint8_t* data, uint8_t offset,
334 uint8_t addrSize)
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530335{
336 char ipAddr[INET6_ADDRSTRLEN] = {};
337
Patrick Venture0b02be92018-08-31 11:55:55 -0700338 switch (family)
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530339 {
340 case AF_INET:
341 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700342 struct sockaddr_in addr4
343 {
344 };
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700345 std::memcpy(&addr4.sin_addr.s_addr, &data[offset], addrSize);
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530346
Patrick Venture0b02be92018-08-31 11:55:55 -0700347 inet_ntop(AF_INET, &addr4.sin_addr, ipAddr, INET_ADDRSTRLEN);
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530348
349 break;
350 }
351 case AF_INET6:
352 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700353 struct sockaddr_in6 addr6
354 {
355 };
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700356 std::memcpy(&addr6.sin6_addr.s6_addr, &data[offset], addrSize);
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530357
Patrick Venture0b02be92018-08-31 11:55:55 -0700358 inet_ntop(AF_INET6, &addr6.sin6_addr, ipAddr, INET6_ADDRSTRLEN);
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530359
360 break;
361 }
362 default:
363 {
364 return {};
365 }
366 }
367
368 return ipAddr;
369}
370
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000371ipmi::Cc setHostNetworkData(ipmi::message::Payload& data)
Ratan Guptafd28dd72016-08-01 04:58:01 -0500372{
Ratan Guptadcb10672017-07-10 10:33:50 +0530373 using namespace std::string_literals;
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000374 std::string hostNetworkConfig;
375 std::string mac("00:00:00:00:00:00");
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530376 std::string ipAddress, gateway;
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000377 std::string addrOrigin{0};
Patrick Venture0b02be92018-08-31 11:55:55 -0700378 uint8_t addrSize{0};
Ratan Guptadcb10672017-07-10 10:33:50 +0530379 std::string addressOrigin =
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530380 "xyz.openbmc_project.Network.IP.AddressOrigin.DHCP";
Patrick Venture0b02be92018-08-31 11:55:55 -0700381 std::string addressType = "xyz.openbmc_project.Network.IP.Protocol.IPv4";
382 uint8_t prefix{0};
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530383 uint8_t family = AF_INET;
Ratan Guptafd28dd72016-08-01 04:58:01 -0500384
Patrick Venture0b02be92018-08-31 11:55:55 -0700385 // cookie starts from second byte
Ratan Guptafd28dd72016-08-01 04:58:01 -0500386 // version starts from sixth byte
387
Ratan Guptadcb10672017-07-10 10:33:50 +0530388 try
Ratan Guptafd28dd72016-08-01 04:58:01 -0500389 {
Ratan Guptadcb10672017-07-10 10:33:50 +0530390 do
391 {
392 // cookie == 0x21 0x70 0x62 0x21
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000393 data.trailingOk = true;
394 auto msgLen = data.size();
395 std::vector<uint8_t> msgPayloadBytes(msgLen);
396 if (data.unpack(msgPayloadBytes) != 0 || !data.fullyUnpacked())
Ratan Guptadcb10672017-07-10 10:33:50 +0530397 {
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000398 log<level::ERR>(
399 "Error in unpacking message of setHostNetworkData");
400 return ipmi::ccReqDataLenInvalid;
401 }
402
403 uint8_t* msgPayloadStartingPos = msgPayloadBytes.data();
404 constexpr size_t cookieSize = 4;
405 if (msgLen < cookieOffset + cookieSize)
406 {
407 log<level::ERR>(
408 "Error in cookie getting of setHostNetworkData");
409 return ipmi::ccReqDataLenInvalid;
410 }
411 if (std::equal(msgPayloadStartingPos + cookieOffset,
412 msgPayloadStartingPos + cookieOffset + cookieSize,
413 (netConfInitialBytes + cookieOffset)) != 0)
414 {
415 // all cookie == 0
416 if (std::all_of(msgPayloadStartingPos + cookieOffset,
417 msgPayloadStartingPos + cookieOffset +
418 cookieSize,
419 [](int i) { return i == 0; }) == true)
Ratan Guptadcb10672017-07-10 10:33:50 +0530420 {
421 // need to zero out the network settings.
422 break;
423 }
424
425 log<level::ERR>("Invalid Cookie");
426 elog<InternalFailure>();
427 }
428
429 // vesion == 0x00 0x01
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000430 if (msgLen < versionOffset + sizeVersion)
Ratan Guptadcb10672017-07-10 10:33:50 +0530431 {
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000432 log<level::ERR>(
433 "Error in version getting of setHostNetworkData");
434 return ipmi::ccReqDataLenInvalid;
435 }
436 if (std::equal(msgPayloadStartingPos + versionOffset,
437 msgPayloadStartingPos + versionOffset + sizeVersion,
438 (netConfInitialBytes + versionOffset)) != 0)
439 {
Ratan Guptadcb10672017-07-10 10:33:50 +0530440 log<level::ERR>("Invalid Version");
441 elog<InternalFailure>();
442 }
443
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000444 if (msgLen < macOffset + 6)
445 {
446 log<level::ERR>(
447 "Error in mac address getting of setHostNetworkData");
448 return ipmi::ccReqDataLenInvalid;
449 }
450 std::stringstream result;
451 std::copy((msgPayloadStartingPos + macOffset),
452 (msgPayloadStartingPos + macOffset + 5),
453 std::ostream_iterator<int>(result, ":"));
454 mac = result.str();
Ratan Guptadcb10672017-07-10 10:33:50 +0530455
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000456 if (msgLen < addrTypeOffset + sizeof(decltype(addrOrigin)))
457 {
458 log<level::ERR>(
459 "Error in original address getting of setHostNetworkData");
460 return ipmi::ccReqDataLenInvalid;
461 }
462 std::copy(msgPayloadStartingPos + addrTypeOffset,
463 msgPayloadStartingPos + addrTypeOffset +
464 sizeof(decltype(addrOrigin)),
465 std::ostream_iterator<int>(result, ""));
466 addrOrigin = result.str();
Ratan Guptadcb10672017-07-10 10:33:50 +0530467
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000468 if (!addrOrigin.empty())
Ratan Guptadcb10672017-07-10 10:33:50 +0530469 {
470 addressOrigin =
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530471 "xyz.openbmc_project.Network.IP.AddressOrigin.Static";
Ratan Guptadcb10672017-07-10 10:33:50 +0530472 }
473
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000474 if (msgLen < addrSizeOffset + sizeof(decltype(addrSize)))
475 {
476 log<level::ERR>(
477 "Error in address size getting of setHostNetworkData");
478 return ipmi::ccReqDataLenInvalid;
479 }
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530480 // Get the address size
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000481 std::copy(msgPayloadStartingPos + addrSizeOffset,
482 (msgPayloadStartingPos + addrSizeOffset +
483 sizeof(decltype(addrSize))),
484 &addrSize);
Ratan Guptadcb10672017-07-10 10:33:50 +0530485
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000486 uint8_t prefixOffset = ipAddrOffset + addrSize;
487 if (msgLen < prefixOffset + sizeof(decltype(prefix)))
488 {
489 log<level::ERR>(
490 "Error in prefix getting of setHostNetworkData");
491 return ipmi::ccReqDataLenInvalid;
492 }
493 std::copy(msgPayloadStartingPos + prefixOffset,
494 (msgPayloadStartingPos + prefixOffset +
495 sizeof(decltype(prefix))),
496 &prefix);
Ratan Guptadcb10672017-07-10 10:33:50 +0530497
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530498 uint8_t gatewayOffset = prefixOffset + sizeof(decltype(prefix));
Ratan Gupta8c31d232017-08-13 05:49:43 +0530499 if (addrSize != ipmi::network::IPV4_ADDRESS_SIZE_BYTE)
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530500 {
501 addressType = "xyz.openbmc_project.Network.IP.Protocol.IPv6";
502 family = AF_INET6;
503 }
504
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000505 if (msgLen < ipAddrOffset + addrSize)
506 {
507 log<level::ERR>(
508 "Error in IP address getting of setHostNetworkData");
509 return ipmi::ccReqDataLenInvalid;
510 }
511 ipAddress = getAddrStr(family, msgPayloadStartingPos, ipAddrOffset,
512 addrSize);
Ratan Guptad70f4532017-08-04 02:07:31 +0530513
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000514 if (msgLen < gatewayOffset + addrSize)
515 {
516 log<level::ERR>(
517 "Error in gateway address getting of setHostNetworkData");
518 return ipmi::ccReqDataLenInvalid;
519 }
520 gateway = getAddrStr(family, msgPayloadStartingPos, gatewayOffset,
521 addrSize);
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530522
Patrick Venture0b02be92018-08-31 11:55:55 -0700523 } while (0);
Ratan Guptadcb10672017-07-10 10:33:50 +0530524
Patrick Venture0b02be92018-08-31 11:55:55 -0700525 // Cookie == 0 or it is a valid cookie
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000526 hostNetworkConfig += "ipaddress="s + ipAddress + ",prefix="s +
527 std::to_string(prefix) + ",gateway="s + gateway +
528 ",mac="s + mac + ",addressOrigin="s +
529 addressOrigin;
Ratan Guptafd28dd72016-08-01 04:58:01 -0500530
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530531 sdbusplus::bus::bus bus(ipmid_get_sd_bus_connection());
532
533 auto ipObjectInfo = ipmi::getDbusObject(bus, IP_INTERFACE,
534 SETTINGS_ROOT, SETTINGS_MATCH);
535 auto macObjectInfo = ipmi::getDbusObject(bus, MAC_INTERFACE,
536 SETTINGS_ROOT, SETTINGS_MATCH);
Ratan Guptadcb10672017-07-10 10:33:50 +0530537 // set the dbus property
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530538 ipmi::setDbusProperty(bus, ipObjectInfo.second, ipObjectInfo.first,
Patrick Venture0b02be92018-08-31 11:55:55 -0700539 IP_INTERFACE, "Address", std::string(ipAddress));
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530540 ipmi::setDbusProperty(bus, ipObjectInfo.second, ipObjectInfo.first,
Patrick Venture0b02be92018-08-31 11:55:55 -0700541 IP_INTERFACE, "PrefixLength", prefix);
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530542 ipmi::setDbusProperty(bus, ipObjectInfo.second, ipObjectInfo.first,
Patrick Venture0b02be92018-08-31 11:55:55 -0700543 IP_INTERFACE, "Origin", addressOrigin);
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530544 ipmi::setDbusProperty(bus, ipObjectInfo.second, ipObjectInfo.first,
Patrick Venture0b02be92018-08-31 11:55:55 -0700545 IP_INTERFACE, "Gateway", std::string(gateway));
546 ipmi::setDbusProperty(
547 bus, ipObjectInfo.second, ipObjectInfo.first, IP_INTERFACE, "Type",
548 std::string("xyz.openbmc_project.Network.IP.Protocol.IPv4"));
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530549 ipmi::setDbusProperty(bus, macObjectInfo.second, macObjectInfo.first,
Patrick Venture0b02be92018-08-31 11:55:55 -0700550 MAC_INTERFACE, "MACAddress", std::string(mac));
Ratan Guptafd28dd72016-08-01 04:58:01 -0500551
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000552 log<level::DEBUG>("Network configuration changed",
553 entry("NETWORKCONFIG=%s", hostNetworkConfig.c_str()));
Ratan Guptafd28dd72016-08-01 04:58:01 -0500554 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -0500555 catch (const sdbusplus::exception_t& e)
Ratan Guptadcb10672017-07-10 10:33:50 +0530556 {
557 commit<InternalFailure>();
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000558 log<level::ERR>("Error in ipmiChassisSetSysBootOptions call");
559 return ipmi::ccUnspecifiedError;
Ratan Guptadcb10672017-07-10 10:33:50 +0530560 }
561
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +0000562 return ipmi::ccSuccess;
Ratan Guptafd28dd72016-08-01 04:58:01 -0500563}
564
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -0500565uint32_t getPOHCounter()
566{
567 sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
568
Patrick Venture0b02be92018-08-31 11:55:55 -0700569 auto chassisStateObj =
570 ipmi::getDbusObject(bus, chassisPOHStateIntf, chassisStateRoot, match);
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -0500571
Patrick Venture0b02be92018-08-31 11:55:55 -0700572 auto service =
573 ipmi::getService(bus, chassisPOHStateIntf, chassisStateObj.first);
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -0500574
Patrick Venture0b02be92018-08-31 11:55:55 -0700575 auto propValue =
576 ipmi::getDbusProperty(bus, service, chassisStateObj.first,
Patrick Williams7345ac42021-04-30 20:57:39 -0500577 chassisPOHStateIntf, pohCounterProperty);
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -0500578
Vernon Maueryf442e112019-04-09 11:44:36 -0700579 return std::get<uint32_t>(propValue);
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -0500580}
581
anil kumar appana43263c62019-05-27 12:45:04 +0000582/** @brief Implements the get chassis capabilities command
583 *
584 * @returns IPMI completion code plus response data
585 * chassisCapFlags - chassis capability flag
586 * chassisFRUInfoDevAddr - chassis FRU info Device Address
587 * chassisSDRDevAddr - chassis SDR device address
588 * chassisSELDevAddr - chassis SEL device address
589 * chassisSMDevAddr - chassis system management device address
590 * chassisBridgeDevAddr - chassis bridge device address
591 */
Karthick Sundarrajan86d8bd72019-11-26 12:48:50 -0800592ipmi::RspType<bool, // chassis intrusion sensor
593 bool, // chassis Front panel lockout
594 bool, // chassis NMI
595 bool, // chassis power interlock
596 uint4_t, // reserved
anil kumar appana43263c62019-05-27 12:45:04 +0000597 uint8_t, // chassis FRU info Device Address
598 uint8_t, // chassis SDR device address
599 uint8_t, // chassis SEL device address
600 uint8_t, // chassis system management device address
601 uint8_t // chassis bridge device address
602 >
603 ipmiGetChassisCap()
Nan Li8d15fb42016-08-16 22:29:40 +0800604{
anil kumar appana43263c62019-05-27 12:45:04 +0000605 ipmi::PropertyMap properties;
Yong Liae4b0402018-11-02 11:12:14 +0800606 try
607 {
608 sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
Nan Li8d15fb42016-08-16 22:29:40 +0800609
Yong Liae4b0402018-11-02 11:12:14 +0800610 ipmi::DbusObjectInfo chassisCapObject =
611 ipmi::getDbusObject(bus, chassisCapIntf);
Nan Li8d15fb42016-08-16 22:29:40 +0800612
Yong Liae4b0402018-11-02 11:12:14 +0800613 // capabilities flags
614 // [7..4] - reserved
615 // [3] – 1b = provides power interlock (IPM 1.5)
616 // [2] – 1b = provides Diagnostic Interrupt (FP NMI)
617 // [1] – 1b = provides “Front Panel Lockout” (indicates that the chassis
618 // has capabilities
619 // to lock out external power control and reset button or
620 // front panel interfaces and/or detect tampering with those
621 // interfaces).
622 // [0] -1b = Chassis provides intrusion (physical security) sensor.
623 // set to default value 0x0.
Nan Li8d15fb42016-08-16 22:29:40 +0800624
anil kumar appana43263c62019-05-27 12:45:04 +0000625 properties =
626 ipmi::getAllDbusProperties(bus, chassisCapObject.second,
627 chassisCapObject.first, chassisCapIntf);
Yong Liae4b0402018-11-02 11:12:14 +0800628 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -0500629 catch (const std::exception& e)
Yong Liae4b0402018-11-02 11:12:14 +0800630 {
anil kumar appana43263c62019-05-27 12:45:04 +0000631 log<level::ERR>("Failed to fetch Chassis Capability properties",
632 entry("ERROR=%s", e.what()));
633 return ipmi::responseUnspecifiedError();
Yong Liae4b0402018-11-02 11:12:14 +0800634 }
635
Karthick Sundarrajan86d8bd72019-11-26 12:48:50 -0800636 bool* chassisIntrusionFlag =
637 std::get_if<bool>(&properties[chassisIntrusionProp]);
638 if (chassisIntrusionFlag == nullptr)
anil kumar appana43263c62019-05-27 12:45:04 +0000639 {
Karthick Sundarrajan86d8bd72019-11-26 12:48:50 -0800640 log<level::ERR>("Error to get chassis Intrusion flags");
641 return ipmi::responseUnspecifiedError();
642 }
643 bool* chassisFrontPanelFlag =
644 std::get_if<bool>(&properties[chassisFrontPanelLockoutProp]);
645 if (chassisFrontPanelFlag == nullptr)
646 {
647 log<level::ERR>("Error to get chassis intrusion flags");
648 return ipmi::responseUnspecifiedError();
649 }
650 bool* chassisNMIFlag = std::get_if<bool>(&properties[chassisNMIProp]);
651 if (chassisNMIFlag == nullptr)
652 {
653 log<level::ERR>("Error to get chassis NMI flags");
654 return ipmi::responseUnspecifiedError();
655 }
656 bool* chassisPowerInterlockFlag =
657 std::get_if<bool>(&properties[chassisPowerInterlockProp]);
658 if (chassisPowerInterlockFlag == nullptr)
659 {
660 log<level::ERR>("Error to get chassis power interlock flags");
anil kumar appana43263c62019-05-27 12:45:04 +0000661 return ipmi::responseUnspecifiedError();
662 }
663 uint8_t* chassisFRUInfoDevAddr =
664 std::get_if<uint8_t>(&properties[chassisFRUDevAddrProp]);
665 if (chassisFRUInfoDevAddr == nullptr)
666 {
667 log<level::ERR>("Error to get chassis FRU info device address");
668 return ipmi::responseUnspecifiedError();
669 }
670 uint8_t* chassisSDRDevAddr =
671 std::get_if<uint8_t>(&properties[chassisSDRDevAddrProp]);
672 if (chassisSDRDevAddr == nullptr)
673 {
674 log<level::ERR>("Error to get chassis SDR device address");
675 return ipmi::responseUnspecifiedError();
676 }
677 uint8_t* chassisSELDevAddr =
678 std::get_if<uint8_t>(&properties[chassisSELDevAddrProp]);
679 if (chassisSELDevAddr == nullptr)
680 {
681 log<level::ERR>("Error to get chassis SEL device address");
682 return ipmi::responseUnspecifiedError();
683 }
684 uint8_t* chassisSMDevAddr =
685 std::get_if<uint8_t>(&properties[chassisSMDevAddrProp]);
686 if (chassisSMDevAddr == nullptr)
687 {
688 log<level::ERR>("Error to get chassis SM device address");
689 return ipmi::responseUnspecifiedError();
690 }
691 uint8_t* chassisBridgeDevAddr =
692 std::get_if<uint8_t>(&properties[chassisBridgeDevAddrProp]);
693 if (chassisBridgeDevAddr == nullptr)
694 {
695 log<level::ERR>("Error to get chassis bridge device address");
696 return ipmi::responseUnspecifiedError();
697 }
698
Karthick Sundarrajan86d8bd72019-11-26 12:48:50 -0800699 return ipmi::responseSuccess(*chassisIntrusionFlag, *chassisFrontPanelFlag,
700 *chassisNMIFlag, *chassisPowerInterlockFlag, 0,
701 *chassisFRUInfoDevAddr, *chassisSDRDevAddr,
702 *chassisSELDevAddr, *chassisSMDevAddr,
703 *chassisBridgeDevAddr);
Yong Liae4b0402018-11-02 11:12:14 +0800704}
705
anil kumar appana894d0222019-05-27 16:32:14 +0000706/** @brief implements set chassis capalibities command
707 * @param intrusion - chassis intrusion
708 * @param fpLockout - frontpannel lockout
709 * @param reserved1 - skip one bit
710 * @param fruDeviceAddr - chassis FRU info Device Address
711 * @param sdrDeviceAddr - chassis SDR device address
712 * @param selDeviceAddr - chassis SEL device address
713 * @param smDeviceAddr - chassis system management device address
714 * @param bridgeDeviceAddr - chassis bridge device address
715 *
716 * @returns IPMI completion code
717 */
718ipmi::RspType<> ipmiSetChassisCap(bool intrusion, bool fpLockout,
719 uint6_t reserved1,
720
721 uint8_t fruDeviceAddr,
722
723 uint8_t sdrDeviceAddr,
724
725 uint8_t selDeviceAddr,
726
727 uint8_t smDeviceAddr,
728
729 uint8_t bridgeDeviceAddr)
Yong Liae4b0402018-11-02 11:12:14 +0800730{
Yong Liae4b0402018-11-02 11:12:14 +0800731
732 // check input data
anil kumar appana894d0222019-05-27 16:32:14 +0000733 if (reserved1 != 0)
Yong Liae4b0402018-11-02 11:12:14 +0800734 {
anil kumar appana894d0222019-05-27 16:32:14 +0000735 log<level::ERR>("Unsupported request parameter");
736 return ipmi::responseInvalidFieldRequest();
Yong Liae4b0402018-11-02 11:12:14 +0800737 }
738
anil kumar appana894d0222019-05-27 16:32:14 +0000739 if ((fruDeviceAddr & ~chassisCapAddrMask) != 0)
Yong Liae4b0402018-11-02 11:12:14 +0800740 {
741 log<level::ERR>("Unsupported request parameter(FRU Addr)",
anil kumar appana894d0222019-05-27 16:32:14 +0000742 entry("REQ=0x%x", fruDeviceAddr));
743 return ipmi::responseInvalidFieldRequest();
Yong Liae4b0402018-11-02 11:12:14 +0800744 }
anil kumar appana894d0222019-05-27 16:32:14 +0000745 if ((sdrDeviceAddr & ~chassisCapAddrMask) != 0)
Yong Liae4b0402018-11-02 11:12:14 +0800746 {
747 log<level::ERR>("Unsupported request parameter(SDR Addr)",
anil kumar appana894d0222019-05-27 16:32:14 +0000748 entry("REQ=0x%x", sdrDeviceAddr));
749 return ipmi::responseInvalidFieldRequest();
Yong Liae4b0402018-11-02 11:12:14 +0800750 }
751
anil kumar appana894d0222019-05-27 16:32:14 +0000752 if ((selDeviceAddr & ~chassisCapAddrMask) != 0)
Yong Liae4b0402018-11-02 11:12:14 +0800753 {
754 log<level::ERR>("Unsupported request parameter(SEL Addr)",
anil kumar appana894d0222019-05-27 16:32:14 +0000755 entry("REQ=0x%x", selDeviceAddr));
756 return ipmi::responseInvalidFieldRequest();
Yong Liae4b0402018-11-02 11:12:14 +0800757 }
758
anil kumar appana894d0222019-05-27 16:32:14 +0000759 if ((smDeviceAddr & ~chassisCapAddrMask) != 0)
Yong Liae4b0402018-11-02 11:12:14 +0800760 {
anil kumar appana894d0222019-05-27 16:32:14 +0000761 log<level::ERR>("Unsupported request parameter(SM Addr)",
762 entry("REQ=0x%x", smDeviceAddr));
763 return ipmi::responseInvalidFieldRequest();
Yong Liae4b0402018-11-02 11:12:14 +0800764 }
765
anil kumar appana894d0222019-05-27 16:32:14 +0000766 if ((bridgeDeviceAddr & ~chassisCapAddrMask) != 0)
Yong Liae4b0402018-11-02 11:12:14 +0800767 {
768 log<level::ERR>("Unsupported request parameter(Bridge Addr)",
anil kumar appana894d0222019-05-27 16:32:14 +0000769 entry("REQ=0x%x", bridgeDeviceAddr));
770 return ipmi::responseInvalidFieldRequest();
Yong Liae4b0402018-11-02 11:12:14 +0800771 }
772
773 try
774 {
775 sdbusplus::bus::bus bus(ipmid_get_sd_bus_connection());
776 ipmi::DbusObjectInfo chassisCapObject =
777 ipmi::getDbusObject(bus, chassisCapIntf);
778
779 ipmi::setDbusProperty(bus, chassisCapObject.second,
780 chassisCapObject.first, chassisCapIntf,
Karthick Sundarrajan86d8bd72019-11-26 12:48:50 -0800781 chassisIntrusionProp, intrusion);
782
783 ipmi::setDbusProperty(bus, chassisCapObject.second,
784 chassisCapObject.first, chassisCapIntf,
785 chassisFrontPanelLockoutProp, fpLockout);
Yong Liae4b0402018-11-02 11:12:14 +0800786
787 ipmi::setDbusProperty(bus, chassisCapObject.second,
788 chassisCapObject.first, chassisCapIntf,
anil kumar appana894d0222019-05-27 16:32:14 +0000789 chassisFRUDevAddrProp, fruDeviceAddr);
Yong Liae4b0402018-11-02 11:12:14 +0800790
791 ipmi::setDbusProperty(bus, chassisCapObject.second,
792 chassisCapObject.first, chassisCapIntf,
anil kumar appana894d0222019-05-27 16:32:14 +0000793 chassisSDRDevAddrProp, sdrDeviceAddr);
Yong Liae4b0402018-11-02 11:12:14 +0800794
795 ipmi::setDbusProperty(bus, chassisCapObject.second,
796 chassisCapObject.first, chassisCapIntf,
anil kumar appana894d0222019-05-27 16:32:14 +0000797 chassisSELDevAddrProp, selDeviceAddr);
Yong Liae4b0402018-11-02 11:12:14 +0800798
799 ipmi::setDbusProperty(bus, chassisCapObject.second,
800 chassisCapObject.first, chassisCapIntf,
anil kumar appana894d0222019-05-27 16:32:14 +0000801 chassisSMDevAddrProp, smDeviceAddr);
Yong Liae4b0402018-11-02 11:12:14 +0800802
803 ipmi::setDbusProperty(bus, chassisCapObject.second,
804 chassisCapObject.first, chassisCapIntf,
anil kumar appana894d0222019-05-27 16:32:14 +0000805 chassisBridgeDevAddrProp, bridgeDeviceAddr);
Yong Liae4b0402018-11-02 11:12:14 +0800806 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -0500807 catch (const std::exception& e)
Yong Liae4b0402018-11-02 11:12:14 +0800808 {
809 log<level::ERR>(e.what());
anil kumar appana894d0222019-05-27 16:32:14 +0000810 return ipmi::responseUnspecifiedError();
Yong Liae4b0402018-11-02 11:12:14 +0800811 }
anil kumar appana894d0222019-05-27 16:32:14 +0000812 return ipmi::responseSuccess();
Nan Li8d15fb42016-08-16 22:29:40 +0800813}
814
Vishwanatha Subbannab12b0c02017-03-07 18:17:19 +0530815//------------------------------------------
816// Calls into Host State Manager Dbus object
817//------------------------------------------
Jason M. Bills664e1c32020-01-30 16:02:39 -0800818int initiateHostStateTransition(ipmi::Context::ptr& ctx,
819 State::Host::Transition transition)
vishwa36993272015-11-20 12:43:49 -0600820{
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500821 // OpenBMC Host State Manager dbus framework
Jason M. Bills664e1c32020-01-30 16:02:39 -0800822 constexpr auto hostStatePath = "/xyz/openbmc_project/state/host0";
823 constexpr auto hostStateIntf = "xyz.openbmc_project.State.Host";
Vishwanatha Subbannab12b0c02017-03-07 18:17:19 +0530824
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500825 // Convert to string equivalent of the passed in transition enum.
826 auto request = State::convertForMessage(transition);
Vishwanatha Subbannab12b0c02017-03-07 18:17:19 +0530827
Jason M. Bills664e1c32020-01-30 16:02:39 -0800828 std::string service;
829 boost::system::error_code ec =
830 ipmi::getService(ctx, hostStateIntf, hostStatePath, service);
831
832 if (!ec)
833 {
834 ec = ipmi::setDbusProperty(ctx, service, hostStatePath, hostStateIntf,
835 "RequestedHostTransition", request);
836 }
837 if (ec)
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500838 {
839 log<level::ERR>("Failed to initiate transition",
Jason M. Bills664e1c32020-01-30 16:02:39 -0800840 entry("EXCEPTION=%s, REQUEST=%s", ec.message().c_str(),
841 request.c_str()));
842 return -1;
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500843 }
Jason M. Bills664e1c32020-01-30 16:02:39 -0800844 log<level::INFO>(
845 "Transition request initiated successfully",
846 entry("USERID=%d, REQUEST=%s", ctx->userId, request.c_str()));
847 return 0;
vishwa36993272015-11-20 12:43:49 -0600848}
849
Kuiying Wang6b0ceaa2019-11-05 15:13:40 +0800850//------------------------------------------
851// Set Enabled property to inform NMI source
852// handling to trigger a NMI_OUT BSOD.
853//------------------------------------------
854int setNmiProperty(const bool value)
855{
856 constexpr const char* nmiSourceObjPath =
857 "/xyz/openbmc_project/Chassis/Control/NMISource";
858 constexpr const char* nmiSourceIntf =
859 "xyz.openbmc_project.Chassis.Control.NMISource";
860 std::string bmcSourceSignal = "xyz.openbmc_project.Chassis.Control."
861 "NMISource.BMCSourceSignal.ChassisCmd";
862 std::shared_ptr<sdbusplus::asio::connection> busp = getSdBus();
863
864 try
865 {
866 auto service = ipmi::getService(*busp, nmiSourceIntf, nmiSourceObjPath);
867 ipmi::setDbusProperty(*busp, service, nmiSourceObjPath, nmiSourceIntf,
868 "BMCSource", bmcSourceSignal);
869 ipmi::setDbusProperty(*busp, service, nmiSourceObjPath, nmiSourceIntf,
870 "Enabled", value);
871 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -0500872 catch (const std::exception& e)
Kuiying Wang6b0ceaa2019-11-05 15:13:40 +0800873 {
874 log<level::ERR>("Failed to trigger NMI_OUT",
875 entry("EXCEPTION=%s", e.what()));
876 return -1;
877 }
878
879 return 0;
880}
881
Deepak Kodihalli18b70d12017-07-21 13:36:33 -0500882namespace power_policy
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500883{
Nan Lifdd8ec52016-08-28 03:57:40 +0800884
Deepak Kodihalli18b70d12017-07-21 13:36:33 -0500885using namespace sdbusplus::xyz::openbmc_project::Control::Power::server;
886using IpmiValue = uint8_t;
887using DbusValue = RestorePolicy::Policy;
Nan Lifdd8ec52016-08-28 03:57:40 +0800888
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700889const std::map<DbusValue, IpmiValue> dbusToIpmi = {
Deepak Kodihalli18b70d12017-07-21 13:36:33 -0500890 {RestorePolicy::Policy::AlwaysOff, 0x00},
891 {RestorePolicy::Policy::Restore, 0x01},
Patrick Venture0b02be92018-08-31 11:55:55 -0700892 {RestorePolicy::Policy::AlwaysOn, 0x02}};
Nan Lifdd8ec52016-08-28 03:57:40 +0800893
Yong Lic6713cf2018-09-12 12:35:13 +0800894static constexpr uint8_t noChange = 0x03;
895static constexpr uint8_t allSupport = 0x01 | 0x02 | 0x04;
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700896
897/* helper function for Get Chassis Status Command
898 */
899std::optional<uint2_t> getPowerRestorePolicy()
900{
901 uint2_t restorePolicy = 0;
902 using namespace chassis::internal;
903
James Feist225dec82019-11-26 16:25:06 -0800904 settings::Objects& objects = cache::getObjects();
905
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700906 try
907 {
908 const auto& powerRestoreSetting =
James Feist225dec82019-11-26 16:25:06 -0800909 objects.map.at(powerRestoreIntf).front();
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700910 ipmi::Value result = ipmi::getDbusProperty(
911 *getSdBus(),
James Feist225dec82019-11-26 16:25:06 -0800912 objects.service(powerRestoreSetting, powerRestoreIntf).c_str(),
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700913 powerRestoreSetting.c_str(), powerRestoreIntf,
914 "PowerRestorePolicy");
915 auto powerRestore = RestorePolicy::convertPolicyFromString(
916 std::get<std::string>(result));
917 restorePolicy = dbusToIpmi.at(powerRestore);
918 }
919 catch (const std::exception& e)
920 {
921 log<level::ERR>(
922 "Failed to fetch pgood property", entry("ERROR=%s", e.what()),
James Feist225dec82019-11-26 16:25:06 -0800923 entry("PATH=%s", objects.map.at(powerRestoreIntf).front().c_str()),
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700924 entry("INTERFACE=%s", powerRestoreIntf));
James Feist225dec82019-11-26 16:25:06 -0800925 cache::objectsPtr.reset();
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700926 return std::nullopt;
927 }
928 return std::make_optional(restorePolicy);
929}
930
931/*
932 * getPowerStatus
933 * helper function for Get Chassis Status Command
934 * return - optional value for pgood (no value on error)
935 */
936std::optional<bool> getPowerStatus()
937{
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700938 bool powerGood = false;
939 std::shared_ptr<sdbusplus::asio::connection> busp = getSdBus();
940 try
941 {
Jason M. Bills3de424c2019-05-21 09:57:16 -0700942 constexpr const char* chassisStatePath =
943 "/xyz/openbmc_project/state/chassis0";
944 constexpr const char* chassisStateIntf =
945 "xyz.openbmc_project.State.Chassis";
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700946 auto service =
Jason M. Bills3de424c2019-05-21 09:57:16 -0700947 ipmi::getService(*busp, chassisStateIntf, chassisStatePath);
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700948
Jason M. Bills3de424c2019-05-21 09:57:16 -0700949 ipmi::Value powerState =
950 ipmi::getDbusProperty(*busp, service, chassisStatePath,
951 chassisStateIntf, "CurrentPowerState");
952 powerGood = std::get<std::string>(powerState) ==
953 "xyz.openbmc_project.State.Chassis.PowerState.On";
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700954 }
955 catch (const std::exception& e)
956 {
957 try
958 {
959 // FIXME: some legacy modules use the older path; try that next
960 constexpr const char* legacyPwrCtrlObj =
961 "/org/openbmc/control/power0";
962 constexpr const char* legacyPwrCtrlIntf =
963 "org.openbmc.control.Power";
964 auto service =
965 ipmi::getService(*busp, legacyPwrCtrlIntf, legacyPwrCtrlObj);
966
967 ipmi::Value variant = ipmi::getDbusProperty(
968 *busp, service, legacyPwrCtrlObj, legacyPwrCtrlIntf, "pgood");
969 powerGood = static_cast<bool>(std::get<int>(variant));
970 }
971 catch (const std::exception& e)
972 {
973 log<level::ERR>("Failed to fetch pgood property",
Jason M. Bills3de424c2019-05-21 09:57:16 -0700974 entry("ERROR=%s", e.what()));
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -0700975 return std::nullopt;
976 }
977 }
978 return std::make_optional(powerGood);
979}
980
Yong Li70ce7352019-05-16 21:15:27 +0800981/*
982 * getACFailStatus
983 * helper function for Get Chassis Status Command
984 * return - bool value for ACFail (false on error)
985 */
986bool getACFailStatus()
987{
988 constexpr const char* powerControlObj =
989 "/xyz/openbmc_project/Chassis/Control/Power0";
990 constexpr const char* powerControlIntf =
991 "xyz.openbmc_project.Chassis.Control.Power";
992 bool acFail = false;
993 std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus();
994 try
995 {
996 auto service =
997 ipmi::getService(*bus, powerControlIntf, powerControlObj);
998
999 ipmi::Value variant = ipmi::getDbusProperty(
1000 *bus, service, powerControlObj, powerControlIntf, "PFail");
1001 acFail = std::get<bool>(variant);
1002 }
1003 catch (const std::exception& e)
1004 {
1005 log<level::ERR>("Failed to fetch PFail property",
1006 entry("ERROR=%s", e.what()),
1007 entry("PATH=%s", powerControlObj),
1008 entry("INTERFACE=%s", powerControlIntf));
1009 }
1010 return acFail;
1011}
Deepak Kodihalli18b70d12017-07-21 13:36:33 -05001012} // namespace power_policy
Nan Lifdd8ec52016-08-28 03:57:40 +08001013
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001014static std::optional<bool> getButtonEnabled(const std::string& buttonPath,
1015 const std::string& buttonIntf)
1016{
1017 std::shared_ptr<sdbusplus::asio::connection> busp = getSdBus();
1018 bool buttonDisabled = false;
1019 try
1020 {
1021 auto service = ipmi::getService(*busp, buttonIntf, buttonPath);
1022 ipmi::Value enabled = ipmi::getDbusProperty(*busp, service, buttonPath,
1023 buttonIntf, "Enabled");
1024 buttonDisabled = !std::get<bool>(enabled);
1025 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -05001026 catch (const sdbusplus::exception::exception& e)
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001027 {
1028 log<level::ERR>("Fail to get button Enabled property",
1029 entry("PATH=%s", buttonPath.c_str()),
1030 entry("ERROR=%s", e.what()));
1031 return std::nullopt;
1032 }
1033 return std::make_optional(buttonDisabled);
1034}
1035
Kuiying Wang21addc52019-01-04 10:50:21 +08001036static bool setButtonEnabled(ipmi::Context::ptr& ctx,
1037 const std::string& buttonPath,
1038 const std::string& buttonIntf, bool enable)
1039{
1040 std::string service;
1041 boost::system::error_code ec;
1042 ec = ipmi::getService(ctx, buttonIntf, buttonPath, service);
1043 if (!ec)
1044 {
1045 ec = ipmi::setDbusProperty(ctx, service, buttonPath, buttonIntf,
1046 "Enabled", enable);
1047 }
1048 if (ec)
1049 {
1050 log<level::ERR>("Fail to set button Enabled property",
1051 entry("SERVICE=%s", service.c_str()),
1052 entry("PATH=%s", buttonPath.c_str()),
1053 entry("ERROR=%s", ec.message().c_str()));
1054 return false;
1055 }
1056 return true;
1057}
1058
Nan Lifdd8ec52016-08-28 03:57:40 +08001059//----------------------------------------------------------------------
1060// Get Chassis Status commands
1061//----------------------------------------------------------------------
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001062ipmi::RspType<bool, // Power is on
1063 bool, // Power overload
1064 bool, // Interlock
1065 bool, // power fault
1066 bool, // power control fault
1067 uint2_t, // power restore policy
1068 bool, // reserved
1069
1070 bool, // AC failed
1071 bool, // last power down caused by a Power overload
1072 bool, // last power down caused by a power interlock
1073 bool, // last power down caused by power fault
1074 bool, // last ‘Power is on’ state was entered via IPMI command
1075 uint3_t, // reserved
1076
1077 bool, // Chassis intrusion active
1078 bool, // Front Panel Lockout active
1079 bool, // Drive Fault
1080 bool, // Cooling/fan fault detected
1081 uint2_t, // Chassis Identify State
1082 bool, // Chassis Identify command and state info supported
1083 bool, // reserved
1084
1085 bool, // Power off button disabled
1086 bool, // Reset button disabled
1087 bool, // Diagnostic Interrupt button disabled
1088 bool, // Standby (sleep) button disabled
1089 bool, // Power off button disable allowed
1090 bool, // Reset button disable allowed
1091 bool, // Diagnostic Interrupt button disable allowed
1092 bool // Standby (sleep) button disable allowed
1093 >
1094 ipmiGetChassisStatus()
Nan Lifdd8ec52016-08-28 03:57:40 +08001095{
Deepak Kodihalli18b70d12017-07-21 13:36:33 -05001096 using namespace chassis::internal;
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001097 std::optional<uint2_t> restorePolicy =
1098 power_policy::getPowerRestorePolicy();
1099 std::optional<bool> powerGood = power_policy::getPowerStatus();
1100 if (!restorePolicy || !powerGood)
Deepak Kodihalli18b70d12017-07-21 13:36:33 -05001101 {
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001102 return ipmi::responseUnspecifiedError();
Deepak Kodihalli18b70d12017-07-21 13:36:33 -05001103 }
Nan Lifdd8ec52016-08-28 03:57:40 +08001104
1105 // Front Panel Button Capabilities and disable/enable status(Optional)
Vernon Mauery6d5b2f72019-05-16 14:48:47 -07001106 std::optional<bool> powerButtonReading =
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001107 getButtonEnabled(powerButtonPath, powerButtonIntf);
Vernon Mauery6d5b2f72019-05-16 14:48:47 -07001108 // allow disable if the interface is present
1109 bool powerButtonDisableAllow = static_cast<bool>(powerButtonReading);
1110 // default return the button is enabled (not disabled)
1111 bool powerButtonDisabled = false;
1112 if (powerButtonDisableAllow)
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001113 {
Vernon Mauery6d5b2f72019-05-16 14:48:47 -07001114 // return the real value of the button status, if present
1115 powerButtonDisabled = *powerButtonReading;
1116 }
1117
1118 std::optional<bool> resetButtonReading =
1119 getButtonEnabled(resetButtonPath, resetButtonIntf);
1120 // allow disable if the interface is present
1121 bool resetButtonDisableAllow = static_cast<bool>(resetButtonReading);
1122 // default return the button is enabled (not disabled)
1123 bool resetButtonDisabled = false;
1124 if (resetButtonDisableAllow)
1125 {
1126 // return the real value of the button status, if present
1127 resetButtonDisabled = *resetButtonReading;
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001128 }
Nan Lifdd8ec52016-08-28 03:57:40 +08001129
Yong Li70ce7352019-05-16 21:15:27 +08001130 bool powerDownAcFailed = power_policy::getACFailStatus();
1131
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001132 // This response has a lot of hard-coded, unsupported fields
1133 // They are set to false or 0
1134 constexpr bool powerOverload = false;
1135 constexpr bool chassisInterlock = false;
1136 constexpr bool powerFault = false;
1137 constexpr bool powerControlFault = false;
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001138 constexpr bool powerDownOverload = false;
1139 constexpr bool powerDownInterlock = false;
1140 constexpr bool powerDownPowerFault = false;
1141 constexpr bool powerStatusIPMI = false;
1142 constexpr bool chassisIntrusionActive = false;
1143 constexpr bool frontPanelLockoutActive = false;
1144 constexpr bool driveFault = false;
1145 constexpr bool coolingFanFault = false;
1146 // chassisIdentifySupport set because this command is implemented
1147 constexpr bool chassisIdentifySupport = true;
William A. Kennington III7a0e5df2021-05-19 13:31:29 -07001148 uint2_t chassisIdentifyState = types::enum_cast<uint2_t>(chassisIDState);
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001149 constexpr bool diagButtonDisabled = false;
1150 constexpr bool sleepButtonDisabled = false;
1151 constexpr bool diagButtonDisableAllow = false;
1152 constexpr bool sleepButtonDisableAllow = false;
1153
1154 return ipmi::responseSuccess(
1155 *powerGood, powerOverload, chassisInterlock, powerFault,
1156 powerControlFault, *restorePolicy,
1157 false, // reserved
1158
1159 powerDownAcFailed, powerDownOverload, powerDownInterlock,
1160 powerDownPowerFault, powerStatusIPMI,
1161 uint3_t(0), // reserved
1162
1163 chassisIntrusionActive, frontPanelLockoutActive, driveFault,
1164 coolingFanFault, chassisIdentifyState, chassisIdentifySupport,
1165 false, // reserved
1166
Vernon Mauery6d5b2f72019-05-16 14:48:47 -07001167 powerButtonDisabled, resetButtonDisabled, diagButtonDisabled,
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07001168 sleepButtonDisabled, powerButtonDisableAllow, resetButtonDisableAllow,
1169 diagButtonDisableAllow, sleepButtonDisableAllow);
Nan Lifdd8ec52016-08-28 03:57:40 +08001170}
Chris Austen7888c4d2015-12-03 15:26:20 -06001171
Vijay Khemka074f64d2020-03-03 15:08:43 -08001172enum class IpmiRestartCause
1173{
1174 Unknown = 0x0,
1175 RemoteCommand = 0x1,
1176 ResetButton = 0x2,
1177 PowerButton = 0x3,
1178 WatchdogTimer = 0x4,
1179 PowerPolicyAlwaysOn = 0x6,
1180 PowerPolicyPreviousState = 0x7,
1181 SoftReset = 0xa,
1182};
1183
1184static IpmiRestartCause
1185 restartCauseToIpmiRestartCause(State::Host::RestartCause cause)
1186{
1187 switch (cause)
1188 {
1189 case State::Host::RestartCause::Unknown:
1190 {
1191 return IpmiRestartCause::Unknown;
1192 }
1193 case State::Host::RestartCause::RemoteCommand:
1194 {
1195 return IpmiRestartCause::RemoteCommand;
1196 }
1197 case State::Host::RestartCause::ResetButton:
1198 {
1199 return IpmiRestartCause::ResetButton;
1200 }
1201 case State::Host::RestartCause::PowerButton:
1202 {
1203 return IpmiRestartCause::PowerButton;
1204 }
1205 case State::Host::RestartCause::WatchdogTimer:
1206 {
1207 return IpmiRestartCause::WatchdogTimer;
1208 }
1209 case State::Host::RestartCause::PowerPolicyAlwaysOn:
1210 {
1211 return IpmiRestartCause::PowerPolicyAlwaysOn;
1212 }
1213 case State::Host::RestartCause::PowerPolicyPreviousState:
1214 {
1215 return IpmiRestartCause::PowerPolicyPreviousState;
1216 }
1217 case State::Host::RestartCause::SoftReset:
1218 {
1219 return IpmiRestartCause::SoftReset;
1220 }
1221 default:
1222 {
1223 return IpmiRestartCause::Unknown;
1224 }
1225 }
1226}
1227
1228/*
1229 * getRestartCause
1230 * helper function for Get Host restart cause Command
1231 * return - optional value for RestartCause (no value on error)
1232 */
1233static std::optional<uint4_t> getRestartCause(ipmi::Context::ptr ctx)
1234{
1235 constexpr const char* restartCausePath =
1236 "/xyz/openbmc_project/control/host0/restart_cause";
1237 constexpr const char* restartCauseIntf =
1238 "xyz.openbmc_project.Control.Host.RestartCause";
1239
1240 std::string service;
1241 boost::system::error_code ec =
1242 ipmi::getService(ctx, restartCauseIntf, restartCausePath, service);
1243 if (!ec)
1244 {
1245 std::string restartCauseStr;
1246 ec = ipmi::getDbusProperty<std::string>(
1247 ctx, service, restartCausePath, restartCauseIntf, "RestartCause",
1248 restartCauseStr);
1249 if (!ec)
1250 {
1251 auto cause =
1252 State::Host::convertRestartCauseFromString(restartCauseStr);
William A. Kennington III7a0e5df2021-05-19 13:31:29 -07001253 return types::enum_cast<uint4_t>(
1254 restartCauseToIpmiRestartCause(cause));
Vijay Khemka074f64d2020-03-03 15:08:43 -08001255 }
1256 }
1257
1258 log<level::ERR>("Failed to fetch RestartCause property",
1259 entry("ERROR=%s", ec.message().c_str()),
1260 entry("PATH=%s", restartCausePath),
1261 entry("INTERFACE=%s", restartCauseIntf));
1262 return std::nullopt;
1263}
1264
1265ipmi::RspType<uint4_t, // Restart Cause
1266 uint4_t, // reserved
1267 uint8_t // channel number (not supported)
1268 >
1269 ipmiGetSystemRestartCause(ipmi::Context::ptr ctx)
1270{
1271 std::optional<uint4_t> cause = getRestartCause(ctx);
1272 if (!cause)
1273 {
1274 return ipmi::responseUnspecifiedError();
1275 }
1276
Vernon Mauery916d4232021-03-29 13:42:16 -07001277 constexpr uint4_t reserved = 0;
1278 auto channel = static_cast<uint8_t>(ctx->channel);
1279 return ipmi::responseSuccess(cause.value(), reserved, channel);
Vijay Khemka074f64d2020-03-03 15:08:43 -08001280}
1281
Vishwanatha Subbanna83b5c1c2017-01-25 18:41:51 +05301282//-------------------------------------------------------------
1283// Send a command to SoftPowerOff application to stop any timer
1284//-------------------------------------------------------------
1285int stop_soft_off_timer()
1286{
Patrick Venture0b02be92018-08-31 11:55:55 -07001287 constexpr auto iface = "org.freedesktop.DBus.Properties";
1288 constexpr auto soft_off_iface = "xyz.openbmc_project.Ipmi.Internal."
1289 "SoftPowerOff";
Vishwanatha Subbanna83b5c1c2017-01-25 18:41:51 +05301290
Patrick Venture0b02be92018-08-31 11:55:55 -07001291 constexpr auto property = "ResponseReceived";
1292 constexpr auto value = "xyz.openbmc_project.Ipmi.Internal."
1293 "SoftPowerOff.HostResponse.HostShutdown";
Vishwanatha Subbanna83b5c1c2017-01-25 18:41:51 +05301294
1295 // Get the system bus where most system services are provided.
1296 auto bus = ipmid_get_sd_bus_connection();
1297
1298 // Get the service name
Andrew Geissler2b4e4592017-06-08 11:18:35 -05001299 // TODO openbmc/openbmc#1661 - Mapper refactor
1300 //
1301 // See openbmc/openbmc#1743 for some details but high level summary is that
1302 // for now the code will directly call the soft off interface due to a
1303 // race condition with mapper usage
1304 //
Patrick Venture0b02be92018-08-31 11:55:55 -07001305 // char *busname = nullptr;
1306 // auto r = mapper_get_service(bus, SOFTOFF_OBJPATH, &busname);
1307 // if (r < 0)
Andrew Geissler2b4e4592017-06-08 11:18:35 -05001308 //{
1309 // fprintf(stderr, "Failed to get %s bus name: %s\n",
Aditya Saripalli5fb14602017-11-09 14:46:27 +05301310 // SOFTOFF_OBJPATH, -r);
Andrew Geissler2b4e4592017-06-08 11:18:35 -05001311 // return r;
1312 //}
Vishwanatha Subbanna83b5c1c2017-01-25 18:41:51 +05301313
1314 // No error object or reply expected.
Andrew Geissler2b4e4592017-06-08 11:18:35 -05001315 int rc = sd_bus_call_method(bus, SOFTOFF_BUSNAME, SOFTOFF_OBJPATH, iface,
Patrick Venture0b02be92018-08-31 11:55:55 -07001316 "Set", nullptr, nullptr, "ssv", soft_off_iface,
1317 property, "s", value);
Vishwanatha Subbanna83b5c1c2017-01-25 18:41:51 +05301318 if (rc < 0)
1319 {
Aditya Saripalli5fb14602017-11-09 14:46:27 +05301320 log<level::ERR>("Failed to set property in SoftPowerOff object",
1321 entry("ERRNO=0x%X", -rc));
Vishwanatha Subbanna83b5c1c2017-01-25 18:41:51 +05301322 }
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001323
Patrick Venture0b02be92018-08-31 11:55:55 -07001324 // TODO openbmc/openbmc#1661 - Mapper refactor
1325 // free(busname);
Vishwanatha Subbanna83b5c1c2017-01-25 18:41:51 +05301326 return rc;
1327}
1328
vishwa36993272015-11-20 12:43:49 -06001329//----------------------------------------------------------------------
Andrew Geisslera6e3a302017-05-31 19:34:00 -05001330// Create file to indicate there is no need for softoff notification to host
1331//----------------------------------------------------------------------
1332void indicate_no_softoff_needed()
1333{
1334 fs::path path{HOST_INBAND_REQUEST_DIR};
1335 if (!fs::is_directory(path))
1336 {
1337 fs::create_directory(path);
1338 }
1339
1340 // Add the host instance (default 0 for now) to the file name
1341 std::string file{HOST_INBAND_REQUEST_FILE};
Patrick Venture0b02be92018-08-31 11:55:55 -07001342 auto size = std::snprintf(nullptr, 0, file.c_str(), 0);
Andrew Geisslera6e3a302017-05-31 19:34:00 -05001343 size++; // null
1344 std::unique_ptr<char[]> buf(new char[size]);
Patrick Venture0b02be92018-08-31 11:55:55 -07001345 std::snprintf(buf.get(), size, file.c_str(), 0);
Andrew Geisslera6e3a302017-05-31 19:34:00 -05001346
1347 // Append file name to directory and create it
1348 path /= buf.get();
1349 std::ofstream(path.c_str());
1350}
1351
anil kumar appanadafff5f2019-04-27 18:06:00 +00001352/** @brief Implementation of chassis control command
1353 *
1354 * @param - chassisControl command byte
1355 *
1356 * @return Success or InvalidFieldRequest.
1357 */
Jason M. Bills664e1c32020-01-30 16:02:39 -08001358ipmi::RspType<> ipmiChassisControl(ipmi::Context::ptr& ctx,
1359 uint8_t chassisControl)
vishwa36993272015-11-20 12:43:49 -06001360{
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001361 int rc = 0;
anil kumar appanadafff5f2019-04-27 18:06:00 +00001362 switch (chassisControl)
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001363 {
1364 case CMD_POWER_ON:
Jason M. Bills664e1c32020-01-30 16:02:39 -08001365 rc = initiateHostStateTransition(ctx, State::Host::Transition::On);
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001366 break;
1367 case CMD_POWER_OFF:
Vishwanatha Subbanna8b26d352017-08-04 18:35:18 +05301368 // This path would be hit in 2 conditions.
1369 // 1: When user asks for power off using ipmi chassis command 0x04
1370 // 2: Host asking for power off post shutting down.
1371
1372 // If it's a host requested power off, then need to nudge Softoff
1373 // application that it needs to stop the watchdog timer if running.
1374 // If it is a user requested power off, then this is not really
1375 // needed. But then we need to differentiate between user and host
1376 // calling this same command
1377
1378 // For now, we are going ahead with trying to nudge the soft off and
1379 // interpret the failure to do so as a non softoff case
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001380 rc = stop_soft_off_timer();
Vishwanatha Subbanna8b26d352017-08-04 18:35:18 +05301381
Andrew Geisslera6e3a302017-05-31 19:34:00 -05001382 // Only request the Off transition if the soft power off
1383 // application is not running
1384 if (rc < 0)
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001385 {
Andrew Geisslera6e3a302017-05-31 19:34:00 -05001386 // First create a file to indicate to the soft off application
Vishwanatha Subbanna8b26d352017-08-04 18:35:18 +05301387 // that it should not run. Not doing this will result in State
1388 // manager doing a default soft power off when asked for power
1389 // off.
Andrew Geisslera6e3a302017-05-31 19:34:00 -05001390 indicate_no_softoff_needed();
1391
1392 // Now request the shutdown
Jason M. Bills664e1c32020-01-30 16:02:39 -08001393 rc = initiateHostStateTransition(ctx,
1394 State::Host::Transition::Off);
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001395 }
Andrew Geisslera6e3a302017-05-31 19:34:00 -05001396 else
1397 {
Vishwanatha Subbanna8b26d352017-08-04 18:35:18 +05301398 log<level::INFO>("Soft off is running, so let shutdown target "
1399 "stop the host");
Andrew Geisslera6e3a302017-05-31 19:34:00 -05001400 }
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001401 break;
Vishwanatha Subbanna83b5c1c2017-01-25 18:41:51 +05301402
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001403 case CMD_HARD_RESET:
Jason M. Bills664e1c32020-01-30 16:02:39 -08001404 rc = initiateHostStateTransition(
1405 ctx, State::Host::Transition::ForceWarmReboot);
Chanh Nguyend0a7fcd2021-07-16 22:59:28 +07001406 break;
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001407 case CMD_POWER_CYCLE:
1408 // SPEC has a section that says certain implementations can trigger
1409 // PowerOn if power is Off when a command to power cycle is
1410 // requested
Andrew Geisslera6e3a302017-05-31 19:34:00 -05001411
1412 // First create a file to indicate to the soft off application
1413 // that it should not run since this is a direct user initiated
1414 // power reboot request (i.e. a reboot request that is not
1415 // originating via a soft power off SMS request)
1416 indicate_no_softoff_needed();
1417
Jason M. Bills664e1c32020-01-30 16:02:39 -08001418 rc = initiateHostStateTransition(ctx,
1419 State::Host::Transition::Reboot);
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001420 break;
Vishwanatha Subbanna8b26d352017-08-04 18:35:18 +05301421
1422 case CMD_SOFT_OFF_VIA_OVER_TEMP:
1423 // Request Host State Manager to do a soft power off
Jason M. Bills664e1c32020-01-30 16:02:39 -08001424 rc = initiateHostStateTransition(ctx, State::Host::Transition::Off);
Vishwanatha Subbanna8b26d352017-08-04 18:35:18 +05301425 break;
1426
Kuiying Wang6b0ceaa2019-11-05 15:13:40 +08001427 case CMD_PULSE_DIAGNOSTIC_INTR:
1428 rc = setNmiProperty(true);
1429 break;
1430
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001431 default:
1432 {
Aditya Saripalli5fb14602017-11-09 14:46:27 +05301433 log<level::ERR>("Invalid Chassis Control command",
anil kumar appanadafff5f2019-04-27 18:06:00 +00001434 entry("CMD=0x%X", chassisControl));
1435 return ipmi::responseInvalidFieldRequest();
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001436 }
1437 }
vishwa36993272015-11-20 12:43:49 -06001438
anil kumar appanadafff5f2019-04-27 18:06:00 +00001439 return ((rc < 0) ? ipmi::responseUnspecifiedError()
1440 : ipmi::responseSuccess());
vishwa36993272015-11-20 12:43:49 -06001441}
1442
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001443/** @brief Return D-Bus connection string to enclosure identify LED object
1444 *
1445 * @param[in, out] connection - connection to D-Bus object
1446 * @return a IPMI return code
1447 */
1448std::string getEnclosureIdentifyConnection()
Tom Joseph5110c122018-03-23 17:55:40 +05301449{
Tom Joseph5110c122018-03-23 17:55:40 +05301450 // lookup enclosure_identify group owner(s) in mapper
1451 auto mapperCall = chassis::internal::dbus.new_method_call(
Patrick Venture0b02be92018-08-31 11:55:55 -07001452 ipmi::MAPPER_BUS_NAME, ipmi::MAPPER_OBJ, ipmi::MAPPER_INTF,
1453 "GetObject");
Tom Joseph5110c122018-03-23 17:55:40 +05301454
1455 mapperCall.append(identify_led_object_name);
Patrick Venture0b02be92018-08-31 11:55:55 -07001456 static const std::vector<std::string> interfaces = {
1457 "xyz.openbmc_project.Led.Group"};
Tom Joseph5110c122018-03-23 17:55:40 +05301458 mapperCall.append(interfaces);
1459 auto mapperReply = chassis::internal::dbus.call(mapperCall);
1460 if (mapperReply.is_method_error())
1461 {
1462 log<level::ERR>("Chassis Identify: Error communicating to mapper.");
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001463 elog<InternalFailure>();
Tom Joseph5110c122018-03-23 17:55:40 +05301464 }
1465 std::vector<std::pair<std::string, std::vector<std::string>>> mapperResp;
1466 mapperReply.read(mapperResp);
1467
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001468 if (mapperResp.size() != encIdentifyObjectsSize)
Tom Joseph5110c122018-03-23 17:55:40 +05301469 {
Patrick Venture0b02be92018-08-31 11:55:55 -07001470 log<level::ERR>(
1471 "Invalid number of enclosure identify objects.",
1472 entry("ENC_IDENTITY_OBJECTS_SIZE=%d", mapperResp.size()));
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001473 elog<InternalFailure>();
1474 }
1475 auto pair = mapperResp[encIdentifyObjectsSize - 1];
1476 return pair.first;
1477}
Tom Joseph5110c122018-03-23 17:55:40 +05301478
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001479/** @brief Turn On/Off enclosure identify LED
1480 *
1481 * @param[in] flag - true to turn on LED, false to turn off
1482 * @return a IPMI return code
1483 */
1484void enclosureIdentifyLed(bool flag)
1485{
1486 using namespace chassis::internal;
1487 std::string connection = std::move(getEnclosureIdentifyConnection());
Vernon Mauery400cc782018-10-09 13:49:53 -07001488 auto msg = std::string("enclosureIdentifyLed(") +
1489 boost::lexical_cast<std::string>(flag) + ")";
1490 log<level::DEBUG>(msg.c_str());
Patrick Venture0b02be92018-08-31 11:55:55 -07001491 auto led =
1492 dbus.new_method_call(connection.c_str(), identify_led_object_name,
1493 "org.freedesktop.DBus.Properties", "Set");
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001494 led.append("xyz.openbmc_project.Led.Group", "Asserted",
Vernon Mauery16b86932019-05-01 08:36:11 -07001495 std::variant<bool>(flag));
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001496 auto ledReply = dbus.call(led);
1497 if (ledReply.is_method_error())
1498 {
1499 log<level::ERR>("Chassis Identify: Error Setting State On/Off\n",
Patrick Venture0b02be92018-08-31 11:55:55 -07001500 entry("LED_STATE=%d", flag));
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001501 elog<InternalFailure>();
1502 }
1503}
1504
1505/** @brief Callback method to turn off LED
1506 */
1507void enclosureIdentifyLedOff()
1508{
1509 try
1510 {
Yong Lif4e38512019-05-21 14:46:55 +08001511 chassisIDState = ChassisIDState::off;
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001512 enclosureIdentifyLed(false);
1513 }
1514 catch (const InternalFailure& e)
1515 {
1516 report<InternalFailure>();
1517 }
1518}
1519
1520/** @brief Create timer to turn on and off the enclosure LED
1521 */
1522void createIdentifyTimer()
1523{
1524 if (!identifyTimer)
1525 {
Vernon Mauery1181af72018-10-08 12:05:00 -07001526 identifyTimer =
1527 std::make_unique<phosphor::Timer>(enclosureIdentifyLedOff);
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001528 }
1529}
1530
Vernon Mauery400cc782018-10-09 13:49:53 -07001531ipmi::RspType<> ipmiChassisIdentify(std::optional<uint8_t> interval,
1532 std::optional<uint8_t> force)
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001533{
Vernon Mauery400cc782018-10-09 13:49:53 -07001534 uint8_t identifyInterval = interval.value_or(DEFAULT_IDENTIFY_TIME_OUT);
1535 bool forceIdentify = force.value_or(0) & 0x01;
Tom Josephbed26992018-07-31 23:00:24 +05301536
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001537 if (identifyInterval || forceIdentify)
1538 {
Vernon Mauery400cc782018-10-09 13:49:53 -07001539 // stop the timer if already started;
1540 // for force identify we should not turn off LED
Vernon Mauery1181af72018-10-08 12:05:00 -07001541 identifyTimer->stop();
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001542 try
Tom Joseph5110c122018-03-23 17:55:40 +05301543 {
Yong Lif4e38512019-05-21 14:46:55 +08001544 chassisIDState = ChassisIDState::temporaryOn;
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001545 enclosureIdentifyLed(true);
1546 }
1547 catch (const InternalFailure& e)
1548 {
1549 report<InternalFailure>();
Vernon Mauery400cc782018-10-09 13:49:53 -07001550 return ipmi::responseResponseError();
Tom Joseph5110c122018-03-23 17:55:40 +05301551 }
1552
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001553 if (forceIdentify)
Tom Joseph5110c122018-03-23 17:55:40 +05301554 {
Yong Lif4e38512019-05-21 14:46:55 +08001555 chassisIDState = ChassisIDState::indefiniteOn;
Vernon Mauery400cc782018-10-09 13:49:53 -07001556 return ipmi::responseSuccess();
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001557 }
1558 // start the timer
1559 auto time = std::chrono::duration_cast<std::chrono::microseconds>(
Patrick Venture0b02be92018-08-31 11:55:55 -07001560 std::chrono::seconds(identifyInterval));
Vernon Mauery1181af72018-10-08 12:05:00 -07001561 identifyTimer->start(time);
Tom Joseph5110c122018-03-23 17:55:40 +05301562 }
Tom Josephbed26992018-07-31 23:00:24 +05301563 else if (!identifyInterval)
1564 {
Vernon Mauery1181af72018-10-08 12:05:00 -07001565 identifyTimer->stop();
Tom Josephbed26992018-07-31 23:00:24 +05301566 enclosureIdentifyLedOff();
1567 }
Vernon Mauery400cc782018-10-09 13:49:53 -07001568 return ipmi::responseSuccess();
Tom Joseph5110c122018-03-23 17:55:40 +05301569}
1570
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001571namespace boot_options
1572{
1573
1574using namespace sdbusplus::xyz::openbmc_project::Control::Boot::server;
1575using IpmiValue = uint8_t;
1576constexpr auto ipmiDefault = 0;
1577
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001578std::map<IpmiValue, Type::Types> typeIpmiToDbus = {{0x00, Type::Types::Legacy},
1579 {0x01, Type::Types::EFI}};
1580
Patrick Venture0b02be92018-08-31 11:55:55 -07001581std::map<IpmiValue, Source::Sources> sourceIpmiToDbus = {
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001582 {0x01, Source::Sources::Network},
1583 {0x02, Source::Sources::Disk},
1584 {0x05, Source::Sources::ExternalMedia},
Jia, chunhui67c5e5d2019-05-06 11:29:54 +08001585 {0x0f, Source::Sources::RemovableMedia},
Patrick Venture0b02be92018-08-31 11:55:55 -07001586 {ipmiDefault, Source::Sources::Default}};
shgoupfd84fbbf2015-12-17 10:05:51 +08001587
Patrick Venture0b02be92018-08-31 11:55:55 -07001588std::map<IpmiValue, Mode::Modes> modeIpmiToDbus = {
Yong Li5833cb62019-10-30 13:27:12 +08001589#ifdef ENABLE_BOOT_FLAG_SAFE_MODE_SUPPORT
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001590 {0x03, Mode::Modes::Safe},
Yong Li5833cb62019-10-30 13:27:12 +08001591#endif // ENABLE_BOOT_SAFE_MODE_SUPPORT
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001592 {0x06, Mode::Modes::Setup},
Patrick Venture0b02be92018-08-31 11:55:55 -07001593 {ipmiDefault, Mode::Modes::Regular}};
shgoupfd84fbbf2015-12-17 10:05:51 +08001594
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001595std::map<Type::Types, IpmiValue> typeDbusToIpmi = {{Type::Types::Legacy, 0x00},
1596 {Type::Types::EFI, 0x01}};
1597
Patrick Venture0b02be92018-08-31 11:55:55 -07001598std::map<Source::Sources, IpmiValue> sourceDbusToIpmi = {
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001599 {Source::Sources::Network, 0x01},
1600 {Source::Sources::Disk, 0x02},
1601 {Source::Sources::ExternalMedia, 0x05},
Jia, chunhui67c5e5d2019-05-06 11:29:54 +08001602 {Source::Sources::RemovableMedia, 0x0f},
Patrick Venture0b02be92018-08-31 11:55:55 -07001603 {Source::Sources::Default, ipmiDefault}};
shgoupfd84fbbf2015-12-17 10:05:51 +08001604
Patrick Venture0b02be92018-08-31 11:55:55 -07001605std::map<Mode::Modes, IpmiValue> modeDbusToIpmi = {
Yong Li5833cb62019-10-30 13:27:12 +08001606#ifdef ENABLE_BOOT_FLAG_SAFE_MODE_SUPPORT
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001607 {Mode::Modes::Safe, 0x03},
Yong Li5833cb62019-10-30 13:27:12 +08001608#endif // ENABLE_BOOT_SAFE_MODE_SUPPORT
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001609 {Mode::Modes::Setup, 0x06},
Patrick Venture0b02be92018-08-31 11:55:55 -07001610 {Mode::Modes::Regular, ipmiDefault}};
shgoupfd84fbbf2015-12-17 10:05:51 +08001611
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001612} // namespace boot_options
shgoupfd84fbbf2015-12-17 10:05:51 +08001613
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001614/** @brief Get the property value for boot source
1615 * @param[in] ctx - context pointer
1616 * @param[out] source - boot source value
1617 * @return On failure return IPMI error.
1618 */
1619static ipmi::Cc getBootSource(ipmi::Context::ptr& ctx, Source::Sources& source)
1620{
1621 using namespace chassis::internal;
1622 std::string result;
1623 std::string service;
1624 boost::system::error_code ec =
1625 getService(ctx, bootSourceIntf, bootSettingsPath, service);
1626 if (!ec)
1627 {
1628 ec = ipmi::getDbusProperty(ctx, service, bootSettingsPath,
1629 bootSourceIntf, "BootSource", result);
1630 if (!ec)
1631 {
1632 source = Source::convertSourcesFromString(result);
1633 return ipmi::ccSuccess;
1634 }
1635 }
1636 log<level::ERR>("Error in BootSource Get",
1637 entry("ERROR=%s", ec.message().c_str()));
1638 return ipmi::ccUnspecifiedError;
1639}
1640
Marri Devender Rao81719702018-05-07 00:53:48 -05001641/** @brief Set the property value for boot source
Konstantin Aladysheve76a61a2021-03-18 22:19:13 +03001642 * @param[in] ctx - context pointer
Marri Devender Rao81719702018-05-07 00:53:48 -05001643 * @param[in] source - boot source value
1644 * @return On failure return IPMI error.
1645 */
Jayaprakash Mutyala6088e9f2021-07-14 07:40:29 +00001646static ipmi::Cc setBootSource(ipmi::Context::ptr& ctx,
1647 const Source::Sources& source)
Marri Devender Rao81719702018-05-07 00:53:48 -05001648{
1649 using namespace chassis::internal;
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001650 std::string service;
1651 boost::system::error_code ec =
1652 getService(ctx, bootSourceIntf, bootSettingsPath, service);
1653 if (!ec)
Marri Devender Rao81719702018-05-07 00:53:48 -05001654 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001655 ec = ipmi::setDbusProperty(ctx, service, bootSettingsPath,
1656 bootSourceIntf, "BootSource",
1657 convertForMessage(source));
1658 if (!ec)
1659 {
1660 return ipmi::ccSuccess;
1661 }
Marri Devender Rao81719702018-05-07 00:53:48 -05001662 }
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001663 log<level::ERR>("Error in BootSource Set",
1664 entry("ERROR=%s", ec.message().c_str()));
1665 return ipmi::ccUnspecifiedError;
1666}
1667
1668/** @brief Get the property value for boot mode
1669 * @param[in] ctx - context pointer
1670 * @param[out] mode - boot mode value
1671 * @return On failure return IPMI error.
1672 */
1673static ipmi::Cc getBootMode(ipmi::Context::ptr& ctx, Mode::Modes& mode)
1674{
1675 using namespace chassis::internal;
1676 std::string result;
1677 std::string service;
1678 boost::system::error_code ec =
1679 getService(ctx, bootModeIntf, bootSettingsPath, service);
1680 if (!ec)
1681 {
1682 ec = ipmi::getDbusProperty(ctx, service, bootSettingsPath, bootModeIntf,
1683 "BootMode", result);
1684 if (!ec)
1685 {
1686 mode = Mode::convertModesFromString(result);
1687 return ipmi::ccSuccess;
1688 }
1689 }
1690 log<level::ERR>("Error in BootMode Get",
1691 entry("ERROR=%s", ec.message().c_str()));
1692 return ipmi::ccUnspecifiedError;
Marri Devender Rao81719702018-05-07 00:53:48 -05001693}
1694
Patrick Venture0b02be92018-08-31 11:55:55 -07001695/** @brief Set the property value for boot mode
Konstantin Aladysheve76a61a2021-03-18 22:19:13 +03001696 * @param[in] ctx - context pointer
Marri Devender Rao81719702018-05-07 00:53:48 -05001697 * @param[in] mode - boot mode value
1698 * @return On failure return IPMI error.
1699 */
Konstantin Aladysheve76a61a2021-03-18 22:19:13 +03001700static ipmi::Cc setBootMode(ipmi::Context::ptr& ctx, const Mode::Modes& mode)
Marri Devender Rao81719702018-05-07 00:53:48 -05001701{
1702 using namespace chassis::internal;
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001703 std::string service;
1704 boost::system::error_code ec =
1705 getService(ctx, bootModeIntf, bootSettingsPath, service);
1706 if (!ec)
Marri Devender Rao81719702018-05-07 00:53:48 -05001707 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001708 ec = ipmi::setDbusProperty(ctx, service, bootSettingsPath, bootModeIntf,
1709 "BootMode", convertForMessage(mode));
1710 if (!ec)
1711 {
1712 return ipmi::ccSuccess;
1713 }
Marri Devender Rao81719702018-05-07 00:53:48 -05001714 }
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001715 log<level::ERR>("Error in BootMode Set",
1716 entry("ERROR=%s", ec.message().c_str()));
1717 return ipmi::ccUnspecifiedError;
1718}
1719
1720/** @brief Get the property value for boot type
1721 * @param[in] ctx - context pointer
1722 * @param[out] type - boot type value
1723 * @return On failure return IPMI error.
1724 */
1725static ipmi::Cc getBootType(ipmi::Context::ptr& ctx, Type::Types& type)
1726{
1727 using namespace chassis::internal;
1728 std::string result;
1729 std::string service;
1730 boost::system::error_code ec =
1731 getService(ctx, bootTypeIntf, bootSettingsPath, service);
1732
1733 // Don't throw error if BootType interface is not present.
1734 // This interface is not relevant for some Host architectures
1735 // (for example POWER). In this case we don't won't IPMI to
1736 // return an error, but simply return bootType as EFI.
1737 type = Type::Types::EFI;
1738 if (!ec)
1739 {
1740 ec = ipmi::getDbusProperty(ctx, service, bootSettingsPath, bootTypeIntf,
1741 "BootType", result);
1742 if (ec)
1743 {
1744 log<level::ERR>("Error in BootType Get",
1745 entry("ERROR=%s", ec.message().c_str()));
1746 return ipmi::ccUnspecifiedError;
1747 }
1748 type = Type::convertTypesFromString(result);
1749 }
1750
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00001751 return ipmi::ccSuccess;
Marri Devender Rao81719702018-05-07 00:53:48 -05001752}
1753
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001754/** @brief Set the property value for boot type
Konstantin Aladysheve76a61a2021-03-18 22:19:13 +03001755 * @param[in] ctx - context pointer
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001756 * @param[in] type - boot type value
1757 * @return On failure return IPMI error.
1758 */
Konstantin Aladysheve76a61a2021-03-18 22:19:13 +03001759static ipmi::Cc setBootType(ipmi::Context::ptr& ctx, const Type::Types& type)
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001760{
1761 using namespace chassis::internal;
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001762 std::string service;
1763 boost::system::error_code ec =
1764 getService(ctx, bootTypeIntf, bootSettingsPath, service);
1765 if (!ec)
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001766 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001767 ec = ipmi::setDbusProperty(ctx, service, bootSettingsPath, bootTypeIntf,
1768 "BootType", convertForMessage(type));
1769 if (ec)
1770 {
1771 log<level::ERR>("Error in BootType Set",
1772 entry("ERROR=%s", ec.message().c_str()));
1773 return ipmi::ccUnspecifiedError;
1774 }
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001775 }
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001776 // Don't throw error if BootType interface is not present.
1777 // This interface is not relevant for some Host architectures
1778 // (for example POWER). In this case we don't won't IPMI to
1779 // return an error, but want to just skip this function.
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001780 return ipmi::ccSuccess;
1781}
1782
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001783/** @brief Get the property value for boot override enable
1784 * @param[in] ctx - context pointer
1785 * @param[out] enable - boot override enable
1786 * @return On failure return IPMI error.
1787 */
1788static ipmi::Cc getBootEnable(ipmi::Context::ptr& ctx, bool& enable)
1789{
1790 using namespace chassis::internal;
1791 std::string result;
1792 std::string service;
1793 boost::system::error_code ec =
1794 getService(ctx, bootEnableIntf, bootSettingsPath, service);
1795 if (!ec)
1796 {
1797 ec = ipmi::getDbusProperty(ctx, service, bootSettingsPath,
1798 bootEnableIntf, "Enabled", enable);
1799 if (!ec)
1800 {
1801 return ipmi::ccSuccess;
1802 }
1803 }
1804 log<level::ERR>("Error in Boot Override Enable Get",
1805 entry("ERROR=%s", ec.message().c_str()));
1806 return ipmi::ccUnspecifiedError;
1807}
1808
1809/** @brief Set the property value for boot override enable
1810 * @param[in] ctx - context pointer
1811 * @param[in] enable - boot override enable
1812 * @return On failure return IPMI error.
1813 */
1814static ipmi::Cc setBootEnable(ipmi::Context::ptr& ctx, const bool& enable)
1815{
1816 using namespace chassis::internal;
1817 std::string service;
1818 boost::system::error_code ec =
1819 getService(ctx, bootEnableIntf, bootSettingsPath, service);
1820 if (!ec)
1821 {
1822 ec = ipmi::setDbusProperty(ctx, service, bootSettingsPath,
1823 bootEnableIntf, "Enabled", enable);
1824 if (!ec)
1825 {
1826 return ipmi::ccSuccess;
1827 }
1828 }
1829 log<level::ERR>("Error in Boot Source Override Enable Set",
1830 entry("ERROR=%s", ec.message().c_str()));
1831 return ipmi::ccUnspecifiedError;
1832}
1833
1834/** @brief Get the property value for boot override one-time
1835 * @param[in] ctx - context pointer
1836 * @param[out] onetime - boot override one-time
1837 * @return On failure return IPMI error.
1838 */
1839static ipmi::Cc getBootOneTime(ipmi::Context::ptr& ctx, bool& onetime)
1840{
1841 using namespace chassis::internal;
1842 std::string result;
1843 std::string service;
1844 boost::system::error_code ec =
1845 getService(ctx, bootOneTimeIntf, bootSettingsOneTimePath, service);
1846 if (!ec)
1847 {
1848 ec = ipmi::getDbusProperty(ctx, service, bootSettingsOneTimePath,
1849 bootOneTimeIntf, "Enabled", onetime);
1850 if (!ec)
1851 {
1852 return ipmi::ccSuccess;
1853 }
1854 }
1855 log<level::ERR>("Error in Boot Override OneTime Get",
1856 entry("ERROR=%s", ec.message().c_str()));
1857 return ipmi::ccUnspecifiedError;
1858}
1859
1860/** @brief Set the property value for boot override one-time
1861 * @param[in] ctx - context pointer
1862 * @param[in] onetime - boot override one-time
1863 * @return On failure return IPMI error.
1864 */
1865static ipmi::Cc setBootOneTime(ipmi::Context::ptr& ctx, const bool& onetime)
1866{
1867 using namespace chassis::internal;
1868 std::string service;
1869 boost::system::error_code ec =
1870 getService(ctx, bootOneTimeIntf, bootSettingsOneTimePath, service);
1871 if (!ec)
1872 {
1873 ec = ipmi::setDbusProperty(ctx, service, bootSettingsOneTimePath,
1874 bootOneTimeIntf, "Enabled", onetime);
1875 if (!ec)
1876 {
1877 return ipmi::ccSuccess;
1878 }
1879 }
1880 log<level::ERR>("Error in Boot Source Override OneTime Set",
1881 entry("ERROR=%s", ec.message().c_str()));
1882 return ipmi::ccUnspecifiedError;
1883}
1884
huangheab369282020-10-10 14:40:00 +08001885static constexpr uint8_t setComplete = 0x0;
1886static constexpr uint8_t setInProgress = 0x1;
1887static uint8_t transferStatus = setComplete;
Chen Yugang86ac4992021-06-25 08:14:52 +08001888static uint8_t bootFlagValidBitClr = 0;
Hieu Huynh38ffafc2021-05-14 08:40:14 +00001889static uint5_t bootInitiatorAckData = 0x0;
Hieu Huynh1982a3f2021-09-21 03:06:45 +00001890static bool cmosClear = false;
huangheab369282020-10-10 14:40:00 +08001891
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00001892/** @brief implements the Get Chassis system boot option
Konstantin Aladysheve76a61a2021-03-18 22:19:13 +03001893 * @param ctx - context pointer
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00001894 * @param bootOptionParameter - boot option parameter selector
1895 * @param reserved1 - reserved bit
1896 * @param setSelector - selects a particular block or set of parameters
1897 * under the given parameter selector
1898 * write as 00h if parameter doesn't use a setSelector
1899 * @param blockSelector- selects a particular block within a set of
1900 * parameters write as 00h if parameter doesn't use a
1901 * blockSelector
1902 *
1903 * @return IPMI completion code plus response data
1904 * @return Payload contains below parameters:
1905 * version - parameter version
1906 * bootOptionParameter - boot option parameter selector
Patrick Venture8b1c3032020-09-15 09:43:03 -07001907 * parmIndicator - parameter valid/invalid indicator
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00001908 * data - configuration parameter data
1909 */
1910ipmi::RspType<ipmi::message::Payload>
Konstantin Aladysheve76a61a2021-03-18 22:19:13 +03001911 ipmiChassisGetSysBootOptions(ipmi::Context::ptr ctx,
1912 uint7_t bootOptionParameter, bool reserved1,
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00001913
1914 uint8_t setSelector, uint8_t blockSelector)
Adriana Kobylak40814c62015-10-27 15:58:44 -05001915{
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001916 ipmi::Cc rc;
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00001917 if (reserved1)
1918 {
1919 return ipmi::responseInvalidFieldRequest();
1920 }
1921
1922 constexpr uint4_t version = 0x01;
1923 ipmi::message::Payload response;
1924 response.pack(version, uint4_t{});
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001925 using namespace boot_options;
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00001926
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001927 IpmiValue bootOption = ipmiDefault;
Adriana Kobylak40814c62015-10-27 15:58:44 -05001928
William A. Kennington III7a0e5df2021-05-19 13:31:29 -07001929 if (types::enum_cast<BootOptionParameter>(bootOptionParameter) ==
1930 BootOptionParameter::setInProgress)
huangheab369282020-10-10 14:40:00 +08001931 {
1932 response.pack(bootOptionParameter, reserved1, transferStatus);
1933 return ipmi::responseSuccess(std::move(response));
1934 }
1935
William A. Kennington III7a0e5df2021-05-19 13:31:29 -07001936 if (types::enum_cast<BootOptionParameter>(bootOptionParameter) ==
1937 BootOptionParameter::bootInfo)
John Wang0213f902020-12-28 14:49:57 +08001938 {
1939 constexpr uint8_t writeMask = 0;
Hieu Huynh38ffafc2021-05-14 08:40:14 +00001940 response.pack(bootOptionParameter, reserved1, writeMask,
1941 bootInitiatorAckData);
John Wang0213f902020-12-28 14:49:57 +08001942 return ipmi::responseSuccess(std::move(response));
1943 }
1944
Chen Yugang86ac4992021-06-25 08:14:52 +08001945 if (types::enum_cast<BootOptionParameter>(bootOptionParameter) ==
1946 BootOptionParameter::bootFlagValidClr)
1947 {
1948 response.pack(bootOptionParameter, reserved1,
1949 uint5_t{bootFlagValidBitClr}, uint3_t{});
1950 return ipmi::responseSuccess(std::move(response));
1951 }
1952
shgoupfd84fbbf2015-12-17 10:05:51 +08001953 /*
1954 * Parameter #5 means boot flags. Please refer to 28.13 of ipmi doc.
1955 * This is the only parameter used by petitboot.
1956 */
William A. Kennington III7a0e5df2021-05-19 13:31:29 -07001957 if (types::enum_cast<BootOptionParameter>(bootOptionParameter) ==
1958 BootOptionParameter::bootFlags)
Patrick Venture0b02be92018-08-31 11:55:55 -07001959 {
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001960 using namespace chassis::internal;
1961 using namespace chassis::internal::cache;
shgoupfd84fbbf2015-12-17 10:05:51 +08001962
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001963 try
ratagupta6f6bff2016-04-04 06:20:11 -05001964 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001965 Source::Sources bootSource;
1966 rc = getBootSource(ctx, bootSource);
1967 if (rc != ipmi::ccSuccess)
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001968 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001969 return ipmi::response(rc);
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001970 }
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001971
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001972 Type::Types bootType;
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001973 rc = getBootType(ctx, bootType);
1974 if (rc != ipmi::ccSuccess)
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001975 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001976 return ipmi::response(rc);
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001977 }
1978
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001979 Mode::Modes bootMode;
1980 rc = getBootMode(ctx, bootMode);
1981 if (rc != ipmi::ccSuccess)
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001982 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001983 return ipmi::response(rc);
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001984 }
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001985
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001986 bootOption = sourceDbusToIpmi.at(bootSource);
1987 if ((Mode::Modes::Regular == bootMode) &&
1988 (Source::Sources::Default == bootSource))
1989 {
1990 bootOption = ipmiDefault;
1991 }
1992 else if (Source::Sources::Default == bootSource)
1993 {
1994 bootOption = modeDbusToIpmi.at(bootMode);
1995 }
ratagupta6f6bff2016-04-04 06:20:11 -05001996
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03001997 IpmiValue biosBootType = typeDbusToIpmi.at(bootType);
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03001998
1999 bool oneTimeEnabled;
2000 rc = getBootOneTime(ctx, oneTimeEnabled);
2001 if (rc != ipmi::ccSuccess)
2002 {
2003 return ipmi::response(rc);
2004 }
2005
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03002006 uint1_t permanent = oneTimeEnabled ? 0 : 1;
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03002007
2008 bool valid;
2009 rc = getBootEnable(ctx, valid);
2010 if (rc != ipmi::ccSuccess)
2011 {
2012 return ipmi::response(rc);
2013 }
2014
2015 uint1_t validFlag = valid ? 1 : 0;
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03002016
2017 response.pack(bootOptionParameter, reserved1, uint5_t{},
2018 uint1_t{biosBootType}, uint1_t{permanent},
2019 uint1_t{validFlag}, uint2_t{}, uint4_t{bootOption},
Hieu Huynh1982a3f2021-09-21 03:06:45 +00002020 uint1_t{}, cmosClear, uint8_t{}, uint8_t{},
2021 uint8_t{});
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00002022 return ipmi::responseSuccess(std::move(response));
ratagupta6f6bff2016-04-04 06:20:11 -05002023 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -05002024 catch (const InternalFailure& e)
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05002025 {
James Feist225dec82019-11-26 16:25:06 -08002026 cache::objectsPtr.reset();
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05002027 report<InternalFailure>();
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00002028 return ipmi::responseUnspecifiedError();
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05002029 }
Patrick Venture0b02be92018-08-31 11:55:55 -07002030 }
Patrick Venture0b02be92018-08-31 11:55:55 -07002031 else
2032 {
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00002033 if ((bootOptionParameter >= oemParmStart) &&
2034 (bootOptionParameter <= oemParmEnd))
2035 {
William A. Kennington III7a0e5df2021-05-19 13:31:29 -07002036 if (types::enum_cast<BootOptionParameter>(bootOptionParameter) ==
2037 BootOptionParameter::opalNetworkSettings)
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00002038 {
2039 response.pack(bootOptionParameter, reserved1);
2040 int ret = getHostNetworkData(response);
2041 if (ret < 0)
2042 {
2043 response.trailingOk = true;
2044 log<level::ERR>(
2045 "getHostNetworkData failed for GetSysBootOptions.");
2046 return ipmi::responseUnspecifiedError();
2047 }
2048 else
2049 {
2050 return ipmi::responseSuccess(std::move(response));
2051 }
2052 }
Jayaprakash Mutyala43a88102021-08-04 16:41:58 +00002053 else
2054 {
2055 log<level::ERR>(
2056 "ipmiChassisGetSysBootOptions: Unsupported parameter",
2057 entry("PARAM=0x%x",
2058 static_cast<uint8_t>(bootOptionParameter)));
2059 return ipmi::responseParmNotSupported();
2060 }
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00002061 }
2062 else
2063 {
2064 log<level::ERR>(
2065 "ipmiChassisGetSysBootOptions: Unsupported parameter",
2066 entry("PARAM=0x%x", static_cast<uint8_t>(bootOptionParameter)));
Jayaprakash Mutyala6088e9f2021-07-14 07:40:29 +00002067 return ipmi::responseParmNotSupported();
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00002068 }
shgoupfd84fbbf2015-12-17 10:05:51 +08002069 }
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00002070 return ipmi::responseUnspecifiedError();
shgoupfd84fbbf2015-12-17 10:05:51 +08002071}
2072
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002073ipmi::RspType<> ipmiChassisSetSysBootOptions(ipmi::Context::ptr ctx,
2074 uint7_t parameterSelector,
2075 bool parameterIsValid,
2076 ipmi::message::Payload& data)
shgoupfd84fbbf2015-12-17 10:05:51 +08002077{
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05002078 using namespace boot_options;
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002079 ipmi::Cc rc;
shgoupfd84fbbf2015-12-17 10:05:51 +08002080
William A. Kennington III7a0e5df2021-05-19 13:31:29 -07002081 if (types::enum_cast<BootOptionParameter>(parameterSelector) ==
2082 BootOptionParameter::setInProgress)
huangheab369282020-10-10 14:40:00 +08002083 {
2084 uint2_t setInProgressFlag;
2085 uint6_t rsvd;
2086 if (data.unpack(setInProgressFlag, rsvd) != 0 || !data.fullyUnpacked())
2087 {
2088 return ipmi::responseReqDataLenInvalid();
2089 }
2090 if (rsvd)
2091 {
2092 return ipmi::responseInvalidFieldRequest();
2093 }
2094 if ((transferStatus == setInProgress) &&
2095 (static_cast<uint8_t>(setInProgressFlag) != setComplete))
2096 {
2097 return ipmi::response(IPMI_CC_FAIL_SET_IN_PROGRESS);
2098 }
2099 transferStatus = static_cast<uint8_t>(setInProgressFlag);
2100 return ipmi::responseSuccess();
2101 }
2102
shgoupfd84fbbf2015-12-17 10:05:51 +08002103 /* 000101
2104 * Parameter #5 means boot flags. Please refer to 28.13 of ipmi doc.
2105 * This is the only parameter used by petitboot.
2106 */
Ratan Guptafd28dd72016-08-01 04:58:01 -05002107
William A. Kennington III7a0e5df2021-05-19 13:31:29 -07002108 if (types::enum_cast<BootOptionParameter>(parameterSelector) ==
2109 BootOptionParameter::bootFlags)
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05002110 {
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002111 uint5_t rsvd;
2112 bool validFlag;
2113 bool permanent;
2114 bool biosBootType;
2115 bool lockOutResetButton;
2116 bool screenBlank;
2117 uint4_t bootDeviceSelector;
2118 bool lockKeyboard;
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002119 uint8_t data3;
2120 uint4_t biosInfo;
2121 uint4_t rsvd1;
2122 uint5_t deviceInstance;
2123 uint3_t rsvd2;
2124
2125 if (data.unpack(rsvd, biosBootType, permanent, validFlag,
2126 lockOutResetButton, screenBlank, bootDeviceSelector,
2127 lockKeyboard, cmosClear, data3, biosInfo, rsvd1,
2128 deviceInstance, rsvd2) != 0 ||
2129 !data.fullyUnpacked())
2130 {
2131 return ipmi::responseReqDataLenInvalid();
2132 }
2133 if (rsvd || rsvd1 || rsvd2)
2134 {
2135 return ipmi::responseInvalidFieldRequest();
2136 }
2137
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05002138 using namespace chassis::internal;
2139 using namespace chassis::internal::cache;
shgoupfd84fbbf2015-12-17 10:05:51 +08002140
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05002141 try
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05002142 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03002143 rc = setBootOneTime(ctx, !permanent);
2144 if (rc != ipmi::ccSuccess)
Konstantin Aladyshev69e8e842021-06-18 17:01:18 +03002145 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03002146 return ipmi::response(rc);
2147 }
Vernon Maueryafd45db2021-07-29 16:27:25 +00002148
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03002149 rc = setBootEnable(ctx, validFlag);
2150 if (rc != ipmi::ccSuccess)
2151 {
2152 return ipmi::response(rc);
Tom Joseph57e8eb72017-09-25 18:05:02 +05302153 }
2154
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002155 auto modeItr =
2156 modeIpmiToDbus.find(static_cast<uint8_t>(bootDeviceSelector));
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03002157 auto typeItr =
2158 typeIpmiToDbus.find(static_cast<uint8_t>(biosBootType));
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002159 auto sourceItr =
2160 sourceIpmiToDbus.find(static_cast<uint8_t>(bootDeviceSelector));
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05002161 if (sourceIpmiToDbus.end() != sourceItr)
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05002162 {
Konstantin Aladysheve76a61a2021-03-18 22:19:13 +03002163 rc = setBootSource(ctx, sourceItr->second);
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002164 if (rc != ipmi::ccSuccess)
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05002165 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03002166 return ipmi::response(rc);
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05002167 }
Marri Devender Rao54fa1302018-05-07 01:06:23 -05002168 // If a set boot device is mapping to a boot source, then reset
2169 // the boot mode D-Bus property to default.
2170 // This way the ipmid code can determine which property is not
2171 // at the default value
Patrick Venture0b02be92018-08-31 11:55:55 -07002172 if (sourceItr->second != Source::Sources::Default)
Marri Devender Rao54fa1302018-05-07 01:06:23 -05002173 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03002174 rc = setBootMode(ctx, Mode::Modes::Regular);
2175 if (rc != ipmi::ccSuccess)
2176 {
2177 return ipmi::response(rc);
2178 }
Marri Devender Rao54fa1302018-05-07 01:06:23 -05002179 }
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05002180 }
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03002181
2182 if (typeIpmiToDbus.end() != typeItr)
2183 {
Konstantin Aladysheve76a61a2021-03-18 22:19:13 +03002184 rc = setBootType(ctx, typeItr->second);
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03002185 if (rc != ipmi::ccSuccess)
2186 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03002187 return ipmi::response(rc);
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03002188 }
2189 }
2190
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05002191 if (modeIpmiToDbus.end() != modeItr)
2192 {
Konstantin Aladysheve76a61a2021-03-18 22:19:13 +03002193 rc = setBootMode(ctx, modeItr->second);
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002194 if (rc != ipmi::ccSuccess)
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05002195 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03002196 return ipmi::response(rc);
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05002197 }
Marri Devender Rao54fa1302018-05-07 01:06:23 -05002198 // If a set boot device is mapping to a boot mode, then reset
2199 // the boot source D-Bus property to default.
2200 // This way the ipmid code can determine which property is not
2201 // at the default value
Patrick Venture0b02be92018-08-31 11:55:55 -07002202 if (modeItr->second != Mode::Modes::Regular)
Marri Devender Rao54fa1302018-05-07 01:06:23 -05002203 {
Konstantin Aladyshev08a080a2021-06-18 17:01:18 +03002204 rc = setBootSource(ctx, Source::Sources::Default);
2205 if (rc != ipmi::ccSuccess)
2206 {
2207 return ipmi::response(rc);
2208 }
Marri Devender Rao54fa1302018-05-07 01:06:23 -05002209 }
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05002210 }
Jia, chunhui67c5e5d2019-05-06 11:29:54 +08002211 if ((modeIpmiToDbus.end() == modeItr) &&
Konstantin Aladyshev96ef0282021-02-09 13:57:10 +03002212 (typeIpmiToDbus.end() == typeItr) &&
Jia, chunhui67c5e5d2019-05-06 11:29:54 +08002213 (sourceIpmiToDbus.end() == sourceItr))
2214 {
2215 // return error if boot option is not supported
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002216 log<level::ERR>(
2217 "ipmiChassisSetSysBootOptions: Boot option not supported");
2218 return ipmi::responseInvalidFieldRequest();
Jia, chunhui67c5e5d2019-05-06 11:29:54 +08002219 }
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05002220 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -05002221 catch (const sdbusplus::exception_t& e)
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05002222 {
James Feist225dec82019-11-26 16:25:06 -08002223 objectsPtr.reset();
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05002224 report<InternalFailure>();
Aditya Saripalli5fb14602017-11-09 14:46:27 +05302225 log<level::ERR>(
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002226 "ipmiChassisSetSysBootOptions: Error in setting Boot "
2227 "flag parameters");
2228 return ipmi::responseUnspecifiedError();
Ratan Guptafd28dd72016-08-01 04:58:01 -05002229 }
Patrick Venture0b02be92018-08-31 11:55:55 -07002230 }
William A. Kennington III7a0e5df2021-05-19 13:31:29 -07002231 else if (types::enum_cast<BootOptionParameter>(parameterSelector) ==
2232 BootOptionParameter::bootInfo)
Patrick Venture0b02be92018-08-31 11:55:55 -07002233 {
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002234 uint8_t writeMak;
Hieu Huynh38ffafc2021-05-14 08:40:14 +00002235 uint5_t bootInfoAck;
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002236 uint3_t rsvd;
2237
Hieu Huynh38ffafc2021-05-14 08:40:14 +00002238 if (data.unpack(writeMak, bootInfoAck, rsvd) != 0 ||
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002239 !data.fullyUnpacked())
2240 {
2241 return ipmi::responseReqDataLenInvalid();
2242 }
2243 if (rsvd)
2244 {
2245 return ipmi::responseInvalidFieldRequest();
2246 }
Hieu Huynh38ffafc2021-05-14 08:40:14 +00002247 bootInitiatorAckData &= ~writeMak;
2248 bootInitiatorAckData |= (writeMak & bootInfoAck);
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002249 log<level::INFO>("ipmiChassisSetSysBootOptions: bootInfo parameter set "
2250 "successfully");
2251 data.trailingOk = true;
2252 return ipmi::responseSuccess();
Patrick Venture0b02be92018-08-31 11:55:55 -07002253 }
Chen Yugang86ac4992021-06-25 08:14:52 +08002254 else if (types::enum_cast<BootOptionParameter>(parameterSelector) ==
2255 BootOptionParameter::bootFlagValidClr)
2256 {
2257 uint5_t bootFlagValidClr;
2258 uint3_t rsvd;
2259
2260 if (data.unpack(bootFlagValidClr, rsvd) != 0 || !data.fullyUnpacked())
2261 {
2262 return ipmi::responseReqDataLenInvalid();
2263 }
2264 if (rsvd)
2265 {
2266 return ipmi::responseInvalidFieldRequest();
2267 }
2268 // store boot flag valid bits clear value
2269 bootFlagValidBitClr = static_cast<uint8_t>(bootFlagValidClr);
2270 log<level::INFO>(
2271 "ipmiChassisSetSysBootOptions: bootFlagValidBits parameter set "
2272 "successfully",
2273 entry("value=0x%x", bootFlagValidBitClr));
2274 return ipmi::responseSuccess();
2275 }
Patrick Venture0b02be92018-08-31 11:55:55 -07002276 else
2277 {
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002278 if ((parameterSelector >= static_cast<uint7_t>(oemParmStart)) &&
2279 (parameterSelector <= static_cast<uint7_t>(oemParmEnd)))
2280 {
William A. Kennington III7a0e5df2021-05-19 13:31:29 -07002281 if (types::enum_cast<BootOptionParameter>(parameterSelector) ==
2282 BootOptionParameter::opalNetworkSettings)
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002283 {
2284 ipmi::Cc ret = setHostNetworkData(data);
2285 if (ret != ipmi::ccSuccess)
2286 {
2287 log<level::ERR>("ipmiChassisSetSysBootOptions: Error in "
2288 "setHostNetworkData");
2289 data.trailingOk = true;
2290 return ipmi::response(ret);
2291 }
2292 data.trailingOk = true;
2293 return ipmi::responseSuccess();
2294 }
2295 else
2296 {
2297 log<level::ERR>(
2298 "ipmiChassisSetSysBootOptions: Unsupported parameters",
2299 entry("PARAM=0x%x",
2300 static_cast<uint8_t>(parameterSelector)));
2301 data.trailingOk = true;
2302 return ipmi::responseParmNotSupported();
2303 }
2304 }
2305 data.trailingOk = true;
2306 return ipmi::responseParmNotSupported();
Adriana Kobylak40814c62015-10-27 15:58:44 -05002307 }
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002308 return ipmi::responseSuccess();
Adriana Kobylak40814c62015-10-27 15:58:44 -05002309}
2310
anil kumar appanaa5a76eb2019-04-30 14:57:24 +00002311/** @brief implements Get POH counter command
2312 * @parameter
2313 * - none
2314 * @returns IPMI completion code plus response data
2315 * - minPerCount - Minutes per count
2316 * - counterReading - counter reading
2317 */
2318ipmi::RspType<uint8_t, // Minutes per count
2319 uint32_t // Counter reading
2320 >
2321 ipmiGetPOHCounter()
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -05002322{
2323 // sd_bus error
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -05002324 try
2325 {
anil kumar appanaa5a76eb2019-04-30 14:57:24 +00002326 return ipmi::responseSuccess(static_cast<uint8_t>(poh::minutesPerCount),
2327 getPOHCounter());
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -05002328 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -05002329 catch (const std::exception& e)
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -05002330 {
2331 log<level::ERR>(e.what());
anil kumar appanaa5a76eb2019-04-30 14:57:24 +00002332 return ipmi::responseUnspecifiedError();
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -05002333 }
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -05002334}
2335
Jason M. Billsbc996a32019-06-17 15:46:37 -07002336ipmi::RspType<uint3_t, // policy support
2337 uint5_t // reserved
2338 >
Vernon Mauerye278ead2018-10-09 09:23:43 -07002339 ipmiChassisSetPowerRestorePolicy(boost::asio::yield_context yield,
Jason M. Billsbc996a32019-06-17 15:46:37 -07002340 uint3_t policy, uint5_t reserved)
Yong Lic6713cf2018-09-12 12:35:13 +08002341{
Yong Lic6713cf2018-09-12 12:35:13 +08002342 power_policy::DbusValue value =
2343 power_policy::RestorePolicy::Policy::AlwaysOff;
2344
Jason M. Billsbc996a32019-06-17 15:46:37 -07002345 if (reserved || (policy > power_policy::noChange))
Yong Lic6713cf2018-09-12 12:35:13 +08002346 {
Vernon Mauerye278ead2018-10-09 09:23:43 -07002347 phosphor::logging::log<level::ERR>(
2348 "Reserved request parameter",
2349 entry("REQ=0x%x", static_cast<int>(policy)));
Jason M. Billsbc996a32019-06-17 15:46:37 -07002350 return ipmi::responseInvalidFieldRequest();
Yong Lic6713cf2018-09-12 12:35:13 +08002351 }
2352
Vernon Mauerye278ead2018-10-09 09:23:43 -07002353 if (policy == power_policy::noChange)
Yong Lic6713cf2018-09-12 12:35:13 +08002354 {
2355 // just return the supported policy
Jason M. Billsbc996a32019-06-17 15:46:37 -07002356 return ipmi::responseSuccess(power_policy::allSupport, reserved);
Yong Lic6713cf2018-09-12 12:35:13 +08002357 }
2358
2359 for (auto const& it : power_policy::dbusToIpmi)
2360 {
Vernon Mauerye278ead2018-10-09 09:23:43 -07002361 if (it.second == policy)
Yong Lic6713cf2018-09-12 12:35:13 +08002362 {
2363 value = it.first;
2364 break;
2365 }
2366 }
2367
2368 try
2369 {
James Feist225dec82019-11-26 16:25:06 -08002370 settings::Objects& objects = chassis::internal::cache::getObjects();
Yong Lic6713cf2018-09-12 12:35:13 +08002371 const settings::Path& powerRestoreSetting =
James Feist225dec82019-11-26 16:25:06 -08002372 objects.map.at(chassis::internal::powerRestoreIntf).front();
Vernon Mauery16b86932019-05-01 08:36:11 -07002373 std::variant<std::string> property = convertForMessage(value);
Yong Lic6713cf2018-09-12 12:35:13 +08002374
Vernon Mauerye278ead2018-10-09 09:23:43 -07002375 auto sdbusp = getSdBus();
2376 boost::system::error_code ec;
2377 sdbusp->yield_method_call<void>(
2378 yield, ec,
James Feist225dec82019-11-26 16:25:06 -08002379 objects
Yong Lic6713cf2018-09-12 12:35:13 +08002380 .service(powerRestoreSetting,
2381 chassis::internal::powerRestoreIntf)
2382 .c_str(),
Vernon Mauerye278ead2018-10-09 09:23:43 -07002383 powerRestoreSetting, ipmi::PROP_INTF, "Set",
2384 chassis::internal::powerRestoreIntf, "PowerRestorePolicy",
2385 property);
2386 if (ec)
Yong Lic6713cf2018-09-12 12:35:13 +08002387 {
2388 phosphor::logging::log<level::ERR>("Unspecified Error");
Vernon Mauerye278ead2018-10-09 09:23:43 -07002389 return ipmi::responseUnspecifiedError();
Yong Lic6713cf2018-09-12 12:35:13 +08002390 }
2391 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -05002392 catch (const InternalFailure& e)
Yong Lic6713cf2018-09-12 12:35:13 +08002393 {
James Feist225dec82019-11-26 16:25:06 -08002394 chassis::internal::cache::objectsPtr.reset();
Yong Lic6713cf2018-09-12 12:35:13 +08002395 report<InternalFailure>();
Vernon Mauerye278ead2018-10-09 09:23:43 -07002396 return ipmi::responseUnspecifiedError();
Yong Lic6713cf2018-09-12 12:35:13 +08002397 }
2398
Jason M. Billsbc996a32019-06-17 15:46:37 -07002399 return ipmi::responseSuccess(power_policy::allSupport, reserved);
Yong Lic6713cf2018-09-12 12:35:13 +08002400}
2401
Kuiying Wang21addc52019-01-04 10:50:21 +08002402ipmi::RspType<> ipmiSetFrontPanelButtonEnables(
2403 ipmi::Context::ptr ctx, bool disablePowerButton, bool disableResetButton,
2404 bool disableDiagButton, bool disableSleepButton, uint4_t reserved)
2405{
2406 using namespace chassis::internal;
2407
2408 // set power button Enabled property
2409 bool success = setButtonEnabled(ctx, powerButtonPath, powerButtonIntf,
2410 !disablePowerButton);
2411
2412 // set reset button Enabled property
2413 success &= setButtonEnabled(ctx, resetButtonPath, resetButtonIntf,
2414 !disableResetButton);
2415
2416 if (!success)
2417 {
2418 // not all buttons were successfully set
2419 return ipmi::responseUnspecifiedError();
2420 }
2421 return ipmi::responseSuccess();
2422}
2423
Adriana Kobylak40814c62015-10-27 15:58:44 -05002424void register_netfn_chassis_functions()
2425{
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05002426 createIdentifyTimer();
2427
Tom05732372016-09-06 17:21:23 +05302428 // Get Chassis Capabilities
anil kumar appana43263c62019-05-27 12:45:04 +00002429 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis,
2430 ipmi::chassis::cmdGetChassisCapabilities,
2431 ipmi::Privilege::User, ipmiGetChassisCap);
Nan Li8d15fb42016-08-16 22:29:40 +08002432
Kuiying Wang21addc52019-01-04 10:50:21 +08002433 // Set Front Panel Button Enables
2434 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis,
2435 ipmi::chassis::cmdSetFrontPanelButtonEnables,
2436 ipmi::Privilege::Admin,
2437 ipmiSetFrontPanelButtonEnables);
2438
Yong Liae4b0402018-11-02 11:12:14 +08002439 // Set Chassis Capabilities
anil kumar appana894d0222019-05-27 16:32:14 +00002440 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis,
2441 ipmi::chassis::cmdSetChassisCapabilities,
2442 ipmi::Privilege::User, ipmiSetChassisCap);
Yong Liae4b0402018-11-02 11:12:14 +08002443
Tom05732372016-09-06 17:21:23 +05302444 // <Get System Boot Options>
Jayaprakash Mutyalad1ef8772020-08-25 10:32:58 +00002445 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis,
2446 ipmi::chassis::cmdGetSystemBootOptions,
2447 ipmi::Privilege::Operator,
2448 ipmiChassisGetSysBootOptions);
Adriana Kobylak40814c62015-10-27 15:58:44 -05002449
Tom05732372016-09-06 17:21:23 +05302450 // <Get Chassis Status>
Vernon Mauery4a8a4eb2019-04-04 15:09:37 -07002451 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis,
2452 ipmi::chassis::cmdGetChassisStatus,
2453 ipmi::Privilege::User, ipmiGetChassisStatus);
Nan Lifdd8ec52016-08-28 03:57:40 +08002454
Vijay Khemka074f64d2020-03-03 15:08:43 -08002455 // <Chassis Get System Restart Cause>
2456 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis,
2457 ipmi::chassis::cmdGetSystemRestartCause,
2458 ipmi::Privilege::User, ipmiGetSystemRestartCause);
2459
Tom05732372016-09-06 17:21:23 +05302460 // <Chassis Control>
anil kumar appanadafff5f2019-04-27 18:06:00 +00002461 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis,
2462 ipmi::chassis::cmdChassisControl,
2463 ipmi::Privilege::Operator, ipmiChassisControl);
shgoupfd84fbbf2015-12-17 10:05:51 +08002464
Tom Joseph5110c122018-03-23 17:55:40 +05302465 // <Chassis Identify>
Vernon Mauery400cc782018-10-09 13:49:53 -07002466 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis,
2467 ipmi::chassis::cmdChassisIdentify,
2468 ipmi::Privilege::Operator, ipmiChassisIdentify);
Tom Joseph5110c122018-03-23 17:55:40 +05302469
Tom05732372016-09-06 17:21:23 +05302470 // <Set System Boot Options>
jayaprakash Mutyalabfd8fc42020-05-05 22:38:03 +00002471 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis,
2472 ipmi::chassis::cmdSetSystemBootOptions,
2473 ipmi::Privilege::Operator,
2474 ipmiChassisSetSysBootOptions);
2475
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -05002476 // <Get POH Counter>
anil kumar appanaa5a76eb2019-04-30 14:57:24 +00002477 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis,
2478 ipmi::chassis::cmdGetPohCounter,
2479 ipmi::Privilege::User, ipmiGetPOHCounter);
Yong Lic6713cf2018-09-12 12:35:13 +08002480
2481 // <Set Power Restore Policy>
Vernon Mauerye278ead2018-10-09 09:23:43 -07002482 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis,
2483 ipmi::chassis::cmdSetPowerRestorePolicy,
2484 ipmi::Privilege::Operator,
2485 ipmiChassisSetPowerRestorePolicy);
vishwa36993272015-11-20 12:43:49 -06002486}