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> |
| 8 | #include <mapper.h> |
| 9 | #include <netinet/in.h> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 10 | |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 11 | #include <array> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 12 | #include <chrono> |
Patrick Venture | b51bf9c | 2018-09-10 15:53:14 -0700 | [diff] [blame] | 13 | #include <cstring> |
Vernon Mauery | bdda800 | 2019-02-26 10:18:51 -0800 | [diff] [blame] | 14 | #include <filesystem> |
Andrew Geissler | a6e3a30 | 2017-05-31 19:34:00 -0500 | [diff] [blame] | 15 | #include <fstream> |
Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 16 | #include <future> |
Vernon Mauery | e08fbff | 2019-04-03 09:19:34 -0700 | [diff] [blame] | 17 | #include <ipmid/api.hpp> |
Vernon Mauery | 3325024 | 2019-03-12 16:49:26 -0700 | [diff] [blame] | 18 | #include <ipmid/types.hpp> |
Vernon Mauery | 6a98fe7 | 2019-03-11 15:57:48 -0700 | [diff] [blame] | 19 | #include <ipmid/utils.hpp> |
Patrick Venture | 3a5071a | 2018-09-12 13:27:42 -0700 | [diff] [blame] | 20 | #include <map> |
| 21 | #include <phosphor-logging/elog-errors.hpp> |
| 22 | #include <phosphor-logging/log.hpp> |
| 23 | #include <sdbusplus/bus.hpp> |
William A. Kennington III | 4c00802 | 2018-10-12 17:18:14 -0700 | [diff] [blame] | 24 | #include <sdbusplus/message/types.hpp> |
Patrick Venture | 3a5071a | 2018-09-12 13:27:42 -0700 | [diff] [blame] | 25 | #include <sdbusplus/server/object.hpp> |
Vernon Mauery | 1181af7 | 2018-10-08 12:05:00 -0700 | [diff] [blame] | 26 | #include <sdbusplus/timer.hpp> |
Vernon Mauery | e278ead | 2018-10-09 09:23:43 -0700 | [diff] [blame] | 27 | #include <settings.hpp> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 28 | #include <sstream> |
Patrick Venture | 3a5071a | 2018-09-12 13:27:42 -0700 | [diff] [blame] | 29 | #include <string> |
| 30 | #include <xyz/openbmc_project/Common/error.hpp> |
| 31 | #include <xyz/openbmc_project/Control/Boot/Mode/server.hpp> |
| 32 | #include <xyz/openbmc_project/Control/Boot/Source/server.hpp> |
Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 33 | #include <xyz/openbmc_project/Control/Boot/Type/server.hpp> |
Patrick Venture | 3a5071a | 2018-09-12 13:27:42 -0700 | [diff] [blame] | 34 | #include <xyz/openbmc_project/Control/Power/RestorePolicy/server.hpp> |
| 35 | #include <xyz/openbmc_project/State/Host/server.hpp> |
| 36 | #include <xyz/openbmc_project/State/PowerOnHours/server.hpp> |
| 37 | |
Lei YU | 4b0ddb6 | 2019-01-25 16:43:50 +0800 | [diff] [blame] | 38 | std::unique_ptr<phosphor::Timer> identifyTimer |
| 39 | __attribute__((init_priority(101))); |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 40 | |
Yong Li | f4e3851 | 2019-05-21 14:46:55 +0800 | [diff] [blame] | 41 | static ChassisIDState chassisIDState = ChassisIDState::reserved; |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 42 | static constexpr uint8_t setParmVersion = 0x01; |
Yong Li | f4e3851 | 2019-05-21 14:46:55 +0800 | [diff] [blame] | 43 | |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 44 | constexpr size_t sizeVersion = 2; |
Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 45 | constexpr size_t DEFAULT_IDENTIFY_TIME_OUT = 15; |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 46 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 47 | // PetiBoot-Specific |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 48 | static constexpr uint8_t netConfInitialBytes[] = {0x80, 0x21, 0x70, 0x62, |
| 49 | 0x21, 0x00, 0x01, 0x06}; |
| 50 | static constexpr uint8_t oemParmStart = 96; |
| 51 | static constexpr uint8_t oemParmEnd = 127; |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 52 | |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 53 | static constexpr size_t cookieOffset = 1; |
| 54 | static constexpr size_t versionOffset = 5; |
| 55 | static constexpr size_t addrSizeOffset = 8; |
| 56 | static constexpr size_t macOffset = 9; |
| 57 | static constexpr size_t addrTypeOffset = 16; |
| 58 | static constexpr size_t ipAddrOffset = 17; |
ratagupt | a6f6bff | 2016-04-04 06:20:11 -0500 | [diff] [blame] | 59 | |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 60 | static constexpr size_t encIdentifyObjectsSize = 1; |
| 61 | static constexpr size_t chassisIdentifyReqLength = 2; |
| 62 | static constexpr size_t identifyIntervalPos = 0; |
| 63 | static constexpr size_t forceIdentifyPos = 1; |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 64 | |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 65 | namespace ipmi |
| 66 | { |
| 67 | constexpr Cc ccParmNotSupported = 0x80; |
| 68 | |
| 69 | static inline auto responseParmNotSupported() |
| 70 | { |
| 71 | return response(ccParmNotSupported); |
| 72 | } |
| 73 | } // namespace ipmi |
| 74 | |
Adriana Kobylak | 40814c6 | 2015-10-27 15:58:44 -0500 | [diff] [blame] | 75 | void register_netfn_chassis_functions() __attribute__((constructor)); |
| 76 | |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 77 | // Host settings in dbus |
| 78 | // Service name should be referenced by connection name got via object mapper |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 79 | const char* settings_object_name = "/org/openbmc/settings/host0"; |
| 80 | const char* settings_intf_name = "org.freedesktop.DBus.Properties"; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 81 | const char* identify_led_object_name = |
Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 82 | "/xyz/openbmc_project/led/groups/enclosure_identify"; |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 83 | |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 84 | constexpr auto SETTINGS_ROOT = "/"; |
| 85 | constexpr auto SETTINGS_MATCH = "host0"; |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 86 | |
| 87 | constexpr auto IP_INTERFACE = "xyz.openbmc_project.Network.IP"; |
| 88 | constexpr auto MAC_INTERFACE = "xyz.openbmc_project.Network.MACAddress"; |
| 89 | |
Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 90 | static constexpr auto chassisStateRoot = "/xyz/openbmc_project/state"; |
| 91 | static constexpr auto chassisPOHStateIntf = |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 92 | "xyz.openbmc_project.State.PowerOnHours"; |
Patrick Williams | 7345ac4 | 2021-04-30 20:57:39 -0500 | [diff] [blame] | 93 | static constexpr auto pohCounterProperty = "POHCounter"; |
Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 94 | static constexpr auto match = "chassis0"; |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 95 | const static constexpr char chassisCapIntf[] = |
| 96 | "xyz.openbmc_project.Control.ChassisCapabilities"; |
Karthick Sundarrajan | 86d8bd7 | 2019-11-26 12:48:50 -0800 | [diff] [blame] | 97 | const static constexpr char chassisIntrusionProp[] = "ChassisIntrusionEnabled"; |
| 98 | const static constexpr char chassisFrontPanelLockoutProp[] = |
| 99 | "ChassisFrontPanelLockoutEnabled"; |
| 100 | const static constexpr char chassisNMIProp[] = "ChassisNMIEnabled"; |
| 101 | const static constexpr char chassisPowerInterlockProp[] = |
| 102 | "ChassisPowerInterlockEnabled"; |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 103 | const static constexpr char chassisFRUDevAddrProp[] = "FRUDeviceAddress"; |
| 104 | const static constexpr char chassisSDRDevAddrProp[] = "SDRDeviceAddress"; |
| 105 | const static constexpr char chassisSELDevAddrProp[] = "SELDeviceAddress"; |
| 106 | const static constexpr char chassisSMDevAddrProp[] = "SMDeviceAddress"; |
| 107 | const static constexpr char chassisBridgeDevAddrProp[] = "BridgeDeviceAddress"; |
| 108 | static constexpr uint8_t chassisCapFlagMask = 0x0f; |
| 109 | static constexpr uint8_t chassisCapAddrMask = 0xfe; |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 110 | static constexpr const char* powerButtonIntf = |
| 111 | "xyz.openbmc_project.Chassis.Buttons.Power"; |
| 112 | static constexpr const char* powerButtonPath = |
| 113 | "/xyz/openbmc_project/Chassis/Buttons/Power0"; |
| 114 | static constexpr const char* resetButtonIntf = |
| 115 | "xyz.openbmc_project.Chassis.Buttons.Reset"; |
| 116 | static constexpr const char* resetButtonPath = |
| 117 | "/xyz/openbmc_project/Chassis/Buttons/Reset0"; |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 118 | |
Vishwanatha Subbanna | b12b0c0 | 2017-03-07 18:17:19 +0530 | [diff] [blame] | 119 | // Phosphor Host State manager |
| 120 | namespace State = sdbusplus::xyz::openbmc_project::State::server; |
| 121 | |
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; |
| 125 | using namespace sdbusplus::xyz::openbmc_project::Common::Error; |
Marri Devender Rao | 8171970 | 2018-05-07 00:53:48 -0500 | [diff] [blame] | 126 | using namespace sdbusplus::xyz::openbmc_project::Control::Boot::server; |
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"; |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 144 | sdbusplus::bus::bus dbus(ipmid_get_sd_bus_connection()); |
| 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 | |
Ratan Gupta | 01d4bd1 | 2017-08-07 15:53:25 +0530 | [diff] [blame] | 189 | sdbusplus::bus::bus 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 |
| 343 | { |
| 344 | }; |
Patrick Venture | b51bf9c | 2018-09-10 15:53:14 -0700 | [diff] [blame] | 345 | std::memcpy(&addr4.sin_addr.s_addr, &data[offset], addrSize); |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 346 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 347 | inet_ntop(AF_INET, &addr4.sin_addr, ipAddr, INET_ADDRSTRLEN); |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 348 | |
| 349 | break; |
| 350 | } |
| 351 | case AF_INET6: |
| 352 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 353 | struct sockaddr_in6 addr6 |
| 354 | { |
| 355 | }; |
Patrick Venture | b51bf9c | 2018-09-10 15:53:14 -0700 | [diff] [blame] | 356 | std::memcpy(&addr6.sin6_addr.s6_addr, &data[offset], addrSize); |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 357 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 358 | inet_ntop(AF_INET6, &addr6.sin6_addr, ipAddr, INET6_ADDRSTRLEN); |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 359 | |
| 360 | break; |
| 361 | } |
| 362 | default: |
| 363 | { |
| 364 | return {}; |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | return ipAddr; |
| 369 | } |
| 370 | |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 371 | ipmi::Cc setHostNetworkData(ipmi::message::Payload& data) |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 372 | { |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 373 | using namespace std::string_literals; |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 374 | std::string hostNetworkConfig; |
| 375 | std::string mac("00:00:00:00:00:00"); |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 376 | std::string ipAddress, gateway; |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 377 | std::string addrOrigin{0}; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 378 | uint8_t addrSize{0}; |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 379 | std::string addressOrigin = |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 380 | "xyz.openbmc_project.Network.IP.AddressOrigin.DHCP"; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 381 | std::string addressType = "xyz.openbmc_project.Network.IP.Protocol.IPv4"; |
| 382 | uint8_t prefix{0}; |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 383 | uint8_t family = AF_INET; |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 384 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 385 | // cookie starts from second byte |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 386 | // version starts from sixth byte |
| 387 | |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 388 | try |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 389 | { |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 390 | do |
| 391 | { |
| 392 | // cookie == 0x21 0x70 0x62 0x21 |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 393 | data.trailingOk = true; |
| 394 | auto msgLen = data.size(); |
| 395 | std::vector<uint8_t> msgPayloadBytes(msgLen); |
| 396 | if (data.unpack(msgPayloadBytes) != 0 || !data.fullyUnpacked()) |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 397 | { |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 398 | log<level::ERR>( |
| 399 | "Error in unpacking message of setHostNetworkData"); |
| 400 | return ipmi::ccReqDataLenInvalid; |
| 401 | } |
| 402 | |
| 403 | uint8_t* msgPayloadStartingPos = msgPayloadBytes.data(); |
| 404 | constexpr size_t cookieSize = 4; |
| 405 | if (msgLen < cookieOffset + cookieSize) |
| 406 | { |
| 407 | log<level::ERR>( |
| 408 | "Error in cookie getting of setHostNetworkData"); |
| 409 | return ipmi::ccReqDataLenInvalid; |
| 410 | } |
| 411 | if (std::equal(msgPayloadStartingPos + cookieOffset, |
| 412 | msgPayloadStartingPos + cookieOffset + cookieSize, |
| 413 | (netConfInitialBytes + cookieOffset)) != 0) |
| 414 | { |
| 415 | // all cookie == 0 |
| 416 | if (std::all_of(msgPayloadStartingPos + cookieOffset, |
| 417 | msgPayloadStartingPos + cookieOffset + |
| 418 | cookieSize, |
| 419 | [](int i) { return i == 0; }) == true) |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 420 | { |
| 421 | // need to zero out the network settings. |
| 422 | break; |
| 423 | } |
| 424 | |
| 425 | log<level::ERR>("Invalid Cookie"); |
| 426 | elog<InternalFailure>(); |
| 427 | } |
| 428 | |
| 429 | // vesion == 0x00 0x01 |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 430 | if (msgLen < versionOffset + sizeVersion) |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 431 | { |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 432 | log<level::ERR>( |
| 433 | "Error in version getting of setHostNetworkData"); |
| 434 | return ipmi::ccReqDataLenInvalid; |
| 435 | } |
| 436 | if (std::equal(msgPayloadStartingPos + versionOffset, |
| 437 | msgPayloadStartingPos + versionOffset + sizeVersion, |
| 438 | (netConfInitialBytes + versionOffset)) != 0) |
| 439 | { |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 440 | log<level::ERR>("Invalid Version"); |
| 441 | elog<InternalFailure>(); |
| 442 | } |
| 443 | |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 444 | if (msgLen < macOffset + 6) |
| 445 | { |
| 446 | log<level::ERR>( |
| 447 | "Error in mac address getting of setHostNetworkData"); |
| 448 | return ipmi::ccReqDataLenInvalid; |
| 449 | } |
| 450 | std::stringstream result; |
| 451 | std::copy((msgPayloadStartingPos + macOffset), |
| 452 | (msgPayloadStartingPos + macOffset + 5), |
| 453 | std::ostream_iterator<int>(result, ":")); |
| 454 | mac = result.str(); |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 455 | |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 456 | if (msgLen < addrTypeOffset + sizeof(decltype(addrOrigin))) |
| 457 | { |
| 458 | log<level::ERR>( |
| 459 | "Error in original address getting of setHostNetworkData"); |
| 460 | return ipmi::ccReqDataLenInvalid; |
| 461 | } |
| 462 | std::copy(msgPayloadStartingPos + addrTypeOffset, |
| 463 | msgPayloadStartingPos + addrTypeOffset + |
| 464 | sizeof(decltype(addrOrigin)), |
| 465 | std::ostream_iterator<int>(result, "")); |
| 466 | addrOrigin = result.str(); |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 467 | |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 468 | if (!addrOrigin.empty()) |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 469 | { |
| 470 | addressOrigin = |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 471 | "xyz.openbmc_project.Network.IP.AddressOrigin.Static"; |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 472 | } |
| 473 | |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 474 | if (msgLen < addrSizeOffset + sizeof(decltype(addrSize))) |
| 475 | { |
| 476 | log<level::ERR>( |
| 477 | "Error in address size getting of setHostNetworkData"); |
| 478 | return ipmi::ccReqDataLenInvalid; |
| 479 | } |
Ratan Gupta | 6ec7daa | 2017-07-15 14:13:01 +0530 | [diff] [blame] | 480 | // Get the address size |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 481 | std::copy(msgPayloadStartingPos + addrSizeOffset, |
| 482 | (msgPayloadStartingPos + addrSizeOffset + |
| 483 | sizeof(decltype(addrSize))), |
| 484 | &addrSize); |
Ratan Gupta | dcb1067 | 2017-07-10 10:33:50 +0530 | [diff] [blame] | 485 | |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 486 | uint8_t prefixOffset = ipAddrOffset + addrSize; |
| 487 | if (msgLen < prefixOffset + sizeof(decltype(prefix))) |
| 488 | { |
| 489 | log<level::ERR>( |
| 490 | "Error in prefix getting of setHostNetworkData"); |
| 491 | return ipmi::ccReqDataLenInvalid; |
| 492 | } |
| 493 | std::copy(msgPayloadStartingPos + prefixOffset, |
| 494 | (msgPayloadStartingPos + prefixOffset + |
| 495 | sizeof(decltype(prefix))), |
| 496 | &prefix); |
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 | |
Ratan Gupta | 01d4bd1 | 2017-08-07 15:53:25 +0530 | [diff] [blame] | 531 | sdbusplus::bus::bus bus(ipmid_get_sd_bus_connection()); |
| 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 | { |
| 567 | sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()}; |
| 568 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 569 | auto chassisStateObj = |
| 570 | ipmi::getDbusObject(bus, chassisPOHStateIntf, chassisStateRoot, match); |
Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 571 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 572 | auto service = |
| 573 | ipmi::getService(bus, chassisPOHStateIntf, chassisStateObj.first); |
Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 574 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 575 | auto propValue = |
| 576 | ipmi::getDbusProperty(bus, service, chassisStateObj.first, |
Patrick Williams | 7345ac4 | 2021-04-30 20:57:39 -0500 | [diff] [blame] | 577 | chassisPOHStateIntf, 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 | { |
| 608 | sdbusplus::bus::bus 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 | |
anil kumar appana | 43263c6 | 2019-05-27 12:45:04 +0000 | [diff] [blame] | 625 | properties = |
| 626 | ipmi::getAllDbusProperties(bus, chassisCapObject.second, |
| 627 | chassisCapObject.first, 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 | |
| 732 | // check input data |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 733 | if (reserved1 != 0) |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 734 | { |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 735 | log<level::ERR>("Unsupported request parameter"); |
| 736 | return ipmi::responseInvalidFieldRequest(); |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 737 | } |
| 738 | |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 739 | if ((fruDeviceAddr & ~chassisCapAddrMask) != 0) |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 740 | { |
| 741 | log<level::ERR>("Unsupported request parameter(FRU Addr)", |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 742 | entry("REQ=0x%x", fruDeviceAddr)); |
| 743 | return ipmi::responseInvalidFieldRequest(); |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 744 | } |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 745 | if ((sdrDeviceAddr & ~chassisCapAddrMask) != 0) |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 746 | { |
| 747 | log<level::ERR>("Unsupported request parameter(SDR Addr)", |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 748 | entry("REQ=0x%x", sdrDeviceAddr)); |
| 749 | return ipmi::responseInvalidFieldRequest(); |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 750 | } |
| 751 | |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 752 | if ((selDeviceAddr & ~chassisCapAddrMask) != 0) |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 753 | { |
| 754 | log<level::ERR>("Unsupported request parameter(SEL Addr)", |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 755 | entry("REQ=0x%x", selDeviceAddr)); |
| 756 | return ipmi::responseInvalidFieldRequest(); |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 757 | } |
| 758 | |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 759 | if ((smDeviceAddr & ~chassisCapAddrMask) != 0) |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 760 | { |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 761 | log<level::ERR>("Unsupported request parameter(SM Addr)", |
| 762 | entry("REQ=0x%x", smDeviceAddr)); |
| 763 | return ipmi::responseInvalidFieldRequest(); |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 764 | } |
| 765 | |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 766 | if ((bridgeDeviceAddr & ~chassisCapAddrMask) != 0) |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 767 | { |
| 768 | log<level::ERR>("Unsupported request parameter(Bridge Addr)", |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 769 | entry("REQ=0x%x", bridgeDeviceAddr)); |
| 770 | return ipmi::responseInvalidFieldRequest(); |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 771 | } |
| 772 | |
| 773 | try |
| 774 | { |
| 775 | sdbusplus::bus::bus bus(ipmid_get_sd_bus_connection()); |
| 776 | ipmi::DbusObjectInfo chassisCapObject = |
| 777 | ipmi::getDbusObject(bus, chassisCapIntf); |
| 778 | |
| 779 | ipmi::setDbusProperty(bus, chassisCapObject.second, |
| 780 | chassisCapObject.first, chassisCapIntf, |
Karthick Sundarrajan | 86d8bd7 | 2019-11-26 12:48:50 -0800 | [diff] [blame] | 781 | chassisIntrusionProp, intrusion); |
| 782 | |
| 783 | ipmi::setDbusProperty(bus, chassisCapObject.second, |
| 784 | chassisCapObject.first, chassisCapIntf, |
| 785 | chassisFrontPanelLockoutProp, fpLockout); |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 786 | |
| 787 | ipmi::setDbusProperty(bus, chassisCapObject.second, |
| 788 | chassisCapObject.first, chassisCapIntf, |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 789 | chassisFRUDevAddrProp, fruDeviceAddr); |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 790 | |
| 791 | ipmi::setDbusProperty(bus, chassisCapObject.second, |
| 792 | chassisCapObject.first, chassisCapIntf, |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 793 | chassisSDRDevAddrProp, sdrDeviceAddr); |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 794 | |
| 795 | ipmi::setDbusProperty(bus, chassisCapObject.second, |
| 796 | chassisCapObject.first, chassisCapIntf, |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 797 | chassisSELDevAddrProp, selDeviceAddr); |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 798 | |
| 799 | ipmi::setDbusProperty(bus, chassisCapObject.second, |
| 800 | chassisCapObject.first, chassisCapIntf, |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 801 | chassisSMDevAddrProp, smDeviceAddr); |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 802 | |
| 803 | ipmi::setDbusProperty(bus, chassisCapObject.second, |
| 804 | chassisCapObject.first, chassisCapIntf, |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 805 | chassisBridgeDevAddrProp, bridgeDeviceAddr); |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 806 | } |
Patrick Williams | a2ad2da | 2021-10-06 12:21:46 -0500 | [diff] [blame] | 807 | catch (const std::exception& e) |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 808 | { |
| 809 | log<level::ERR>(e.what()); |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 810 | return ipmi::responseUnspecifiedError(); |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 811 | } |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 812 | return ipmi::responseSuccess(); |
Nan Li | 8d15fb4 | 2016-08-16 22:29:40 +0800 | [diff] [blame] | 813 | } |
| 814 | |
Vishwanatha Subbanna | b12b0c0 | 2017-03-07 18:17:19 +0530 | [diff] [blame] | 815 | //------------------------------------------ |
| 816 | // Calls into Host State Manager Dbus object |
| 817 | //------------------------------------------ |
| 818 | int initiate_state_transition(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 |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 821 | constexpr auto HOST_STATE_MANAGER_ROOT = "/xyz/openbmc_project/state/host0"; |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 822 | constexpr auto HOST_STATE_MANAGER_IFACE = "xyz.openbmc_project.State.Host"; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 823 | constexpr auto DBUS_PROPERTY_IFACE = "org.freedesktop.DBus.Properties"; |
| 824 | constexpr auto PROPERTY = "RequestedHostTransition"; |
Vishwanatha Subbanna | b12b0c0 | 2017-03-07 18:17:19 +0530 | [diff] [blame] | 825 | |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 826 | // sd_bus error |
| 827 | int rc = 0; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 828 | char* busname = NULL; |
vishwa | 3699327 | 2015-11-20 12:43:49 -0600 | [diff] [blame] | 829 | |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 830 | // SD Bus error report mechanism. |
| 831 | sd_bus_error bus_error = SD_BUS_ERROR_NULL; |
vishwa | 3699327 | 2015-11-20 12:43:49 -0600 | [diff] [blame] | 832 | |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 833 | // Gets a hook onto either a SYSTEM or SESSION bus |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 834 | sd_bus* bus_type = ipmid_get_sd_bus_connection(); |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 835 | rc = mapper_get_service(bus_type, HOST_STATE_MANAGER_ROOT, &busname); |
| 836 | if (rc < 0) |
| 837 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 838 | log<level::ERR>( |
| 839 | "Failed to get bus name", |
| 840 | entry("ERRNO=0x%X, OBJPATH=%s", -rc, HOST_STATE_MANAGER_ROOT)); |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 841 | return rc; |
| 842 | } |
Vishwanatha Subbanna | b12b0c0 | 2017-03-07 18:17:19 +0530 | [diff] [blame] | 843 | |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 844 | // Convert to string equivalent of the passed in transition enum. |
| 845 | auto request = State::convertForMessage(transition); |
Vishwanatha Subbanna | b12b0c0 | 2017-03-07 18:17:19 +0530 | [diff] [blame] | 846 | |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 847 | rc = sd_bus_call_method(bus_type, // On the system bus |
| 848 | busname, // Service to contact |
| 849 | HOST_STATE_MANAGER_ROOT, // Object path |
| 850 | DBUS_PROPERTY_IFACE, // Interface name |
| 851 | "Set", // Method to be called |
| 852 | &bus_error, // object to return error |
| 853 | nullptr, // Response buffer if any |
| 854 | "ssv", // Takes 3 arguments |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 855 | HOST_STATE_MANAGER_IFACE, PROPERTY, "s", |
| 856 | request.c_str()); |
| 857 | if (rc < 0) |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 858 | { |
| 859 | log<level::ERR>("Failed to initiate transition", |
Aditya Saripalli | 5fb1460 | 2017-11-09 14:46:27 +0530 | [diff] [blame] | 860 | entry("ERRNO=0x%X, REQUEST=%s", -rc, request.c_str())); |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 861 | } |
| 862 | else |
| 863 | { |
| 864 | log<level::INFO>("Transition request initiated successfully"); |
| 865 | } |
vishwa | 3699327 | 2015-11-20 12:43:49 -0600 | [diff] [blame] | 866 | |
| 867 | sd_bus_error_free(&bus_error); |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame] | 868 | free(busname); |
vishwa | 3699327 | 2015-11-20 12:43:49 -0600 | [diff] [blame] | 869 | |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame] | 870 | return rc; |
vishwa | 3699327 | 2015-11-20 12:43:49 -0600 | [diff] [blame] | 871 | } |
| 872 | |
Kuiying Wang | 6b0ceaa | 2019-11-05 15:13:40 +0800 | [diff] [blame] | 873 | //------------------------------------------ |
| 874 | // Set Enabled property to inform NMI source |
| 875 | // handling to trigger a NMI_OUT BSOD. |
| 876 | //------------------------------------------ |
| 877 | int setNmiProperty(const bool value) |
| 878 | { |
| 879 | constexpr const char* nmiSourceObjPath = |
| 880 | "/xyz/openbmc_project/Chassis/Control/NMISource"; |
| 881 | constexpr const char* nmiSourceIntf = |
| 882 | "xyz.openbmc_project.Chassis.Control.NMISource"; |
| 883 | std::string bmcSourceSignal = "xyz.openbmc_project.Chassis.Control." |
| 884 | "NMISource.BMCSourceSignal.ChassisCmd"; |
| 885 | std::shared_ptr<sdbusplus::asio::connection> busp = getSdBus(); |
| 886 | |
| 887 | try |
| 888 | { |
| 889 | auto service = ipmi::getService(*busp, nmiSourceIntf, nmiSourceObjPath); |
| 890 | ipmi::setDbusProperty(*busp, service, nmiSourceObjPath, nmiSourceIntf, |
| 891 | "BMCSource", bmcSourceSignal); |
| 892 | ipmi::setDbusProperty(*busp, service, nmiSourceObjPath, nmiSourceIntf, |
| 893 | "Enabled", value); |
| 894 | } |
Patrick Williams | a2ad2da | 2021-10-06 12:21:46 -0500 | [diff] [blame] | 895 | catch (const std::exception& e) |
Kuiying Wang | 6b0ceaa | 2019-11-05 15:13:40 +0800 | [diff] [blame] | 896 | { |
| 897 | log<level::ERR>("Failed to trigger NMI_OUT", |
| 898 | entry("EXCEPTION=%s", e.what())); |
| 899 | return -1; |
| 900 | } |
| 901 | |
| 902 | return 0; |
| 903 | } |
| 904 | |
Deepak Kodihalli | 18b70d1 | 2017-07-21 13:36:33 -0500 | [diff] [blame] | 905 | namespace power_policy |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 906 | { |
Nan Li | fdd8ec5 | 2016-08-28 03:57:40 +0800 | [diff] [blame] | 907 | |
Deepak Kodihalli | 18b70d1 | 2017-07-21 13:36:33 -0500 | [diff] [blame] | 908 | using namespace sdbusplus::xyz::openbmc_project::Control::Power::server; |
| 909 | using IpmiValue = uint8_t; |
| 910 | using DbusValue = RestorePolicy::Policy; |
Nan Li | fdd8ec5 | 2016-08-28 03:57:40 +0800 | [diff] [blame] | 911 | |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 912 | const std::map<DbusValue, IpmiValue> dbusToIpmi = { |
Deepak Kodihalli | 18b70d1 | 2017-07-21 13:36:33 -0500 | [diff] [blame] | 913 | {RestorePolicy::Policy::AlwaysOff, 0x00}, |
| 914 | {RestorePolicy::Policy::Restore, 0x01}, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 915 | {RestorePolicy::Policy::AlwaysOn, 0x02}}; |
Nan Li | fdd8ec5 | 2016-08-28 03:57:40 +0800 | [diff] [blame] | 916 | |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 917 | static constexpr uint8_t noChange = 0x03; |
| 918 | static constexpr uint8_t allSupport = 0x01 | 0x02 | 0x04; |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 919 | |
| 920 | /* helper function for Get Chassis Status Command |
| 921 | */ |
| 922 | std::optional<uint2_t> getPowerRestorePolicy() |
| 923 | { |
| 924 | uint2_t restorePolicy = 0; |
| 925 | using namespace chassis::internal; |
| 926 | |
James Feist | 225dec8 | 2019-11-26 16:25:06 -0800 | [diff] [blame] | 927 | settings::Objects& objects = cache::getObjects(); |
| 928 | |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 929 | try |
| 930 | { |
| 931 | const auto& powerRestoreSetting = |
James Feist | 225dec8 | 2019-11-26 16:25:06 -0800 | [diff] [blame] | 932 | objects.map.at(powerRestoreIntf).front(); |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 933 | ipmi::Value result = ipmi::getDbusProperty( |
| 934 | *getSdBus(), |
James Feist | 225dec8 | 2019-11-26 16:25:06 -0800 | [diff] [blame] | 935 | objects.service(powerRestoreSetting, powerRestoreIntf).c_str(), |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 936 | powerRestoreSetting.c_str(), powerRestoreIntf, |
| 937 | "PowerRestorePolicy"); |
| 938 | auto powerRestore = RestorePolicy::convertPolicyFromString( |
| 939 | std::get<std::string>(result)); |
| 940 | restorePolicy = dbusToIpmi.at(powerRestore); |
| 941 | } |
| 942 | catch (const std::exception& e) |
| 943 | { |
| 944 | log<level::ERR>( |
| 945 | "Failed to fetch pgood property", entry("ERROR=%s", e.what()), |
James Feist | 225dec8 | 2019-11-26 16:25:06 -0800 | [diff] [blame] | 946 | entry("PATH=%s", objects.map.at(powerRestoreIntf).front().c_str()), |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 947 | entry("INTERFACE=%s", powerRestoreIntf)); |
James Feist | 225dec8 | 2019-11-26 16:25:06 -0800 | [diff] [blame] | 948 | cache::objectsPtr.reset(); |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 949 | return std::nullopt; |
| 950 | } |
| 951 | return std::make_optional(restorePolicy); |
| 952 | } |
| 953 | |
| 954 | /* |
| 955 | * getPowerStatus |
| 956 | * helper function for Get Chassis Status Command |
| 957 | * return - optional value for pgood (no value on error) |
| 958 | */ |
| 959 | std::optional<bool> getPowerStatus() |
| 960 | { |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 961 | bool powerGood = false; |
| 962 | std::shared_ptr<sdbusplus::asio::connection> busp = getSdBus(); |
| 963 | try |
| 964 | { |
Jason M. Bills | 3de424c | 2019-05-21 09:57:16 -0700 | [diff] [blame] | 965 | constexpr const char* chassisStatePath = |
| 966 | "/xyz/openbmc_project/state/chassis0"; |
| 967 | constexpr const char* chassisStateIntf = |
| 968 | "xyz.openbmc_project.State.Chassis"; |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 969 | auto service = |
Jason M. Bills | 3de424c | 2019-05-21 09:57:16 -0700 | [diff] [blame] | 970 | ipmi::getService(*busp, chassisStateIntf, chassisStatePath); |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 971 | |
Jason M. Bills | 3de424c | 2019-05-21 09:57:16 -0700 | [diff] [blame] | 972 | ipmi::Value powerState = |
| 973 | ipmi::getDbusProperty(*busp, service, chassisStatePath, |
| 974 | chassisStateIntf, "CurrentPowerState"); |
| 975 | powerGood = std::get<std::string>(powerState) == |
| 976 | "xyz.openbmc_project.State.Chassis.PowerState.On"; |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 977 | } |
| 978 | catch (const std::exception& e) |
| 979 | { |
| 980 | try |
| 981 | { |
| 982 | // FIXME: some legacy modules use the older path; try that next |
| 983 | constexpr const char* legacyPwrCtrlObj = |
| 984 | "/org/openbmc/control/power0"; |
| 985 | constexpr const char* legacyPwrCtrlIntf = |
| 986 | "org.openbmc.control.Power"; |
| 987 | auto service = |
| 988 | ipmi::getService(*busp, legacyPwrCtrlIntf, legacyPwrCtrlObj); |
| 989 | |
| 990 | ipmi::Value variant = ipmi::getDbusProperty( |
| 991 | *busp, service, legacyPwrCtrlObj, legacyPwrCtrlIntf, "pgood"); |
| 992 | powerGood = static_cast<bool>(std::get<int>(variant)); |
| 993 | } |
| 994 | catch (const std::exception& e) |
| 995 | { |
| 996 | log<level::ERR>("Failed to fetch pgood property", |
Jason M. Bills | 3de424c | 2019-05-21 09:57:16 -0700 | [diff] [blame] | 997 | entry("ERROR=%s", e.what())); |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 998 | return std::nullopt; |
| 999 | } |
| 1000 | } |
| 1001 | return std::make_optional(powerGood); |
| 1002 | } |
| 1003 | |
Yong Li | 70ce735 | 2019-05-16 21:15:27 +0800 | [diff] [blame] | 1004 | /* |
| 1005 | * getACFailStatus |
| 1006 | * helper function for Get Chassis Status Command |
| 1007 | * return - bool value for ACFail (false on error) |
| 1008 | */ |
| 1009 | bool getACFailStatus() |
| 1010 | { |
| 1011 | constexpr const char* powerControlObj = |
| 1012 | "/xyz/openbmc_project/Chassis/Control/Power0"; |
| 1013 | constexpr const char* powerControlIntf = |
| 1014 | "xyz.openbmc_project.Chassis.Control.Power"; |
| 1015 | bool acFail = false; |
| 1016 | std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus(); |
| 1017 | try |
| 1018 | { |
| 1019 | auto service = |
| 1020 | ipmi::getService(*bus, powerControlIntf, powerControlObj); |
| 1021 | |
| 1022 | ipmi::Value variant = ipmi::getDbusProperty( |
| 1023 | *bus, service, powerControlObj, powerControlIntf, "PFail"); |
| 1024 | acFail = std::get<bool>(variant); |
| 1025 | } |
| 1026 | catch (const std::exception& e) |
| 1027 | { |
| 1028 | log<level::ERR>("Failed to fetch PFail property", |
| 1029 | entry("ERROR=%s", e.what()), |
| 1030 | entry("PATH=%s", powerControlObj), |
| 1031 | entry("INTERFACE=%s", powerControlIntf)); |
| 1032 | } |
| 1033 | return acFail; |
| 1034 | } |
Deepak Kodihalli | 18b70d1 | 2017-07-21 13:36:33 -0500 | [diff] [blame] | 1035 | } // namespace power_policy |
Nan Li | fdd8ec5 | 2016-08-28 03:57:40 +0800 | [diff] [blame] | 1036 | |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1037 | static std::optional<bool> getButtonEnabled(const std::string& buttonPath, |
| 1038 | const std::string& buttonIntf) |
| 1039 | { |
| 1040 | std::shared_ptr<sdbusplus::asio::connection> busp = getSdBus(); |
| 1041 | bool buttonDisabled = false; |
| 1042 | try |
| 1043 | { |
| 1044 | auto service = ipmi::getService(*busp, buttonIntf, buttonPath); |
| 1045 | ipmi::Value enabled = ipmi::getDbusProperty(*busp, service, buttonPath, |
| 1046 | buttonIntf, "Enabled"); |
| 1047 | buttonDisabled = !std::get<bool>(enabled); |
| 1048 | } |
Patrick Williams | a2ad2da | 2021-10-06 12:21:46 -0500 | [diff] [blame] | 1049 | catch (const sdbusplus::exception::exception& e) |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1050 | { |
| 1051 | log<level::ERR>("Fail to get button Enabled property", |
| 1052 | entry("PATH=%s", buttonPath.c_str()), |
| 1053 | entry("ERROR=%s", e.what())); |
| 1054 | return std::nullopt; |
| 1055 | } |
| 1056 | return std::make_optional(buttonDisabled); |
| 1057 | } |
| 1058 | |
Kuiying Wang | 21addc5 | 2019-01-04 10:50:21 +0800 | [diff] [blame] | 1059 | static bool setButtonEnabled(ipmi::Context::ptr& ctx, |
| 1060 | const std::string& buttonPath, |
| 1061 | const std::string& buttonIntf, bool enable) |
| 1062 | { |
| 1063 | std::string service; |
| 1064 | boost::system::error_code ec; |
| 1065 | ec = ipmi::getService(ctx, buttonIntf, buttonPath, service); |
| 1066 | if (!ec) |
| 1067 | { |
| 1068 | ec = ipmi::setDbusProperty(ctx, service, buttonPath, buttonIntf, |
| 1069 | "Enabled", enable); |
| 1070 | } |
| 1071 | if (ec) |
| 1072 | { |
| 1073 | log<level::ERR>("Fail to set button Enabled property", |
| 1074 | entry("SERVICE=%s", service.c_str()), |
| 1075 | entry("PATH=%s", buttonPath.c_str()), |
| 1076 | entry("ERROR=%s", ec.message().c_str())); |
| 1077 | return false; |
| 1078 | } |
| 1079 | return true; |
| 1080 | } |
| 1081 | |
Nan Li | fdd8ec5 | 2016-08-28 03:57:40 +0800 | [diff] [blame] | 1082 | //---------------------------------------------------------------------- |
| 1083 | // Get Chassis Status commands |
| 1084 | //---------------------------------------------------------------------- |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1085 | ipmi::RspType<bool, // Power is on |
| 1086 | bool, // Power overload |
| 1087 | bool, // Interlock |
| 1088 | bool, // power fault |
| 1089 | bool, // power control fault |
| 1090 | uint2_t, // power restore policy |
| 1091 | bool, // reserved |
| 1092 | |
| 1093 | bool, // AC failed |
| 1094 | bool, // last power down caused by a Power overload |
| 1095 | bool, // last power down caused by a power interlock |
| 1096 | bool, // last power down caused by power fault |
| 1097 | bool, // last ‘Power is on’ state was entered via IPMI command |
| 1098 | uint3_t, // reserved |
| 1099 | |
| 1100 | bool, // Chassis intrusion active |
| 1101 | bool, // Front Panel Lockout active |
| 1102 | bool, // Drive Fault |
| 1103 | bool, // Cooling/fan fault detected |
| 1104 | uint2_t, // Chassis Identify State |
| 1105 | bool, // Chassis Identify command and state info supported |
| 1106 | bool, // reserved |
| 1107 | |
| 1108 | bool, // Power off button disabled |
| 1109 | bool, // Reset button disabled |
| 1110 | bool, // Diagnostic Interrupt button disabled |
| 1111 | bool, // Standby (sleep) button disabled |
| 1112 | bool, // Power off button disable allowed |
| 1113 | bool, // Reset button disable allowed |
| 1114 | bool, // Diagnostic Interrupt button disable allowed |
| 1115 | bool // Standby (sleep) button disable allowed |
| 1116 | > |
| 1117 | ipmiGetChassisStatus() |
Nan Li | fdd8ec5 | 2016-08-28 03:57:40 +0800 | [diff] [blame] | 1118 | { |
Deepak Kodihalli | 18b70d1 | 2017-07-21 13:36:33 -0500 | [diff] [blame] | 1119 | using namespace chassis::internal; |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1120 | std::optional<uint2_t> restorePolicy = |
| 1121 | power_policy::getPowerRestorePolicy(); |
| 1122 | std::optional<bool> powerGood = power_policy::getPowerStatus(); |
| 1123 | if (!restorePolicy || !powerGood) |
Deepak Kodihalli | 18b70d1 | 2017-07-21 13:36:33 -0500 | [diff] [blame] | 1124 | { |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1125 | return ipmi::responseUnspecifiedError(); |
Deepak Kodihalli | 18b70d1 | 2017-07-21 13:36:33 -0500 | [diff] [blame] | 1126 | } |
Nan Li | fdd8ec5 | 2016-08-28 03:57:40 +0800 | [diff] [blame] | 1127 | |
| 1128 | // Front Panel Button Capabilities and disable/enable status(Optional) |
Vernon Mauery | 6d5b2f7 | 2019-05-16 14:48:47 -0700 | [diff] [blame] | 1129 | std::optional<bool> powerButtonReading = |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1130 | getButtonEnabled(powerButtonPath, powerButtonIntf); |
Vernon Mauery | 6d5b2f7 | 2019-05-16 14:48:47 -0700 | [diff] [blame] | 1131 | // allow disable if the interface is present |
| 1132 | bool powerButtonDisableAllow = static_cast<bool>(powerButtonReading); |
| 1133 | // default return the button is enabled (not disabled) |
| 1134 | bool powerButtonDisabled = false; |
| 1135 | if (powerButtonDisableAllow) |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1136 | { |
Vernon Mauery | 6d5b2f7 | 2019-05-16 14:48:47 -0700 | [diff] [blame] | 1137 | // return the real value of the button status, if present |
| 1138 | powerButtonDisabled = *powerButtonReading; |
| 1139 | } |
| 1140 | |
| 1141 | std::optional<bool> resetButtonReading = |
| 1142 | getButtonEnabled(resetButtonPath, resetButtonIntf); |
| 1143 | // allow disable if the interface is present |
| 1144 | bool resetButtonDisableAllow = static_cast<bool>(resetButtonReading); |
| 1145 | // default return the button is enabled (not disabled) |
| 1146 | bool resetButtonDisabled = false; |
| 1147 | if (resetButtonDisableAllow) |
| 1148 | { |
| 1149 | // return the real value of the button status, if present |
| 1150 | resetButtonDisabled = *resetButtonReading; |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1151 | } |
Nan Li | fdd8ec5 | 2016-08-28 03:57:40 +0800 | [diff] [blame] | 1152 | |
Yong Li | 70ce735 | 2019-05-16 21:15:27 +0800 | [diff] [blame] | 1153 | bool powerDownAcFailed = power_policy::getACFailStatus(); |
| 1154 | |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1155 | // This response has a lot of hard-coded, unsupported fields |
| 1156 | // They are set to false or 0 |
| 1157 | constexpr bool powerOverload = false; |
| 1158 | constexpr bool chassisInterlock = false; |
| 1159 | constexpr bool powerFault = false; |
| 1160 | constexpr bool powerControlFault = false; |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1161 | constexpr bool powerDownOverload = false; |
| 1162 | constexpr bool powerDownInterlock = false; |
| 1163 | constexpr bool powerDownPowerFault = false; |
| 1164 | constexpr bool powerStatusIPMI = false; |
| 1165 | constexpr bool chassisIntrusionActive = false; |
| 1166 | constexpr bool frontPanelLockoutActive = false; |
| 1167 | constexpr bool driveFault = false; |
| 1168 | constexpr bool coolingFanFault = false; |
| 1169 | // chassisIdentifySupport set because this command is implemented |
| 1170 | constexpr bool chassisIdentifySupport = true; |
William A. Kennington III | 7a0e5df | 2021-05-19 13:31:29 -0700 | [diff] [blame] | 1171 | uint2_t chassisIdentifyState = types::enum_cast<uint2_t>(chassisIDState); |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1172 | constexpr bool diagButtonDisabled = false; |
| 1173 | constexpr bool sleepButtonDisabled = false; |
| 1174 | constexpr bool diagButtonDisableAllow = false; |
| 1175 | constexpr bool sleepButtonDisableAllow = false; |
| 1176 | |
| 1177 | return ipmi::responseSuccess( |
| 1178 | *powerGood, powerOverload, chassisInterlock, powerFault, |
| 1179 | powerControlFault, *restorePolicy, |
| 1180 | false, // reserved |
| 1181 | |
| 1182 | powerDownAcFailed, powerDownOverload, powerDownInterlock, |
| 1183 | powerDownPowerFault, powerStatusIPMI, |
| 1184 | uint3_t(0), // reserved |
| 1185 | |
| 1186 | chassisIntrusionActive, frontPanelLockoutActive, driveFault, |
| 1187 | coolingFanFault, chassisIdentifyState, chassisIdentifySupport, |
| 1188 | false, // reserved |
| 1189 | |
Vernon Mauery | 6d5b2f7 | 2019-05-16 14:48:47 -0700 | [diff] [blame] | 1190 | powerButtonDisabled, resetButtonDisabled, diagButtonDisabled, |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 1191 | sleepButtonDisabled, powerButtonDisableAllow, resetButtonDisableAllow, |
| 1192 | diagButtonDisableAllow, sleepButtonDisableAllow); |
Nan Li | fdd8ec5 | 2016-08-28 03:57:40 +0800 | [diff] [blame] | 1193 | } |
Chris Austen | 7888c4d | 2015-12-03 15:26:20 -0600 | [diff] [blame] | 1194 | |
Vijay Khemka | 074f64d | 2020-03-03 15:08:43 -0800 | [diff] [blame] | 1195 | enum class IpmiRestartCause |
| 1196 | { |
| 1197 | Unknown = 0x0, |
| 1198 | RemoteCommand = 0x1, |
| 1199 | ResetButton = 0x2, |
| 1200 | PowerButton = 0x3, |
| 1201 | WatchdogTimer = 0x4, |
| 1202 | PowerPolicyAlwaysOn = 0x6, |
| 1203 | PowerPolicyPreviousState = 0x7, |
| 1204 | SoftReset = 0xa, |
| 1205 | }; |
| 1206 | |
| 1207 | static IpmiRestartCause |
| 1208 | restartCauseToIpmiRestartCause(State::Host::RestartCause cause) |
| 1209 | { |
| 1210 | switch (cause) |
| 1211 | { |
| 1212 | case State::Host::RestartCause::Unknown: |
| 1213 | { |
| 1214 | return IpmiRestartCause::Unknown; |
| 1215 | } |
| 1216 | case State::Host::RestartCause::RemoteCommand: |
| 1217 | { |
| 1218 | return IpmiRestartCause::RemoteCommand; |
| 1219 | } |
| 1220 | case State::Host::RestartCause::ResetButton: |
| 1221 | { |
| 1222 | return IpmiRestartCause::ResetButton; |
| 1223 | } |
| 1224 | case State::Host::RestartCause::PowerButton: |
| 1225 | { |
| 1226 | return IpmiRestartCause::PowerButton; |
| 1227 | } |
| 1228 | case State::Host::RestartCause::WatchdogTimer: |
| 1229 | { |
| 1230 | return IpmiRestartCause::WatchdogTimer; |
| 1231 | } |
| 1232 | case State::Host::RestartCause::PowerPolicyAlwaysOn: |
| 1233 | { |
| 1234 | return IpmiRestartCause::PowerPolicyAlwaysOn; |
| 1235 | } |
| 1236 | case State::Host::RestartCause::PowerPolicyPreviousState: |
| 1237 | { |
| 1238 | return IpmiRestartCause::PowerPolicyPreviousState; |
| 1239 | } |
| 1240 | case State::Host::RestartCause::SoftReset: |
| 1241 | { |
| 1242 | return IpmiRestartCause::SoftReset; |
| 1243 | } |
| 1244 | default: |
| 1245 | { |
| 1246 | return IpmiRestartCause::Unknown; |
| 1247 | } |
| 1248 | } |
| 1249 | } |
| 1250 | |
| 1251 | /* |
| 1252 | * getRestartCause |
| 1253 | * helper function for Get Host restart cause Command |
| 1254 | * return - optional value for RestartCause (no value on error) |
| 1255 | */ |
| 1256 | static std::optional<uint4_t> getRestartCause(ipmi::Context::ptr ctx) |
| 1257 | { |
| 1258 | constexpr const char* restartCausePath = |
| 1259 | "/xyz/openbmc_project/control/host0/restart_cause"; |
| 1260 | constexpr const char* restartCauseIntf = |
| 1261 | "xyz.openbmc_project.Control.Host.RestartCause"; |
| 1262 | |
| 1263 | std::string service; |
| 1264 | boost::system::error_code ec = |
| 1265 | ipmi::getService(ctx, restartCauseIntf, restartCausePath, service); |
| 1266 | if (!ec) |
| 1267 | { |
| 1268 | std::string restartCauseStr; |
| 1269 | ec = ipmi::getDbusProperty<std::string>( |
| 1270 | ctx, service, restartCausePath, restartCauseIntf, "RestartCause", |
| 1271 | restartCauseStr); |
| 1272 | if (!ec) |
| 1273 | { |
| 1274 | auto cause = |
| 1275 | State::Host::convertRestartCauseFromString(restartCauseStr); |
William A. Kennington III | 7a0e5df | 2021-05-19 13:31:29 -0700 | [diff] [blame] | 1276 | return types::enum_cast<uint4_t>( |
| 1277 | restartCauseToIpmiRestartCause(cause)); |
Vijay Khemka | 074f64d | 2020-03-03 15:08:43 -0800 | [diff] [blame] | 1278 | } |
| 1279 | } |
| 1280 | |
| 1281 | log<level::ERR>("Failed to fetch RestartCause property", |
| 1282 | entry("ERROR=%s", ec.message().c_str()), |
| 1283 | entry("PATH=%s", restartCausePath), |
| 1284 | entry("INTERFACE=%s", restartCauseIntf)); |
| 1285 | return std::nullopt; |
| 1286 | } |
| 1287 | |
| 1288 | ipmi::RspType<uint4_t, // Restart Cause |
| 1289 | uint4_t, // reserved |
| 1290 | uint8_t // channel number (not supported) |
| 1291 | > |
| 1292 | ipmiGetSystemRestartCause(ipmi::Context::ptr ctx) |
| 1293 | { |
| 1294 | std::optional<uint4_t> cause = getRestartCause(ctx); |
| 1295 | if (!cause) |
| 1296 | { |
| 1297 | return ipmi::responseUnspecifiedError(); |
| 1298 | } |
| 1299 | |
Vernon Mauery | 916d423 | 2021-03-29 13:42:16 -0700 | [diff] [blame] | 1300 | constexpr uint4_t reserved = 0; |
| 1301 | auto channel = static_cast<uint8_t>(ctx->channel); |
| 1302 | return ipmi::responseSuccess(cause.value(), reserved, channel); |
Vijay Khemka | 074f64d | 2020-03-03 15:08:43 -0800 | [diff] [blame] | 1303 | } |
| 1304 | |
Vishwanatha Subbanna | 83b5c1c | 2017-01-25 18:41:51 +0530 | [diff] [blame] | 1305 | //------------------------------------------------------------- |
| 1306 | // Send a command to SoftPowerOff application to stop any timer |
| 1307 | //------------------------------------------------------------- |
| 1308 | int stop_soft_off_timer() |
| 1309 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1310 | constexpr auto iface = "org.freedesktop.DBus.Properties"; |
| 1311 | constexpr auto soft_off_iface = "xyz.openbmc_project.Ipmi.Internal." |
| 1312 | "SoftPowerOff"; |
Vishwanatha Subbanna | 83b5c1c | 2017-01-25 18:41:51 +0530 | [diff] [blame] | 1313 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1314 | constexpr auto property = "ResponseReceived"; |
| 1315 | constexpr auto value = "xyz.openbmc_project.Ipmi.Internal." |
| 1316 | "SoftPowerOff.HostResponse.HostShutdown"; |
Vishwanatha Subbanna | 83b5c1c | 2017-01-25 18:41:51 +0530 | [diff] [blame] | 1317 | |
| 1318 | // Get the system bus where most system services are provided. |
| 1319 | auto bus = ipmid_get_sd_bus_connection(); |
| 1320 | |
| 1321 | // Get the service name |
Andrew Geissler | 2b4e459 | 2017-06-08 11:18:35 -0500 | [diff] [blame] | 1322 | // TODO openbmc/openbmc#1661 - Mapper refactor |
| 1323 | // |
| 1324 | // See openbmc/openbmc#1743 for some details but high level summary is that |
| 1325 | // for now the code will directly call the soft off interface due to a |
| 1326 | // race condition with mapper usage |
| 1327 | // |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1328 | // char *busname = nullptr; |
| 1329 | // auto r = mapper_get_service(bus, SOFTOFF_OBJPATH, &busname); |
| 1330 | // if (r < 0) |
Andrew Geissler | 2b4e459 | 2017-06-08 11:18:35 -0500 | [diff] [blame] | 1331 | //{ |
| 1332 | // fprintf(stderr, "Failed to get %s bus name: %s\n", |
Aditya Saripalli | 5fb1460 | 2017-11-09 14:46:27 +0530 | [diff] [blame] | 1333 | // SOFTOFF_OBJPATH, -r); |
Andrew Geissler | 2b4e459 | 2017-06-08 11:18:35 -0500 | [diff] [blame] | 1334 | // return r; |
| 1335 | //} |
Vishwanatha Subbanna | 83b5c1c | 2017-01-25 18:41:51 +0530 | [diff] [blame] | 1336 | |
| 1337 | // No error object or reply expected. |
Andrew Geissler | 2b4e459 | 2017-06-08 11:18:35 -0500 | [diff] [blame] | 1338 | int rc = sd_bus_call_method(bus, SOFTOFF_BUSNAME, SOFTOFF_OBJPATH, iface, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1339 | "Set", nullptr, nullptr, "ssv", soft_off_iface, |
| 1340 | property, "s", value); |
Vishwanatha Subbanna | 83b5c1c | 2017-01-25 18:41:51 +0530 | [diff] [blame] | 1341 | if (rc < 0) |
| 1342 | { |
Aditya Saripalli | 5fb1460 | 2017-11-09 14:46:27 +0530 | [diff] [blame] | 1343 | log<level::ERR>("Failed to set property in SoftPowerOff object", |
| 1344 | entry("ERRNO=0x%X", -rc)); |
Vishwanatha Subbanna | 83b5c1c | 2017-01-25 18:41:51 +0530 | [diff] [blame] | 1345 | } |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 1346 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1347 | // TODO openbmc/openbmc#1661 - Mapper refactor |
| 1348 | // free(busname); |
Vishwanatha Subbanna | 83b5c1c | 2017-01-25 18:41:51 +0530 | [diff] [blame] | 1349 | return rc; |
| 1350 | } |
| 1351 | |
vishwa | 3699327 | 2015-11-20 12:43:49 -0600 | [diff] [blame] | 1352 | //---------------------------------------------------------------------- |
Andrew Geissler | a6e3a30 | 2017-05-31 19:34:00 -0500 | [diff] [blame] | 1353 | // Create file to indicate there is no need for softoff notification to host |
| 1354 | //---------------------------------------------------------------------- |
| 1355 | void indicate_no_softoff_needed() |
| 1356 | { |
| 1357 | fs::path path{HOST_INBAND_REQUEST_DIR}; |
| 1358 | if (!fs::is_directory(path)) |
| 1359 | { |
| 1360 | fs::create_directory(path); |
| 1361 | } |
| 1362 | |
| 1363 | // Add the host instance (default 0 for now) to the file name |
| 1364 | std::string file{HOST_INBAND_REQUEST_FILE}; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1365 | auto size = std::snprintf(nullptr, 0, file.c_str(), 0); |
Andrew Geissler | a6e3a30 | 2017-05-31 19:34:00 -0500 | [diff] [blame] | 1366 | size++; // null |
| 1367 | std::unique_ptr<char[]> buf(new char[size]); |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1368 | std::snprintf(buf.get(), size, file.c_str(), 0); |
Andrew Geissler | a6e3a30 | 2017-05-31 19:34:00 -0500 | [diff] [blame] | 1369 | |
| 1370 | // Append file name to directory and create it |
| 1371 | path /= buf.get(); |
| 1372 | std::ofstream(path.c_str()); |
| 1373 | } |
| 1374 | |
anil kumar appana | dafff5f | 2019-04-27 18:06:00 +0000 | [diff] [blame] | 1375 | /** @brief Implementation of chassis control command |
| 1376 | * |
| 1377 | * @param - chassisControl command byte |
| 1378 | * |
| 1379 | * @return Success or InvalidFieldRequest. |
| 1380 | */ |
| 1381 | ipmi::RspType<> ipmiChassisControl(uint8_t chassisControl) |
vishwa | 3699327 | 2015-11-20 12:43:49 -0600 | [diff] [blame] | 1382 | { |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 1383 | int rc = 0; |
anil kumar appana | dafff5f | 2019-04-27 18:06:00 +0000 | [diff] [blame] | 1384 | switch (chassisControl) |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 1385 | { |
| 1386 | case CMD_POWER_ON: |
| 1387 | rc = initiate_state_transition(State::Host::Transition::On); |
| 1388 | break; |
| 1389 | case CMD_POWER_OFF: |
Vishwanatha Subbanna | 8b26d35 | 2017-08-04 18:35:18 +0530 | [diff] [blame] | 1390 | // This path would be hit in 2 conditions. |
| 1391 | // 1: When user asks for power off using ipmi chassis command 0x04 |
| 1392 | // 2: Host asking for power off post shutting down. |
| 1393 | |
| 1394 | // If it's a host requested power off, then need to nudge Softoff |
| 1395 | // application that it needs to stop the watchdog timer if running. |
| 1396 | // If it is a user requested power off, then this is not really |
| 1397 | // needed. But then we need to differentiate between user and host |
| 1398 | // calling this same command |
| 1399 | |
| 1400 | // For now, we are going ahead with trying to nudge the soft off and |
| 1401 | // interpret the failure to do so as a non softoff case |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 1402 | rc = stop_soft_off_timer(); |
Vishwanatha Subbanna | 8b26d35 | 2017-08-04 18:35:18 +0530 | [diff] [blame] | 1403 | |
Andrew Geissler | a6e3a30 | 2017-05-31 19:34:00 -0500 | [diff] [blame] | 1404 | // Only request the Off transition if the soft power off |
| 1405 | // application is not running |
| 1406 | if (rc < 0) |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 1407 | { |
Andrew Geissler | a6e3a30 | 2017-05-31 19:34:00 -0500 | [diff] [blame] | 1408 | // First create a file to indicate to the soft off application |
Vishwanatha Subbanna | 8b26d35 | 2017-08-04 18:35:18 +0530 | [diff] [blame] | 1409 | // that it should not run. Not doing this will result in State |
| 1410 | // manager doing a default soft power off when asked for power |
| 1411 | // off. |
Andrew Geissler | a6e3a30 | 2017-05-31 19:34:00 -0500 | [diff] [blame] | 1412 | indicate_no_softoff_needed(); |
| 1413 | |
| 1414 | // Now request the shutdown |
| 1415 | rc = initiate_state_transition(State::Host::Transition::Off); |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 1416 | } |
Andrew Geissler | a6e3a30 | 2017-05-31 19:34:00 -0500 | [diff] [blame] | 1417 | else |
| 1418 | { |
Vishwanatha Subbanna | 8b26d35 | 2017-08-04 18:35:18 +0530 | [diff] [blame] | 1419 | log<level::INFO>("Soft off is running, so let shutdown target " |
| 1420 | "stop the host"); |
Andrew Geissler | a6e3a30 | 2017-05-31 19:34:00 -0500 | [diff] [blame] | 1421 | } |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 1422 | break; |
Vishwanatha Subbanna | 83b5c1c | 2017-01-25 18:41:51 +0530 | [diff] [blame] | 1423 | |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 1424 | case CMD_HARD_RESET: |
Chanh Nguyen | d0a7fcd | 2021-07-16 22:59:28 +0700 | [diff] [blame] | 1425 | rc = initiate_state_transition( |
| 1426 | State::Host::Transition::ForceWarmReboot); |
| 1427 | break; |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 1428 | case CMD_POWER_CYCLE: |
| 1429 | // SPEC has a section that says certain implementations can trigger |
| 1430 | // PowerOn if power is Off when a command to power cycle is |
| 1431 | // requested |
Andrew Geissler | a6e3a30 | 2017-05-31 19:34:00 -0500 | [diff] [blame] | 1432 | |
| 1433 | // First create a file to indicate to the soft off application |
| 1434 | // that it should not run since this is a direct user initiated |
| 1435 | // power reboot request (i.e. a reboot request that is not |
| 1436 | // originating via a soft power off SMS request) |
| 1437 | indicate_no_softoff_needed(); |
| 1438 | |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 1439 | rc = initiate_state_transition(State::Host::Transition::Reboot); |
| 1440 | break; |
Vishwanatha Subbanna | 8b26d35 | 2017-08-04 18:35:18 +0530 | [diff] [blame] | 1441 | |
| 1442 | case CMD_SOFT_OFF_VIA_OVER_TEMP: |
| 1443 | // Request Host State Manager to do a soft power off |
| 1444 | rc = initiate_state_transition(State::Host::Transition::Off); |
| 1445 | break; |
| 1446 | |
Kuiying Wang | 6b0ceaa | 2019-11-05 15:13:40 +0800 | [diff] [blame] | 1447 | case CMD_PULSE_DIAGNOSTIC_INTR: |
| 1448 | rc = setNmiProperty(true); |
| 1449 | break; |
| 1450 | |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 1451 | default: |
| 1452 | { |
Aditya Saripalli | 5fb1460 | 2017-11-09 14:46:27 +0530 | [diff] [blame] | 1453 | log<level::ERR>("Invalid Chassis Control command", |
anil kumar appana | dafff5f | 2019-04-27 18:06:00 +0000 | [diff] [blame] | 1454 | entry("CMD=0x%X", chassisControl)); |
| 1455 | return ipmi::responseInvalidFieldRequest(); |
Andrew Geissler | fca6a4f | 2017-05-30 10:55:39 -0500 | [diff] [blame] | 1456 | } |
| 1457 | } |
vishwa | 3699327 | 2015-11-20 12:43:49 -0600 | [diff] [blame] | 1458 | |
anil kumar appana | dafff5f | 2019-04-27 18:06:00 +0000 | [diff] [blame] | 1459 | return ((rc < 0) ? ipmi::responseUnspecifiedError() |
| 1460 | : ipmi::responseSuccess()); |
vishwa | 3699327 | 2015-11-20 12:43:49 -0600 | [diff] [blame] | 1461 | } |
| 1462 | |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1463 | /** @brief Return D-Bus connection string to enclosure identify LED object |
| 1464 | * |
| 1465 | * @param[in, out] connection - connection to D-Bus object |
| 1466 | * @return a IPMI return code |
| 1467 | */ |
| 1468 | std::string getEnclosureIdentifyConnection() |
Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 1469 | { |
Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 1470 | // lookup enclosure_identify group owner(s) in mapper |
| 1471 | auto mapperCall = chassis::internal::dbus.new_method_call( |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1472 | ipmi::MAPPER_BUS_NAME, ipmi::MAPPER_OBJ, ipmi::MAPPER_INTF, |
| 1473 | "GetObject"); |
Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 1474 | |
| 1475 | mapperCall.append(identify_led_object_name); |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1476 | static const std::vector<std::string> interfaces = { |
| 1477 | "xyz.openbmc_project.Led.Group"}; |
Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 1478 | mapperCall.append(interfaces); |
| 1479 | auto mapperReply = chassis::internal::dbus.call(mapperCall); |
| 1480 | if (mapperReply.is_method_error()) |
| 1481 | { |
| 1482 | log<level::ERR>("Chassis Identify: Error communicating to mapper."); |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1483 | elog<InternalFailure>(); |
Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 1484 | } |
| 1485 | std::vector<std::pair<std::string, std::vector<std::string>>> mapperResp; |
| 1486 | mapperReply.read(mapperResp); |
| 1487 | |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1488 | if (mapperResp.size() != encIdentifyObjectsSize) |
Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 1489 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1490 | log<level::ERR>( |
| 1491 | "Invalid number of enclosure identify objects.", |
| 1492 | entry("ENC_IDENTITY_OBJECTS_SIZE=%d", mapperResp.size())); |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1493 | elog<InternalFailure>(); |
| 1494 | } |
| 1495 | auto pair = mapperResp[encIdentifyObjectsSize - 1]; |
| 1496 | return pair.first; |
| 1497 | } |
Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 1498 | |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1499 | /** @brief Turn On/Off enclosure identify LED |
| 1500 | * |
| 1501 | * @param[in] flag - true to turn on LED, false to turn off |
| 1502 | * @return a IPMI return code |
| 1503 | */ |
| 1504 | void enclosureIdentifyLed(bool flag) |
| 1505 | { |
| 1506 | using namespace chassis::internal; |
| 1507 | std::string connection = std::move(getEnclosureIdentifyConnection()); |
Vernon Mauery | 400cc78 | 2018-10-09 13:49:53 -0700 | [diff] [blame] | 1508 | auto msg = std::string("enclosureIdentifyLed(") + |
| 1509 | boost::lexical_cast<std::string>(flag) + ")"; |
| 1510 | log<level::DEBUG>(msg.c_str()); |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1511 | auto led = |
| 1512 | dbus.new_method_call(connection.c_str(), identify_led_object_name, |
| 1513 | "org.freedesktop.DBus.Properties", "Set"); |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1514 | led.append("xyz.openbmc_project.Led.Group", "Asserted", |
Vernon Mauery | 16b8693 | 2019-05-01 08:36:11 -0700 | [diff] [blame] | 1515 | std::variant<bool>(flag)); |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1516 | auto ledReply = dbus.call(led); |
| 1517 | if (ledReply.is_method_error()) |
| 1518 | { |
| 1519 | log<level::ERR>("Chassis Identify: Error Setting State On/Off\n", |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1520 | entry("LED_STATE=%d", flag)); |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1521 | elog<InternalFailure>(); |
| 1522 | } |
| 1523 | } |
| 1524 | |
| 1525 | /** @brief Callback method to turn off LED |
| 1526 | */ |
| 1527 | void enclosureIdentifyLedOff() |
| 1528 | { |
| 1529 | try |
| 1530 | { |
Yong Li | f4e3851 | 2019-05-21 14:46:55 +0800 | [diff] [blame] | 1531 | chassisIDState = ChassisIDState::off; |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1532 | enclosureIdentifyLed(false); |
| 1533 | } |
| 1534 | catch (const InternalFailure& e) |
| 1535 | { |
| 1536 | report<InternalFailure>(); |
| 1537 | } |
| 1538 | } |
| 1539 | |
| 1540 | /** @brief Create timer to turn on and off the enclosure LED |
| 1541 | */ |
| 1542 | void createIdentifyTimer() |
| 1543 | { |
| 1544 | if (!identifyTimer) |
| 1545 | { |
Vernon Mauery | 1181af7 | 2018-10-08 12:05:00 -0700 | [diff] [blame] | 1546 | identifyTimer = |
| 1547 | std::make_unique<phosphor::Timer>(enclosureIdentifyLedOff); |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1548 | } |
| 1549 | } |
| 1550 | |
Vernon Mauery | 400cc78 | 2018-10-09 13:49:53 -0700 | [diff] [blame] | 1551 | ipmi::RspType<> ipmiChassisIdentify(std::optional<uint8_t> interval, |
| 1552 | std::optional<uint8_t> force) |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1553 | { |
Vernon Mauery | 400cc78 | 2018-10-09 13:49:53 -0700 | [diff] [blame] | 1554 | uint8_t identifyInterval = interval.value_or(DEFAULT_IDENTIFY_TIME_OUT); |
| 1555 | bool forceIdentify = force.value_or(0) & 0x01; |
Tom Joseph | bed2699 | 2018-07-31 23:00:24 +0530 | [diff] [blame] | 1556 | |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1557 | if (identifyInterval || forceIdentify) |
| 1558 | { |
Vernon Mauery | 400cc78 | 2018-10-09 13:49:53 -0700 | [diff] [blame] | 1559 | // stop the timer if already started; |
| 1560 | // for force identify we should not turn off LED |
Vernon Mauery | 1181af7 | 2018-10-08 12:05:00 -0700 | [diff] [blame] | 1561 | identifyTimer->stop(); |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1562 | try |
Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 1563 | { |
Yong Li | f4e3851 | 2019-05-21 14:46:55 +0800 | [diff] [blame] | 1564 | chassisIDState = ChassisIDState::temporaryOn; |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1565 | enclosureIdentifyLed(true); |
| 1566 | } |
| 1567 | catch (const InternalFailure& e) |
| 1568 | { |
| 1569 | report<InternalFailure>(); |
Vernon Mauery | 400cc78 | 2018-10-09 13:49:53 -0700 | [diff] [blame] | 1570 | return ipmi::responseResponseError(); |
Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 1571 | } |
| 1572 | |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1573 | if (forceIdentify) |
Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 1574 | { |
Yong Li | f4e3851 | 2019-05-21 14:46:55 +0800 | [diff] [blame] | 1575 | chassisIDState = ChassisIDState::indefiniteOn; |
Vernon Mauery | 400cc78 | 2018-10-09 13:49:53 -0700 | [diff] [blame] | 1576 | return ipmi::responseSuccess(); |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 1577 | } |
| 1578 | // start the timer |
| 1579 | auto time = std::chrono::duration_cast<std::chrono::microseconds>( |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1580 | std::chrono::seconds(identifyInterval)); |
Vernon Mauery | 1181af7 | 2018-10-08 12:05:00 -0700 | [diff] [blame] | 1581 | identifyTimer->start(time); |
Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 1582 | } |
Tom Joseph | bed2699 | 2018-07-31 23:00:24 +0530 | [diff] [blame] | 1583 | else if (!identifyInterval) |
| 1584 | { |
Vernon Mauery | 1181af7 | 2018-10-08 12:05:00 -0700 | [diff] [blame] | 1585 | identifyTimer->stop(); |
Tom Joseph | bed2699 | 2018-07-31 23:00:24 +0530 | [diff] [blame] | 1586 | enclosureIdentifyLedOff(); |
| 1587 | } |
Vernon Mauery | 400cc78 | 2018-10-09 13:49:53 -0700 | [diff] [blame] | 1588 | return ipmi::responseSuccess(); |
Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 1589 | } |
| 1590 | |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1591 | namespace boot_options |
| 1592 | { |
| 1593 | |
| 1594 | using namespace sdbusplus::xyz::openbmc_project::Control::Boot::server; |
| 1595 | using IpmiValue = uint8_t; |
| 1596 | constexpr auto ipmiDefault = 0; |
| 1597 | |
Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 1598 | std::map<IpmiValue, Type::Types> typeIpmiToDbus = {{0x00, Type::Types::Legacy}, |
| 1599 | {0x01, Type::Types::EFI}}; |
| 1600 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1601 | std::map<IpmiValue, Source::Sources> sourceIpmiToDbus = { |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1602 | {0x01, Source::Sources::Network}, |
| 1603 | {0x02, Source::Sources::Disk}, |
| 1604 | {0x05, Source::Sources::ExternalMedia}, |
Jia, chunhui | 67c5e5d | 2019-05-06 11:29:54 +0800 | [diff] [blame] | 1605 | {0x0f, Source::Sources::RemovableMedia}, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1606 | {ipmiDefault, Source::Sources::Default}}; |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 1607 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1608 | std::map<IpmiValue, Mode::Modes> modeIpmiToDbus = { |
Yong Li | 5833cb6 | 2019-10-30 13:27:12 +0800 | [diff] [blame] | 1609 | #ifdef ENABLE_BOOT_FLAG_SAFE_MODE_SUPPORT |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1610 | {0x03, Mode::Modes::Safe}, |
Yong Li | 5833cb6 | 2019-10-30 13:27:12 +0800 | [diff] [blame] | 1611 | #endif // ENABLE_BOOT_SAFE_MODE_SUPPORT |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1612 | {0x06, Mode::Modes::Setup}, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1613 | {ipmiDefault, Mode::Modes::Regular}}; |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 1614 | |
Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 1615 | std::map<Type::Types, IpmiValue> typeDbusToIpmi = {{Type::Types::Legacy, 0x00}, |
| 1616 | {Type::Types::EFI, 0x01}}; |
| 1617 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1618 | std::map<Source::Sources, IpmiValue> sourceDbusToIpmi = { |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1619 | {Source::Sources::Network, 0x01}, |
| 1620 | {Source::Sources::Disk, 0x02}, |
| 1621 | {Source::Sources::ExternalMedia, 0x05}, |
Jia, chunhui | 67c5e5d | 2019-05-06 11:29:54 +0800 | [diff] [blame] | 1622 | {Source::Sources::RemovableMedia, 0x0f}, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1623 | {Source::Sources::Default, ipmiDefault}}; |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 1624 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1625 | std::map<Mode::Modes, IpmiValue> modeDbusToIpmi = { |
Yong Li | 5833cb6 | 2019-10-30 13:27:12 +0800 | [diff] [blame] | 1626 | #ifdef ENABLE_BOOT_FLAG_SAFE_MODE_SUPPORT |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1627 | {Mode::Modes::Safe, 0x03}, |
Yong Li | 5833cb6 | 2019-10-30 13:27:12 +0800 | [diff] [blame] | 1628 | #endif // ENABLE_BOOT_SAFE_MODE_SUPPORT |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1629 | {Mode::Modes::Setup, 0x06}, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1630 | {Mode::Modes::Regular, ipmiDefault}}; |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 1631 | |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1632 | } // namespace boot_options |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 1633 | |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1634 | /** @brief Get the property value for boot source |
| 1635 | * @param[in] ctx - context pointer |
| 1636 | * @param[out] source - boot source value |
| 1637 | * @return On failure return IPMI error. |
| 1638 | */ |
| 1639 | static ipmi::Cc getBootSource(ipmi::Context::ptr& ctx, Source::Sources& source) |
| 1640 | { |
| 1641 | using namespace chassis::internal; |
| 1642 | std::string result; |
| 1643 | std::string service; |
| 1644 | boost::system::error_code ec = |
| 1645 | getService(ctx, bootSourceIntf, bootSettingsPath, service); |
| 1646 | if (!ec) |
| 1647 | { |
| 1648 | ec = ipmi::getDbusProperty(ctx, service, bootSettingsPath, |
| 1649 | bootSourceIntf, "BootSource", result); |
| 1650 | if (!ec) |
| 1651 | { |
| 1652 | source = Source::convertSourcesFromString(result); |
| 1653 | return ipmi::ccSuccess; |
| 1654 | } |
| 1655 | } |
| 1656 | log<level::ERR>("Error in BootSource Get", |
| 1657 | entry("ERROR=%s", ec.message().c_str())); |
| 1658 | return ipmi::ccUnspecifiedError; |
| 1659 | } |
| 1660 | |
Marri Devender Rao | 8171970 | 2018-05-07 00:53:48 -0500 | [diff] [blame] | 1661 | /** @brief Set the property value for boot source |
Konstantin Aladyshev | e76a61a | 2021-03-18 22:19:13 +0300 | [diff] [blame] | 1662 | * @param[in] ctx - context pointer |
Marri Devender Rao | 8171970 | 2018-05-07 00:53:48 -0500 | [diff] [blame] | 1663 | * @param[in] source - boot source value |
| 1664 | * @return On failure return IPMI error. |
| 1665 | */ |
Jayaprakash Mutyala | 6088e9f | 2021-07-14 07:40:29 +0000 | [diff] [blame] | 1666 | static ipmi::Cc setBootSource(ipmi::Context::ptr& ctx, |
| 1667 | const Source::Sources& source) |
Marri Devender Rao | 8171970 | 2018-05-07 00:53:48 -0500 | [diff] [blame] | 1668 | { |
| 1669 | using namespace chassis::internal; |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1670 | std::string service; |
| 1671 | boost::system::error_code ec = |
| 1672 | getService(ctx, bootSourceIntf, bootSettingsPath, service); |
| 1673 | if (!ec) |
Marri Devender Rao | 8171970 | 2018-05-07 00:53:48 -0500 | [diff] [blame] | 1674 | { |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1675 | ec = ipmi::setDbusProperty(ctx, service, bootSettingsPath, |
| 1676 | bootSourceIntf, "BootSource", |
| 1677 | convertForMessage(source)); |
| 1678 | if (!ec) |
| 1679 | { |
| 1680 | return ipmi::ccSuccess; |
| 1681 | } |
Marri Devender Rao | 8171970 | 2018-05-07 00:53:48 -0500 | [diff] [blame] | 1682 | } |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1683 | log<level::ERR>("Error in BootSource Set", |
| 1684 | entry("ERROR=%s", ec.message().c_str())); |
| 1685 | return ipmi::ccUnspecifiedError; |
| 1686 | } |
| 1687 | |
| 1688 | /** @brief Get the property value for boot mode |
| 1689 | * @param[in] ctx - context pointer |
| 1690 | * @param[out] mode - boot mode value |
| 1691 | * @return On failure return IPMI error. |
| 1692 | */ |
| 1693 | static ipmi::Cc getBootMode(ipmi::Context::ptr& ctx, Mode::Modes& mode) |
| 1694 | { |
| 1695 | using namespace chassis::internal; |
| 1696 | std::string result; |
| 1697 | std::string service; |
| 1698 | boost::system::error_code ec = |
| 1699 | getService(ctx, bootModeIntf, bootSettingsPath, service); |
| 1700 | if (!ec) |
| 1701 | { |
| 1702 | ec = ipmi::getDbusProperty(ctx, service, bootSettingsPath, bootModeIntf, |
| 1703 | "BootMode", result); |
| 1704 | if (!ec) |
| 1705 | { |
| 1706 | mode = Mode::convertModesFromString(result); |
| 1707 | return ipmi::ccSuccess; |
| 1708 | } |
| 1709 | } |
| 1710 | log<level::ERR>("Error in BootMode Get", |
| 1711 | entry("ERROR=%s", ec.message().c_str())); |
| 1712 | return ipmi::ccUnspecifiedError; |
Marri Devender Rao | 8171970 | 2018-05-07 00:53:48 -0500 | [diff] [blame] | 1713 | } |
| 1714 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1715 | /** @brief Set the property value for boot mode |
Konstantin Aladyshev | e76a61a | 2021-03-18 22:19:13 +0300 | [diff] [blame] | 1716 | * @param[in] ctx - context pointer |
Marri Devender Rao | 8171970 | 2018-05-07 00:53:48 -0500 | [diff] [blame] | 1717 | * @param[in] mode - boot mode value |
| 1718 | * @return On failure return IPMI error. |
| 1719 | */ |
Konstantin Aladyshev | e76a61a | 2021-03-18 22:19:13 +0300 | [diff] [blame] | 1720 | 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] | 1721 | { |
| 1722 | using namespace chassis::internal; |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1723 | std::string service; |
| 1724 | boost::system::error_code ec = |
| 1725 | getService(ctx, bootModeIntf, bootSettingsPath, service); |
| 1726 | if (!ec) |
Marri Devender Rao | 8171970 | 2018-05-07 00:53:48 -0500 | [diff] [blame] | 1727 | { |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1728 | ec = ipmi::setDbusProperty(ctx, service, bootSettingsPath, bootModeIntf, |
| 1729 | "BootMode", convertForMessage(mode)); |
| 1730 | if (!ec) |
| 1731 | { |
| 1732 | return ipmi::ccSuccess; |
| 1733 | } |
Marri Devender Rao | 8171970 | 2018-05-07 00:53:48 -0500 | [diff] [blame] | 1734 | } |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1735 | log<level::ERR>("Error in BootMode Set", |
| 1736 | entry("ERROR=%s", ec.message().c_str())); |
| 1737 | return ipmi::ccUnspecifiedError; |
| 1738 | } |
| 1739 | |
| 1740 | /** @brief Get the property value for boot type |
| 1741 | * @param[in] ctx - context pointer |
| 1742 | * @param[out] type - boot type value |
| 1743 | * @return On failure return IPMI error. |
| 1744 | */ |
| 1745 | static ipmi::Cc getBootType(ipmi::Context::ptr& ctx, Type::Types& type) |
| 1746 | { |
| 1747 | using namespace chassis::internal; |
| 1748 | std::string result; |
| 1749 | std::string service; |
| 1750 | boost::system::error_code ec = |
| 1751 | getService(ctx, bootTypeIntf, bootSettingsPath, service); |
| 1752 | |
| 1753 | // Don't throw error if BootType interface is not present. |
| 1754 | // This interface is not relevant for some Host architectures |
| 1755 | // (for example POWER). In this case we don't won't IPMI to |
| 1756 | // return an error, but simply return bootType as EFI. |
| 1757 | type = Type::Types::EFI; |
| 1758 | if (!ec) |
| 1759 | { |
| 1760 | ec = ipmi::getDbusProperty(ctx, service, bootSettingsPath, bootTypeIntf, |
| 1761 | "BootType", result); |
| 1762 | if (ec) |
| 1763 | { |
| 1764 | log<level::ERR>("Error in BootType Get", |
| 1765 | entry("ERROR=%s", ec.message().c_str())); |
| 1766 | return ipmi::ccUnspecifiedError; |
| 1767 | } |
| 1768 | type = Type::convertTypesFromString(result); |
| 1769 | } |
| 1770 | |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 1771 | return ipmi::ccSuccess; |
Marri Devender Rao | 8171970 | 2018-05-07 00:53:48 -0500 | [diff] [blame] | 1772 | } |
| 1773 | |
Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 1774 | /** @brief Set the property value for boot type |
Konstantin Aladyshev | e76a61a | 2021-03-18 22:19:13 +0300 | [diff] [blame] | 1775 | * @param[in] ctx - context pointer |
Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 1776 | * @param[in] type - boot type value |
| 1777 | * @return On failure return IPMI error. |
| 1778 | */ |
Konstantin Aladyshev | e76a61a | 2021-03-18 22:19:13 +0300 | [diff] [blame] | 1779 | static ipmi::Cc setBootType(ipmi::Context::ptr& ctx, const Type::Types& type) |
Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 1780 | { |
| 1781 | using namespace chassis::internal; |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1782 | std::string service; |
| 1783 | boost::system::error_code ec = |
| 1784 | getService(ctx, bootTypeIntf, bootSettingsPath, service); |
| 1785 | if (!ec) |
Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 1786 | { |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1787 | ec = ipmi::setDbusProperty(ctx, service, bootSettingsPath, bootTypeIntf, |
| 1788 | "BootType", convertForMessage(type)); |
| 1789 | if (ec) |
| 1790 | { |
| 1791 | log<level::ERR>("Error in BootType Set", |
| 1792 | entry("ERROR=%s", ec.message().c_str())); |
| 1793 | return ipmi::ccUnspecifiedError; |
| 1794 | } |
Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 1795 | } |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1796 | // Don't throw error if BootType interface is not present. |
| 1797 | // This interface is not relevant for some Host architectures |
| 1798 | // (for example POWER). In this case we don't won't IPMI to |
| 1799 | // return an error, but want to just skip this function. |
Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 1800 | return ipmi::ccSuccess; |
| 1801 | } |
| 1802 | |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1803 | /** @brief Get the property value for boot override enable |
| 1804 | * @param[in] ctx - context pointer |
| 1805 | * @param[out] enable - boot override enable |
| 1806 | * @return On failure return IPMI error. |
| 1807 | */ |
| 1808 | static ipmi::Cc getBootEnable(ipmi::Context::ptr& ctx, bool& enable) |
| 1809 | { |
| 1810 | using namespace chassis::internal; |
| 1811 | std::string result; |
| 1812 | std::string service; |
| 1813 | boost::system::error_code ec = |
| 1814 | getService(ctx, bootEnableIntf, bootSettingsPath, service); |
| 1815 | if (!ec) |
| 1816 | { |
| 1817 | ec = ipmi::getDbusProperty(ctx, service, bootSettingsPath, |
| 1818 | bootEnableIntf, "Enabled", enable); |
| 1819 | if (!ec) |
| 1820 | { |
| 1821 | return ipmi::ccSuccess; |
| 1822 | } |
| 1823 | } |
| 1824 | log<level::ERR>("Error in Boot Override Enable Get", |
| 1825 | entry("ERROR=%s", ec.message().c_str())); |
| 1826 | return ipmi::ccUnspecifiedError; |
| 1827 | } |
| 1828 | |
| 1829 | /** @brief Set the property value for boot override enable |
| 1830 | * @param[in] ctx - context pointer |
| 1831 | * @param[in] enable - boot override enable |
| 1832 | * @return On failure return IPMI error. |
| 1833 | */ |
| 1834 | static ipmi::Cc setBootEnable(ipmi::Context::ptr& ctx, const bool& enable) |
| 1835 | { |
| 1836 | using namespace chassis::internal; |
| 1837 | std::string service; |
| 1838 | boost::system::error_code ec = |
| 1839 | getService(ctx, bootEnableIntf, bootSettingsPath, service); |
| 1840 | if (!ec) |
| 1841 | { |
| 1842 | ec = ipmi::setDbusProperty(ctx, service, bootSettingsPath, |
| 1843 | bootEnableIntf, "Enabled", enable); |
| 1844 | if (!ec) |
| 1845 | { |
| 1846 | return ipmi::ccSuccess; |
| 1847 | } |
| 1848 | } |
| 1849 | log<level::ERR>("Error in Boot Source Override Enable Set", |
| 1850 | entry("ERROR=%s", ec.message().c_str())); |
| 1851 | return ipmi::ccUnspecifiedError; |
| 1852 | } |
| 1853 | |
| 1854 | /** @brief Get the property value for boot override one-time |
| 1855 | * @param[in] ctx - context pointer |
| 1856 | * @param[out] onetime - boot override one-time |
| 1857 | * @return On failure return IPMI error. |
| 1858 | */ |
| 1859 | static ipmi::Cc getBootOneTime(ipmi::Context::ptr& ctx, bool& onetime) |
| 1860 | { |
| 1861 | using namespace chassis::internal; |
| 1862 | std::string result; |
| 1863 | std::string service; |
| 1864 | boost::system::error_code ec = |
| 1865 | getService(ctx, bootOneTimeIntf, bootSettingsOneTimePath, service); |
| 1866 | if (!ec) |
| 1867 | { |
| 1868 | ec = ipmi::getDbusProperty(ctx, service, bootSettingsOneTimePath, |
| 1869 | bootOneTimeIntf, "Enabled", onetime); |
| 1870 | if (!ec) |
| 1871 | { |
| 1872 | return ipmi::ccSuccess; |
| 1873 | } |
| 1874 | } |
| 1875 | log<level::ERR>("Error in Boot Override OneTime Get", |
| 1876 | entry("ERROR=%s", ec.message().c_str())); |
| 1877 | return ipmi::ccUnspecifiedError; |
| 1878 | } |
| 1879 | |
| 1880 | /** @brief Set the property value for boot override one-time |
| 1881 | * @param[in] ctx - context pointer |
| 1882 | * @param[in] onetime - boot override one-time |
| 1883 | * @return On failure return IPMI error. |
| 1884 | */ |
| 1885 | static ipmi::Cc setBootOneTime(ipmi::Context::ptr& ctx, const bool& onetime) |
| 1886 | { |
| 1887 | using namespace chassis::internal; |
| 1888 | std::string service; |
| 1889 | boost::system::error_code ec = |
| 1890 | getService(ctx, bootOneTimeIntf, bootSettingsOneTimePath, service); |
| 1891 | if (!ec) |
| 1892 | { |
| 1893 | ec = ipmi::setDbusProperty(ctx, service, bootSettingsOneTimePath, |
| 1894 | bootOneTimeIntf, "Enabled", onetime); |
| 1895 | if (!ec) |
| 1896 | { |
| 1897 | return ipmi::ccSuccess; |
| 1898 | } |
| 1899 | } |
| 1900 | log<level::ERR>("Error in Boot Source Override OneTime Set", |
| 1901 | entry("ERROR=%s", ec.message().c_str())); |
| 1902 | return ipmi::ccUnspecifiedError; |
| 1903 | } |
| 1904 | |
huanghe | ab36928 | 2020-10-10 14:40:00 +0800 | [diff] [blame] | 1905 | static constexpr uint8_t setComplete = 0x0; |
| 1906 | static constexpr uint8_t setInProgress = 0x1; |
| 1907 | static uint8_t transferStatus = setComplete; |
Chen Yugang | 86ac499 | 2021-06-25 08:14:52 +0800 | [diff] [blame] | 1908 | static uint8_t bootFlagValidBitClr = 0; |
Hieu Huynh | 38ffafc | 2021-05-14 08:40:14 +0000 | [diff] [blame] | 1909 | static uint5_t bootInitiatorAckData = 0x0; |
Hieu Huynh | 1982a3f | 2021-09-21 03:06:45 +0000 | [diff] [blame] | 1910 | static bool cmosClear = false; |
huanghe | ab36928 | 2020-10-10 14:40:00 +0800 | [diff] [blame] | 1911 | |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 1912 | /** @brief implements the Get Chassis system boot option |
Konstantin Aladyshev | e76a61a | 2021-03-18 22:19:13 +0300 | [diff] [blame] | 1913 | * @param ctx - context pointer |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 1914 | * @param bootOptionParameter - boot option parameter selector |
| 1915 | * @param reserved1 - reserved bit |
| 1916 | * @param setSelector - selects a particular block or set of parameters |
| 1917 | * under the given parameter selector |
| 1918 | * write as 00h if parameter doesn't use a setSelector |
| 1919 | * @param blockSelector- selects a particular block within a set of |
| 1920 | * parameters write as 00h if parameter doesn't use a |
| 1921 | * blockSelector |
| 1922 | * |
| 1923 | * @return IPMI completion code plus response data |
| 1924 | * @return Payload contains below parameters: |
| 1925 | * version - parameter version |
| 1926 | * bootOptionParameter - boot option parameter selector |
Patrick Venture | 8b1c303 | 2020-09-15 09:43:03 -0700 | [diff] [blame] | 1927 | * parmIndicator - parameter valid/invalid indicator |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 1928 | * data - configuration parameter data |
| 1929 | */ |
| 1930 | ipmi::RspType<ipmi::message::Payload> |
Konstantin Aladyshev | e76a61a | 2021-03-18 22:19:13 +0300 | [diff] [blame] | 1931 | ipmiChassisGetSysBootOptions(ipmi::Context::ptr ctx, |
| 1932 | uint7_t bootOptionParameter, bool reserved1, |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 1933 | |
| 1934 | uint8_t setSelector, uint8_t blockSelector) |
Adriana Kobylak | 40814c6 | 2015-10-27 15:58:44 -0500 | [diff] [blame] | 1935 | { |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1936 | ipmi::Cc rc; |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 1937 | if (reserved1) |
| 1938 | { |
| 1939 | return ipmi::responseInvalidFieldRequest(); |
| 1940 | } |
| 1941 | |
| 1942 | constexpr uint4_t version = 0x01; |
| 1943 | ipmi::message::Payload response; |
| 1944 | response.pack(version, uint4_t{}); |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1945 | using namespace boot_options; |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 1946 | |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1947 | IpmiValue bootOption = ipmiDefault; |
Adriana Kobylak | 40814c6 | 2015-10-27 15:58:44 -0500 | [diff] [blame] | 1948 | |
William A. Kennington III | 7a0e5df | 2021-05-19 13:31:29 -0700 | [diff] [blame] | 1949 | if (types::enum_cast<BootOptionParameter>(bootOptionParameter) == |
| 1950 | BootOptionParameter::setInProgress) |
huanghe | ab36928 | 2020-10-10 14:40:00 +0800 | [diff] [blame] | 1951 | { |
| 1952 | response.pack(bootOptionParameter, reserved1, transferStatus); |
| 1953 | return ipmi::responseSuccess(std::move(response)); |
| 1954 | } |
| 1955 | |
William A. Kennington III | 7a0e5df | 2021-05-19 13:31:29 -0700 | [diff] [blame] | 1956 | if (types::enum_cast<BootOptionParameter>(bootOptionParameter) == |
| 1957 | BootOptionParameter::bootInfo) |
John Wang | 0213f90 | 2020-12-28 14:49:57 +0800 | [diff] [blame] | 1958 | { |
| 1959 | constexpr uint8_t writeMask = 0; |
Hieu Huynh | 38ffafc | 2021-05-14 08:40:14 +0000 | [diff] [blame] | 1960 | response.pack(bootOptionParameter, reserved1, writeMask, |
| 1961 | bootInitiatorAckData); |
John Wang | 0213f90 | 2020-12-28 14:49:57 +0800 | [diff] [blame] | 1962 | return ipmi::responseSuccess(std::move(response)); |
| 1963 | } |
| 1964 | |
Chen Yugang | 86ac499 | 2021-06-25 08:14:52 +0800 | [diff] [blame] | 1965 | if (types::enum_cast<BootOptionParameter>(bootOptionParameter) == |
| 1966 | BootOptionParameter::bootFlagValidClr) |
| 1967 | { |
| 1968 | response.pack(bootOptionParameter, reserved1, |
| 1969 | uint5_t{bootFlagValidBitClr}, uint3_t{}); |
| 1970 | return ipmi::responseSuccess(std::move(response)); |
| 1971 | } |
| 1972 | |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 1973 | /* |
| 1974 | * Parameter #5 means boot flags. Please refer to 28.13 of ipmi doc. |
| 1975 | * This is the only parameter used by petitboot. |
| 1976 | */ |
William A. Kennington III | 7a0e5df | 2021-05-19 13:31:29 -0700 | [diff] [blame] | 1977 | if (types::enum_cast<BootOptionParameter>(bootOptionParameter) == |
| 1978 | BootOptionParameter::bootFlags) |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1979 | { |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1980 | using namespace chassis::internal; |
| 1981 | using namespace chassis::internal::cache; |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 1982 | |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1983 | try |
ratagupt | a6f6bff | 2016-04-04 06:20:11 -0500 | [diff] [blame] | 1984 | { |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1985 | Source::Sources bootSource; |
| 1986 | rc = getBootSource(ctx, bootSource); |
| 1987 | if (rc != ipmi::ccSuccess) |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1988 | { |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1989 | return ipmi::response(rc); |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1990 | } |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1991 | |
Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 1992 | Type::Types bootType; |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1993 | rc = getBootType(ctx, bootType); |
| 1994 | if (rc != ipmi::ccSuccess) |
Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 1995 | { |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1996 | return ipmi::response(rc); |
Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 1997 | } |
| 1998 | |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 1999 | Mode::Modes bootMode; |
| 2000 | rc = getBootMode(ctx, bootMode); |
| 2001 | if (rc != ipmi::ccSuccess) |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 2002 | { |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 2003 | return ipmi::response(rc); |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 2004 | } |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 2005 | |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 2006 | bootOption = sourceDbusToIpmi.at(bootSource); |
| 2007 | if ((Mode::Modes::Regular == bootMode) && |
| 2008 | (Source::Sources::Default == bootSource)) |
| 2009 | { |
| 2010 | bootOption = ipmiDefault; |
| 2011 | } |
| 2012 | else if (Source::Sources::Default == bootSource) |
| 2013 | { |
| 2014 | bootOption = modeDbusToIpmi.at(bootMode); |
| 2015 | } |
ratagupt | a6f6bff | 2016-04-04 06:20:11 -0500 | [diff] [blame] | 2016 | |
Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 2017 | IpmiValue biosBootType = typeDbusToIpmi.at(bootType); |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 2018 | |
| 2019 | bool oneTimeEnabled; |
| 2020 | rc = getBootOneTime(ctx, oneTimeEnabled); |
| 2021 | if (rc != ipmi::ccSuccess) |
| 2022 | { |
| 2023 | return ipmi::response(rc); |
| 2024 | } |
| 2025 | |
Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 2026 | uint1_t permanent = oneTimeEnabled ? 0 : 1; |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 2027 | |
| 2028 | bool valid; |
| 2029 | rc = getBootEnable(ctx, valid); |
| 2030 | if (rc != ipmi::ccSuccess) |
| 2031 | { |
| 2032 | return ipmi::response(rc); |
| 2033 | } |
| 2034 | |
| 2035 | uint1_t validFlag = valid ? 1 : 0; |
Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 2036 | |
| 2037 | response.pack(bootOptionParameter, reserved1, uint5_t{}, |
| 2038 | uint1_t{biosBootType}, uint1_t{permanent}, |
| 2039 | uint1_t{validFlag}, uint2_t{}, uint4_t{bootOption}, |
Hieu Huynh | 1982a3f | 2021-09-21 03:06:45 +0000 | [diff] [blame] | 2040 | uint1_t{}, cmosClear, uint8_t{}, uint8_t{}, |
| 2041 | uint8_t{}); |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 2042 | return ipmi::responseSuccess(std::move(response)); |
ratagupt | a6f6bff | 2016-04-04 06:20:11 -0500 | [diff] [blame] | 2043 | } |
Patrick Williams | a2ad2da | 2021-10-06 12:21:46 -0500 | [diff] [blame] | 2044 | catch (const InternalFailure& e) |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 2045 | { |
James Feist | 225dec8 | 2019-11-26 16:25:06 -0800 | [diff] [blame] | 2046 | cache::objectsPtr.reset(); |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 2047 | report<InternalFailure>(); |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 2048 | return ipmi::responseUnspecifiedError(); |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 2049 | } |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 2050 | } |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 2051 | else |
| 2052 | { |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 2053 | if ((bootOptionParameter >= oemParmStart) && |
| 2054 | (bootOptionParameter <= oemParmEnd)) |
| 2055 | { |
William A. Kennington III | 7a0e5df | 2021-05-19 13:31:29 -0700 | [diff] [blame] | 2056 | if (types::enum_cast<BootOptionParameter>(bootOptionParameter) == |
| 2057 | BootOptionParameter::opalNetworkSettings) |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 2058 | { |
| 2059 | response.pack(bootOptionParameter, reserved1); |
| 2060 | int ret = getHostNetworkData(response); |
| 2061 | if (ret < 0) |
| 2062 | { |
| 2063 | response.trailingOk = true; |
| 2064 | log<level::ERR>( |
| 2065 | "getHostNetworkData failed for GetSysBootOptions."); |
| 2066 | return ipmi::responseUnspecifiedError(); |
| 2067 | } |
| 2068 | else |
| 2069 | { |
| 2070 | return ipmi::responseSuccess(std::move(response)); |
| 2071 | } |
| 2072 | } |
Jayaprakash Mutyala | 43a8810 | 2021-08-04 16:41:58 +0000 | [diff] [blame] | 2073 | else |
| 2074 | { |
| 2075 | log<level::ERR>( |
| 2076 | "ipmiChassisGetSysBootOptions: Unsupported parameter", |
| 2077 | entry("PARAM=0x%x", |
| 2078 | static_cast<uint8_t>(bootOptionParameter))); |
| 2079 | return ipmi::responseParmNotSupported(); |
| 2080 | } |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 2081 | } |
| 2082 | else |
| 2083 | { |
| 2084 | log<level::ERR>( |
| 2085 | "ipmiChassisGetSysBootOptions: Unsupported parameter", |
| 2086 | entry("PARAM=0x%x", static_cast<uint8_t>(bootOptionParameter))); |
Jayaprakash Mutyala | 6088e9f | 2021-07-14 07:40:29 +0000 | [diff] [blame] | 2087 | return ipmi::responseParmNotSupported(); |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 2088 | } |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 2089 | } |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 2090 | return ipmi::responseUnspecifiedError(); |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 2091 | } |
| 2092 | |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2093 | ipmi::RspType<> ipmiChassisSetSysBootOptions(ipmi::Context::ptr ctx, |
| 2094 | uint7_t parameterSelector, |
| 2095 | bool parameterIsValid, |
| 2096 | ipmi::message::Payload& data) |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 2097 | { |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 2098 | using namespace boot_options; |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2099 | ipmi::Cc rc; |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 2100 | |
William A. Kennington III | 7a0e5df | 2021-05-19 13:31:29 -0700 | [diff] [blame] | 2101 | if (types::enum_cast<BootOptionParameter>(parameterSelector) == |
| 2102 | BootOptionParameter::setInProgress) |
huanghe | ab36928 | 2020-10-10 14:40:00 +0800 | [diff] [blame] | 2103 | { |
| 2104 | uint2_t setInProgressFlag; |
| 2105 | uint6_t rsvd; |
| 2106 | if (data.unpack(setInProgressFlag, rsvd) != 0 || !data.fullyUnpacked()) |
| 2107 | { |
| 2108 | return ipmi::responseReqDataLenInvalid(); |
| 2109 | } |
| 2110 | if (rsvd) |
| 2111 | { |
| 2112 | return ipmi::responseInvalidFieldRequest(); |
| 2113 | } |
| 2114 | if ((transferStatus == setInProgress) && |
| 2115 | (static_cast<uint8_t>(setInProgressFlag) != setComplete)) |
| 2116 | { |
| 2117 | return ipmi::response(IPMI_CC_FAIL_SET_IN_PROGRESS); |
| 2118 | } |
| 2119 | transferStatus = static_cast<uint8_t>(setInProgressFlag); |
| 2120 | return ipmi::responseSuccess(); |
| 2121 | } |
| 2122 | |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 2123 | /* 000101 |
| 2124 | * Parameter #5 means boot flags. Please refer to 28.13 of ipmi doc. |
| 2125 | * This is the only parameter used by petitboot. |
| 2126 | */ |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 2127 | |
William A. Kennington III | 7a0e5df | 2021-05-19 13:31:29 -0700 | [diff] [blame] | 2128 | if (types::enum_cast<BootOptionParameter>(parameterSelector) == |
| 2129 | BootOptionParameter::bootFlags) |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 2130 | { |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2131 | uint5_t rsvd; |
| 2132 | bool validFlag; |
| 2133 | bool permanent; |
| 2134 | bool biosBootType; |
| 2135 | bool lockOutResetButton; |
| 2136 | bool screenBlank; |
| 2137 | uint4_t bootDeviceSelector; |
| 2138 | bool lockKeyboard; |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2139 | uint8_t data3; |
| 2140 | uint4_t biosInfo; |
| 2141 | uint4_t rsvd1; |
| 2142 | uint5_t deviceInstance; |
| 2143 | uint3_t rsvd2; |
| 2144 | |
| 2145 | if (data.unpack(rsvd, biosBootType, permanent, validFlag, |
| 2146 | lockOutResetButton, screenBlank, bootDeviceSelector, |
| 2147 | lockKeyboard, cmosClear, data3, biosInfo, rsvd1, |
| 2148 | deviceInstance, rsvd2) != 0 || |
| 2149 | !data.fullyUnpacked()) |
| 2150 | { |
| 2151 | return ipmi::responseReqDataLenInvalid(); |
| 2152 | } |
| 2153 | if (rsvd || rsvd1 || rsvd2) |
| 2154 | { |
| 2155 | return ipmi::responseInvalidFieldRequest(); |
| 2156 | } |
| 2157 | |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 2158 | using namespace chassis::internal; |
| 2159 | using namespace chassis::internal::cache; |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 2160 | |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 2161 | try |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 2162 | { |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 2163 | rc = setBootOneTime(ctx, !permanent); |
| 2164 | if (rc != ipmi::ccSuccess) |
Konstantin Aladyshev | 69e8e84 | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 2165 | { |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 2166 | return ipmi::response(rc); |
| 2167 | } |
Vernon Mauery | afd45db | 2021-07-29 16:27:25 +0000 | [diff] [blame] | 2168 | |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 2169 | rc = setBootEnable(ctx, validFlag); |
| 2170 | if (rc != ipmi::ccSuccess) |
| 2171 | { |
| 2172 | return ipmi::response(rc); |
Tom Joseph | 57e8eb7 | 2017-09-25 18:05:02 +0530 | [diff] [blame] | 2173 | } |
| 2174 | |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2175 | auto modeItr = |
| 2176 | modeIpmiToDbus.find(static_cast<uint8_t>(bootDeviceSelector)); |
Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 2177 | auto typeItr = |
| 2178 | typeIpmiToDbus.find(static_cast<uint8_t>(biosBootType)); |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2179 | auto sourceItr = |
| 2180 | sourceIpmiToDbus.find(static_cast<uint8_t>(bootDeviceSelector)); |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 2181 | if (sourceIpmiToDbus.end() != sourceItr) |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 2182 | { |
Konstantin Aladyshev | e76a61a | 2021-03-18 22:19:13 +0300 | [diff] [blame] | 2183 | rc = setBootSource(ctx, sourceItr->second); |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2184 | if (rc != ipmi::ccSuccess) |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 2185 | { |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 2186 | return ipmi::response(rc); |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 2187 | } |
Marri Devender Rao | 54fa130 | 2018-05-07 01:06:23 -0500 | [diff] [blame] | 2188 | // If a set boot device is mapping to a boot source, then reset |
| 2189 | // the boot mode D-Bus property to default. |
| 2190 | // This way the ipmid code can determine which property is not |
| 2191 | // at the default value |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 2192 | if (sourceItr->second != Source::Sources::Default) |
Marri Devender Rao | 54fa130 | 2018-05-07 01:06:23 -0500 | [diff] [blame] | 2193 | { |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 2194 | rc = setBootMode(ctx, Mode::Modes::Regular); |
| 2195 | if (rc != ipmi::ccSuccess) |
| 2196 | { |
| 2197 | return ipmi::response(rc); |
| 2198 | } |
Marri Devender Rao | 54fa130 | 2018-05-07 01:06:23 -0500 | [diff] [blame] | 2199 | } |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 2200 | } |
Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 2201 | |
| 2202 | if (typeIpmiToDbus.end() != typeItr) |
| 2203 | { |
Konstantin Aladyshev | e76a61a | 2021-03-18 22:19:13 +0300 | [diff] [blame] | 2204 | rc = setBootType(ctx, typeItr->second); |
Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 2205 | if (rc != ipmi::ccSuccess) |
| 2206 | { |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 2207 | return ipmi::response(rc); |
Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 2208 | } |
| 2209 | } |
| 2210 | |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 2211 | if (modeIpmiToDbus.end() != modeItr) |
| 2212 | { |
Konstantin Aladyshev | e76a61a | 2021-03-18 22:19:13 +0300 | [diff] [blame] | 2213 | rc = setBootMode(ctx, modeItr->second); |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2214 | if (rc != ipmi::ccSuccess) |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 2215 | { |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 2216 | return ipmi::response(rc); |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 2217 | } |
Marri Devender Rao | 54fa130 | 2018-05-07 01:06:23 -0500 | [diff] [blame] | 2218 | // If a set boot device is mapping to a boot mode, then reset |
| 2219 | // the boot source D-Bus property to default. |
| 2220 | // This way the ipmid code can determine which property is not |
| 2221 | // at the default value |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 2222 | if (modeItr->second != Mode::Modes::Regular) |
Marri Devender Rao | 54fa130 | 2018-05-07 01:06:23 -0500 | [diff] [blame] | 2223 | { |
Konstantin Aladyshev | 08a080a | 2021-06-18 17:01:18 +0300 | [diff] [blame] | 2224 | rc = setBootSource(ctx, Source::Sources::Default); |
| 2225 | if (rc != ipmi::ccSuccess) |
| 2226 | { |
| 2227 | return ipmi::response(rc); |
| 2228 | } |
Marri Devender Rao | 54fa130 | 2018-05-07 01:06:23 -0500 | [diff] [blame] | 2229 | } |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 2230 | } |
Jia, chunhui | 67c5e5d | 2019-05-06 11:29:54 +0800 | [diff] [blame] | 2231 | if ((modeIpmiToDbus.end() == modeItr) && |
Konstantin Aladyshev | 96ef028 | 2021-02-09 13:57:10 +0300 | [diff] [blame] | 2232 | (typeIpmiToDbus.end() == typeItr) && |
Jia, chunhui | 67c5e5d | 2019-05-06 11:29:54 +0800 | [diff] [blame] | 2233 | (sourceIpmiToDbus.end() == sourceItr)) |
| 2234 | { |
| 2235 | // return error if boot option is not supported |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2236 | log<level::ERR>( |
| 2237 | "ipmiChassisSetSysBootOptions: Boot option not supported"); |
| 2238 | return ipmi::responseInvalidFieldRequest(); |
Jia, chunhui | 67c5e5d | 2019-05-06 11:29:54 +0800 | [diff] [blame] | 2239 | } |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 2240 | } |
Patrick Williams | a2ad2da | 2021-10-06 12:21:46 -0500 | [diff] [blame] | 2241 | catch (const sdbusplus::exception_t& e) |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 2242 | { |
James Feist | 225dec8 | 2019-11-26 16:25:06 -0800 | [diff] [blame] | 2243 | objectsPtr.reset(); |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 2244 | report<InternalFailure>(); |
Aditya Saripalli | 5fb1460 | 2017-11-09 14:46:27 +0530 | [diff] [blame] | 2245 | log<level::ERR>( |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2246 | "ipmiChassisSetSysBootOptions: Error in setting Boot " |
| 2247 | "flag parameters"); |
| 2248 | return ipmi::responseUnspecifiedError(); |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 2249 | } |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 2250 | } |
William A. Kennington III | 7a0e5df | 2021-05-19 13:31:29 -0700 | [diff] [blame] | 2251 | else if (types::enum_cast<BootOptionParameter>(parameterSelector) == |
| 2252 | BootOptionParameter::bootInfo) |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 2253 | { |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2254 | uint8_t writeMak; |
Hieu Huynh | 38ffafc | 2021-05-14 08:40:14 +0000 | [diff] [blame] | 2255 | uint5_t bootInfoAck; |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2256 | uint3_t rsvd; |
| 2257 | |
Hieu Huynh | 38ffafc | 2021-05-14 08:40:14 +0000 | [diff] [blame] | 2258 | if (data.unpack(writeMak, bootInfoAck, rsvd) != 0 || |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2259 | !data.fullyUnpacked()) |
| 2260 | { |
| 2261 | return ipmi::responseReqDataLenInvalid(); |
| 2262 | } |
| 2263 | if (rsvd) |
| 2264 | { |
| 2265 | return ipmi::responseInvalidFieldRequest(); |
| 2266 | } |
Hieu Huynh | 38ffafc | 2021-05-14 08:40:14 +0000 | [diff] [blame] | 2267 | bootInitiatorAckData &= ~writeMak; |
| 2268 | bootInitiatorAckData |= (writeMak & bootInfoAck); |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2269 | log<level::INFO>("ipmiChassisSetSysBootOptions: bootInfo parameter set " |
| 2270 | "successfully"); |
| 2271 | data.trailingOk = true; |
| 2272 | return ipmi::responseSuccess(); |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 2273 | } |
Chen Yugang | 86ac499 | 2021-06-25 08:14:52 +0800 | [diff] [blame] | 2274 | else if (types::enum_cast<BootOptionParameter>(parameterSelector) == |
| 2275 | BootOptionParameter::bootFlagValidClr) |
| 2276 | { |
| 2277 | uint5_t bootFlagValidClr; |
| 2278 | uint3_t rsvd; |
| 2279 | |
| 2280 | if (data.unpack(bootFlagValidClr, rsvd) != 0 || !data.fullyUnpacked()) |
| 2281 | { |
| 2282 | return ipmi::responseReqDataLenInvalid(); |
| 2283 | } |
| 2284 | if (rsvd) |
| 2285 | { |
| 2286 | return ipmi::responseInvalidFieldRequest(); |
| 2287 | } |
| 2288 | // store boot flag valid bits clear value |
| 2289 | bootFlagValidBitClr = static_cast<uint8_t>(bootFlagValidClr); |
| 2290 | log<level::INFO>( |
| 2291 | "ipmiChassisSetSysBootOptions: bootFlagValidBits parameter set " |
| 2292 | "successfully", |
| 2293 | entry("value=0x%x", bootFlagValidBitClr)); |
| 2294 | return ipmi::responseSuccess(); |
| 2295 | } |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 2296 | else |
| 2297 | { |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2298 | if ((parameterSelector >= static_cast<uint7_t>(oemParmStart)) && |
| 2299 | (parameterSelector <= static_cast<uint7_t>(oemParmEnd))) |
| 2300 | { |
William A. Kennington III | 7a0e5df | 2021-05-19 13:31:29 -0700 | [diff] [blame] | 2301 | if (types::enum_cast<BootOptionParameter>(parameterSelector) == |
| 2302 | BootOptionParameter::opalNetworkSettings) |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2303 | { |
| 2304 | ipmi::Cc ret = setHostNetworkData(data); |
| 2305 | if (ret != ipmi::ccSuccess) |
| 2306 | { |
| 2307 | log<level::ERR>("ipmiChassisSetSysBootOptions: Error in " |
| 2308 | "setHostNetworkData"); |
| 2309 | data.trailingOk = true; |
| 2310 | return ipmi::response(ret); |
| 2311 | } |
| 2312 | data.trailingOk = true; |
| 2313 | return ipmi::responseSuccess(); |
| 2314 | } |
| 2315 | else |
| 2316 | { |
| 2317 | log<level::ERR>( |
| 2318 | "ipmiChassisSetSysBootOptions: Unsupported parameters", |
| 2319 | entry("PARAM=0x%x", |
| 2320 | static_cast<uint8_t>(parameterSelector))); |
| 2321 | data.trailingOk = true; |
| 2322 | return ipmi::responseParmNotSupported(); |
| 2323 | } |
| 2324 | } |
| 2325 | data.trailingOk = true; |
| 2326 | return ipmi::responseParmNotSupported(); |
Adriana Kobylak | 40814c6 | 2015-10-27 15:58:44 -0500 | [diff] [blame] | 2327 | } |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2328 | return ipmi::responseSuccess(); |
Adriana Kobylak | 40814c6 | 2015-10-27 15:58:44 -0500 | [diff] [blame] | 2329 | } |
| 2330 | |
anil kumar appana | a5a76eb | 2019-04-30 14:57:24 +0000 | [diff] [blame] | 2331 | /** @brief implements Get POH counter command |
| 2332 | * @parameter |
| 2333 | * - none |
| 2334 | * @returns IPMI completion code plus response data |
| 2335 | * - minPerCount - Minutes per count |
| 2336 | * - counterReading - counter reading |
| 2337 | */ |
| 2338 | ipmi::RspType<uint8_t, // Minutes per count |
| 2339 | uint32_t // Counter reading |
| 2340 | > |
| 2341 | ipmiGetPOHCounter() |
Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 2342 | { |
| 2343 | // sd_bus error |
Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 2344 | try |
| 2345 | { |
anil kumar appana | a5a76eb | 2019-04-30 14:57:24 +0000 | [diff] [blame] | 2346 | return ipmi::responseSuccess(static_cast<uint8_t>(poh::minutesPerCount), |
| 2347 | getPOHCounter()); |
Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 2348 | } |
Patrick Williams | a2ad2da | 2021-10-06 12:21:46 -0500 | [diff] [blame] | 2349 | catch (const std::exception& e) |
Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 2350 | { |
| 2351 | log<level::ERR>(e.what()); |
anil kumar appana | a5a76eb | 2019-04-30 14:57:24 +0000 | [diff] [blame] | 2352 | return ipmi::responseUnspecifiedError(); |
Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 2353 | } |
Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 2354 | } |
| 2355 | |
Jason M. Bills | bc996a3 | 2019-06-17 15:46:37 -0700 | [diff] [blame] | 2356 | ipmi::RspType<uint3_t, // policy support |
| 2357 | uint5_t // reserved |
| 2358 | > |
Vernon Mauery | e278ead | 2018-10-09 09:23:43 -0700 | [diff] [blame] | 2359 | ipmiChassisSetPowerRestorePolicy(boost::asio::yield_context yield, |
Jason M. Bills | bc996a3 | 2019-06-17 15:46:37 -0700 | [diff] [blame] | 2360 | uint3_t policy, uint5_t reserved) |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2361 | { |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2362 | power_policy::DbusValue value = |
| 2363 | power_policy::RestorePolicy::Policy::AlwaysOff; |
| 2364 | |
Jason M. Bills | bc996a3 | 2019-06-17 15:46:37 -0700 | [diff] [blame] | 2365 | if (reserved || (policy > power_policy::noChange)) |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2366 | { |
Vernon Mauery | e278ead | 2018-10-09 09:23:43 -0700 | [diff] [blame] | 2367 | phosphor::logging::log<level::ERR>( |
| 2368 | "Reserved request parameter", |
| 2369 | entry("REQ=0x%x", static_cast<int>(policy))); |
Jason M. Bills | bc996a3 | 2019-06-17 15:46:37 -0700 | [diff] [blame] | 2370 | return ipmi::responseInvalidFieldRequest(); |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2371 | } |
| 2372 | |
Vernon Mauery | e278ead | 2018-10-09 09:23:43 -0700 | [diff] [blame] | 2373 | if (policy == power_policy::noChange) |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2374 | { |
| 2375 | // just return the supported policy |
Jason M. Bills | bc996a3 | 2019-06-17 15:46:37 -0700 | [diff] [blame] | 2376 | return ipmi::responseSuccess(power_policy::allSupport, reserved); |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2377 | } |
| 2378 | |
| 2379 | for (auto const& it : power_policy::dbusToIpmi) |
| 2380 | { |
Vernon Mauery | e278ead | 2018-10-09 09:23:43 -0700 | [diff] [blame] | 2381 | if (it.second == policy) |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2382 | { |
| 2383 | value = it.first; |
| 2384 | break; |
| 2385 | } |
| 2386 | } |
| 2387 | |
| 2388 | try |
| 2389 | { |
James Feist | 225dec8 | 2019-11-26 16:25:06 -0800 | [diff] [blame] | 2390 | settings::Objects& objects = chassis::internal::cache::getObjects(); |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2391 | const settings::Path& powerRestoreSetting = |
James Feist | 225dec8 | 2019-11-26 16:25:06 -0800 | [diff] [blame] | 2392 | objects.map.at(chassis::internal::powerRestoreIntf).front(); |
Vernon Mauery | 16b8693 | 2019-05-01 08:36:11 -0700 | [diff] [blame] | 2393 | std::variant<std::string> property = convertForMessage(value); |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2394 | |
Vernon Mauery | e278ead | 2018-10-09 09:23:43 -0700 | [diff] [blame] | 2395 | auto sdbusp = getSdBus(); |
| 2396 | boost::system::error_code ec; |
| 2397 | sdbusp->yield_method_call<void>( |
| 2398 | yield, ec, |
James Feist | 225dec8 | 2019-11-26 16:25:06 -0800 | [diff] [blame] | 2399 | objects |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2400 | .service(powerRestoreSetting, |
| 2401 | chassis::internal::powerRestoreIntf) |
| 2402 | .c_str(), |
Vernon Mauery | e278ead | 2018-10-09 09:23:43 -0700 | [diff] [blame] | 2403 | powerRestoreSetting, ipmi::PROP_INTF, "Set", |
| 2404 | chassis::internal::powerRestoreIntf, "PowerRestorePolicy", |
| 2405 | property); |
| 2406 | if (ec) |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2407 | { |
| 2408 | phosphor::logging::log<level::ERR>("Unspecified Error"); |
Vernon Mauery | e278ead | 2018-10-09 09:23:43 -0700 | [diff] [blame] | 2409 | return ipmi::responseUnspecifiedError(); |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2410 | } |
| 2411 | } |
Patrick Williams | a2ad2da | 2021-10-06 12:21:46 -0500 | [diff] [blame] | 2412 | catch (const InternalFailure& e) |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2413 | { |
James Feist | 225dec8 | 2019-11-26 16:25:06 -0800 | [diff] [blame] | 2414 | chassis::internal::cache::objectsPtr.reset(); |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2415 | report<InternalFailure>(); |
Vernon Mauery | e278ead | 2018-10-09 09:23:43 -0700 | [diff] [blame] | 2416 | return ipmi::responseUnspecifiedError(); |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2417 | } |
| 2418 | |
Jason M. Bills | bc996a3 | 2019-06-17 15:46:37 -0700 | [diff] [blame] | 2419 | return ipmi::responseSuccess(power_policy::allSupport, reserved); |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2420 | } |
| 2421 | |
Kuiying Wang | 21addc5 | 2019-01-04 10:50:21 +0800 | [diff] [blame] | 2422 | ipmi::RspType<> ipmiSetFrontPanelButtonEnables( |
| 2423 | ipmi::Context::ptr ctx, bool disablePowerButton, bool disableResetButton, |
| 2424 | bool disableDiagButton, bool disableSleepButton, uint4_t reserved) |
| 2425 | { |
| 2426 | using namespace chassis::internal; |
| 2427 | |
| 2428 | // set power button Enabled property |
| 2429 | bool success = setButtonEnabled(ctx, powerButtonPath, powerButtonIntf, |
| 2430 | !disablePowerButton); |
| 2431 | |
| 2432 | // set reset button Enabled property |
| 2433 | success &= setButtonEnabled(ctx, resetButtonPath, resetButtonIntf, |
| 2434 | !disableResetButton); |
| 2435 | |
| 2436 | if (!success) |
| 2437 | { |
| 2438 | // not all buttons were successfully set |
| 2439 | return ipmi::responseUnspecifiedError(); |
| 2440 | } |
| 2441 | return ipmi::responseSuccess(); |
| 2442 | } |
| 2443 | |
Adriana Kobylak | 40814c6 | 2015-10-27 15:58:44 -0500 | [diff] [blame] | 2444 | void register_netfn_chassis_functions() |
| 2445 | { |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 2446 | createIdentifyTimer(); |
| 2447 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 2448 | // Get Chassis Capabilities |
anil kumar appana | 43263c6 | 2019-05-27 12:45:04 +0000 | [diff] [blame] | 2449 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis, |
| 2450 | ipmi::chassis::cmdGetChassisCapabilities, |
| 2451 | ipmi::Privilege::User, ipmiGetChassisCap); |
Nan Li | 8d15fb4 | 2016-08-16 22:29:40 +0800 | [diff] [blame] | 2452 | |
Kuiying Wang | 21addc5 | 2019-01-04 10:50:21 +0800 | [diff] [blame] | 2453 | // Set Front Panel Button Enables |
| 2454 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis, |
| 2455 | ipmi::chassis::cmdSetFrontPanelButtonEnables, |
| 2456 | ipmi::Privilege::Admin, |
| 2457 | ipmiSetFrontPanelButtonEnables); |
| 2458 | |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 2459 | // Set Chassis Capabilities |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 2460 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis, |
| 2461 | ipmi::chassis::cmdSetChassisCapabilities, |
| 2462 | ipmi::Privilege::User, ipmiSetChassisCap); |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 2463 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 2464 | // <Get System Boot Options> |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 2465 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis, |
| 2466 | ipmi::chassis::cmdGetSystemBootOptions, |
| 2467 | ipmi::Privilege::Operator, |
| 2468 | ipmiChassisGetSysBootOptions); |
Adriana Kobylak | 40814c6 | 2015-10-27 15:58:44 -0500 | [diff] [blame] | 2469 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 2470 | // <Get Chassis Status> |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 2471 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis, |
| 2472 | ipmi::chassis::cmdGetChassisStatus, |
| 2473 | ipmi::Privilege::User, ipmiGetChassisStatus); |
Nan Li | fdd8ec5 | 2016-08-28 03:57:40 +0800 | [diff] [blame] | 2474 | |
Vijay Khemka | 074f64d | 2020-03-03 15:08:43 -0800 | [diff] [blame] | 2475 | // <Chassis Get System Restart Cause> |
| 2476 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis, |
| 2477 | ipmi::chassis::cmdGetSystemRestartCause, |
| 2478 | ipmi::Privilege::User, ipmiGetSystemRestartCause); |
| 2479 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 2480 | // <Chassis Control> |
anil kumar appana | dafff5f | 2019-04-27 18:06:00 +0000 | [diff] [blame] | 2481 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis, |
| 2482 | ipmi::chassis::cmdChassisControl, |
| 2483 | ipmi::Privilege::Operator, ipmiChassisControl); |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 2484 | |
Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 2485 | // <Chassis Identify> |
Vernon Mauery | 400cc78 | 2018-10-09 13:49:53 -0700 | [diff] [blame] | 2486 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis, |
| 2487 | ipmi::chassis::cmdChassisIdentify, |
| 2488 | ipmi::Privilege::Operator, ipmiChassisIdentify); |
Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 2489 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 2490 | // <Set System Boot Options> |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2491 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis, |
| 2492 | ipmi::chassis::cmdSetSystemBootOptions, |
| 2493 | ipmi::Privilege::Operator, |
| 2494 | ipmiChassisSetSysBootOptions); |
| 2495 | |
Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 2496 | // <Get POH Counter> |
anil kumar appana | a5a76eb | 2019-04-30 14:57:24 +0000 | [diff] [blame] | 2497 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis, |
| 2498 | ipmi::chassis::cmdGetPohCounter, |
| 2499 | ipmi::Privilege::User, ipmiGetPOHCounter); |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2500 | |
| 2501 | // <Set Power Restore Policy> |
Vernon Mauery | e278ead | 2018-10-09 09:23:43 -0700 | [diff] [blame] | 2502 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis, |
| 2503 | ipmi::chassis::cmdSetPowerRestorePolicy, |
| 2504 | ipmi::Privilege::Operator, |
| 2505 | ipmiChassisSetPowerRestorePolicy); |
vishwa | 3699327 | 2015-11-20 12:43:49 -0600 | [diff] [blame] | 2506 | } |