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