diff options
author | ratagupt <ratagupt@in.ibm.com> | 2016-04-04 06:20:11 -0500 |
---|---|---|
committer | ratagupt <ratagupt@in.ibm.com> | 2016-04-19 08:42:11 -0500 |
commit | a6f6bff34912050b1061a2a8b794914d2b5809c1 (patch) | |
tree | e3711eb59813383acee72bbd554eaabb95f522ae /chassishandler.C | |
parent | b7e01a16951e868b076f3d68ecb0688a5209aa5b (diff) | |
download | phosphor-host-ipmid-a6f6bff34912050b1061a2a8b794914d2b5809c1.tar.gz phosphor-host-ipmid-a6f6bff34912050b1061a2a8b794914d2b5809c1.zip |
Adding Boot Policy
Review Comment added for 146621
Diffstat (limited to 'chassishandler.C')
-rw-r--r-- | chassishandler.C | 72 |
1 files changed, 58 insertions, 14 deletions
diff --git a/chassishandler.C b/chassishandler.C index fca3c79..d5b3404 100644 --- a/chassishandler.C +++ b/chassishandler.C @@ -4,6 +4,15 @@ #include <string.h> #include <stdint.h> + +//Defines +#define SET_PARM_VERSION 1 +#define SET_PARM_BOOT_FLAGS_PERMANENT 0x40 //boot flags data1 7th bit on +#define SET_PARM_BOOT_FLAGS_VALID_ONE_TIME 0x80 //boot flags data1 8th bit on +#define SET_PARM_BOOT_FLAGS_VALID_PERMANENT 0xC0 //boot flags data1 7 & 8 bit on + + + // OpenBMC Chassis Manager dbus framework const char *chassis_bus_name = "org.openbmc.control.Chassis"; const char *chassis_object_name = "/org/openbmc/control/chassis0"; @@ -92,7 +101,7 @@ finish: return r; } -int dbus_get_property(char **buf) +int dbus_get_property(const char *name, char **buf) { sd_bus_error error = SD_BUS_ERROR_NULL; sd_bus_message *m = NULL; @@ -128,7 +137,7 @@ int dbus_get_property(char **buf) &m, /* return message on success */ "ss", /* input signature */ host_intf_name, /* first argument */ - "boot_flags"); /* second argument */ + name); /* second argument */ if (r < 0) { fprintf(stderr, "Failed to issue method call: %s\n", error.message); @@ -161,7 +170,7 @@ finish: return r; } -int dbus_set_property(const char *buf) +int dbus_set_property(const char * name, const char *value) { sd_bus_error error = SD_BUS_ERROR_NULL; sd_bus_message *m = NULL; @@ -196,16 +205,16 @@ int dbus_set_property(const char *buf) &m, /* return message on success */ "ssv", /* input signature */ host_intf_name, /* first argument */ - "boot_flags", /* second argument */ + name, /* second argument */ "s", /* third argument */ - buf); /* fourth argument */ + value); /* fourth argument */ if (r < 0) { fprintf(stderr, "Failed to issue method call: %s\n", error.message); goto finish; } - printf("IPMID boot option property set: {%s}.\n", buf); + printf("IPMID boot option property set: {%s}.\n", value); finish: sd_bus_error_free(&error); @@ -373,9 +382,6 @@ char* get_boot_option_by_ipmi(uint8_t p) { return s->dbusname; } -#define SET_PARM_VERSION 1 -#define SET_PARM_BOOT_FLAGS_VALID 0x80 - ipmi_ret_t ipmi_chassis_get_sys_boot_options(ipmi_netfn_t netfn, ipmi_cmd_t cmd, ipmi_request_t request, ipmi_response_t response, ipmi_data_len_t data_len, ipmi_context_t context) @@ -391,7 +397,7 @@ ipmi_ret_t ipmi_chassis_get_sys_boot_options(ipmi_netfn_t netfn, ipmi_cmd_t cmd, memset(resp,0,sizeof(*resp)); resp->version = SET_PARM_VERSION; resp->parm = 5; - resp->data[0] = SET_PARM_BOOT_FLAGS_VALID; + resp->data[0] = SET_PARM_BOOT_FLAGS_VALID_ONE_TIME; *data_len = sizeof(*resp); @@ -401,10 +407,11 @@ ipmi_ret_t ipmi_chassis_get_sys_boot_options(ipmi_netfn_t netfn, ipmi_cmd_t cmd, */ if (reqptr->parameter == 5) { - int r = dbus_get_property(&p); + /* Get the boot device */ + int r = dbus_get_property("boot_flags",&p); if (r < 0) { - fprintf(stderr, "Dbus get property failed for get_sys_boot_options.\n"); + fprintf(stderr, "Dbus get property(boot_flags) failed for get_sys_boot_options.\n"); rc = IPMI_CC_UNSPECIFIED_ERROR; } else { @@ -412,8 +419,33 @@ ipmi_ret_t ipmi_chassis_get_sys_boot_options(ipmi_netfn_t netfn, ipmi_cmd_t cmd, s = get_ipmi_boot_option(p); resp->data[1] = (s << 2); rc = IPMI_CC_OK; + + } + + if (p) + { + free(p); + p = NULL; + } + + /* Get the boot policy */ + r = dbus_get_property("boot_policy",&p); + + if (r < 0) { + fprintf(stderr, "Dbus get property(boot_policy) failed for get_sys_boot_options.\n"); + rc = IPMI_CC_UNSPECIFIED_ERROR; + + } else { + + printf("BootPolicy is[%s]", p); + resp->data[0] = (strncmp(p,"ONETIME",strlen("ONETIME"))==0) ? + SET_PARM_BOOT_FLAGS_VALID_ONE_TIME: + SET_PARM_BOOT_FLAGS_VALID_PERMANENT; + rc = IPMI_CC_OK; + } + } else { fprintf(stderr, "Unsupported parameter 0x%x\n", reqptr->parameter); } @@ -455,13 +487,25 @@ ipmi_ret_t ipmi_chassis_set_sys_boot_options(ipmi_netfn_t netfn, ipmi_cmd_t cmd, } else { - int r = dbus_set_property(s); + int r = dbus_set_property("boot_flags",s); if (r < 0) { - fprintf(stderr, "Dbus set property failed for set_sys_boot_options.\n"); + fprintf(stderr, "Dbus set property(boot_flags) failed for set_sys_boot_options.\n"); rc = IPMI_CC_UNSPECIFIED_ERROR; } } + + /* setting the boot policy */ + s = (char *)(((reqptr->data[0] & SET_PARM_BOOT_FLAGS_PERMANENT) == + SET_PARM_BOOT_FLAGS_PERMANENT) ?"PERMANENT":"ONETIME"); + + printf ( "\nBoot Policy is %s",s); + int r = dbus_set_property("boot_policy",s); + + if (r < 0) { + fprintf(stderr, "Dbus set property(boot_policy) failed for set_sys_boot_options.\n"); + rc = IPMI_CC_UNSPECIFIED_ERROR; + } } else { fprintf(stderr, "Unsupported parameter 0x%x\n", reqptr->parameter); |