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 | |
huanghe | ab36928 | 2020-10-10 14:40:00 +0800 | [diff] [blame] | 1673 | static constexpr uint8_t setComplete = 0x0; |
| 1674 | static constexpr uint8_t setInProgress = 0x1; |
| 1675 | static uint8_t transferStatus = setComplete; |
| 1676 | |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 1677 | /** @brief implements the Get Chassis system boot option |
| 1678 | * @param bootOptionParameter - boot option parameter selector |
| 1679 | * @param reserved1 - reserved bit |
| 1680 | * @param setSelector - selects a particular block or set of parameters |
| 1681 | * under the given parameter selector |
| 1682 | * write as 00h if parameter doesn't use a setSelector |
| 1683 | * @param blockSelector- selects a particular block within a set of |
| 1684 | * parameters write as 00h if parameter doesn't use a |
| 1685 | * blockSelector |
| 1686 | * |
| 1687 | * @return IPMI completion code plus response data |
| 1688 | * @return Payload contains below parameters: |
| 1689 | * version - parameter version |
| 1690 | * bootOptionParameter - boot option parameter selector |
Patrick Venture | 8b1c303 | 2020-09-15 09:43:03 -0700 | [diff] [blame] | 1691 | * parmIndicator - parameter valid/invalid indicator |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 1692 | * data - configuration parameter data |
| 1693 | */ |
| 1694 | ipmi::RspType<ipmi::message::Payload> |
| 1695 | ipmiChassisGetSysBootOptions(uint7_t bootOptionParameter, bool reserved1, |
| 1696 | |
| 1697 | uint8_t setSelector, uint8_t blockSelector) |
Adriana Kobylak | 40814c6 | 2015-10-27 15:58:44 -0500 | [diff] [blame] | 1698 | { |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 1699 | if (reserved1) |
| 1700 | { |
| 1701 | return ipmi::responseInvalidFieldRequest(); |
| 1702 | } |
| 1703 | |
| 1704 | constexpr uint4_t version = 0x01; |
| 1705 | ipmi::message::Payload response; |
| 1706 | response.pack(version, uint4_t{}); |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1707 | using namespace boot_options; |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 1708 | |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1709 | IpmiValue bootOption = ipmiDefault; |
Adriana Kobylak | 40814c6 | 2015-10-27 15:58:44 -0500 | [diff] [blame] | 1710 | |
huanghe | ab36928 | 2020-10-10 14:40:00 +0800 | [diff] [blame] | 1711 | if (static_cast<uint8_t>(bootOptionParameter) == |
| 1712 | static_cast<uint8_t>(BootOptionParameter::setInProgress)) |
| 1713 | { |
| 1714 | response.pack(bootOptionParameter, reserved1, transferStatus); |
| 1715 | return ipmi::responseSuccess(std::move(response)); |
| 1716 | } |
| 1717 | |
John Wang | 0213f90 | 2020-12-28 14:49:57 +0800 | [diff] [blame] | 1718 | if (static_cast<uint8_t>(bootOptionParameter) == |
| 1719 | static_cast<uint8_t>(BootOptionParameter::bootInfo)) |
| 1720 | { |
| 1721 | constexpr uint8_t writeMask = 0; |
| 1722 | constexpr uint8_t bootInfoAck = 0; |
| 1723 | response.pack(bootOptionParameter, writeMask, bootInfoAck); |
| 1724 | return ipmi::responseSuccess(std::move(response)); |
| 1725 | } |
| 1726 | |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 1727 | /* |
| 1728 | * Parameter #5 means boot flags. Please refer to 28.13 of ipmi doc. |
| 1729 | * This is the only parameter used by petitboot. |
| 1730 | */ |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 1731 | if (static_cast<uint8_t>(bootOptionParameter) == |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 1732 | static_cast<uint8_t>(BootOptionParameter::bootFlags)) |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1733 | { |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1734 | using namespace chassis::internal; |
| 1735 | using namespace chassis::internal::cache; |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 1736 | |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1737 | try |
ratagupt | a6f6bff | 2016-04-04 06:20:11 -0500 | [diff] [blame] | 1738 | { |
James Feist | 225dec8 | 2019-11-26 16:25:06 -0800 | [diff] [blame] | 1739 | settings::Objects& objects = getObjects(); |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1740 | auto bootSetting = settings::boot::setting(objects, bootSourceIntf); |
| 1741 | const auto& bootSourceSetting = |
| 1742 | std::get<settings::Path>(bootSetting); |
| 1743 | auto oneTimeEnabled = |
| 1744 | std::get<settings::boot::OneTimeEnabled>(bootSetting); |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1745 | auto method = dbus.new_method_call( |
| 1746 | objects.service(bootSourceSetting, bootSourceIntf).c_str(), |
| 1747 | bootSourceSetting.c_str(), ipmi::PROP_INTF, "Get"); |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1748 | method.append(bootSourceIntf, "BootSource"); |
| 1749 | auto reply = dbus.call(method); |
| 1750 | if (reply.is_method_error()) |
| 1751 | { |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 1752 | log<level::ERR>( |
| 1753 | "ipmiChassisGetSysBootOptions: Error in BootSource Get"); |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1754 | report<InternalFailure>(); |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 1755 | return ipmi::responseUnspecifiedError(); |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1756 | } |
Vernon Mauery | 16b8693 | 2019-05-01 08:36:11 -0700 | [diff] [blame] | 1757 | std::variant<std::string> result; |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1758 | reply.read(result); |
Vernon Mauery | f442e11 | 2019-04-09 11:44:36 -0700 | [diff] [blame] | 1759 | auto bootSource = |
| 1760 | Source::convertSourcesFromString(std::get<std::string>(result)); |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1761 | |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1762 | bootSetting = settings::boot::setting(objects, bootModeIntf); |
| 1763 | const auto& bootModeSetting = std::get<settings::Path>(bootSetting); |
| 1764 | method = dbus.new_method_call( |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1765 | objects.service(bootModeSetting, bootModeIntf).c_str(), |
| 1766 | bootModeSetting.c_str(), ipmi::PROP_INTF, "Get"); |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1767 | method.append(bootModeIntf, "BootMode"); |
| 1768 | reply = dbus.call(method); |
| 1769 | if (reply.is_method_error()) |
| 1770 | { |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 1771 | log<level::ERR>( |
| 1772 | "ipmiChassisGetSysBootOptions: Error in BootMode Get"); |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1773 | report<InternalFailure>(); |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 1774 | return ipmi::responseUnspecifiedError(); |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1775 | } |
| 1776 | reply.read(result); |
Vernon Mauery | f442e11 | 2019-04-09 11:44:36 -0700 | [diff] [blame] | 1777 | auto bootMode = |
| 1778 | Mode::convertModesFromString(std::get<std::string>(result)); |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1779 | |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1780 | bootOption = sourceDbusToIpmi.at(bootSource); |
| 1781 | if ((Mode::Modes::Regular == bootMode) && |
| 1782 | (Source::Sources::Default == bootSource)) |
| 1783 | { |
| 1784 | bootOption = ipmiDefault; |
| 1785 | } |
| 1786 | else if (Source::Sources::Default == bootSource) |
| 1787 | { |
| 1788 | bootOption = modeDbusToIpmi.at(bootMode); |
| 1789 | } |
ratagupt | a6f6bff | 2016-04-04 06:20:11 -0500 | [diff] [blame] | 1790 | |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 1791 | uint8_t bootOptionParam = oneTimeEnabled |
| 1792 | ? setParmBootFlagsValidOneTime |
| 1793 | : setParmBootFlagsValidPermanent; |
| 1794 | response.pack(bootOptionParameter, reserved1, bootOptionParam, |
| 1795 | uint2_t{}, uint4_t{bootOption}, uint2_t{}, uint8_t{}, |
| 1796 | uint8_t{}, uint8_t{}); |
| 1797 | return ipmi::responseSuccess(std::move(response)); |
ratagupt | a6f6bff | 2016-04-04 06:20:11 -0500 | [diff] [blame] | 1798 | } |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1799 | catch (InternalFailure& e) |
| 1800 | { |
James Feist | 225dec8 | 2019-11-26 16:25:06 -0800 | [diff] [blame] | 1801 | cache::objectsPtr.reset(); |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1802 | report<InternalFailure>(); |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 1803 | return ipmi::responseUnspecifiedError(); |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1804 | } |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1805 | } |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1806 | else |
| 1807 | { |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 1808 | if ((bootOptionParameter >= oemParmStart) && |
| 1809 | (bootOptionParameter <= oemParmEnd)) |
| 1810 | { |
| 1811 | if (static_cast<uint8_t>(bootOptionParameter) == |
| 1812 | static_cast<uint8_t>(BootOptionParameter::opalNetworkSettings)) |
| 1813 | { |
| 1814 | response.pack(bootOptionParameter, reserved1); |
| 1815 | int ret = getHostNetworkData(response); |
| 1816 | if (ret < 0) |
| 1817 | { |
| 1818 | response.trailingOk = true; |
| 1819 | log<level::ERR>( |
| 1820 | "getHostNetworkData failed for GetSysBootOptions."); |
| 1821 | return ipmi::responseUnspecifiedError(); |
| 1822 | } |
| 1823 | else |
| 1824 | { |
| 1825 | return ipmi::responseSuccess(std::move(response)); |
| 1826 | } |
| 1827 | } |
| 1828 | } |
| 1829 | else |
| 1830 | { |
| 1831 | log<level::ERR>( |
| 1832 | "ipmiChassisGetSysBootOptions: Unsupported parameter", |
| 1833 | entry("PARAM=0x%x", static_cast<uint8_t>(bootOptionParameter))); |
| 1834 | return ipmi::responseUnspecifiedError(); |
| 1835 | } |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 1836 | } |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 1837 | return ipmi::responseUnspecifiedError(); |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 1838 | } |
| 1839 | |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 1840 | ipmi::RspType<> ipmiChassisSetSysBootOptions(ipmi::Context::ptr ctx, |
| 1841 | uint7_t parameterSelector, |
| 1842 | bool parameterIsValid, |
| 1843 | ipmi::message::Payload& data) |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 1844 | { |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1845 | using namespace boot_options; |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 1846 | ipmi::Cc rc; |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 1847 | |
huanghe | ab36928 | 2020-10-10 14:40:00 +0800 | [diff] [blame] | 1848 | if (parameterSelector == |
| 1849 | static_cast<uint7_t>(BootOptionParameter::setInProgress)) |
| 1850 | { |
| 1851 | uint2_t setInProgressFlag; |
| 1852 | uint6_t rsvd; |
| 1853 | if (data.unpack(setInProgressFlag, rsvd) != 0 || !data.fullyUnpacked()) |
| 1854 | { |
| 1855 | return ipmi::responseReqDataLenInvalid(); |
| 1856 | } |
| 1857 | if (rsvd) |
| 1858 | { |
| 1859 | return ipmi::responseInvalidFieldRequest(); |
| 1860 | } |
| 1861 | if ((transferStatus == setInProgress) && |
| 1862 | (static_cast<uint8_t>(setInProgressFlag) != setComplete)) |
| 1863 | { |
| 1864 | return ipmi::response(IPMI_CC_FAIL_SET_IN_PROGRESS); |
| 1865 | } |
| 1866 | transferStatus = static_cast<uint8_t>(setInProgressFlag); |
| 1867 | return ipmi::responseSuccess(); |
| 1868 | } |
| 1869 | |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 1870 | /* 000101 |
| 1871 | * Parameter #5 means boot flags. Please refer to 28.13 of ipmi doc. |
| 1872 | * This is the only parameter used by petitboot. |
| 1873 | */ |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 1874 | |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 1875 | if (parameterSelector == |
| 1876 | static_cast<uint7_t>(BootOptionParameter::bootFlags)) |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1877 | { |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 1878 | uint5_t rsvd; |
| 1879 | bool validFlag; |
| 1880 | bool permanent; |
| 1881 | bool biosBootType; |
| 1882 | bool lockOutResetButton; |
| 1883 | bool screenBlank; |
| 1884 | uint4_t bootDeviceSelector; |
| 1885 | bool lockKeyboard; |
| 1886 | bool cmosClear; |
| 1887 | uint8_t data3; |
| 1888 | uint4_t biosInfo; |
| 1889 | uint4_t rsvd1; |
| 1890 | uint5_t deviceInstance; |
| 1891 | uint3_t rsvd2; |
| 1892 | |
| 1893 | if (data.unpack(rsvd, biosBootType, permanent, validFlag, |
| 1894 | lockOutResetButton, screenBlank, bootDeviceSelector, |
| 1895 | lockKeyboard, cmosClear, data3, biosInfo, rsvd1, |
| 1896 | deviceInstance, rsvd2) != 0 || |
| 1897 | !data.fullyUnpacked()) |
| 1898 | { |
| 1899 | return ipmi::responseReqDataLenInvalid(); |
| 1900 | } |
| 1901 | if (rsvd || rsvd1 || rsvd2) |
| 1902 | { |
| 1903 | return ipmi::responseInvalidFieldRequest(); |
| 1904 | } |
| 1905 | |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1906 | using namespace chassis::internal; |
| 1907 | using namespace chassis::internal::cache; |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1908 | auto oneTimeEnabled = false; |
| 1909 | constexpr auto enabledIntf = "xyz.openbmc_project.Object.Enable"; |
Tom Joseph | 57e8eb7 | 2017-09-25 18:05:02 +0530 | [diff] [blame] | 1910 | constexpr auto oneTimePath = |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1911 | "/xyz/openbmc_project/control/host0/boot/one_time"; |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 1912 | |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1913 | try |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1914 | { |
James Feist | 225dec8 | 2019-11-26 16:25:06 -0800 | [diff] [blame] | 1915 | settings::Objects& objects = getObjects(); |
| 1916 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1917 | auto bootSetting = settings::boot::setting(objects, bootSourceIntf); |
Tom Joseph | 57e8eb7 | 2017-09-25 18:05:02 +0530 | [diff] [blame] | 1918 | |
| 1919 | oneTimeEnabled = |
| 1920 | std::get<settings::boot::OneTimeEnabled>(bootSetting); |
| 1921 | |
| 1922 | /* |
| 1923 | * Check if the current boot setting is onetime or permanent, if the |
| 1924 | * request in the command is otherwise, then set the "Enabled" |
| 1925 | * property in one_time object path to 'True' to indicate onetime |
| 1926 | * and 'False' to indicate permanent. |
| 1927 | * |
| 1928 | * Once the onetime/permanent setting is applied, then the bootMode |
| 1929 | * and bootSource is updated for the corresponding object. |
| 1930 | */ |
| 1931 | if ((permanent && oneTimeEnabled) || |
| 1932 | (!permanent && !oneTimeEnabled)) |
| 1933 | { |
| 1934 | auto service = ipmi::getService(dbus, enabledIntf, oneTimePath); |
| 1935 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1936 | ipmi::setDbusProperty(dbus, service, oneTimePath, enabledIntf, |
| 1937 | "Enabled", !permanent); |
Tom Joseph | 57e8eb7 | 2017-09-25 18:05:02 +0530 | [diff] [blame] | 1938 | } |
| 1939 | |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 1940 | auto modeItr = |
| 1941 | modeIpmiToDbus.find(static_cast<uint8_t>(bootDeviceSelector)); |
| 1942 | auto sourceItr = |
| 1943 | sourceIpmiToDbus.find(static_cast<uint8_t>(bootDeviceSelector)); |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1944 | if (sourceIpmiToDbus.end() != sourceItr) |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1945 | { |
Marri Devender Rao | 8171970 | 2018-05-07 00:53:48 -0500 | [diff] [blame] | 1946 | rc = setBootSource(sourceItr->second); |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 1947 | if (rc != ipmi::ccSuccess) |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1948 | { |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 1949 | log<level::ERR>("ipmiChassisSetSysBootOptions: Error in " |
| 1950 | "setting boot source"); |
| 1951 | return ipmi::responseUnspecifiedError(); |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1952 | } |
Marri Devender Rao | 54fa130 | 2018-05-07 01:06:23 -0500 | [diff] [blame] | 1953 | // If a set boot device is mapping to a boot source, then reset |
| 1954 | // the boot mode D-Bus property to default. |
| 1955 | // This way the ipmid code can determine which property is not |
| 1956 | // at the default value |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1957 | if (sourceItr->second != Source::Sources::Default) |
Marri Devender Rao | 54fa130 | 2018-05-07 01:06:23 -0500 | [diff] [blame] | 1958 | { |
| 1959 | setBootMode(Mode::Modes::Regular); |
| 1960 | } |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1961 | } |
| 1962 | if (modeIpmiToDbus.end() != modeItr) |
| 1963 | { |
Marri Devender Rao | 8171970 | 2018-05-07 00:53:48 -0500 | [diff] [blame] | 1964 | rc = setBootMode(modeItr->second); |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 1965 | if (rc != ipmi::ccSuccess) |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1966 | { |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 1967 | log<level::ERR>("ipmiChassisSetSysBootOptions: Error in " |
| 1968 | "setting boot mode"); |
| 1969 | return ipmi::responseUnspecifiedError(); |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1970 | } |
Marri Devender Rao | 54fa130 | 2018-05-07 01:06:23 -0500 | [diff] [blame] | 1971 | // If a set boot device is mapping to a boot mode, then reset |
| 1972 | // the boot source D-Bus property to default. |
| 1973 | // This way the ipmid code can determine which property is not |
| 1974 | // at the default value |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1975 | if (modeItr->second != Mode::Modes::Regular) |
Marri Devender Rao | 54fa130 | 2018-05-07 01:06:23 -0500 | [diff] [blame] | 1976 | { |
| 1977 | setBootSource(Source::Sources::Default); |
| 1978 | } |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1979 | } |
Jia, chunhui | 67c5e5d | 2019-05-06 11:29:54 +0800 | [diff] [blame] | 1980 | if ((modeIpmiToDbus.end() == modeItr) && |
| 1981 | (sourceIpmiToDbus.end() == sourceItr)) |
| 1982 | { |
| 1983 | // return error if boot option is not supported |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 1984 | log<level::ERR>( |
| 1985 | "ipmiChassisSetSysBootOptions: Boot option not supported"); |
| 1986 | return ipmi::responseInvalidFieldRequest(); |
Jia, chunhui | 67c5e5d | 2019-05-06 11:29:54 +0800 | [diff] [blame] | 1987 | } |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1988 | } |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 1989 | catch (sdbusplus::exception_t& e) |
Deepak Kodihalli | 8cc1936 | 2017-07-21 11:18:38 -0500 | [diff] [blame] | 1990 | { |
James Feist | 225dec8 | 2019-11-26 16:25:06 -0800 | [diff] [blame] | 1991 | objectsPtr.reset(); |
Deepak Kodihalli | 13791bd | 2017-08-28 06:50:51 -0500 | [diff] [blame] | 1992 | report<InternalFailure>(); |
Aditya Saripalli | 5fb1460 | 2017-11-09 14:46:27 +0530 | [diff] [blame] | 1993 | log<level::ERR>( |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 1994 | "ipmiChassisSetSysBootOptions: Error in setting Boot " |
| 1995 | "flag parameters"); |
| 1996 | return ipmi::responseUnspecifiedError(); |
Ratan Gupta | fd28dd7 | 2016-08-01 04:58:01 -0500 | [diff] [blame] | 1997 | } |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1998 | } |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 1999 | else if (parameterSelector == |
| 2000 | static_cast<uint7_t>(BootOptionParameter::bootInfo)) |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 2001 | { |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2002 | uint8_t writeMak; |
| 2003 | uint5_t bootInitiatorAckData; |
| 2004 | uint3_t rsvd; |
| 2005 | |
| 2006 | if (data.unpack(writeMak, bootInitiatorAckData, rsvd) != 0 || |
| 2007 | !data.fullyUnpacked()) |
| 2008 | { |
| 2009 | return ipmi::responseReqDataLenInvalid(); |
| 2010 | } |
| 2011 | if (rsvd) |
| 2012 | { |
| 2013 | return ipmi::responseInvalidFieldRequest(); |
| 2014 | } |
| 2015 | // (ccSuccess). There is no implementation in OpenBMC for this |
Tom Joseph | f536c90 | 2017-09-25 18:08:15 +0530 | [diff] [blame] | 2016 | // parameter. This is added to support the ipmitool command `chassis |
| 2017 | // bootdev` which sends set on parameter #4, before setting the boot |
| 2018 | // flags. |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2019 | log<level::INFO>("ipmiChassisSetSysBootOptions: bootInfo parameter set " |
| 2020 | "successfully"); |
| 2021 | data.trailingOk = true; |
| 2022 | return ipmi::responseSuccess(); |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 2023 | } |
| 2024 | else |
| 2025 | { |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2026 | if ((parameterSelector >= static_cast<uint7_t>(oemParmStart)) && |
| 2027 | (parameterSelector <= static_cast<uint7_t>(oemParmEnd))) |
| 2028 | { |
| 2029 | if (parameterSelector == |
| 2030 | static_cast<uint7_t>(BootOptionParameter::opalNetworkSettings)) |
| 2031 | { |
| 2032 | ipmi::Cc ret = setHostNetworkData(data); |
| 2033 | if (ret != ipmi::ccSuccess) |
| 2034 | { |
| 2035 | log<level::ERR>("ipmiChassisSetSysBootOptions: Error in " |
| 2036 | "setHostNetworkData"); |
| 2037 | data.trailingOk = true; |
| 2038 | return ipmi::response(ret); |
| 2039 | } |
| 2040 | data.trailingOk = true; |
| 2041 | return ipmi::responseSuccess(); |
| 2042 | } |
| 2043 | else |
| 2044 | { |
| 2045 | log<level::ERR>( |
| 2046 | "ipmiChassisSetSysBootOptions: Unsupported parameters", |
| 2047 | entry("PARAM=0x%x", |
| 2048 | static_cast<uint8_t>(parameterSelector))); |
| 2049 | data.trailingOk = true; |
| 2050 | return ipmi::responseParmNotSupported(); |
| 2051 | } |
| 2052 | } |
| 2053 | data.trailingOk = true; |
| 2054 | return ipmi::responseParmNotSupported(); |
Adriana Kobylak | 40814c6 | 2015-10-27 15:58:44 -0500 | [diff] [blame] | 2055 | } |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2056 | return ipmi::responseSuccess(); |
Adriana Kobylak | 40814c6 | 2015-10-27 15:58:44 -0500 | [diff] [blame] | 2057 | } |
| 2058 | |
anil kumar appana | a5a76eb | 2019-04-30 14:57:24 +0000 | [diff] [blame] | 2059 | /** @brief implements Get POH counter command |
| 2060 | * @parameter |
| 2061 | * - none |
| 2062 | * @returns IPMI completion code plus response data |
| 2063 | * - minPerCount - Minutes per count |
| 2064 | * - counterReading - counter reading |
| 2065 | */ |
| 2066 | ipmi::RspType<uint8_t, // Minutes per count |
| 2067 | uint32_t // Counter reading |
| 2068 | > |
| 2069 | ipmiGetPOHCounter() |
Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 2070 | { |
| 2071 | // sd_bus error |
Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 2072 | try |
| 2073 | { |
anil kumar appana | a5a76eb | 2019-04-30 14:57:24 +0000 | [diff] [blame] | 2074 | return ipmi::responseSuccess(static_cast<uint8_t>(poh::minutesPerCount), |
| 2075 | getPOHCounter()); |
Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 2076 | } |
| 2077 | catch (std::exception& e) |
| 2078 | { |
| 2079 | log<level::ERR>(e.what()); |
anil kumar appana | a5a76eb | 2019-04-30 14:57:24 +0000 | [diff] [blame] | 2080 | return ipmi::responseUnspecifiedError(); |
Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 2081 | } |
Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 2082 | } |
| 2083 | |
Jason M. Bills | bc996a3 | 2019-06-17 15:46:37 -0700 | [diff] [blame] | 2084 | ipmi::RspType<uint3_t, // policy support |
| 2085 | uint5_t // reserved |
| 2086 | > |
Vernon Mauery | e278ead | 2018-10-09 09:23:43 -0700 | [diff] [blame] | 2087 | ipmiChassisSetPowerRestorePolicy(boost::asio::yield_context yield, |
Jason M. Bills | bc996a3 | 2019-06-17 15:46:37 -0700 | [diff] [blame] | 2088 | uint3_t policy, uint5_t reserved) |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2089 | { |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2090 | power_policy::DbusValue value = |
| 2091 | power_policy::RestorePolicy::Policy::AlwaysOff; |
| 2092 | |
Jason M. Bills | bc996a3 | 2019-06-17 15:46:37 -0700 | [diff] [blame] | 2093 | if (reserved || (policy > power_policy::noChange)) |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2094 | { |
Vernon Mauery | e278ead | 2018-10-09 09:23:43 -0700 | [diff] [blame] | 2095 | phosphor::logging::log<level::ERR>( |
| 2096 | "Reserved request parameter", |
| 2097 | entry("REQ=0x%x", static_cast<int>(policy))); |
Jason M. Bills | bc996a3 | 2019-06-17 15:46:37 -0700 | [diff] [blame] | 2098 | return ipmi::responseInvalidFieldRequest(); |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2099 | } |
| 2100 | |
Vernon Mauery | e278ead | 2018-10-09 09:23:43 -0700 | [diff] [blame] | 2101 | if (policy == power_policy::noChange) |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2102 | { |
| 2103 | // just return the supported policy |
Jason M. Bills | bc996a3 | 2019-06-17 15:46:37 -0700 | [diff] [blame] | 2104 | return ipmi::responseSuccess(power_policy::allSupport, reserved); |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2105 | } |
| 2106 | |
| 2107 | for (auto const& it : power_policy::dbusToIpmi) |
| 2108 | { |
Vernon Mauery | e278ead | 2018-10-09 09:23:43 -0700 | [diff] [blame] | 2109 | if (it.second == policy) |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2110 | { |
| 2111 | value = it.first; |
| 2112 | break; |
| 2113 | } |
| 2114 | } |
| 2115 | |
| 2116 | try |
| 2117 | { |
James Feist | 225dec8 | 2019-11-26 16:25:06 -0800 | [diff] [blame] | 2118 | settings::Objects& objects = chassis::internal::cache::getObjects(); |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2119 | const settings::Path& powerRestoreSetting = |
James Feist | 225dec8 | 2019-11-26 16:25:06 -0800 | [diff] [blame] | 2120 | objects.map.at(chassis::internal::powerRestoreIntf).front(); |
Vernon Mauery | 16b8693 | 2019-05-01 08:36:11 -0700 | [diff] [blame] | 2121 | std::variant<std::string> property = convertForMessage(value); |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2122 | |
Vernon Mauery | e278ead | 2018-10-09 09:23:43 -0700 | [diff] [blame] | 2123 | auto sdbusp = getSdBus(); |
| 2124 | boost::system::error_code ec; |
| 2125 | sdbusp->yield_method_call<void>( |
| 2126 | yield, ec, |
James Feist | 225dec8 | 2019-11-26 16:25:06 -0800 | [diff] [blame] | 2127 | objects |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2128 | .service(powerRestoreSetting, |
| 2129 | chassis::internal::powerRestoreIntf) |
| 2130 | .c_str(), |
Vernon Mauery | e278ead | 2018-10-09 09:23:43 -0700 | [diff] [blame] | 2131 | powerRestoreSetting, ipmi::PROP_INTF, "Set", |
| 2132 | chassis::internal::powerRestoreIntf, "PowerRestorePolicy", |
| 2133 | property); |
| 2134 | if (ec) |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2135 | { |
| 2136 | phosphor::logging::log<level::ERR>("Unspecified Error"); |
Vernon Mauery | e278ead | 2018-10-09 09:23:43 -0700 | [diff] [blame] | 2137 | return ipmi::responseUnspecifiedError(); |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2138 | } |
| 2139 | } |
| 2140 | catch (InternalFailure& e) |
| 2141 | { |
James Feist | 225dec8 | 2019-11-26 16:25:06 -0800 | [diff] [blame] | 2142 | chassis::internal::cache::objectsPtr.reset(); |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2143 | report<InternalFailure>(); |
Vernon Mauery | e278ead | 2018-10-09 09:23:43 -0700 | [diff] [blame] | 2144 | return ipmi::responseUnspecifiedError(); |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2145 | } |
| 2146 | |
Jason M. Bills | bc996a3 | 2019-06-17 15:46:37 -0700 | [diff] [blame] | 2147 | return ipmi::responseSuccess(power_policy::allSupport, reserved); |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2148 | } |
| 2149 | |
Kuiying Wang | 21addc5 | 2019-01-04 10:50:21 +0800 | [diff] [blame] | 2150 | ipmi::RspType<> ipmiSetFrontPanelButtonEnables( |
| 2151 | ipmi::Context::ptr ctx, bool disablePowerButton, bool disableResetButton, |
| 2152 | bool disableDiagButton, bool disableSleepButton, uint4_t reserved) |
| 2153 | { |
| 2154 | using namespace chassis::internal; |
| 2155 | |
| 2156 | // set power button Enabled property |
| 2157 | bool success = setButtonEnabled(ctx, powerButtonPath, powerButtonIntf, |
| 2158 | !disablePowerButton); |
| 2159 | |
| 2160 | // set reset button Enabled property |
| 2161 | success &= setButtonEnabled(ctx, resetButtonPath, resetButtonIntf, |
| 2162 | !disableResetButton); |
| 2163 | |
| 2164 | if (!success) |
| 2165 | { |
| 2166 | // not all buttons were successfully set |
| 2167 | return ipmi::responseUnspecifiedError(); |
| 2168 | } |
| 2169 | return ipmi::responseSuccess(); |
| 2170 | } |
| 2171 | |
Adriana Kobylak | 40814c6 | 2015-10-27 15:58:44 -0500 | [diff] [blame] | 2172 | void register_netfn_chassis_functions() |
| 2173 | { |
Marri Devender Rao | 6706c1c | 2018-05-14 00:29:38 -0500 | [diff] [blame] | 2174 | createIdentifyTimer(); |
| 2175 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 2176 | // Get Chassis Capabilities |
anil kumar appana | 43263c6 | 2019-05-27 12:45:04 +0000 | [diff] [blame] | 2177 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis, |
| 2178 | ipmi::chassis::cmdGetChassisCapabilities, |
| 2179 | ipmi::Privilege::User, ipmiGetChassisCap); |
Nan Li | 8d15fb4 | 2016-08-16 22:29:40 +0800 | [diff] [blame] | 2180 | |
Kuiying Wang | 21addc5 | 2019-01-04 10:50:21 +0800 | [diff] [blame] | 2181 | // Set Front Panel Button Enables |
| 2182 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis, |
| 2183 | ipmi::chassis::cmdSetFrontPanelButtonEnables, |
| 2184 | ipmi::Privilege::Admin, |
| 2185 | ipmiSetFrontPanelButtonEnables); |
| 2186 | |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 2187 | // Set Chassis Capabilities |
anil kumar appana | 894d022 | 2019-05-27 16:32:14 +0000 | [diff] [blame] | 2188 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis, |
| 2189 | ipmi::chassis::cmdSetChassisCapabilities, |
| 2190 | ipmi::Privilege::User, ipmiSetChassisCap); |
Yong Li | ae4b040 | 2018-11-02 11:12:14 +0800 | [diff] [blame] | 2191 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 2192 | // <Get System Boot Options> |
Jayaprakash Mutyala | d1ef877 | 2020-08-25 10:32:58 +0000 | [diff] [blame] | 2193 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis, |
| 2194 | ipmi::chassis::cmdGetSystemBootOptions, |
| 2195 | ipmi::Privilege::Operator, |
| 2196 | ipmiChassisGetSysBootOptions); |
Adriana Kobylak | 40814c6 | 2015-10-27 15:58:44 -0500 | [diff] [blame] | 2197 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 2198 | // <Get Chassis Status> |
Vernon Mauery | 4a8a4eb | 2019-04-04 15:09:37 -0700 | [diff] [blame] | 2199 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis, |
| 2200 | ipmi::chassis::cmdGetChassisStatus, |
| 2201 | ipmi::Privilege::User, ipmiGetChassisStatus); |
Nan Li | fdd8ec5 | 2016-08-28 03:57:40 +0800 | [diff] [blame] | 2202 | |
Vijay Khemka | 074f64d | 2020-03-03 15:08:43 -0800 | [diff] [blame] | 2203 | // <Chassis Get System Restart Cause> |
| 2204 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis, |
| 2205 | ipmi::chassis::cmdGetSystemRestartCause, |
| 2206 | ipmi::Privilege::User, ipmiGetSystemRestartCause); |
| 2207 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 2208 | // <Chassis Control> |
anil kumar appana | dafff5f | 2019-04-27 18:06:00 +0000 | [diff] [blame] | 2209 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis, |
| 2210 | ipmi::chassis::cmdChassisControl, |
| 2211 | ipmi::Privilege::Operator, ipmiChassisControl); |
shgoupf | d84fbbf | 2015-12-17 10:05:51 +0800 | [diff] [blame] | 2212 | |
Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 2213 | // <Chassis Identify> |
Vernon Mauery | 400cc78 | 2018-10-09 13:49:53 -0700 | [diff] [blame] | 2214 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis, |
| 2215 | ipmi::chassis::cmdChassisIdentify, |
| 2216 | ipmi::Privilege::Operator, ipmiChassisIdentify); |
Tom Joseph | 5110c12 | 2018-03-23 17:55:40 +0530 | [diff] [blame] | 2217 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 2218 | // <Set System Boot Options> |
jayaprakash Mutyala | bfd8fc4 | 2020-05-05 22:38:03 +0000 | [diff] [blame] | 2219 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis, |
| 2220 | ipmi::chassis::cmdSetSystemBootOptions, |
| 2221 | ipmi::Privilege::Operator, |
| 2222 | ipmiChassisSetSysBootOptions); |
| 2223 | |
Nagaraju Goruganti | a59d83f | 2018-04-06 05:55:42 -0500 | [diff] [blame] | 2224 | // <Get POH Counter> |
anil kumar appana | a5a76eb | 2019-04-30 14:57:24 +0000 | [diff] [blame] | 2225 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis, |
| 2226 | ipmi::chassis::cmdGetPohCounter, |
| 2227 | ipmi::Privilege::User, ipmiGetPOHCounter); |
Yong Li | c6713cf | 2018-09-12 12:35:13 +0800 | [diff] [blame] | 2228 | |
| 2229 | // <Set Power Restore Policy> |
Vernon Mauery | e278ead | 2018-10-09 09:23:43 -0700 | [diff] [blame] | 2230 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnChassis, |
| 2231 | ipmi::chassis::cmdSetPowerRestorePolicy, |
| 2232 | ipmi::Privilege::Operator, |
| 2233 | ipmiChassisSetPowerRestorePolicy); |
vishwa | 3699327 | 2015-11-20 12:43:49 -0600 | [diff] [blame] | 2234 | } |