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