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