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