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