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