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