summaryrefslogtreecommitdiff
path: root/src/power_commands.c
blob: 40007331921fa58e6f2681ba5d0a43910f974040 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include <stdio.h>
#include <string.h>
#include <errno.h>

#include "d_bus_commands.h"

#include "power_commands.h"

static const string_quadruple_t chassis_dbus = {
    "xyz.openbmc_project.State.Chassis",
    "/xyz/openbmc_project/state/chassis0",
    "xyz.openbmc_project.State.Chassis",
    "RequestedPowerTransition"};

static const string_quadruple_t host_dbus = {
    "xyz.openbmc_project.State.Host",
    "/xyz/openbmc_project/state/host0",
    "xyz.openbmc_project.State.Host",
    "RequestedHostTransition"};

static const string_quadruple_t policy_dbus = {
    "xyz.openbmc_project.Settings",
    "/xyz/openbmc_project/control/host0/power_restore_policy",
    "xyz.openbmc_project.Control.Power.RestorePolicy",
    "PowerRestorePolicy"};


typedef enum
{
    POWER_UNKNOWN=-1,
    POWER_ON_GRACEFUL=100,
    POWER_ON_FORCE,
    POWER_OFF_GRACEFUL,
    POWER_OFF_FORCE,
    POWER_RESET_GRACEFUL,
    POWER_RESET_FORCE
}power_command_t;

const command_dbus_path_t power_command_paths[] = {
    { POWER_ON_GRACEFUL, &host_dbus },
    { POWER_ON_FORCE, &host_dbus },
    { POWER_OFF_GRACEFUL, &host_dbus },
    { POWER_OFF_FORCE, &chassis_dbus },
    { POWER_RESET_GRACEFUL, &host_dbus },
    { POWER_RESET_FORCE, &host_dbus },
    { 0, NULL }
};

const command_dbus_member_t power_command_values[] = {
    { POWER_ON_GRACEFUL, "xyz.openbmc_project.State.Host.Transition.On" },
    { POWER_ON_FORCE, "xyz.openbmc_project.State.Host.Transition.On" },
    { POWER_OFF_GRACEFUL, "xyz.openbmc_project.State.Host.Transition.Off" },
    { POWER_OFF_FORCE, "xyz.openbmc_project.State.Chassis.Transition.Off" },
    { POWER_RESET_GRACEFUL, "xyz.openbmc_project.State.Host.Transition.GracefulWarmReboot" },
    { POWER_RESET_FORCE, "xyz.openbmc_project.State.Host.Transition.ForceWarmReboot" },
    { 0, NULL }
};

typedef enum
{
    POWER_POLICY_UNKNOWN=-1,
    POWER_POLICY_ON=100,
    POWER_POLICY_OFF,
    POWER_POLICY_RESTORE

}power_policy_command_t;


universal_command_t power_commands[] = {
    { "on-graceful", POWER_ON_GRACEFUL, "Graceful Power On" },
    { "on", POWER_ON_GRACEFUL, "Graceful Power On" },
    { "on-force", POWER_ON_FORCE, "Force Power On" },
    { "off-graceful", POWER_OFF_GRACEFUL, "Graceful Power Off" },
    { "off", POWER_OFF_GRACEFUL, "Graceful Power Off" },
    { "off-force", POWER_OFF_FORCE, "Force Power Off" },
    { "reset-graceful", POWER_RESET_GRACEFUL, "Graceful Reset" },
    { "reset", POWER_RESET_GRACEFUL, "Graceful Reset" },
    { "reset-force", POWER_RESET_FORCE, "Force Reset" },
    { NULL, 0, NULL }
};

const universal_command_t power_policy_commands[] = {
    {"always-on", POWER_POLICY_ON, "Server is always ON"},
    {"always-off", POWER_POLICY_OFF, "Server is always ON"},
    {"restore", POWER_POLICY_RESTORE, "Server restores previous state"},
    { NULL, 0, NULL }
};

const command_dbus_path_t power_command_policy_paths[] = {
    { POWER_POLICY_ON, &policy_dbus },
    { POWER_POLICY_OFF, &policy_dbus },
    { POWER_POLICY_RESTORE, &policy_dbus },
    { 0, NULL }
};

const command_dbus_member_t power_command_policy_values[] = {
    { POWER_POLICY_ON, "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.AlwaysOn" },
    { POWER_POLICY_OFF, "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.AlwaysOff" },
    { POWER_POLICY_RESTORE, "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.Restore" },
    { 0, NULL }
};

int com_power( char *arg )
{
    return com_dbus_property(arg, power_commands, power_command_paths, power_command_values);
}

int com_power_policy( char* arg )
{
    return com_dbus_property(arg, power_policy_commands, power_command_policy_paths, power_command_policy_values);
}