blob: 6002e7a207329701d1f0ded7464073cab8a1381d [file] [log] [blame]
Adriana Kobylak40814c62015-10-27 15:58:44 -05001#include "chassishandler.h"
Patrick Venture0b02be92018-08-31 11:55:55 -07002
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05003#include "ipmid.hpp"
4#include "settings.hpp"
Patrick Venture0b02be92018-08-31 11:55:55 -07005#include "types.hpp"
Ratan Guptacc8feb42017-07-25 21:52:10 +05306#include "utils.hpp"
Ratan Guptadcb10672017-07-10 10:33:50 +05307
Patrick Venture0b02be92018-08-31 11:55:55 -07008#include <arpa/inet.h>
9#include <endian.h>
10#include <limits.h>
11#include <mapper.h>
12#include <netinet/in.h>
13#include <stdint.h>
Adriana Kobylak40814c62015-10-27 15:58:44 -050014#include <stdio.h>
Ratan Guptafd28dd72016-08-01 04:58:01 -050015#include <stdlib.h>
Ratan Guptafd28dd72016-08-01 04:58:01 -050016#include <string.h>
Patrick Venture0b02be92018-08-31 11:55:55 -070017
Ratan Guptafd28dd72016-08-01 04:58:01 -050018#include <array>
Patrick Venture0b02be92018-08-31 11:55:55 -070019#include <chrono>
Andrew Geisslera6e3a302017-05-31 19:34:00 -050020#include <fstream>
Tom Joseph5110c122018-03-23 17:55:40 +053021#include <future>
Patrick Venture0b02be92018-08-31 11:55:55 -070022#include <sstream>
23
24#include "host-ipmid/ipmid-api.h"
Vernon Mauery185b9f82018-07-20 10:52:36 -070025#if __has_include(<filesystem>)
26#include <filesystem>
27#elif __has_include(<experimental/filesystem>)
Andrew Geisslera6e3a302017-05-31 19:34:00 -050028#include <experimental/filesystem>
Patrick Venture0b02be92018-08-31 11:55:55 -070029namespace std
30{
31// splice experimental::filesystem into std
32namespace filesystem = std::experimental::filesystem;
33} // namespace std
Vernon Mauery185b9f82018-07-20 10:52:36 -070034#else
Patrick Venture0b02be92018-08-31 11:55:55 -070035#error filesystem not available
Vernon Mauery185b9f82018-07-20 10:52:36 -070036#endif
Patrick Venture0b02be92018-08-31 11:55:55 -070037#include "config.h"
38
39#include "timer.hpp"
40
Deepak Kodihalli8cc19362017-07-21 11:18:38 -050041#include <map>
Ratan Guptadcb10672017-07-10 10:33:50 +053042#include <phosphor-logging/elog-errors.hpp>
Patrick Venture0b02be92018-08-31 11:55:55 -070043#include <phosphor-logging/log.hpp>
Ratan Guptadcb10672017-07-10 10:33:50 +053044#include <sdbusplus/bus.hpp>
45#include <sdbusplus/server/object.hpp>
Patrick Venture0b02be92018-08-31 11:55:55 -070046#include <string>
47#include <xyz/openbmc_project/Common/error.hpp>
Deepak Kodihalli8cc19362017-07-21 11:18:38 -050048#include <xyz/openbmc_project/Control/Boot/Mode/server.hpp>
Patrick Venture0b02be92018-08-31 11:55:55 -070049#include <xyz/openbmc_project/Control/Boot/Source/server.hpp>
Deepak Kodihalli18b70d12017-07-21 13:36:33 -050050#include <xyz/openbmc_project/Control/Power/RestorePolicy/server.hpp>
Patrick Venture0b02be92018-08-31 11:55:55 -070051#include <xyz/openbmc_project/State/Host/server.hpp>
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -050052#include <xyz/openbmc_project/State/PowerOnHours/server.hpp>
Patrick Venture0b02be92018-08-31 11:55:55 -070053// Defines
54#define SET_PARM_VERSION 0x01
55#define SET_PARM_BOOT_FLAGS_PERMANENT 0x40 // boot flags data1 7th bit on
56#define SET_PARM_BOOT_FLAGS_VALID_ONE_TIME 0x80 // boot flags data1 8th bit on
57#define SET_PARM_BOOT_FLAGS_VALID_PERMANENT \
58 0xC0 // boot flags data1 7 & 8 bit
59 // on
ratagupta6f6bff2016-04-04 06:20:11 -050060
Marri Devender Rao6706c1c2018-05-14 00:29:38 -050061std::unique_ptr<phosphor::ipmi::Timer> identifyTimer = nullptr;
62
Patrick Venture0b02be92018-08-31 11:55:55 -070063constexpr size_t SIZE_MAC = 18;
64constexpr size_t SIZE_BOOT_OPTION = (uint8_t)
65 BootOptionResponseSize::OPAL_NETWORK_SETTINGS; // Maximum size of the boot
66 // option parametrs
Ratan Guptafd28dd72016-08-01 04:58:01 -050067constexpr size_t SIZE_PREFIX = 7;
68constexpr size_t MAX_PREFIX_VALUE = 32;
69constexpr size_t SIZE_COOKIE = 4;
70constexpr size_t SIZE_VERSION = 2;
Tom Joseph5110c122018-03-23 17:55:40 +053071constexpr size_t DEFAULT_IDENTIFY_TIME_OUT = 15;
Ratan Gupta6ec7daa2017-07-15 14:13:01 +053072
Patrick Venture0b02be92018-08-31 11:55:55 -070073// PetiBoot-Specific
Ratan Gupta6ec7daa2017-07-15 14:13:01 +053074static constexpr uint8_t net_conf_initial_bytes[] = {0x80, 0x21, 0x70, 0x62,
Patrick Venture0b02be92018-08-31 11:55:55 -070075 0x21, 0x00, 0x01, 0x06};
Ratan Guptafd28dd72016-08-01 04:58:01 -050076
77static constexpr size_t COOKIE_OFFSET = 1;
78static constexpr size_t VERSION_OFFSET = 5;
Ratan Gupta6ec7daa2017-07-15 14:13:01 +053079static constexpr size_t ADDR_SIZE_OFFSET = 8;
Ratan Guptafd28dd72016-08-01 04:58:01 -050080static constexpr size_t MAC_OFFSET = 9;
81static constexpr size_t ADDRTYPE_OFFSET = 16;
82static constexpr size_t IPADDR_OFFSET = 17;
ratagupta6f6bff2016-04-04 06:20:11 -050083
Marri Devender Rao6706c1c2018-05-14 00:29:38 -050084static constexpr size_t encIdentifyObjectsSize = 1;
85static constexpr size_t chassisIdentifyReqLength = 2;
86static constexpr size_t identifyIntervalPos = 0;
87static constexpr size_t forceIdentifyPos = 1;
shgoupfd84fbbf2015-12-17 10:05:51 +080088
Adriana Kobylak40814c62015-10-27 15:58:44 -050089void register_netfn_chassis_functions() __attribute__((constructor));
90
shgoupfd84fbbf2015-12-17 10:05:51 +080091// Host settings in dbus
92// Service name should be referenced by connection name got via object mapper
Patrick Venture0b02be92018-08-31 11:55:55 -070093const char* settings_object_name = "/org/openbmc/settings/host0";
94const char* settings_intf_name = "org.freedesktop.DBus.Properties";
95const char* host_intf_name = "org.openbmc.settings.Host";
96const char* identify_led_object_name =
Tom Joseph5110c122018-03-23 17:55:40 +053097 "/xyz/openbmc_project/led/groups/enclosure_identify";
shgoupfd84fbbf2015-12-17 10:05:51 +080098
Ratan Guptadcb10672017-07-10 10:33:50 +053099constexpr auto SETTINGS_ROOT = "/";
100constexpr auto SETTINGS_MATCH = "host0";
Ratan Guptadcb10672017-07-10 10:33:50 +0530101
102constexpr auto IP_INTERFACE = "xyz.openbmc_project.Network.IP";
103constexpr auto MAC_INTERFACE = "xyz.openbmc_project.Network.MACAddress";
104
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -0500105static constexpr auto chassisStateRoot = "/xyz/openbmc_project/state";
106static constexpr auto chassisPOHStateIntf =
Patrick Venture0b02be92018-08-31 11:55:55 -0700107 "xyz.openbmc_project.State.PowerOnHours";
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -0500108static constexpr auto pOHCounterProperty = "POHCounter";
109static constexpr auto match = "chassis0";
Ratan Guptadcb10672017-07-10 10:33:50 +0530110
Nan Li8d15fb42016-08-16 22:29:40 +0800111typedef struct
112{
113 uint8_t cap_flags;
114 uint8_t fru_info_dev_addr;
115 uint8_t sdr_dev_addr;
116 uint8_t sel_dev_addr;
117 uint8_t system_management_dev_addr;
118 uint8_t bridge_dev_addr;
Patrick Venture0b02be92018-08-31 11:55:55 -0700119} __attribute__((packed)) ipmi_chassis_cap_t;
Nan Li8d15fb42016-08-16 22:29:40 +0800120
Nan Lifdd8ec52016-08-28 03:57:40 +0800121typedef struct
122{
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500123 uint8_t cur_power_state;
124 uint8_t last_power_event;
125 uint8_t misc_power_state;
126 uint8_t front_panel_button_cap_status;
Patrick Venture0b02be92018-08-31 11:55:55 -0700127} __attribute__((packed)) ipmi_get_chassis_status_t;
Nan Lifdd8ec52016-08-28 03:57:40 +0800128
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -0500129/**
130 * @struct Get POH counter command response data
131 */
132struct GetPOHCountResponse
133{
Patrick Venture0b02be92018-08-31 11:55:55 -0700134 uint8_t minPerCount; ///< Minutes per count
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -0500135 uint8_t counterReading[4]; ///< Counter reading
Patrick Venture0b02be92018-08-31 11:55:55 -0700136} __attribute__((packed));
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -0500137
Vishwanatha Subbannab12b0c02017-03-07 18:17:19 +0530138// Phosphor Host State manager
139namespace State = sdbusplus::xyz::openbmc_project::State::server;
140
Vernon Mauery185b9f82018-07-20 10:52:36 -0700141namespace fs = std::filesystem;
Andrew Geisslera6e3a302017-05-31 19:34:00 -0500142
Ratan Guptadcb10672017-07-10 10:33:50 +0530143using namespace phosphor::logging;
144using namespace sdbusplus::xyz::openbmc_project::Common::Error;
Marri Devender Rao81719702018-05-07 00:53:48 -0500145using namespace sdbusplus::xyz::openbmc_project::Control::Boot::server;
Deepak Kodihalli8cc19362017-07-21 11:18:38 -0500146namespace chassis
147{
148namespace internal
149{
150
151constexpr auto bootModeIntf = "xyz.openbmc_project.Control.Boot.Mode";
152constexpr auto bootSourceIntf = "xyz.openbmc_project.Control.Boot.Source";
Deepak Kodihalli18b70d12017-07-21 13:36:33 -0500153constexpr auto powerRestoreIntf =
154 "xyz.openbmc_project.Control.Power.RestorePolicy";
Deepak Kodihalli8cc19362017-07-21 11:18:38 -0500155sdbusplus::bus::bus dbus(ipmid_get_sd_bus_connection());
156
157namespace cache
158{
159
160settings::Objects objects(dbus,
Deepak Kodihalli18b70d12017-07-21 13:36:33 -0500161 {bootModeIntf, bootSourceIntf, powerRestoreIntf});
Deepak Kodihalli8cc19362017-07-21 11:18:38 -0500162
163} // namespace cache
164} // namespace internal
165} // namespace chassis
166
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -0500167namespace poh
168{
169
170constexpr auto minutesPerCount = 60;
171
172} // namespace poh
173
Patrick Venture0b02be92018-08-31 11:55:55 -0700174// TODO : Can remove the below function as we have
Ratan Guptadcb10672017-07-10 10:33:50 +0530175// new functions which uses sdbusplus.
176//
177// openbmc/openbmc#1489
Patrick Venture0b02be92018-08-31 11:55:55 -0700178int dbus_get_property(const char* name, char** buf)
shgoupfd84fbbf2015-12-17 10:05:51 +0800179{
180 sd_bus_error error = SD_BUS_ERROR_NULL;
Patrick Venture0b02be92018-08-31 11:55:55 -0700181 sd_bus_message* m = NULL;
182 sd_bus* bus = NULL;
183 char* temp_buf = NULL;
184 char* connection = NULL;
shgoupfd84fbbf2015-12-17 10:05:51 +0800185 int r;
186
Brad Bishop35518682016-07-22 08:35:41 -0400187 // Get the system bus where most system services are provided.
188 bus = ipmid_get_sd_bus_connection();
shgoupfd84fbbf2015-12-17 10:05:51 +0800189
Brad Bishop35518682016-07-22 08:35:41 -0400190 r = mapper_get_service(bus, settings_object_name, &connection);
Patrick Venture0b02be92018-08-31 11:55:55 -0700191 if (r < 0)
192 {
Aditya Saripalli5fb14602017-11-09 14:46:27 +0530193 log<level::ERR>("Failed to get connection",
194 entry("OBJ_NAME=%s", settings_object_name),
195 entry("ERRNO=0x%X", -r));
shgoupfd84fbbf2015-12-17 10:05:51 +0800196 goto finish;
197 }
198
shgoupfd84fbbf2015-12-17 10:05:51 +0800199 /*
200 * Bus, service, object path, interface and method are provided to call
201 * the method.
202 * Signatures and input arguments are provided by the arguments at the
203 * end.
204 */
Patrick Venture0b02be92018-08-31 11:55:55 -0700205 r = sd_bus_call_method(bus, connection, /* service to contact */
206 settings_object_name, /* object path */
207 settings_intf_name, /* interface name */
208 "Get", /* method name */
209 &error, /* object to return error in */
210 &m, /* return message on success */
211 "ss", /* input signature */
212 host_intf_name, /* first argument */
213 name); /* second argument */
shgoupfd84fbbf2015-12-17 10:05:51 +0800214
Patrick Venture0b02be92018-08-31 11:55:55 -0700215 if (r < 0)
216 {
217 log<level::ERR>("Failed to issue Get method call",
Aditya Saripalli5fb14602017-11-09 14:46:27 +0530218 entry("ERRNO=0x%X", r));
shgoupfd84fbbf2015-12-17 10:05:51 +0800219 goto finish;
220 }
221
Patrick Venture0b02be92018-08-31 11:55:55 -0700222 /*
223 * The output should be parsed exactly the same as the output formatting
224 * specified.
225 */
226 r = sd_bus_message_read(m, "v", "s", &temp_buf);
227 if (r < 0)
228 {
229 log<level::ERR>("Failed to parse response message",
230 entry("ERRNO=0x%X", -r));
231 goto finish;
232 }
233
234 *buf = strdup(temp_buf);
235 /* *buf = (char*) malloc(strlen(temp_buf));
236 if (*buf) {
237 strcpy(*buf, temp_buf);
238 }
239 */
240
241finish:
shgoupfd84fbbf2015-12-17 10:05:51 +0800242 sd_bus_error_free(&error);
243 sd_bus_message_unref(m);
244 free(connection);
245
246 return r;
247}
248
Patrick Venture0b02be92018-08-31 11:55:55 -0700249// TODO : Can remove the below function as we have
250// new functions which uses sdbusplus.
251//
252// openbmc/openbmc#1489
253
254int dbus_set_property(const char* name, const char* value)
255{
256 sd_bus_error error = SD_BUS_ERROR_NULL;
257 sd_bus_message* m = NULL;
258 sd_bus* bus = NULL;
259 char* connection = NULL;
260 int r;
261
262 // Get the system bus where most system services are provided.
263 bus = ipmid_get_sd_bus_connection();
264
265 r = mapper_get_service(bus, settings_object_name, &connection);
266 if (r < 0)
267 {
268 log<level::ERR>("Failed to get connection",
269 entry("OBJ_NAME=%s", settings_object_name),
270 entry("ERRNO=0x%X", -r));
271 goto finish;
272 }
273
274 /*
275 * Bus, service, object path, interface and method are provided to call
276 * the method.
277 * Signatures and input arguments are provided by the arguments at the
278 * end.
279 */
280 r = sd_bus_call_method(bus, connection, /* service to contact */
281 settings_object_name, /* object path */
282 settings_intf_name, /* interface name */
283 "Set", /* method name */
284 &error, /* object to return error in */
285 &m, /* return message on success */
286 "ssv", /* input signature */
287 host_intf_name, /* first argument */
288 name, /* second argument */
289 "s", /* third argument */
290 value); /* fourth argument */
291
292 if (r < 0)
293 {
294 log<level::ERR>("Failed to issue Set method call",
295 entry("ERRNO=0x%X", r));
296 goto finish;
297 }
298
299finish:
300 sd_bus_error_free(&error);
301 sd_bus_message_unref(m);
302 free(connection);
303
304 return r;
305}
306
307struct get_sys_boot_options_t
308{
Adriana Kobylak40814c62015-10-27 15:58:44 -0500309 uint8_t parameter;
310 uint8_t set;
311 uint8_t block;
Patrick Venture0b02be92018-08-31 11:55:55 -0700312} __attribute__((packed));
Adriana Kobylak40814c62015-10-27 15:58:44 -0500313
Patrick Venture0b02be92018-08-31 11:55:55 -0700314struct get_sys_boot_options_response_t
315{
shgoupfd84fbbf2015-12-17 10:05:51 +0800316 uint8_t version;
317 uint8_t parm;
Ratan Guptafd28dd72016-08-01 04:58:01 -0500318 uint8_t data[SIZE_BOOT_OPTION];
Patrick Venture0b02be92018-08-31 11:55:55 -0700319} __attribute__((packed));
shgoupfd84fbbf2015-12-17 10:05:51 +0800320
Patrick Venture0b02be92018-08-31 11:55:55 -0700321struct set_sys_boot_options_t
322{
shgoupfd84fbbf2015-12-17 10:05:51 +0800323 uint8_t parameter;
Ratan Guptafd28dd72016-08-01 04:58:01 -0500324 uint8_t data[SIZE_BOOT_OPTION];
Patrick Venture0b02be92018-08-31 11:55:55 -0700325} __attribute__((packed));
Ratan Guptafd28dd72016-08-01 04:58:01 -0500326
Ratan Guptadcb10672017-07-10 10:33:50 +0530327int getHostNetworkData(get_sys_boot_options_response_t* respptr)
Ratan Guptafd28dd72016-08-01 04:58:01 -0500328{
Ratan Guptadcb10672017-07-10 10:33:50 +0530329 ipmi::PropertyMap properties;
330 int rc = 0;
Ratan Gupta8c31d232017-08-13 05:49:43 +0530331 uint8_t addrSize = ipmi::network::IPV4_ADDRESS_SIZE_BYTE;
Ratan Guptafd28dd72016-08-01 04:58:01 -0500332
Ratan Guptadcb10672017-07-10 10:33:50 +0530333 try
334 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700335 // TODO There may be cases where an interface is implemented by multiple
Ratan Guptadcb10672017-07-10 10:33:50 +0530336 // objects,to handle such cases we are interested on that object
337 // which are on interested busname.
338 // Currenlty mapper doesn't give the readable busname(gives busid)
339 // so we can't match with bus name so giving some object specific info
340 // as SETTINGS_MATCH.
341 // Later SETTINGS_MATCH will be replaced with busname.
Ratan Guptafd28dd72016-08-01 04:58:01 -0500342
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530343 sdbusplus::bus::bus bus(ipmid_get_sd_bus_connection());
Ratan Guptadcb10672017-07-10 10:33:50 +0530344
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530345 auto ipObjectInfo = ipmi::getDbusObject(bus, IP_INTERFACE,
346 SETTINGS_ROOT, SETTINGS_MATCH);
347
348 auto macObjectInfo = ipmi::getDbusObject(bus, MAC_INTERFACE,
349 SETTINGS_ROOT, SETTINGS_MATCH);
350
Patrick Venture0b02be92018-08-31 11:55:55 -0700351 properties = ipmi::getAllDbusProperties(
352 bus, ipObjectInfo.second, ipObjectInfo.first, IP_INTERFACE);
353 auto variant = ipmi::getDbusProperty(bus, macObjectInfo.second,
354 macObjectInfo.first, MAC_INTERFACE,
355 "MACAddress");
Ratan Guptadcb10672017-07-10 10:33:50 +0530356
Patrick Venture0b02be92018-08-31 11:55:55 -0700357 auto ipAddress = properties["Address"].get<std::string>();
Ratan Guptad70f4532017-08-04 02:07:31 +0530358
359 auto gateway = properties["Gateway"].get<std::string>();
360
361 auto prefix = properties["PrefixLength"].get<uint8_t>();
362
Patrick Venture0b02be92018-08-31 11:55:55 -0700363 uint8_t isStatic =
364 (properties["Origin"].get<std::string>() ==
365 "xyz.openbmc_project.Network.IP.AddressOrigin.Static")
366 ? 1
367 : 0;
Ratan Guptad70f4532017-08-04 02:07:31 +0530368
Ratan Guptacc8feb42017-07-25 21:52:10 +0530369 auto MACAddress = variant.get<std::string>();
370
Ratan Guptad70f4532017-08-04 02:07:31 +0530371 // it is expected here that we should get the valid data
372 // but we may also get the default values.
373 // Validation of the data is done by settings.
374 //
375 // if mac address is default mac address then
376 // don't send blank override.
Ratan Gupta8c31d232017-08-13 05:49:43 +0530377 if ((MACAddress == ipmi::network::DEFAULT_MAC_ADDRESS))
Ratan Guptad70f4532017-08-04 02:07:31 +0530378 {
379 memset(respptr->data, 0, SIZE_BOOT_OPTION);
380 rc = -1;
381 return rc;
382 }
383 // if addr is static then ipaddress,gateway,prefix
384 // should not be default one,don't send blank override.
385 if (isStatic)
386 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700387 if ((ipAddress == ipmi::network::DEFAULT_ADDRESS) ||
388 (gateway == ipmi::network::DEFAULT_ADDRESS) || (!prefix))
Ratan Guptad70f4532017-08-04 02:07:31 +0530389 {
390 memset(respptr->data, 0, SIZE_BOOT_OPTION);
391 rc = -1;
392 return rc;
393 }
394 }
395
Patrick Venture0b02be92018-08-31 11:55:55 -0700396 sscanf(
397 MACAddress.c_str(), ipmi::network::MAC_ADDRESS_FORMAT,
398 (respptr->data + MAC_OFFSET), (respptr->data + MAC_OFFSET + 1),
399 (respptr->data + MAC_OFFSET + 2), (respptr->data + MAC_OFFSET + 3),
400 (respptr->data + MAC_OFFSET + 4), (respptr->data + MAC_OFFSET + 5));
Ratan Guptadcb10672017-07-10 10:33:50 +0530401
Ratan Guptadcb10672017-07-10 10:33:50 +0530402 respptr->data[MAC_OFFSET + 6] = 0x00;
403
Patrick Venture0b02be92018-08-31 11:55:55 -0700404 memcpy(respptr->data + ADDRTYPE_OFFSET, &isStatic, sizeof(isStatic));
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530405
406 uint8_t addressFamily = (properties["Type"].get<std::string>() ==
Patrick Venture0b02be92018-08-31 11:55:55 -0700407 "xyz.openbmc_project.Network.IP.Protocol.IPv4")
408 ? AF_INET
409 : AF_INET6;
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530410
Patrick Venture0b02be92018-08-31 11:55:55 -0700411 addrSize = (addressFamily == AF_INET)
412 ? ipmi::network::IPV4_ADDRESS_SIZE_BYTE
413 : ipmi::network::IPV6_ADDRESS_SIZE_BYTE;
Ratan Guptadcb10672017-07-10 10:33:50 +0530414
415 // ipaddress and gateway would be in IPv4 format
Ratan Guptad70f4532017-08-04 02:07:31 +0530416 inet_pton(addressFamily, ipAddress.c_str(),
Patrick Venture0b02be92018-08-31 11:55:55 -0700417 (respptr->data + IPADDR_OFFSET));
Ratan Guptadcb10672017-07-10 10:33:50 +0530418
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530419 uint8_t prefixOffset = IPADDR_OFFSET + addrSize;
420
421 memcpy(respptr->data + prefixOffset, &prefix, sizeof(prefix));
422
423 uint8_t gatewayOffset = prefixOffset + sizeof(decltype(prefix));
424
Ratan Guptad70f4532017-08-04 02:07:31 +0530425 inet_pton(addressFamily, gateway.c_str(),
Patrick Venture0b02be92018-08-31 11:55:55 -0700426 (respptr->data + gatewayOffset));
Ratan Guptadcb10672017-07-10 10:33:50 +0530427 }
428 catch (InternalFailure& e)
429 {
430 commit<InternalFailure>();
431 memset(respptr->data, 0, SIZE_BOOT_OPTION);
432 rc = -1;
Ratan Guptafd28dd72016-08-01 04:58:01 -0500433 return rc;
434 }
435
Patrick Venture0b02be92018-08-31 11:55:55 -0700436 // PetiBoot-Specific
437 // If success then copy the first 9 bytes to the data
Ratan Guptadcb10672017-07-10 10:33:50 +0530438 memcpy(respptr->data, net_conf_initial_bytes,
439 sizeof(net_conf_initial_bytes));
Ratan Guptafd28dd72016-08-01 04:58:01 -0500440
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530441 memcpy(respptr->data + ADDR_SIZE_OFFSET, &addrSize, sizeof(addrSize));
442
Ratan Guptafd28dd72016-08-01 04:58:01 -0500443#ifdef _IPMI_DEBUG_
Ratan Guptadcb10672017-07-10 10:33:50 +0530444 printf("\n===Printing the IPMI Formatted Data========\n");
Ratan Guptafd28dd72016-08-01 04:58:01 -0500445
Ratan Guptadcb10672017-07-10 10:33:50 +0530446 for (uint8_t pos = 0; pos < index; pos++)
447 {
448 printf("%02x ", respptr->data[pos]);
449 }
Ratan Guptafd28dd72016-08-01 04:58:01 -0500450#endif
451
Ratan Guptafd28dd72016-08-01 04:58:01 -0500452 return rc;
453}
454
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530455/** @brief convert IPv4 and IPv6 addresses from binary to text form.
456 * @param[in] family - IPv4/Ipv6
457 * @param[in] data - req data pointer.
458 * @param[in] offset - offset in the data.
459 * @param[in] addrSize - size of the data which needs to be read from offset.
460 * @returns address in text form.
461 */
462
Patrick Venture0b02be92018-08-31 11:55:55 -0700463std::string getAddrStr(uint8_t family, uint8_t* data, uint8_t offset,
464 uint8_t addrSize)
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530465{
466 char ipAddr[INET6_ADDRSTRLEN] = {};
467
Patrick Venture0b02be92018-08-31 11:55:55 -0700468 switch (family)
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530469 {
470 case AF_INET:
471 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700472 struct sockaddr_in addr4
473 {
474 };
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530475 memcpy(&addr4.sin_addr.s_addr, &data[offset], addrSize);
476
Patrick Venture0b02be92018-08-31 11:55:55 -0700477 inet_ntop(AF_INET, &addr4.sin_addr, ipAddr, INET_ADDRSTRLEN);
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530478
479 break;
480 }
481 case AF_INET6:
482 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700483 struct sockaddr_in6 addr6
484 {
485 };
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530486 memcpy(&addr6.sin6_addr.s6_addr, &data[offset], addrSize);
487
Patrick Venture0b02be92018-08-31 11:55:55 -0700488 inet_ntop(AF_INET6, &addr6.sin6_addr, ipAddr, INET6_ADDRSTRLEN);
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530489
490 break;
491 }
492 default:
493 {
494 return {};
495 }
496 }
497
498 return ipAddr;
499}
500
Ratan Guptadcb10672017-07-10 10:33:50 +0530501int setHostNetworkData(set_sys_boot_options_t* reqptr)
Ratan Guptafd28dd72016-08-01 04:58:01 -0500502{
Ratan Guptadcb10672017-07-10 10:33:50 +0530503 using namespace std::string_literals;
Ratan Guptafd28dd72016-08-01 04:58:01 -0500504 std::string host_network_config;
Patrick Venture0b02be92018-08-31 11:55:55 -0700505 char mac[]{"00:00:00:00:00:00"};
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530506 std::string ipAddress, gateway;
Patrick Venture0b02be92018-08-31 11:55:55 -0700507 char addrOrigin{0};
508 uint8_t addrSize{0};
Ratan Guptadcb10672017-07-10 10:33:50 +0530509 std::string addressOrigin =
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530510 "xyz.openbmc_project.Network.IP.AddressOrigin.DHCP";
Patrick Venture0b02be92018-08-31 11:55:55 -0700511 std::string addressType = "xyz.openbmc_project.Network.IP.Protocol.IPv4";
512 uint8_t prefix{0};
Ratan Guptadcb10672017-07-10 10:33:50 +0530513 uint32_t zeroCookie = 0;
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530514 uint8_t family = AF_INET;
Ratan Guptafd28dd72016-08-01 04:58:01 -0500515
Patrick Venture0b02be92018-08-31 11:55:55 -0700516 // cookie starts from second byte
Ratan Guptafd28dd72016-08-01 04:58:01 -0500517 // version starts from sixth byte
518
Ratan Guptadcb10672017-07-10 10:33:50 +0530519 try
Ratan Guptafd28dd72016-08-01 04:58:01 -0500520 {
Ratan Guptadcb10672017-07-10 10:33:50 +0530521 do
522 {
523 // cookie == 0x21 0x70 0x62 0x21
524 if (memcmp(&(reqptr->data[COOKIE_OFFSET]),
Patrick Venture0b02be92018-08-31 11:55:55 -0700525 (net_conf_initial_bytes + COOKIE_OFFSET),
526 SIZE_COOKIE) != 0)
Ratan Guptadcb10672017-07-10 10:33:50 +0530527 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700528 // cookie == 0
529 if (memcmp(&(reqptr->data[COOKIE_OFFSET]), &zeroCookie,
530 SIZE_COOKIE) == 0)
Ratan Guptadcb10672017-07-10 10:33:50 +0530531 {
532 // need to zero out the network settings.
533 break;
534 }
535
536 log<level::ERR>("Invalid Cookie");
537 elog<InternalFailure>();
538 }
539
540 // vesion == 0x00 0x01
541 if (memcmp(&(reqptr->data[VERSION_OFFSET]),
Patrick Venture0b02be92018-08-31 11:55:55 -0700542 (net_conf_initial_bytes + VERSION_OFFSET),
543 SIZE_VERSION) != 0)
Ratan Guptadcb10672017-07-10 10:33:50 +0530544 {
545
546 log<level::ERR>("Invalid Version");
547 elog<InternalFailure>();
548 }
549
Ratan Gupta8c31d232017-08-13 05:49:43 +0530550 snprintf(mac, SIZE_MAC, ipmi::network::MAC_ADDRESS_FORMAT,
Patrick Venture0b02be92018-08-31 11:55:55 -0700551 reqptr->data[MAC_OFFSET], reqptr->data[MAC_OFFSET + 1],
552 reqptr->data[MAC_OFFSET + 2], reqptr->data[MAC_OFFSET + 3],
Ratan Guptadcb10672017-07-10 10:33:50 +0530553 reqptr->data[MAC_OFFSET + 4],
554 reqptr->data[MAC_OFFSET + 5]);
555
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530556 memcpy(&addrOrigin, &(reqptr->data[ADDRTYPE_OFFSET]),
557 sizeof(decltype(addrOrigin)));
Ratan Guptadcb10672017-07-10 10:33:50 +0530558
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530559 if (addrOrigin)
Ratan Guptadcb10672017-07-10 10:33:50 +0530560 {
561 addressOrigin =
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530562 "xyz.openbmc_project.Network.IP.AddressOrigin.Static";
Ratan Guptadcb10672017-07-10 10:33:50 +0530563 }
564
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530565 // Get the address size
Patrick Venture0b02be92018-08-31 11:55:55 -0700566 memcpy(&addrSize, &reqptr->data[ADDR_SIZE_OFFSET],
567 sizeof(addrSize));
Ratan Guptadcb10672017-07-10 10:33:50 +0530568
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530569 uint8_t prefixOffset = IPADDR_OFFSET + addrSize;
Ratan Guptadcb10672017-07-10 10:33:50 +0530570
Ratan Guptad70f4532017-08-04 02:07:31 +0530571 memcpy(&prefix, &(reqptr->data[prefixOffset]),
572 sizeof(decltype(prefix)));
Ratan Guptadcb10672017-07-10 10:33:50 +0530573
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530574 uint8_t gatewayOffset = prefixOffset + sizeof(decltype(prefix));
575
Ratan Gupta8c31d232017-08-13 05:49:43 +0530576 if (addrSize != ipmi::network::IPV4_ADDRESS_SIZE_BYTE)
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530577 {
578 addressType = "xyz.openbmc_project.Network.IP.Protocol.IPv6";
579 family = AF_INET6;
580 }
581
Patrick Venture0b02be92018-08-31 11:55:55 -0700582 ipAddress =
583 getAddrStr(family, reqptr->data, IPADDR_OFFSET, addrSize);
Ratan Guptad70f4532017-08-04 02:07:31 +0530584
Ratan Gupta6ec7daa2017-07-15 14:13:01 +0530585 gateway = getAddrStr(family, reqptr->data, gatewayOffset, addrSize);
586
Patrick Venture0b02be92018-08-31 11:55:55 -0700587 } while (0);
Ratan Guptadcb10672017-07-10 10:33:50 +0530588
Patrick Venture0b02be92018-08-31 11:55:55 -0700589 // Cookie == 0 or it is a valid cookie
590 host_network_config += "ipaddress="s + ipAddress + ",prefix="s +
591 std::to_string(prefix) + ",gateway="s + gateway +
592 ",mac="s + mac + ",addressOrigin="s +
593 addressOrigin;
Ratan Guptafd28dd72016-08-01 04:58:01 -0500594
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530595 sdbusplus::bus::bus bus(ipmid_get_sd_bus_connection());
596
597 auto ipObjectInfo = ipmi::getDbusObject(bus, IP_INTERFACE,
598 SETTINGS_ROOT, SETTINGS_MATCH);
599 auto macObjectInfo = ipmi::getDbusObject(bus, MAC_INTERFACE,
600 SETTINGS_ROOT, SETTINGS_MATCH);
Ratan Guptadcb10672017-07-10 10:33:50 +0530601 // set the dbus property
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530602 ipmi::setDbusProperty(bus, ipObjectInfo.second, ipObjectInfo.first,
Patrick Venture0b02be92018-08-31 11:55:55 -0700603 IP_INTERFACE, "Address", std::string(ipAddress));
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530604 ipmi::setDbusProperty(bus, ipObjectInfo.second, ipObjectInfo.first,
Patrick Venture0b02be92018-08-31 11:55:55 -0700605 IP_INTERFACE, "PrefixLength", prefix);
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530606 ipmi::setDbusProperty(bus, ipObjectInfo.second, ipObjectInfo.first,
Patrick Venture0b02be92018-08-31 11:55:55 -0700607 IP_INTERFACE, "Origin", addressOrigin);
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530608 ipmi::setDbusProperty(bus, ipObjectInfo.second, ipObjectInfo.first,
Patrick Venture0b02be92018-08-31 11:55:55 -0700609 IP_INTERFACE, "Gateway", std::string(gateway));
610 ipmi::setDbusProperty(
611 bus, ipObjectInfo.second, ipObjectInfo.first, IP_INTERFACE, "Type",
612 std::string("xyz.openbmc_project.Network.IP.Protocol.IPv4"));
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530613 ipmi::setDbusProperty(bus, macObjectInfo.second, macObjectInfo.first,
Patrick Venture0b02be92018-08-31 11:55:55 -0700614 MAC_INTERFACE, "MACAddress", std::string(mac));
Ratan Guptafd28dd72016-08-01 04:58:01 -0500615
Patrick Venture0b02be92018-08-31 11:55:55 -0700616 log<level::DEBUG>(
617 "Network configuration changed",
618 entry("NETWORKCONFIG=%s", host_network_config.c_str()));
Ratan Guptafd28dd72016-08-01 04:58:01 -0500619 }
Ratan Guptadcb10672017-07-10 10:33:50 +0530620 catch (InternalFailure& e)
621 {
622 commit<InternalFailure>();
623 return -1;
624 }
625
626 return 0;
Ratan Guptafd28dd72016-08-01 04:58:01 -0500627}
628
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -0500629uint32_t getPOHCounter()
630{
631 sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
632
Patrick Venture0b02be92018-08-31 11:55:55 -0700633 auto chassisStateObj =
634 ipmi::getDbusObject(bus, chassisPOHStateIntf, chassisStateRoot, match);
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -0500635
Patrick Venture0b02be92018-08-31 11:55:55 -0700636 auto service =
637 ipmi::getService(bus, chassisPOHStateIntf, chassisStateObj.first);
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -0500638
Patrick Venture0b02be92018-08-31 11:55:55 -0700639 auto propValue =
640 ipmi::getDbusProperty(bus, service, chassisStateObj.first,
641 chassisPOHStateIntf, pOHCounterProperty);
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -0500642
643 return propValue.get<uint32_t>();
644}
645
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500646ipmi_ret_t ipmi_chassis_wildcard(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
647 ipmi_request_t request,
648 ipmi_response_t response,
649 ipmi_data_len_t data_len,
650 ipmi_context_t context)
Adriana Kobylak40814c62015-10-27 15:58:44 -0500651{
Adriana Kobylak40814c62015-10-27 15:58:44 -0500652 // Status code.
Nan Li70aa8d92016-08-29 00:11:10 +0800653 ipmi_ret_t rc = IPMI_CC_INVALID;
Adriana Kobylak40814c62015-10-27 15:58:44 -0500654 *data_len = 0;
655 return rc;
656}
657
Nan Li8d15fb42016-08-16 22:29:40 +0800658ipmi_ret_t ipmi_get_chassis_cap(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
Patrick Venture0b02be92018-08-31 11:55:55 -0700659 ipmi_request_t request,
660 ipmi_response_t response,
661 ipmi_data_len_t data_len,
662 ipmi_context_t context)
Nan Li8d15fb42016-08-16 22:29:40 +0800663{
664 // sd_bus error
665 ipmi_ret_t rc = IPMI_CC_OK;
666
667 ipmi_chassis_cap_t chassis_cap{};
668
669 *data_len = sizeof(ipmi_chassis_cap_t);
670
671 // TODO: need future work. Get those flag from MRW.
672
673 // capabilities flags
674 // [7..4] - reserved
675 // [3] – 1b = provides power interlock (IPM 1.5)
676 // [2] – 1b = provides Diagnostic Interrupt (FP NMI)
Patrick Venture0b02be92018-08-31 11:55:55 -0700677 // [1] – 1b = provides “Front Panel Lockout” (indicates that the chassis has
678 // capabilities
679 // to lock out external power control and reset button or front
680 // panel interfaces and/or detect tampering with those
681 // interfaces).
Nan Li8d15fb42016-08-16 22:29:40 +0800682 // [0] -1b = Chassis provides intrusion (physical security) sensor.
683 // set to default value 0x0.
684 chassis_cap.cap_flags = 0x0;
685
686 // Since we do not have a separate SDR Device/SEL Device/ FRU repository.
687 // The 20h was given as those 5 device addresses.
688 // Chassis FRU info Device Address
689 chassis_cap.fru_info_dev_addr = 0x20;
690
691 // Chassis SDR Device Address
692 chassis_cap.sdr_dev_addr = 0x20;
693
694 // Chassis SEL Device Address
695 chassis_cap.sel_dev_addr = 0x20;
696
697 // Chassis System Management Device Address
698 chassis_cap.system_management_dev_addr = 0x20;
699
700 // Chassis Bridge Device Address.
701 chassis_cap.bridge_dev_addr = 0x20;
702
703 memcpy(response, &chassis_cap, *data_len);
704
705 return rc;
706}
707
Vishwanatha Subbannab12b0c02017-03-07 18:17:19 +0530708//------------------------------------------
709// Calls into Host State Manager Dbus object
710//------------------------------------------
711int initiate_state_transition(State::Host::Transition transition)
vishwa36993272015-11-20 12:43:49 -0600712{
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500713 // OpenBMC Host State Manager dbus framework
Patrick Venture0b02be92018-08-31 11:55:55 -0700714 constexpr auto HOST_STATE_MANAGER_ROOT = "/xyz/openbmc_project/state/host0";
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500715 constexpr auto HOST_STATE_MANAGER_IFACE = "xyz.openbmc_project.State.Host";
Patrick Venture0b02be92018-08-31 11:55:55 -0700716 constexpr auto DBUS_PROPERTY_IFACE = "org.freedesktop.DBus.Properties";
717 constexpr auto PROPERTY = "RequestedHostTransition";
Vishwanatha Subbannab12b0c02017-03-07 18:17:19 +0530718
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500719 // sd_bus error
720 int rc = 0;
Patrick Venture0b02be92018-08-31 11:55:55 -0700721 char* busname = NULL;
vishwa36993272015-11-20 12:43:49 -0600722
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500723 // SD Bus error report mechanism.
724 sd_bus_error bus_error = SD_BUS_ERROR_NULL;
vishwa36993272015-11-20 12:43:49 -0600725
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500726 // Gets a hook onto either a SYSTEM or SESSION bus
Patrick Venture0b02be92018-08-31 11:55:55 -0700727 sd_bus* bus_type = ipmid_get_sd_bus_connection();
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500728 rc = mapper_get_service(bus_type, HOST_STATE_MANAGER_ROOT, &busname);
729 if (rc < 0)
730 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700731 log<level::ERR>(
732 "Failed to get bus name",
733 entry("ERRNO=0x%X, OBJPATH=%s", -rc, HOST_STATE_MANAGER_ROOT));
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500734 return rc;
735 }
Vishwanatha Subbannab12b0c02017-03-07 18:17:19 +0530736
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500737 // Convert to string equivalent of the passed in transition enum.
738 auto request = State::convertForMessage(transition);
Vishwanatha Subbannab12b0c02017-03-07 18:17:19 +0530739
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500740 rc = sd_bus_call_method(bus_type, // On the system bus
741 busname, // Service to contact
742 HOST_STATE_MANAGER_ROOT, // Object path
743 DBUS_PROPERTY_IFACE, // Interface name
744 "Set", // Method to be called
745 &bus_error, // object to return error
746 nullptr, // Response buffer if any
747 "ssv", // Takes 3 arguments
Patrick Venture0b02be92018-08-31 11:55:55 -0700748 HOST_STATE_MANAGER_IFACE, PROPERTY, "s",
749 request.c_str());
750 if (rc < 0)
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500751 {
752 log<level::ERR>("Failed to initiate transition",
Aditya Saripalli5fb14602017-11-09 14:46:27 +0530753 entry("ERRNO=0x%X, REQUEST=%s", -rc, request.c_str()));
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500754 }
755 else
756 {
757 log<level::INFO>("Transition request initiated successfully");
758 }
vishwa36993272015-11-20 12:43:49 -0600759
760 sd_bus_error_free(&bus_error);
Sergey Solomineb9b8142016-08-23 09:07:28 -0500761 free(busname);
vishwa36993272015-11-20 12:43:49 -0600762
Sergey Solomineb9b8142016-08-23 09:07:28 -0500763 return rc;
vishwa36993272015-11-20 12:43:49 -0600764}
765
Deepak Kodihalli18b70d12017-07-21 13:36:33 -0500766namespace power_policy
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500767{
Nan Lifdd8ec52016-08-28 03:57:40 +0800768
Deepak Kodihalli18b70d12017-07-21 13:36:33 -0500769using namespace sdbusplus::xyz::openbmc_project::Control::Power::server;
770using IpmiValue = uint8_t;
771using DbusValue = RestorePolicy::Policy;
Nan Lifdd8ec52016-08-28 03:57:40 +0800772
Patrick Venture0b02be92018-08-31 11:55:55 -0700773std::map<DbusValue, IpmiValue> dbusToIpmi = {
Deepak Kodihalli18b70d12017-07-21 13:36:33 -0500774 {RestorePolicy::Policy::AlwaysOff, 0x00},
775 {RestorePolicy::Policy::Restore, 0x01},
Patrick Venture0b02be92018-08-31 11:55:55 -0700776 {RestorePolicy::Policy::AlwaysOn, 0x02}};
Nan Lifdd8ec52016-08-28 03:57:40 +0800777
Deepak Kodihalli18b70d12017-07-21 13:36:33 -0500778} // namespace power_policy
Nan Lifdd8ec52016-08-28 03:57:40 +0800779
780//----------------------------------------------------------------------
781// Get Chassis Status commands
782//----------------------------------------------------------------------
783ipmi_ret_t ipmi_get_chassis_status(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500784 ipmi_request_t request,
785 ipmi_response_t response,
786 ipmi_data_len_t data_len,
787 ipmi_context_t context)
Nan Lifdd8ec52016-08-28 03:57:40 +0800788{
Patrick Venture0b02be92018-08-31 11:55:55 -0700789 const char* objname = "/org/openbmc/control/power0";
790 const char* intf = "org.openbmc.control.Power";
Nan Lifdd8ec52016-08-28 03:57:40 +0800791
Patrick Venture0b02be92018-08-31 11:55:55 -0700792 sd_bus* bus = NULL;
793 sd_bus_message* reply = NULL;
Nan Lifdd8ec52016-08-28 03:57:40 +0800794 int r = 0;
795 int pgood = 0;
Patrick Venture0b02be92018-08-31 11:55:55 -0700796 char* busname = NULL;
Nan Lifdd8ec52016-08-28 03:57:40 +0800797 ipmi_ret_t rc = IPMI_CC_OK;
798 ipmi_get_chassis_status_t chassis_status{};
799
Nan Lifdd8ec52016-08-28 03:57:40 +0800800 uint8_t s = 0;
801
Deepak Kodihalli18b70d12017-07-21 13:36:33 -0500802 using namespace chassis::internal;
803 using namespace chassis::internal::cache;
804 using namespace power_policy;
805
Deepak Kodihallie6027092017-08-27 08:13:37 -0500806 const auto& powerRestoreSetting = objects.map.at(powerRestoreIntf).front();
Patrick Venture0b02be92018-08-31 11:55:55 -0700807 auto method = dbus.new_method_call(
808 objects.service(powerRestoreSetting, powerRestoreIntf).c_str(),
809 powerRestoreSetting.c_str(), ipmi::PROP_INTF, "Get");
Deepak Kodihalli18b70d12017-07-21 13:36:33 -0500810 method.append(powerRestoreIntf, "PowerRestorePolicy");
811 auto resp = dbus.call(method);
812 if (resp.is_method_error())
813 {
814 log<level::ERR>("Error in PowerRestorePolicy Get");
815 report<InternalFailure>();
816 *data_len = 0;
817 return IPMI_CC_UNSPECIFIED_ERROR;
818 }
819 sdbusplus::message::variant<std::string> result;
820 resp.read(result);
821 auto powerRestore =
822 RestorePolicy::convertPolicyFromString(result.get<std::string>());
Nan Lifdd8ec52016-08-28 03:57:40 +0800823
824 *data_len = 4;
825
Tom Joseph63a00512017-08-09 23:39:59 +0530826 bus = ipmid_get_sd_bus_connection();
827
Nan Lifdd8ec52016-08-28 03:57:40 +0800828 r = mapper_get_service(bus, objname, &busname);
Patrick Venture0b02be92018-08-31 11:55:55 -0700829 if (r < 0)
830 {
831 log<level::ERR>("Failed to get bus name", entry("ERRNO=0x%X", -r));
Nan Lifdd8ec52016-08-28 03:57:40 +0800832 rc = IPMI_CC_UNSPECIFIED_ERROR;
833 goto finish;
834 }
835
Patrick Venture0b02be92018-08-31 11:55:55 -0700836 r = sd_bus_get_property(bus, busname, objname, intf, "pgood", NULL, &reply,
837 "i");
838 if (r < 0)
839 {
Aditya Saripalli5fb14602017-11-09 14:46:27 +0530840 log<level::ERR>("Failed to call sd_bus_get_property",
Patrick Venture0b02be92018-08-31 11:55:55 -0700841 entry("PROPERTY=%s", "pgood"), entry("ERRNO=0x%X", -r),
842 entry("BUS=%s", busname), entry("PATH=%s", objname),
Aditya Saripalli5fb14602017-11-09 14:46:27 +0530843 entry("INTERFACE=%s", intf));
Nan Lifdd8ec52016-08-28 03:57:40 +0800844 rc = IPMI_CC_UNSPECIFIED_ERROR;
845 goto finish;
846 }
847
848 r = sd_bus_message_read(reply, "i", &pgood);
Patrick Venture0b02be92018-08-31 11:55:55 -0700849 if (r < 0)
850 {
851 log<level::ERR>("Failed to read sensor:", entry("ERRNO=0x%X", -r));
Nan Lifdd8ec52016-08-28 03:57:40 +0800852 rc = IPMI_CC_UNSPECIFIED_ERROR;
853 goto finish;
854 }
855
Deepak Kodihalli18b70d12017-07-21 13:36:33 -0500856 s = dbusToIpmi.at(powerRestore);
Nan Lifdd8ec52016-08-28 03:57:40 +0800857
858 // Current Power State
859 // [7] reserved
860 // [6..5] power restore policy
861 // 00b = chassis stays powered off after AC/mains returns
862 // 01b = after AC returns, power is restored to the state that was
863 // in effect when AC/mains was lost.
864 // 10b = chassis always powers up after AC/mains returns
865 // 11b = unknow
866 // Set to 00b, by observing the hardware behavior.
Patrick Venture0b02be92018-08-31 11:55:55 -0700867 // Do we need to define a dbus property to identify the restore
868 // policy?
Nan Lifdd8ec52016-08-28 03:57:40 +0800869
870 // [4] power control fault
871 // 1b = controller attempted to turn system power on or off, but
872 // system did not enter desired state.
873 // Set to 0b, since We don't support it..
874
875 // [3] power fault
876 // 1b = fault detected in main power subsystem.
877 // set to 0b. for we don't support it.
878
879 // [2] 1b = interlock (chassis is presently shut down because a chassis
880 // panel interlock switch is active). (IPMI 1.5)
881 // set to 0b, for we don't support it.
882
883 // [1] power overload
884 // 1b = system shutdown because of power overload condition.
885 // set to 0b, for we don't support it.
886
887 // [0] power is on
888 // 1b = system power is on
889 // 0b = system power is off(soft-off S4/S5, or mechanical off)
890
Patrick Venture0b02be92018-08-31 11:55:55 -0700891 chassis_status.cur_power_state = ((s & 0x3) << 5) | (pgood & 0x1);
Nan Lifdd8ec52016-08-28 03:57:40 +0800892
893 // Last Power Event
894 // [7..5] – reserved
895 // [4] – 1b = last ‘Power is on’ state was entered via IPMI command
896 // [3] – 1b = last power down caused by power fault
897 // [2] – 1b = last power down caused by a power interlock being activated
898 // [1] – 1b = last power down caused by a Power overload
899 // [0] – 1b = AC failed
900 // set to 0x0, for we don't support these fields.
901
902 chassis_status.last_power_event = 0;
903
904 // Misc. Chassis State
905 // [7] – reserved
906 // [6] – 1b = Chassis Identify command and state info supported (Optional)
907 // 0b = Chassis Identify command support unspecified via this command.
908 // (The Get Command Support command , if implemented, would still
909 // indicate support for the Chassis Identify command)
Patrick Venture0b02be92018-08-31 11:55:55 -0700910 // [5..4] – Chassis Identify State. Mandatory when bit[6] =1b, reserved
911 // (return
Nan Lifdd8ec52016-08-28 03:57:40 +0800912 // as 00b) otherwise. Returns the present chassis identify state.
913 // Refer to the Chassis Identify command for more info.
914 // 00b = chassis identify state = Off
915 // 01b = chassis identify state = Temporary(timed) On
916 // 10b = chassis identify state = Indefinite On
917 // 11b = reserved
918 // [3] – 1b = Cooling/fan fault detected
919 // [2] – 1b = Drive Fault
920 // [1] – 1b = Front Panel Lockout active (power off and reset via chassis
921 // push-buttons disabled.)
922 // [0] – 1b = Chassis Intrusion active
923 // set to 0, for we don't support them.
924 chassis_status.misc_power_state = 0;
925
926 // Front Panel Button Capabilities and disable/enable status(Optional)
927 // set to 0, for we don't support them.
928 chassis_status.front_panel_button_cap_status = 0;
929
930 // Pack the actual response
931 memcpy(response, &chassis_status, *data_len);
932
933finish:
934 free(busname);
935 reply = sd_bus_message_unref(reply);
936
937 return rc;
938}
Chris Austen7888c4d2015-12-03 15:26:20 -0600939
Vishwanatha Subbanna83b5c1c2017-01-25 18:41:51 +0530940//-------------------------------------------------------------
941// Send a command to SoftPowerOff application to stop any timer
942//-------------------------------------------------------------
943int stop_soft_off_timer()
944{
Patrick Venture0b02be92018-08-31 11:55:55 -0700945 constexpr auto iface = "org.freedesktop.DBus.Properties";
946 constexpr auto soft_off_iface = "xyz.openbmc_project.Ipmi.Internal."
947 "SoftPowerOff";
Vishwanatha Subbanna83b5c1c2017-01-25 18:41:51 +0530948
Patrick Venture0b02be92018-08-31 11:55:55 -0700949 constexpr auto property = "ResponseReceived";
950 constexpr auto value = "xyz.openbmc_project.Ipmi.Internal."
951 "SoftPowerOff.HostResponse.HostShutdown";
Vishwanatha Subbanna83b5c1c2017-01-25 18:41:51 +0530952
953 // Get the system bus where most system services are provided.
954 auto bus = ipmid_get_sd_bus_connection();
955
956 // Get the service name
Andrew Geissler2b4e4592017-06-08 11:18:35 -0500957 // TODO openbmc/openbmc#1661 - Mapper refactor
958 //
959 // See openbmc/openbmc#1743 for some details but high level summary is that
960 // for now the code will directly call the soft off interface due to a
961 // race condition with mapper usage
962 //
Patrick Venture0b02be92018-08-31 11:55:55 -0700963 // char *busname = nullptr;
964 // auto r = mapper_get_service(bus, SOFTOFF_OBJPATH, &busname);
965 // if (r < 0)
Andrew Geissler2b4e4592017-06-08 11:18:35 -0500966 //{
967 // fprintf(stderr, "Failed to get %s bus name: %s\n",
Aditya Saripalli5fb14602017-11-09 14:46:27 +0530968 // SOFTOFF_OBJPATH, -r);
Andrew Geissler2b4e4592017-06-08 11:18:35 -0500969 // return r;
970 //}
Vishwanatha Subbanna83b5c1c2017-01-25 18:41:51 +0530971
972 // No error object or reply expected.
Andrew Geissler2b4e4592017-06-08 11:18:35 -0500973 int rc = sd_bus_call_method(bus, SOFTOFF_BUSNAME, SOFTOFF_OBJPATH, iface,
Patrick Venture0b02be92018-08-31 11:55:55 -0700974 "Set", nullptr, nullptr, "ssv", soft_off_iface,
975 property, "s", value);
Vishwanatha Subbanna83b5c1c2017-01-25 18:41:51 +0530976 if (rc < 0)
977 {
Aditya Saripalli5fb14602017-11-09 14:46:27 +0530978 log<level::ERR>("Failed to set property in SoftPowerOff object",
979 entry("ERRNO=0x%X", -rc));
Vishwanatha Subbanna83b5c1c2017-01-25 18:41:51 +0530980 }
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -0500981
Patrick Venture0b02be92018-08-31 11:55:55 -0700982 // TODO openbmc/openbmc#1661 - Mapper refactor
983 // free(busname);
Vishwanatha Subbanna83b5c1c2017-01-25 18:41:51 +0530984 return rc;
985}
986
vishwa36993272015-11-20 12:43:49 -0600987//----------------------------------------------------------------------
Andrew Geisslera6e3a302017-05-31 19:34:00 -0500988// Create file to indicate there is no need for softoff notification to host
989//----------------------------------------------------------------------
990void indicate_no_softoff_needed()
991{
992 fs::path path{HOST_INBAND_REQUEST_DIR};
993 if (!fs::is_directory(path))
994 {
995 fs::create_directory(path);
996 }
997
998 // Add the host instance (default 0 for now) to the file name
999 std::string file{HOST_INBAND_REQUEST_FILE};
Patrick Venture0b02be92018-08-31 11:55:55 -07001000 auto size = std::snprintf(nullptr, 0, file.c_str(), 0);
Andrew Geisslera6e3a302017-05-31 19:34:00 -05001001 size++; // null
1002 std::unique_ptr<char[]> buf(new char[size]);
Patrick Venture0b02be92018-08-31 11:55:55 -07001003 std::snprintf(buf.get(), size, file.c_str(), 0);
Andrew Geisslera6e3a302017-05-31 19:34:00 -05001004
1005 // Append file name to directory and create it
1006 path /= buf.get();
1007 std::ofstream(path.c_str());
1008}
1009
1010//----------------------------------------------------------------------
vishwa36993272015-11-20 12:43:49 -06001011// Chassis Control commands
1012//----------------------------------------------------------------------
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001013ipmi_ret_t ipmi_chassis_control(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
1014 ipmi_request_t request,
1015 ipmi_response_t response,
1016 ipmi_data_len_t data_len,
1017 ipmi_context_t context)
vishwa36993272015-11-20 12:43:49 -06001018{
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001019 // Error from power off.
1020 int rc = 0;
vishwa36993272015-11-20 12:43:49 -06001021
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001022 // No response for this command.
vishwa36993272015-11-20 12:43:49 -06001023 *data_len = 0;
1024
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001025 // Catch the actual operaton by peeking into request buffer
Patrick Venture0b02be92018-08-31 11:55:55 -07001026 uint8_t chassis_ctrl_cmd = *(uint8_t*)request;
vishwa36993272015-11-20 12:43:49 -06001027
Patrick Venture0b02be92018-08-31 11:55:55 -07001028 switch (chassis_ctrl_cmd)
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001029 {
1030 case CMD_POWER_ON:
1031 rc = initiate_state_transition(State::Host::Transition::On);
1032 break;
1033 case CMD_POWER_OFF:
Vishwanatha Subbanna8b26d352017-08-04 18:35:18 +05301034 // This path would be hit in 2 conditions.
1035 // 1: When user asks for power off using ipmi chassis command 0x04
1036 // 2: Host asking for power off post shutting down.
1037
1038 // If it's a host requested power off, then need to nudge Softoff
1039 // application that it needs to stop the watchdog timer if running.
1040 // If it is a user requested power off, then this is not really
1041 // needed. But then we need to differentiate between user and host
1042 // calling this same command
1043
1044 // For now, we are going ahead with trying to nudge the soft off and
1045 // interpret the failure to do so as a non softoff case
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001046 rc = stop_soft_off_timer();
Vishwanatha Subbanna8b26d352017-08-04 18:35:18 +05301047
Andrew Geisslera6e3a302017-05-31 19:34:00 -05001048 // Only request the Off transition if the soft power off
1049 // application is not running
1050 if (rc < 0)
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001051 {
Andrew Geisslera6e3a302017-05-31 19:34:00 -05001052 // First create a file to indicate to the soft off application
Vishwanatha Subbanna8b26d352017-08-04 18:35:18 +05301053 // that it should not run. Not doing this will result in State
1054 // manager doing a default soft power off when asked for power
1055 // off.
Andrew Geisslera6e3a302017-05-31 19:34:00 -05001056 indicate_no_softoff_needed();
1057
1058 // Now request the shutdown
1059 rc = initiate_state_transition(State::Host::Transition::Off);
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001060 }
Andrew Geisslera6e3a302017-05-31 19:34:00 -05001061 else
1062 {
Vishwanatha Subbanna8b26d352017-08-04 18:35:18 +05301063 log<level::INFO>("Soft off is running, so let shutdown target "
1064 "stop the host");
Andrew Geisslera6e3a302017-05-31 19:34:00 -05001065 }
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001066 break;
Vishwanatha Subbanna83b5c1c2017-01-25 18:41:51 +05301067
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001068 case CMD_HARD_RESET:
1069 case CMD_POWER_CYCLE:
1070 // SPEC has a section that says certain implementations can trigger
1071 // PowerOn if power is Off when a command to power cycle is
1072 // requested
Andrew Geisslera6e3a302017-05-31 19:34:00 -05001073
1074 // First create a file to indicate to the soft off application
1075 // that it should not run since this is a direct user initiated
1076 // power reboot request (i.e. a reboot request that is not
1077 // originating via a soft power off SMS request)
1078 indicate_no_softoff_needed();
1079
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001080 rc = initiate_state_transition(State::Host::Transition::Reboot);
1081 break;
Vishwanatha Subbanna8b26d352017-08-04 18:35:18 +05301082
1083 case CMD_SOFT_OFF_VIA_OVER_TEMP:
1084 // Request Host State Manager to do a soft power off
1085 rc = initiate_state_transition(State::Host::Transition::Off);
1086 break;
1087
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001088 default:
1089 {
Aditya Saripalli5fb14602017-11-09 14:46:27 +05301090 log<level::ERR>("Invalid Chassis Control command",
1091 entry("CMD=0x%X", chassis_ctrl_cmd));
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001092 rc = -1;
1093 }
1094 }
vishwa36993272015-11-20 12:43:49 -06001095
Patrick Venture0b02be92018-08-31 11:55:55 -07001096 return ((rc < 0) ? IPMI_CC_INVALID : IPMI_CC_OK);
vishwa36993272015-11-20 12:43:49 -06001097}
1098
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001099/** @brief Return D-Bus connection string to enclosure identify LED object
1100 *
1101 * @param[in, out] connection - connection to D-Bus object
1102 * @return a IPMI return code
1103 */
1104std::string getEnclosureIdentifyConnection()
Tom Joseph5110c122018-03-23 17:55:40 +05301105{
Tom Joseph5110c122018-03-23 17:55:40 +05301106 // lookup enclosure_identify group owner(s) in mapper
1107 auto mapperCall = chassis::internal::dbus.new_method_call(
Patrick Venture0b02be92018-08-31 11:55:55 -07001108 ipmi::MAPPER_BUS_NAME, ipmi::MAPPER_OBJ, ipmi::MAPPER_INTF,
1109 "GetObject");
Tom Joseph5110c122018-03-23 17:55:40 +05301110
1111 mapperCall.append(identify_led_object_name);
Patrick Venture0b02be92018-08-31 11:55:55 -07001112 static const std::vector<std::string> interfaces = {
1113 "xyz.openbmc_project.Led.Group"};
Tom Joseph5110c122018-03-23 17:55:40 +05301114 mapperCall.append(interfaces);
1115 auto mapperReply = chassis::internal::dbus.call(mapperCall);
1116 if (mapperReply.is_method_error())
1117 {
1118 log<level::ERR>("Chassis Identify: Error communicating to mapper.");
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001119 elog<InternalFailure>();
Tom Joseph5110c122018-03-23 17:55:40 +05301120 }
1121 std::vector<std::pair<std::string, std::vector<std::string>>> mapperResp;
1122 mapperReply.read(mapperResp);
1123
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001124 if (mapperResp.size() != encIdentifyObjectsSize)
Tom Joseph5110c122018-03-23 17:55:40 +05301125 {
Patrick Venture0b02be92018-08-31 11:55:55 -07001126 log<level::ERR>(
1127 "Invalid number of enclosure identify objects.",
1128 entry("ENC_IDENTITY_OBJECTS_SIZE=%d", mapperResp.size()));
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001129 elog<InternalFailure>();
1130 }
1131 auto pair = mapperResp[encIdentifyObjectsSize - 1];
1132 return pair.first;
1133}
Tom Joseph5110c122018-03-23 17:55:40 +05301134
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001135/** @brief Turn On/Off enclosure identify LED
1136 *
1137 * @param[in] flag - true to turn on LED, false to turn off
1138 * @return a IPMI return code
1139 */
1140void enclosureIdentifyLed(bool flag)
1141{
1142 using namespace chassis::internal;
1143 std::string connection = std::move(getEnclosureIdentifyConnection());
Patrick Venture0b02be92018-08-31 11:55:55 -07001144 auto led =
1145 dbus.new_method_call(connection.c_str(), identify_led_object_name,
1146 "org.freedesktop.DBus.Properties", "Set");
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001147 led.append("xyz.openbmc_project.Led.Group", "Asserted",
Patrick Venture0b02be92018-08-31 11:55:55 -07001148 sdbusplus::message::variant<bool>(flag));
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001149 auto ledReply = dbus.call(led);
1150 if (ledReply.is_method_error())
1151 {
1152 log<level::ERR>("Chassis Identify: Error Setting State On/Off\n",
Patrick Venture0b02be92018-08-31 11:55:55 -07001153 entry("LED_STATE=%d", flag));
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001154 elog<InternalFailure>();
1155 }
1156}
1157
1158/** @brief Callback method to turn off LED
1159 */
1160void enclosureIdentifyLedOff()
1161{
1162 try
1163 {
1164 enclosureIdentifyLed(false);
1165 }
1166 catch (const InternalFailure& e)
1167 {
1168 report<InternalFailure>();
1169 }
1170}
1171
1172/** @brief Create timer to turn on and off the enclosure LED
1173 */
1174void createIdentifyTimer()
1175{
1176 if (!identifyTimer)
1177 {
1178 identifyTimer = std::make_unique<phosphor::ipmi::Timer>(
1179 ipmid_get_sd_event_connection(), enclosureIdentifyLedOff);
1180 }
1181}
1182
1183ipmi_ret_t ipmi_chassis_identify(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
1184 ipmi_request_t request,
1185 ipmi_response_t response,
1186 ipmi_data_len_t data_len,
1187 ipmi_context_t context)
1188{
1189 if (*data_len > chassisIdentifyReqLength)
1190 {
1191 return IPMI_CC_REQ_DATA_LEN_INVALID;
1192 }
Patrick Venture0b02be92018-08-31 11:55:55 -07001193 uint8_t identifyInterval =
1194 *data_len > identifyIntervalPos
1195 ? (static_cast<uint8_t*>(request))[identifyIntervalPos]
1196 : DEFAULT_IDENTIFY_TIME_OUT;
1197 bool forceIdentify =
1198 (*data_len == chassisIdentifyReqLength)
1199 ? (static_cast<uint8_t*>(request))[forceIdentifyPos] & 0x01
1200 : false;
Tom Josephbed26992018-07-31 23:00:24 +05301201
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001202 if (identifyInterval || forceIdentify)
1203 {
1204 // stop the timer if already started, for force identify we should
1205 // not turn off LED
1206 identifyTimer->setTimer(SD_EVENT_OFF);
1207 try
Tom Joseph5110c122018-03-23 17:55:40 +05301208 {
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001209 enclosureIdentifyLed(true);
1210 }
1211 catch (const InternalFailure& e)
1212 {
1213 report<InternalFailure>();
1214 return IPMI_CC_RESPONSE_ERROR;
Tom Joseph5110c122018-03-23 17:55:40 +05301215 }
1216
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001217 if (forceIdentify)
Tom Joseph5110c122018-03-23 17:55:40 +05301218 {
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001219 return IPMI_CC_OK;
1220 }
1221 // start the timer
1222 auto time = std::chrono::duration_cast<std::chrono::microseconds>(
Patrick Venture0b02be92018-08-31 11:55:55 -07001223 std::chrono::seconds(identifyInterval));
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001224 identifyTimer->startTimer(time);
Tom Joseph5110c122018-03-23 17:55:40 +05301225 }
Tom Josephbed26992018-07-31 23:00:24 +05301226 else if (!identifyInterval)
1227 {
1228 identifyTimer->setTimer(SD_EVENT_OFF);
1229 enclosureIdentifyLedOff();
1230 }
Tom Joseph5110c122018-03-23 17:55:40 +05301231 return IPMI_CC_OK;
1232}
1233
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001234namespace boot_options
1235{
1236
1237using namespace sdbusplus::xyz::openbmc_project::Control::Boot::server;
1238using IpmiValue = uint8_t;
1239constexpr auto ipmiDefault = 0;
1240
Patrick Venture0b02be92018-08-31 11:55:55 -07001241std::map<IpmiValue, Source::Sources> sourceIpmiToDbus = {
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001242 {0x01, Source::Sources::Network},
1243 {0x02, Source::Sources::Disk},
1244 {0x05, Source::Sources::ExternalMedia},
Patrick Venture0b02be92018-08-31 11:55:55 -07001245 {ipmiDefault, Source::Sources::Default}};
shgoupfd84fbbf2015-12-17 10:05:51 +08001246
Patrick Venture0b02be92018-08-31 11:55:55 -07001247std::map<IpmiValue, Mode::Modes> modeIpmiToDbus = {
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001248 {0x03, Mode::Modes::Safe},
1249 {0x06, Mode::Modes::Setup},
Patrick Venture0b02be92018-08-31 11:55:55 -07001250 {ipmiDefault, Mode::Modes::Regular}};
shgoupfd84fbbf2015-12-17 10:05:51 +08001251
Patrick Venture0b02be92018-08-31 11:55:55 -07001252std::map<Source::Sources, IpmiValue> sourceDbusToIpmi = {
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001253 {Source::Sources::Network, 0x01},
1254 {Source::Sources::Disk, 0x02},
1255 {Source::Sources::ExternalMedia, 0x05},
Patrick Venture0b02be92018-08-31 11:55:55 -07001256 {Source::Sources::Default, ipmiDefault}};
shgoupfd84fbbf2015-12-17 10:05:51 +08001257
Patrick Venture0b02be92018-08-31 11:55:55 -07001258std::map<Mode::Modes, IpmiValue> modeDbusToIpmi = {
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001259 {Mode::Modes::Safe, 0x03},
1260 {Mode::Modes::Setup, 0x06},
Patrick Venture0b02be92018-08-31 11:55:55 -07001261 {Mode::Modes::Regular, ipmiDefault}};
shgoupfd84fbbf2015-12-17 10:05:51 +08001262
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001263} // namespace boot_options
shgoupfd84fbbf2015-12-17 10:05:51 +08001264
Marri Devender Rao81719702018-05-07 00:53:48 -05001265/** @brief Set the property value for boot source
1266 * @param[in] source - boot source value
1267 * @return On failure return IPMI error.
1268 */
1269static ipmi_ret_t setBootSource(const Source::Sources& source)
1270{
1271 using namespace chassis::internal;
1272 using namespace chassis::internal::cache;
1273 sdbusplus::message::variant<std::string> property =
1274 convertForMessage(source);
1275 auto bootSetting = settings::boot::setting(objects, bootSourceIntf);
1276 const auto& bootSourceSetting = std::get<settings::Path>(bootSetting);
Patrick Venture0b02be92018-08-31 11:55:55 -07001277 auto method = dbus.new_method_call(
1278 objects.service(bootSourceSetting, bootSourceIntf).c_str(),
1279 bootSourceSetting.c_str(), ipmi::PROP_INTF, "Set");
Marri Devender Rao81719702018-05-07 00:53:48 -05001280 method.append(bootSourceIntf, "BootSource", property);
1281 auto reply = dbus.call(method);
1282 if (reply.is_method_error())
1283 {
1284 log<level::ERR>("Error in BootSource Set");
1285 report<InternalFailure>();
1286 return IPMI_CC_UNSPECIFIED_ERROR;
1287 }
1288 return IPMI_CC_OK;
1289}
1290
Patrick Venture0b02be92018-08-31 11:55:55 -07001291/** @brief Set the property value for boot mode
Marri Devender Rao81719702018-05-07 00:53:48 -05001292 * @param[in] mode - boot mode value
1293 * @return On failure return IPMI error.
1294 */
1295static ipmi_ret_t setBootMode(const Mode::Modes& mode)
1296{
1297 using namespace chassis::internal;
1298 using namespace chassis::internal::cache;
Patrick Venture0b02be92018-08-31 11:55:55 -07001299 sdbusplus::message::variant<std::string> property = convertForMessage(mode);
Marri Devender Rao81719702018-05-07 00:53:48 -05001300 auto bootSetting = settings::boot::setting(objects, bootModeIntf);
1301 const auto& bootModeSetting = std::get<settings::Path>(bootSetting);
Patrick Venture0b02be92018-08-31 11:55:55 -07001302 auto method = dbus.new_method_call(
1303 objects.service(bootModeSetting, bootModeIntf).c_str(),
1304 bootModeSetting.c_str(), ipmi::PROP_INTF, "Set");
Marri Devender Rao81719702018-05-07 00:53:48 -05001305 method.append(bootModeIntf, "BootMode", property);
1306 auto reply = dbus.call(method);
1307 if (reply.is_method_error())
1308 {
1309 log<level::ERR>("Error in BootMode Set");
1310 report<InternalFailure>();
1311 return IPMI_CC_UNSPECIFIED_ERROR;
1312 }
1313 return IPMI_CC_OK;
1314}
1315
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001316ipmi_ret_t ipmi_chassis_get_sys_boot_options(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
1317 ipmi_request_t request,
1318 ipmi_response_t response,
1319 ipmi_data_len_t data_len,
1320 ipmi_context_t context)
Adriana Kobylak40814c62015-10-27 15:58:44 -05001321{
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001322 using namespace boot_options;
shgoupfd84fbbf2015-12-17 10:05:51 +08001323 ipmi_ret_t rc = IPMI_CC_PARM_NOT_SUPPORTED;
Patrick Venture0b02be92018-08-31 11:55:55 -07001324 char* p = NULL;
1325 get_sys_boot_options_response_t* resp =
1326 (get_sys_boot_options_response_t*)response;
1327 get_sys_boot_options_t* reqptr = (get_sys_boot_options_t*)request;
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001328 IpmiValue bootOption = ipmiDefault;
Adriana Kobylak40814c62015-10-27 15:58:44 -05001329
Patrick Venture0b02be92018-08-31 11:55:55 -07001330 memset(resp, 0, sizeof(*resp));
1331 resp->version = SET_PARM_VERSION;
1332 resp->parm = 5;
1333 resp->data[0] = SET_PARM_BOOT_FLAGS_VALID_ONE_TIME;
Adriana Kobylak40814c62015-10-27 15:58:44 -05001334
shgoupfd84fbbf2015-12-17 10:05:51 +08001335 /*
1336 * Parameter #5 means boot flags. Please refer to 28.13 of ipmi doc.
1337 * This is the only parameter used by petitboot.
1338 */
Patrick Venture0b02be92018-08-31 11:55:55 -07001339 if (reqptr->parameter ==
1340 static_cast<uint8_t>(BootOptionParameter::BOOT_FLAGS))
1341 {
shgoupfd84fbbf2015-12-17 10:05:51 +08001342
Ratan Guptafd28dd72016-08-01 04:58:01 -05001343 *data_len = static_cast<uint8_t>(BootOptionResponseSize::BOOT_FLAGS);
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001344 using namespace chassis::internal;
1345 using namespace chassis::internal::cache;
shgoupfd84fbbf2015-12-17 10:05:51 +08001346
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001347 try
ratagupta6f6bff2016-04-04 06:20:11 -05001348 {
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001349 auto bootSetting = settings::boot::setting(objects, bootSourceIntf);
1350 const auto& bootSourceSetting =
1351 std::get<settings::Path>(bootSetting);
1352 auto oneTimeEnabled =
1353 std::get<settings::boot::OneTimeEnabled>(bootSetting);
Patrick Venture0b02be92018-08-31 11:55:55 -07001354 auto method = dbus.new_method_call(
1355 objects.service(bootSourceSetting, bootSourceIntf).c_str(),
1356 bootSourceSetting.c_str(), ipmi::PROP_INTF, "Get");
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001357 method.append(bootSourceIntf, "BootSource");
1358 auto reply = dbus.call(method);
1359 if (reply.is_method_error())
1360 {
1361 log<level::ERR>("Error in BootSource Get");
1362 report<InternalFailure>();
1363 *data_len = 0;
1364 return IPMI_CC_UNSPECIFIED_ERROR;
1365 }
1366 sdbusplus::message::variant<std::string> result;
1367 reply.read(result);
1368 auto bootSource =
1369 Source::convertSourcesFromString(result.get<std::string>());
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001370
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001371 bootSetting = settings::boot::setting(objects, bootModeIntf);
1372 const auto& bootModeSetting = std::get<settings::Path>(bootSetting);
1373 method = dbus.new_method_call(
Patrick Venture0b02be92018-08-31 11:55:55 -07001374 objects.service(bootModeSetting, bootModeIntf).c_str(),
1375 bootModeSetting.c_str(), ipmi::PROP_INTF, "Get");
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001376 method.append(bootModeIntf, "BootMode");
1377 reply = dbus.call(method);
1378 if (reply.is_method_error())
1379 {
1380 log<level::ERR>("Error in BootMode Get");
1381 report<InternalFailure>();
1382 *data_len = 0;
1383 return IPMI_CC_UNSPECIFIED_ERROR;
1384 }
1385 reply.read(result);
1386 auto bootMode =
1387 Mode::convertModesFromString(result.get<std::string>());
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001388
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001389 bootOption = sourceDbusToIpmi.at(bootSource);
1390 if ((Mode::Modes::Regular == bootMode) &&
1391 (Source::Sources::Default == bootSource))
1392 {
1393 bootOption = ipmiDefault;
1394 }
1395 else if (Source::Sources::Default == bootSource)
1396 {
1397 bootOption = modeDbusToIpmi.at(bootMode);
1398 }
1399 resp->data[1] = (bootOption << 2);
ratagupta6f6bff2016-04-04 06:20:11 -05001400
Patrick Venture0b02be92018-08-31 11:55:55 -07001401 resp->data[0] = oneTimeEnabled
1402 ? SET_PARM_BOOT_FLAGS_VALID_ONE_TIME
1403 : SET_PARM_BOOT_FLAGS_VALID_PERMANENT;
ratagupta6f6bff2016-04-04 06:20:11 -05001404
ratagupta6f6bff2016-04-04 06:20:11 -05001405 rc = IPMI_CC_OK;
ratagupta6f6bff2016-04-04 06:20:11 -05001406 }
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001407 catch (InternalFailure& e)
1408 {
1409 report<InternalFailure>();
1410 *data_len = 0;
1411 return IPMI_CC_UNSPECIFIED_ERROR;
1412 }
Patrick Venture0b02be92018-08-31 11:55:55 -07001413 }
1414 else if (reqptr->parameter ==
1415 static_cast<uint8_t>(BootOptionParameter::OPAL_NETWORK_SETTINGS))
1416 {
Ratan Guptafd28dd72016-08-01 04:58:01 -05001417
Patrick Venture0b02be92018-08-31 11:55:55 -07001418 *data_len =
1419 static_cast<uint8_t>(BootOptionResponseSize::OPAL_NETWORK_SETTINGS);
Ratan Guptafd28dd72016-08-01 04:58:01 -05001420
Patrick Venture0b02be92018-08-31 11:55:55 -07001421 resp->parm =
1422 static_cast<uint8_t>(BootOptionParameter::OPAL_NETWORK_SETTINGS);
Ratan Guptafd28dd72016-08-01 04:58:01 -05001423
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001424 int ret = getHostNetworkData(resp);
Ratan Guptafd28dd72016-08-01 04:58:01 -05001425
Patrick Venture0b02be92018-08-31 11:55:55 -07001426 if (ret < 0)
1427 {
Ratan Guptafd28dd72016-08-01 04:58:01 -05001428
Aditya Saripalli5fb14602017-11-09 14:46:27 +05301429 log<level::ERR>(
Patrick Venture0b02be92018-08-31 11:55:55 -07001430 "getHostNetworkData failed for get_sys_boot_options.");
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001431 rc = IPMI_CC_UNSPECIFIED_ERROR;
Patrick Venture0b02be92018-08-31 11:55:55 -07001432 }
1433 else
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001434 rc = IPMI_CC_OK;
Ratan Guptafd28dd72016-08-01 04:58:01 -05001435 }
1436
Patrick Venture0b02be92018-08-31 11:55:55 -07001437 else
1438 {
1439 log<level::ERR>("Unsupported parameter",
1440 entry("PARAM=0x%x", reqptr->parameter));
shgoupfd84fbbf2015-12-17 10:05:51 +08001441 }
1442
1443 if (p)
1444 free(p);
1445
Ratan Guptafd28dd72016-08-01 04:58:01 -05001446 if (rc == IPMI_CC_OK)
1447 {
1448 *data_len += 2;
1449 }
1450
shgoupfd84fbbf2015-12-17 10:05:51 +08001451 return rc;
1452}
1453
shgoupfd84fbbf2015-12-17 10:05:51 +08001454ipmi_ret_t ipmi_chassis_set_sys_boot_options(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
Andrew Geisslerfca6a4f2017-05-30 10:55:39 -05001455 ipmi_request_t request,
1456 ipmi_response_t response,
1457 ipmi_data_len_t data_len,
1458 ipmi_context_t context)
shgoupfd84fbbf2015-12-17 10:05:51 +08001459{
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001460 using namespace boot_options;
shgoupfd84fbbf2015-12-17 10:05:51 +08001461 ipmi_ret_t rc = IPMI_CC_OK;
Patrick Venture0b02be92018-08-31 11:55:55 -07001462 set_sys_boot_options_t* reqptr = (set_sys_boot_options_t*)request;
shgoupfd84fbbf2015-12-17 10:05:51 +08001463
Patrick Venture0b02be92018-08-31 11:55:55 -07001464 printf("IPMI SET_SYS_BOOT_OPTIONS reqptr->parameter =[%d]\n",
1465 reqptr->parameter);
Ratan Guptafd28dd72016-08-01 04:58:01 -05001466
shgoupfd84fbbf2015-12-17 10:05:51 +08001467 // This IPMI command does not have any resposne data
1468 *data_len = 0;
1469
1470 /* 000101
1471 * Parameter #5 means boot flags. Please refer to 28.13 of ipmi doc.
1472 * This is the only parameter used by petitboot.
1473 */
Ratan Guptafd28dd72016-08-01 04:58:01 -05001474
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001475 if (reqptr->parameter == (uint8_t)BootOptionParameter::BOOT_FLAGS)
1476 {
1477 IpmiValue bootOption = ((reqptr->data[1] & 0x3C) >> 2);
1478 using namespace chassis::internal;
1479 using namespace chassis::internal::cache;
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001480 auto oneTimeEnabled = false;
1481 constexpr auto enabledIntf = "xyz.openbmc_project.Object.Enable";
Tom Joseph57e8eb72017-09-25 18:05:02 +05301482 constexpr auto oneTimePath =
Patrick Venture0b02be92018-08-31 11:55:55 -07001483 "/xyz/openbmc_project/control/host0/boot/one_time";
shgoupfd84fbbf2015-12-17 10:05:51 +08001484
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001485 try
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001486 {
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001487 bool permanent =
1488 (reqptr->data[0] & SET_PARM_BOOT_FLAGS_PERMANENT) ==
1489 SET_PARM_BOOT_FLAGS_PERMANENT;
1490
Patrick Venture0b02be92018-08-31 11:55:55 -07001491 auto bootSetting = settings::boot::setting(objects, bootSourceIntf);
Tom Joseph57e8eb72017-09-25 18:05:02 +05301492
1493 oneTimeEnabled =
1494 std::get<settings::boot::OneTimeEnabled>(bootSetting);
1495
1496 /*
1497 * Check if the current boot setting is onetime or permanent, if the
1498 * request in the command is otherwise, then set the "Enabled"
1499 * property in one_time object path to 'True' to indicate onetime
1500 * and 'False' to indicate permanent.
1501 *
1502 * Once the onetime/permanent setting is applied, then the bootMode
1503 * and bootSource is updated for the corresponding object.
1504 */
1505 if ((permanent && oneTimeEnabled) ||
1506 (!permanent && !oneTimeEnabled))
1507 {
1508 auto service = ipmi::getService(dbus, enabledIntf, oneTimePath);
1509
Patrick Venture0b02be92018-08-31 11:55:55 -07001510 ipmi::setDbusProperty(dbus, service, oneTimePath, enabledIntf,
1511 "Enabled", !permanent);
Tom Joseph57e8eb72017-09-25 18:05:02 +05301512 }
1513
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001514 auto modeItr = modeIpmiToDbus.find(bootOption);
1515 auto sourceItr = sourceIpmiToDbus.find(bootOption);
1516 if (sourceIpmiToDbus.end() != sourceItr)
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001517 {
Marri Devender Rao81719702018-05-07 00:53:48 -05001518 rc = setBootSource(sourceItr->second);
1519 if (rc != IPMI_CC_OK)
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001520 {
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001521 *data_len = 0;
Marri Devender Rao81719702018-05-07 00:53:48 -05001522 return rc;
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001523 }
Marri Devender Rao54fa1302018-05-07 01:06:23 -05001524 // If a set boot device is mapping to a boot source, then reset
1525 // the boot mode D-Bus property to default.
1526 // This way the ipmid code can determine which property is not
1527 // at the default value
Patrick Venture0b02be92018-08-31 11:55:55 -07001528 if (sourceItr->second != Source::Sources::Default)
Marri Devender Rao54fa1302018-05-07 01:06:23 -05001529 {
1530 setBootMode(Mode::Modes::Regular);
1531 }
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001532 }
1533 if (modeIpmiToDbus.end() != modeItr)
1534 {
Marri Devender Rao81719702018-05-07 00:53:48 -05001535 rc = setBootMode(modeItr->second);
1536 if (rc != IPMI_CC_OK)
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001537 {
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001538 *data_len = 0;
Marri Devender Rao81719702018-05-07 00:53:48 -05001539 return rc;
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001540 }
Marri Devender Rao54fa1302018-05-07 01:06:23 -05001541 // If a set boot device is mapping to a boot mode, then reset
1542 // the boot source D-Bus property to default.
1543 // This way the ipmid code can determine which property is not
1544 // at the default value
Patrick Venture0b02be92018-08-31 11:55:55 -07001545 if (modeItr->second != Mode::Modes::Regular)
Marri Devender Rao54fa1302018-05-07 01:06:23 -05001546 {
1547 setBootSource(Source::Sources::Default);
1548 }
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001549 }
1550 }
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001551 catch (InternalFailure& e)
Deepak Kodihalli8cc19362017-07-21 11:18:38 -05001552 {
Deepak Kodihalli13791bd2017-08-28 06:50:51 -05001553 report<InternalFailure>();
1554 *data_len = 0;
1555 return IPMI_CC_UNSPECIFIED_ERROR;
shgoupfd84fbbf2015-12-17 10:05:51 +08001556 }
Patrick Venture0b02be92018-08-31 11:55:55 -07001557 }
1558 else if (reqptr->parameter ==
1559 (uint8_t)BootOptionParameter::OPAL_NETWORK_SETTINGS)
1560 {
Ratan Guptafd28dd72016-08-01 04:58:01 -05001561
1562 int ret = setHostNetworkData(reqptr);
Patrick Venture0b02be92018-08-31 11:55:55 -07001563 if (ret < 0)
1564 {
Aditya Saripalli5fb14602017-11-09 14:46:27 +05301565 log<level::ERR>(
Patrick Venture0b02be92018-08-31 11:55:55 -07001566 "setHostNetworkData failed for set_sys_boot_options");
Ratan Guptafd28dd72016-08-01 04:58:01 -05001567 rc = IPMI_CC_UNSPECIFIED_ERROR;
1568 }
Patrick Venture0b02be92018-08-31 11:55:55 -07001569 }
1570 else if (reqptr->parameter ==
1571 static_cast<uint8_t>(BootOptionParameter::BOOT_INFO))
1572 {
Tom Josephf536c902017-09-25 18:08:15 +05301573 // Handle parameter #4 and return command completed normally
1574 // (IPMI_CC_OK). There is no implementation in OpenBMC for this
1575 // parameter. This is added to support the ipmitool command `chassis
1576 // bootdev` which sends set on parameter #4, before setting the boot
1577 // flags.
1578 rc = IPMI_CC_OK;
Patrick Venture0b02be92018-08-31 11:55:55 -07001579 }
1580 else
1581 {
1582 log<level::ERR>("Unsupported parameter",
1583 entry("PARAM=0x%x", reqptr->parameter));
shgoupfd84fbbf2015-12-17 10:05:51 +08001584 rc = IPMI_CC_PARM_NOT_SUPPORTED;
Adriana Kobylak40814c62015-10-27 15:58:44 -05001585 }
1586
1587 return rc;
1588}
1589
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -05001590ipmi_ret_t ipmiGetPOHCounter(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
1591 ipmi_request_t request, ipmi_response_t response,
1592 ipmi_data_len_t data_len, ipmi_context_t context)
1593{
1594 // sd_bus error
1595 ipmi_ret_t rc = IPMI_CC_OK;
1596
1597 auto resptr = reinterpret_cast<GetPOHCountResponse*>(response);
1598
1599 try
1600 {
1601 auto pohCounter = getPOHCounter();
1602 resptr->counterReading[0] = pohCounter;
1603 resptr->counterReading[1] = pohCounter >> 8;
1604 resptr->counterReading[2] = pohCounter >> 16;
1605 resptr->counterReading[3] = pohCounter >> 24;
1606 }
1607 catch (std::exception& e)
1608 {
1609 log<level::ERR>(e.what());
1610 return IPMI_CC_UNSPECIFIED_ERROR;
1611 }
1612
1613 resptr->minPerCount = poh::minutesPerCount;
1614 *data_len = sizeof(GetPOHCountResponse);
1615
1616 return rc;
1617}
1618
Adriana Kobylak40814c62015-10-27 15:58:44 -05001619void register_netfn_chassis_functions()
1620{
Marri Devender Rao6706c1c2018-05-14 00:29:38 -05001621 createIdentifyTimer();
1622
Tom05732372016-09-06 17:21:23 +05301623 // <Wildcard Command>
Patrick Venture0b02be92018-08-31 11:55:55 -07001624 ipmi_register_callback(NETFUN_CHASSIS, IPMI_CMD_WILDCARD, NULL,
1625 ipmi_chassis_wildcard, PRIVILEGE_USER);
Adriana Kobylak40814c62015-10-27 15:58:44 -05001626
Tom05732372016-09-06 17:21:23 +05301627 // Get Chassis Capabilities
Patrick Venture0b02be92018-08-31 11:55:55 -07001628 ipmi_register_callback(NETFUN_CHASSIS, IPMI_CMD_GET_CHASSIS_CAP, NULL,
1629 ipmi_get_chassis_cap, PRIVILEGE_USER);
Nan Li8d15fb42016-08-16 22:29:40 +08001630
Tom05732372016-09-06 17:21:23 +05301631 // <Get System Boot Options>
Tom05732372016-09-06 17:21:23 +05301632 ipmi_register_callback(NETFUN_CHASSIS, IPMI_CMD_GET_SYS_BOOT_OPTIONS, NULL,
Patrick Venture0b02be92018-08-31 11:55:55 -07001633 ipmi_chassis_get_sys_boot_options,
1634 PRIVILEGE_OPERATOR);
Adriana Kobylak40814c62015-10-27 15:58:44 -05001635
Tom05732372016-09-06 17:21:23 +05301636 // <Get Chassis Status>
Patrick Venture0b02be92018-08-31 11:55:55 -07001637 ipmi_register_callback(NETFUN_CHASSIS, IPMI_CMD_CHASSIS_STATUS, NULL,
1638 ipmi_get_chassis_status, PRIVILEGE_USER);
Nan Lifdd8ec52016-08-28 03:57:40 +08001639
Tom05732372016-09-06 17:21:23 +05301640 // <Chassis Control>
Patrick Venture0b02be92018-08-31 11:55:55 -07001641 ipmi_register_callback(NETFUN_CHASSIS, IPMI_CMD_CHASSIS_CONTROL, NULL,
1642 ipmi_chassis_control, PRIVILEGE_OPERATOR);
shgoupfd84fbbf2015-12-17 10:05:51 +08001643
Tom Joseph5110c122018-03-23 17:55:40 +05301644 // <Chassis Identify>
Tom Joseph5110c122018-03-23 17:55:40 +05301645 ipmi_register_callback(NETFUN_CHASSIS, IPMI_CMD_CHASSIS_IDENTIFY, NULL,
1646 ipmi_chassis_identify, PRIVILEGE_OPERATOR);
1647
Tom05732372016-09-06 17:21:23 +05301648 // <Set System Boot Options>
Tom05732372016-09-06 17:21:23 +05301649 ipmi_register_callback(NETFUN_CHASSIS, IPMI_CMD_SET_SYS_BOOT_OPTIONS, NULL,
Patrick Venture0b02be92018-08-31 11:55:55 -07001650 ipmi_chassis_set_sys_boot_options,
1651 PRIVILEGE_OPERATOR);
Nagaraju Gorugantia59d83f2018-04-06 05:55:42 -05001652 // <Get POH Counter>
1653 ipmi_register_callback(NETFUN_CHASSIS, IPMI_CMD_GET_POH_COUNTER, NULL,
1654 ipmiGetPOHCounter, PRIVILEGE_USER);
vishwa36993272015-11-20 12:43:49 -06001655}