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