blob: fbb00a6d63e4ea51cd778ca1e2d53fe20af5a554 [file] [log] [blame]
Adriana Kobylak40814c62015-10-27 15:58:44 -05001#include "chassishandler.h"
Patrick Williams37af7332016-09-02 21:21:42 -05002#include "host-ipmid/ipmid-api.h"
Ratan Guptadcb10672017-07-10 10:33:50 +05303#include "types.hpp"
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05004#include "ipmid.hpp"
5#include "settings.hpp"
Ratan Guptacc8feb42017-07-25 21:52:10 +05306#include "utils.hpp"
Ratan Guptadcb10672017-07-10 10:33:50 +05307
Adriana Kobylak40814c62015-10-27 15:58:44 -05008#include <stdio.h>
Ratan Guptafd28dd72016-08-01 04:58:01 -05009#include <stdlib.h>
Adriana Kobylak40814c62015-10-27 15:58:44 -050010#include <stdint.h>
Brad Bishop35518682016-07-22 08:35:41 -040011#include <mapper.h>
Ratan Guptafd28dd72016-08-01 04:58:01 -050012#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 Geisslera6e3a302017-05-31 19:34:00 -050019#include <fstream>
20#include <experimental/filesystem>
Ratan Guptadcb10672017-07-10 10:33:50 +053021#include <string>
Deepak Kodihalli8cc19362017-07-21 11:18:38 -050022#include <map>
Ratan Guptadcb10672017-07-10 10:33:50 +053023
Vishwanatha Subbannab12b0c02017-03-07 18:17:19 +053024#include <phosphor-logging/log.hpp>
Ratan Guptadcb10672017-07-10 10:33:50 +053025#include <phosphor-logging/elog-errors.hpp>
Vishwanatha Subbannab12b0c02017-03-07 18:17:19 +053026#include <xyz/openbmc_project/State/Host/server.hpp>
Ratan Guptadcb10672017-07-10 10:33:50 +053027#include "xyz/openbmc_project/Common/error.hpp"
28
29#include <sdbusplus/bus.hpp>
30#include <sdbusplus/server/object.hpp>
Deepak Kodihalli8cc19362017-07-21 11:18:38 -050031#include <xyz/openbmc_project/Control/Boot/Source/server.hpp>
32#include <xyz/openbmc_project/Control/Boot/Mode/server.hpp>
Deepak Kodihalli18b70d12017-07-21 13:36:33 -050033#include <xyz/openbmc_project/Control/Power/RestorePolicy/server.hpp>
Ratan Guptadcb10672017-07-10 10:33:50 +053034
Vishwanatha Subbannab891a572017-03-31 11:34:48 +053035#include "config.h"
ratagupta6f6bff2016-04-04 06:20:11 -050036
37//Defines
Ratan Guptafd28dd72016-08-01 04:58:01 -050038#define SET_PARM_VERSION 0x01
39#define SET_PARM_BOOT_FLAGS_PERMANENT 0x40 //boot flags data1 7th bit on
ratagupta6f6bff2016-04-04 06:20:11 -050040#define SET_PARM_BOOT_FLAGS_VALID_ONE_TIME 0x80 //boot flags data1 8th bit on
Ratan Guptafd28dd72016-08-01 04:58:01 -050041#define SET_PARM_BOOT_FLAGS_VALID_PERMANENT 0xC0 //boot flags data1 7 & 8 bit on
ratagupta6f6bff2016-04-04 06:20:11 -050042
Ratan Guptafd28dd72016-08-01 04:58:01 -050043constexpr size_t SIZE_MAC = 18;
44constexpr size_t SIZE_BOOT_OPTION = (uint8_t)BootOptionResponseSize::
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -050045 OPAL_NETWORK_SETTINGS;//Maximum size of the boot option parametrs
Ratan Guptafd28dd72016-08-01 04:58:01 -050046constexpr size_t SIZE_PREFIX = 7;
47constexpr size_t MAX_PREFIX_VALUE = 32;
48constexpr size_t SIZE_COOKIE = 4;
49constexpr size_t SIZE_VERSION = 2;
Ratan Gupta6ec7daa2017-07-15 14:13:01 +053050
Ratan Guptafd28dd72016-08-01 04:58:01 -050051//PetiBoot-Specific
Ratan Gupta6ec7daa2017-07-15 14:13:01 +053052static constexpr uint8_t net_conf_initial_bytes[] = {0x80, 0x21, 0x70, 0x62,
53 0x21, 0x00, 0x01, 0x06};
Ratan Guptafd28dd72016-08-01 04:58:01 -050054
55static constexpr size_t COOKIE_OFFSET = 1;
56static constexpr size_t VERSION_OFFSET = 5;
Ratan Gupta6ec7daa2017-07-15 14:13:01 +053057static constexpr size_t ADDR_SIZE_OFFSET = 8;
Ratan Guptafd28dd72016-08-01 04:58:01 -050058static constexpr size_t MAC_OFFSET = 9;
59static constexpr size_t ADDRTYPE_OFFSET = 16;
60static constexpr size_t IPADDR_OFFSET = 17;
ratagupta6f6bff2016-04-04 06:20:11 -050061
shgoupfd84fbbf2015-12-17 10:05:51 +080062
Adriana Kobylak40814c62015-10-27 15:58:44 -050063void register_netfn_chassis_functions() __attribute__((constructor));
64
shgoupfd84fbbf2015-12-17 10:05:51 +080065// Host settings in dbus
66// Service name should be referenced by connection name got via object mapper
67const char *settings_object_name = "/org/openbmc/settings/host0";
68const char *settings_intf_name = "org.freedesktop.DBus.Properties";
69const char *host_intf_name = "org.openbmc.settings.Host";
70
Ratan Guptadcb10672017-07-10 10:33:50 +053071constexpr auto SETTINGS_ROOT = "/";
72constexpr auto SETTINGS_MATCH = "host0";
Ratan Guptadcb10672017-07-10 10:33:50 +053073
74constexpr auto IP_INTERFACE = "xyz.openbmc_project.Network.IP";
75constexpr auto MAC_INTERFACE = "xyz.openbmc_project.Network.MACAddress";
76
Ratan Guptadcb10672017-07-10 10:33:50 +053077
Nan Li8d15fb42016-08-16 22:29:40 +080078typedef struct
79{
80 uint8_t cap_flags;
81 uint8_t fru_info_dev_addr;
82 uint8_t sdr_dev_addr;
83 uint8_t sel_dev_addr;
84 uint8_t system_management_dev_addr;
85 uint8_t bridge_dev_addr;
86}__attribute__((packed)) ipmi_chassis_cap_t;
87
Nan Lifdd8ec52016-08-28 03:57:40 +080088typedef struct
89{
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -050090 uint8_t cur_power_state;
91 uint8_t last_power_event;
92 uint8_t misc_power_state;
93 uint8_t front_panel_button_cap_status;
Nan Lifdd8ec52016-08-28 03:57:40 +080094}__attribute__((packed)) ipmi_get_chassis_status_t;
95
Vishwanatha Subbannab12b0c02017-03-07 18:17:19 +053096// Phosphor Host State manager
97namespace State = sdbusplus::xyz::openbmc_project::State::server;
98
Andrew Geisslera6e3a302017-05-31 19:34:00 -050099namespace fs = std::experimental::filesystem;
100
Ratan Guptadcb10672017-07-10 10:33:50 +0530101using namespace phosphor::logging;
102using namespace sdbusplus::xyz::openbmc_project::Common::Error;
103
Deepak Kodihalli8cc19362017-07-21 11:18:38 -0500104namespace chassis
105{
106namespace internal
107{
108
109constexpr auto bootModeIntf = "xyz.openbmc_project.Control.Boot.Mode";
110constexpr auto bootSourceIntf = "xyz.openbmc_project.Control.Boot.Source";
Deepak Kodihalli18b70d12017-07-21 13:36:33 -0500111constexpr auto powerRestoreIntf =
112 "xyz.openbmc_project.Control.Power.RestorePolicy";
Deepak Kodihalli8cc19362017-07-21 11:18:38 -0500113sdbusplus::bus::bus dbus(ipmid_get_sd_bus_connection());
114
115namespace cache
116{
117
118settings::Objects objects(dbus,
Deepak Kodihalli18b70d12017-07-21 13:36:33 -0500119 {bootModeIntf, bootSourceIntf, powerRestoreIntf});
Deepak Kodihalli8cc19362017-07-21 11:18:38 -0500120
121} // namespace cache
122} // namespace internal
123} // namespace chassis
124
Ratan Guptadcb10672017-07-10 10:33:50 +0530125//TODO : Can remove the below function as we have
126// new functions which uses sdbusplus.
127//
128// openbmc/openbmc#1489
ratagupta6f6bff2016-04-04 06:20:11 -0500129int dbus_get_property(const char *name, char **buf)
shgoupfd84fbbf2015-12-17 10:05:51 +0800130{
131 sd_bus_error error = SD_BUS_ERROR_NULL;
132 sd_bus_message *m = NULL;
133 sd_bus *bus = NULL;
134 char *temp_buf = NULL;
135 char *connection = NULL;
136 int r;
137
Brad Bishop35518682016-07-22 08:35:41 -0400138 // Get the system bus where most system services are provided.
139 bus = ipmid_get_sd_bus_connection();
shgoupfd84fbbf2015-12-17 10:05:51 +0800140
Brad Bishop35518682016-07-22 08:35:41 -0400141 r = mapper_get_service(bus, settings_object_name, &connection);
shgoupfd84fbbf2015-12-17 10:05:51 +0800142 if (r < 0) {
Brad Bishop819ddd42016-10-05 21:19:19 -0400143 fprintf(stderr, "Failed to get %s connection: %s\n",
144 settings_object_name, strerror(-r));
shgoupfd84fbbf2015-12-17 10:05:51 +0800145 goto finish;
146 }
147
shgoupfd84fbbf2015-12-17 10:05:51 +0800148 /*
149 * Bus, service, object path, interface and method are provided to call
150 * the method.
151 * Signatures and input arguments are provided by the arguments at the
152 * end.
153 */
154 r = sd_bus_call_method(bus,
155 connection, /* service to contact */
156 settings_object_name, /* object path */
157 settings_intf_name, /* interface name */
158 "Get", /* method name */
159 &error, /* object to return error in */
160 &m, /* return message on success */
161 "ss", /* input signature */
162 host_intf_name, /* first argument */
ratagupta6f6bff2016-04-04 06:20:11 -0500163 name); /* second argument */
shgoupfd84fbbf2015-12-17 10:05:51 +0800164
165 if (r < 0) {
166 fprintf(stderr, "Failed to issue method call: %s\n", error.message);
167 goto finish;
168 }
169
170 /*
171 * The output should be parsed exactly the same as the output formatting
172 * specified.
173 */
174 r = sd_bus_message_read(m, "v", "s", &temp_buf);
175 if (r < 0) {
176 fprintf(stderr, "Failed to parse response message: %s\n", strerror(-r));
177 goto finish;
178 }
179
Matthew Barth56181052017-01-23 09:36:29 -0600180 *buf = strdup(temp_buf);
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500181 /* *buf = (char*) malloc(strlen(temp_buf));
shgoupfd84fbbf2015-12-17 10:05:51 +0800182 if (*buf) {
183 strcpy(*buf, temp_buf);
184 }
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500185 */
shgoupfd84fbbf2015-12-17 10:05:51 +0800186 printf("IPMID boot option property get: {%s}.\n", (char *) temp_buf);
187
188finish:
189 sd_bus_error_free(&error);
190 sd_bus_message_unref(m);
191 free(connection);
192
193 return r;
194}
195
Ratan Guptadcb10672017-07-10 10:33:50 +0530196//TODO : Can remove the below function as we have
197// new functions which uses sdbusplus.
198//
199// openbmc/openbmc#1489
200
ratagupta6f6bff2016-04-04 06:20:11 -0500201int dbus_set_property(const char * name, const char *value)
shgoupfd84fbbf2015-12-17 10:05:51 +0800202{
203 sd_bus_error error = SD_BUS_ERROR_NULL;
204 sd_bus_message *m = NULL;
205 sd_bus *bus = NULL;
206 char *connection = NULL;
207 int r;
208
Brad Bishop35518682016-07-22 08:35:41 -0400209 // Get the system bus where most system services are provided.
210 bus = ipmid_get_sd_bus_connection();
shgoupfd84fbbf2015-12-17 10:05:51 +0800211
Brad Bishop35518682016-07-22 08:35:41 -0400212 r = mapper_get_service(bus, settings_object_name, &connection);
shgoupfd84fbbf2015-12-17 10:05:51 +0800213 if (r < 0) {
Brad Bishop819ddd42016-10-05 21:19:19 -0400214 fprintf(stderr, "Failed to get %s connection: %s\n",
215 settings_object_name, strerror(-r));
shgoupfd84fbbf2015-12-17 10:05:51 +0800216 goto finish;
217 }
218
shgoupfd84fbbf2015-12-17 10:05:51 +0800219 /*
220 * Bus, service, object path, interface and method are provided to call
221 * the method.
222 * Signatures and input arguments are provided by the arguments at the
223 * end.
224 */
225 r = sd_bus_call_method(bus,
226 connection, /* service to contact */
227 settings_object_name, /* object path */
228 settings_intf_name, /* interface name */
229 "Set", /* method name */
230 &error, /* object to return error in */
231 &m, /* return message on success */
232 "ssv", /* input signature */
233 host_intf_name, /* first argument */
ratagupta6f6bff2016-04-04 06:20:11 -0500234 name, /* second argument */
shgoupfd84fbbf2015-12-17 10:05:51 +0800235 "s", /* third argument */
ratagupta6f6bff2016-04-04 06:20:11 -0500236 value); /* fourth argument */
shgoupfd84fbbf2015-12-17 10:05:51 +0800237
238 if (r < 0) {
239 fprintf(stderr, "Failed to issue method call: %s\n", error.message);
240 goto finish;
241 }
242
ratagupta6f6bff2016-04-04 06:20:11 -0500243 printf("IPMID boot option property set: {%s}.\n", value);
shgoupfd84fbbf2015-12-17 10:05:51 +0800244
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500245 finish:
shgoupfd84fbbf2015-12-17 10:05:51 +0800246 sd_bus_error_free(&error);
247 sd_bus_message_unref(m);
248 free(connection);
249
250 return r;
251}
252
Adriana Kobylak40814c62015-10-27 15:58:44 -0500253struct get_sys_boot_options_t {
254 uint8_t parameter;
255 uint8_t set;
256 uint8_t block;
257} __attribute__ ((packed));
258
shgoupfd84fbbf2015-12-17 10:05:51 +0800259struct get_sys_boot_options_response_t {
260 uint8_t version;
261 uint8_t parm;
Ratan Guptafd28dd72016-08-01 04:58:01 -0500262 uint8_t data[SIZE_BOOT_OPTION];
shgoupfd84fbbf2015-12-17 10:05:51 +0800263} __attribute__ ((packed));
264
265struct set_sys_boot_options_t {
266 uint8_t parameter;
Ratan Guptafd28dd72016-08-01 04:58:01 -0500267 uint8_t data[SIZE_BOOT_OPTION];
shgoupfd84fbbf2015-12-17 10:05:51 +0800268} __attribute__ ((packed));
269
Ratan Guptafd28dd72016-08-01 04:58:01 -0500270
Ratan Guptadcb10672017-07-10 10:33:50 +0530271int getHostNetworkData(get_sys_boot_options_response_t* respptr)
Ratan Guptafd28dd72016-08-01 04:58:01 -0500272{
Ratan Guptadcb10672017-07-10 10:33:50 +0530273 ipmi::PropertyMap properties;
274 int rc = 0;
Ratan Gupta8c31d232017-08-13 05:49:43 +0530275 uint8_t addrSize = ipmi::network::IPV4_ADDRESS_SIZE_BYTE;
Ratan Guptafd28dd72016-08-01 04:58:01 -0500276
Ratan Guptadcb10672017-07-10 10:33:50 +0530277 try
278 {
279 //TODO There may be cases where an interface is implemented by multiple
280 // objects,to handle such cases we are interested on that object
281 // which are on interested busname.
282 // Currenlty mapper doesn't give the readable busname(gives busid)
283 // so we can't match with bus name so giving some object specific info
284 // as SETTINGS_MATCH.
285 // Later SETTINGS_MATCH will be replaced with busname.
Ratan Guptafd28dd72016-08-01 04:58:01 -0500286
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530287 sdbusplus::bus::bus bus(ipmid_get_sd_bus_connection());
Ratan Guptadcb10672017-07-10 10:33:50 +0530288
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530289 auto ipObjectInfo = ipmi::getDbusObject(bus, IP_INTERFACE,
290 SETTINGS_ROOT, SETTINGS_MATCH);
291
292 auto macObjectInfo = ipmi::getDbusObject(bus, MAC_INTERFACE,
293 SETTINGS_ROOT, SETTINGS_MATCH);
294
295 properties = ipmi::getAllDbusProperties(bus, ipObjectInfo.second,
296 ipObjectInfo.first, IP_INTERFACE);
Ratan Guptacc8feb42017-07-25 21:52:10 +0530297 auto variant =
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530298 ipmi::getDbusProperty(bus, macObjectInfo.second,
299 macObjectInfo.first,
Ratan Guptacc8feb42017-07-25 21:52:10 +0530300 MAC_INTERFACE, "MACAddress");
Ratan Guptadcb10672017-07-10 10:33:50 +0530301
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530302 auto ipAddress = properties["Address"].get<std::string>();
Ratan Guptad70f4532017-08-04 02:07:31 +0530303
304 auto gateway = properties["Gateway"].get<std::string>();
305
306 auto prefix = properties["PrefixLength"].get<uint8_t>();
307
308 uint8_t isStatic = (properties["Origin"].get<std::string>() ==
309 "xyz.openbmc_project.Network.IP.AddressOrigin.Static")
310 ? 1 : 0;
311
Ratan Guptacc8feb42017-07-25 21:52:10 +0530312 auto MACAddress = variant.get<std::string>();
313
Ratan Guptad70f4532017-08-04 02:07:31 +0530314 // it is expected here that we should get the valid data
315 // but we may also get the default values.
316 // Validation of the data is done by settings.
317 //
318 // if mac address is default mac address then
319 // don't send blank override.
Ratan Gupta8c31d232017-08-13 05:49:43 +0530320 if ((MACAddress == ipmi::network::DEFAULT_MAC_ADDRESS))
Ratan Guptad70f4532017-08-04 02:07:31 +0530321 {
322 memset(respptr->data, 0, SIZE_BOOT_OPTION);
323 rc = -1;
324 return rc;
325 }
326 // if addr is static then ipaddress,gateway,prefix
327 // should not be default one,don't send blank override.
328 if (isStatic)
329 {
Ratan Gupta8c31d232017-08-13 05:49:43 +0530330 if((ipAddress == ipmi::network::DEFAULT_ADDRESS) ||
331 (gateway == ipmi::network::DEFAULT_ADDRESS) ||
Ratan Guptad70f4532017-08-04 02:07:31 +0530332 (!prefix))
333 {
334 memset(respptr->data, 0, SIZE_BOOT_OPTION);
335 rc = -1;
336 return rc;
337 }
338 }
339
Ratan Gupta8c31d232017-08-13 05:49:43 +0530340 sscanf(MACAddress.c_str(), ipmi::network::MAC_ADDRESS_FORMAT,
Ratan Guptadcb10672017-07-10 10:33:50 +0530341 (respptr->data + MAC_OFFSET),
342 (respptr->data + MAC_OFFSET + 1),
343 (respptr->data + MAC_OFFSET + 2),
344 (respptr->data + MAC_OFFSET + 3),
345 (respptr->data + MAC_OFFSET + 4),
346 (respptr->data + MAC_OFFSET + 5));
347
Ratan Guptadcb10672017-07-10 10:33:50 +0530348 respptr->data[MAC_OFFSET + 6] = 0x00;
349
Ratan Guptad70f4532017-08-04 02:07:31 +0530350 memcpy(respptr->data + ADDRTYPE_OFFSET, &isStatic,
351 sizeof(isStatic));
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530352
353 uint8_t addressFamily = (properties["Type"].get<std::string>() ==
354 "xyz.openbmc_project.Network.IP.Protocol.IPv4") ?
355 AF_INET : AF_INET6;
356
Ratan Gupta8c31d232017-08-13 05:49:43 +0530357 addrSize = (addressFamily == AF_INET) ?
358 ipmi::network::IPV4_ADDRESS_SIZE_BYTE :
359 ipmi::network::IPV6_ADDRESS_SIZE_BYTE;
Ratan Guptadcb10672017-07-10 10:33:50 +0530360
361 // ipaddress and gateway would be in IPv4 format
Ratan Guptad70f4532017-08-04 02:07:31 +0530362 inet_pton(addressFamily, ipAddress.c_str(),
363 (respptr->data + IPADDR_OFFSET));
Ratan Guptadcb10672017-07-10 10:33:50 +0530364
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530365 uint8_t prefixOffset = IPADDR_OFFSET + addrSize;
366
367 memcpy(respptr->data + prefixOffset, &prefix, sizeof(prefix));
368
369 uint8_t gatewayOffset = prefixOffset + sizeof(decltype(prefix));
370
Ratan Guptad70f4532017-08-04 02:07:31 +0530371 inet_pton(addressFamily, gateway.c_str(),
372 (respptr->data + gatewayOffset));
Ratan Guptadcb10672017-07-10 10:33:50 +0530373
374 }
375 catch (InternalFailure& e)
376 {
377 commit<InternalFailure>();
378 memset(respptr->data, 0, SIZE_BOOT_OPTION);
379 rc = -1;
Ratan Guptafd28dd72016-08-01 04:58:01 -0500380 return rc;
381 }
382
Ratan Guptadcb10672017-07-10 10:33:50 +0530383 //PetiBoot-Specific
384 //If sucess then copy the first 9 bytes to the data
Ratan Guptadcb10672017-07-10 10:33:50 +0530385 memcpy(respptr->data, net_conf_initial_bytes,
386 sizeof(net_conf_initial_bytes));
Ratan Guptafd28dd72016-08-01 04:58:01 -0500387
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530388 memcpy(respptr->data + ADDR_SIZE_OFFSET, &addrSize, sizeof(addrSize));
389
Ratan Guptafd28dd72016-08-01 04:58:01 -0500390#ifdef _IPMI_DEBUG_
Ratan Guptadcb10672017-07-10 10:33:50 +0530391 printf("\n===Printing the IPMI Formatted Data========\n");
Ratan Guptafd28dd72016-08-01 04:58:01 -0500392
Ratan Guptadcb10672017-07-10 10:33:50 +0530393 for (uint8_t pos = 0; pos < index; pos++)
394 {
395 printf("%02x ", respptr->data[pos]);
396 }
Ratan Guptafd28dd72016-08-01 04:58:01 -0500397#endif
398
Ratan Guptafd28dd72016-08-01 04:58:01 -0500399 return rc;
400}
401
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530402/** @brief convert IPv4 and IPv6 addresses from binary to text form.
403 * @param[in] family - IPv4/Ipv6
404 * @param[in] data - req data pointer.
405 * @param[in] offset - offset in the data.
406 * @param[in] addrSize - size of the data which needs to be read from offset.
407 * @returns address in text form.
408 */
409
410std::string getAddrStr(uint8_t family, uint8_t* data,
411 uint8_t offset, uint8_t addrSize)
412{
413 char ipAddr[INET6_ADDRSTRLEN] = {};
414
415 switch(family)
416 {
417 case AF_INET:
418 {
419 struct sockaddr_in addr4 {};
420 memcpy(&addr4.sin_addr.s_addr, &data[offset], addrSize);
421
422 inet_ntop(AF_INET, &addr4.sin_addr,
423 ipAddr, INET_ADDRSTRLEN);
424
425 break;
426 }
427 case AF_INET6:
428 {
429 struct sockaddr_in6 addr6 {};
430 memcpy(&addr6.sin6_addr.s6_addr, &data[offset], addrSize);
431
432 inet_ntop(AF_INET6, &addr6.sin6_addr,
433 ipAddr, INET6_ADDRSTRLEN);
434
435 break;
436 }
437 default:
438 {
439 return {};
440 }
441 }
442
443 return ipAddr;
444}
445
Ratan Guptadcb10672017-07-10 10:33:50 +0530446int setHostNetworkData(set_sys_boot_options_t* reqptr)
Ratan Guptafd28dd72016-08-01 04:58:01 -0500447{
Ratan Guptadcb10672017-07-10 10:33:50 +0530448 using namespace std::string_literals;
Ratan Guptafd28dd72016-08-01 04:58:01 -0500449 std::string host_network_config;
Ratan Guptad70f4532017-08-04 02:07:31 +0530450 char mac[] {"00:00:00:00:00:00"};
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530451 std::string ipAddress, gateway;
452 char addrOrigin {0};
453 uint8_t addrSize {0};
Ratan Guptadcb10672017-07-10 10:33:50 +0530454 std::string addressOrigin =
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530455 "xyz.openbmc_project.Network.IP.AddressOrigin.DHCP";
456 std::string addressType =
457 "xyz.openbmc_project.Network.IP.Protocol.IPv4";
Ratan Guptadcb10672017-07-10 10:33:50 +0530458 uint8_t prefix {0};
459 uint32_t zeroCookie = 0;
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530460 uint8_t family = AF_INET;
Ratan Guptafd28dd72016-08-01 04:58:01 -0500461
462 //cookie starts from second byte
463 // version starts from sixth byte
464
Ratan Guptadcb10672017-07-10 10:33:50 +0530465 try
Ratan Guptafd28dd72016-08-01 04:58:01 -0500466 {
Ratan Guptadcb10672017-07-10 10:33:50 +0530467 do
468 {
469 // cookie == 0x21 0x70 0x62 0x21
470 if (memcmp(&(reqptr->data[COOKIE_OFFSET]),
471 (net_conf_initial_bytes + COOKIE_OFFSET),
472 SIZE_COOKIE) != 0)
473 {
474 //cookie == 0
475 if (memcmp(&(reqptr->data[COOKIE_OFFSET]),
476 &zeroCookie,
477 SIZE_COOKIE) == 0)
478 {
479 // need to zero out the network settings.
480 break;
481 }
482
483 log<level::ERR>("Invalid Cookie");
484 elog<InternalFailure>();
485 }
486
487 // vesion == 0x00 0x01
488 if (memcmp(&(reqptr->data[VERSION_OFFSET]),
489 (net_conf_initial_bytes + VERSION_OFFSET),
490 SIZE_VERSION) != 0)
491 {
492
493 log<level::ERR>("Invalid Version");
494 elog<InternalFailure>();
495 }
496
Ratan Gupta8c31d232017-08-13 05:49:43 +0530497 snprintf(mac, SIZE_MAC, ipmi::network::MAC_ADDRESS_FORMAT,
Ratan Guptadcb10672017-07-10 10:33:50 +0530498 reqptr->data[MAC_OFFSET],
499 reqptr->data[MAC_OFFSET + 1],
500 reqptr->data[MAC_OFFSET + 2],
501 reqptr->data[MAC_OFFSET + 3],
502 reqptr->data[MAC_OFFSET + 4],
503 reqptr->data[MAC_OFFSET + 5]);
504
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530505 memcpy(&addrOrigin, &(reqptr->data[ADDRTYPE_OFFSET]),
506 sizeof(decltype(addrOrigin)));
Ratan Guptadcb10672017-07-10 10:33:50 +0530507
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530508 if (addrOrigin)
Ratan Guptadcb10672017-07-10 10:33:50 +0530509 {
510 addressOrigin =
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530511 "xyz.openbmc_project.Network.IP.AddressOrigin.Static";
Ratan Guptadcb10672017-07-10 10:33:50 +0530512 }
513
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530514 // Get the address size
515 memcpy(&addrSize ,&reqptr->data[ADDR_SIZE_OFFSET], sizeof(addrSize));
Ratan Guptadcb10672017-07-10 10:33:50 +0530516
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530517 uint8_t prefixOffset = IPADDR_OFFSET + addrSize;
Ratan Guptadcb10672017-07-10 10:33:50 +0530518
Ratan Guptad70f4532017-08-04 02:07:31 +0530519 memcpy(&prefix, &(reqptr->data[prefixOffset]),
520 sizeof(decltype(prefix)));
Ratan Guptadcb10672017-07-10 10:33:50 +0530521
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530522 uint8_t gatewayOffset = prefixOffset + sizeof(decltype(prefix));
523
Ratan Gupta8c31d232017-08-13 05:49:43 +0530524 if (addrSize != ipmi::network::IPV4_ADDRESS_SIZE_BYTE)
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530525 {
526 addressType = "xyz.openbmc_project.Network.IP.Protocol.IPv6";
527 family = AF_INET6;
528 }
529
530 ipAddress = getAddrStr(family, reqptr->data, IPADDR_OFFSET, addrSize);
Ratan Guptad70f4532017-08-04 02:07:31 +0530531
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530532 gateway = getAddrStr(family, reqptr->data, gatewayOffset, addrSize);
533
Ratan Guptadcb10672017-07-10 10:33:50 +0530534 } while(0);
535
Ratan Guptafd28dd72016-08-01 04:58:01 -0500536 //Cookie == 0 or it is a valid cookie
Ratan Guptadcb10672017-07-10 10:33:50 +0530537 host_network_config += "ipaddress="s + ipAddress +
538 ",prefix="s + std::to_string(prefix) + ",gateway="s + gateway +
539 ",mac="s + mac + ",addressOrigin="s + addressOrigin;
Ratan Guptafd28dd72016-08-01 04:58:01 -0500540
Ratan Guptafd28dd72016-08-01 04:58:01 -0500541
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530542 sdbusplus::bus::bus bus(ipmid_get_sd_bus_connection());
543
544 auto ipObjectInfo = ipmi::getDbusObject(bus, IP_INTERFACE,
545 SETTINGS_ROOT, SETTINGS_MATCH);
546 auto macObjectInfo = ipmi::getDbusObject(bus, MAC_INTERFACE,
547 SETTINGS_ROOT, SETTINGS_MATCH);
Ratan Guptadcb10672017-07-10 10:33:50 +0530548 // set the dbus property
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530549 ipmi::setDbusProperty(bus, ipObjectInfo.second, ipObjectInfo.first,
Ratan Guptadcb10672017-07-10 10:33:50 +0530550 IP_INTERFACE, "Address", std::string(ipAddress));
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530551 ipmi::setDbusProperty(bus, ipObjectInfo.second, ipObjectInfo.first,
Ratan Guptadcb10672017-07-10 10:33:50 +0530552 IP_INTERFACE, "PrefixLength", prefix);
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530553 ipmi::setDbusProperty(bus, ipObjectInfo.second, ipObjectInfo.first,
Ratan Guptadcb10672017-07-10 10:33:50 +0530554 IP_INTERFACE, "Origin", addressOrigin);
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530555 ipmi::setDbusProperty(bus, ipObjectInfo.second, ipObjectInfo.first,
Ratan Guptadcb10672017-07-10 10:33:50 +0530556 IP_INTERFACE, "Gateway", std::string(gateway));
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530557 ipmi::setDbusProperty(bus, ipObjectInfo.second, ipObjectInfo.first,
Ratan Guptadcb10672017-07-10 10:33:50 +0530558 IP_INTERFACE, "Type",
559 std::string("xyz.openbmc_project.Network.IP.Protocol.IPv4"));
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530560 ipmi::setDbusProperty(bus, macObjectInfo.second, macObjectInfo.first,
Ratan Guptadcb10672017-07-10 10:33:50 +0530561 MAC_INTERFACE,"MACAddress", std::string(mac));
Ratan Guptafd28dd72016-08-01 04:58:01 -0500562
Ratan Guptad70f4532017-08-04 02:07:31 +0530563 log<level::DEBUG>("Network configuration changed",
564 entry("NETWORKCONFIG=%s", host_network_config.c_str()));
565
Ratan Guptafd28dd72016-08-01 04:58:01 -0500566 }
Ratan Guptadcb10672017-07-10 10:33:50 +0530567 catch (InternalFailure& e)
568 {
569 commit<InternalFailure>();
570 return -1;
571 }
572
573 return 0;
Ratan Guptafd28dd72016-08-01 04:58:01 -0500574}
575
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500576ipmi_ret_t ipmi_chassis_wildcard(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
577 ipmi_request_t request,
578 ipmi_response_t response,
579 ipmi_data_len_t data_len,
580 ipmi_context_t context)
Adriana Kobylak40814c62015-10-27 15:58:44 -0500581{
582 printf("Handling CHASSIS WILDCARD Netfn:[0x%X], Cmd:[0x%X]\n",netfn, cmd);
583 // Status code.
Nan Li70aa8d92016-08-29 00:11:10 +0800584 ipmi_ret_t rc = IPMI_CC_INVALID;
Adriana Kobylak40814c62015-10-27 15:58:44 -0500585 *data_len = 0;
586 return rc;
587}
588
Nan Li8d15fb42016-08-16 22:29:40 +0800589ipmi_ret_t ipmi_get_chassis_cap(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500590 ipmi_request_t request, ipmi_response_t response,
591 ipmi_data_len_t data_len, ipmi_context_t context)
Nan Li8d15fb42016-08-16 22:29:40 +0800592{
593 // sd_bus error
594 ipmi_ret_t rc = IPMI_CC_OK;
595
596 ipmi_chassis_cap_t chassis_cap{};
597
598 *data_len = sizeof(ipmi_chassis_cap_t);
599
600 // TODO: need future work. Get those flag from MRW.
601
602 // capabilities flags
603 // [7..4] - reserved
604 // [3] – 1b = provides power interlock (IPM 1.5)
605 // [2] – 1b = provides Diagnostic Interrupt (FP NMI)
606 // [1] – 1b = provides “Front Panel Lockout” (indicates that the chassis has capabilities
607 // to lock out external power control and reset button or front panel interfaces
608 // and/or detect tampering with those interfaces).
609 // [0] -1b = Chassis provides intrusion (physical security) sensor.
610 // set to default value 0x0.
611 chassis_cap.cap_flags = 0x0;
612
613 // Since we do not have a separate SDR Device/SEL Device/ FRU repository.
614 // The 20h was given as those 5 device addresses.
615 // Chassis FRU info Device Address
616 chassis_cap.fru_info_dev_addr = 0x20;
617
618 // Chassis SDR Device Address
619 chassis_cap.sdr_dev_addr = 0x20;
620
621 // Chassis SEL Device Address
622 chassis_cap.sel_dev_addr = 0x20;
623
624 // Chassis System Management Device Address
625 chassis_cap.system_management_dev_addr = 0x20;
626
627 // Chassis Bridge Device Address.
628 chassis_cap.bridge_dev_addr = 0x20;
629
630 memcpy(response, &chassis_cap, *data_len);
631
632 return rc;
633}
634
Vishwanatha Subbannab12b0c02017-03-07 18:17:19 +0530635//------------------------------------------
636// Calls into Host State Manager Dbus object
637//------------------------------------------
638int initiate_state_transition(State::Host::Transition transition)
vishwa36993272015-11-20 12:43:49 -0600639{
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500640 // OpenBMC Host State Manager dbus framework
641 constexpr auto HOST_STATE_MANAGER_ROOT = "/xyz/openbmc_project/state/host0";
642 constexpr auto HOST_STATE_MANAGER_IFACE = "xyz.openbmc_project.State.Host";
643 constexpr auto DBUS_PROPERTY_IFACE = "org.freedesktop.DBus.Properties";
644 constexpr auto PROPERTY = "RequestedHostTransition";
Vishwanatha Subbannab12b0c02017-03-07 18:17:19 +0530645
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500646 // sd_bus error
647 int rc = 0;
648 char *busname = NULL;
vishwa36993272015-11-20 12:43:49 -0600649
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500650 // SD Bus error report mechanism.
651 sd_bus_error bus_error = SD_BUS_ERROR_NULL;
vishwa36993272015-11-20 12:43:49 -0600652
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500653 // Gets a hook onto either a SYSTEM or SESSION bus
654 sd_bus *bus_type = ipmid_get_sd_bus_connection();
655 rc = mapper_get_service(bus_type, HOST_STATE_MANAGER_ROOT, &busname);
656 if (rc < 0)
657 {
658 log<level::ERR>("Failed to get bus name",
659 entry("ERROR=%s, OBJPATH=%s",
660 strerror(-rc), HOST_STATE_MANAGER_ROOT));
661 return rc;
662 }
Vishwanatha Subbannab12b0c02017-03-07 18:17:19 +0530663
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500664 // Convert to string equivalent of the passed in transition enum.
665 auto request = State::convertForMessage(transition);
Vishwanatha Subbannab12b0c02017-03-07 18:17:19 +0530666
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500667 rc = sd_bus_call_method(bus_type, // On the system bus
668 busname, // Service to contact
669 HOST_STATE_MANAGER_ROOT, // Object path
670 DBUS_PROPERTY_IFACE, // Interface name
671 "Set", // Method to be called
672 &bus_error, // object to return error
673 nullptr, // Response buffer if any
674 "ssv", // Takes 3 arguments
675 HOST_STATE_MANAGER_IFACE,
676 PROPERTY,
677 "s", request.c_str());
678 if(rc < 0)
679 {
680 log<level::ERR>("Failed to initiate transition",
681 entry("ERROR=%s, REQUEST=%s",
682 bus_error.message, request.c_str()));
683 }
684 else
685 {
686 log<level::INFO>("Transition request initiated successfully");
687 }
vishwa36993272015-11-20 12:43:49 -0600688
689 sd_bus_error_free(&bus_error);
Sergey Solomineb9b8142016-08-23 09:07:28 -0500690 free(busname);
vishwa36993272015-11-20 12:43:49 -0600691
Sergey Solomineb9b8142016-08-23 09:07:28 -0500692 return rc;
vishwa36993272015-11-20 12:43:49 -0600693}
694
Deepak Kodihalli18b70d12017-07-21 13:36:33 -0500695namespace power_policy
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500696{
Nan Lifdd8ec52016-08-28 03:57:40 +0800697
Deepak Kodihalli18b70d12017-07-21 13:36:33 -0500698using namespace sdbusplus::xyz::openbmc_project::Control::Power::server;
699using IpmiValue = uint8_t;
700using DbusValue = RestorePolicy::Policy;
Nan Lifdd8ec52016-08-28 03:57:40 +0800701
Deepak Kodihalli18b70d12017-07-21 13:36:33 -0500702std::map<DbusValue, IpmiValue> dbusToIpmi =
703{
704 {RestorePolicy::Policy::AlwaysOff, 0x00},
705 {RestorePolicy::Policy::Restore, 0x01},
706 {RestorePolicy::Policy::AlwaysOn, 0x02}
707};
Nan Lifdd8ec52016-08-28 03:57:40 +0800708
Deepak Kodihalli18b70d12017-07-21 13:36:33 -0500709} // namespace power_policy
Nan Lifdd8ec52016-08-28 03:57:40 +0800710
711//----------------------------------------------------------------------
712// Get Chassis Status commands
713//----------------------------------------------------------------------
714ipmi_ret_t ipmi_get_chassis_status(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500715 ipmi_request_t request,
716 ipmi_response_t response,
717 ipmi_data_len_t data_len,
718 ipmi_context_t context)
Nan Lifdd8ec52016-08-28 03:57:40 +0800719{
720 const char *objname = "/org/openbmc/control/power0";
721 const char *intf = "org.openbmc.control.Power";
722
723 sd_bus *bus = NULL;
724 sd_bus_message *reply = NULL;
725 int r = 0;
726 int pgood = 0;
727 char *busname = NULL;
728 ipmi_ret_t rc = IPMI_CC_OK;
729 ipmi_get_chassis_status_t chassis_status{};
730
Nan Lifdd8ec52016-08-28 03:57:40 +0800731 uint8_t s = 0;
732
Deepak Kodihalli18b70d12017-07-21 13:36:33 -0500733 using namespace chassis::internal;
734 using namespace chassis::internal::cache;
735 using namespace power_policy;
736
737 const auto& powerRestoreSetting = objects.map.at(powerRestoreIntf);
738 auto method =
739 dbus.new_method_call(
740 objects.service(powerRestoreSetting, powerRestoreIntf).c_str(),
741 powerRestoreSetting.c_str(),
Ratan Guptacc8feb42017-07-25 21:52:10 +0530742 ipmi::PROP_INTF,
Deepak Kodihalli18b70d12017-07-21 13:36:33 -0500743 "Get");
744 method.append(powerRestoreIntf, "PowerRestorePolicy");
745 auto resp = dbus.call(method);
746 if (resp.is_method_error())
747 {
748 log<level::ERR>("Error in PowerRestorePolicy Get");
749 report<InternalFailure>();
750 *data_len = 0;
751 return IPMI_CC_UNSPECIFIED_ERROR;
752 }
753 sdbusplus::message::variant<std::string> result;
754 resp.read(result);
755 auto powerRestore =
756 RestorePolicy::convertPolicyFromString(result.get<std::string>());
Nan Lifdd8ec52016-08-28 03:57:40 +0800757
758 *data_len = 4;
759
Tom Joseph63a00512017-08-09 23:39:59 +0530760 bus = ipmid_get_sd_bus_connection();
761
Nan Lifdd8ec52016-08-28 03:57:40 +0800762 r = mapper_get_service(bus, objname, &busname);
763 if (r < 0) {
764 fprintf(stderr, "Failed to get bus name, return value: %s.\n", strerror(-r));
765 rc = IPMI_CC_UNSPECIFIED_ERROR;
766 goto finish;
767 }
768
769 r = sd_bus_get_property(bus, busname, objname, intf, "pgood", NULL, &reply, "i");
770 if (r < 0) {
771 fprintf(stderr, "Failed to call sd_bus_get_property:%d, %s\n", r, strerror(-r));
772 fprintf(stderr, "Bus: %s, Path: %s, Interface: %s\n",
773 busname, objname, intf);
774 rc = IPMI_CC_UNSPECIFIED_ERROR;
775 goto finish;
776 }
777
778 r = sd_bus_message_read(reply, "i", &pgood);
779 if (r < 0) {
780 fprintf(stderr, "Failed to read sensor: %s\n", strerror(-r));
781 rc = IPMI_CC_UNSPECIFIED_ERROR;
782 goto finish;
783 }
784
785 printf("pgood is 0x%02x\n", pgood);
786
Deepak Kodihalli18b70d12017-07-21 13:36:33 -0500787 s = dbusToIpmi.at(powerRestore);
Nan Lifdd8ec52016-08-28 03:57:40 +0800788
789 // Current Power State
790 // [7] reserved
791 // [6..5] power restore policy
792 // 00b = chassis stays powered off after AC/mains returns
793 // 01b = after AC returns, power is restored to the state that was
794 // in effect when AC/mains was lost.
795 // 10b = chassis always powers up after AC/mains returns
796 // 11b = unknow
797 // Set to 00b, by observing the hardware behavior.
798 // Do we need to define a dbus property to identify the restore policy?
799
800 // [4] power control fault
801 // 1b = controller attempted to turn system power on or off, but
802 // system did not enter desired state.
803 // Set to 0b, since We don't support it..
804
805 // [3] power fault
806 // 1b = fault detected in main power subsystem.
807 // set to 0b. for we don't support it.
808
809 // [2] 1b = interlock (chassis is presently shut down because a chassis
810 // panel interlock switch is active). (IPMI 1.5)
811 // set to 0b, for we don't support it.
812
813 // [1] power overload
814 // 1b = system shutdown because of power overload condition.
815 // set to 0b, for we don't support it.
816
817 // [0] power is on
818 // 1b = system power is on
819 // 0b = system power is off(soft-off S4/S5, or mechanical off)
820
821 chassis_status.cur_power_state = ((s & 0x3)<<5) | (pgood & 0x1);
822
823 // Last Power Event
824 // [7..5] – reserved
825 // [4] – 1b = last ‘Power is on’ state was entered via IPMI command
826 // [3] – 1b = last power down caused by power fault
827 // [2] – 1b = last power down caused by a power interlock being activated
828 // [1] – 1b = last power down caused by a Power overload
829 // [0] – 1b = AC failed
830 // set to 0x0, for we don't support these fields.
831
832 chassis_status.last_power_event = 0;
833
834 // Misc. Chassis State
835 // [7] – reserved
836 // [6] – 1b = Chassis Identify command and state info supported (Optional)
837 // 0b = Chassis Identify command support unspecified via this command.
838 // (The Get Command Support command , if implemented, would still
839 // indicate support for the Chassis Identify command)
840 // [5..4] – Chassis Identify State. Mandatory when bit[6] =1b, reserved (return
841 // as 00b) otherwise. Returns the present chassis identify state.
842 // Refer to the Chassis Identify command for more info.
843 // 00b = chassis identify state = Off
844 // 01b = chassis identify state = Temporary(timed) On
845 // 10b = chassis identify state = Indefinite On
846 // 11b = reserved
847 // [3] – 1b = Cooling/fan fault detected
848 // [2] – 1b = Drive Fault
849 // [1] – 1b = Front Panel Lockout active (power off and reset via chassis
850 // push-buttons disabled.)
851 // [0] – 1b = Chassis Intrusion active
852 // set to 0, for we don't support them.
853 chassis_status.misc_power_state = 0;
854
855 // Front Panel Button Capabilities and disable/enable status(Optional)
856 // set to 0, for we don't support them.
857 chassis_status.front_panel_button_cap_status = 0;
858
859 // Pack the actual response
860 memcpy(response, &chassis_status, *data_len);
861
862finish:
863 free(busname);
864 reply = sd_bus_message_unref(reply);
865
866 return rc;
867}
Chris Austen7888c4d2015-12-03 15:26:20 -0600868
Vishwanatha Subbanna83b5c1c2017-01-25 18:41:51 +0530869//-------------------------------------------------------------
870// Send a command to SoftPowerOff application to stop any timer
871//-------------------------------------------------------------
872int stop_soft_off_timer()
873{
Vishwanatha Subbanna83b5c1c2017-01-25 18:41:51 +0530874 constexpr auto iface = "org.freedesktop.DBus.Properties";
875 constexpr auto soft_off_iface = "xyz.openbmc_project.Ipmi.Internal."
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500876 "SoftPowerOff";
Vishwanatha Subbanna83b5c1c2017-01-25 18:41:51 +0530877
878 constexpr auto property = "ResponseReceived";
879 constexpr auto value = "xyz.openbmc_project.Ipmi.Internal."
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500880 "SoftPowerOff.HostResponse.HostShutdown";
Vishwanatha Subbanna83b5c1c2017-01-25 18:41:51 +0530881
882 // Get the system bus where most system services are provided.
883 auto bus = ipmid_get_sd_bus_connection();
884
885 // Get the service name
Andrew Geissler2b4e4592017-06-08 11:18:35 -0500886 // TODO openbmc/openbmc#1661 - Mapper refactor
887 //
888 // See openbmc/openbmc#1743 for some details but high level summary is that
889 // for now the code will directly call the soft off interface due to a
890 // race condition with mapper usage
891 //
892 //char *busname = nullptr;
893 //auto r = mapper_get_service(bus, SOFTOFF_OBJPATH, &busname);
894 //if (r < 0)
895 //{
896 // fprintf(stderr, "Failed to get %s bus name: %s\n",
897 // SOFTOFF_OBJPATH, strerror(-r));
898 // return r;
899 //}
Vishwanatha Subbanna83b5c1c2017-01-25 18:41:51 +0530900
901 // No error object or reply expected.
Andrew Geissler2b4e4592017-06-08 11:18:35 -0500902 int rc = sd_bus_call_method(bus, SOFTOFF_BUSNAME, SOFTOFF_OBJPATH, iface,
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500903 "Set", nullptr, nullptr, "ssv",
904 soft_off_iface, property, "s", value);
Vishwanatha Subbanna83b5c1c2017-01-25 18:41:51 +0530905 if (rc < 0)
906 {
907 fprintf(stderr, "Failed to set property in SoftPowerOff object: %s\n",
908 strerror(-rc));
909 }
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500910
Andrew Geissler2b4e4592017-06-08 11:18:35 -0500911 //TODO openbmc/openbmc#1661 - Mapper refactor
912 //free(busname);
Vishwanatha Subbanna83b5c1c2017-01-25 18:41:51 +0530913 return rc;
914}
915
vishwa36993272015-11-20 12:43:49 -0600916//----------------------------------------------------------------------
Andrew Geisslera6e3a302017-05-31 19:34:00 -0500917// Create file to indicate there is no need for softoff notification to host
918//----------------------------------------------------------------------
919void indicate_no_softoff_needed()
920{
921 fs::path path{HOST_INBAND_REQUEST_DIR};
922 if (!fs::is_directory(path))
923 {
924 fs::create_directory(path);
925 }
926
927 // Add the host instance (default 0 for now) to the file name
928 std::string file{HOST_INBAND_REQUEST_FILE};
929 auto size = std::snprintf(nullptr,0,file.c_str(),0);
930 size++; // null
931 std::unique_ptr<char[]> buf(new char[size]);
932 std::snprintf(buf.get(),size,file.c_str(),0);
933
934 // Append file name to directory and create it
935 path /= buf.get();
936 std::ofstream(path.c_str());
937}
938
939//----------------------------------------------------------------------
vishwa36993272015-11-20 12:43:49 -0600940// Chassis Control commands
941//----------------------------------------------------------------------
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500942ipmi_ret_t ipmi_chassis_control(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
943 ipmi_request_t request,
944 ipmi_response_t response,
945 ipmi_data_len_t data_len,
946 ipmi_context_t context)
vishwa36993272015-11-20 12:43:49 -0600947{
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500948 // Error from power off.
949 int rc = 0;
vishwa36993272015-11-20 12:43:49 -0600950
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500951 // No response for this command.
vishwa36993272015-11-20 12:43:49 -0600952 *data_len = 0;
953
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500954 // Catch the actual operaton by peeking into request buffer
955 uint8_t chassis_ctrl_cmd = *(uint8_t *)request;
956 printf("Chassis Control Command: Operation:[0x%X]\n",chassis_ctrl_cmd);
vishwa36993272015-11-20 12:43:49 -0600957
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500958 switch(chassis_ctrl_cmd)
959 {
960 case CMD_POWER_ON:
961 rc = initiate_state_transition(State::Host::Transition::On);
962 break;
963 case CMD_POWER_OFF:
964 // Need to Nudge SoftPowerOff application that it needs to stop the
965 // watchdog timer if running.
966 rc = stop_soft_off_timer();
Andrew Geisslera6e3a302017-05-31 19:34:00 -0500967 // Only request the Off transition if the soft power off
968 // application is not running
969 if (rc < 0)
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500970 {
Andrew Geisslera6e3a302017-05-31 19:34:00 -0500971 log<level::INFO>("Did not find soft off service so request "
972 "Host:Transition:Off");
973
974 // First create a file to indicate to the soft off application
975 // that it should not run since this is a direct user initiated
976 // power off request (i.e. a power off request that is not
977 // originating via a soft power off SMS request)
978 indicate_no_softoff_needed();
979
980 // Now request the shutdown
981 rc = initiate_state_transition(State::Host::Transition::Off);
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500982 }
Andrew Geisslera6e3a302017-05-31 19:34:00 -0500983 else
984 {
985 log<level::INFO>("Soft off is running, so let that stop "
986 "the host");
987 }
988
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500989 break;
Vishwanatha Subbanna83b5c1c2017-01-25 18:41:51 +0530990
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500991 case CMD_HARD_RESET:
992 case CMD_POWER_CYCLE:
993 // SPEC has a section that says certain implementations can trigger
994 // PowerOn if power is Off when a command to power cycle is
995 // requested
Andrew Geisslera6e3a302017-05-31 19:34:00 -0500996
997 // First create a file to indicate to the soft off application
998 // that it should not run since this is a direct user initiated
999 // power reboot request (i.e. a reboot request that is not
1000 // originating via a soft power off SMS request)
1001 indicate_no_softoff_needed();
1002
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001003 rc = initiate_state_transition(State::Host::Transition::Reboot);
1004 break;
1005 default:
1006 {
1007 fprintf(stderr, "Invalid Chassis Control command:[0x%X] received\n",chassis_ctrl_cmd);
1008 rc = -1;
1009 }
1010 }
vishwa36993272015-11-20 12:43:49 -06001011
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001012 return ( (rc < 0) ? IPMI_CC_INVALID : IPMI_CC_OK);
vishwa36993272015-11-20 12:43:49 -06001013}
1014
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001015namespace boot_options
1016{
1017
1018using namespace sdbusplus::xyz::openbmc_project::Control::Boot::server;
1019using IpmiValue = uint8_t;
1020constexpr auto ipmiDefault = 0;
1021
1022std::map<IpmiValue, Source::Sources> sourceIpmiToDbus =
1023{
1024 {0x01, Source::Sources::Network},
1025 {0x02, Source::Sources::Disk},
1026 {0x05, Source::Sources::ExternalMedia},
1027 {ipmiDefault, Source::Sources::Default}
shgoupfd84fbbf2015-12-17 10:05:51 +08001028};
1029
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001030std::map<IpmiValue, Mode::Modes> modeIpmiToDbus =
1031{
1032 {0x03, Mode::Modes::Safe},
1033 {0x06, Mode::Modes::Setup},
1034 {ipmiDefault, Mode::Modes::Regular}
shgoupfd84fbbf2015-12-17 10:05:51 +08001035};
1036
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001037std::map<Source::Sources, IpmiValue> sourceDbusToIpmi =
1038{
1039 {Source::Sources::Network, 0x01},
1040 {Source::Sources::Disk, 0x02},
1041 {Source::Sources::ExternalMedia, 0x05},
1042 {Source::Sources::Default, ipmiDefault}
1043};
shgoupfd84fbbf2015-12-17 10:05:51 +08001044
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001045std::map<Mode::Modes, IpmiValue> modeDbusToIpmi =
1046{
1047 {Mode::Modes::Safe, 0x03},
1048 {Mode::Modes::Setup, 0x06},
1049 {Mode::Modes::Regular, ipmiDefault}
1050};
shgoupfd84fbbf2015-12-17 10:05:51 +08001051
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001052} // namespace boot_options
shgoupfd84fbbf2015-12-17 10:05:51 +08001053
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001054ipmi_ret_t ipmi_chassis_get_sys_boot_options(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
1055 ipmi_request_t request,
1056 ipmi_response_t response,
1057 ipmi_data_len_t data_len,
1058 ipmi_context_t context)
Adriana Kobylak40814c62015-10-27 15:58:44 -05001059{
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001060 using namespace boot_options;
shgoupfd84fbbf2015-12-17 10:05:51 +08001061 ipmi_ret_t rc = IPMI_CC_PARM_NOT_SUPPORTED;
1062 char *p = NULL;
1063 get_sys_boot_options_response_t *resp = (get_sys_boot_options_response_t *) response;
1064 get_sys_boot_options_t *reqptr = (get_sys_boot_options_t*) request;
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001065 IpmiValue bootOption = ipmiDefault;
Adriana Kobylak40814c62015-10-27 15:58:44 -05001066
1067 printf("IPMI GET_SYS_BOOT_OPTIONS\n");
1068
shgoupfd84fbbf2015-12-17 10:05:51 +08001069 memset(resp,0,sizeof(*resp));
1070 resp->version = SET_PARM_VERSION;
1071 resp->parm = 5;
ratagupta6f6bff2016-04-04 06:20:11 -05001072 resp->data[0] = SET_PARM_BOOT_FLAGS_VALID_ONE_TIME;
Adriana Kobylak40814c62015-10-27 15:58:44 -05001073
Adriana Kobylak40814c62015-10-27 15:58:44 -05001074
shgoupfd84fbbf2015-12-17 10:05:51 +08001075 /*
1076 * Parameter #5 means boot flags. Please refer to 28.13 of ipmi doc.
1077 * This is the only parameter used by petitboot.
1078 */
Ratan Guptafd28dd72016-08-01 04:58:01 -05001079 if ( reqptr->parameter == static_cast<uint8_t>
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001080 ( BootOptionParameter::BOOT_FLAGS )) {
shgoupfd84fbbf2015-12-17 10:05:51 +08001081
Ratan Guptafd28dd72016-08-01 04:58:01 -05001082 *data_len = static_cast<uint8_t>(BootOptionResponseSize::BOOT_FLAGS);
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001083 using namespace chassis::internal;
1084 using namespace chassis::internal::cache;
shgoupfd84fbbf2015-12-17 10:05:51 +08001085
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001086 const auto& bootSourceSetting = objects.map.at(bootSourceIntf);
1087 auto method =
1088 dbus.new_method_call(
1089 objects.service(bootSourceSetting, bootSourceIntf).c_str(),
1090 bootSourceSetting.c_str(),
Ratan Guptacc8feb42017-07-25 21:52:10 +05301091 ipmi::PROP_INTF,
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001092 "Get");
1093 method.append(bootSourceIntf, "BootSource");
1094 auto reply = dbus.call(method);
1095 if (reply.is_method_error())
ratagupta6f6bff2016-04-04 06:20:11 -05001096 {
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001097 log<level::ERR>("Error in BootSource Get");
1098 report<InternalFailure>();
1099 *data_len = 0;
1100 return IPMI_CC_UNSPECIFIED_ERROR;
ratagupta6f6bff2016-04-04 06:20:11 -05001101 }
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001102 sdbusplus::message::variant<std::string> result;
1103 reply.read(result);
1104 auto bootSource =
1105 Source::convertSourcesFromString(result.get<std::string>());
1106
1107 const auto& bootModeSetting = objects.map.at(bootModeIntf);
1108 method = dbus.new_method_call(
1109 objects.service(bootModeSetting, bootModeIntf).c_str(),
1110 bootModeSetting.c_str(),
Ratan Guptacc8feb42017-07-25 21:52:10 +05301111 ipmi::PROP_INTF,
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001112 "Get");
1113 method.append(bootModeIntf, "BootMode");
1114 reply = dbus.call(method);
1115 if (reply.is_method_error())
1116 {
1117 log<level::ERR>("Error in BootMode Get");
1118 report<InternalFailure>();
1119 *data_len = 0;
1120 return IPMI_CC_UNSPECIFIED_ERROR;
1121 }
1122 reply.read(result);
1123 auto bootMode = Mode::convertModesFromString(result.get<std::string>());
1124
1125 bootOption = sourceDbusToIpmi.at(bootSource);
1126 if ((Mode::Modes::Regular == bootMode) &&
1127 (Source::Sources::Default == bootSource))
1128 {
1129 bootOption = ipmiDefault;
1130 }
1131 else if (Source::Sources::Default == bootSource)
1132 {
1133 bootOption = modeDbusToIpmi.at(bootMode);
1134 }
1135 resp->data[1] = (bootOption << 2);
1136 rc = IPMI_CC_OK;
ratagupta6f6bff2016-04-04 06:20:11 -05001137
1138 /* Get the boot policy */
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001139 int r = dbus_get_property("boot_policy",&p);
ratagupta6f6bff2016-04-04 06:20:11 -05001140
1141 if (r < 0) {
1142 fprintf(stderr, "Dbus get property(boot_policy) failed for get_sys_boot_options.\n");
1143 rc = IPMI_CC_UNSPECIFIED_ERROR;
1144
1145 } else {
1146
George Keishing012d6a42017-06-14 03:06:48 -05001147 printf("BootPolicy is [%s]\n", p);
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001148 resp->data[0] = (strncmp(p,"ONETIME",strlen("ONETIME"))==0) ?
1149 SET_PARM_BOOT_FLAGS_VALID_ONE_TIME:
1150 SET_PARM_BOOT_FLAGS_VALID_PERMANENT;
ratagupta6f6bff2016-04-04 06:20:11 -05001151 rc = IPMI_CC_OK;
1152
1153 }
1154
1155
Ratan Guptafd28dd72016-08-01 04:58:01 -05001156 } else if ( reqptr->parameter == static_cast<uint8_t>
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001157 ( BootOptionParameter::OPAL_NETWORK_SETTINGS )) {
Ratan Guptafd28dd72016-08-01 04:58:01 -05001158
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001159 *data_len = static_cast<uint8_t>(BootOptionResponseSize::OPAL_NETWORK_SETTINGS);
Ratan Guptafd28dd72016-08-01 04:58:01 -05001160
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001161 resp->parm = static_cast<uint8_t>(BootOptionParameter::OPAL_NETWORK_SETTINGS);
Ratan Guptafd28dd72016-08-01 04:58:01 -05001162
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001163 int ret = getHostNetworkData(resp);
Ratan Guptafd28dd72016-08-01 04:58:01 -05001164
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001165 if (ret < 0) {
Ratan Guptafd28dd72016-08-01 04:58:01 -05001166
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001167 fprintf(stderr, "getHostNetworkData failed for get_sys_boot_options.\n");
1168 rc = IPMI_CC_UNSPECIFIED_ERROR;
Ratan Guptafd28dd72016-08-01 04:58:01 -05001169
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001170 }else
1171 rc = IPMI_CC_OK;
Ratan Guptafd28dd72016-08-01 04:58:01 -05001172 }
1173
1174 else {
Adriana Kobylak40814c62015-10-27 15:58:44 -05001175 fprintf(stderr, "Unsupported parameter 0x%x\n", reqptr->parameter);
shgoupfd84fbbf2015-12-17 10:05:51 +08001176 }
1177
1178 if (p)
1179 free(p);
1180
Ratan Guptafd28dd72016-08-01 04:58:01 -05001181 if (rc == IPMI_CC_OK)
1182 {
1183 *data_len += 2;
1184 }
1185
shgoupfd84fbbf2015-12-17 10:05:51 +08001186 return rc;
1187}
1188
1189
1190
1191ipmi_ret_t ipmi_chassis_set_sys_boot_options(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001192 ipmi_request_t request,
1193 ipmi_response_t response,
1194 ipmi_data_len_t data_len,
1195 ipmi_context_t context)
shgoupfd84fbbf2015-12-17 10:05:51 +08001196{
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001197 using namespace boot_options;
shgoupfd84fbbf2015-12-17 10:05:51 +08001198 ipmi_ret_t rc = IPMI_CC_OK;
shgoupfd84fbbf2015-12-17 10:05:51 +08001199 set_sys_boot_options_t *reqptr = (set_sys_boot_options_t *) request;
1200
Ratan Guptafd28dd72016-08-01 04:58:01 -05001201 printf("IPMI SET_SYS_BOOT_OPTIONS reqptr->parameter =[%d]\n",reqptr->parameter);
1202
shgoupfd84fbbf2015-12-17 10:05:51 +08001203 // This IPMI command does not have any resposne data
1204 *data_len = 0;
1205
1206 /* 000101
1207 * Parameter #5 means boot flags. Please refer to 28.13 of ipmi doc.
1208 * This is the only parameter used by petitboot.
1209 */
Ratan Guptafd28dd72016-08-01 04:58:01 -05001210
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001211 if (reqptr->parameter == (uint8_t)BootOptionParameter::BOOT_FLAGS)
1212 {
1213 IpmiValue bootOption = ((reqptr->data[1] & 0x3C) >> 2);
1214 using namespace chassis::internal;
1215 using namespace chassis::internal::cache;
shgoupfd84fbbf2015-12-17 10:05:51 +08001216
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001217 auto modeItr = modeIpmiToDbus.find(bootOption);
1218 auto sourceItr = sourceIpmiToDbus.find(bootOption);
1219 if ((ipmiDefault == bootOption) ||
1220 (sourceIpmiToDbus.end() != sourceItr))
1221 {
1222 sdbusplus::message::variant<std::string> property =
1223 convertForMessage(sourceItr->second);
1224 const auto& bootSourceSetting =
1225 objects.map.at(bootSourceIntf);
1226 auto method =
1227 dbus.new_method_call(
1228 objects.service(bootSourceSetting, bootSourceIntf).c_str(),
1229 bootSourceSetting.c_str(),
Ratan Guptacc8feb42017-07-25 21:52:10 +05301230 ipmi::PROP_INTF,
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001231 "Set");
1232 method.append(bootSourceIntf, "BootSource", property);
1233 auto reply = dbus.call(method);
1234 if (reply.is_method_error())
1235 {
1236 log<level::ERR>("Error in BootSource Set");
1237 report<InternalFailure>();
1238 *data_len = 0;
1239 return IPMI_CC_UNSPECIFIED_ERROR;
1240 }
1241 }
1242 if ((ipmiDefault == bootOption) ||
1243 (modeIpmiToDbus.end() != modeItr))
1244 {
1245 sdbusplus::message::variant<std::string> property =
1246 convertForMessage(modeItr->second);
1247 const auto& bootModeSetting = objects.map.at(bootModeIntf);
1248 auto method =
1249 dbus.new_method_call(
1250 objects.service(bootModeSetting, bootModeIntf).c_str(),
1251 bootModeSetting.c_str(),
Ratan Guptacc8feb42017-07-25 21:52:10 +05301252 ipmi::PROP_INTF,
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001253 "Set");
1254 method.append(bootModeIntf, "BootMode", property);
1255 auto reply = dbus.call(method);
1256 if (reply.is_method_error())
1257 {
1258 log<level::ERR>("Error in BootMode Set");
1259 report<InternalFailure>();
1260 *data_len = 0;
1261 return IPMI_CC_UNSPECIFIED_ERROR;
shgoupfd84fbbf2015-12-17 10:05:51 +08001262 }
1263 }
Ratan Guptafd28dd72016-08-01 04:58:01 -05001264
ratagupta6f6bff2016-04-04 06:20:11 -05001265 /* setting the boot policy */
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001266 std::string value =
1267 (char *)(((reqptr->data[0] & SET_PARM_BOOT_FLAGS_PERMANENT) ==
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001268 SET_PARM_BOOT_FLAGS_PERMANENT) ?"PERMANENT":"ONETIME");
ratagupta6f6bff2016-04-04 06:20:11 -05001269
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001270 printf ( "\nBoot Policy is %s",value.c_str());
1271 int r = dbus_set_property("boot_policy",value.c_str());
ratagupta6f6bff2016-04-04 06:20:11 -05001272
1273 if (r < 0) {
1274 fprintf(stderr, "Dbus set property(boot_policy) failed for set_sys_boot_options.\n");
1275 rc = IPMI_CC_UNSPECIFIED_ERROR;
1276 }
shgoupfd84fbbf2015-12-17 10:05:51 +08001277
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001278 } else if (reqptr->parameter ==
1279 (uint8_t)BootOptionParameter::OPAL_NETWORK_SETTINGS) {
Ratan Guptafd28dd72016-08-01 04:58:01 -05001280
1281 int ret = setHostNetworkData(reqptr);
1282 if (ret < 0) {
1283 fprintf(stderr, "setHostNetworkData failed for set_sys_boot_options.\n");
1284 rc = IPMI_CC_UNSPECIFIED_ERROR;
1285 }
1286 }
1287 else {
shgoupfd84fbbf2015-12-17 10:05:51 +08001288 fprintf(stderr, "Unsupported parameter 0x%x\n", reqptr->parameter);
1289 rc = IPMI_CC_PARM_NOT_SUPPORTED;
Adriana Kobylak40814c62015-10-27 15:58:44 -05001290 }
1291
1292 return rc;
1293}
1294
1295void register_netfn_chassis_functions()
1296{
Tom05732372016-09-06 17:21:23 +05301297 // <Wildcard Command>
Adriana Kobylak40814c62015-10-27 15:58:44 -05001298 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_CHASSIS, IPMI_CMD_WILDCARD);
Tom05732372016-09-06 17:21:23 +05301299 ipmi_register_callback(NETFUN_CHASSIS, IPMI_CMD_WILDCARD, NULL, ipmi_chassis_wildcard,
1300 PRIVILEGE_USER);
Adriana Kobylak40814c62015-10-27 15:58:44 -05001301
Tom05732372016-09-06 17:21:23 +05301302 // Get Chassis Capabilities
Nan Li8d15fb42016-08-16 22:29:40 +08001303 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_CHASSIS, IPMI_CMD_GET_CHASSIS_CAP);
Tom05732372016-09-06 17:21:23 +05301304 ipmi_register_callback(NETFUN_CHASSIS, IPMI_CMD_GET_CHASSIS_CAP, NULL, ipmi_get_chassis_cap,
1305 PRIVILEGE_USER);
Nan Li8d15fb42016-08-16 22:29:40 +08001306
Tom05732372016-09-06 17:21:23 +05301307 // <Get System Boot Options>
Adriana Kobylak40814c62015-10-27 15:58:44 -05001308 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_CHASSIS, IPMI_CMD_GET_SYS_BOOT_OPTIONS);
Tom05732372016-09-06 17:21:23 +05301309 ipmi_register_callback(NETFUN_CHASSIS, IPMI_CMD_GET_SYS_BOOT_OPTIONS, NULL,
1310 ipmi_chassis_get_sys_boot_options, PRIVILEGE_OPERATOR);
Adriana Kobylak40814c62015-10-27 15:58:44 -05001311
Tom05732372016-09-06 17:21:23 +05301312 // <Get Chassis Status>
Nan Lifdd8ec52016-08-28 03:57:40 +08001313 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_CHASSIS, IPMI_CMD_CHASSIS_STATUS);
Tom05732372016-09-06 17:21:23 +05301314 ipmi_register_callback(NETFUN_CHASSIS, IPMI_CMD_CHASSIS_STATUS, NULL, ipmi_get_chassis_status,
1315 PRIVILEGE_USER);
Nan Lifdd8ec52016-08-28 03:57:40 +08001316
Tom05732372016-09-06 17:21:23 +05301317 // <Chassis Control>
vishwa36993272015-11-20 12:43:49 -06001318 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_CHASSIS, IPMI_CMD_CHASSIS_CONTROL);
Tom05732372016-09-06 17:21:23 +05301319 ipmi_register_callback(NETFUN_CHASSIS, IPMI_CMD_CHASSIS_CONTROL, NULL, ipmi_chassis_control,
1320 PRIVILEGE_OPERATOR);
shgoupfd84fbbf2015-12-17 10:05:51 +08001321
Tom05732372016-09-06 17:21:23 +05301322 // <Set System Boot Options>
shgoupfd84fbbf2015-12-17 10:05:51 +08001323 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n", NETFUN_CHASSIS, IPMI_CMD_SET_SYS_BOOT_OPTIONS);
Tom05732372016-09-06 17:21:23 +05301324 ipmi_register_callback(NETFUN_CHASSIS, IPMI_CMD_SET_SYS_BOOT_OPTIONS, NULL,
1325 ipmi_chassis_set_sys_boot_options, PRIVILEGE_OPERATOR);
vishwa36993272015-11-20 12:43:49 -06001326}