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