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