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