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