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