Patrick Venture | 46470a3 | 2018-09-07 19:26:25 -0700 | [diff] [blame] | 1 | #include "config.h" |
| 2 | |
| 3 | #include "chassishandler.hpp" |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 4 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 5 | #include <arpa/inet.h> |
| 6 | #include <endian.h> |
| 7 | #include <limits.h> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 8 | #include <netinet/in.h> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 9 | |
Vernon Mauery | e08fbff | 2019-04-03 09:19:34 -0700 | [diff] [blame] | 10 | #include <ipmid/api.hpp> |
Vernon Mauery | 3325024 | 2019-03-12 16:49:26 -0700 | [diff] [blame] | 11 | #include <ipmid/types.hpp> |
Vernon Mauery | 6a98fe7 | 2019-03-11 15:57:48 -0700 | [diff] [blame] | 12 | #include <ipmid/utils.hpp> |
Patrick Venture | 3a5071a | 2018-09-12 13:27:42 -0700 | [diff] [blame] | 13 | #include <phosphor-logging/elog-errors.hpp> |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 14 | #include <phosphor-logging/lg2.hpp> |
Patrick Venture | 3a5071a | 2018-09-12 13:27:42 -0700 | [diff] [blame] | 15 | #include <sdbusplus/bus.hpp> |
William A. Kennington III | 4c00802 | 2018-10-12 17:18:14 -0700 | [diff] [blame] | 16 | #include <sdbusplus/message/types.hpp> |
Patrick Venture | 3a5071a | 2018-09-12 13:27:42 -0700 | [diff] [blame] | 17 | #include <sdbusplus/server/object.hpp> |
Vernon Mauery | 1181af7 | 2018-10-08 12:05:00 -0700 | [diff] [blame] | 18 | #include <sdbusplus/timer.hpp> |
Vernon Mauery | e278ead | 2018-10-09 09:23:43 -0700 | [diff] [blame] | 19 | #include <settings.hpp> |
Chau Ly | 8c1376c | 2024-01-05 07:22:10 +0000 | [diff] [blame] | 20 | #include <xyz/openbmc_project/Chassis/Intrusion/client.hpp> |
Patrick Venture | 3a5071a | 2018-09-12 13:27:42 -0700 | [diff] [blame] | 21 | #include <xyz/openbmc_project/Common/error.hpp> |
| 22 | #include <xyz/openbmc_project/Control/Boot/Mode/server.hpp> |
| 23 | #include <xyz/openbmc_project/Control/Boot/Source/server.hpp> |
Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 24 | #include <xyz/openbmc_project/Control/Boot/Type/server.hpp> |
Patrick Venture | 3a5071a | 2018-09-12 13:27:42 -0700 | [diff] [blame] | 25 | #include <xyz/openbmc_project/Control/Power/RestorePolicy/server.hpp> |
Jason M. Bills | ad588bf | 2020-01-30 16:18:33 -0800 | [diff] [blame] | 26 | #include <xyz/openbmc_project/State/Chassis/server.hpp> |
Patrick Venture | 3a5071a | 2018-09-12 13:27:42 -0700 | [diff] [blame] | 27 | #include <xyz/openbmc_project/State/Host/server.hpp> |
| 28 | #include <xyz/openbmc_project/State/PowerOnHours/server.hpp> |
| 29 | |
Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 30 | #include <array> |
| 31 | #include <chrono> |
| 32 | #include <cstring> |
| 33 | #include <filesystem> |
| 34 | #include <fstream> |
| 35 | #include <future> |
| 36 | #include <map> |
| 37 | #include <sstream> |
| 38 | #include <string> |
| 39 | |
Patrick Williams | 9565522 | 2023-12-05 12:45:02 -0600 | [diff] [blame] | 40 | std::unique_ptr<sdbusplus::Timer> identifyTimer |
Lei YU | 4b0ddb6 | 2019-01-25 16:43:50 +0800 | [diff] [blame] | 41 | __attribute__((init_priority(101))); |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 42 | |
Yong Li | f4e3851 | 2019-05-21 14:46:55 +0800 | [diff] [blame] | 43 | static ChassisIDState chassisIDState = ChassisIDState::reserved; |
| 44 | |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 45 | constexpr size_t sizeVersion = 2; |
Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 46 | constexpr size_t DEFAULT_IDENTIFY_TIME_OUT = 15; |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 47 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 48 | // PetiBoot-Specific |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 49 | static constexpr uint8_t netConfInitialBytes[] = {0x80, 0x21, 0x70, 0x62, |
| 50 | 0x21, 0x00, 0x01, 0x06}; |
| 51 | static constexpr uint8_t oemParmStart = 96; |
| 52 | static constexpr uint8_t oemParmEnd = 127; |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 53 | |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 54 | static constexpr size_t cookieOffset = 1; |
| 55 | static constexpr size_t versionOffset = 5; |
| 56 | static constexpr size_t addrSizeOffset = 8; |
| 57 | static constexpr size_t macOffset = 9; |
| 58 | static constexpr size_t addrTypeOffset = 16; |
| 59 | static constexpr size_t ipAddrOffset = 17; |
ratagupt | a6f6bff | 2016-04-04 06:20:11 -0500 | [diff] [blame] | 60 | |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 61 | namespace ipmi |
| 62 | { |
| 63 | constexpr Cc ccParmNotSupported = 0x80; |
George Liu | f5dd102 | 2025-07-07 09:13:07 +0800 | [diff] [blame] | 64 | constexpr Cc ccFailSetInProgress = 0x81; |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 65 | |
| 66 | static inline auto responseParmNotSupported() |
| 67 | { |
| 68 | return response(ccParmNotSupported); |
| 69 | } |
George Liu | f5dd102 | 2025-07-07 09:13:07 +0800 | [diff] [blame] | 70 | |
| 71 | static inline auto responsefailSetInProgress() |
| 72 | { |
| 73 | return response(ccFailSetInProgress); |
| 74 | } |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 75 | } // namespace ipmi |
| 76 | |
George Liu | 5087b07 | 2025-03-11 19:28:17 +0800 | [diff] [blame] | 77 | void registerNetFnChassisFunctions() __attribute__((constructor)); |
Adriana Kobylak | 40814c6 | 2015-10-27 15:58:44 -0500 | [diff] [blame] | 78 | |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 79 | // Host settings in dbus |
| 80 | // Service name should be referenced by connection name got via object mapper |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 81 | const char* settings_object_name = "/org/openbmc/settings/host0"; |
| 82 | const char* settings_intf_name = "org.freedesktop.DBus.Properties"; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 83 | const char* identify_led_object_name = |
Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 84 | "/xyz/openbmc_project/led/groups/enclosure_identify"; |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 85 | |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 86 | constexpr auto SETTINGS_ROOT = "/"; |
| 87 | constexpr auto SETTINGS_MATCH = "host0"; |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 88 | |
| 89 | constexpr auto IP_INTERFACE = "xyz.openbmc_project.Network.IP"; |
| 90 | constexpr auto MAC_INTERFACE = "xyz.openbmc_project.Network.MACAddress"; |
| 91 | |
Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 92 | static constexpr auto chassisStateRoot = "/xyz/openbmc_project/state"; |
| 93 | static constexpr auto chassisPOHStateIntf = |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 94 | "xyz.openbmc_project.State.PowerOnHours"; |
Patrick Williams | 7345ac4 | 2021-04-30 20:57:39 -0500 | [diff] [blame] | 95 | static constexpr auto pohCounterProperty = "POHCounter"; |
Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 96 | static constexpr auto match = "chassis0"; |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 97 | const static constexpr char chassisCapIntf[] = |
| 98 | "xyz.openbmc_project.Control.ChassisCapabilities"; |
Karthick Sundarrajan | 86d8bd7 | 2019-11-26 12:48:50 -0800 | [diff] [blame] | 99 | const static constexpr char chassisIntrusionProp[] = "ChassisIntrusionEnabled"; |
| 100 | const static constexpr char chassisFrontPanelLockoutProp[] = |
| 101 | "ChassisFrontPanelLockoutEnabled"; |
| 102 | const static constexpr char chassisNMIProp[] = "ChassisNMIEnabled"; |
| 103 | const static constexpr char chassisPowerInterlockProp[] = |
| 104 | "ChassisPowerInterlockEnabled"; |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 105 | const static constexpr char chassisFRUDevAddrProp[] = "FRUDeviceAddress"; |
| 106 | const static constexpr char chassisSDRDevAddrProp[] = "SDRDeviceAddress"; |
| 107 | const static constexpr char chassisSELDevAddrProp[] = "SELDeviceAddress"; |
| 108 | const static constexpr char chassisSMDevAddrProp[] = "SMDeviceAddress"; |
| 109 | const static constexpr char chassisBridgeDevAddrProp[] = "BridgeDeviceAddress"; |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 110 | static constexpr uint8_t chassisCapAddrMask = 0xfe; |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 111 | static constexpr const char* powerButtonIntf = |
| 112 | "xyz.openbmc_project.Chassis.Buttons.Power"; |
| 113 | static constexpr const char* powerButtonPath = |
| 114 | "/xyz/openbmc_project/Chassis/Buttons/Power0"; |
| 115 | static constexpr const char* resetButtonIntf = |
| 116 | "xyz.openbmc_project.Chassis.Buttons.Reset"; |
| 117 | static constexpr const char* resetButtonPath = |
| 118 | "/xyz/openbmc_project/Chassis/Buttons/Reset0"; |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 119 | |
Vishwanatha Subbanna | b12b0c0 | 2017-03-07 18:17:19 +0530 | [diff] [blame] | 120 | // Phosphor Host State manager |
Willy Tu | 523e2d1 | 2023-09-05 11:36:48 -0700 | [diff] [blame] | 121 | namespace State = sdbusplus::server::xyz::openbmc_project::state; |
Vernon Mauery | 185b9f8 | 2018-07-20 10:52:36 -0700 | [diff] [blame] | 122 | namespace fs = std::filesystem; |
Andrew Geissler | a6e3a30 | 2017-05-31 19:34:00 -0500 | [diff] [blame] | 123 | |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 124 | using namespace phosphor::logging; |
Willy Tu | 523e2d1 | 2023-09-05 11:36:48 -0700 | [diff] [blame] | 125 | using namespace sdbusplus::error::xyz::openbmc_project::common; |
| 126 | using namespace sdbusplus::server::xyz::openbmc_project::control::boot; |
Chau Ly | 8c1376c | 2024-01-05 07:22:10 +0000 | [diff] [blame] | 127 | using Intrusion = sdbusplus::client::xyz::openbmc_project::chassis::Intrusion<>; |
William A. Kennington III | 4c00802 | 2018-10-12 17:18:14 -0700 | [diff] [blame] | 128 | |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 129 | namespace chassis |
| 130 | { |
| 131 | namespace internal |
| 132 | { |
| 133 | |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 134 | constexpr auto bootSettingsPath = "/xyz/openbmc_project/control/host0/boot"; |
| 135 | constexpr auto bootEnableIntf = "xyz.openbmc_project.Object.Enable"; |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 136 | constexpr auto bootModeIntf = "xyz.openbmc_project.Control.Boot.Mode"; |
Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 137 | constexpr auto bootTypeIntf = "xyz.openbmc_project.Control.Boot.Type"; |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 138 | constexpr auto bootSourceIntf = "xyz.openbmc_project.Control.Boot.Source"; |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 139 | constexpr auto bootSettingsOneTimePath = |
| 140 | "/xyz/openbmc_project/control/host0/boot/one_time"; |
| 141 | constexpr auto bootOneTimeIntf = "xyz.openbmc_project.Object.Enable"; |
| 142 | |
Deepak Kodihalli | 18b70d1 | 2017-07-21 13:36:33 -0500 | [diff] [blame] | 143 | constexpr auto powerRestoreIntf = |
| 144 | "xyz.openbmc_project.Control.Power.RestorePolicy"; |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 145 | sdbusplus::bus_t dbus(ipmid_get_sd_bus_connection()); |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 146 | |
| 147 | namespace cache |
| 148 | { |
| 149 | |
James Feist | 225dec8 | 2019-11-26 16:25:06 -0800 | [diff] [blame] | 150 | std::unique_ptr<settings::Objects> objectsPtr = nullptr; |
| 151 | |
| 152 | settings::Objects& getObjects() |
| 153 | { |
| 154 | if (objectsPtr == nullptr) |
| 155 | { |
| 156 | objectsPtr = std::make_unique<settings::Objects>( |
Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 157 | dbus, std::vector<std::string>{bootModeIntf, bootTypeIntf, |
| 158 | bootSourceIntf, powerRestoreIntf}); |
James Feist | 225dec8 | 2019-11-26 16:25:06 -0800 | [diff] [blame] | 159 | } |
| 160 | return *objectsPtr; |
| 161 | } |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 162 | |
| 163 | } // namespace cache |
| 164 | } // namespace internal |
| 165 | } // namespace chassis |
| 166 | |
Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 167 | namespace poh |
| 168 | { |
| 169 | |
| 170 | constexpr auto minutesPerCount = 60; |
| 171 | |
| 172 | } // namespace poh |
| 173 | |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 174 | int getHostNetworkData(ipmi::message::Payload& payload) |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 175 | { |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 176 | ipmi::PropertyMap properties; |
| 177 | int rc = 0; |
Ratan Gupta | 8c31d23 | 2017-08-13 05:49:43 +0530 | [diff] [blame] | 178 | uint8_t addrSize = ipmi::network::IPV4_ADDRESS_SIZE_BYTE; |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 179 | |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 180 | try |
| 181 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 182 | // TODO There may be cases where an interface is implemented by multiple |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 183 | // objects,to handle such cases we are interested on that object |
| 184 | // which are on interested busname. |
| 185 | // Currenlty mapper doesn't give the readable busname(gives busid) |
| 186 | // so we can't match with bus name so giving some object specific info |
| 187 | // as SETTINGS_MATCH. |
| 188 | // Later SETTINGS_MATCH will be replaced with busname. |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 189 | |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 190 | sdbusplus::bus_t bus(ipmid_get_sd_bus_connection()); |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 191 | |
Ratan Gupta | 01d4bd1 | 2017-08-07 15:53:25 +0530 | [diff] [blame] | 192 | auto ipObjectInfo = ipmi::getDbusObject(bus, IP_INTERFACE, |
| 193 | SETTINGS_ROOT, SETTINGS_MATCH); |
| 194 | |
| 195 | auto macObjectInfo = ipmi::getDbusObject(bus, MAC_INTERFACE, |
| 196 | SETTINGS_ROOT, SETTINGS_MATCH); |
| 197 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 198 | properties = ipmi::getAllDbusProperties( |
| 199 | bus, ipObjectInfo.second, ipObjectInfo.first, IP_INTERFACE); |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 200 | auto variant = ipmi::getDbusProperty( |
| 201 | bus, macObjectInfo.second, macObjectInfo.first, MAC_INTERFACE, |
| 202 | "MACAddress"); |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 203 | |
Vernon Mauery | f442e11 | 2019-04-09 11:44:36 -0700 | [diff] [blame] | 204 | auto ipAddress = std::get<std::string>(properties["Address"]); |
Ratan Gupta | d70f453 | 2017-08-04 02:07:31 +0530 | [diff] [blame] | 205 | |
Vernon Mauery | f442e11 | 2019-04-09 11:44:36 -0700 | [diff] [blame] | 206 | auto gateway = std::get<std::string>(properties["Gateway"]); |
Ratan Gupta | d70f453 | 2017-08-04 02:07:31 +0530 | [diff] [blame] | 207 | |
Vernon Mauery | f442e11 | 2019-04-09 11:44:36 -0700 | [diff] [blame] | 208 | auto prefix = std::get<uint8_t>(properties["PrefixLength"]); |
Ratan Gupta | d70f453 | 2017-08-04 02:07:31 +0530 | [diff] [blame] | 209 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 210 | uint8_t isStatic = |
Vernon Mauery | f442e11 | 2019-04-09 11:44:36 -0700 | [diff] [blame] | 211 | (std::get<std::string>(properties["Origin"]) == |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 212 | "xyz.openbmc_project.Network.IP.AddressOrigin.Static") |
| 213 | ? 1 |
| 214 | : 0; |
Ratan Gupta | d70f453 | 2017-08-04 02:07:31 +0530 | [diff] [blame] | 215 | |
Vernon Mauery | f442e11 | 2019-04-09 11:44:36 -0700 | [diff] [blame] | 216 | auto MACAddress = std::get<std::string>(variant); |
Ratan Gupta | cc8feb4 | 2017-07-25 21:52:10 +0530 | [diff] [blame] | 217 | |
Ratan Gupta | d70f453 | 2017-08-04 02:07:31 +0530 | [diff] [blame] | 218 | // it is expected here that we should get the valid data |
| 219 | // but we may also get the default values. |
| 220 | // Validation of the data is done by settings. |
| 221 | // |
| 222 | // if mac address is default mac address then |
| 223 | // don't send blank override. |
Ratan Gupta | 8c31d23 | 2017-08-13 05:49:43 +0530 | [diff] [blame] | 224 | if ((MACAddress == ipmi::network::DEFAULT_MAC_ADDRESS)) |
Ratan Gupta | d70f453 | 2017-08-04 02:07:31 +0530 | [diff] [blame] | 225 | { |
Ratan Gupta | d70f453 | 2017-08-04 02:07:31 +0530 | [diff] [blame] | 226 | rc = -1; |
| 227 | return rc; |
| 228 | } |
| 229 | // if addr is static then ipaddress,gateway,prefix |
| 230 | // should not be default one,don't send blank override. |
| 231 | if (isStatic) |
| 232 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 233 | if ((ipAddress == ipmi::network::DEFAULT_ADDRESS) || |
| 234 | (gateway == ipmi::network::DEFAULT_ADDRESS) || (!prefix)) |
Ratan Gupta | d70f453 | 2017-08-04 02:07:31 +0530 | [diff] [blame] | 235 | { |
Ratan Gupta | d70f453 | 2017-08-04 02:07:31 +0530 | [diff] [blame] | 236 | rc = -1; |
| 237 | return rc; |
| 238 | } |
| 239 | } |
| 240 | |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 241 | std::string token; |
| 242 | std::stringstream ss(MACAddress); |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 243 | |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 244 | // First pack macOffset no of bytes in payload. |
| 245 | // Latter this PetiBoot-Specific data will be populated. |
| 246 | std::vector<uint8_t> payloadInitialBytes(macOffset); |
| 247 | payload.pack(payloadInitialBytes); |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 248 | |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 249 | while (std::getline(ss, token, ':')) |
| 250 | { |
| 251 | payload.pack(stoi(token, nullptr, 16)); |
| 252 | } |
| 253 | |
| 254 | payload.pack(0x00); |
| 255 | |
| 256 | payload.pack(isStatic); |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 257 | |
Vernon Mauery | f442e11 | 2019-04-09 11:44:36 -0700 | [diff] [blame] | 258 | uint8_t addressFamily = (std::get<std::string>(properties["Type"]) == |
| 259 | "xyz.openbmc_project.Network.IP.Protocol.IPv4") |
| 260 | ? AF_INET |
| 261 | : AF_INET6; |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 262 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 263 | addrSize = (addressFamily == AF_INET) |
| 264 | ? ipmi::network::IPV4_ADDRESS_SIZE_BYTE |
| 265 | : ipmi::network::IPV6_ADDRESS_SIZE_BYTE; |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 266 | |
| 267 | // ipaddress and gateway would be in IPv4 format |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 268 | std::vector<uint8_t> addrInBinary(addrSize); |
Ratan Gupta | d70f453 | 2017-08-04 02:07:31 +0530 | [diff] [blame] | 269 | inet_pton(addressFamily, ipAddress.c_str(), |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 270 | reinterpret_cast<void*>(addrInBinary.data())); |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 271 | |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 272 | payload.pack(addrInBinary); |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 273 | |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 274 | payload.pack(prefix); |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 275 | |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 276 | std::vector<uint8_t> gatewayDetails(addrSize); |
Ratan Gupta | d70f453 | 2017-08-04 02:07:31 +0530 | [diff] [blame] | 277 | inet_pton(addressFamily, gateway.c_str(), |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 278 | reinterpret_cast<void*>(gatewayDetails.data())); |
| 279 | payload.pack(gatewayDetails); |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 280 | } |
Patrick Williams | a2ad2da | 2021-10-06 12:21:46 -0500 | [diff] [blame] | 281 | catch (const InternalFailure& e) |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 282 | { |
| 283 | commit<InternalFailure>(); |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 284 | rc = -1; |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 285 | return rc; |
| 286 | } |
| 287 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 288 | // PetiBoot-Specific |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 289 | // If success then copy the first 9 bytes to the payload message |
| 290 | // payload first 2 bytes contain the parameter values. Skip that 2 bytes. |
| 291 | uint8_t skipFirstTwoBytes = 2; |
| 292 | size_t payloadSize = payload.size(); |
| 293 | uint8_t* configDataStartingAddress = payload.data() + skipFirstTwoBytes; |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 294 | |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 295 | if (payloadSize < skipFirstTwoBytes + sizeof(netConfInitialBytes)) |
| 296 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 297 | lg2::error("Invalid net config"); |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 298 | rc = -1; |
| 299 | return rc; |
| 300 | } |
| 301 | std::copy(netConfInitialBytes, |
| 302 | netConfInitialBytes + sizeof(netConfInitialBytes), |
| 303 | configDataStartingAddress); |
| 304 | |
| 305 | if (payloadSize < skipFirstTwoBytes + addrSizeOffset + sizeof(addrSize)) |
| 306 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 307 | lg2::error("Invalid length of address size"); |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 308 | rc = -1; |
| 309 | return rc; |
| 310 | } |
| 311 | std::copy(&addrSize, &(addrSize) + sizeof(addrSize), |
| 312 | configDataStartingAddress + addrSizeOffset); |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 313 | |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 314 | #ifdef _IPMI_DEBUG_ |
Patrick Venture | b51bf9c | 2018-09-10 15:53:14 -0700 | [diff] [blame] | 315 | std::printf("\n===Printing the IPMI Formatted Data========\n"); |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 316 | |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 317 | for (uint8_t pos = 0; pos < index; pos++) |
| 318 | { |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 319 | std::printf("%02x ", payloadStartingAddress[pos]); |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 320 | } |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 321 | #endif |
| 322 | |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 323 | return rc; |
| 324 | } |
| 325 | |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 326 | /** @brief convert IPv4 and IPv6 addresses from binary to text form. |
| 327 | * @param[in] family - IPv4/Ipv6 |
| 328 | * @param[in] data - req data pointer. |
| 329 | * @param[in] offset - offset in the data. |
| 330 | * @param[in] addrSize - size of the data which needs to be read from offset. |
| 331 | * @returns address in text form. |
| 332 | */ |
| 333 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 334 | std::string getAddrStr(uint8_t family, uint8_t* data, uint8_t offset, |
| 335 | uint8_t addrSize) |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 336 | { |
| 337 | char ipAddr[INET6_ADDRSTRLEN] = {}; |
| 338 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 339 | switch (family) |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 340 | { |
| 341 | case AF_INET: |
| 342 | { |
Patrick Williams | 99db688 | 2024-12-18 11:20:17 -0500 | [diff] [blame] | 343 | struct sockaddr_in addr4{}; |
Patrick Venture | b51bf9c | 2018-09-10 15:53:14 -0700 | [diff] [blame] | 344 | std::memcpy(&addr4.sin_addr.s_addr, &data[offset], addrSize); |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 345 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 346 | inet_ntop(AF_INET, &addr4.sin_addr, ipAddr, INET_ADDRSTRLEN); |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 347 | |
| 348 | break; |
| 349 | } |
| 350 | case AF_INET6: |
| 351 | { |
Patrick Williams | 99db688 | 2024-12-18 11:20:17 -0500 | [diff] [blame] | 352 | struct sockaddr_in6 addr6{}; |
Patrick Venture | b51bf9c | 2018-09-10 15:53:14 -0700 | [diff] [blame] | 353 | std::memcpy(&addr6.sin6_addr.s6_addr, &data[offset], addrSize); |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 354 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 355 | inet_ntop(AF_INET6, &addr6.sin6_addr, ipAddr, INET6_ADDRSTRLEN); |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 356 | |
| 357 | break; |
| 358 | } |
| 359 | default: |
| 360 | { |
| 361 | return {}; |
| 362 | } |
| 363 | } |
| 364 | |
| 365 | return ipAddr; |
| 366 | } |
| 367 | |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 368 | ipmi::Cc setHostNetworkData(ipmi::message::Payload& data) |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 369 | { |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 370 | using namespace std::string_literals; |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 371 | std::string hostNetworkConfig; |
| 372 | std::string mac("00:00:00:00:00:00"); |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 373 | std::string ipAddress, gateway; |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 374 | std::string addrOrigin{0}; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 375 | uint8_t addrSize{0}; |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 376 | std::string addressOrigin = |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 377 | "xyz.openbmc_project.Network.IP.AddressOrigin.DHCP"; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 378 | std::string addressType = "xyz.openbmc_project.Network.IP.Protocol.IPv4"; |
| 379 | uint8_t prefix{0}; |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 380 | uint8_t family = AF_INET; |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 381 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 382 | // cookie starts from second byte |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 383 | // version starts from sixth byte |
| 384 | |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 385 | try |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 386 | { |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 387 | do |
| 388 | { |
| 389 | // cookie == 0x21 0x70 0x62 0x21 |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 390 | data.trailingOk = true; |
| 391 | auto msgLen = data.size(); |
| 392 | std::vector<uint8_t> msgPayloadBytes(msgLen); |
| 393 | if (data.unpack(msgPayloadBytes) != 0 || !data.fullyUnpacked()) |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 394 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 395 | lg2::error("Error in unpacking message of setHostNetworkData"); |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 396 | return ipmi::ccReqDataLenInvalid; |
| 397 | } |
| 398 | |
| 399 | uint8_t* msgPayloadStartingPos = msgPayloadBytes.data(); |
| 400 | constexpr size_t cookieSize = 4; |
| 401 | if (msgLen < cookieOffset + cookieSize) |
| 402 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 403 | lg2::error("Error in cookie getting of setHostNetworkData"); |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 404 | return ipmi::ccReqDataLenInvalid; |
| 405 | } |
| 406 | if (std::equal(msgPayloadStartingPos + cookieOffset, |
| 407 | msgPayloadStartingPos + cookieOffset + cookieSize, |
| 408 | (netConfInitialBytes + cookieOffset)) != 0) |
| 409 | { |
| 410 | // all cookie == 0 |
| 411 | if (std::all_of(msgPayloadStartingPos + cookieOffset, |
| 412 | msgPayloadStartingPos + cookieOffset + |
| 413 | cookieSize, |
| 414 | [](int i) { return i == 0; }) == true) |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 415 | { |
| 416 | // need to zero out the network settings. |
| 417 | break; |
| 418 | } |
| 419 | |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 420 | lg2::error("Invalid Cookie"); |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 421 | elog<InternalFailure>(); |
| 422 | } |
| 423 | |
| 424 | // vesion == 0x00 0x01 |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 425 | if (msgLen < versionOffset + sizeVersion) |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 426 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 427 | lg2::error("Error in version getting of setHostNetworkData"); |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 428 | return ipmi::ccReqDataLenInvalid; |
| 429 | } |
| 430 | if (std::equal(msgPayloadStartingPos + versionOffset, |
| 431 | msgPayloadStartingPos + versionOffset + sizeVersion, |
| 432 | (netConfInitialBytes + versionOffset)) != 0) |
| 433 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 434 | lg2::error("Invalid Version"); |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 435 | elog<InternalFailure>(); |
| 436 | } |
| 437 | |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 438 | if (msgLen < macOffset + 6) |
| 439 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 440 | lg2::error( |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 441 | "Error in mac address getting of setHostNetworkData"); |
| 442 | return ipmi::ccReqDataLenInvalid; |
| 443 | } |
| 444 | std::stringstream result; |
| 445 | std::copy((msgPayloadStartingPos + macOffset), |
| 446 | (msgPayloadStartingPos + macOffset + 5), |
| 447 | std::ostream_iterator<int>(result, ":")); |
| 448 | mac = result.str(); |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 449 | |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 450 | if (msgLen < addrTypeOffset + sizeof(decltype(addrOrigin))) |
| 451 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 452 | lg2::error( |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 453 | "Error in original address getting of setHostNetworkData"); |
| 454 | return ipmi::ccReqDataLenInvalid; |
| 455 | } |
| 456 | std::copy(msgPayloadStartingPos + addrTypeOffset, |
| 457 | msgPayloadStartingPos + addrTypeOffset + |
| 458 | sizeof(decltype(addrOrigin)), |
| 459 | std::ostream_iterator<int>(result, "")); |
| 460 | addrOrigin = result.str(); |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 461 | |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 462 | if (!addrOrigin.empty()) |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 463 | { |
| 464 | addressOrigin = |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 465 | "xyz.openbmc_project.Network.IP.AddressOrigin.Static"; |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 466 | } |
| 467 | |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 468 | if (msgLen < addrSizeOffset + sizeof(decltype(addrSize))) |
| 469 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 470 | lg2::error( |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 471 | "Error in address size getting of setHostNetworkData"); |
| 472 | return ipmi::ccReqDataLenInvalid; |
| 473 | } |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 474 | // Get the address size |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 475 | std::copy(msgPayloadStartingPos + addrSizeOffset, |
| 476 | (msgPayloadStartingPos + addrSizeOffset + |
| 477 | sizeof(decltype(addrSize))), |
| 478 | &addrSize); |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 479 | |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 480 | uint8_t prefixOffset = ipAddrOffset + addrSize; |
| 481 | if (msgLen < prefixOffset + sizeof(decltype(prefix))) |
| 482 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 483 | lg2::error("Error in prefix getting of setHostNetworkData"); |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 484 | return ipmi::ccReqDataLenInvalid; |
| 485 | } |
William A. Kennington III | 4c52102 | 2023-07-28 13:07:30 -0700 | [diff] [blame] | 486 | // std::copy(msgPayloadStartingPos + prefixOffset, |
| 487 | // msgPayloadStartingPos + prefixOffset + |
| 488 | // sizeof(decltype(prefix)), |
| 489 | // &prefix); |
| 490 | // Workaround compiler misdetecting out of bounds memcpy |
| 491 | prefix = msgPayloadStartingPos[prefixOffset]; |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 492 | |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 493 | uint8_t gatewayOffset = prefixOffset + sizeof(decltype(prefix)); |
Ratan Gupta | 8c31d23 | 2017-08-13 05:49:43 +0530 | [diff] [blame] | 494 | if (addrSize != ipmi::network::IPV4_ADDRESS_SIZE_BYTE) |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 495 | { |
| 496 | addressType = "xyz.openbmc_project.Network.IP.Protocol.IPv6"; |
| 497 | family = AF_INET6; |
| 498 | } |
| 499 | |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 500 | if (msgLen < ipAddrOffset + addrSize) |
| 501 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 502 | lg2::error("Error in IP address getting of setHostNetworkData"); |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 503 | return ipmi::ccReqDataLenInvalid; |
| 504 | } |
| 505 | ipAddress = getAddrStr(family, msgPayloadStartingPos, ipAddrOffset, |
| 506 | addrSize); |
Ratan Gupta | d70f453 | 2017-08-04 02:07:31 +0530 | [diff] [blame] | 507 | |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 508 | if (msgLen < gatewayOffset + addrSize) |
| 509 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 510 | lg2::error( |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 511 | "Error in gateway address getting of setHostNetworkData"); |
| 512 | return ipmi::ccReqDataLenInvalid; |
| 513 | } |
| 514 | gateway = getAddrStr(family, msgPayloadStartingPos, gatewayOffset, |
| 515 | addrSize); |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 516 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 517 | } while (0); |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 518 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 519 | // Cookie == 0 or it is a valid cookie |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 520 | hostNetworkConfig += |
| 521 | "ipaddress="s + ipAddress + ",prefix="s + std::to_string(prefix) + |
| 522 | ",gateway="s + gateway + ",mac="s + mac + ",addressOrigin="s + |
| 523 | addressOrigin; |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 524 | |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 525 | sdbusplus::bus_t bus(ipmid_get_sd_bus_connection()); |
Ratan Gupta | 01d4bd1 | 2017-08-07 15:53:25 +0530 | [diff] [blame] | 526 | |
| 527 | auto ipObjectInfo = ipmi::getDbusObject(bus, IP_INTERFACE, |
| 528 | SETTINGS_ROOT, SETTINGS_MATCH); |
| 529 | auto macObjectInfo = ipmi::getDbusObject(bus, MAC_INTERFACE, |
| 530 | SETTINGS_ROOT, SETTINGS_MATCH); |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 531 | // set the dbus property |
Ratan Gupta | 01d4bd1 | 2017-08-07 15:53:25 +0530 | [diff] [blame] | 532 | ipmi::setDbusProperty(bus, ipObjectInfo.second, ipObjectInfo.first, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 533 | IP_INTERFACE, "Address", std::string(ipAddress)); |
Ratan Gupta | 01d4bd1 | 2017-08-07 15:53:25 +0530 | [diff] [blame] | 534 | ipmi::setDbusProperty(bus, ipObjectInfo.second, ipObjectInfo.first, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 535 | IP_INTERFACE, "PrefixLength", prefix); |
Ratan Gupta | 01d4bd1 | 2017-08-07 15:53:25 +0530 | [diff] [blame] | 536 | ipmi::setDbusProperty(bus, ipObjectInfo.second, ipObjectInfo.first, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 537 | IP_INTERFACE, "Origin", addressOrigin); |
Ratan Gupta | 01d4bd1 | 2017-08-07 15:53:25 +0530 | [diff] [blame] | 538 | ipmi::setDbusProperty(bus, ipObjectInfo.second, ipObjectInfo.first, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 539 | IP_INTERFACE, "Gateway", std::string(gateway)); |
| 540 | ipmi::setDbusProperty( |
| 541 | bus, ipObjectInfo.second, ipObjectInfo.first, IP_INTERFACE, "Type", |
| 542 | std::string("xyz.openbmc_project.Network.IP.Protocol.IPv4")); |
Ratan Gupta | 01d4bd1 | 2017-08-07 15:53:25 +0530 | [diff] [blame] | 543 | ipmi::setDbusProperty(bus, macObjectInfo.second, macObjectInfo.first, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 544 | MAC_INTERFACE, "MACAddress", std::string(mac)); |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 545 | |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 546 | lg2::debug("Network configuration changed: {NETWORKCONFIG}", |
| 547 | "NETWORKCONFIG", hostNetworkConfig); |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 548 | } |
Patrick Williams | a2ad2da | 2021-10-06 12:21:46 -0500 | [diff] [blame] | 549 | catch (const sdbusplus::exception_t& e) |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 550 | { |
| 551 | commit<InternalFailure>(); |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 552 | lg2::error("Error in ipmiChassisSetSysBootOptions call"); |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 553 | return ipmi::ccUnspecifiedError; |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 554 | } |
| 555 | |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 556 | return ipmi::ccSuccess; |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 557 | } |
| 558 | |
Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 559 | uint32_t getPOHCounter() |
| 560 | { |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 561 | sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()}; |
Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 562 | |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 563 | auto chassisStateObj = |
| 564 | ipmi::getDbusObject(bus, chassisPOHStateIntf, chassisStateRoot, match); |
Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 565 | |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 566 | auto service = |
| 567 | ipmi::getService(bus, chassisPOHStateIntf, chassisStateObj.first); |
Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 568 | |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 569 | auto propValue = |
| 570 | ipmi::getDbusProperty(bus, service, chassisStateObj.first, |
| 571 | chassisPOHStateIntf, pohCounterProperty); |
Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 572 | |
Vernon Mauery | f442e11 | 2019-04-09 11:44:36 -0700 | [diff] [blame] | 573 | return std::get<uint32_t>(propValue); |
Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 574 | } |
| 575 | |
anil kumar appana | 43263c6 | 2019-05-27 12:45:04 +0000 | [diff] [blame] | 576 | /** @brief Implements the get chassis capabilities command |
| 577 | * |
| 578 | * @returns IPMI completion code plus response data |
| 579 | * chassisCapFlags - chassis capability flag |
| 580 | * chassisFRUInfoDevAddr - chassis FRU info Device Address |
| 581 | * chassisSDRDevAddr - chassis SDR device address |
| 582 | * chassisSELDevAddr - chassis SEL device address |
| 583 | * chassisSMDevAddr - chassis system management device address |
| 584 | * chassisBridgeDevAddr - chassis bridge device address |
| 585 | */ |
Karthick Sundarrajan | 86d8bd7 | 2019-11-26 12:48:50 -0800 | [diff] [blame] | 586 | ipmi::RspType<bool, // chassis intrusion sensor |
| 587 | bool, // chassis Front panel lockout |
| 588 | bool, // chassis NMI |
| 589 | bool, // chassis power interlock |
| 590 | uint4_t, // reserved |
anil kumar appana | 43263c6 | 2019-05-27 12:45:04 +0000 | [diff] [blame] | 591 | uint8_t, // chassis FRU info Device Address |
| 592 | uint8_t, // chassis SDR device address |
| 593 | uint8_t, // chassis SEL device address |
| 594 | uint8_t, // chassis system management device address |
| 595 | uint8_t // chassis bridge device address |
| 596 | > |
| 597 | ipmiGetChassisCap() |
Nan Li | 8d15fb4 | 2016-08-16 22:29:40 +0800 | [diff] [blame] | 598 | { |
anil kumar appana | 43263c6 | 2019-05-27 12:45:04 +0000 | [diff] [blame] | 599 | ipmi::PropertyMap properties; |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 600 | try |
| 601 | { |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 602 | sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()}; |
Nan Li | 8d15fb4 | 2016-08-16 22:29:40 +0800 | [diff] [blame] | 603 | |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 604 | ipmi::DbusObjectInfo chassisCapObject = |
| 605 | ipmi::getDbusObject(bus, chassisCapIntf); |
Nan Li | 8d15fb4 | 2016-08-16 22:29:40 +0800 | [diff] [blame] | 606 | |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 607 | // capabilities flags |
| 608 | // [7..4] - reserved |
| 609 | // [3] – 1b = provides power interlock (IPM 1.5) |
| 610 | // [2] – 1b = provides Diagnostic Interrupt (FP NMI) |
| 611 | // [1] – 1b = provides “Front Panel Lockout” (indicates that the chassis |
| 612 | // has capabilities |
| 613 | // to lock out external power control and reset button or |
| 614 | // front panel interfaces and/or detect tampering with those |
| 615 | // interfaces). |
| 616 | // [0] -1b = Chassis provides intrusion (physical security) sensor. |
| 617 | // set to default value 0x0. |
Nan Li | 8d15fb4 | 2016-08-16 22:29:40 +0800 | [diff] [blame] | 618 | |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 619 | properties = |
| 620 | ipmi::getAllDbusProperties(bus, chassisCapObject.second, |
| 621 | chassisCapObject.first, chassisCapIntf); |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 622 | } |
Patrick Williams | a2ad2da | 2021-10-06 12:21:46 -0500 | [diff] [blame] | 623 | catch (const std::exception& e) |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 624 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 625 | lg2::error("Failed to fetch Chassis Capability properties: {ERROR}", |
| 626 | "ERROR", e); |
anil kumar appana | 43263c6 | 2019-05-27 12:45:04 +0000 | [diff] [blame] | 627 | return ipmi::responseUnspecifiedError(); |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 628 | } |
| 629 | |
Karthick Sundarrajan | 86d8bd7 | 2019-11-26 12:48:50 -0800 | [diff] [blame] | 630 | bool* chassisIntrusionFlag = |
| 631 | std::get_if<bool>(&properties[chassisIntrusionProp]); |
| 632 | if (chassisIntrusionFlag == nullptr) |
anil kumar appana | 43263c6 | 2019-05-27 12:45:04 +0000 | [diff] [blame] | 633 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 634 | lg2::error("Error to get chassis Intrusion flags"); |
Karthick Sundarrajan | 86d8bd7 | 2019-11-26 12:48:50 -0800 | [diff] [blame] | 635 | return ipmi::responseUnspecifiedError(); |
| 636 | } |
| 637 | bool* chassisFrontPanelFlag = |
| 638 | std::get_if<bool>(&properties[chassisFrontPanelLockoutProp]); |
| 639 | if (chassisFrontPanelFlag == nullptr) |
| 640 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 641 | lg2::error("Error to get chassis intrusion flags"); |
Karthick Sundarrajan | 86d8bd7 | 2019-11-26 12:48:50 -0800 | [diff] [blame] | 642 | return ipmi::responseUnspecifiedError(); |
| 643 | } |
| 644 | bool* chassisNMIFlag = std::get_if<bool>(&properties[chassisNMIProp]); |
| 645 | if (chassisNMIFlag == nullptr) |
| 646 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 647 | lg2::error("Error to get chassis NMI flags"); |
Karthick Sundarrajan | 86d8bd7 | 2019-11-26 12:48:50 -0800 | [diff] [blame] | 648 | return ipmi::responseUnspecifiedError(); |
| 649 | } |
| 650 | bool* chassisPowerInterlockFlag = |
| 651 | std::get_if<bool>(&properties[chassisPowerInterlockProp]); |
| 652 | if (chassisPowerInterlockFlag == nullptr) |
| 653 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 654 | lg2::error("Error to get chassis power interlock flags"); |
anil kumar appana | 43263c6 | 2019-05-27 12:45:04 +0000 | [diff] [blame] | 655 | return ipmi::responseUnspecifiedError(); |
| 656 | } |
| 657 | uint8_t* chassisFRUInfoDevAddr = |
| 658 | std::get_if<uint8_t>(&properties[chassisFRUDevAddrProp]); |
| 659 | if (chassisFRUInfoDevAddr == nullptr) |
| 660 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 661 | lg2::error("Error to get chassis FRU info device address"); |
anil kumar appana | 43263c6 | 2019-05-27 12:45:04 +0000 | [diff] [blame] | 662 | return ipmi::responseUnspecifiedError(); |
| 663 | } |
| 664 | uint8_t* chassisSDRDevAddr = |
| 665 | std::get_if<uint8_t>(&properties[chassisSDRDevAddrProp]); |
| 666 | if (chassisSDRDevAddr == nullptr) |
| 667 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 668 | lg2::error("Error to get chassis SDR device address"); |
anil kumar appana | 43263c6 | 2019-05-27 12:45:04 +0000 | [diff] [blame] | 669 | return ipmi::responseUnspecifiedError(); |
| 670 | } |
| 671 | uint8_t* chassisSELDevAddr = |
| 672 | std::get_if<uint8_t>(&properties[chassisSELDevAddrProp]); |
| 673 | if (chassisSELDevAddr == nullptr) |
| 674 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 675 | lg2::error("Error to get chassis SEL device address"); |
anil kumar appana | 43263c6 | 2019-05-27 12:45:04 +0000 | [diff] [blame] | 676 | return ipmi::responseUnspecifiedError(); |
| 677 | } |
| 678 | uint8_t* chassisSMDevAddr = |
| 679 | std::get_if<uint8_t>(&properties[chassisSMDevAddrProp]); |
| 680 | if (chassisSMDevAddr == nullptr) |
| 681 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 682 | lg2::error("Error to get chassis SM device address"); |
anil kumar appana | 43263c6 | 2019-05-27 12:45:04 +0000 | [diff] [blame] | 683 | return ipmi::responseUnspecifiedError(); |
| 684 | } |
| 685 | uint8_t* chassisBridgeDevAddr = |
| 686 | std::get_if<uint8_t>(&properties[chassisBridgeDevAddrProp]); |
| 687 | if (chassisBridgeDevAddr == nullptr) |
| 688 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 689 | lg2::error("Error to get chassis bridge device address"); |
anil kumar appana | 43263c6 | 2019-05-27 12:45:04 +0000 | [diff] [blame] | 690 | return ipmi::responseUnspecifiedError(); |
| 691 | } |
| 692 | |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 693 | return ipmi::responseSuccess( |
| 694 | *chassisIntrusionFlag, *chassisFrontPanelFlag, *chassisNMIFlag, |
| 695 | *chassisPowerInterlockFlag, 0, *chassisFRUInfoDevAddr, |
| 696 | *chassisSDRDevAddr, *chassisSELDevAddr, *chassisSMDevAddr, |
| 697 | *chassisBridgeDevAddr); |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 698 | } |
| 699 | |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 700 | /** @brief implements set chassis capalibities command |
| 701 | * @param intrusion - chassis intrusion |
| 702 | * @param fpLockout - frontpannel lockout |
| 703 | * @param reserved1 - skip one bit |
| 704 | * @param fruDeviceAddr - chassis FRU info Device Address |
| 705 | * @param sdrDeviceAddr - chassis SDR device address |
| 706 | * @param selDeviceAddr - chassis SEL device address |
| 707 | * @param smDeviceAddr - chassis system management device address |
| 708 | * @param bridgeDeviceAddr - chassis bridge device address |
| 709 | * |
| 710 | * @returns IPMI completion code |
| 711 | */ |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 712 | ipmi::RspType<> ipmiSetChassisCap( |
| 713 | bool intrusion, bool fpLockout, uint6_t reserved1, |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 714 | |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 715 | uint8_t fruDeviceAddr, |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 716 | |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 717 | uint8_t sdrDeviceAddr, |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 718 | |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 719 | uint8_t selDeviceAddr, |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 720 | |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 721 | uint8_t smDeviceAddr, |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 722 | |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 723 | uint8_t bridgeDeviceAddr) |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 724 | { |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 725 | // check input data |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 726 | if (reserved1 != 0) |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 727 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 728 | lg2::error("Unsupported request parameter"); |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 729 | return ipmi::responseInvalidFieldRequest(); |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 730 | } |
| 731 | |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 732 | if ((fruDeviceAddr & ~chassisCapAddrMask) != 0) |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 733 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 734 | lg2::error("Unsupported request parameter(FRU Addr) for REQ={REQ}", |
| 735 | "REQ", lg2::hex, fruDeviceAddr); |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 736 | return ipmi::responseInvalidFieldRequest(); |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 737 | } |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 738 | if ((sdrDeviceAddr & ~chassisCapAddrMask) != 0) |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 739 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 740 | lg2::error("Unsupported request parameter(SDR Addr) for REQ={REQ}", |
| 741 | "REQ", lg2::hex, sdrDeviceAddr); |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 742 | return ipmi::responseInvalidFieldRequest(); |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 743 | } |
| 744 | |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 745 | if ((selDeviceAddr & ~chassisCapAddrMask) != 0) |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 746 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 747 | lg2::error("Unsupported request parameter(SEL Addr) for REQ={REQ}", |
| 748 | "REQ", lg2::hex, selDeviceAddr); |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 749 | return ipmi::responseInvalidFieldRequest(); |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 750 | } |
| 751 | |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 752 | if ((smDeviceAddr & ~chassisCapAddrMask) != 0) |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 753 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 754 | lg2::error("Unsupported request parameter(SM Addr) for REQ={REQ}", |
| 755 | "REQ", lg2::hex, smDeviceAddr); |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 756 | return ipmi::responseInvalidFieldRequest(); |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 757 | } |
| 758 | |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 759 | if ((bridgeDeviceAddr & ~chassisCapAddrMask) != 0) |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 760 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 761 | lg2::error("Unsupported request parameter(Bridge Addr) for REQ={REQ}", |
| 762 | "REQ", lg2::hex, bridgeDeviceAddr); |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 763 | return ipmi::responseInvalidFieldRequest(); |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 764 | } |
| 765 | |
| 766 | try |
| 767 | { |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 768 | sdbusplus::bus_t bus(ipmid_get_sd_bus_connection()); |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 769 | ipmi::DbusObjectInfo chassisCapObject = |
| 770 | ipmi::getDbusObject(bus, chassisCapIntf); |
| 771 | |
| 772 | ipmi::setDbusProperty(bus, chassisCapObject.second, |
| 773 | chassisCapObject.first, chassisCapIntf, |
Karthick Sundarrajan | 86d8bd7 | 2019-11-26 12:48:50 -0800 | [diff] [blame] | 774 | chassisIntrusionProp, intrusion); |
| 775 | |
| 776 | ipmi::setDbusProperty(bus, chassisCapObject.second, |
| 777 | chassisCapObject.first, chassisCapIntf, |
| 778 | chassisFrontPanelLockoutProp, fpLockout); |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 779 | |
| 780 | ipmi::setDbusProperty(bus, chassisCapObject.second, |
| 781 | chassisCapObject.first, chassisCapIntf, |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 782 | chassisFRUDevAddrProp, fruDeviceAddr); |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 783 | |
| 784 | ipmi::setDbusProperty(bus, chassisCapObject.second, |
| 785 | chassisCapObject.first, chassisCapIntf, |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 786 | chassisSDRDevAddrProp, sdrDeviceAddr); |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 787 | |
| 788 | ipmi::setDbusProperty(bus, chassisCapObject.second, |
| 789 | chassisCapObject.first, chassisCapIntf, |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 790 | chassisSELDevAddrProp, selDeviceAddr); |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 791 | |
| 792 | ipmi::setDbusProperty(bus, chassisCapObject.second, |
| 793 | chassisCapObject.first, chassisCapIntf, |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 794 | chassisSMDevAddrProp, smDeviceAddr); |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 795 | |
| 796 | ipmi::setDbusProperty(bus, chassisCapObject.second, |
| 797 | chassisCapObject.first, chassisCapIntf, |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 798 | chassisBridgeDevAddrProp, bridgeDeviceAddr); |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 799 | } |
Patrick Williams | a2ad2da | 2021-10-06 12:21:46 -0500 | [diff] [blame] | 800 | catch (const std::exception& e) |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 801 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 802 | lg2::error("Failed to set chassis capability properties: {ERR}", "ERR", |
| 803 | e); |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 804 | return ipmi::responseUnspecifiedError(); |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 805 | } |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 806 | return ipmi::responseSuccess(); |
Nan Li | 8d15fb4 | 2016-08-16 22:29:40 +0800 | [diff] [blame] | 807 | } |
| 808 | |
Vishwanatha Subbanna | b12b0c0 | 2017-03-07 18:17:19 +0530 | [diff] [blame] | 809 | //------------------------------------------ |
| 810 | // Calls into Host State Manager Dbus object |
| 811 | //------------------------------------------ |
Jason M. Bills | 664e1c3 | 2020-01-30 16:02:39 -0800 | [diff] [blame] | 812 | int initiateHostStateTransition(ipmi::Context::ptr& ctx, |
| 813 | State::Host::Transition transition) |
vishwa | 3699327 | 2015-11-20 12:43:49 -0600 | [diff] [blame] | 814 | { |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 815 | // OpenBMC Host State Manager dbus framework |
Jason M. Bills | 664e1c3 | 2020-01-30 16:02:39 -0800 | [diff] [blame] | 816 | constexpr auto hostStatePath = "/xyz/openbmc_project/state/host0"; |
| 817 | constexpr auto hostStateIntf = "xyz.openbmc_project.State.Host"; |
Vishwanatha Subbanna | b12b0c0 | 2017-03-07 18:17:19 +0530 | [diff] [blame] | 818 | |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 819 | // Convert to string equivalent of the passed in transition enum. |
Willy Tu | 523e2d1 | 2023-09-05 11:36:48 -0700 | [diff] [blame] | 820 | auto request = |
| 821 | sdbusplus::common::xyz::openbmc_project::state::convertForMessage( |
| 822 | transition); |
Vishwanatha Subbanna | b12b0c0 | 2017-03-07 18:17:19 +0530 | [diff] [blame] | 823 | |
Jason M. Bills | 664e1c3 | 2020-01-30 16:02:39 -0800 | [diff] [blame] | 824 | std::string service; |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 825 | boost::system::error_code ec = |
| 826 | ipmi::getService(ctx, hostStateIntf, hostStatePath, service); |
Jason M. Bills | 664e1c3 | 2020-01-30 16:02:39 -0800 | [diff] [blame] | 827 | |
| 828 | if (!ec) |
| 829 | { |
| 830 | ec = ipmi::setDbusProperty(ctx, service, hostStatePath, hostStateIntf, |
| 831 | "RequestedHostTransition", request); |
| 832 | } |
| 833 | if (ec) |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 834 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 835 | lg2::error( |
| 836 | "Failed to initiate transition for request {REQUEST}: {EXCEPTION}", |
| 837 | "REQUEST", request, "EXCEPTION", ec.message()); |
Jason M. Bills | 664e1c3 | 2020-01-30 16:02:39 -0800 | [diff] [blame] | 838 | return -1; |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 839 | } |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 840 | lg2::info( |
| 841 | "Transition request {REQUEST} initiated successfully by user {USERID}", |
| 842 | "REQUEST", request, "USERID", ctx->userId); |
Jason M. Bills | 664e1c3 | 2020-01-30 16:02:39 -0800 | [diff] [blame] | 843 | return 0; |
vishwa | 3699327 | 2015-11-20 12:43:49 -0600 | [diff] [blame] | 844 | } |
| 845 | |
Kuiying Wang | 6b0ceaa | 2019-11-05 15:13:40 +0800 | [diff] [blame] | 846 | //------------------------------------------ |
Jason M. Bills | ad588bf | 2020-01-30 16:18:33 -0800 | [diff] [blame] | 847 | // Calls into Chassis State Manager Dbus object |
| 848 | //------------------------------------------ |
| 849 | int initiateChassisStateTransition(ipmi::Context::ptr& ctx, |
| 850 | State::Chassis::Transition transition) |
| 851 | { |
| 852 | // OpenBMC Chassis State Manager dbus framework |
| 853 | constexpr auto chassisStatePath = "/xyz/openbmc_project/state/chassis0"; |
| 854 | constexpr auto chassisStateIntf = "xyz.openbmc_project.State.Chassis"; |
| 855 | |
| 856 | std::string service; |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 857 | boost::system::error_code ec = |
| 858 | ipmi::getService(ctx, chassisStateIntf, chassisStatePath, service); |
Jason M. Bills | ad588bf | 2020-01-30 16:18:33 -0800 | [diff] [blame] | 859 | |
| 860 | // Convert to string equivalent of the passed in transition enum. |
Willy Tu | 523e2d1 | 2023-09-05 11:36:48 -0700 | [diff] [blame] | 861 | auto request = |
| 862 | sdbusplus::common::xyz::openbmc_project::state::convertForMessage( |
| 863 | transition); |
Jason M. Bills | ad588bf | 2020-01-30 16:18:33 -0800 | [diff] [blame] | 864 | |
| 865 | if (!ec) |
| 866 | { |
| 867 | ec = ipmi::setDbusProperty(ctx, service, chassisStatePath, |
| 868 | chassisStateIntf, "RequestedPowerTransition", |
| 869 | request); |
| 870 | } |
| 871 | if (ec) |
| 872 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 873 | lg2::error("Failed to initiate transition {REQUEST}: {EXCEPTION}", |
| 874 | "REQUEST", request, "EXCEPTION", ec.message()); |
| 875 | |
Jason M. Bills | ad588bf | 2020-01-30 16:18:33 -0800 | [diff] [blame] | 876 | return -1; |
| 877 | } |
| 878 | |
| 879 | return 0; |
| 880 | } |
| 881 | |
| 882 | //------------------------------------------ |
Zev Weiss | 337a097 | 2024-03-08 08:31:15 +0000 | [diff] [blame] | 883 | // Trigger an NMI on the host via dbus |
Kuiying Wang | 6b0ceaa | 2019-11-05 15:13:40 +0800 | [diff] [blame] | 884 | //------------------------------------------ |
Zev Weiss | 337a097 | 2024-03-08 08:31:15 +0000 | [diff] [blame] | 885 | static int doNmi(ipmi::Context::ptr& ctx) |
Kuiying Wang | 6b0ceaa | 2019-11-05 15:13:40 +0800 | [diff] [blame] | 886 | { |
Zev Weiss | 337a097 | 2024-03-08 08:31:15 +0000 | [diff] [blame] | 887 | constexpr const char* nmiIntfName = "xyz.openbmc_project.Control.Host.NMI"; |
| 888 | ipmi::DbusObjectInfo nmiObj{}; |
| 889 | boost::system::error_code ec; |
Kuiying Wang | 6b0ceaa | 2019-11-05 15:13:40 +0800 | [diff] [blame] | 890 | |
Zev Weiss | 337a097 | 2024-03-08 08:31:15 +0000 | [diff] [blame] | 891 | ec = ipmi::getDbusObject(ctx, nmiIntfName, nmiObj); |
Vernon Mauery | 9bb4a38 | 2021-11-05 12:46:19 -0700 | [diff] [blame] | 892 | if (ec) |
Kuiying Wang | 6b0ceaa | 2019-11-05 15:13:40 +0800 | [diff] [blame] | 893 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 894 | lg2::error("Failed to find NMI service: {ERROR}", "ERROR", |
| 895 | ec.message()); |
Zev Weiss | 337a097 | 2024-03-08 08:31:15 +0000 | [diff] [blame] | 896 | return -1; |
| 897 | } |
| 898 | |
George Liu | de1420d | 2025-03-03 15:14:25 +0800 | [diff] [blame] | 899 | ec = ipmi::callDbusMethod(ctx, nmiObj.second, nmiObj.first, nmiIntfName, |
| 900 | "NMI"); |
Zev Weiss | 337a097 | 2024-03-08 08:31:15 +0000 | [diff] [blame] | 901 | if (ec) |
| 902 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 903 | lg2::error("NMI call failed: {ERROR}", "ERROR", ec.message()); |
Zev Weiss | 337a097 | 2024-03-08 08:31:15 +0000 | [diff] [blame] | 904 | elog<InternalFailure>(); |
Kuiying Wang | 6b0ceaa | 2019-11-05 15:13:40 +0800 | [diff] [blame] | 905 | return -1; |
| 906 | } |
| 907 | |
| 908 | return 0; |
| 909 | } |
| 910 | |
Deepak Kodihalli | 18b70d1 | 2017-07-21 13:36:33 -0500 | [diff] [blame] | 911 | namespace power_policy |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 912 | { |
Nan Li | fdd8ec5 | 2016-08-28 03:57:40 +0800 | [diff] [blame] | 913 | |
Willy Tu | 523e2d1 | 2023-09-05 11:36:48 -0700 | [diff] [blame] | 914 | using namespace sdbusplus::server::xyz::openbmc_project::control::power; |
Deepak Kodihalli | 18b70d1 | 2017-07-21 13:36:33 -0500 | [diff] [blame] | 915 | using IpmiValue = uint8_t; |
| 916 | using DbusValue = RestorePolicy::Policy; |
Nan Li | fdd8ec5 | 2016-08-28 03:57:40 +0800 | [diff] [blame] | 917 | |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 918 | const std::map<DbusValue, IpmiValue> dbusToIpmi = { |
Deepak Kodihalli | 18b70d1 | 2017-07-21 13:36:33 -0500 | [diff] [blame] | 919 | {RestorePolicy::Policy::AlwaysOff, 0x00}, |
| 920 | {RestorePolicy::Policy::Restore, 0x01}, |
George Liu | e561d3e | 2024-02-04 15:19:30 +0800 | [diff] [blame] | 921 | {RestorePolicy::Policy::AlwaysOn, 0x02}, |
| 922 | {RestorePolicy::Policy::None, 0x03}}; |
Nan Li | fdd8ec5 | 2016-08-28 03:57:40 +0800 | [diff] [blame] | 923 | |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 924 | static constexpr uint8_t noChange = 0x03; |
| 925 | static constexpr uint8_t allSupport = 0x01 | 0x02 | 0x04; |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 926 | |
| 927 | /* helper function for Get Chassis Status Command |
| 928 | */ |
| 929 | std::optional<uint2_t> getPowerRestorePolicy() |
| 930 | { |
| 931 | uint2_t restorePolicy = 0; |
| 932 | using namespace chassis::internal; |
| 933 | |
James Feist | 225dec8 | 2019-11-26 16:25:06 -0800 | [diff] [blame] | 934 | settings::Objects& objects = cache::getObjects(); |
| 935 | |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 936 | try |
| 937 | { |
| 938 | const auto& powerRestoreSetting = |
James Feist | 225dec8 | 2019-11-26 16:25:06 -0800 | [diff] [blame] | 939 | objects.map.at(powerRestoreIntf).front(); |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 940 | ipmi::Value result = ipmi::getDbusProperty( |
| 941 | *getSdBus(), |
James Feist | 225dec8 | 2019-11-26 16:25:06 -0800 | [diff] [blame] | 942 | objects.service(powerRestoreSetting, powerRestoreIntf).c_str(), |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 943 | powerRestoreSetting.c_str(), powerRestoreIntf, |
| 944 | "PowerRestorePolicy"); |
| 945 | auto powerRestore = RestorePolicy::convertPolicyFromString( |
| 946 | std::get<std::string>(result)); |
| 947 | restorePolicy = dbusToIpmi.at(powerRestore); |
| 948 | } |
| 949 | catch (const std::exception& e) |
| 950 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 951 | lg2::error( |
| 952 | "Failed to fetch pgood property ({PATH}/{INTERFACE}): {ERROR}", |
| 953 | "PATH", objects.map.at(powerRestoreIntf).front(), "INTERFACE", |
| 954 | powerRestoreIntf, "ERROR", e); |
James Feist | 225dec8 | 2019-11-26 16:25:06 -0800 | [diff] [blame] | 955 | cache::objectsPtr.reset(); |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 956 | return std::nullopt; |
| 957 | } |
| 958 | return std::make_optional(restorePolicy); |
| 959 | } |
| 960 | |
| 961 | /* |
| 962 | * getPowerStatus |
| 963 | * helper function for Get Chassis Status Command |
| 964 | * return - optional value for pgood (no value on error) |
| 965 | */ |
| 966 | std::optional<bool> getPowerStatus() |
| 967 | { |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 968 | bool powerGood = false; |
| 969 | std::shared_ptr<sdbusplus::asio::connection> busp = getSdBus(); |
| 970 | try |
| 971 | { |
Jason M. Bills | 3de424c | 2019-05-21 09:57:16 -0700 | [diff] [blame] | 972 | constexpr const char* chassisStatePath = |
| 973 | "/xyz/openbmc_project/state/chassis0"; |
| 974 | constexpr const char* chassisStateIntf = |
| 975 | "xyz.openbmc_project.State.Chassis"; |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 976 | auto service = |
| 977 | ipmi::getService(*busp, chassisStateIntf, chassisStatePath); |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 978 | |
Jason M. Bills | 3de424c | 2019-05-21 09:57:16 -0700 | [diff] [blame] | 979 | ipmi::Value powerState = |
| 980 | ipmi::getDbusProperty(*busp, service, chassisStatePath, |
| 981 | chassisStateIntf, "CurrentPowerState"); |
Chau Ly | ee3983b | 2024-01-05 07:33:45 +0000 | [diff] [blame] | 982 | std::string powerStateStr = std::get<std::string>(powerState); |
| 983 | if (powerStateStr.ends_with(".On") || |
| 984 | powerStateStr.ends_with(".TransitioningToOff")) |
| 985 | { |
| 986 | powerGood = true; |
| 987 | } |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 988 | } |
| 989 | catch (const std::exception& e) |
| 990 | { |
| 991 | try |
| 992 | { |
| 993 | // FIXME: some legacy modules use the older path; try that next |
| 994 | constexpr const char* legacyPwrCtrlObj = |
| 995 | "/org/openbmc/control/power0"; |
| 996 | constexpr const char* legacyPwrCtrlIntf = |
| 997 | "org.openbmc.control.Power"; |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 998 | auto service = |
| 999 | ipmi::getService(*busp, legacyPwrCtrlIntf, legacyPwrCtrlObj); |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1000 | |
| 1001 | ipmi::Value variant = ipmi::getDbusProperty( |
| 1002 | *busp, service, legacyPwrCtrlObj, legacyPwrCtrlIntf, "pgood"); |
| 1003 | powerGood = static_cast<bool>(std::get<int>(variant)); |
| 1004 | } |
| 1005 | catch (const std::exception& e) |
| 1006 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 1007 | lg2::error("Failed to fetch pgood property: {ERROR}", "ERROR", e); |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1008 | return std::nullopt; |
| 1009 | } |
| 1010 | } |
| 1011 | return std::make_optional(powerGood); |
| 1012 | } |
| 1013 | |
Yong Li | 70ce735 | 2019-05-16 21:15:27 +0800 | [diff] [blame] | 1014 | /* |
| 1015 | * getACFailStatus |
| 1016 | * helper function for Get Chassis Status Command |
| 1017 | * return - bool value for ACFail (false on error) |
| 1018 | */ |
| 1019 | bool getACFailStatus() |
| 1020 | { |
| 1021 | constexpr const char* powerControlObj = |
| 1022 | "/xyz/openbmc_project/Chassis/Control/Power0"; |
| 1023 | constexpr const char* powerControlIntf = |
| 1024 | "xyz.openbmc_project.Chassis.Control.Power"; |
| 1025 | bool acFail = false; |
| 1026 | std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus(); |
| 1027 | try |
| 1028 | { |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 1029 | auto service = |
| 1030 | ipmi::getService(*bus, powerControlIntf, powerControlObj); |
Yong Li | 70ce735 | 2019-05-16 21:15:27 +0800 | [diff] [blame] | 1031 | |
| 1032 | ipmi::Value variant = ipmi::getDbusProperty( |
| 1033 | *bus, service, powerControlObj, powerControlIntf, "PFail"); |
| 1034 | acFail = std::get<bool>(variant); |
| 1035 | } |
| 1036 | catch (const std::exception& e) |
| 1037 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 1038 | lg2::error( |
Konstantin Aladyshev | 37de2e1 | 2025-01-29 11:49:26 +0300 | [diff] [blame] | 1039 | "Failed to fetch PFail property ({PATH}/{INTERFACE}): {ERROR}", |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 1040 | "PATH", powerControlObj, "INTERFACE", powerControlIntf, "ERROR", e); |
Yong Li | 70ce735 | 2019-05-16 21:15:27 +0800 | [diff] [blame] | 1041 | } |
| 1042 | return acFail; |
| 1043 | } |
Deepak Kodihalli | 18b70d1 | 2017-07-21 13:36:33 -0500 | [diff] [blame] | 1044 | } // namespace power_policy |
Nan Li | fdd8ec5 | 2016-08-28 03:57:40 +0800 | [diff] [blame] | 1045 | |
Patrick Williams | 615a14e | 2025-04-07 17:07:24 -0400 | [diff] [blame] | 1046 | static std::optional<bool> getButtonDisabled(ipmi::Context::ptr& ctx, |
| 1047 | const std::string& buttonPath, |
| 1048 | const std::string& buttonIntf) |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1049 | { |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1050 | bool buttonDisabled = false; |
Konstantin Aladyshev | 2738b9e | 2025-02-15 00:56:19 +0300 | [diff] [blame] | 1051 | boost::system::error_code ec; |
| 1052 | std::string service; |
| 1053 | ec = ipmi::getService(ctx, buttonIntf, buttonPath, service); |
| 1054 | if (!ec) |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1055 | { |
Konstantin Aladyshev | 2738b9e | 2025-02-15 00:56:19 +0300 | [diff] [blame] | 1056 | bool enabled; |
| 1057 | ec = ipmi::getDbusProperty(ctx, service, buttonPath, buttonIntf, |
| 1058 | "Enabled", enabled); |
| 1059 | buttonDisabled = !enabled; |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1060 | } |
Konstantin Aladyshev | 2738b9e | 2025-02-15 00:56:19 +0300 | [diff] [blame] | 1061 | |
| 1062 | if (ec) |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1063 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 1064 | lg2::error("Fail to get button Enabled property ({PATH}): {ERROR}", |
Konstantin Aladyshev | 2738b9e | 2025-02-15 00:56:19 +0300 | [diff] [blame] | 1065 | "PATH", buttonPath, "ERROR", ec.message()); |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1066 | return std::nullopt; |
| 1067 | } |
| 1068 | return std::make_optional(buttonDisabled); |
| 1069 | } |
| 1070 | |
Konstantin Aladyshev | 305d864 | 2025-02-15 00:36:54 +0300 | [diff] [blame] | 1071 | static bool setButtonDisabled(ipmi::Context::ptr& ctx, |
| 1072 | const std::string& buttonPath, |
| 1073 | const std::string& buttonIntf, bool disable) |
Kuiying Wang | 21addc5 | 2019-01-04 10:50:21 +0800 | [diff] [blame] | 1074 | { |
| 1075 | std::string service; |
| 1076 | boost::system::error_code ec; |
| 1077 | ec = ipmi::getService(ctx, buttonIntf, buttonPath, service); |
| 1078 | if (!ec) |
| 1079 | { |
| 1080 | ec = ipmi::setDbusProperty(ctx, service, buttonPath, buttonIntf, |
Konstantin Aladyshev | 305d864 | 2025-02-15 00:36:54 +0300 | [diff] [blame] | 1081 | "Enabled", !disable); |
Kuiying Wang | 21addc5 | 2019-01-04 10:50:21 +0800 | [diff] [blame] | 1082 | } |
| 1083 | if (ec) |
| 1084 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 1085 | lg2::error( |
| 1086 | "Fail to set button Enabled property ({SERVICE}:{PATH}): {ERROR}", |
| 1087 | "SERVICE", service, "PATH", buttonPath, "ERROR", ec.message()); |
Kuiying Wang | 21addc5 | 2019-01-04 10:50:21 +0800 | [diff] [blame] | 1088 | return false; |
| 1089 | } |
| 1090 | return true; |
| 1091 | } |
| 1092 | |
Chau Ly | 9e666cd | 2023-03-06 08:46:14 +0000 | [diff] [blame] | 1093 | static std::optional<bool> getChassisIntrusionStatus(ipmi::Context::ptr& ctx) |
| 1094 | { |
Chau Ly | 8c1376c | 2024-01-05 07:22:10 +0000 | [diff] [blame] | 1095 | std::vector<std::string> interfaces = {std::string(Intrusion::interface)}; |
| 1096 | ipmi::ObjectTree objs; |
| 1097 | std::string propVal; |
| 1098 | std::optional<bool> ret = std::nullopt; |
Chau Ly | 9e666cd | 2023-03-06 08:46:14 +0000 | [diff] [blame] | 1099 | |
Chau Ly | 8c1376c | 2024-01-05 07:22:10 +0000 | [diff] [blame] | 1100 | boost::system::error_code ec = |
| 1101 | ipmi::getSubTree(ctx, interfaces, std::string("/"), 0, objs); |
| 1102 | |
| 1103 | if (ec) |
Chau Ly | 9e666cd | 2023-03-06 08:46:14 +0000 | [diff] [blame] | 1104 | { |
Chau Ly | 8c1376c | 2024-01-05 07:22:10 +0000 | [diff] [blame] | 1105 | lg2::error("Fail to find Chassis Intrusion Interface on D-Bus " |
| 1106 | "({INTERFACE}): {ERROR}", |
| 1107 | "INTERFACE", Intrusion::interface, "ERROR", ec.message()); |
| 1108 | return ret; |
| 1109 | } |
| 1110 | |
| 1111 | for (const auto& [path, map] : objs) |
| 1112 | { |
| 1113 | for (const auto& [service, intfs] : map) |
Chau Ly | 9e666cd | 2023-03-06 08:46:14 +0000 | [diff] [blame] | 1114 | { |
Chau Ly | 8c1376c | 2024-01-05 07:22:10 +0000 | [diff] [blame] | 1115 | ec = ipmi::getDbusProperty<std::string>( |
| 1116 | ctx, service, path, Intrusion::interface, "Status", propVal); |
Jayanth Othayoth | 195d552 | 2025-06-07 02:28:07 -0500 | [diff] [blame] | 1117 | |
Chau Ly | 8c1376c | 2024-01-05 07:22:10 +0000 | [diff] [blame] | 1118 | if (ec) |
| 1119 | { |
Jayanth Othayoth | 195d552 | 2025-06-07 02:28:07 -0500 | [diff] [blame] | 1120 | lg2::error("Failed to get Chassis Intrusion Status property " |
Chau Ly | 8c1376c | 2024-01-05 07:22:10 +0000 | [diff] [blame] | 1121 | "({SERVICE}/{PATH}/{INTERFACE}): {ERROR}", |
| 1122 | "SERVICE", service, "PATH", path, "INTERFACE", |
| 1123 | Intrusion::interface, "ERROR", ec.message()); |
Jayanth Othayoth | 195d552 | 2025-06-07 02:28:07 -0500 | [diff] [blame] | 1124 | continue; |
Chau Ly | 8c1376c | 2024-01-05 07:22:10 +0000 | [diff] [blame] | 1125 | } |
Jayanth Othayoth | 195d552 | 2025-06-07 02:28:07 -0500 | [diff] [blame] | 1126 | |
| 1127 | auto statusOpt = |
| 1128 | sdbusplus::message::convert_from_string<Intrusion::Status>( |
| 1129 | propVal); |
| 1130 | if (statusOpt) |
Chau Ly | 8c1376c | 2024-01-05 07:22:10 +0000 | [diff] [blame] | 1131 | { |
Jayanth Othayoth | 195d552 | 2025-06-07 02:28:07 -0500 | [diff] [blame] | 1132 | if (*statusOpt == Intrusion::Status::Normal) |
Chau Ly | 8c1376c | 2024-01-05 07:22:10 +0000 | [diff] [blame] | 1133 | { |
| 1134 | ret = std::make_optional(false); |
| 1135 | } |
| 1136 | else |
| 1137 | { |
| 1138 | ret = std::make_optional(true); |
Jayanth Othayoth | 195d552 | 2025-06-07 02:28:07 -0500 | [diff] [blame] | 1139 | return ret; // Early return on first non-Normal status |
Chau Ly | 8c1376c | 2024-01-05 07:22:10 +0000 | [diff] [blame] | 1140 | } |
| 1141 | } |
Jayanth Othayoth | 195d552 | 2025-06-07 02:28:07 -0500 | [diff] [blame] | 1142 | else |
| 1143 | { |
| 1144 | lg2::warning( |
| 1145 | "Invalid Intrusion::Status value received: {VALUE}", |
| 1146 | "VALUE", propVal); |
| 1147 | return std::nullopt; |
| 1148 | } |
Chau Ly | 9e666cd | 2023-03-06 08:46:14 +0000 | [diff] [blame] | 1149 | } |
| 1150 | } |
Chau Ly | 8c1376c | 2024-01-05 07:22:10 +0000 | [diff] [blame] | 1151 | return ret; |
Chau Ly | 9e666cd | 2023-03-06 08:46:14 +0000 | [diff] [blame] | 1152 | } |
| 1153 | |
Nan Li | fdd8ec5 | 2016-08-28 03:57:40 +0800 | [diff] [blame] | 1154 | //---------------------------------------------------------------------- |
| 1155 | // Get Chassis Status commands |
| 1156 | //---------------------------------------------------------------------- |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1157 | ipmi::RspType<bool, // Power is on |
| 1158 | bool, // Power overload |
| 1159 | bool, // Interlock |
| 1160 | bool, // power fault |
| 1161 | bool, // power control fault |
| 1162 | uint2_t, // power restore policy |
| 1163 | bool, // reserved |
| 1164 | |
Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 1165 | bool, // AC failed |
| 1166 | bool, // last power down caused by a Power overload |
| 1167 | bool, // last power down caused by a power interlock |
| 1168 | bool, // last power down caused by power fault |
Patrick Williams | 99db688 | 2024-12-18 11:20:17 -0500 | [diff] [blame] | 1169 | bool, // last ‘Power is on’ state was entered via IPMI command |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1170 | uint3_t, // reserved |
| 1171 | |
| 1172 | bool, // Chassis intrusion active |
| 1173 | bool, // Front Panel Lockout active |
| 1174 | bool, // Drive Fault |
| 1175 | bool, // Cooling/fan fault detected |
| 1176 | uint2_t, // Chassis Identify State |
| 1177 | bool, // Chassis Identify command and state info supported |
| 1178 | bool, // reserved |
| 1179 | |
Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 1180 | bool, // Power off button disabled |
| 1181 | bool, // Reset button disabled |
| 1182 | bool, // Diagnostic Interrupt button disabled |
| 1183 | bool, // Standby (sleep) button disabled |
| 1184 | bool, // Power off button disable allowed |
| 1185 | bool, // Reset button disable allowed |
| 1186 | bool, // Diagnostic Interrupt button disable allowed |
| 1187 | bool // Standby (sleep) button disable allowed |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1188 | > |
Chau Ly | 9e666cd | 2023-03-06 08:46:14 +0000 | [diff] [blame] | 1189 | ipmiGetChassisStatus(ipmi::Context::ptr& ctx) |
Nan Li | fdd8ec5 | 2016-08-28 03:57:40 +0800 | [diff] [blame] | 1190 | { |
Deepak Kodihalli | 18b70d1 | 2017-07-21 13:36:33 -0500 | [diff] [blame] | 1191 | using namespace chassis::internal; |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1192 | std::optional<uint2_t> restorePolicy = |
| 1193 | power_policy::getPowerRestorePolicy(); |
| 1194 | std::optional<bool> powerGood = power_policy::getPowerStatus(); |
| 1195 | if (!restorePolicy || !powerGood) |
Deepak Kodihalli | 18b70d1 | 2017-07-21 13:36:33 -0500 | [diff] [blame] | 1196 | { |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1197 | return ipmi::responseUnspecifiedError(); |
Deepak Kodihalli | 18b70d1 | 2017-07-21 13:36:33 -0500 | [diff] [blame] | 1198 | } |
Nan Li | fdd8ec5 | 2016-08-28 03:57:40 +0800 | [diff] [blame] | 1199 | |
| 1200 | // Front Panel Button Capabilities and disable/enable status(Optional) |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 1201 | std::optional<bool> powerButtonReading = |
Konstantin Aladyshev | 2738b9e | 2025-02-15 00:56:19 +0300 | [diff] [blame] | 1202 | getButtonDisabled(ctx, powerButtonPath, powerButtonIntf); |
Vernon Mauery | 6d5b2f7 | 2019-05-16 14:48:47 -0700 | [diff] [blame] | 1203 | // allow disable if the interface is present |
| 1204 | bool powerButtonDisableAllow = static_cast<bool>(powerButtonReading); |
| 1205 | // default return the button is enabled (not disabled) |
| 1206 | bool powerButtonDisabled = false; |
| 1207 | if (powerButtonDisableAllow) |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1208 | { |
Vernon Mauery | 6d5b2f7 | 2019-05-16 14:48:47 -0700 | [diff] [blame] | 1209 | // return the real value of the button status, if present |
| 1210 | powerButtonDisabled = *powerButtonReading; |
| 1211 | } |
| 1212 | |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 1213 | std::optional<bool> resetButtonReading = |
Konstantin Aladyshev | 2738b9e | 2025-02-15 00:56:19 +0300 | [diff] [blame] | 1214 | getButtonDisabled(ctx, resetButtonPath, resetButtonIntf); |
Vernon Mauery | 6d5b2f7 | 2019-05-16 14:48:47 -0700 | [diff] [blame] | 1215 | // allow disable if the interface is present |
| 1216 | bool resetButtonDisableAllow = static_cast<bool>(resetButtonReading); |
| 1217 | // default return the button is enabled (not disabled) |
| 1218 | bool resetButtonDisabled = false; |
| 1219 | if (resetButtonDisableAllow) |
| 1220 | { |
| 1221 | // return the real value of the button status, if present |
| 1222 | resetButtonDisabled = *resetButtonReading; |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1223 | } |
Nan Li | fdd8ec5 | 2016-08-28 03:57:40 +0800 | [diff] [blame] | 1224 | |
Yong Li | 70ce735 | 2019-05-16 21:15:27 +0800 | [diff] [blame] | 1225 | bool powerDownAcFailed = power_policy::getACFailStatus(); |
| 1226 | |
Chau Ly | 9e666cd | 2023-03-06 08:46:14 +0000 | [diff] [blame] | 1227 | bool chassisIntrusionActive = false; |
| 1228 | std::optional<bool> chassisIntrusionStatus = getChassisIntrusionStatus(ctx); |
| 1229 | if (chassisIntrusionStatus) |
| 1230 | { |
| 1231 | chassisIntrusionActive = chassisIntrusionStatus.value(); |
| 1232 | } |
| 1233 | |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1234 | // This response has a lot of hard-coded, unsupported fields |
| 1235 | // They are set to false or 0 |
| 1236 | constexpr bool powerOverload = false; |
| 1237 | constexpr bool chassisInterlock = false; |
| 1238 | constexpr bool powerFault = false; |
| 1239 | constexpr bool powerControlFault = false; |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1240 | constexpr bool powerDownOverload = false; |
| 1241 | constexpr bool powerDownInterlock = false; |
| 1242 | constexpr bool powerDownPowerFault = false; |
| 1243 | constexpr bool powerStatusIPMI = false; |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1244 | constexpr bool frontPanelLockoutActive = false; |
| 1245 | constexpr bool driveFault = false; |
| 1246 | constexpr bool coolingFanFault = false; |
| 1247 | // chassisIdentifySupport set because this command is implemented |
| 1248 | constexpr bool chassisIdentifySupport = true; |
William A. Kennington III | 7a0e5df | 2021-05-19 13:31:29 -0700 | [diff] [blame] | 1249 | uint2_t chassisIdentifyState = types::enum_cast<uint2_t>(chassisIDState); |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1250 | constexpr bool diagButtonDisabled = false; |
| 1251 | constexpr bool sleepButtonDisabled = false; |
| 1252 | constexpr bool diagButtonDisableAllow = false; |
| 1253 | constexpr bool sleepButtonDisableAllow = false; |
| 1254 | |
| 1255 | return ipmi::responseSuccess( |
| 1256 | *powerGood, powerOverload, chassisInterlock, powerFault, |
| 1257 | powerControlFault, *restorePolicy, |
| 1258 | false, // reserved |
| 1259 | |
| 1260 | powerDownAcFailed, powerDownOverload, powerDownInterlock, |
| 1261 | powerDownPowerFault, powerStatusIPMI, |
| 1262 | uint3_t(0), // reserved |
| 1263 | |
| 1264 | chassisIntrusionActive, frontPanelLockoutActive, driveFault, |
| 1265 | coolingFanFault, chassisIdentifyState, chassisIdentifySupport, |
| 1266 | false, // reserved |
| 1267 | |
Vernon Mauery | 6d5b2f7 | 2019-05-16 14:48:47 -0700 | [diff] [blame] | 1268 | powerButtonDisabled, resetButtonDisabled, diagButtonDisabled, |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1269 | sleepButtonDisabled, powerButtonDisableAllow, resetButtonDisableAllow, |
| 1270 | diagButtonDisableAllow, sleepButtonDisableAllow); |
Nan Li | fdd8ec5 | 2016-08-28 03:57:40 +0800 | [diff] [blame] | 1271 | } |
Chris Austen | 7888c4d | 2015-12-03 15:26:20 -0600 | [diff] [blame] | 1272 | |
Vijay Khemka | 074f64d | 2020-03-03 15:08:43 -0800 | [diff] [blame] | 1273 | enum class IpmiRestartCause |
| 1274 | { |
| 1275 | Unknown = 0x0, |
| 1276 | RemoteCommand = 0x1, |
| 1277 | ResetButton = 0x2, |
| 1278 | PowerButton = 0x3, |
| 1279 | WatchdogTimer = 0x4, |
| 1280 | PowerPolicyAlwaysOn = 0x6, |
| 1281 | PowerPolicyPreviousState = 0x7, |
| 1282 | SoftReset = 0xa, |
| 1283 | }; |
| 1284 | |
Patrick Williams | 69b4c28 | 2025-03-03 11:19:13 -0500 | [diff] [blame] | 1285 | static IpmiRestartCause restartCauseToIpmiRestartCause( |
| 1286 | State::Host::RestartCause cause) |
Vijay Khemka | 074f64d | 2020-03-03 15:08:43 -0800 | [diff] [blame] | 1287 | { |
| 1288 | switch (cause) |
| 1289 | { |
| 1290 | case State::Host::RestartCause::Unknown: |
| 1291 | { |
| 1292 | return IpmiRestartCause::Unknown; |
| 1293 | } |
| 1294 | case State::Host::RestartCause::RemoteCommand: |
| 1295 | { |
| 1296 | return IpmiRestartCause::RemoteCommand; |
| 1297 | } |
| 1298 | case State::Host::RestartCause::ResetButton: |
| 1299 | { |
| 1300 | return IpmiRestartCause::ResetButton; |
| 1301 | } |
| 1302 | case State::Host::RestartCause::PowerButton: |
| 1303 | { |
| 1304 | return IpmiRestartCause::PowerButton; |
| 1305 | } |
| 1306 | case State::Host::RestartCause::WatchdogTimer: |
| 1307 | { |
| 1308 | return IpmiRestartCause::WatchdogTimer; |
| 1309 | } |
| 1310 | case State::Host::RestartCause::PowerPolicyAlwaysOn: |
| 1311 | { |
| 1312 | return IpmiRestartCause::PowerPolicyAlwaysOn; |
| 1313 | } |
| 1314 | case State::Host::RestartCause::PowerPolicyPreviousState: |
| 1315 | { |
| 1316 | return IpmiRestartCause::PowerPolicyPreviousState; |
| 1317 | } |
| 1318 | case State::Host::RestartCause::SoftReset: |
| 1319 | { |
| 1320 | return IpmiRestartCause::SoftReset; |
| 1321 | } |
| 1322 | default: |
| 1323 | { |
| 1324 | return IpmiRestartCause::Unknown; |
| 1325 | } |
| 1326 | } |
| 1327 | } |
| 1328 | |
| 1329 | /* |
| 1330 | * getRestartCause |
| 1331 | * helper function for Get Host restart cause Command |
| 1332 | * return - optional value for RestartCause (no value on error) |
| 1333 | */ |
| 1334 | static std::optional<uint4_t> getRestartCause(ipmi::Context::ptr ctx) |
| 1335 | { |
okashany | ced0ddf | 2023-05-18 18:35:09 +0000 | [diff] [blame] | 1336 | constexpr const char* restartCausePath = "/xyz/openbmc_project/state/host0"; |
| 1337 | constexpr const char* restartCauseIntf = "xyz.openbmc_project.State.Host"; |
Vijay Khemka | 074f64d | 2020-03-03 15:08:43 -0800 | [diff] [blame] | 1338 | |
| 1339 | std::string service; |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 1340 | boost::system::error_code ec = |
| 1341 | ipmi::getService(ctx, restartCauseIntf, restartCausePath, service); |
Vijay Khemka | 074f64d | 2020-03-03 15:08:43 -0800 | [diff] [blame] | 1342 | if (!ec) |
| 1343 | { |
| 1344 | std::string restartCauseStr; |
| 1345 | ec = ipmi::getDbusProperty<std::string>( |
| 1346 | ctx, service, restartCausePath, restartCauseIntf, "RestartCause", |
| 1347 | restartCauseStr); |
| 1348 | if (!ec) |
| 1349 | { |
| 1350 | auto cause = |
| 1351 | State::Host::convertRestartCauseFromString(restartCauseStr); |
William A. Kennington III | 7a0e5df | 2021-05-19 13:31:29 -0700 | [diff] [blame] | 1352 | return types::enum_cast<uint4_t>( |
| 1353 | restartCauseToIpmiRestartCause(cause)); |
Vijay Khemka | 074f64d | 2020-03-03 15:08:43 -0800 | [diff] [blame] | 1354 | } |
| 1355 | } |
| 1356 | |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 1357 | lg2::error( |
| 1358 | "Failed to fetch RestartCause property ({PATH}/{INTERFACE}): {ERROR}", |
| 1359 | "ERROR", ec.message(), "PATH", restartCausePath, "INTERFACE", |
| 1360 | restartCauseIntf); |
Vijay Khemka | 074f64d | 2020-03-03 15:08:43 -0800 | [diff] [blame] | 1361 | return std::nullopt; |
| 1362 | } |
| 1363 | |
| 1364 | ipmi::RspType<uint4_t, // Restart Cause |
| 1365 | uint4_t, // reserved |
| 1366 | uint8_t // channel number (not supported) |
| 1367 | > |
| 1368 | ipmiGetSystemRestartCause(ipmi::Context::ptr ctx) |
| 1369 | { |
| 1370 | std::optional<uint4_t> cause = getRestartCause(ctx); |
| 1371 | if (!cause) |
| 1372 | { |
| 1373 | return ipmi::responseUnspecifiedError(); |
| 1374 | } |
| 1375 | |
Vernon Mauery | 916d423 | 2021-03-29 13:42:16 -0700 | [diff] [blame] | 1376 | constexpr uint4_t reserved = 0; |
| 1377 | auto channel = static_cast<uint8_t>(ctx->channel); |
| 1378 | return ipmi::responseSuccess(cause.value(), reserved, channel); |
Vijay Khemka | 074f64d | 2020-03-03 15:08:43 -0800 | [diff] [blame] | 1379 | } |
anil kumar appana | dafff5f | 2019-04-27 18:06:00 +0000 | [diff] [blame] | 1380 | /** @brief Implementation of chassis control command |
| 1381 | * |
| 1382 | * @param - chassisControl command byte |
| 1383 | * |
| 1384 | * @return Success or InvalidFieldRequest. |
| 1385 | */ |
Jason M. Bills | 664e1c3 | 2020-01-30 16:02:39 -0800 | [diff] [blame] | 1386 | ipmi::RspType<> ipmiChassisControl(ipmi::Context::ptr& ctx, |
| 1387 | uint8_t chassisControl) |
vishwa | 3699327 | 2015-11-20 12:43:49 -0600 | [diff] [blame] | 1388 | { |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 1389 | int rc = 0; |
anil kumar appana | dafff5f | 2019-04-27 18:06:00 +0000 | [diff] [blame] | 1390 | switch (chassisControl) |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 1391 | { |
George Liu | 8f4717c | 2025-07-03 09:22:34 +0800 | [diff] [blame] | 1392 | case cmdPowerOn: |
Jason M. Bills | 664e1c3 | 2020-01-30 16:02:39 -0800 | [diff] [blame] | 1393 | rc = initiateHostStateTransition(ctx, State::Host::Transition::On); |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 1394 | break; |
George Liu | 8f4717c | 2025-07-03 09:22:34 +0800 | [diff] [blame] | 1395 | case cmdPowerOff: |
Jason M. Bills | c2c3a40 | 2020-01-30 16:22:24 -0800 | [diff] [blame] | 1396 | rc = initiateChassisStateTransition( |
| 1397 | ctx, State::Chassis::Transition::Off); |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 1398 | break; |
George Liu | 8f4717c | 2025-07-03 09:22:34 +0800 | [diff] [blame] | 1399 | case cmdHardReset: |
Jason M. Bills | 664e1c3 | 2020-01-30 16:02:39 -0800 | [diff] [blame] | 1400 | rc = initiateHostStateTransition( |
| 1401 | ctx, State::Host::Transition::ForceWarmReboot); |
Chanh Nguyen | d0a7fcd | 2021-07-16 22:59:28 +0700 | [diff] [blame] | 1402 | break; |
George Liu | 8f4717c | 2025-07-03 09:22:34 +0800 | [diff] [blame] | 1403 | case cmdPowerCycle: |
Jason M. Bills | 664e1c3 | 2020-01-30 16:02:39 -0800 | [diff] [blame] | 1404 | rc = initiateHostStateTransition(ctx, |
| 1405 | State::Host::Transition::Reboot); |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 1406 | break; |
George Liu | 8f4717c | 2025-07-03 09:22:34 +0800 | [diff] [blame] | 1407 | case cmdSoftOffViaOverTemp: |
Jason M. Bills | 664e1c3 | 2020-01-30 16:02:39 -0800 | [diff] [blame] | 1408 | rc = initiateHostStateTransition(ctx, State::Host::Transition::Off); |
Vishwanatha Subbanna | 8b26d35 | 2017-08-04 18:35:18 +0530 | [diff] [blame] | 1409 | break; |
George Liu | 8f4717c | 2025-07-03 09:22:34 +0800 | [diff] [blame] | 1410 | case cmdPulseDiagnosticInterrupt: |
Zev Weiss | 337a097 | 2024-03-08 08:31:15 +0000 | [diff] [blame] | 1411 | rc = doNmi(ctx); |
Kuiying Wang | 6b0ceaa | 2019-11-05 15:13:40 +0800 | [diff] [blame] | 1412 | break; |
| 1413 | |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 1414 | default: |
| 1415 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 1416 | lg2::error("Invalid Chassis Control command: {CMD}", "CMD", |
| 1417 | lg2::hex, chassisControl); |
anil kumar appana | dafff5f | 2019-04-27 18:06:00 +0000 | [diff] [blame] | 1418 | return ipmi::responseInvalidFieldRequest(); |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 1419 | } |
| 1420 | } |
vishwa | 3699327 | 2015-11-20 12:43:49 -0600 | [diff] [blame] | 1421 | |
anil kumar appana | dafff5f | 2019-04-27 18:06:00 +0000 | [diff] [blame] | 1422 | return ((rc < 0) ? ipmi::responseUnspecifiedError() |
| 1423 | : ipmi::responseSuccess()); |
vishwa | 3699327 | 2015-11-20 12:43:49 -0600 | [diff] [blame] | 1424 | } |
| 1425 | |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1426 | /** @brief Return D-Bus connection string to enclosure identify LED object |
| 1427 | * |
| 1428 | * @param[in, out] connection - connection to D-Bus object |
| 1429 | * @return a IPMI return code |
| 1430 | */ |
| 1431 | std::string getEnclosureIdentifyConnection() |
Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 1432 | { |
Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 1433 | // lookup enclosure_identify group owner(s) in mapper |
George Liu | 3e3cc35 | 2023-07-26 15:59:31 +0800 | [diff] [blame] | 1434 | try |
Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 1435 | { |
George Liu | 3e3cc35 | 2023-07-26 15:59:31 +0800 | [diff] [blame] | 1436 | return ipmi::getService(*getSdBus(), "xyz.openbmc_project.Led.Group", |
| 1437 | identify_led_object_name); |
| 1438 | } |
| 1439 | catch (const std::exception& e) |
| 1440 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 1441 | lg2::error("Chassis Identify: Error communicating to mapper: {ERROR}", |
| 1442 | "ERROR", e); |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1443 | elog<InternalFailure>(); |
Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 1444 | } |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1445 | } |
Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 1446 | |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1447 | /** @brief Turn On/Off enclosure identify LED |
| 1448 | * |
| 1449 | * @param[in] flag - true to turn on LED, false to turn off |
| 1450 | * @return a IPMI return code |
| 1451 | */ |
| 1452 | void enclosureIdentifyLed(bool flag) |
| 1453 | { |
| 1454 | using namespace chassis::internal; |
George Liu | 3e3cc35 | 2023-07-26 15:59:31 +0800 | [diff] [blame] | 1455 | try |
| 1456 | { |
| 1457 | std::string connection = getEnclosureIdentifyConnection(); |
| 1458 | |
| 1459 | auto msg = std::string("enclosureIdentifyLed(") + |
| 1460 | boost::lexical_cast<std::string>(flag) + ")"; |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 1461 | lg2::debug(msg.c_str()); |
George Liu | 3e3cc35 | 2023-07-26 15:59:31 +0800 | [diff] [blame] | 1462 | |
| 1463 | ipmi::setDbusProperty(*getSdBus(), connection, identify_led_object_name, |
| 1464 | "xyz.openbmc_project.Led.Group", "Asserted", |
| 1465 | flag); |
| 1466 | } |
| 1467 | catch (const std::exception& e) |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1468 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 1469 | lg2::error("Chassis Identify: Error Setting State {LED_STATE}: {ERROR}", |
| 1470 | "LED_STATE", flag, "ERROR", e); |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1471 | elog<InternalFailure>(); |
| 1472 | } |
| 1473 | } |
| 1474 | |
| 1475 | /** @brief Callback method to turn off LED |
| 1476 | */ |
| 1477 | void enclosureIdentifyLedOff() |
| 1478 | { |
| 1479 | try |
| 1480 | { |
Yong Li | f4e3851 | 2019-05-21 14:46:55 +0800 | [diff] [blame] | 1481 | chassisIDState = ChassisIDState::off; |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1482 | enclosureIdentifyLed(false); |
| 1483 | } |
| 1484 | catch (const InternalFailure& e) |
| 1485 | { |
| 1486 | report<InternalFailure>(); |
| 1487 | } |
| 1488 | } |
| 1489 | |
| 1490 | /** @brief Create timer to turn on and off the enclosure LED |
| 1491 | */ |
| 1492 | void createIdentifyTimer() |
| 1493 | { |
| 1494 | if (!identifyTimer) |
| 1495 | { |
Vernon Mauery | 1181af7 | 2018-10-08 12:05:00 -0700 | [diff] [blame] | 1496 | identifyTimer = |
Patrick Williams | 9565522 | 2023-12-05 12:45:02 -0600 | [diff] [blame] | 1497 | std::make_unique<sdbusplus::Timer>(enclosureIdentifyLedOff); |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1498 | } |
| 1499 | } |
| 1500 | |
Vernon Mauery | 400cc78 | 2018-10-09 13:49:53 -0700 | [diff] [blame] | 1501 | ipmi::RspType<> ipmiChassisIdentify(std::optional<uint8_t> interval, |
| 1502 | std::optional<uint8_t> force) |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1503 | { |
Vernon Mauery | 400cc78 | 2018-10-09 13:49:53 -0700 | [diff] [blame] | 1504 | uint8_t identifyInterval = interval.value_or(DEFAULT_IDENTIFY_TIME_OUT); |
| 1505 | bool forceIdentify = force.value_or(0) & 0x01; |
Tom Joseph | bed2699 | 2018-07-31 23:00:24 +0530 | [diff] [blame] | 1506 | |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1507 | if (identifyInterval || forceIdentify) |
| 1508 | { |
Vernon Mauery | 400cc78 | 2018-10-09 13:49:53 -0700 | [diff] [blame] | 1509 | // stop the timer if already started; |
| 1510 | // for force identify we should not turn off LED |
Vernon Mauery | 1181af7 | 2018-10-08 12:05:00 -0700 | [diff] [blame] | 1511 | identifyTimer->stop(); |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1512 | try |
Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 1513 | { |
Yong Li | f4e3851 | 2019-05-21 14:46:55 +0800 | [diff] [blame] | 1514 | chassisIDState = ChassisIDState::temporaryOn; |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1515 | enclosureIdentifyLed(true); |
| 1516 | } |
| 1517 | catch (const InternalFailure& e) |
| 1518 | { |
| 1519 | report<InternalFailure>(); |
Vernon Mauery | 400cc78 | 2018-10-09 13:49:53 -0700 | [diff] [blame] | 1520 | return ipmi::responseResponseError(); |
Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 1521 | } |
| 1522 | |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1523 | if (forceIdentify) |
Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 1524 | { |
Yong Li | f4e3851 | 2019-05-21 14:46:55 +0800 | [diff] [blame] | 1525 | chassisIDState = ChassisIDState::indefiniteOn; |
Vernon Mauery | 400cc78 | 2018-10-09 13:49:53 -0700 | [diff] [blame] | 1526 | return ipmi::responseSuccess(); |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1527 | } |
| 1528 | // start the timer |
| 1529 | auto time = std::chrono::duration_cast<std::chrono::microseconds>( |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1530 | std::chrono::seconds(identifyInterval)); |
Vernon Mauery | 1181af7 | 2018-10-08 12:05:00 -0700 | [diff] [blame] | 1531 | identifyTimer->start(time); |
Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 1532 | } |
Tom Joseph | bed2699 | 2018-07-31 23:00:24 +0530 | [diff] [blame] | 1533 | else if (!identifyInterval) |
| 1534 | { |
Vernon Mauery | 1181af7 | 2018-10-08 12:05:00 -0700 | [diff] [blame] | 1535 | identifyTimer->stop(); |
Tom Joseph | bed2699 | 2018-07-31 23:00:24 +0530 | [diff] [blame] | 1536 | enclosureIdentifyLedOff(); |
| 1537 | } |
Vernon Mauery | 400cc78 | 2018-10-09 13:49:53 -0700 | [diff] [blame] | 1538 | return ipmi::responseSuccess(); |
Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 1539 | } |
| 1540 | |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1541 | namespace boot_options |
| 1542 | { |
| 1543 | |
Willy Tu | 523e2d1 | 2023-09-05 11:36:48 -0700 | [diff] [blame] | 1544 | using namespace sdbusplus::server::xyz::openbmc_project::control::boot; |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1545 | using IpmiValue = uint8_t; |
| 1546 | constexpr auto ipmiDefault = 0; |
| 1547 | |
Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 1548 | std::map<IpmiValue, Type::Types> typeIpmiToDbus = {{0x00, Type::Types::Legacy}, |
| 1549 | {0x01, Type::Types::EFI}}; |
| 1550 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1551 | std::map<IpmiValue, Source::Sources> sourceIpmiToDbus = { |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1552 | {0x01, Source::Sources::Network}, |
| 1553 | {0x02, Source::Sources::Disk}, |
| 1554 | {0x05, Source::Sources::ExternalMedia}, |
Jia, chunhui | 67c5e5d | 2019-05-06 11:29:54 +0800 | [diff] [blame] | 1555 | {0x0f, Source::Sources::RemovableMedia}, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1556 | {ipmiDefault, Source::Sources::Default}}; |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 1557 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1558 | std::map<IpmiValue, Mode::Modes> modeIpmiToDbus = { |
Yong Li | 5833cb6 | 2019-10-30 13:27:12 +0800 | [diff] [blame] | 1559 | #ifdef ENABLE_BOOT_FLAG_SAFE_MODE_SUPPORT |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1560 | {0x03, Mode::Modes::Safe}, |
Yong Li | 5833cb6 | 2019-10-30 13:27:12 +0800 | [diff] [blame] | 1561 | #endif // ENABLE_BOOT_SAFE_MODE_SUPPORT |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1562 | {0x06, Mode::Modes::Setup}, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1563 | {ipmiDefault, Mode::Modes::Regular}}; |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 1564 | |
Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 1565 | std::map<Type::Types, IpmiValue> typeDbusToIpmi = {{Type::Types::Legacy, 0x00}, |
| 1566 | {Type::Types::EFI, 0x01}}; |
| 1567 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1568 | std::map<Source::Sources, IpmiValue> sourceDbusToIpmi = { |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1569 | {Source::Sources::Network, 0x01}, |
| 1570 | {Source::Sources::Disk, 0x02}, |
| 1571 | {Source::Sources::ExternalMedia, 0x05}, |
Jia, chunhui | 67c5e5d | 2019-05-06 11:29:54 +0800 | [diff] [blame] | 1572 | {Source::Sources::RemovableMedia, 0x0f}, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1573 | {Source::Sources::Default, ipmiDefault}}; |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 1574 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1575 | std::map<Mode::Modes, IpmiValue> modeDbusToIpmi = { |
Yong Li | 5833cb6 | 2019-10-30 13:27:12 +0800 | [diff] [blame] | 1576 | #ifdef ENABLE_BOOT_FLAG_SAFE_MODE_SUPPORT |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1577 | {Mode::Modes::Safe, 0x03}, |
Yong Li | 5833cb6 | 2019-10-30 13:27:12 +0800 | [diff] [blame] | 1578 | #endif // ENABLE_BOOT_SAFE_MODE_SUPPORT |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1579 | {Mode::Modes::Setup, 0x06}, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1580 | {Mode::Modes::Regular, ipmiDefault}}; |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 1581 | |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1582 | } // namespace boot_options |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 1583 | |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1584 | /** @brief Get the property value for boot source |
| 1585 | * @param[in] ctx - context pointer |
| 1586 | * @param[out] source - boot source value |
| 1587 | * @return On failure return IPMI error. |
| 1588 | */ |
| 1589 | static ipmi::Cc getBootSource(ipmi::Context::ptr& ctx, Source::Sources& source) |
| 1590 | { |
| 1591 | using namespace chassis::internal; |
| 1592 | std::string result; |
| 1593 | std::string service; |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 1594 | boost::system::error_code ec = |
| 1595 | getService(ctx, bootSourceIntf, bootSettingsPath, service); |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1596 | if (!ec) |
| 1597 | { |
| 1598 | ec = ipmi::getDbusProperty(ctx, service, bootSettingsPath, |
| 1599 | bootSourceIntf, "BootSource", result); |
| 1600 | if (!ec) |
| 1601 | { |
| 1602 | source = Source::convertSourcesFromString(result); |
| 1603 | return ipmi::ccSuccess; |
| 1604 | } |
| 1605 | } |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 1606 | lg2::error("Error in BootSource Get: {ERROR}", "ERROR", ec.message()); |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1607 | return ipmi::ccUnspecifiedError; |
| 1608 | } |
| 1609 | |
Marri Devender Rao | 8171970 | 2018-05-07 00:53:48 -0500 | [diff] [blame] | 1610 | /** @brief Set the property value for boot source |
Konstantin Aladyshev | e76a61a | 2021-03-18 22:19:13 +0300 | [diff] [blame] | 1611 | * @param[in] ctx - context pointer |
Marri Devender Rao | 8171970 | 2018-05-07 00:53:48 -0500 | [diff] [blame] | 1612 | * @param[in] source - boot source value |
| 1613 | * @return On failure return IPMI error. |
| 1614 | */ |
Jayaprakash Mutyala | 6088e9f | 2021-07-14 07:40:29 +0000 | [diff] [blame] | 1615 | static ipmi::Cc setBootSource(ipmi::Context::ptr& ctx, |
| 1616 | const Source::Sources& source) |
Marri Devender Rao | 8171970 | 2018-05-07 00:53:48 -0500 | [diff] [blame] | 1617 | { |
| 1618 | using namespace chassis::internal; |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1619 | std::string service; |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 1620 | boost::system::error_code ec = |
| 1621 | getService(ctx, bootSourceIntf, bootSettingsPath, service); |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1622 | if (!ec) |
Marri Devender Rao | 8171970 | 2018-05-07 00:53:48 -0500 | [diff] [blame] | 1623 | { |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1624 | ec = ipmi::setDbusProperty(ctx, service, bootSettingsPath, |
| 1625 | bootSourceIntf, "BootSource", |
| 1626 | convertForMessage(source)); |
| 1627 | if (!ec) |
| 1628 | { |
| 1629 | return ipmi::ccSuccess; |
| 1630 | } |
Marri Devender Rao | 8171970 | 2018-05-07 00:53:48 -0500 | [diff] [blame] | 1631 | } |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 1632 | lg2::error("Error in BootSource Set: {ERROR}", "ERROR", ec.message()); |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1633 | return ipmi::ccUnspecifiedError; |
| 1634 | } |
| 1635 | |
| 1636 | /** @brief Get the property value for boot mode |
| 1637 | * @param[in] ctx - context pointer |
| 1638 | * @param[out] mode - boot mode value |
| 1639 | * @return On failure return IPMI error. |
| 1640 | */ |
| 1641 | static ipmi::Cc getBootMode(ipmi::Context::ptr& ctx, Mode::Modes& mode) |
| 1642 | { |
| 1643 | using namespace chassis::internal; |
| 1644 | std::string result; |
| 1645 | std::string service; |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 1646 | boost::system::error_code ec = |
| 1647 | getService(ctx, bootModeIntf, bootSettingsPath, service); |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1648 | if (!ec) |
| 1649 | { |
| 1650 | ec = ipmi::getDbusProperty(ctx, service, bootSettingsPath, bootModeIntf, |
| 1651 | "BootMode", result); |
| 1652 | if (!ec) |
| 1653 | { |
| 1654 | mode = Mode::convertModesFromString(result); |
| 1655 | return ipmi::ccSuccess; |
| 1656 | } |
| 1657 | } |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 1658 | lg2::error("Error in BootMode Get: {ERROR}", "ERROR", ec.message()); |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1659 | return ipmi::ccUnspecifiedError; |
Marri Devender Rao | 8171970 | 2018-05-07 00:53:48 -0500 | [diff] [blame] | 1660 | } |
| 1661 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1662 | /** @brief Set the property value for boot mode |
Konstantin Aladyshev | e76a61a | 2021-03-18 22:19:13 +0300 | [diff] [blame] | 1663 | * @param[in] ctx - context pointer |
Marri Devender Rao | 8171970 | 2018-05-07 00:53:48 -0500 | [diff] [blame] | 1664 | * @param[in] mode - boot mode value |
| 1665 | * @return On failure return IPMI error. |
| 1666 | */ |
Konstantin Aladyshev | e76a61a | 2021-03-18 22:19:13 +0300 | [diff] [blame] | 1667 | static ipmi::Cc setBootMode(ipmi::Context::ptr& ctx, const Mode::Modes& mode) |
Marri Devender Rao | 8171970 | 2018-05-07 00:53:48 -0500 | [diff] [blame] | 1668 | { |
| 1669 | using namespace chassis::internal; |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1670 | std::string service; |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 1671 | boost::system::error_code ec = |
| 1672 | getService(ctx, bootModeIntf, bootSettingsPath, service); |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1673 | if (!ec) |
Marri Devender Rao | 8171970 | 2018-05-07 00:53:48 -0500 | [diff] [blame] | 1674 | { |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1675 | ec = ipmi::setDbusProperty(ctx, service, bootSettingsPath, bootModeIntf, |
| 1676 | "BootMode", convertForMessage(mode)); |
| 1677 | if (!ec) |
| 1678 | { |
| 1679 | return ipmi::ccSuccess; |
| 1680 | } |
Marri Devender Rao | 8171970 | 2018-05-07 00:53:48 -0500 | [diff] [blame] | 1681 | } |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 1682 | lg2::error("Error in BootMode Set: {ERROR}", "ERROR", ec.message()); |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1683 | return ipmi::ccUnspecifiedError; |
| 1684 | } |
| 1685 | |
| 1686 | /** @brief Get the property value for boot type |
| 1687 | * @param[in] ctx - context pointer |
| 1688 | * @param[out] type - boot type value |
| 1689 | * @return On failure return IPMI error. |
| 1690 | */ |
| 1691 | static ipmi::Cc getBootType(ipmi::Context::ptr& ctx, Type::Types& type) |
| 1692 | { |
| 1693 | using namespace chassis::internal; |
| 1694 | std::string result; |
| 1695 | std::string service; |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 1696 | boost::system::error_code ec = |
| 1697 | getService(ctx, bootTypeIntf, bootSettingsPath, service); |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1698 | |
| 1699 | // Don't throw error if BootType interface is not present. |
| 1700 | // This interface is not relevant for some Host architectures |
| 1701 | // (for example POWER). In this case we don't won't IPMI to |
| 1702 | // return an error, but simply return bootType as EFI. |
| 1703 | type = Type::Types::EFI; |
| 1704 | if (!ec) |
| 1705 | { |
| 1706 | ec = ipmi::getDbusProperty(ctx, service, bootSettingsPath, bootTypeIntf, |
| 1707 | "BootType", result); |
| 1708 | if (ec) |
| 1709 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 1710 | lg2::error("Error in BootType Get: {ERROR}", "ERROR", ec.message()); |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1711 | return ipmi::ccUnspecifiedError; |
| 1712 | } |
| 1713 | type = Type::convertTypesFromString(result); |
| 1714 | } |
| 1715 | |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 1716 | return ipmi::ccSuccess; |
Marri Devender Rao | 8171970 | 2018-05-07 00:53:48 -0500 | [diff] [blame] | 1717 | } |
| 1718 | |
Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 1719 | /** @brief Set the property value for boot type |
Konstantin Aladyshev | e76a61a | 2021-03-18 22:19:13 +0300 | [diff] [blame] | 1720 | * @param[in] ctx - context pointer |
Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 1721 | * @param[in] type - boot type value |
| 1722 | * @return On failure return IPMI error. |
| 1723 | */ |
Konstantin Aladyshev | e76a61a | 2021-03-18 22:19:13 +0300 | [diff] [blame] | 1724 | static ipmi::Cc setBootType(ipmi::Context::ptr& ctx, const Type::Types& type) |
Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 1725 | { |
| 1726 | using namespace chassis::internal; |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1727 | std::string service; |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 1728 | boost::system::error_code ec = |
| 1729 | getService(ctx, bootTypeIntf, bootSettingsPath, service); |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1730 | if (!ec) |
Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 1731 | { |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1732 | ec = ipmi::setDbusProperty(ctx, service, bootSettingsPath, bootTypeIntf, |
| 1733 | "BootType", convertForMessage(type)); |
| 1734 | if (ec) |
| 1735 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 1736 | lg2::error("Error in BootType Set: {ERROR}", "ERROR", ec.message()); |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1737 | return ipmi::ccUnspecifiedError; |
| 1738 | } |
Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 1739 | } |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1740 | // Don't throw error if BootType interface is not present. |
| 1741 | // This interface is not relevant for some Host architectures |
| 1742 | // (for example POWER). In this case we don't won't IPMI to |
| 1743 | // return an error, but want to just skip this function. |
Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 1744 | return ipmi::ccSuccess; |
| 1745 | } |
| 1746 | |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1747 | /** @brief Get the property value for boot override enable |
| 1748 | * @param[in] ctx - context pointer |
| 1749 | * @param[out] enable - boot override enable |
| 1750 | * @return On failure return IPMI error. |
| 1751 | */ |
| 1752 | static ipmi::Cc getBootEnable(ipmi::Context::ptr& ctx, bool& enable) |
| 1753 | { |
| 1754 | using namespace chassis::internal; |
| 1755 | std::string result; |
| 1756 | std::string service; |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 1757 | boost::system::error_code ec = |
| 1758 | getService(ctx, bootEnableIntf, bootSettingsPath, service); |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1759 | if (!ec) |
| 1760 | { |
| 1761 | ec = ipmi::getDbusProperty(ctx, service, bootSettingsPath, |
| 1762 | bootEnableIntf, "Enabled", enable); |
| 1763 | if (!ec) |
| 1764 | { |
| 1765 | return ipmi::ccSuccess; |
| 1766 | } |
| 1767 | } |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 1768 | lg2::error("Error in Boot Override Enable Get: {ERROR}", "ERROR", |
| 1769 | ec.message()); |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1770 | return ipmi::ccUnspecifiedError; |
| 1771 | } |
| 1772 | |
| 1773 | /** @brief Set the property value for boot override enable |
| 1774 | * @param[in] ctx - context pointer |
| 1775 | * @param[in] enable - boot override enable |
| 1776 | * @return On failure return IPMI error. |
| 1777 | */ |
| 1778 | static ipmi::Cc setBootEnable(ipmi::Context::ptr& ctx, const bool& enable) |
| 1779 | { |
| 1780 | using namespace chassis::internal; |
| 1781 | std::string service; |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 1782 | boost::system::error_code ec = |
| 1783 | getService(ctx, bootEnableIntf, bootSettingsPath, service); |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1784 | if (!ec) |
| 1785 | { |
| 1786 | ec = ipmi::setDbusProperty(ctx, service, bootSettingsPath, |
| 1787 | bootEnableIntf, "Enabled", enable); |
| 1788 | if (!ec) |
| 1789 | { |
| 1790 | return ipmi::ccSuccess; |
| 1791 | } |
| 1792 | } |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 1793 | lg2::error("Error in Boot Source Override Enable Set: {ERROR}", "ERROR", |
| 1794 | ec.message()); |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1795 | return ipmi::ccUnspecifiedError; |
| 1796 | } |
| 1797 | |
| 1798 | /** @brief Get the property value for boot override one-time |
| 1799 | * @param[in] ctx - context pointer |
| 1800 | * @param[out] onetime - boot override one-time |
| 1801 | * @return On failure return IPMI error. |
| 1802 | */ |
| 1803 | static ipmi::Cc getBootOneTime(ipmi::Context::ptr& ctx, bool& onetime) |
| 1804 | { |
| 1805 | using namespace chassis::internal; |
| 1806 | std::string result; |
| 1807 | std::string service; |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 1808 | boost::system::error_code ec = |
| 1809 | getService(ctx, bootOneTimeIntf, bootSettingsOneTimePath, service); |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1810 | if (!ec) |
| 1811 | { |
| 1812 | ec = ipmi::getDbusProperty(ctx, service, bootSettingsOneTimePath, |
| 1813 | bootOneTimeIntf, "Enabled", onetime); |
| 1814 | if (!ec) |
| 1815 | { |
| 1816 | return ipmi::ccSuccess; |
| 1817 | } |
| 1818 | } |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 1819 | lg2::error("Error in Boot Override OneTime Get: {ERROR}", "ERROR", |
| 1820 | ec.message()); |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1821 | return ipmi::ccUnspecifiedError; |
| 1822 | } |
| 1823 | |
| 1824 | /** @brief Set the property value for boot override one-time |
| 1825 | * @param[in] ctx - context pointer |
| 1826 | * @param[in] onetime - boot override one-time |
| 1827 | * @return On failure return IPMI error. |
| 1828 | */ |
| 1829 | static ipmi::Cc setBootOneTime(ipmi::Context::ptr& ctx, const bool& onetime) |
| 1830 | { |
| 1831 | using namespace chassis::internal; |
| 1832 | std::string service; |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 1833 | boost::system::error_code ec = |
| 1834 | getService(ctx, bootOneTimeIntf, bootSettingsOneTimePath, service); |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1835 | if (!ec) |
| 1836 | { |
| 1837 | ec = ipmi::setDbusProperty(ctx, service, bootSettingsOneTimePath, |
| 1838 | bootOneTimeIntf, "Enabled", onetime); |
| 1839 | if (!ec) |
| 1840 | { |
| 1841 | return ipmi::ccSuccess; |
| 1842 | } |
| 1843 | } |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 1844 | lg2::error("Error in Boot Source Override OneTime Set: {ERROR}", "ERROR", |
| 1845 | ec.message()); |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1846 | return ipmi::ccUnspecifiedError; |
| 1847 | } |
| 1848 | |
huanghe | ab36928 | 2020-10-10 14:40:00 +0800 | [diff] [blame] | 1849 | static constexpr uint8_t setComplete = 0x0; |
| 1850 | static constexpr uint8_t setInProgress = 0x1; |
| 1851 | static uint8_t transferStatus = setComplete; |
Chen Yugang | 86ac499 | 2021-06-25 08:14:52 +0800 | [diff] [blame] | 1852 | static uint8_t bootFlagValidBitClr = 0; |
Hieu Huynh | 38ffafc | 2021-05-14 08:40:14 +0000 | [diff] [blame] | 1853 | static uint5_t bootInitiatorAckData = 0x0; |
Hieu Huynh | 1982a3f | 2021-09-21 03:06:45 +0000 | [diff] [blame] | 1854 | static bool cmosClear = false; |
Cosmo Chou | 5383121 | 2025-01-10 13:36:36 +0800 | [diff] [blame] | 1855 | static uint2_t biosVerbosity = 0x0; |
huanghe | ab36928 | 2020-10-10 14:40:00 +0800 | [diff] [blame] | 1856 | |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 1857 | /** @brief implements the Get Chassis system boot option |
Konstantin Aladyshev | e76a61a | 2021-03-18 22:19:13 +0300 | [diff] [blame] | 1858 | * @param ctx - context pointer |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 1859 | * @param bootOptionParameter - boot option parameter selector |
| 1860 | * @param reserved1 - reserved bit |
| 1861 | * @param setSelector - selects a particular block or set of parameters |
| 1862 | * under the given parameter selector |
| 1863 | * write as 00h if parameter doesn't use a setSelector |
| 1864 | * @param blockSelector- selects a particular block within a set of |
| 1865 | * parameters write as 00h if parameter doesn't use a |
| 1866 | * blockSelector |
| 1867 | * |
| 1868 | * @return IPMI completion code plus response data |
| 1869 | * @return Payload contains below parameters: |
| 1870 | * version - parameter version |
| 1871 | * bootOptionParameter - boot option parameter selector |
Patrick Venture | 8b1c303 | 2020-09-15 09:43:03 -0700 | [diff] [blame] | 1872 | * parmIndicator - parameter valid/invalid indicator |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 1873 | * data - configuration parameter data |
| 1874 | */ |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 1875 | ipmi::RspType<ipmi::message::Payload> ipmiChassisGetSysBootOptions( |
| 1876 | ipmi::Context::ptr ctx, uint7_t bootOptionParameter, bool reserved1, |
| 1877 | [[maybe_unused]] uint8_t setSelector, |
| 1878 | [[maybe_unused]] uint8_t blockSelector) |
Adriana Kobylak | 40814c6 | 2015-10-27 15:58:44 -0500 | [diff] [blame] | 1879 | { |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1880 | ipmi::Cc rc; |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 1881 | if (reserved1) |
| 1882 | { |
| 1883 | return ipmi::responseInvalidFieldRequest(); |
| 1884 | } |
| 1885 | |
| 1886 | constexpr uint4_t version = 0x01; |
| 1887 | ipmi::message::Payload response; |
| 1888 | response.pack(version, uint4_t{}); |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1889 | using namespace boot_options; |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 1890 | |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1891 | IpmiValue bootOption = ipmiDefault; |
Adriana Kobylak | 40814c6 | 2015-10-27 15:58:44 -0500 | [diff] [blame] | 1892 | |
William A. Kennington III | 7a0e5df | 2021-05-19 13:31:29 -0700 | [diff] [blame] | 1893 | if (types::enum_cast<BootOptionParameter>(bootOptionParameter) == |
| 1894 | BootOptionParameter::setInProgress) |
huanghe | ab36928 | 2020-10-10 14:40:00 +0800 | [diff] [blame] | 1895 | { |
| 1896 | response.pack(bootOptionParameter, reserved1, transferStatus); |
| 1897 | return ipmi::responseSuccess(std::move(response)); |
| 1898 | } |
| 1899 | |
William A. Kennington III | 7a0e5df | 2021-05-19 13:31:29 -0700 | [diff] [blame] | 1900 | if (types::enum_cast<BootOptionParameter>(bootOptionParameter) == |
| 1901 | BootOptionParameter::bootInfo) |
John Wang | 0213f90 | 2020-12-28 14:49:57 +0800 | [diff] [blame] | 1902 | { |
| 1903 | constexpr uint8_t writeMask = 0; |
Hieu Huynh | 38ffafc | 2021-05-14 08:40:14 +0000 | [diff] [blame] | 1904 | response.pack(bootOptionParameter, reserved1, writeMask, |
| 1905 | bootInitiatorAckData); |
John Wang | 0213f90 | 2020-12-28 14:49:57 +0800 | [diff] [blame] | 1906 | return ipmi::responseSuccess(std::move(response)); |
| 1907 | } |
| 1908 | |
Chen Yugang | 86ac499 | 2021-06-25 08:14:52 +0800 | [diff] [blame] | 1909 | if (types::enum_cast<BootOptionParameter>(bootOptionParameter) == |
| 1910 | BootOptionParameter::bootFlagValidClr) |
| 1911 | { |
| 1912 | response.pack(bootOptionParameter, reserved1, |
| 1913 | uint5_t{bootFlagValidBitClr}, uint3_t{}); |
| 1914 | return ipmi::responseSuccess(std::move(response)); |
| 1915 | } |
| 1916 | |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 1917 | /* |
| 1918 | * Parameter #5 means boot flags. Please refer to 28.13 of ipmi doc. |
| 1919 | * This is the only parameter used by petitboot. |
| 1920 | */ |
William A. Kennington III | 7a0e5df | 2021-05-19 13:31:29 -0700 | [diff] [blame] | 1921 | if (types::enum_cast<BootOptionParameter>(bootOptionParameter) == |
| 1922 | BootOptionParameter::bootFlags) |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1923 | { |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1924 | using namespace chassis::internal; |
| 1925 | using namespace chassis::internal::cache; |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 1926 | |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1927 | try |
ratagupt | a6f6bff | 2016-04-04 06:20:11 -0500 | [diff] [blame] | 1928 | { |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1929 | Source::Sources bootSource; |
| 1930 | rc = getBootSource(ctx, bootSource); |
| 1931 | if (rc != ipmi::ccSuccess) |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1932 | { |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1933 | return ipmi::response(rc); |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1934 | } |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1935 | |
Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 1936 | Type::Types bootType; |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1937 | rc = getBootType(ctx, bootType); |
| 1938 | if (rc != ipmi::ccSuccess) |
Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 1939 | { |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1940 | return ipmi::response(rc); |
Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 1941 | } |
| 1942 | |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1943 | Mode::Modes bootMode; |
| 1944 | rc = getBootMode(ctx, bootMode); |
| 1945 | if (rc != ipmi::ccSuccess) |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1946 | { |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1947 | return ipmi::response(rc); |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1948 | } |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1949 | |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1950 | bootOption = sourceDbusToIpmi.at(bootSource); |
| 1951 | if ((Mode::Modes::Regular == bootMode) && |
| 1952 | (Source::Sources::Default == bootSource)) |
| 1953 | { |
| 1954 | bootOption = ipmiDefault; |
| 1955 | } |
| 1956 | else if (Source::Sources::Default == bootSource) |
| 1957 | { |
| 1958 | bootOption = modeDbusToIpmi.at(bootMode); |
| 1959 | } |
ratagupt | a6f6bff | 2016-04-04 06:20:11 -0500 | [diff] [blame] | 1960 | |
Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 1961 | IpmiValue biosBootType = typeDbusToIpmi.at(bootType); |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1962 | |
| 1963 | bool oneTimeEnabled; |
| 1964 | rc = getBootOneTime(ctx, oneTimeEnabled); |
| 1965 | if (rc != ipmi::ccSuccess) |
| 1966 | { |
| 1967 | return ipmi::response(rc); |
| 1968 | } |
| 1969 | |
Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 1970 | uint1_t permanent = oneTimeEnabled ? 0 : 1; |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1971 | |
| 1972 | bool valid; |
| 1973 | rc = getBootEnable(ctx, valid); |
| 1974 | if (rc != ipmi::ccSuccess) |
| 1975 | { |
| 1976 | return ipmi::response(rc); |
| 1977 | } |
| 1978 | |
| 1979 | uint1_t validFlag = valid ? 1 : 0; |
Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 1980 | |
Cosmo Chou | 5383121 | 2025-01-10 13:36:36 +0800 | [diff] [blame] | 1981 | response.pack( |
| 1982 | bootOptionParameter, reserved1, uint5_t{}, |
| 1983 | uint1_t{biosBootType}, uint1_t{permanent}, uint1_t{validFlag}, |
| 1984 | uint2_t{}, uint4_t{bootOption}, uint1_t{}, cmosClear, uint5_t{}, |
| 1985 | uint2_t{biosVerbosity}, uint1_t{}, uint8_t{}, uint8_t{}); |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 1986 | return ipmi::responseSuccess(std::move(response)); |
ratagupt | a6f6bff | 2016-04-04 06:20:11 -0500 | [diff] [blame] | 1987 | } |
Patrick Williams | a2ad2da | 2021-10-06 12:21:46 -0500 | [diff] [blame] | 1988 | catch (const InternalFailure& e) |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1989 | { |
James Feist | 225dec8 | 2019-11-26 16:25:06 -0800 | [diff] [blame] | 1990 | cache::objectsPtr.reset(); |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1991 | report<InternalFailure>(); |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 1992 | return ipmi::responseUnspecifiedError(); |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1993 | } |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1994 | } |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1995 | else |
| 1996 | { |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 1997 | if ((bootOptionParameter >= oemParmStart) && |
| 1998 | (bootOptionParameter <= oemParmEnd)) |
| 1999 | { |
William A. Kennington III | 7a0e5df | 2021-05-19 13:31:29 -0700 | [diff] [blame] | 2000 | if (types::enum_cast<BootOptionParameter>(bootOptionParameter) == |
| 2001 | BootOptionParameter::opalNetworkSettings) |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 2002 | { |
| 2003 | response.pack(bootOptionParameter, reserved1); |
| 2004 | int ret = getHostNetworkData(response); |
| 2005 | if (ret < 0) |
| 2006 | { |
| 2007 | response.trailingOk = true; |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 2008 | lg2::error( |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 2009 | "getHostNetworkData failed for GetSysBootOptions."); |
| 2010 | return ipmi::responseUnspecifiedError(); |
| 2011 | } |
| 2012 | else |
| 2013 | { |
| 2014 | return ipmi::responseSuccess(std::move(response)); |
| 2015 | } |
| 2016 | } |
Jayaprakash Mutyala | 43a8810 | 2021-08-04 16:41:58 +0000 | [diff] [blame] | 2017 | else |
| 2018 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 2019 | lg2::error( |
| 2020 | "ipmiChassisGetSysBootOptions: Unsupported parameter {PARAM}", |
| 2021 | "PARAM", lg2::hex, |
| 2022 | static_cast<uint8_t>(bootOptionParameter)); |
Jayaprakash Mutyala | 43a8810 | 2021-08-04 16:41:58 +0000 | [diff] [blame] | 2023 | return ipmi::responseParmNotSupported(); |
| 2024 | } |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 2025 | } |
| 2026 | else |
| 2027 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 2028 | lg2::error( |
| 2029 | "ipmiChassisGetSysBootOptions: Unsupported parameter {PARAM}", |
| 2030 | "PARAM", lg2::hex, static_cast<uint8_t>(bootOptionParameter)); |
Jayaprakash Mutyala | 6088e9f | 2021-07-14 07:40:29 +0000 | [diff] [blame] | 2031 | return ipmi::responseParmNotSupported(); |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 2032 | } |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 2033 | } |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 2034 | return ipmi::responseUnspecifiedError(); |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 2035 | } |
| 2036 | |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2037 | ipmi::RspType<> ipmiChassisSetSysBootOptions(ipmi::Context::ptr ctx, |
Willy Tu | 11d6889 | 2022-01-20 10:37:34 -0800 | [diff] [blame] | 2038 | uint7_t parameterSelector, bool, |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2039 | ipmi::message::Payload& data) |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 2040 | { |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 2041 | using namespace boot_options; |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2042 | ipmi::Cc rc; |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 2043 | |
William A. Kennington III | 7a0e5df | 2021-05-19 13:31:29 -0700 | [diff] [blame] | 2044 | if (types::enum_cast<BootOptionParameter>(parameterSelector) == |
| 2045 | BootOptionParameter::setInProgress) |
huanghe | ab36928 | 2020-10-10 14:40:00 +0800 | [diff] [blame] | 2046 | { |
| 2047 | uint2_t setInProgressFlag; |
| 2048 | uint6_t rsvd; |
| 2049 | if (data.unpack(setInProgressFlag, rsvd) != 0 || !data.fullyUnpacked()) |
| 2050 | { |
| 2051 | return ipmi::responseReqDataLenInvalid(); |
| 2052 | } |
| 2053 | if (rsvd) |
| 2054 | { |
| 2055 | return ipmi::responseInvalidFieldRequest(); |
| 2056 | } |
| 2057 | if ((transferStatus == setInProgress) && |
| 2058 | (static_cast<uint8_t>(setInProgressFlag) != setComplete)) |
| 2059 | { |
George Liu | f5dd102 | 2025-07-07 09:13:07 +0800 | [diff] [blame] | 2060 | return ipmi::responsefailSetInProgress(); |
huanghe | ab36928 | 2020-10-10 14:40:00 +0800 | [diff] [blame] | 2061 | } |
| 2062 | transferStatus = static_cast<uint8_t>(setInProgressFlag); |
| 2063 | return ipmi::responseSuccess(); |
| 2064 | } |
| 2065 | |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 2066 | /* 000101 |
| 2067 | * Parameter #5 means boot flags. Please refer to 28.13 of ipmi doc. |
| 2068 | * This is the only parameter used by petitboot. |
| 2069 | */ |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 2070 | |
William A. Kennington III | 7a0e5df | 2021-05-19 13:31:29 -0700 | [diff] [blame] | 2071 | if (types::enum_cast<BootOptionParameter>(parameterSelector) == |
| 2072 | BootOptionParameter::bootFlags) |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 2073 | { |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2074 | uint5_t rsvd; |
| 2075 | bool validFlag; |
| 2076 | bool permanent; |
| 2077 | bool biosBootType; |
| 2078 | bool lockOutResetButton; |
| 2079 | bool screenBlank; |
| 2080 | uint4_t bootDeviceSelector; |
| 2081 | bool lockKeyboard; |
Cosmo Chou | 5383121 | 2025-01-10 13:36:36 +0800 | [diff] [blame] | 2082 | uint5_t biosCtrls; |
| 2083 | bool lockOutPower; |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2084 | uint4_t biosInfo; |
| 2085 | uint4_t rsvd1; |
| 2086 | uint5_t deviceInstance; |
| 2087 | uint3_t rsvd2; |
| 2088 | |
| 2089 | if (data.unpack(rsvd, biosBootType, permanent, validFlag, |
| 2090 | lockOutResetButton, screenBlank, bootDeviceSelector, |
Cosmo Chou | 5383121 | 2025-01-10 13:36:36 +0800 | [diff] [blame] | 2091 | lockKeyboard, cmosClear, biosCtrls, biosVerbosity, |
| 2092 | lockOutPower, biosInfo, rsvd1, deviceInstance, rsvd2) != |
| 2093 | 0 || |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2094 | !data.fullyUnpacked()) |
| 2095 | { |
| 2096 | return ipmi::responseReqDataLenInvalid(); |
| 2097 | } |
| 2098 | if (rsvd || rsvd1 || rsvd2) |
| 2099 | { |
| 2100 | return ipmi::responseInvalidFieldRequest(); |
| 2101 | } |
| 2102 | |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 2103 | using namespace chassis::internal; |
| 2104 | using namespace chassis::internal::cache; |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 2105 | |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 2106 | try |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 2107 | { |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 2108 | rc = setBootOneTime(ctx, !permanent); |
| 2109 | if (rc != ipmi::ccSuccess) |
Konstantin Aladyshev | 69e8e84 | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 2110 | { |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 2111 | return ipmi::response(rc); |
| 2112 | } |
Vernon Mauery | afd45db | 2021-07-29 16:27:25 +0000 | [diff] [blame] | 2113 | |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 2114 | rc = setBootEnable(ctx, validFlag); |
| 2115 | if (rc != ipmi::ccSuccess) |
| 2116 | { |
| 2117 | return ipmi::response(rc); |
Tom Joseph | 57e8eb7 | 2017-09-25 18:05:02 +0530 | [diff] [blame] | 2118 | } |
| 2119 | |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2120 | auto modeItr = |
| 2121 | modeIpmiToDbus.find(static_cast<uint8_t>(bootDeviceSelector)); |
Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 2122 | auto typeItr = |
| 2123 | typeIpmiToDbus.find(static_cast<uint8_t>(biosBootType)); |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2124 | auto sourceItr = |
| 2125 | sourceIpmiToDbus.find(static_cast<uint8_t>(bootDeviceSelector)); |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 2126 | if (sourceIpmiToDbus.end() != sourceItr) |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 2127 | { |
Konstantin Aladyshev | e76a61a | 2021-03-18 22:19:13 +0300 | [diff] [blame] | 2128 | rc = setBootSource(ctx, sourceItr->second); |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2129 | if (rc != ipmi::ccSuccess) |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 2130 | { |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 2131 | return ipmi::response(rc); |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 2132 | } |
Marri Devender Rao | 54fa130 | 2018-05-07 01:06:23 -0500 | [diff] [blame] | 2133 | // If a set boot device is mapping to a boot source, then reset |
| 2134 | // the boot mode D-Bus property to default. |
| 2135 | // This way the ipmid code can determine which property is not |
| 2136 | // at the default value |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 2137 | if (sourceItr->second != Source::Sources::Default) |
Marri Devender Rao | 54fa130 | 2018-05-07 01:06:23 -0500 | [diff] [blame] | 2138 | { |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 2139 | rc = setBootMode(ctx, Mode::Modes::Regular); |
| 2140 | if (rc != ipmi::ccSuccess) |
| 2141 | { |
| 2142 | return ipmi::response(rc); |
| 2143 | } |
Marri Devender Rao | 54fa130 | 2018-05-07 01:06:23 -0500 | [diff] [blame] | 2144 | } |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 2145 | } |
Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 2146 | |
| 2147 | if (typeIpmiToDbus.end() != typeItr) |
| 2148 | { |
Konstantin Aladyshev | e76a61a | 2021-03-18 22:19:13 +0300 | [diff] [blame] | 2149 | rc = setBootType(ctx, typeItr->second); |
Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 2150 | if (rc != ipmi::ccSuccess) |
| 2151 | { |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 2152 | return ipmi::response(rc); |
Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 2153 | } |
| 2154 | } |
| 2155 | |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 2156 | if (modeIpmiToDbus.end() != modeItr) |
| 2157 | { |
Konstantin Aladyshev | e76a61a | 2021-03-18 22:19:13 +0300 | [diff] [blame] | 2158 | rc = setBootMode(ctx, modeItr->second); |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2159 | if (rc != ipmi::ccSuccess) |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 2160 | { |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 2161 | return ipmi::response(rc); |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 2162 | } |
Marri Devender Rao | 54fa130 | 2018-05-07 01:06:23 -0500 | [diff] [blame] | 2163 | // If a set boot device is mapping to a boot mode, then reset |
| 2164 | // the boot source D-Bus property to default. |
| 2165 | // This way the ipmid code can determine which property is not |
| 2166 | // at the default value |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 2167 | if (modeItr->second != Mode::Modes::Regular) |
Marri Devender Rao | 54fa130 | 2018-05-07 01:06:23 -0500 | [diff] [blame] | 2168 | { |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 2169 | rc = setBootSource(ctx, Source::Sources::Default); |
| 2170 | if (rc != ipmi::ccSuccess) |
| 2171 | { |
| 2172 | return ipmi::response(rc); |
| 2173 | } |
Marri Devender Rao | 54fa130 | 2018-05-07 01:06:23 -0500 | [diff] [blame] | 2174 | } |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 2175 | } |
Jia, chunhui | 67c5e5d | 2019-05-06 11:29:54 +0800 | [diff] [blame] | 2176 | if ((modeIpmiToDbus.end() == modeItr) && |
Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 2177 | (typeIpmiToDbus.end() == typeItr) && |
Jia, chunhui | 67c5e5d | 2019-05-06 11:29:54 +0800 | [diff] [blame] | 2178 | (sourceIpmiToDbus.end() == sourceItr)) |
| 2179 | { |
| 2180 | // return error if boot option is not supported |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 2181 | lg2::error( |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2182 | "ipmiChassisSetSysBootOptions: Boot option not supported"); |
| 2183 | return ipmi::responseInvalidFieldRequest(); |
Jia, chunhui | 67c5e5d | 2019-05-06 11:29:54 +0800 | [diff] [blame] | 2184 | } |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 2185 | } |
Patrick Williams | a2ad2da | 2021-10-06 12:21:46 -0500 | [diff] [blame] | 2186 | catch (const sdbusplus::exception_t& e) |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 2187 | { |
James Feist | 225dec8 | 2019-11-26 16:25:06 -0800 | [diff] [blame] | 2188 | objectsPtr.reset(); |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 2189 | report<InternalFailure>(); |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 2190 | lg2::error("ipmiChassisSetSysBootOptions: Error in setting Boot " |
| 2191 | "flag parameters"); |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2192 | return ipmi::responseUnspecifiedError(); |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 2193 | } |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 2194 | } |
William A. Kennington III | 7a0e5df | 2021-05-19 13:31:29 -0700 | [diff] [blame] | 2195 | else if (types::enum_cast<BootOptionParameter>(parameterSelector) == |
| 2196 | BootOptionParameter::bootInfo) |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 2197 | { |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2198 | uint8_t writeMak; |
Hieu Huynh | 38ffafc | 2021-05-14 08:40:14 +0000 | [diff] [blame] | 2199 | uint5_t bootInfoAck; |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2200 | uint3_t rsvd; |
| 2201 | |
Hieu Huynh | 38ffafc | 2021-05-14 08:40:14 +0000 | [diff] [blame] | 2202 | if (data.unpack(writeMak, bootInfoAck, rsvd) != 0 || |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2203 | !data.fullyUnpacked()) |
| 2204 | { |
| 2205 | return ipmi::responseReqDataLenInvalid(); |
| 2206 | } |
| 2207 | if (rsvd) |
| 2208 | { |
| 2209 | return ipmi::responseInvalidFieldRequest(); |
| 2210 | } |
Hieu Huynh | 38ffafc | 2021-05-14 08:40:14 +0000 | [diff] [blame] | 2211 | bootInitiatorAckData &= ~writeMak; |
| 2212 | bootInitiatorAckData |= (writeMak & bootInfoAck); |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 2213 | lg2::info("ipmiChassisSetSysBootOptions: bootInfo parameter set " |
| 2214 | "successfully"); |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2215 | data.trailingOk = true; |
| 2216 | return ipmi::responseSuccess(); |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 2217 | } |
Chen Yugang | 86ac499 | 2021-06-25 08:14:52 +0800 | [diff] [blame] | 2218 | else if (types::enum_cast<BootOptionParameter>(parameterSelector) == |
| 2219 | BootOptionParameter::bootFlagValidClr) |
| 2220 | { |
| 2221 | uint5_t bootFlagValidClr; |
| 2222 | uint3_t rsvd; |
| 2223 | |
| 2224 | if (data.unpack(bootFlagValidClr, rsvd) != 0 || !data.fullyUnpacked()) |
| 2225 | { |
| 2226 | return ipmi::responseReqDataLenInvalid(); |
| 2227 | } |
| 2228 | if (rsvd) |
| 2229 | { |
| 2230 | return ipmi::responseInvalidFieldRequest(); |
| 2231 | } |
| 2232 | // store boot flag valid bits clear value |
| 2233 | bootFlagValidBitClr = static_cast<uint8_t>(bootFlagValidClr); |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 2234 | lg2::info( |
Chen Yugang | 86ac499 | 2021-06-25 08:14:52 +0800 | [diff] [blame] | 2235 | "ipmiChassisSetSysBootOptions: bootFlagValidBits parameter set " |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 2236 | "successfully to {VALUE}", |
| 2237 | "VALUE", lg2::hex, bootFlagValidBitClr); |
Chen Yugang | 86ac499 | 2021-06-25 08:14:52 +0800 | [diff] [blame] | 2238 | return ipmi::responseSuccess(); |
| 2239 | } |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 2240 | else |
| 2241 | { |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2242 | if ((parameterSelector >= static_cast<uint7_t>(oemParmStart)) && |
| 2243 | (parameterSelector <= static_cast<uint7_t>(oemParmEnd))) |
| 2244 | { |
William A. Kennington III | 7a0e5df | 2021-05-19 13:31:29 -0700 | [diff] [blame] | 2245 | if (types::enum_cast<BootOptionParameter>(parameterSelector) == |
| 2246 | BootOptionParameter::opalNetworkSettings) |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2247 | { |
| 2248 | ipmi::Cc ret = setHostNetworkData(data); |
| 2249 | if (ret != ipmi::ccSuccess) |
| 2250 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 2251 | lg2::error("ipmiChassisSetSysBootOptions: Error in " |
| 2252 | "setHostNetworkData"); |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2253 | data.trailingOk = true; |
| 2254 | return ipmi::response(ret); |
| 2255 | } |
| 2256 | data.trailingOk = true; |
| 2257 | return ipmi::responseSuccess(); |
| 2258 | } |
| 2259 | else |
| 2260 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 2261 | lg2::error( |
| 2262 | "ipmiChassisSetSysBootOptions: Unsupported param: {PARAM}", |
| 2263 | "PARAM", lg2::hex, static_cast<uint8_t>(parameterSelector)); |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2264 | data.trailingOk = true; |
| 2265 | return ipmi::responseParmNotSupported(); |
| 2266 | } |
| 2267 | } |
| 2268 | data.trailingOk = true; |
| 2269 | return ipmi::responseParmNotSupported(); |
Adriana Kobylak | 40814c6 | 2015-10-27 15:58:44 -0500 | [diff] [blame] | 2270 | } |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2271 | return ipmi::responseSuccess(); |
Adriana Kobylak | 40814c6 | 2015-10-27 15:58:44 -0500 | [diff] [blame] | 2272 | } |
| 2273 | |
anil kumar appana | a5a76eb | 2019-04-30 14:57:24 +0000 | [diff] [blame] | 2274 | /** @brief implements Get POH counter command |
| 2275 | * @parameter |
| 2276 | * - none |
| 2277 | * @returns IPMI completion code plus response data |
| 2278 | * - minPerCount - Minutes per count |
| 2279 | * - counterReading - counter reading |
| 2280 | */ |
| 2281 | ipmi::RspType<uint8_t, // Minutes per count |
| 2282 | uint32_t // Counter reading |
| 2283 | > |
| 2284 | ipmiGetPOHCounter() |
Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 2285 | { |
| 2286 | // sd_bus error |
Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 2287 | try |
| 2288 | { |
anil kumar appana | a5a76eb | 2019-04-30 14:57:24 +0000 | [diff] [blame] | 2289 | return ipmi::responseSuccess(static_cast<uint8_t>(poh::minutesPerCount), |
| 2290 | getPOHCounter()); |
Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 2291 | } |
Patrick Williams | a2ad2da | 2021-10-06 12:21:46 -0500 | [diff] [blame] | 2292 | catch (const std::exception& e) |
Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 2293 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 2294 | lg2::error("getPOHCounter error: {ERROR}", "ERROR", e); |
anil kumar appana | a5a76eb | 2019-04-30 14:57:24 +0000 | [diff] [blame] | 2295 | return ipmi::responseUnspecifiedError(); |
Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 2296 | } |
Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 2297 | } |
| 2298 | |
Jason M. Bills | bc996a3 | 2019-06-17 15:46:37 -0700 | [diff] [blame] | 2299 | ipmi::RspType<uint3_t, // policy support |
| 2300 | uint5_t // reserved |
| 2301 | > |
George Liu | de1420d | 2025-03-03 15:14:25 +0800 | [diff] [blame] | 2302 | ipmiChassisSetPowerRestorePolicy(ipmi::Context::ptr ctx, uint3_t policy, |
| 2303 | uint5_t reserved) |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2304 | { |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2305 | power_policy::DbusValue value = |
| 2306 | power_policy::RestorePolicy::Policy::AlwaysOff; |
| 2307 | |
Jason M. Bills | bc996a3 | 2019-06-17 15:46:37 -0700 | [diff] [blame] | 2308 | if (reserved || (policy > power_policy::noChange)) |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2309 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 2310 | lg2::error("Reserved request parameter: {REQ}", "REQ", lg2::hex, |
| 2311 | static_cast<int>(policy)); |
Jason M. Bills | bc996a3 | 2019-06-17 15:46:37 -0700 | [diff] [blame] | 2312 | return ipmi::responseInvalidFieldRequest(); |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2313 | } |
| 2314 | |
Vernon Mauery | e278ead | 2018-10-09 09:23:43 -0700 | [diff] [blame] | 2315 | if (policy == power_policy::noChange) |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2316 | { |
| 2317 | // just return the supported policy |
Jason M. Bills | bc996a3 | 2019-06-17 15:46:37 -0700 | [diff] [blame] | 2318 | return ipmi::responseSuccess(power_policy::allSupport, reserved); |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2319 | } |
| 2320 | |
Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 2321 | for (const auto& it : power_policy::dbusToIpmi) |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2322 | { |
Vernon Mauery | e278ead | 2018-10-09 09:23:43 -0700 | [diff] [blame] | 2323 | if (it.second == policy) |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2324 | { |
| 2325 | value = it.first; |
| 2326 | break; |
| 2327 | } |
| 2328 | } |
| 2329 | |
| 2330 | try |
| 2331 | { |
James Feist | 225dec8 | 2019-11-26 16:25:06 -0800 | [diff] [blame] | 2332 | settings::Objects& objects = chassis::internal::cache::getObjects(); |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2333 | const settings::Path& powerRestoreSetting = |
James Feist | 225dec8 | 2019-11-26 16:25:06 -0800 | [diff] [blame] | 2334 | objects.map.at(chassis::internal::powerRestoreIntf).front(); |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2335 | |
George Liu | de1420d | 2025-03-03 15:14:25 +0800 | [diff] [blame] | 2336 | boost::system::error_code ec = ipmi::setDbusProperty( |
| 2337 | ctx, |
| 2338 | objects.service(powerRestoreSetting, |
| 2339 | chassis::internal::powerRestoreIntf), |
| 2340 | powerRestoreSetting, chassis::internal::powerRestoreIntf, |
| 2341 | "PowerRestorePolicy", convertForMessage(value)); |
Vernon Mauery | e278ead | 2018-10-09 09:23:43 -0700 | [diff] [blame] | 2342 | if (ec) |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2343 | { |
Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 2344 | lg2::error("Unspecified Error"); |
Vernon Mauery | e278ead | 2018-10-09 09:23:43 -0700 | [diff] [blame] | 2345 | return ipmi::responseUnspecifiedError(); |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2346 | } |
| 2347 | } |
Patrick Williams | a2ad2da | 2021-10-06 12:21:46 -0500 | [diff] [blame] | 2348 | catch (const InternalFailure& e) |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2349 | { |
James Feist | 225dec8 | 2019-11-26 16:25:06 -0800 | [diff] [blame] | 2350 | chassis::internal::cache::objectsPtr.reset(); |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2351 | report<InternalFailure>(); |
Vernon Mauery | e278ead | 2018-10-09 09:23:43 -0700 | [diff] [blame] | 2352 | return ipmi::responseUnspecifiedError(); |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2353 | } |
| 2354 | |
Jason M. Bills | bc996a3 | 2019-06-17 15:46:37 -0700 | [diff] [blame] | 2355 | return ipmi::responseSuccess(power_policy::allSupport, reserved); |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2356 | } |
| 2357 | |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 2358 | ipmi::RspType<> ipmiSetFrontPanelButtonEnables( |
| 2359 | ipmi::Context::ptr ctx, bool disablePowerButton, bool disableResetButton, |
| 2360 | bool, bool, uint4_t) |
Kuiying Wang | 21addc5 | 2019-01-04 10:50:21 +0800 | [diff] [blame] | 2361 | { |
| 2362 | using namespace chassis::internal; |
| 2363 | |
| 2364 | // set power button Enabled property |
Konstantin Aladyshev | 305d864 | 2025-02-15 00:36:54 +0300 | [diff] [blame] | 2365 | bool success = setButtonDisabled(ctx, powerButtonPath, powerButtonIntf, |
| 2366 | disablePowerButton); |
Kuiying Wang | 21addc5 | 2019-01-04 10:50:21 +0800 | [diff] [blame] | 2367 | |
| 2368 | // set reset button Enabled property |
Konstantin Aladyshev | 305d864 | 2025-02-15 00:36:54 +0300 | [diff] [blame] | 2369 | success &= setButtonDisabled(ctx, resetButtonPath, resetButtonIntf, |
| 2370 | disableResetButton); |
Kuiying Wang | 21addc5 | 2019-01-04 10:50:21 +0800 | [diff] [blame] | 2371 | |
| 2372 | if (!success) |
| 2373 | { |
| 2374 | // not all buttons were successfully set |
| 2375 | return ipmi::responseUnspecifiedError(); |
| 2376 | } |
| 2377 | return ipmi::responseSuccess(); |
| 2378 | } |
| 2379 | |
George Liu | 5087b07 | 2025-03-11 19:28:17 +0800 | [diff] [blame] | 2380 | void registerNetFnChassisFunctions() |
Adriana Kobylak | 40814c6 | 2015-10-27 15:58:44 -0500 | [diff] [blame] | 2381 | { |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 2382 | createIdentifyTimer(); |
| 2383 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 2384 | // Get Chassis Capabilities |
anil kumar appana | 43263c6 | 2019-05-27 12:45:04 +0000 | [diff] [blame] | 2385 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis, |
| 2386 | ipmi::chassis::cmdGetChassisCapabilities, |
| 2387 | ipmi::Privilege::User, ipmiGetChassisCap); |
Nan Li | 8d15fb4 | 2016-08-16 22:29:40 +0800 | [diff] [blame] | 2388 | |
Kuiying Wang | 21addc5 | 2019-01-04 10:50:21 +0800 | [diff] [blame] | 2389 | // Set Front Panel Button Enables |
| 2390 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis, |
| 2391 | ipmi::chassis::cmdSetFrontPanelButtonEnables, |
| 2392 | ipmi::Privilege::Admin, |
| 2393 | ipmiSetFrontPanelButtonEnables); |
| 2394 | |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 2395 | // Set Chassis Capabilities |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 2396 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis, |
| 2397 | ipmi::chassis::cmdSetChassisCapabilities, |
| 2398 | ipmi::Privilege::User, ipmiSetChassisCap); |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 2399 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 2400 | // <Get System Boot Options> |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 2401 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis, |
| 2402 | ipmi::chassis::cmdGetSystemBootOptions, |
| 2403 | ipmi::Privilege::Operator, |
| 2404 | ipmiChassisGetSysBootOptions); |
Adriana Kobylak | 40814c6 | 2015-10-27 15:58:44 -0500 | [diff] [blame] | 2405 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 2406 | // <Get Chassis Status> |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 2407 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis, |
| 2408 | ipmi::chassis::cmdGetChassisStatus, |
| 2409 | ipmi::Privilege::User, ipmiGetChassisStatus); |
Nan Li | fdd8ec5 | 2016-08-28 03:57:40 +0800 | [diff] [blame] | 2410 | |
Vijay Khemka | 074f64d | 2020-03-03 15:08:43 -0800 | [diff] [blame] | 2411 | // <Chassis Get System Restart Cause> |
| 2412 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis, |
| 2413 | ipmi::chassis::cmdGetSystemRestartCause, |
| 2414 | ipmi::Privilege::User, ipmiGetSystemRestartCause); |
| 2415 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 2416 | // <Chassis Control> |
anil kumar appana | dafff5f | 2019-04-27 18:06:00 +0000 | [diff] [blame] | 2417 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis, |
| 2418 | ipmi::chassis::cmdChassisControl, |
| 2419 | ipmi::Privilege::Operator, ipmiChassisControl); |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 2420 | |
Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 2421 | // <Chassis Identify> |
Vernon Mauery | 400cc78 | 2018-10-09 13:49:53 -0700 | [diff] [blame] | 2422 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis, |
| 2423 | ipmi::chassis::cmdChassisIdentify, |
| 2424 | ipmi::Privilege::Operator, ipmiChassisIdentify); |
Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 2425 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 2426 | // <Set System Boot Options> |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2427 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis, |
| 2428 | ipmi::chassis::cmdSetSystemBootOptions, |
| 2429 | ipmi::Privilege::Operator, |
| 2430 | ipmiChassisSetSysBootOptions); |
| 2431 | |
Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 2432 | // <Get POH Counter> |
anil kumar appana | a5a76eb | 2019-04-30 14:57:24 +0000 | [diff] [blame] | 2433 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis, |
| 2434 | ipmi::chassis::cmdGetPohCounter, |
| 2435 | ipmi::Privilege::User, ipmiGetPOHCounter); |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2436 | |
| 2437 | // <Set Power Restore Policy> |
Vernon Mauery | e278ead | 2018-10-09 09:23:43 -0700 | [diff] [blame] | 2438 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis, |
| 2439 | ipmi::chassis::cmdSetPowerRestorePolicy, |
| 2440 | ipmi::Privilege::Operator, |
| 2441 | ipmiChassisSetPowerRestorePolicy); |
vishwa | 3699327 | 2015-11-20 12:43:49 -0600 | [diff] [blame] | 2442 | } |