Support Power delay configuration
Add set power delay and get power delay commands.
Tested:
1. set power delay:
```
root@nf5280m7:~# ipmitool raw 0x3c 0x24 0x01 0x00
```
2. get power delay:
```
root@nf5280m7:~# ipmitool raw 0x3c 0x25
01 00
```
Change-Id: Ibc42aeade2888572d1aae90fb0e4f7e6db3e3250
Signed-off-by: George Liu <liuxiwei@ieisystem.com>
diff --git a/src/power.cpp b/src/power.cpp
new file mode 100644
index 0000000..9c9ebc0
--- /dev/null
+++ b/src/power.cpp
@@ -0,0 +1,65 @@
+#include "types.hpp"
+#include "utils.hpp"
+
+#include <ipmid/api.hpp>
+
+namespace ipmi
+{
+namespace iei
+{
+namespace power
+{
+
+void registerIEIPowerFunctions() __attribute__((constructor));
+
+static constexpr auto settingsService = "xyz.openbmc_project.Settings";
+
+static constexpr auto powerRestorePolicyPath =
+ "/xyz/openbmc_project/control/host0/power_restore_policy";
+static constexpr auto powerRestorePolicyIface =
+ "xyz.openbmc_project.Control.Power.RestorePolicy";
+static constexpr auto powerRestoreDelayProp = "PowerRestoreDelay";
+
+RspType<> ipmiIEISetPowerDelay(ipmi::Context::ptr ctx,
+ uint16_t powerRestoreDelay)
+{
+ uint64_t powerRestoreDelayInUs = powerRestoreDelay * 1000 * 1000;
+
+ auto ec = iei::setDbusProperty(
+ ctx, settingsService, powerRestorePolicyPath, powerRestorePolicyIface,
+ powerRestoreDelayProp, powerRestoreDelayInUs);
+
+ return ipmi::response(ec);
+}
+
+RspType<uint16_t> ipmiIEIGetPowerDelay(ipmi::Context::ptr ctx)
+{
+ uint64_t powerRestoreDelayInUs = 0;
+
+ auto ec = iei::getDbusProperty(
+ ctx, settingsService, powerRestorePolicyPath, powerRestorePolicyIface,
+ powerRestoreDelayProp, powerRestoreDelayInUs);
+ if (ec)
+ {
+ return ipmi::response(ec);
+ }
+
+ uint16_t powerRestoreDelay = powerRestoreDelayInUs / (1000 * 1000);
+
+ return ipmi::responseSuccess(powerRestoreDelay);
+}
+
+void registerIEIPowerFunctions()
+{
+ // Set power delay
+ ipmi::registerHandler(prioOemBase, netFnIEI, cmdSetPowerDelay,
+ ipmi::Privilege::Operator, ipmiIEISetPowerDelay);
+
+ // Get power delay
+ ipmi::registerHandler(prioOemBase, netFnIEI, cmdGetPowerDelay,
+ ipmi::Privilege::Operator, ipmiIEIGetPowerDelay);
+}
+
+} // namespace power
+} // namespace iei
+} // namespace ipmi