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