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