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