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