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