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