Merge pull request #87 from williamli80/story76_2
Cleanup phosphor-host-ipmid storageaddsel.C
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 @@
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 @@
&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 @@
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 @@
&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 @@
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 @@
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 @@
*/
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 @@
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 @@
} 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);
diff --git a/ipmid-api.h b/ipmid-api.h
index e635528..cf3eaab 100644
--- a/ipmid-api.h
+++ b/ipmid-api.h
@@ -58,6 +58,8 @@
void ipmi_register_callback(ipmi_netfn_t, ipmi_cmd_t,
ipmi_context_t, ipmid_callback_t);
+unsigned short get_sel_reserve_id(void);
+
// These are the command network functions, the response
// network functions are the function + 1. So to determine
// the proper network function which issued the command
@@ -91,6 +93,7 @@
IPMI_CC_OK = 0x00,
IPMI_DCMI_CC_NO_ACTIVE_POWER_LIMIT = 0x80,
IPMI_CC_INVALID = 0xC1,
+ IPMI_CC_INVALID_RESERVATION_ID = 0xC5,
IPMI_CC_PARM_OUT_OF_RANGE = 0xC9,
IPMI_CC_SENSOR_INVALID = 0xCB,
IPMI_CC_RESPONSE_ERROR = 0xCE,
diff --git a/ipmid.C b/ipmid.C
index 728ba0b..063ded6 100644
--- a/ipmid.C
+++ b/ipmid.C
@@ -26,8 +26,6 @@
fprintf(stderr, " mask : 0xFF - Print all trace\n");
}
-
-
const char * DBUS_INTF = "org.openbmc.HostIpmi";
const char * FILTER = "type='signal',interface='org.openbmc.HostIpmi',member='ReceivedMessage'";
@@ -39,6 +37,13 @@
// Global data structure that contains the IPMI command handler's registrations.
std::map<ipmi_fn_cmd_t, ipmi_fn_context_t> g_ipmid_router_map;
+// IPMI Spec, shared Reservation ID.
+unsigned short g_sel_reserve = 0xFFFF;
+
+unsigned short get_sel_reserve_id(void)
+{
+ return g_sel_reserve;
+}
#ifndef HEXDUMP_COLS
#define HEXDUMP_COLS 16
@@ -341,8 +346,8 @@
handler_fqdn += "/";
num_handlers = scandir(ipmi_lib_path, &handler_list, handler_select, alphasort);
- if (num_handlers < 0)
- return;
+ if (num_handlers < 0)
+ return;
while(num_handlers--)
{
@@ -351,6 +356,7 @@
printf("Registering handler:[%s]\n",handler_fqdn.c_str());
lib_handler = dlopen(handler_fqdn.c_str(), RTLD_NOW);
+
if(lib_handler == NULL)
{
fprintf(stderr,"ERROR opening [%s]: %s\n",
@@ -359,6 +365,7 @@
// Wipe the memory allocated for this particular entry.
free(handler_list[num_handlers]);
}
+
// Done with all registration.
free(handler_list);
}
@@ -565,6 +572,11 @@
r = find_openbmc_path("SENSOR", number, &a);
+ if (r < 0) {
+ fprintf(stderr, "Failed to find Sensor 0x%02x\n", number);
+ return 0;
+ }
+
r = sd_bus_message_new_method_call(bus,&m,a.bus,a.path,a.interface,method);
if (r < 0) {
fprintf(stderr, "Failed to create a method call: %s", strerror(-r));
@@ -602,6 +614,11 @@
r = find_openbmc_path("SENSOR", number, &a);
+ if (r < 0) {
+ fprintf(stderr, "Failed to find Sensor 0x%02x\n", number);
+ return 0;
+ }
+
r = sd_bus_message_new_method_call(bus,&m,a.bus,a.path,a.interface,method);
if (r < 0) {
fprintf(stderr, "Failed to create a method call: %s", strerror(-r));
diff --git a/sensorhandler.C b/sensorhandler.C
index bb14e7a..39de660 100644
--- a/sensorhandler.C
+++ b/sensorhandler.C
@@ -180,6 +180,11 @@
r = find_openbmc_path("SENSOR", reqptr->sennum, &a);
+ if (r < 0) {
+ fprintf(stderr, "Failed to find Sensor 0x%02x\n", reqptr->sennum);
+ return IPMI_CC_SENSOR_INVALID;
+ }
+
type = find_sensor(reqptr->sennum);
fprintf(stderr, "Bus: %s, Path: %s, Interface: %s\n", a.bus, a.path, a.interface);
diff --git a/storagehandler.C b/storagehandler.C
index 020a0c9..9622ed9 100644
--- a/storagehandler.C
+++ b/storagehandler.C
@@ -13,7 +13,7 @@
unsigned int g_sel_time = 0xFFFFFFFF;
-unsigned short g_sel_reserve = 0x1;
+extern unsigned short g_sel_reserve;
ipmi_ret_t ipmi_storage_wildcard(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
ipmi_request_t request, ipmi_response_t response,
@@ -100,17 +100,19 @@
return rc;
}
-
-
ipmi_ret_t ipmi_storage_reserve_sel(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)
{
+ unsigned short res_id;
ipmi_ret_t rc = IPMI_CC_OK;
- printf("IPMI Handling RESERVE-SEL 0x%04x\n", g_sel_reserve);
+ // IPMI spec, Reservation ID, the value simply increases against each execution of reserve_sel command.
+ if( ++g_sel_reserve == 0)
+ g_sel_reserve = 1;
+ printf("IPMI Handling RESERVE-SEL 0x%04x\n", g_sel_reserve);
*data_len = sizeof(g_sel_reserve);