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