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