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