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