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