| 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 | |
| NikhilaDande | 530239b | 2025-09-30 09:09:40 +0530 | [diff] [blame] | 723 | std::optional<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 | |
| NikhilaDande | 530239b | 2025-09-30 09:09:40 +0530 | [diff] [blame] | 759 | if (bridgeDeviceAddr.has_value()) |
| Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 760 | { |
| NikhilaDande | 530239b | 2025-09-30 09:09:40 +0530 | [diff] [blame] | 761 | if ((bridgeDeviceAddr.value() & ~chassisCapAddrMask) != 0) |
| 762 | { |
| 763 | lg2::error( |
| 764 | "Unsupported request parameter(Bridge Addr) for REQ={REQ}", |
| 765 | "REQ", lg2::hex, bridgeDeviceAddr.value()); |
| 766 | return ipmi::responseInvalidFieldRequest(); |
| 767 | } |
| Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 768 | } |
| 769 | |
| 770 | try |
| 771 | { |
| Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 772 | sdbusplus::bus_t bus(ipmid_get_sd_bus_connection()); |
| Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 773 | ipmi::DbusObjectInfo chassisCapObject = |
| 774 | ipmi::getDbusObject(bus, chassisCapIntf); |
| 775 | |
| 776 | ipmi::setDbusProperty(bus, chassisCapObject.second, |
| 777 | chassisCapObject.first, chassisCapIntf, |
| Karthick Sundarrajan | 86d8bd7 | 2019-11-26 12:48:50 -0800 | [diff] [blame] | 778 | chassisIntrusionProp, intrusion); |
| 779 | |
| 780 | ipmi::setDbusProperty(bus, chassisCapObject.second, |
| 781 | chassisCapObject.first, chassisCapIntf, |
| 782 | chassisFrontPanelLockoutProp, fpLockout); |
| 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 | chassisFRUDevAddrProp, fruDeviceAddr); |
| 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 | chassisSDRDevAddrProp, sdrDeviceAddr); |
| 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 | chassisSELDevAddrProp, selDeviceAddr); |
| 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 | chassisSMDevAddrProp, smDeviceAddr); |
| Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 799 | |
| NikhilaDande | 530239b | 2025-09-30 09:09:40 +0530 | [diff] [blame] | 800 | if (bridgeDeviceAddr.has_value()) |
| 801 | { |
| 802 | ipmi::setDbusProperty(bus, chassisCapObject.second, |
| 803 | chassisCapObject.first, chassisCapIntf, |
| 804 | chassisBridgeDevAddrProp, |
| 805 | bridgeDeviceAddr.value()); |
| 806 | } |
| Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 807 | } |
| Patrick Williams | a2ad2da | 2021-10-06 12:21:46 -0500 | [diff] [blame] | 808 | catch (const std::exception& e) |
| Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 809 | { |
| Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 810 | lg2::error("Failed to set chassis capability properties: {ERR}", "ERR", |
| 811 | e); |
| anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 812 | return ipmi::responseUnspecifiedError(); |
| Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 813 | } |
| anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 814 | return ipmi::responseSuccess(); |
| Nan Li | 8d15fb4 | 2016-08-16 22:29:40 +0800 | [diff] [blame] | 815 | } |
| 816 | |
| Vishwanatha Subbanna | b12b0c0 | 2017-03-07 18:17:19 +0530 | [diff] [blame] | 817 | //------------------------------------------ |
| 818 | // Calls into Host State Manager Dbus object |
| 819 | //------------------------------------------ |
| Jason M. Bills | 664e1c3 | 2020-01-30 16:02:39 -0800 | [diff] [blame] | 820 | int initiateHostStateTransition(ipmi::Context::ptr& ctx, |
| 821 | State::Host::Transition transition) |
| vishwa | 3699327 | 2015-11-20 12:43:49 -0600 | [diff] [blame] | 822 | { |
| Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 823 | // OpenBMC Host State Manager dbus framework |
| Jason M. Bills | 664e1c3 | 2020-01-30 16:02:39 -0800 | [diff] [blame] | 824 | constexpr auto hostStatePath = "/xyz/openbmc_project/state/host0"; |
| 825 | constexpr auto hostStateIntf = "xyz.openbmc_project.State.Host"; |
| Vishwanatha Subbanna | b12b0c0 | 2017-03-07 18:17:19 +0530 | [diff] [blame] | 826 | |
| Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 827 | // Convert to string equivalent of the passed in transition enum. |
| Willy Tu | 523e2d1 | 2023-09-05 11:36:48 -0700 | [diff] [blame] | 828 | auto request = |
| 829 | sdbusplus::common::xyz::openbmc_project::state::convertForMessage( |
| 830 | transition); |
| Vishwanatha Subbanna | b12b0c0 | 2017-03-07 18:17:19 +0530 | [diff] [blame] | 831 | |
| Jason M. Bills | 664e1c3 | 2020-01-30 16:02:39 -0800 | [diff] [blame] | 832 | std::string service; |
| Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 833 | boost::system::error_code ec = |
| 834 | ipmi::getService(ctx, hostStateIntf, hostStatePath, service); |
| Jason M. Bills | 664e1c3 | 2020-01-30 16:02:39 -0800 | [diff] [blame] | 835 | |
| 836 | if (!ec) |
| 837 | { |
| 838 | ec = ipmi::setDbusProperty(ctx, service, hostStatePath, hostStateIntf, |
| 839 | "RequestedHostTransition", request); |
| 840 | } |
| 841 | if (ec) |
| Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 842 | { |
| Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 843 | lg2::error( |
| 844 | "Failed to initiate transition for request {REQUEST}: {EXCEPTION}", |
| 845 | "REQUEST", request, "EXCEPTION", ec.message()); |
| Jason M. Bills | 664e1c3 | 2020-01-30 16:02:39 -0800 | [diff] [blame] | 846 | return -1; |
| Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 847 | } |
| Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 848 | lg2::info( |
| 849 | "Transition request {REQUEST} initiated successfully by user {USERID}", |
| 850 | "REQUEST", request, "USERID", ctx->userId); |
| Jason M. Bills | 664e1c3 | 2020-01-30 16:02:39 -0800 | [diff] [blame] | 851 | return 0; |
| vishwa | 3699327 | 2015-11-20 12:43:49 -0600 | [diff] [blame] | 852 | } |
| 853 | |
| Kuiying Wang | 6b0ceaa | 2019-11-05 15:13:40 +0800 | [diff] [blame] | 854 | //------------------------------------------ |
| Jason M. Bills | ad588bf | 2020-01-30 16:18:33 -0800 | [diff] [blame] | 855 | // Calls into Chassis State Manager Dbus object |
| 856 | //------------------------------------------ |
| 857 | int initiateChassisStateTransition(ipmi::Context::ptr& ctx, |
| 858 | State::Chassis::Transition transition) |
| 859 | { |
| 860 | // OpenBMC Chassis State Manager dbus framework |
| 861 | constexpr auto chassisStatePath = "/xyz/openbmc_project/state/chassis0"; |
| 862 | constexpr auto chassisStateIntf = "xyz.openbmc_project.State.Chassis"; |
| 863 | |
| 864 | std::string service; |
| Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 865 | boost::system::error_code ec = |
| 866 | ipmi::getService(ctx, chassisStateIntf, chassisStatePath, service); |
| Jason M. Bills | ad588bf | 2020-01-30 16:18:33 -0800 | [diff] [blame] | 867 | |
| 868 | // Convert to string equivalent of the passed in transition enum. |
| Willy Tu | 523e2d1 | 2023-09-05 11:36:48 -0700 | [diff] [blame] | 869 | auto request = |
| 870 | sdbusplus::common::xyz::openbmc_project::state::convertForMessage( |
| 871 | transition); |
| Jason M. Bills | ad588bf | 2020-01-30 16:18:33 -0800 | [diff] [blame] | 872 | |
| 873 | if (!ec) |
| 874 | { |
| 875 | ec = ipmi::setDbusProperty(ctx, service, chassisStatePath, |
| 876 | chassisStateIntf, "RequestedPowerTransition", |
| 877 | request); |
| 878 | } |
| 879 | if (ec) |
| 880 | { |
| Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 881 | lg2::error("Failed to initiate transition {REQUEST}: {EXCEPTION}", |
| 882 | "REQUEST", request, "EXCEPTION", ec.message()); |
| 883 | |
| Jason M. Bills | ad588bf | 2020-01-30 16:18:33 -0800 | [diff] [blame] | 884 | return -1; |
| 885 | } |
| 886 | |
| 887 | return 0; |
| 888 | } |
| 889 | |
| 890 | //------------------------------------------ |
| Zev Weiss | 337a097 | 2024-03-08 08:31:15 +0000 | [diff] [blame] | 891 | // Trigger an NMI on the host via dbus |
| Kuiying Wang | 6b0ceaa | 2019-11-05 15:13:40 +0800 | [diff] [blame] | 892 | //------------------------------------------ |
| Zev Weiss | 337a097 | 2024-03-08 08:31:15 +0000 | [diff] [blame] | 893 | static int doNmi(ipmi::Context::ptr& ctx) |
| Kuiying Wang | 6b0ceaa | 2019-11-05 15:13:40 +0800 | [diff] [blame] | 894 | { |
| Zev Weiss | 337a097 | 2024-03-08 08:31:15 +0000 | [diff] [blame] | 895 | constexpr const char* nmiIntfName = "xyz.openbmc_project.Control.Host.NMI"; |
| 896 | ipmi::DbusObjectInfo nmiObj{}; |
| 897 | boost::system::error_code ec; |
| Kuiying Wang | 6b0ceaa | 2019-11-05 15:13:40 +0800 | [diff] [blame] | 898 | |
| Zev Weiss | 337a097 | 2024-03-08 08:31:15 +0000 | [diff] [blame] | 899 | ec = ipmi::getDbusObject(ctx, nmiIntfName, nmiObj); |
| Vernon Mauery | 9bb4a38 | 2021-11-05 12:46:19 -0700 | [diff] [blame] | 900 | if (ec) |
| Kuiying Wang | 6b0ceaa | 2019-11-05 15:13:40 +0800 | [diff] [blame] | 901 | { |
| Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 902 | lg2::error("Failed to find NMI service: {ERROR}", "ERROR", |
| 903 | ec.message()); |
| Zev Weiss | 337a097 | 2024-03-08 08:31:15 +0000 | [diff] [blame] | 904 | return -1; |
| 905 | } |
| 906 | |
| George Liu | de1420d | 2025-03-03 15:14:25 +0800 | [diff] [blame] | 907 | ec = ipmi::callDbusMethod(ctx, nmiObj.second, nmiObj.first, nmiIntfName, |
| 908 | "NMI"); |
| Zev Weiss | 337a097 | 2024-03-08 08:31:15 +0000 | [diff] [blame] | 909 | if (ec) |
| 910 | { |
| Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 911 | lg2::error("NMI call failed: {ERROR}", "ERROR", ec.message()); |
| Zev Weiss | 337a097 | 2024-03-08 08:31:15 +0000 | [diff] [blame] | 912 | elog<InternalFailure>(); |
| Kuiying Wang | 6b0ceaa | 2019-11-05 15:13:40 +0800 | [diff] [blame] | 913 | return -1; |
| 914 | } |
| 915 | |
| 916 | return 0; |
| 917 | } |
| 918 | |
| Deepak Kodihalli | 18b70d1 | 2017-07-21 13:36:33 -0500 | [diff] [blame] | 919 | namespace power_policy |
| Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 920 | { |
| Nan Li | fdd8ec5 | 2016-08-28 03:57:40 +0800 | [diff] [blame] | 921 | |
| Willy Tu | 523e2d1 | 2023-09-05 11:36:48 -0700 | [diff] [blame] | 922 | using namespace sdbusplus::server::xyz::openbmc_project::control::power; |
| Deepak Kodihalli | 18b70d1 | 2017-07-21 13:36:33 -0500 | [diff] [blame] | 923 | using IpmiValue = uint8_t; |
| 924 | using DbusValue = RestorePolicy::Policy; |
| Nan Li | fdd8ec5 | 2016-08-28 03:57:40 +0800 | [diff] [blame] | 925 | |
| Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 926 | const std::map<DbusValue, IpmiValue> dbusToIpmi = { |
| Deepak Kodihalli | 18b70d1 | 2017-07-21 13:36:33 -0500 | [diff] [blame] | 927 | {RestorePolicy::Policy::AlwaysOff, 0x00}, |
| 928 | {RestorePolicy::Policy::Restore, 0x01}, |
| George Liu | e561d3e | 2024-02-04 15:19:30 +0800 | [diff] [blame] | 929 | {RestorePolicy::Policy::AlwaysOn, 0x02}, |
| 930 | {RestorePolicy::Policy::None, 0x03}}; |
| Nan Li | fdd8ec5 | 2016-08-28 03:57:40 +0800 | [diff] [blame] | 931 | |
| Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 932 | static constexpr uint8_t noChange = 0x03; |
| 933 | static constexpr uint8_t allSupport = 0x01 | 0x02 | 0x04; |
| Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 934 | |
| 935 | /* helper function for Get Chassis Status Command |
| 936 | */ |
| 937 | std::optional<uint2_t> getPowerRestorePolicy() |
| 938 | { |
| 939 | uint2_t restorePolicy = 0; |
| 940 | using namespace chassis::internal; |
| 941 | |
| James Feist | 225dec8 | 2019-11-26 16:25:06 -0800 | [diff] [blame] | 942 | settings::Objects& objects = cache::getObjects(); |
| 943 | |
| Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 944 | try |
| 945 | { |
| 946 | const auto& powerRestoreSetting = |
| James Feist | 225dec8 | 2019-11-26 16:25:06 -0800 | [diff] [blame] | 947 | objects.map.at(powerRestoreIntf).front(); |
| Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 948 | ipmi::Value result = ipmi::getDbusProperty( |
| 949 | *getSdBus(), |
| James Feist | 225dec8 | 2019-11-26 16:25:06 -0800 | [diff] [blame] | 950 | objects.service(powerRestoreSetting, powerRestoreIntf).c_str(), |
| Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 951 | powerRestoreSetting.c_str(), powerRestoreIntf, |
| 952 | "PowerRestorePolicy"); |
| 953 | auto powerRestore = RestorePolicy::convertPolicyFromString( |
| 954 | std::get<std::string>(result)); |
| 955 | restorePolicy = dbusToIpmi.at(powerRestore); |
| 956 | } |
| 957 | catch (const std::exception& e) |
| 958 | { |
| Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 959 | lg2::error( |
| 960 | "Failed to fetch pgood property ({PATH}/{INTERFACE}): {ERROR}", |
| 961 | "PATH", objects.map.at(powerRestoreIntf).front(), "INTERFACE", |
| 962 | powerRestoreIntf, "ERROR", e); |
| James Feist | 225dec8 | 2019-11-26 16:25:06 -0800 | [diff] [blame] | 963 | cache::objectsPtr.reset(); |
| Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 964 | return std::nullopt; |
| 965 | } |
| 966 | return std::make_optional(restorePolicy); |
| 967 | } |
| 968 | |
| 969 | /* |
| 970 | * getPowerStatus |
| 971 | * helper function for Get Chassis Status Command |
| 972 | * return - optional value for pgood (no value on error) |
| 973 | */ |
| 974 | std::optional<bool> getPowerStatus() |
| 975 | { |
| Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 976 | bool powerGood = false; |
| 977 | std::shared_ptr<sdbusplus::asio::connection> busp = getSdBus(); |
| 978 | try |
| 979 | { |
| Jason M. Bills | 3de424c | 2019-05-21 09:57:16 -0700 | [diff] [blame] | 980 | constexpr const char* chassisStatePath = |
| 981 | "/xyz/openbmc_project/state/chassis0"; |
| 982 | constexpr const char* chassisStateIntf = |
| 983 | "xyz.openbmc_project.State.Chassis"; |
| Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 984 | auto service = |
| 985 | ipmi::getService(*busp, chassisStateIntf, chassisStatePath); |
| Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 986 | |
| Jason M. Bills | 3de424c | 2019-05-21 09:57:16 -0700 | [diff] [blame] | 987 | ipmi::Value powerState = |
| 988 | ipmi::getDbusProperty(*busp, service, chassisStatePath, |
| 989 | chassisStateIntf, "CurrentPowerState"); |
| Chau Ly | ee3983b | 2024-01-05 07:33:45 +0000 | [diff] [blame] | 990 | std::string powerStateStr = std::get<std::string>(powerState); |
| 991 | if (powerStateStr.ends_with(".On") || |
| 992 | powerStateStr.ends_with(".TransitioningToOff")) |
| 993 | { |
| 994 | powerGood = true; |
| 995 | } |
| Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 996 | } |
| 997 | catch (const std::exception& e) |
| 998 | { |
| 999 | try |
| 1000 | { |
| 1001 | // FIXME: some legacy modules use the older path; try that next |
| 1002 | constexpr const char* legacyPwrCtrlObj = |
| 1003 | "/org/openbmc/control/power0"; |
| 1004 | constexpr const char* legacyPwrCtrlIntf = |
| 1005 | "org.openbmc.control.Power"; |
| Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 1006 | auto service = |
| 1007 | ipmi::getService(*busp, legacyPwrCtrlIntf, legacyPwrCtrlObj); |
| Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1008 | |
| 1009 | ipmi::Value variant = ipmi::getDbusProperty( |
| 1010 | *busp, service, legacyPwrCtrlObj, legacyPwrCtrlIntf, "pgood"); |
| 1011 | powerGood = static_cast<bool>(std::get<int>(variant)); |
| 1012 | } |
| 1013 | catch (const std::exception& e) |
| 1014 | { |
| Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 1015 | lg2::error("Failed to fetch pgood property: {ERROR}", "ERROR", e); |
| Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1016 | return std::nullopt; |
| 1017 | } |
| 1018 | } |
| 1019 | return std::make_optional(powerGood); |
| 1020 | } |
| 1021 | |
| Yong Li | 70ce735 | 2019-05-16 21:15:27 +0800 | [diff] [blame] | 1022 | /* |
| 1023 | * getACFailStatus |
| 1024 | * helper function for Get Chassis Status Command |
| 1025 | * return - bool value for ACFail (false on error) |
| 1026 | */ |
| 1027 | bool getACFailStatus() |
| 1028 | { |
| 1029 | constexpr const char* powerControlObj = |
| 1030 | "/xyz/openbmc_project/Chassis/Control/Power0"; |
| 1031 | constexpr const char* powerControlIntf = |
| 1032 | "xyz.openbmc_project.Chassis.Control.Power"; |
| 1033 | bool acFail = false; |
| 1034 | std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus(); |
| 1035 | try |
| 1036 | { |
| Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 1037 | auto service = |
| 1038 | ipmi::getService(*bus, powerControlIntf, powerControlObj); |
| Yong Li | 70ce735 | 2019-05-16 21:15:27 +0800 | [diff] [blame] | 1039 | |
| 1040 | ipmi::Value variant = ipmi::getDbusProperty( |
| 1041 | *bus, service, powerControlObj, powerControlIntf, "PFail"); |
| 1042 | acFail = std::get<bool>(variant); |
| 1043 | } |
| 1044 | catch (const std::exception& e) |
| 1045 | { |
| Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 1046 | lg2::error( |
| Konstantin Aladyshev | 37de2e1 | 2025-01-29 11:49:26 +0300 | [diff] [blame] | 1047 | "Failed to fetch PFail property ({PATH}/{INTERFACE}): {ERROR}", |
| Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 1048 | "PATH", powerControlObj, "INTERFACE", powerControlIntf, "ERROR", e); |
| Yong Li | 70ce735 | 2019-05-16 21:15:27 +0800 | [diff] [blame] | 1049 | } |
| 1050 | return acFail; |
| 1051 | } |
| Deepak Kodihalli | 18b70d1 | 2017-07-21 13:36:33 -0500 | [diff] [blame] | 1052 | } // namespace power_policy |
| Nan Li | fdd8ec5 | 2016-08-28 03:57:40 +0800 | [diff] [blame] | 1053 | |
| Patrick Williams | 615a14e | 2025-04-07 17:07:24 -0400 | [diff] [blame] | 1054 | static std::optional<bool> getButtonDisabled(ipmi::Context::ptr& ctx, |
| 1055 | const std::string& buttonPath, |
| 1056 | const std::string& buttonIntf) |
| Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1057 | { |
| Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1058 | bool buttonDisabled = false; |
| Konstantin Aladyshev | 2738b9e | 2025-02-15 00:56:19 +0300 | [diff] [blame] | 1059 | boost::system::error_code ec; |
| 1060 | std::string service; |
| 1061 | ec = ipmi::getService(ctx, buttonIntf, buttonPath, service); |
| 1062 | if (!ec) |
| Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1063 | { |
| Konstantin Aladyshev | 2738b9e | 2025-02-15 00:56:19 +0300 | [diff] [blame] | 1064 | bool enabled; |
| 1065 | ec = ipmi::getDbusProperty(ctx, service, buttonPath, buttonIntf, |
| 1066 | "Enabled", enabled); |
| 1067 | buttonDisabled = !enabled; |
| Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1068 | } |
| Konstantin Aladyshev | 2738b9e | 2025-02-15 00:56:19 +0300 | [diff] [blame] | 1069 | |
| 1070 | if (ec) |
| Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1071 | { |
| Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 1072 | lg2::error("Fail to get button Enabled property ({PATH}): {ERROR}", |
| Konstantin Aladyshev | 2738b9e | 2025-02-15 00:56:19 +0300 | [diff] [blame] | 1073 | "PATH", buttonPath, "ERROR", ec.message()); |
| Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1074 | return std::nullopt; |
| 1075 | } |
| 1076 | return std::make_optional(buttonDisabled); |
| 1077 | } |
| 1078 | |
| Konstantin Aladyshev | 305d864 | 2025-02-15 00:36:54 +0300 | [diff] [blame] | 1079 | static bool setButtonDisabled(ipmi::Context::ptr& ctx, |
| 1080 | const std::string& buttonPath, |
| 1081 | const std::string& buttonIntf, bool disable) |
| Kuiying Wang | 21addc5 | 2019-01-04 10:50:21 +0800 | [diff] [blame] | 1082 | { |
| 1083 | std::string service; |
| 1084 | boost::system::error_code ec; |
| 1085 | ec = ipmi::getService(ctx, buttonIntf, buttonPath, service); |
| 1086 | if (!ec) |
| 1087 | { |
| 1088 | ec = ipmi::setDbusProperty(ctx, service, buttonPath, buttonIntf, |
| Konstantin Aladyshev | 305d864 | 2025-02-15 00:36:54 +0300 | [diff] [blame] | 1089 | "Enabled", !disable); |
| Kuiying Wang | 21addc5 | 2019-01-04 10:50:21 +0800 | [diff] [blame] | 1090 | } |
| 1091 | if (ec) |
| 1092 | { |
| Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 1093 | lg2::error( |
| 1094 | "Fail to set button Enabled property ({SERVICE}:{PATH}): {ERROR}", |
| 1095 | "SERVICE", service, "PATH", buttonPath, "ERROR", ec.message()); |
| Kuiying Wang | 21addc5 | 2019-01-04 10:50:21 +0800 | [diff] [blame] | 1096 | return false; |
| 1097 | } |
| 1098 | return true; |
| 1099 | } |
| 1100 | |
| Chau Ly | 9e666cd | 2023-03-06 08:46:14 +0000 | [diff] [blame] | 1101 | static std::optional<bool> getChassisIntrusionStatus(ipmi::Context::ptr& ctx) |
| 1102 | { |
| Chau Ly | 8c1376c | 2024-01-05 07:22:10 +0000 | [diff] [blame] | 1103 | std::vector<std::string> interfaces = {std::string(Intrusion::interface)}; |
| 1104 | ipmi::ObjectTree objs; |
| 1105 | std::string propVal; |
| 1106 | std::optional<bool> ret = std::nullopt; |
| Chau Ly | 9e666cd | 2023-03-06 08:46:14 +0000 | [diff] [blame] | 1107 | |
| Chau Ly | 8c1376c | 2024-01-05 07:22:10 +0000 | [diff] [blame] | 1108 | boost::system::error_code ec = |
| 1109 | ipmi::getSubTree(ctx, interfaces, std::string("/"), 0, objs); |
| 1110 | |
| 1111 | if (ec) |
| Chau Ly | 9e666cd | 2023-03-06 08:46:14 +0000 | [diff] [blame] | 1112 | { |
| Chau Ly | 8c1376c | 2024-01-05 07:22:10 +0000 | [diff] [blame] | 1113 | lg2::error("Fail to find Chassis Intrusion Interface on D-Bus " |
| 1114 | "({INTERFACE}): {ERROR}", |
| 1115 | "INTERFACE", Intrusion::interface, "ERROR", ec.message()); |
| 1116 | return ret; |
| 1117 | } |
| 1118 | |
| 1119 | for (const auto& [path, map] : objs) |
| 1120 | { |
| 1121 | for (const auto& [service, intfs] : map) |
| Chau Ly | 9e666cd | 2023-03-06 08:46:14 +0000 | [diff] [blame] | 1122 | { |
| Chau Ly | 8c1376c | 2024-01-05 07:22:10 +0000 | [diff] [blame] | 1123 | ec = ipmi::getDbusProperty<std::string>( |
| 1124 | ctx, service, path, Intrusion::interface, "Status", propVal); |
| Jayanth Othayoth | 195d552 | 2025-06-07 02:28:07 -0500 | [diff] [blame] | 1125 | |
| Chau Ly | 8c1376c | 2024-01-05 07:22:10 +0000 | [diff] [blame] | 1126 | if (ec) |
| 1127 | { |
| Jayanth Othayoth | 195d552 | 2025-06-07 02:28:07 -0500 | [diff] [blame] | 1128 | lg2::error("Failed to get Chassis Intrusion Status property " |
| Chau Ly | 8c1376c | 2024-01-05 07:22:10 +0000 | [diff] [blame] | 1129 | "({SERVICE}/{PATH}/{INTERFACE}): {ERROR}", |
| 1130 | "SERVICE", service, "PATH", path, "INTERFACE", |
| 1131 | Intrusion::interface, "ERROR", ec.message()); |
| Jayanth Othayoth | 195d552 | 2025-06-07 02:28:07 -0500 | [diff] [blame] | 1132 | continue; |
| Chau Ly | 8c1376c | 2024-01-05 07:22:10 +0000 | [diff] [blame] | 1133 | } |
| Jayanth Othayoth | 195d552 | 2025-06-07 02:28:07 -0500 | [diff] [blame] | 1134 | |
| 1135 | auto statusOpt = |
| 1136 | sdbusplus::message::convert_from_string<Intrusion::Status>( |
| 1137 | propVal); |
| 1138 | if (statusOpt) |
| Chau Ly | 8c1376c | 2024-01-05 07:22:10 +0000 | [diff] [blame] | 1139 | { |
| Jayanth Othayoth | 195d552 | 2025-06-07 02:28:07 -0500 | [diff] [blame] | 1140 | if (*statusOpt == Intrusion::Status::Normal) |
| Chau Ly | 8c1376c | 2024-01-05 07:22:10 +0000 | [diff] [blame] | 1141 | { |
| 1142 | ret = std::make_optional(false); |
| 1143 | } |
| 1144 | else |
| 1145 | { |
| 1146 | ret = std::make_optional(true); |
| Jayanth Othayoth | 195d552 | 2025-06-07 02:28:07 -0500 | [diff] [blame] | 1147 | return ret; // Early return on first non-Normal status |
| Chau Ly | 8c1376c | 2024-01-05 07:22:10 +0000 | [diff] [blame] | 1148 | } |
| 1149 | } |
| Jayanth Othayoth | 195d552 | 2025-06-07 02:28:07 -0500 | [diff] [blame] | 1150 | else |
| 1151 | { |
| 1152 | lg2::warning( |
| 1153 | "Invalid Intrusion::Status value received: {VALUE}", |
| 1154 | "VALUE", propVal); |
| 1155 | return std::nullopt; |
| 1156 | } |
| Chau Ly | 9e666cd | 2023-03-06 08:46:14 +0000 | [diff] [blame] | 1157 | } |
| 1158 | } |
| Chau Ly | 8c1376c | 2024-01-05 07:22:10 +0000 | [diff] [blame] | 1159 | return ret; |
| Chau Ly | 9e666cd | 2023-03-06 08:46:14 +0000 | [diff] [blame] | 1160 | } |
| 1161 | |
| Nan Li | fdd8ec5 | 2016-08-28 03:57:40 +0800 | [diff] [blame] | 1162 | //---------------------------------------------------------------------- |
| 1163 | // Get Chassis Status commands |
| 1164 | //---------------------------------------------------------------------- |
| Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1165 | ipmi::RspType<bool, // Power is on |
| 1166 | bool, // Power overload |
| 1167 | bool, // Interlock |
| 1168 | bool, // power fault |
| 1169 | bool, // power control fault |
| 1170 | uint2_t, // power restore policy |
| 1171 | bool, // reserved |
| 1172 | |
| Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 1173 | bool, // AC failed |
| 1174 | bool, // last power down caused by a Power overload |
| 1175 | bool, // last power down caused by a power interlock |
| 1176 | bool, // last power down caused by power fault |
| Patrick Williams | 99db688 | 2024-12-18 11:20:17 -0500 | [diff] [blame] | 1177 | bool, // last ‘Power is on’ state was entered via IPMI command |
| Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1178 | uint3_t, // reserved |
| 1179 | |
| 1180 | bool, // Chassis intrusion active |
| 1181 | bool, // Front Panel Lockout active |
| 1182 | bool, // Drive Fault |
| 1183 | bool, // Cooling/fan fault detected |
| 1184 | uint2_t, // Chassis Identify State |
| 1185 | bool, // Chassis Identify command and state info supported |
| 1186 | bool, // reserved |
| 1187 | |
| Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 1188 | bool, // Power off button disabled |
| 1189 | bool, // Reset button disabled |
| 1190 | bool, // Diagnostic Interrupt button disabled |
| 1191 | bool, // Standby (sleep) button disabled |
| 1192 | bool, // Power off button disable allowed |
| 1193 | bool, // Reset button disable allowed |
| 1194 | bool, // Diagnostic Interrupt button disable allowed |
| 1195 | bool // Standby (sleep) button disable allowed |
| Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1196 | > |
| Chau Ly | 9e666cd | 2023-03-06 08:46:14 +0000 | [diff] [blame] | 1197 | ipmiGetChassisStatus(ipmi::Context::ptr& ctx) |
| Nan Li | fdd8ec5 | 2016-08-28 03:57:40 +0800 | [diff] [blame] | 1198 | { |
| Deepak Kodihalli | 18b70d1 | 2017-07-21 13:36:33 -0500 | [diff] [blame] | 1199 | using namespace chassis::internal; |
| Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1200 | std::optional<uint2_t> restorePolicy = |
| 1201 | power_policy::getPowerRestorePolicy(); |
| 1202 | std::optional<bool> powerGood = power_policy::getPowerStatus(); |
| 1203 | if (!restorePolicy || !powerGood) |
| Deepak Kodihalli | 18b70d1 | 2017-07-21 13:36:33 -0500 | [diff] [blame] | 1204 | { |
| Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1205 | return ipmi::responseUnspecifiedError(); |
| Deepak Kodihalli | 18b70d1 | 2017-07-21 13:36:33 -0500 | [diff] [blame] | 1206 | } |
| Nan Li | fdd8ec5 | 2016-08-28 03:57:40 +0800 | [diff] [blame] | 1207 | |
| 1208 | // Front Panel Button Capabilities and disable/enable status(Optional) |
| Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 1209 | std::optional<bool> powerButtonReading = |
| Konstantin Aladyshev | 2738b9e | 2025-02-15 00:56:19 +0300 | [diff] [blame] | 1210 | getButtonDisabled(ctx, powerButtonPath, powerButtonIntf); |
| Vernon Mauery | 6d5b2f7 | 2019-05-16 14:48:47 -0700 | [diff] [blame] | 1211 | // allow disable if the interface is present |
| 1212 | bool powerButtonDisableAllow = static_cast<bool>(powerButtonReading); |
| 1213 | // default return the button is enabled (not disabled) |
| 1214 | bool powerButtonDisabled = false; |
| 1215 | if (powerButtonDisableAllow) |
| Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1216 | { |
| Vernon Mauery | 6d5b2f7 | 2019-05-16 14:48:47 -0700 | [diff] [blame] | 1217 | // return the real value of the button status, if present |
| 1218 | powerButtonDisabled = *powerButtonReading; |
| 1219 | } |
| 1220 | |
| Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 1221 | std::optional<bool> resetButtonReading = |
| Konstantin Aladyshev | 2738b9e | 2025-02-15 00:56:19 +0300 | [diff] [blame] | 1222 | getButtonDisabled(ctx, resetButtonPath, resetButtonIntf); |
| Vernon Mauery | 6d5b2f7 | 2019-05-16 14:48:47 -0700 | [diff] [blame] | 1223 | // allow disable if the interface is present |
| 1224 | bool resetButtonDisableAllow = static_cast<bool>(resetButtonReading); |
| 1225 | // default return the button is enabled (not disabled) |
| 1226 | bool resetButtonDisabled = false; |
| 1227 | if (resetButtonDisableAllow) |
| 1228 | { |
| 1229 | // return the real value of the button status, if present |
| 1230 | resetButtonDisabled = *resetButtonReading; |
| Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1231 | } |
| Nan Li | fdd8ec5 | 2016-08-28 03:57:40 +0800 | [diff] [blame] | 1232 | |
| Yong Li | 70ce735 | 2019-05-16 21:15:27 +0800 | [diff] [blame] | 1233 | bool powerDownAcFailed = power_policy::getACFailStatus(); |
| 1234 | |
| Chau Ly | 9e666cd | 2023-03-06 08:46:14 +0000 | [diff] [blame] | 1235 | bool chassisIntrusionActive = false; |
| 1236 | std::optional<bool> chassisIntrusionStatus = getChassisIntrusionStatus(ctx); |
| 1237 | if (chassisIntrusionStatus) |
| 1238 | { |
| 1239 | chassisIntrusionActive = chassisIntrusionStatus.value(); |
| 1240 | } |
| 1241 | |
| Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1242 | // This response has a lot of hard-coded, unsupported fields |
| 1243 | // They are set to false or 0 |
| 1244 | constexpr bool powerOverload = false; |
| 1245 | constexpr bool chassisInterlock = false; |
| 1246 | constexpr bool powerFault = false; |
| 1247 | constexpr bool powerControlFault = false; |
| Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1248 | constexpr bool powerDownOverload = false; |
| 1249 | constexpr bool powerDownInterlock = false; |
| 1250 | constexpr bool powerDownPowerFault = false; |
| 1251 | constexpr bool powerStatusIPMI = false; |
| Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1252 | constexpr bool frontPanelLockoutActive = false; |
| 1253 | constexpr bool driveFault = false; |
| 1254 | constexpr bool coolingFanFault = false; |
| 1255 | // chassisIdentifySupport set because this command is implemented |
| 1256 | constexpr bool chassisIdentifySupport = true; |
| William A. Kennington III | 7a0e5df | 2021-05-19 13:31:29 -0700 | [diff] [blame] | 1257 | uint2_t chassisIdentifyState = types::enum_cast<uint2_t>(chassisIDState); |
| Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1258 | constexpr bool diagButtonDisabled = false; |
| 1259 | constexpr bool sleepButtonDisabled = false; |
| 1260 | constexpr bool diagButtonDisableAllow = false; |
| 1261 | constexpr bool sleepButtonDisableAllow = false; |
| 1262 | |
| 1263 | return ipmi::responseSuccess( |
| 1264 | *powerGood, powerOverload, chassisInterlock, powerFault, |
| 1265 | powerControlFault, *restorePolicy, |
| 1266 | false, // reserved |
| 1267 | |
| 1268 | powerDownAcFailed, powerDownOverload, powerDownInterlock, |
| 1269 | powerDownPowerFault, powerStatusIPMI, |
| 1270 | uint3_t(0), // reserved |
| 1271 | |
| 1272 | chassisIntrusionActive, frontPanelLockoutActive, driveFault, |
| 1273 | coolingFanFault, chassisIdentifyState, chassisIdentifySupport, |
| 1274 | false, // reserved |
| 1275 | |
| Vernon Mauery | 6d5b2f7 | 2019-05-16 14:48:47 -0700 | [diff] [blame] | 1276 | powerButtonDisabled, resetButtonDisabled, diagButtonDisabled, |
| Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1277 | sleepButtonDisabled, powerButtonDisableAllow, resetButtonDisableAllow, |
| 1278 | diagButtonDisableAllow, sleepButtonDisableAllow); |
| Nan Li | fdd8ec5 | 2016-08-28 03:57:40 +0800 | [diff] [blame] | 1279 | } |
| Chris Austen | 7888c4d | 2015-12-03 15:26:20 -0600 | [diff] [blame] | 1280 | |
| Vijay Khemka | 074f64d | 2020-03-03 15:08:43 -0800 | [diff] [blame] | 1281 | enum class IpmiRestartCause |
| 1282 | { |
| 1283 | Unknown = 0x0, |
| 1284 | RemoteCommand = 0x1, |
| 1285 | ResetButton = 0x2, |
| 1286 | PowerButton = 0x3, |
| 1287 | WatchdogTimer = 0x4, |
| 1288 | PowerPolicyAlwaysOn = 0x6, |
| 1289 | PowerPolicyPreviousState = 0x7, |
| 1290 | SoftReset = 0xa, |
| 1291 | }; |
| 1292 | |
| Patrick Williams | 69b4c28 | 2025-03-03 11:19:13 -0500 | [diff] [blame] | 1293 | static IpmiRestartCause restartCauseToIpmiRestartCause( |
| 1294 | State::Host::RestartCause cause) |
| Vijay Khemka | 074f64d | 2020-03-03 15:08:43 -0800 | [diff] [blame] | 1295 | { |
| 1296 | switch (cause) |
| 1297 | { |
| 1298 | case State::Host::RestartCause::Unknown: |
| 1299 | { |
| 1300 | return IpmiRestartCause::Unknown; |
| 1301 | } |
| 1302 | case State::Host::RestartCause::RemoteCommand: |
| 1303 | { |
| 1304 | return IpmiRestartCause::RemoteCommand; |
| 1305 | } |
| 1306 | case State::Host::RestartCause::ResetButton: |
| 1307 | { |
| 1308 | return IpmiRestartCause::ResetButton; |
| 1309 | } |
| 1310 | case State::Host::RestartCause::PowerButton: |
| 1311 | { |
| 1312 | return IpmiRestartCause::PowerButton; |
| 1313 | } |
| 1314 | case State::Host::RestartCause::WatchdogTimer: |
| 1315 | { |
| 1316 | return IpmiRestartCause::WatchdogTimer; |
| 1317 | } |
| 1318 | case State::Host::RestartCause::PowerPolicyAlwaysOn: |
| 1319 | { |
| 1320 | return IpmiRestartCause::PowerPolicyAlwaysOn; |
| 1321 | } |
| 1322 | case State::Host::RestartCause::PowerPolicyPreviousState: |
| 1323 | { |
| 1324 | return IpmiRestartCause::PowerPolicyPreviousState; |
| 1325 | } |
| 1326 | case State::Host::RestartCause::SoftReset: |
| 1327 | { |
| 1328 | return IpmiRestartCause::SoftReset; |
| 1329 | } |
| 1330 | default: |
| 1331 | { |
| 1332 | return IpmiRestartCause::Unknown; |
| 1333 | } |
| 1334 | } |
| 1335 | } |
| 1336 | |
| 1337 | /* |
| 1338 | * getRestartCause |
| 1339 | * helper function for Get Host restart cause Command |
| 1340 | * return - optional value for RestartCause (no value on error) |
| 1341 | */ |
| 1342 | static std::optional<uint4_t> getRestartCause(ipmi::Context::ptr ctx) |
| 1343 | { |
| okashany | ced0ddf | 2023-05-18 18:35:09 +0000 | [diff] [blame] | 1344 | constexpr const char* restartCausePath = "/xyz/openbmc_project/state/host0"; |
| 1345 | constexpr const char* restartCauseIntf = "xyz.openbmc_project.State.Host"; |
| Vijay Khemka | 074f64d | 2020-03-03 15:08:43 -0800 | [diff] [blame] | 1346 | |
| 1347 | std::string service; |
| Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 1348 | boost::system::error_code ec = |
| 1349 | ipmi::getService(ctx, restartCauseIntf, restartCausePath, service); |
| Vijay Khemka | 074f64d | 2020-03-03 15:08:43 -0800 | [diff] [blame] | 1350 | if (!ec) |
| 1351 | { |
| 1352 | std::string restartCauseStr; |
| 1353 | ec = ipmi::getDbusProperty<std::string>( |
| 1354 | ctx, service, restartCausePath, restartCauseIntf, "RestartCause", |
| 1355 | restartCauseStr); |
| 1356 | if (!ec) |
| 1357 | { |
| 1358 | auto cause = |
| 1359 | State::Host::convertRestartCauseFromString(restartCauseStr); |
| William A. Kennington III | 7a0e5df | 2021-05-19 13:31:29 -0700 | [diff] [blame] | 1360 | return types::enum_cast<uint4_t>( |
| 1361 | restartCauseToIpmiRestartCause(cause)); |
| Vijay Khemka | 074f64d | 2020-03-03 15:08:43 -0800 | [diff] [blame] | 1362 | } |
| 1363 | } |
| 1364 | |
| Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 1365 | lg2::error( |
| 1366 | "Failed to fetch RestartCause property ({PATH}/{INTERFACE}): {ERROR}", |
| 1367 | "ERROR", ec.message(), "PATH", restartCausePath, "INTERFACE", |
| 1368 | restartCauseIntf); |
| Vijay Khemka | 074f64d | 2020-03-03 15:08:43 -0800 | [diff] [blame] | 1369 | return std::nullopt; |
| 1370 | } |
| 1371 | |
| 1372 | ipmi::RspType<uint4_t, // Restart Cause |
| 1373 | uint4_t, // reserved |
| 1374 | uint8_t // channel number (not supported) |
| 1375 | > |
| 1376 | ipmiGetSystemRestartCause(ipmi::Context::ptr ctx) |
| 1377 | { |
| 1378 | std::optional<uint4_t> cause = getRestartCause(ctx); |
| 1379 | if (!cause) |
| 1380 | { |
| 1381 | return ipmi::responseUnspecifiedError(); |
| 1382 | } |
| 1383 | |
| Vernon Mauery | 916d423 | 2021-03-29 13:42:16 -0700 | [diff] [blame] | 1384 | constexpr uint4_t reserved = 0; |
| 1385 | auto channel = static_cast<uint8_t>(ctx->channel); |
| 1386 | return ipmi::responseSuccess(cause.value(), reserved, channel); |
| Vijay Khemka | 074f64d | 2020-03-03 15:08:43 -0800 | [diff] [blame] | 1387 | } |
| anil kumar appana | dafff5f | 2019-04-27 18:06:00 +0000 | [diff] [blame] | 1388 | /** @brief Implementation of chassis control command |
| 1389 | * |
| 1390 | * @param - chassisControl command byte |
| 1391 | * |
| 1392 | * @return Success or InvalidFieldRequest. |
| 1393 | */ |
| Jason M. Bills | 664e1c3 | 2020-01-30 16:02:39 -0800 | [diff] [blame] | 1394 | ipmi::RspType<> ipmiChassisControl(ipmi::Context::ptr& ctx, |
| 1395 | uint8_t chassisControl) |
| vishwa | 3699327 | 2015-11-20 12:43:49 -0600 | [diff] [blame] | 1396 | { |
| Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 1397 | int rc = 0; |
| anil kumar appana | dafff5f | 2019-04-27 18:06:00 +0000 | [diff] [blame] | 1398 | switch (chassisControl) |
| Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 1399 | { |
| George Liu | 8f4717c | 2025-07-03 09:22:34 +0800 | [diff] [blame] | 1400 | case cmdPowerOn: |
| Jason M. Bills | 664e1c3 | 2020-01-30 16:02:39 -0800 | [diff] [blame] | 1401 | rc = initiateHostStateTransition(ctx, State::Host::Transition::On); |
| Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 1402 | break; |
| George Liu | 8f4717c | 2025-07-03 09:22:34 +0800 | [diff] [blame] | 1403 | case cmdPowerOff: |
| Jason M. Bills | c2c3a40 | 2020-01-30 16:22:24 -0800 | [diff] [blame] | 1404 | rc = initiateChassisStateTransition( |
| 1405 | ctx, State::Chassis::Transition::Off); |
| 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 cmdHardReset: |
| Jason M. Bills | 664e1c3 | 2020-01-30 16:02:39 -0800 | [diff] [blame] | 1408 | rc = initiateHostStateTransition( |
| 1409 | ctx, State::Host::Transition::ForceWarmReboot); |
| Chanh Nguyen | d0a7fcd | 2021-07-16 22:59:28 +0700 | [diff] [blame] | 1410 | break; |
| George Liu | 8f4717c | 2025-07-03 09:22:34 +0800 | [diff] [blame] | 1411 | case cmdPowerCycle: |
| Thang Tran | a7d592c | 2025-09-17 03:43:14 +0000 | [diff] [blame] | 1412 | { |
| 1413 | auto powerState = power_policy::getPowerStatus(); |
| 1414 | |
| 1415 | if (powerState == std::nullopt) |
| 1416 | { |
| 1417 | return ipmi::responseUnspecifiedError(); |
| 1418 | } |
| 1419 | |
| 1420 | /* |
| 1421 | * As define in the Chapter 28.3 - Chassis Control Command of IPMI |
| 1422 | * specification: It is recommended that no action occur if system |
| 1423 | * power is off (S4/S5) when this action is selected, and that a D5 |
| 1424 | * "Requiest parameter(s) not supported in this presenst state." |
| 1425 | * error completion code be returned. |
| 1426 | */ |
| 1427 | if (powerState.value() == false) |
| 1428 | { |
| 1429 | return ipmi::responseCommandNotAvailable(); |
| 1430 | } |
| 1431 | |
| Jason M. Bills | 664e1c3 | 2020-01-30 16:02:39 -0800 | [diff] [blame] | 1432 | rc = initiateHostStateTransition(ctx, |
| 1433 | State::Host::Transition::Reboot); |
| Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 1434 | break; |
| Thang Tran | a7d592c | 2025-09-17 03:43:14 +0000 | [diff] [blame] | 1435 | } |
| George Liu | 8f4717c | 2025-07-03 09:22:34 +0800 | [diff] [blame] | 1436 | case cmdSoftOffViaOverTemp: |
| Jason M. Bills | 664e1c3 | 2020-01-30 16:02:39 -0800 | [diff] [blame] | 1437 | rc = initiateHostStateTransition(ctx, State::Host::Transition::Off); |
| Vishwanatha Subbanna | 8b26d35 | 2017-08-04 18:35:18 +0530 | [diff] [blame] | 1438 | break; |
| George Liu | 8f4717c | 2025-07-03 09:22:34 +0800 | [diff] [blame] | 1439 | case cmdPulseDiagnosticInterrupt: |
| Zev Weiss | 337a097 | 2024-03-08 08:31:15 +0000 | [diff] [blame] | 1440 | rc = doNmi(ctx); |
| Kuiying Wang | 6b0ceaa | 2019-11-05 15:13:40 +0800 | [diff] [blame] | 1441 | break; |
| 1442 | |
| Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 1443 | default: |
| 1444 | { |
| Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 1445 | lg2::error("Invalid Chassis Control command: {CMD}", "CMD", |
| 1446 | lg2::hex, chassisControl); |
| anil kumar appana | dafff5f | 2019-04-27 18:06:00 +0000 | [diff] [blame] | 1447 | return ipmi::responseInvalidFieldRequest(); |
| Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 1448 | } |
| 1449 | } |
| vishwa | 3699327 | 2015-11-20 12:43:49 -0600 | [diff] [blame] | 1450 | |
| anil kumar appana | dafff5f | 2019-04-27 18:06:00 +0000 | [diff] [blame] | 1451 | return ((rc < 0) ? ipmi::responseUnspecifiedError() |
| 1452 | : ipmi::responseSuccess()); |
| vishwa | 3699327 | 2015-11-20 12:43:49 -0600 | [diff] [blame] | 1453 | } |
| 1454 | |
| Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1455 | /** @brief Return D-Bus connection string to enclosure identify LED object |
| 1456 | * |
| 1457 | * @param[in, out] connection - connection to D-Bus object |
| 1458 | * @return a IPMI return code |
| 1459 | */ |
| 1460 | std::string getEnclosureIdentifyConnection() |
| Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 1461 | { |
| Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 1462 | // lookup enclosure_identify group owner(s) in mapper |
| George Liu | 3e3cc35 | 2023-07-26 15:59:31 +0800 | [diff] [blame] | 1463 | try |
| Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 1464 | { |
| George Liu | 3e3cc35 | 2023-07-26 15:59:31 +0800 | [diff] [blame] | 1465 | return ipmi::getService(*getSdBus(), "xyz.openbmc_project.Led.Group", |
| 1466 | identify_led_object_name); |
| 1467 | } |
| 1468 | catch (const std::exception& e) |
| 1469 | { |
| Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 1470 | lg2::error("Chassis Identify: Error communicating to mapper: {ERROR}", |
| 1471 | "ERROR", e); |
| Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1472 | elog<InternalFailure>(); |
| Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 1473 | } |
| Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1474 | } |
| Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 1475 | |
| Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1476 | /** @brief Turn On/Off enclosure identify LED |
| 1477 | * |
| 1478 | * @param[in] flag - true to turn on LED, false to turn off |
| 1479 | * @return a IPMI return code |
| 1480 | */ |
| 1481 | void enclosureIdentifyLed(bool flag) |
| 1482 | { |
| 1483 | using namespace chassis::internal; |
| George Liu | cbe50fd | 2025-08-21 16:51:33 +0800 | [diff] [blame] | 1484 | |
| 1485 | std::string connection = getEnclosureIdentifyConnection(); |
| 1486 | |
| 1487 | lg2::debug("enclosureIdentifyLed({FLAG})", "FLAG", flag); |
| 1488 | |
| George Liu | 3e3cc35 | 2023-07-26 15:59:31 +0800 | [diff] [blame] | 1489 | try |
| 1490 | { |
| George Liu | 3e3cc35 | 2023-07-26 15:59:31 +0800 | [diff] [blame] | 1491 | ipmi::setDbusProperty(*getSdBus(), connection, identify_led_object_name, |
| 1492 | "xyz.openbmc_project.Led.Group", "Asserted", |
| 1493 | flag); |
| 1494 | } |
| 1495 | catch (const std::exception& e) |
| Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1496 | { |
| Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 1497 | lg2::error("Chassis Identify: Error Setting State {LED_STATE}: {ERROR}", |
| 1498 | "LED_STATE", flag, "ERROR", e); |
| Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1499 | elog<InternalFailure>(); |
| 1500 | } |
| 1501 | } |
| 1502 | |
| 1503 | /** @brief Callback method to turn off LED |
| 1504 | */ |
| 1505 | void enclosureIdentifyLedOff() |
| 1506 | { |
| 1507 | try |
| 1508 | { |
| Yong Li | f4e3851 | 2019-05-21 14:46:55 +0800 | [diff] [blame] | 1509 | chassisIDState = ChassisIDState::off; |
| Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1510 | enclosureIdentifyLed(false); |
| 1511 | } |
| 1512 | catch (const InternalFailure& e) |
| 1513 | { |
| 1514 | report<InternalFailure>(); |
| 1515 | } |
| 1516 | } |
| 1517 | |
| 1518 | /** @brief Create timer to turn on and off the enclosure LED |
| 1519 | */ |
| 1520 | void createIdentifyTimer() |
| 1521 | { |
| 1522 | if (!identifyTimer) |
| 1523 | { |
| Vernon Mauery | 1181af7 | 2018-10-08 12:05:00 -0700 | [diff] [blame] | 1524 | identifyTimer = |
| Patrick Williams | 9565522 | 2023-12-05 12:45:02 -0600 | [diff] [blame] | 1525 | std::make_unique<sdbusplus::Timer>(enclosureIdentifyLedOff); |
| Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1526 | } |
| 1527 | } |
| 1528 | |
| Vernon Mauery | 400cc78 | 2018-10-09 13:49:53 -0700 | [diff] [blame] | 1529 | ipmi::RspType<> ipmiChassisIdentify(std::optional<uint8_t> interval, |
| 1530 | std::optional<uint8_t> force) |
| Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1531 | { |
| Vernon Mauery | 400cc78 | 2018-10-09 13:49:53 -0700 | [diff] [blame] | 1532 | uint8_t identifyInterval = interval.value_or(DEFAULT_IDENTIFY_TIME_OUT); |
| 1533 | bool forceIdentify = force.value_or(0) & 0x01; |
| Tom Joseph | bed2699 | 2018-07-31 23:00:24 +0530 | [diff] [blame] | 1534 | |
| Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1535 | if (identifyInterval || forceIdentify) |
| 1536 | { |
| Vernon Mauery | 400cc78 | 2018-10-09 13:49:53 -0700 | [diff] [blame] | 1537 | // stop the timer if already started; |
| 1538 | // for force identify we should not turn off LED |
| Vernon Mauery | 1181af7 | 2018-10-08 12:05:00 -0700 | [diff] [blame] | 1539 | identifyTimer->stop(); |
| Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1540 | try |
| Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 1541 | { |
| Yong Li | f4e3851 | 2019-05-21 14:46:55 +0800 | [diff] [blame] | 1542 | chassisIDState = ChassisIDState::temporaryOn; |
| Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1543 | enclosureIdentifyLed(true); |
| 1544 | } |
| 1545 | catch (const InternalFailure& e) |
| 1546 | { |
| 1547 | report<InternalFailure>(); |
| Vernon Mauery | 400cc78 | 2018-10-09 13:49:53 -0700 | [diff] [blame] | 1548 | return ipmi::responseResponseError(); |
| Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 1549 | } |
| 1550 | |
| Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1551 | if (forceIdentify) |
| Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 1552 | { |
| Yong Li | f4e3851 | 2019-05-21 14:46:55 +0800 | [diff] [blame] | 1553 | chassisIDState = ChassisIDState::indefiniteOn; |
| Vernon Mauery | 400cc78 | 2018-10-09 13:49:53 -0700 | [diff] [blame] | 1554 | return ipmi::responseSuccess(); |
| Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1555 | } |
| 1556 | // start the timer |
| 1557 | auto time = std::chrono::duration_cast<std::chrono::microseconds>( |
| Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1558 | std::chrono::seconds(identifyInterval)); |
| Vernon Mauery | 1181af7 | 2018-10-08 12:05:00 -0700 | [diff] [blame] | 1559 | identifyTimer->start(time); |
| Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 1560 | } |
| Tom Joseph | bed2699 | 2018-07-31 23:00:24 +0530 | [diff] [blame] | 1561 | else if (!identifyInterval) |
| 1562 | { |
| Vernon Mauery | 1181af7 | 2018-10-08 12:05:00 -0700 | [diff] [blame] | 1563 | identifyTimer->stop(); |
| Tom Joseph | bed2699 | 2018-07-31 23:00:24 +0530 | [diff] [blame] | 1564 | enclosureIdentifyLedOff(); |
| 1565 | } |
| Vernon Mauery | 400cc78 | 2018-10-09 13:49:53 -0700 | [diff] [blame] | 1566 | return ipmi::responseSuccess(); |
| Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 1567 | } |
| 1568 | |
| Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1569 | namespace boot_options |
| 1570 | { |
| 1571 | |
| Willy Tu | 523e2d1 | 2023-09-05 11:36:48 -0700 | [diff] [blame] | 1572 | using namespace sdbusplus::server::xyz::openbmc_project::control::boot; |
| Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1573 | using IpmiValue = uint8_t; |
| 1574 | constexpr auto ipmiDefault = 0; |
| 1575 | |
| Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 1576 | std::map<IpmiValue, Type::Types> typeIpmiToDbus = {{0x00, Type::Types::Legacy}, |
| 1577 | {0x01, Type::Types::EFI}}; |
| 1578 | |
| Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1579 | std::map<IpmiValue, Source::Sources> sourceIpmiToDbus = { |
| Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1580 | {0x01, Source::Sources::Network}, |
| 1581 | {0x02, Source::Sources::Disk}, |
| 1582 | {0x05, Source::Sources::ExternalMedia}, |
| Jia, chunhui | 67c5e5d | 2019-05-06 11:29:54 +0800 | [diff] [blame] | 1583 | {0x0f, Source::Sources::RemovableMedia}, |
| Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1584 | {ipmiDefault, Source::Sources::Default}}; |
| shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 1585 | |
| Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1586 | std::map<IpmiValue, Mode::Modes> modeIpmiToDbus = { |
| Yong Li | 5833cb6 | 2019-10-30 13:27:12 +0800 | [diff] [blame] | 1587 | #ifdef ENABLE_BOOT_FLAG_SAFE_MODE_SUPPORT |
| Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1588 | {0x03, Mode::Modes::Safe}, |
| Yong Li | 5833cb6 | 2019-10-30 13:27:12 +0800 | [diff] [blame] | 1589 | #endif // ENABLE_BOOT_SAFE_MODE_SUPPORT |
| Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1590 | {0x06, Mode::Modes::Setup}, |
| Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1591 | {ipmiDefault, Mode::Modes::Regular}}; |
| shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 1592 | |
| Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 1593 | std::map<Type::Types, IpmiValue> typeDbusToIpmi = {{Type::Types::Legacy, 0x00}, |
| 1594 | {Type::Types::EFI, 0x01}}; |
| 1595 | |
| Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1596 | std::map<Source::Sources, IpmiValue> sourceDbusToIpmi = { |
| Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1597 | {Source::Sources::Network, 0x01}, |
| 1598 | {Source::Sources::Disk, 0x02}, |
| 1599 | {Source::Sources::ExternalMedia, 0x05}, |
| Jia, chunhui | 67c5e5d | 2019-05-06 11:29:54 +0800 | [diff] [blame] | 1600 | {Source::Sources::RemovableMedia, 0x0f}, |
| Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1601 | {Source::Sources::Default, ipmiDefault}}; |
| shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 1602 | |
| Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1603 | std::map<Mode::Modes, IpmiValue> modeDbusToIpmi = { |
| Yong Li | 5833cb6 | 2019-10-30 13:27:12 +0800 | [diff] [blame] | 1604 | #ifdef ENABLE_BOOT_FLAG_SAFE_MODE_SUPPORT |
| Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1605 | {Mode::Modes::Safe, 0x03}, |
| Yong Li | 5833cb6 | 2019-10-30 13:27:12 +0800 | [diff] [blame] | 1606 | #endif // ENABLE_BOOT_SAFE_MODE_SUPPORT |
| Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1607 | {Mode::Modes::Setup, 0x06}, |
| Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1608 | {Mode::Modes::Regular, ipmiDefault}}; |
| shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 1609 | |
| Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1610 | } // namespace boot_options |
| shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 1611 | |
| Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1612 | /** @brief Get the property value for boot source |
| 1613 | * @param[in] ctx - context pointer |
| 1614 | * @param[out] source - boot source value |
| 1615 | * @return On failure return IPMI error. |
| 1616 | */ |
| 1617 | static ipmi::Cc getBootSource(ipmi::Context::ptr& ctx, Source::Sources& source) |
| 1618 | { |
| 1619 | using namespace chassis::internal; |
| 1620 | std::string result; |
| 1621 | std::string service; |
| Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 1622 | boost::system::error_code ec = |
| 1623 | getService(ctx, bootSourceIntf, bootSettingsPath, service); |
| Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1624 | if (!ec) |
| 1625 | { |
| 1626 | ec = ipmi::getDbusProperty(ctx, service, bootSettingsPath, |
| 1627 | bootSourceIntf, "BootSource", result); |
| 1628 | if (!ec) |
| 1629 | { |
| 1630 | source = Source::convertSourcesFromString(result); |
| 1631 | return ipmi::ccSuccess; |
| 1632 | } |
| 1633 | } |
| Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 1634 | lg2::error("Error in BootSource Get: {ERROR}", "ERROR", ec.message()); |
| Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1635 | return ipmi::ccUnspecifiedError; |
| 1636 | } |
| 1637 | |
| Marri Devender Rao | 8171970 | 2018-05-07 00:53:48 -0500 | [diff] [blame] | 1638 | /** @brief Set the property value for boot source |
| Konstantin Aladyshev | e76a61a | 2021-03-18 22:19:13 +0300 | [diff] [blame] | 1639 | * @param[in] ctx - context pointer |
| Marri Devender Rao | 8171970 | 2018-05-07 00:53:48 -0500 | [diff] [blame] | 1640 | * @param[in] source - boot source value |
| 1641 | * @return On failure return IPMI error. |
| 1642 | */ |
| Jayaprakash Mutyala | 6088e9f | 2021-07-14 07:40:29 +0000 | [diff] [blame] | 1643 | static ipmi::Cc setBootSource(ipmi::Context::ptr& ctx, |
| 1644 | const Source::Sources& source) |
| Marri Devender Rao | 8171970 | 2018-05-07 00:53:48 -0500 | [diff] [blame] | 1645 | { |
| 1646 | using namespace chassis::internal; |
| Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1647 | std::string service; |
| Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 1648 | boost::system::error_code ec = |
| 1649 | getService(ctx, bootSourceIntf, bootSettingsPath, service); |
| Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1650 | if (!ec) |
| Marri Devender Rao | 8171970 | 2018-05-07 00:53:48 -0500 | [diff] [blame] | 1651 | { |
| Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1652 | ec = ipmi::setDbusProperty(ctx, service, bootSettingsPath, |
| 1653 | bootSourceIntf, "BootSource", |
| 1654 | convertForMessage(source)); |
| 1655 | if (!ec) |
| 1656 | { |
| 1657 | return ipmi::ccSuccess; |
| 1658 | } |
| Marri Devender Rao | 8171970 | 2018-05-07 00:53:48 -0500 | [diff] [blame] | 1659 | } |
| Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 1660 | lg2::error("Error in BootSource Set: {ERROR}", "ERROR", ec.message()); |
| Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1661 | return ipmi::ccUnspecifiedError; |
| 1662 | } |
| 1663 | |
| 1664 | /** @brief Get the property value for boot mode |
| 1665 | * @param[in] ctx - context pointer |
| 1666 | * @param[out] mode - boot mode value |
| 1667 | * @return On failure return IPMI error. |
| 1668 | */ |
| 1669 | static ipmi::Cc getBootMode(ipmi::Context::ptr& ctx, Mode::Modes& mode) |
| 1670 | { |
| 1671 | using namespace chassis::internal; |
| 1672 | std::string result; |
| 1673 | std::string service; |
| Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 1674 | boost::system::error_code ec = |
| 1675 | getService(ctx, bootModeIntf, bootSettingsPath, service); |
| Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1676 | if (!ec) |
| 1677 | { |
| 1678 | ec = ipmi::getDbusProperty(ctx, service, bootSettingsPath, bootModeIntf, |
| 1679 | "BootMode", result); |
| 1680 | if (!ec) |
| 1681 | { |
| 1682 | mode = Mode::convertModesFromString(result); |
| 1683 | return ipmi::ccSuccess; |
| 1684 | } |
| 1685 | } |
| Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 1686 | lg2::error("Error in BootMode Get: {ERROR}", "ERROR", ec.message()); |
| Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1687 | return ipmi::ccUnspecifiedError; |
| Marri Devender Rao | 8171970 | 2018-05-07 00:53:48 -0500 | [diff] [blame] | 1688 | } |
| 1689 | |
| Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1690 | /** @brief Set the property value for boot mode |
| Konstantin Aladyshev | e76a61a | 2021-03-18 22:19:13 +0300 | [diff] [blame] | 1691 | * @param[in] ctx - context pointer |
| Marri Devender Rao | 8171970 | 2018-05-07 00:53:48 -0500 | [diff] [blame] | 1692 | * @param[in] mode - boot mode value |
| 1693 | * @return On failure return IPMI error. |
| 1694 | */ |
| Konstantin Aladyshev | e76a61a | 2021-03-18 22:19:13 +0300 | [diff] [blame] | 1695 | 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] | 1696 | { |
| 1697 | using namespace chassis::internal; |
| Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1698 | std::string service; |
| Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 1699 | boost::system::error_code ec = |
| 1700 | getService(ctx, bootModeIntf, bootSettingsPath, service); |
| Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1701 | if (!ec) |
| Marri Devender Rao | 8171970 | 2018-05-07 00:53:48 -0500 | [diff] [blame] | 1702 | { |
| Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1703 | ec = ipmi::setDbusProperty(ctx, service, bootSettingsPath, bootModeIntf, |
| 1704 | "BootMode", convertForMessage(mode)); |
| 1705 | if (!ec) |
| 1706 | { |
| 1707 | return ipmi::ccSuccess; |
| 1708 | } |
| Marri Devender Rao | 8171970 | 2018-05-07 00:53:48 -0500 | [diff] [blame] | 1709 | } |
| Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 1710 | lg2::error("Error in BootMode Set: {ERROR}", "ERROR", ec.message()); |
| Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1711 | return ipmi::ccUnspecifiedError; |
| 1712 | } |
| 1713 | |
| 1714 | /** @brief Get the property value for boot type |
| 1715 | * @param[in] ctx - context pointer |
| 1716 | * @param[out] type - boot type value |
| 1717 | * @return On failure return IPMI error. |
| 1718 | */ |
| 1719 | static ipmi::Cc getBootType(ipmi::Context::ptr& ctx, Type::Types& type) |
| 1720 | { |
| 1721 | using namespace chassis::internal; |
| 1722 | std::string result; |
| 1723 | std::string service; |
| Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 1724 | boost::system::error_code ec = |
| 1725 | getService(ctx, bootTypeIntf, bootSettingsPath, service); |
| Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1726 | |
| 1727 | // Don't throw error if BootType interface is not present. |
| 1728 | // This interface is not relevant for some Host architectures |
| 1729 | // (for example POWER). In this case we don't won't IPMI to |
| 1730 | // return an error, but simply return bootType as EFI. |
| 1731 | type = Type::Types::EFI; |
| 1732 | if (!ec) |
| 1733 | { |
| 1734 | ec = ipmi::getDbusProperty(ctx, service, bootSettingsPath, bootTypeIntf, |
| 1735 | "BootType", result); |
| 1736 | if (ec) |
| 1737 | { |
| Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 1738 | lg2::error("Error in BootType Get: {ERROR}", "ERROR", ec.message()); |
| Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1739 | return ipmi::ccUnspecifiedError; |
| 1740 | } |
| 1741 | type = Type::convertTypesFromString(result); |
| 1742 | } |
| 1743 | |
| jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 1744 | return ipmi::ccSuccess; |
| Marri Devender Rao | 8171970 | 2018-05-07 00:53:48 -0500 | [diff] [blame] | 1745 | } |
| 1746 | |
| Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 1747 | /** @brief Set the property value for boot type |
| Konstantin Aladyshev | e76a61a | 2021-03-18 22:19:13 +0300 | [diff] [blame] | 1748 | * @param[in] ctx - context pointer |
| Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 1749 | * @param[in] type - boot type value |
| 1750 | * @return On failure return IPMI error. |
| 1751 | */ |
| Konstantin Aladyshev | e76a61a | 2021-03-18 22:19:13 +0300 | [diff] [blame] | 1752 | static ipmi::Cc setBootType(ipmi::Context::ptr& ctx, const Type::Types& type) |
| Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 1753 | { |
| 1754 | using namespace chassis::internal; |
| Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1755 | std::string service; |
| Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 1756 | boost::system::error_code ec = |
| 1757 | getService(ctx, bootTypeIntf, bootSettingsPath, service); |
| Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1758 | if (!ec) |
| Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 1759 | { |
| Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1760 | ec = ipmi::setDbusProperty(ctx, service, bootSettingsPath, bootTypeIntf, |
| 1761 | "BootType", convertForMessage(type)); |
| 1762 | if (ec) |
| 1763 | { |
| Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 1764 | lg2::error("Error in BootType Set: {ERROR}", "ERROR", ec.message()); |
| Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1765 | return ipmi::ccUnspecifiedError; |
| 1766 | } |
| Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 1767 | } |
| Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1768 | // Don't throw error if BootType interface is not present. |
| 1769 | // This interface is not relevant for some Host architectures |
| 1770 | // (for example POWER). In this case we don't won't IPMI to |
| 1771 | // return an error, but want to just skip this function. |
| Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 1772 | return ipmi::ccSuccess; |
| 1773 | } |
| 1774 | |
| Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1775 | /** @brief Get the property value for boot override enable |
| 1776 | * @param[in] ctx - context pointer |
| 1777 | * @param[out] enable - boot override enable |
| 1778 | * @return On failure return IPMI error. |
| 1779 | */ |
| 1780 | static ipmi::Cc getBootEnable(ipmi::Context::ptr& ctx, bool& enable) |
| 1781 | { |
| 1782 | using namespace chassis::internal; |
| 1783 | std::string result; |
| 1784 | std::string service; |
| Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 1785 | boost::system::error_code ec = |
| 1786 | getService(ctx, bootEnableIntf, bootSettingsPath, service); |
| Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1787 | if (!ec) |
| 1788 | { |
| 1789 | ec = ipmi::getDbusProperty(ctx, service, bootSettingsPath, |
| 1790 | bootEnableIntf, "Enabled", enable); |
| 1791 | if (!ec) |
| 1792 | { |
| 1793 | return ipmi::ccSuccess; |
| 1794 | } |
| 1795 | } |
| Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 1796 | lg2::error("Error in Boot Override Enable Get: {ERROR}", "ERROR", |
| 1797 | ec.message()); |
| Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1798 | return ipmi::ccUnspecifiedError; |
| 1799 | } |
| 1800 | |
| 1801 | /** @brief Set the property value for boot override enable |
| 1802 | * @param[in] ctx - context pointer |
| 1803 | * @param[in] enable - boot override enable |
| 1804 | * @return On failure return IPMI error. |
| 1805 | */ |
| 1806 | static ipmi::Cc setBootEnable(ipmi::Context::ptr& ctx, const bool& enable) |
| 1807 | { |
| 1808 | using namespace chassis::internal; |
| 1809 | std::string service; |
| Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 1810 | boost::system::error_code ec = |
| 1811 | getService(ctx, bootEnableIntf, bootSettingsPath, service); |
| Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1812 | if (!ec) |
| 1813 | { |
| 1814 | ec = ipmi::setDbusProperty(ctx, service, bootSettingsPath, |
| 1815 | bootEnableIntf, "Enabled", enable); |
| 1816 | if (!ec) |
| 1817 | { |
| 1818 | return ipmi::ccSuccess; |
| 1819 | } |
| 1820 | } |
| Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 1821 | lg2::error("Error in Boot Source Override Enable Set: {ERROR}", "ERROR", |
| 1822 | ec.message()); |
| Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1823 | return ipmi::ccUnspecifiedError; |
| 1824 | } |
| 1825 | |
| 1826 | /** @brief Get the property value for boot override one-time |
| 1827 | * @param[in] ctx - context pointer |
| 1828 | * @param[out] onetime - boot override one-time |
| 1829 | * @return On failure return IPMI error. |
| 1830 | */ |
| 1831 | static ipmi::Cc getBootOneTime(ipmi::Context::ptr& ctx, bool& onetime) |
| 1832 | { |
| 1833 | using namespace chassis::internal; |
| 1834 | std::string result; |
| 1835 | std::string service; |
| Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 1836 | boost::system::error_code ec = |
| 1837 | getService(ctx, bootOneTimeIntf, bootSettingsOneTimePath, service); |
| Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1838 | if (!ec) |
| 1839 | { |
| 1840 | ec = ipmi::getDbusProperty(ctx, service, bootSettingsOneTimePath, |
| 1841 | bootOneTimeIntf, "Enabled", onetime); |
| 1842 | if (!ec) |
| 1843 | { |
| 1844 | return ipmi::ccSuccess; |
| 1845 | } |
| 1846 | } |
| Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 1847 | lg2::error("Error in Boot Override OneTime Get: {ERROR}", "ERROR", |
| 1848 | ec.message()); |
| Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1849 | return ipmi::ccUnspecifiedError; |
| 1850 | } |
| 1851 | |
| 1852 | /** @brief Set the property value for boot override one-time |
| 1853 | * @param[in] ctx - context pointer |
| 1854 | * @param[in] onetime - boot override one-time |
| 1855 | * @return On failure return IPMI error. |
| 1856 | */ |
| 1857 | static ipmi::Cc setBootOneTime(ipmi::Context::ptr& ctx, const bool& onetime) |
| 1858 | { |
| 1859 | using namespace chassis::internal; |
| 1860 | std::string service; |
| Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 1861 | boost::system::error_code ec = |
| 1862 | getService(ctx, bootOneTimeIntf, bootSettingsOneTimePath, service); |
| Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1863 | if (!ec) |
| 1864 | { |
| 1865 | ec = ipmi::setDbusProperty(ctx, service, bootSettingsOneTimePath, |
| 1866 | bootOneTimeIntf, "Enabled", onetime); |
| 1867 | if (!ec) |
| 1868 | { |
| 1869 | return ipmi::ccSuccess; |
| 1870 | } |
| 1871 | } |
| Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 1872 | lg2::error("Error in Boot Source Override OneTime Set: {ERROR}", "ERROR", |
| 1873 | ec.message()); |
| Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1874 | return ipmi::ccUnspecifiedError; |
| 1875 | } |
| 1876 | |
| huanghe | ab36928 | 2020-10-10 14:40:00 +0800 | [diff] [blame] | 1877 | static constexpr uint8_t setComplete = 0x0; |
| 1878 | static constexpr uint8_t setInProgress = 0x1; |
| 1879 | static uint8_t transferStatus = setComplete; |
| Chen Yugang | 86ac499 | 2021-06-25 08:14:52 +0800 | [diff] [blame] | 1880 | static uint8_t bootFlagValidBitClr = 0; |
| Hieu Huynh | 38ffafc | 2021-05-14 08:40:14 +0000 | [diff] [blame] | 1881 | static uint5_t bootInitiatorAckData = 0x0; |
| Hieu Huynh | 1982a3f | 2021-09-21 03:06:45 +0000 | [diff] [blame] | 1882 | static bool cmosClear = false; |
| Cosmo Chou | 5383121 | 2025-01-10 13:36:36 +0800 | [diff] [blame] | 1883 | static uint2_t biosVerbosity = 0x0; |
| huanghe | ab36928 | 2020-10-10 14:40:00 +0800 | [diff] [blame] | 1884 | |
| Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 1885 | /** @brief implements the Get Chassis system boot option |
| Konstantin Aladyshev | e76a61a | 2021-03-18 22:19:13 +0300 | [diff] [blame] | 1886 | * @param ctx - context pointer |
| Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 1887 | * @param bootOptionParameter - boot option parameter selector |
| 1888 | * @param reserved1 - reserved bit |
| 1889 | * @param setSelector - selects a particular block or set of parameters |
| 1890 | * under the given parameter selector |
| 1891 | * write as 00h if parameter doesn't use a setSelector |
| 1892 | * @param blockSelector- selects a particular block within a set of |
| 1893 | * parameters write as 00h if parameter doesn't use a |
| 1894 | * blockSelector |
| 1895 | * |
| 1896 | * @return IPMI completion code plus response data |
| 1897 | * @return Payload contains below parameters: |
| 1898 | * version - parameter version |
| 1899 | * bootOptionParameter - boot option parameter selector |
| Patrick Venture | 8b1c303 | 2020-09-15 09:43:03 -0700 | [diff] [blame] | 1900 | * parmIndicator - parameter valid/invalid indicator |
| Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 1901 | * data - configuration parameter data |
| 1902 | */ |
| Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 1903 | ipmi::RspType<ipmi::message::Payload> ipmiChassisGetSysBootOptions( |
| 1904 | ipmi::Context::ptr ctx, uint7_t bootOptionParameter, bool reserved1, |
| 1905 | [[maybe_unused]] uint8_t setSelector, |
| 1906 | [[maybe_unused]] uint8_t blockSelector) |
| Adriana Kobylak | 40814c6 | 2015-10-27 15:58:44 -0500 | [diff] [blame] | 1907 | { |
| Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1908 | ipmi::Cc rc; |
| Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 1909 | if (reserved1) |
| 1910 | { |
| 1911 | return ipmi::responseInvalidFieldRequest(); |
| 1912 | } |
| 1913 | |
| 1914 | constexpr uint4_t version = 0x01; |
| 1915 | ipmi::message::Payload response; |
| 1916 | response.pack(version, uint4_t{}); |
| Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1917 | using namespace boot_options; |
| Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 1918 | |
| Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1919 | IpmiValue bootOption = ipmiDefault; |
| Adriana Kobylak | 40814c6 | 2015-10-27 15:58:44 -0500 | [diff] [blame] | 1920 | |
| William A. Kennington III | 7a0e5df | 2021-05-19 13:31:29 -0700 | [diff] [blame] | 1921 | if (types::enum_cast<BootOptionParameter>(bootOptionParameter) == |
| 1922 | BootOptionParameter::setInProgress) |
| huanghe | ab36928 | 2020-10-10 14:40:00 +0800 | [diff] [blame] | 1923 | { |
| 1924 | response.pack(bootOptionParameter, reserved1, transferStatus); |
| 1925 | return ipmi::responseSuccess(std::move(response)); |
| 1926 | } |
| 1927 | |
| William A. Kennington III | 7a0e5df | 2021-05-19 13:31:29 -0700 | [diff] [blame] | 1928 | if (types::enum_cast<BootOptionParameter>(bootOptionParameter) == |
| 1929 | BootOptionParameter::bootInfo) |
| John Wang | 0213f90 | 2020-12-28 14:49:57 +0800 | [diff] [blame] | 1930 | { |
| 1931 | constexpr uint8_t writeMask = 0; |
| Hieu Huynh | 38ffafc | 2021-05-14 08:40:14 +0000 | [diff] [blame] | 1932 | response.pack(bootOptionParameter, reserved1, writeMask, |
| 1933 | bootInitiatorAckData); |
| John Wang | 0213f90 | 2020-12-28 14:49:57 +0800 | [diff] [blame] | 1934 | return ipmi::responseSuccess(std::move(response)); |
| 1935 | } |
| 1936 | |
| Chen Yugang | 86ac499 | 2021-06-25 08:14:52 +0800 | [diff] [blame] | 1937 | if (types::enum_cast<BootOptionParameter>(bootOptionParameter) == |
| 1938 | BootOptionParameter::bootFlagValidClr) |
| 1939 | { |
| 1940 | response.pack(bootOptionParameter, reserved1, |
| 1941 | uint5_t{bootFlagValidBitClr}, uint3_t{}); |
| 1942 | return ipmi::responseSuccess(std::move(response)); |
| 1943 | } |
| 1944 | |
| shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 1945 | /* |
| 1946 | * Parameter #5 means boot flags. Please refer to 28.13 of ipmi doc. |
| 1947 | * This is the only parameter used by petitboot. |
| 1948 | */ |
| William A. Kennington III | 7a0e5df | 2021-05-19 13:31:29 -0700 | [diff] [blame] | 1949 | if (types::enum_cast<BootOptionParameter>(bootOptionParameter) == |
| 1950 | BootOptionParameter::bootFlags) |
| Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1951 | { |
| Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1952 | using namespace chassis::internal; |
| 1953 | using namespace chassis::internal::cache; |
| shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 1954 | |
| Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1955 | try |
| ratagupt | a6f6bff | 2016-04-04 06:20:11 -0500 | [diff] [blame] | 1956 | { |
| Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1957 | Source::Sources bootSource; |
| 1958 | rc = getBootSource(ctx, bootSource); |
| 1959 | if (rc != ipmi::ccSuccess) |
| Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1960 | { |
| Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1961 | return ipmi::response(rc); |
| Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1962 | } |
| Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1963 | |
| Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 1964 | Type::Types bootType; |
| Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1965 | rc = getBootType(ctx, bootType); |
| 1966 | if (rc != ipmi::ccSuccess) |
| Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 1967 | { |
| Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1968 | return ipmi::response(rc); |
| Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 1969 | } |
| 1970 | |
| Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1971 | Mode::Modes bootMode; |
| 1972 | rc = getBootMode(ctx, bootMode); |
| 1973 | if (rc != ipmi::ccSuccess) |
| Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1974 | { |
| Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1975 | return ipmi::response(rc); |
| Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1976 | } |
| Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1977 | |
| Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1978 | bootOption = sourceDbusToIpmi.at(bootSource); |
| 1979 | if ((Mode::Modes::Regular == bootMode) && |
| 1980 | (Source::Sources::Default == bootSource)) |
| 1981 | { |
| 1982 | bootOption = ipmiDefault; |
| 1983 | } |
| 1984 | else if (Source::Sources::Default == bootSource) |
| 1985 | { |
| 1986 | bootOption = modeDbusToIpmi.at(bootMode); |
| 1987 | } |
| ratagupt | a6f6bff | 2016-04-04 06:20:11 -0500 | [diff] [blame] | 1988 | |
| Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 1989 | IpmiValue biosBootType = typeDbusToIpmi.at(bootType); |
| Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1990 | |
| 1991 | bool oneTimeEnabled; |
| 1992 | rc = getBootOneTime(ctx, oneTimeEnabled); |
| 1993 | if (rc != ipmi::ccSuccess) |
| 1994 | { |
| 1995 | return ipmi::response(rc); |
| 1996 | } |
| 1997 | |
| Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 1998 | uint1_t permanent = oneTimeEnabled ? 0 : 1; |
| Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1999 | |
| 2000 | bool valid; |
| 2001 | rc = getBootEnable(ctx, valid); |
| 2002 | if (rc != ipmi::ccSuccess) |
| 2003 | { |
| 2004 | return ipmi::response(rc); |
| 2005 | } |
| 2006 | |
| 2007 | uint1_t validFlag = valid ? 1 : 0; |
| Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 2008 | |
| Cosmo Chou | 5383121 | 2025-01-10 13:36:36 +0800 | [diff] [blame] | 2009 | response.pack( |
| 2010 | bootOptionParameter, reserved1, uint5_t{}, |
| 2011 | uint1_t{biosBootType}, uint1_t{permanent}, uint1_t{validFlag}, |
| 2012 | uint2_t{}, uint4_t{bootOption}, uint1_t{}, cmosClear, uint5_t{}, |
| 2013 | uint2_t{biosVerbosity}, uint1_t{}, uint8_t{}, uint8_t{}); |
| Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 2014 | return ipmi::responseSuccess(std::move(response)); |
| ratagupt | a6f6bff | 2016-04-04 06:20:11 -0500 | [diff] [blame] | 2015 | } |
| Patrick Williams | a2ad2da | 2021-10-06 12:21:46 -0500 | [diff] [blame] | 2016 | catch (const InternalFailure& e) |
| Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 2017 | { |
| James Feist | 225dec8 | 2019-11-26 16:25:06 -0800 | [diff] [blame] | 2018 | cache::objectsPtr.reset(); |
| Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 2019 | report<InternalFailure>(); |
| Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 2020 | return ipmi::responseUnspecifiedError(); |
| Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 2021 | } |
| Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 2022 | } |
| Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 2023 | else |
| 2024 | { |
| Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 2025 | if ((bootOptionParameter >= oemParmStart) && |
| 2026 | (bootOptionParameter <= oemParmEnd)) |
| 2027 | { |
| William A. Kennington III | 7a0e5df | 2021-05-19 13:31:29 -0700 | [diff] [blame] | 2028 | if (types::enum_cast<BootOptionParameter>(bootOptionParameter) == |
| 2029 | BootOptionParameter::opalNetworkSettings) |
| Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 2030 | { |
| 2031 | response.pack(bootOptionParameter, reserved1); |
| 2032 | int ret = getHostNetworkData(response); |
| 2033 | if (ret < 0) |
| 2034 | { |
| 2035 | response.trailingOk = true; |
| Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 2036 | lg2::error( |
| Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 2037 | "getHostNetworkData failed for GetSysBootOptions."); |
| 2038 | return ipmi::responseUnspecifiedError(); |
| 2039 | } |
| 2040 | else |
| 2041 | { |
| 2042 | return ipmi::responseSuccess(std::move(response)); |
| 2043 | } |
| 2044 | } |
| Jayaprakash Mutyala | 43a8810 | 2021-08-04 16:41:58 +0000 | [diff] [blame] | 2045 | else |
| 2046 | { |
| Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 2047 | lg2::error( |
| 2048 | "ipmiChassisGetSysBootOptions: Unsupported parameter {PARAM}", |
| 2049 | "PARAM", lg2::hex, |
| 2050 | static_cast<uint8_t>(bootOptionParameter)); |
| Jayaprakash Mutyala | 43a8810 | 2021-08-04 16:41:58 +0000 | [diff] [blame] | 2051 | return ipmi::responseParmNotSupported(); |
| 2052 | } |
| Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 2053 | } |
| 2054 | else |
| 2055 | { |
| Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 2056 | lg2::error( |
| 2057 | "ipmiChassisGetSysBootOptions: Unsupported parameter {PARAM}", |
| 2058 | "PARAM", lg2::hex, static_cast<uint8_t>(bootOptionParameter)); |
| Jayaprakash Mutyala | 6088e9f | 2021-07-14 07:40:29 +0000 | [diff] [blame] | 2059 | return ipmi::responseParmNotSupported(); |
| Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 2060 | } |
| shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 2061 | } |
| Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 2062 | return ipmi::responseUnspecifiedError(); |
| shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 2063 | } |
| 2064 | |
| jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2065 | ipmi::RspType<> ipmiChassisSetSysBootOptions(ipmi::Context::ptr ctx, |
| Willy Tu | 11d6889 | 2022-01-20 10:37:34 -0800 | [diff] [blame] | 2066 | uint7_t parameterSelector, bool, |
| jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2067 | ipmi::message::Payload& data) |
| shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 2068 | { |
| Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 2069 | using namespace boot_options; |
| jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2070 | ipmi::Cc rc; |
| shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 2071 | |
| William A. Kennington III | 7a0e5df | 2021-05-19 13:31:29 -0700 | [diff] [blame] | 2072 | if (types::enum_cast<BootOptionParameter>(parameterSelector) == |
| 2073 | BootOptionParameter::setInProgress) |
| huanghe | ab36928 | 2020-10-10 14:40:00 +0800 | [diff] [blame] | 2074 | { |
| 2075 | uint2_t setInProgressFlag; |
| 2076 | uint6_t rsvd; |
| 2077 | if (data.unpack(setInProgressFlag, rsvd) != 0 || !data.fullyUnpacked()) |
| 2078 | { |
| 2079 | return ipmi::responseReqDataLenInvalid(); |
| 2080 | } |
| 2081 | if (rsvd) |
| 2082 | { |
| 2083 | return ipmi::responseInvalidFieldRequest(); |
| 2084 | } |
| 2085 | if ((transferStatus == setInProgress) && |
| 2086 | (static_cast<uint8_t>(setInProgressFlag) != setComplete)) |
| 2087 | { |
| George Liu | f5dd102 | 2025-07-07 09:13:07 +0800 | [diff] [blame] | 2088 | return ipmi::responsefailSetInProgress(); |
| huanghe | ab36928 | 2020-10-10 14:40:00 +0800 | [diff] [blame] | 2089 | } |
| 2090 | transferStatus = static_cast<uint8_t>(setInProgressFlag); |
| 2091 | return ipmi::responseSuccess(); |
| 2092 | } |
| 2093 | |
| shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 2094 | /* 000101 |
| 2095 | * Parameter #5 means boot flags. Please refer to 28.13 of ipmi doc. |
| 2096 | * This is the only parameter used by petitboot. |
| 2097 | */ |
| Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 2098 | |
| William A. Kennington III | 7a0e5df | 2021-05-19 13:31:29 -0700 | [diff] [blame] | 2099 | if (types::enum_cast<BootOptionParameter>(parameterSelector) == |
| 2100 | BootOptionParameter::bootFlags) |
| Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 2101 | { |
| jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2102 | uint5_t rsvd; |
| 2103 | bool validFlag; |
| 2104 | bool permanent; |
| 2105 | bool biosBootType; |
| 2106 | bool lockOutResetButton; |
| 2107 | bool screenBlank; |
| 2108 | uint4_t bootDeviceSelector; |
| 2109 | bool lockKeyboard; |
| Cosmo Chou | 5383121 | 2025-01-10 13:36:36 +0800 | [diff] [blame] | 2110 | uint5_t biosCtrls; |
| 2111 | bool lockOutPower; |
| jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2112 | uint4_t biosInfo; |
| 2113 | uint4_t rsvd1; |
| 2114 | uint5_t deviceInstance; |
| 2115 | uint3_t rsvd2; |
| 2116 | |
| 2117 | if (data.unpack(rsvd, biosBootType, permanent, validFlag, |
| 2118 | lockOutResetButton, screenBlank, bootDeviceSelector, |
| Cosmo Chou | 5383121 | 2025-01-10 13:36:36 +0800 | [diff] [blame] | 2119 | lockKeyboard, cmosClear, biosCtrls, biosVerbosity, |
| 2120 | lockOutPower, biosInfo, rsvd1, deviceInstance, rsvd2) != |
| 2121 | 0 || |
| jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2122 | !data.fullyUnpacked()) |
| 2123 | { |
| 2124 | return ipmi::responseReqDataLenInvalid(); |
| 2125 | } |
| 2126 | if (rsvd || rsvd1 || rsvd2) |
| 2127 | { |
| 2128 | return ipmi::responseInvalidFieldRequest(); |
| 2129 | } |
| 2130 | |
| Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 2131 | using namespace chassis::internal; |
| 2132 | using namespace chassis::internal::cache; |
| shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 2133 | |
| Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 2134 | try |
| Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 2135 | { |
| Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 2136 | rc = setBootOneTime(ctx, !permanent); |
| 2137 | if (rc != ipmi::ccSuccess) |
| Konstantin Aladyshev | 69e8e84 | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 2138 | { |
| Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 2139 | return ipmi::response(rc); |
| 2140 | } |
| Vernon Mauery | afd45db | 2021-07-29 16:27:25 +0000 | [diff] [blame] | 2141 | |
| Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 2142 | rc = setBootEnable(ctx, validFlag); |
| 2143 | if (rc != ipmi::ccSuccess) |
| 2144 | { |
| 2145 | return ipmi::response(rc); |
| Tom Joseph | 57e8eb7 | 2017-09-25 18:05:02 +0530 | [diff] [blame] | 2146 | } |
| 2147 | |
| jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2148 | auto modeItr = |
| 2149 | modeIpmiToDbus.find(static_cast<uint8_t>(bootDeviceSelector)); |
| Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 2150 | auto typeItr = |
| 2151 | typeIpmiToDbus.find(static_cast<uint8_t>(biosBootType)); |
| jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2152 | auto sourceItr = |
| 2153 | sourceIpmiToDbus.find(static_cast<uint8_t>(bootDeviceSelector)); |
| Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 2154 | if (sourceIpmiToDbus.end() != sourceItr) |
| Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 2155 | { |
| Konstantin Aladyshev | e76a61a | 2021-03-18 22:19:13 +0300 | [diff] [blame] | 2156 | rc = setBootSource(ctx, sourceItr->second); |
| jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2157 | if (rc != ipmi::ccSuccess) |
| Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 2158 | { |
| Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 2159 | return ipmi::response(rc); |
| Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 2160 | } |
| Marri Devender Rao | 54fa130 | 2018-05-07 01:06:23 -0500 | [diff] [blame] | 2161 | // If a set boot device is mapping to a boot source, then reset |
| 2162 | // the boot mode D-Bus property to default. |
| 2163 | // This way the ipmid code can determine which property is not |
| 2164 | // at the default value |
| Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 2165 | if (sourceItr->second != Source::Sources::Default) |
| Marri Devender Rao | 54fa130 | 2018-05-07 01:06:23 -0500 | [diff] [blame] | 2166 | { |
| Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 2167 | rc = setBootMode(ctx, Mode::Modes::Regular); |
| 2168 | if (rc != ipmi::ccSuccess) |
| 2169 | { |
| 2170 | return ipmi::response(rc); |
| 2171 | } |
| Marri Devender Rao | 54fa130 | 2018-05-07 01:06:23 -0500 | [diff] [blame] | 2172 | } |
| Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 2173 | } |
| Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 2174 | |
| 2175 | if (typeIpmiToDbus.end() != typeItr) |
| 2176 | { |
| Konstantin Aladyshev | e76a61a | 2021-03-18 22:19:13 +0300 | [diff] [blame] | 2177 | rc = setBootType(ctx, typeItr->second); |
| Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 2178 | if (rc != ipmi::ccSuccess) |
| 2179 | { |
| Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 2180 | return ipmi::response(rc); |
| Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 2181 | } |
| 2182 | } |
| 2183 | |
| Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 2184 | if (modeIpmiToDbus.end() != modeItr) |
| 2185 | { |
| Konstantin Aladyshev | e76a61a | 2021-03-18 22:19:13 +0300 | [diff] [blame] | 2186 | rc = setBootMode(ctx, modeItr->second); |
| jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2187 | if (rc != ipmi::ccSuccess) |
| Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 2188 | { |
| Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 2189 | return ipmi::response(rc); |
| Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 2190 | } |
| Marri Devender Rao | 54fa130 | 2018-05-07 01:06:23 -0500 | [diff] [blame] | 2191 | // If a set boot device is mapping to a boot mode, then reset |
| 2192 | // the boot source D-Bus property to default. |
| 2193 | // This way the ipmid code can determine which property is not |
| 2194 | // at the default value |
| Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 2195 | if (modeItr->second != Mode::Modes::Regular) |
| Marri Devender Rao | 54fa130 | 2018-05-07 01:06:23 -0500 | [diff] [blame] | 2196 | { |
| Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 2197 | rc = setBootSource(ctx, Source::Sources::Default); |
| 2198 | if (rc != ipmi::ccSuccess) |
| 2199 | { |
| 2200 | return ipmi::response(rc); |
| 2201 | } |
| Marri Devender Rao | 54fa130 | 2018-05-07 01:06:23 -0500 | [diff] [blame] | 2202 | } |
| Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 2203 | } |
| Jia, chunhui | 67c5e5d | 2019-05-06 11:29:54 +0800 | [diff] [blame] | 2204 | if ((modeIpmiToDbus.end() == modeItr) && |
| Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 2205 | (typeIpmiToDbus.end() == typeItr) && |
| Jia, chunhui | 67c5e5d | 2019-05-06 11:29:54 +0800 | [diff] [blame] | 2206 | (sourceIpmiToDbus.end() == sourceItr)) |
| 2207 | { |
| 2208 | // return error if boot option is not supported |
| Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 2209 | lg2::error( |
| jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2210 | "ipmiChassisSetSysBootOptions: Boot option not supported"); |
| 2211 | return ipmi::responseInvalidFieldRequest(); |
| Jia, chunhui | 67c5e5d | 2019-05-06 11:29:54 +0800 | [diff] [blame] | 2212 | } |
| Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 2213 | } |
| Patrick Williams | a2ad2da | 2021-10-06 12:21:46 -0500 | [diff] [blame] | 2214 | catch (const sdbusplus::exception_t& e) |
| Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 2215 | { |
| James Feist | 225dec8 | 2019-11-26 16:25:06 -0800 | [diff] [blame] | 2216 | objectsPtr.reset(); |
| Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 2217 | report<InternalFailure>(); |
| Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 2218 | lg2::error("ipmiChassisSetSysBootOptions: Error in setting Boot " |
| 2219 | "flag parameters"); |
| jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2220 | return ipmi::responseUnspecifiedError(); |
| Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 2221 | } |
| Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 2222 | } |
| William A. Kennington III | 7a0e5df | 2021-05-19 13:31:29 -0700 | [diff] [blame] | 2223 | else if (types::enum_cast<BootOptionParameter>(parameterSelector) == |
| 2224 | BootOptionParameter::bootInfo) |
| Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 2225 | { |
| jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2226 | uint8_t writeMak; |
| Hieu Huynh | 38ffafc | 2021-05-14 08:40:14 +0000 | [diff] [blame] | 2227 | uint5_t bootInfoAck; |
| jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2228 | uint3_t rsvd; |
| 2229 | |
| Hieu Huynh | 38ffafc | 2021-05-14 08:40:14 +0000 | [diff] [blame] | 2230 | if (data.unpack(writeMak, bootInfoAck, rsvd) != 0 || |
| jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2231 | !data.fullyUnpacked()) |
| 2232 | { |
| 2233 | return ipmi::responseReqDataLenInvalid(); |
| 2234 | } |
| 2235 | if (rsvd) |
| 2236 | { |
| 2237 | return ipmi::responseInvalidFieldRequest(); |
| 2238 | } |
| Hieu Huynh | 38ffafc | 2021-05-14 08:40:14 +0000 | [diff] [blame] | 2239 | bootInitiatorAckData &= ~writeMak; |
| 2240 | bootInitiatorAckData |= (writeMak & bootInfoAck); |
| Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 2241 | lg2::info("ipmiChassisSetSysBootOptions: bootInfo parameter set " |
| 2242 | "successfully"); |
| jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2243 | data.trailingOk = true; |
| 2244 | return ipmi::responseSuccess(); |
| Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 2245 | } |
| Chen Yugang | 86ac499 | 2021-06-25 08:14:52 +0800 | [diff] [blame] | 2246 | else if (types::enum_cast<BootOptionParameter>(parameterSelector) == |
| 2247 | BootOptionParameter::bootFlagValidClr) |
| 2248 | { |
| 2249 | uint5_t bootFlagValidClr; |
| 2250 | uint3_t rsvd; |
| 2251 | |
| 2252 | if (data.unpack(bootFlagValidClr, rsvd) != 0 || !data.fullyUnpacked()) |
| 2253 | { |
| 2254 | return ipmi::responseReqDataLenInvalid(); |
| 2255 | } |
| 2256 | if (rsvd) |
| 2257 | { |
| 2258 | return ipmi::responseInvalidFieldRequest(); |
| 2259 | } |
| 2260 | // store boot flag valid bits clear value |
| 2261 | bootFlagValidBitClr = static_cast<uint8_t>(bootFlagValidClr); |
| Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 2262 | lg2::info( |
| Chen Yugang | 86ac499 | 2021-06-25 08:14:52 +0800 | [diff] [blame] | 2263 | "ipmiChassisSetSysBootOptions: bootFlagValidBits parameter set " |
| Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 2264 | "successfully to {VALUE}", |
| 2265 | "VALUE", lg2::hex, bootFlagValidBitClr); |
| Chen Yugang | 86ac499 | 2021-06-25 08:14:52 +0800 | [diff] [blame] | 2266 | return ipmi::responseSuccess(); |
| 2267 | } |
| Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 2268 | else |
| 2269 | { |
| jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2270 | if ((parameterSelector >= static_cast<uint7_t>(oemParmStart)) && |
| 2271 | (parameterSelector <= static_cast<uint7_t>(oemParmEnd))) |
| 2272 | { |
| William A. Kennington III | 7a0e5df | 2021-05-19 13:31:29 -0700 | [diff] [blame] | 2273 | if (types::enum_cast<BootOptionParameter>(parameterSelector) == |
| 2274 | BootOptionParameter::opalNetworkSettings) |
| jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2275 | { |
| 2276 | ipmi::Cc ret = setHostNetworkData(data); |
| 2277 | if (ret != ipmi::ccSuccess) |
| 2278 | { |
| Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 2279 | lg2::error("ipmiChassisSetSysBootOptions: Error in " |
| 2280 | "setHostNetworkData"); |
| jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2281 | data.trailingOk = true; |
| 2282 | return ipmi::response(ret); |
| 2283 | } |
| 2284 | data.trailingOk = true; |
| 2285 | return ipmi::responseSuccess(); |
| 2286 | } |
| 2287 | else |
| 2288 | { |
| Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 2289 | lg2::error( |
| 2290 | "ipmiChassisSetSysBootOptions: Unsupported param: {PARAM}", |
| 2291 | "PARAM", lg2::hex, static_cast<uint8_t>(parameterSelector)); |
| jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2292 | data.trailingOk = true; |
| 2293 | return ipmi::responseParmNotSupported(); |
| 2294 | } |
| 2295 | } |
| 2296 | data.trailingOk = true; |
| 2297 | return ipmi::responseParmNotSupported(); |
| Adriana Kobylak | 40814c6 | 2015-10-27 15:58:44 -0500 | [diff] [blame] | 2298 | } |
| jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2299 | return ipmi::responseSuccess(); |
| Adriana Kobylak | 40814c6 | 2015-10-27 15:58:44 -0500 | [diff] [blame] | 2300 | } |
| 2301 | |
| anil kumar appana | a5a76eb | 2019-04-30 14:57:24 +0000 | [diff] [blame] | 2302 | /** @brief implements Get POH counter command |
| 2303 | * @parameter |
| 2304 | * - none |
| 2305 | * @returns IPMI completion code plus response data |
| 2306 | * - minPerCount - Minutes per count |
| 2307 | * - counterReading - counter reading |
| 2308 | */ |
| 2309 | ipmi::RspType<uint8_t, // Minutes per count |
| 2310 | uint32_t // Counter reading |
| 2311 | > |
| 2312 | ipmiGetPOHCounter() |
| Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 2313 | { |
| 2314 | // sd_bus error |
| Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 2315 | try |
| 2316 | { |
| anil kumar appana | a5a76eb | 2019-04-30 14:57:24 +0000 | [diff] [blame] | 2317 | return ipmi::responseSuccess(static_cast<uint8_t>(poh::minutesPerCount), |
| 2318 | getPOHCounter()); |
| Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 2319 | } |
| Patrick Williams | a2ad2da | 2021-10-06 12:21:46 -0500 | [diff] [blame] | 2320 | catch (const std::exception& e) |
| Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 2321 | { |
| Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 2322 | lg2::error("getPOHCounter error: {ERROR}", "ERROR", e); |
| anil kumar appana | a5a76eb | 2019-04-30 14:57:24 +0000 | [diff] [blame] | 2323 | return ipmi::responseUnspecifiedError(); |
| Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 2324 | } |
| Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 2325 | } |
| 2326 | |
| Jason M. Bills | bc996a3 | 2019-06-17 15:46:37 -0700 | [diff] [blame] | 2327 | ipmi::RspType<uint3_t, // policy support |
| 2328 | uint5_t // reserved |
| 2329 | > |
| George Liu | de1420d | 2025-03-03 15:14:25 +0800 | [diff] [blame] | 2330 | ipmiChassisSetPowerRestorePolicy(ipmi::Context::ptr ctx, uint3_t policy, |
| 2331 | uint5_t reserved) |
| Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2332 | { |
| Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2333 | power_policy::DbusValue value = |
| 2334 | power_policy::RestorePolicy::Policy::AlwaysOff; |
| 2335 | |
| Jason M. Bills | bc996a3 | 2019-06-17 15:46:37 -0700 | [diff] [blame] | 2336 | if (reserved || (policy > power_policy::noChange)) |
| Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2337 | { |
| Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 2338 | lg2::error("Reserved request parameter: {REQ}", "REQ", lg2::hex, |
| 2339 | static_cast<int>(policy)); |
| Jason M. Bills | bc996a3 | 2019-06-17 15:46:37 -0700 | [diff] [blame] | 2340 | return ipmi::responseInvalidFieldRequest(); |
| Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2341 | } |
| 2342 | |
| Vernon Mauery | e278ead | 2018-10-09 09:23:43 -0700 | [diff] [blame] | 2343 | if (policy == power_policy::noChange) |
| Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2344 | { |
| 2345 | // just return the supported policy |
| Jason M. Bills | bc996a3 | 2019-06-17 15:46:37 -0700 | [diff] [blame] | 2346 | return ipmi::responseSuccess(power_policy::allSupport, reserved); |
| Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2347 | } |
| 2348 | |
| Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 2349 | for (const auto& it : power_policy::dbusToIpmi) |
| Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2350 | { |
| Vernon Mauery | e278ead | 2018-10-09 09:23:43 -0700 | [diff] [blame] | 2351 | if (it.second == policy) |
| Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2352 | { |
| 2353 | value = it.first; |
| 2354 | break; |
| 2355 | } |
| 2356 | } |
| 2357 | |
| 2358 | try |
| 2359 | { |
| James Feist | 225dec8 | 2019-11-26 16:25:06 -0800 | [diff] [blame] | 2360 | settings::Objects& objects = chassis::internal::cache::getObjects(); |
| Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2361 | const settings::Path& powerRestoreSetting = |
| James Feist | 225dec8 | 2019-11-26 16:25:06 -0800 | [diff] [blame] | 2362 | objects.map.at(chassis::internal::powerRestoreIntf).front(); |
| Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2363 | |
| George Liu | de1420d | 2025-03-03 15:14:25 +0800 | [diff] [blame] | 2364 | boost::system::error_code ec = ipmi::setDbusProperty( |
| 2365 | ctx, |
| 2366 | objects.service(powerRestoreSetting, |
| 2367 | chassis::internal::powerRestoreIntf), |
| 2368 | powerRestoreSetting, chassis::internal::powerRestoreIntf, |
| 2369 | "PowerRestorePolicy", convertForMessage(value)); |
| Vernon Mauery | e278ead | 2018-10-09 09:23:43 -0700 | [diff] [blame] | 2370 | if (ec) |
| Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2371 | { |
| Vernon Mauery | 38108d9 | 2024-03-11 12:53:55 -0700 | [diff] [blame] | 2372 | lg2::error("Unspecified Error"); |
| Vernon Mauery | e278ead | 2018-10-09 09:23:43 -0700 | [diff] [blame] | 2373 | return ipmi::responseUnspecifiedError(); |
| Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2374 | } |
| 2375 | } |
| Patrick Williams | a2ad2da | 2021-10-06 12:21:46 -0500 | [diff] [blame] | 2376 | catch (const InternalFailure& e) |
| Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2377 | { |
| James Feist | 225dec8 | 2019-11-26 16:25:06 -0800 | [diff] [blame] | 2378 | chassis::internal::cache::objectsPtr.reset(); |
| Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2379 | report<InternalFailure>(); |
| Vernon Mauery | e278ead | 2018-10-09 09:23:43 -0700 | [diff] [blame] | 2380 | return ipmi::responseUnspecifiedError(); |
| Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2381 | } |
| 2382 | |
| Jason M. Bills | bc996a3 | 2019-06-17 15:46:37 -0700 | [diff] [blame] | 2383 | return ipmi::responseSuccess(power_policy::allSupport, reserved); |
| Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2384 | } |
| 2385 | |
| Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 2386 | ipmi::RspType<> ipmiSetFrontPanelButtonEnables( |
| 2387 | ipmi::Context::ptr ctx, bool disablePowerButton, bool disableResetButton, |
| 2388 | bool, bool, uint4_t) |
| Kuiying Wang | 21addc5 | 2019-01-04 10:50:21 +0800 | [diff] [blame] | 2389 | { |
| 2390 | using namespace chassis::internal; |
| 2391 | |
| 2392 | // set power button Enabled property |
| Konstantin Aladyshev | 305d864 | 2025-02-15 00:36:54 +0300 | [diff] [blame] | 2393 | bool success = setButtonDisabled(ctx, powerButtonPath, powerButtonIntf, |
| 2394 | disablePowerButton); |
| Kuiying Wang | 21addc5 | 2019-01-04 10:50:21 +0800 | [diff] [blame] | 2395 | |
| 2396 | // set reset button Enabled property |
| Konstantin Aladyshev | 305d864 | 2025-02-15 00:36:54 +0300 | [diff] [blame] | 2397 | success &= setButtonDisabled(ctx, resetButtonPath, resetButtonIntf, |
| 2398 | disableResetButton); |
| Kuiying Wang | 21addc5 | 2019-01-04 10:50:21 +0800 | [diff] [blame] | 2399 | |
| 2400 | if (!success) |
| 2401 | { |
| 2402 | // not all buttons were successfully set |
| 2403 | return ipmi::responseUnspecifiedError(); |
| 2404 | } |
| 2405 | return ipmi::responseSuccess(); |
| 2406 | } |
| 2407 | |
| George Liu | 5087b07 | 2025-03-11 19:28:17 +0800 | [diff] [blame] | 2408 | void registerNetFnChassisFunctions() |
| Adriana Kobylak | 40814c6 | 2015-10-27 15:58:44 -0500 | [diff] [blame] | 2409 | { |
| Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 2410 | createIdentifyTimer(); |
| 2411 | |
| Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 2412 | // Get Chassis Capabilities |
| anil kumar appana | 43263c6 | 2019-05-27 12:45:04 +0000 | [diff] [blame] | 2413 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis, |
| 2414 | ipmi::chassis::cmdGetChassisCapabilities, |
| 2415 | ipmi::Privilege::User, ipmiGetChassisCap); |
| Nan Li | 8d15fb4 | 2016-08-16 22:29:40 +0800 | [diff] [blame] | 2416 | |
| Kuiying Wang | 21addc5 | 2019-01-04 10:50:21 +0800 | [diff] [blame] | 2417 | // Set Front Panel Button Enables |
| 2418 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis, |
| 2419 | ipmi::chassis::cmdSetFrontPanelButtonEnables, |
| 2420 | ipmi::Privilege::Admin, |
| 2421 | ipmiSetFrontPanelButtonEnables); |
| 2422 | |
| Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 2423 | // Set Chassis Capabilities |
| anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 2424 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis, |
| 2425 | ipmi::chassis::cmdSetChassisCapabilities, |
| 2426 | ipmi::Privilege::User, ipmiSetChassisCap); |
| Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 2427 | |
| Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 2428 | // <Get System Boot Options> |
| Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 2429 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis, |
| 2430 | ipmi::chassis::cmdGetSystemBootOptions, |
| 2431 | ipmi::Privilege::Operator, |
| 2432 | ipmiChassisGetSysBootOptions); |
| Adriana Kobylak | 40814c6 | 2015-10-27 15:58:44 -0500 | [diff] [blame] | 2433 | |
| Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 2434 | // <Get Chassis Status> |
| Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 2435 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis, |
| 2436 | ipmi::chassis::cmdGetChassisStatus, |
| 2437 | ipmi::Privilege::User, ipmiGetChassisStatus); |
| Nan Li | fdd8ec5 | 2016-08-28 03:57:40 +0800 | [diff] [blame] | 2438 | |
| Vijay Khemka | 074f64d | 2020-03-03 15:08:43 -0800 | [diff] [blame] | 2439 | // <Chassis Get System Restart Cause> |
| 2440 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis, |
| 2441 | ipmi::chassis::cmdGetSystemRestartCause, |
| 2442 | ipmi::Privilege::User, ipmiGetSystemRestartCause); |
| 2443 | |
| Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 2444 | // <Chassis Control> |
| anil kumar appana | dafff5f | 2019-04-27 18:06:00 +0000 | [diff] [blame] | 2445 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis, |
| 2446 | ipmi::chassis::cmdChassisControl, |
| 2447 | ipmi::Privilege::Operator, ipmiChassisControl); |
| shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 2448 | |
| Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 2449 | // <Chassis Identify> |
| Vernon Mauery | 400cc78 | 2018-10-09 13:49:53 -0700 | [diff] [blame] | 2450 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis, |
| 2451 | ipmi::chassis::cmdChassisIdentify, |
| 2452 | ipmi::Privilege::Operator, ipmiChassisIdentify); |
| Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 2453 | |
| Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 2454 | // <Set System Boot Options> |
| jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2455 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis, |
| 2456 | ipmi::chassis::cmdSetSystemBootOptions, |
| 2457 | ipmi::Privilege::Operator, |
| 2458 | ipmiChassisSetSysBootOptions); |
| 2459 | |
| Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 2460 | // <Get POH Counter> |
| anil kumar appana | a5a76eb | 2019-04-30 14:57:24 +0000 | [diff] [blame] | 2461 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis, |
| 2462 | ipmi::chassis::cmdGetPohCounter, |
| 2463 | ipmi::Privilege::User, ipmiGetPOHCounter); |
| Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2464 | |
| 2465 | // <Set Power Restore Policy> |
| Vernon Mauery | e278ead | 2018-10-09 09:23:43 -0700 | [diff] [blame] | 2466 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis, |
| 2467 | ipmi::chassis::cmdSetPowerRestorePolicy, |
| 2468 | ipmi::Privilege::Operator, |
| 2469 | ipmiChassisSetPowerRestorePolicy); |
| vishwa | 3699327 | 2015-11-20 12:43:49 -0600 | [diff] [blame] | 2470 | } |