summaryrefslogtreecommitdiff
path: root/lib/ipmi_sel.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/ipmi_sel.c')
-rw-r--r--lib/ipmi_sel.c89
1 files changed, 53 insertions, 36 deletions
diff --git a/lib/ipmi_sel.c b/lib/ipmi_sel.c
index 67e12e3..5df66a7 100644
--- a/lib/ipmi_sel.c
+++ b/lib/ipmi_sel.c
@@ -91,15 +91,22 @@ static int ipmi_sel_oem_readval(char *str)
* reference to byte positions instead of array indexes which (hopefully)
* helps make the code easier to read.
*/
-static int ipmi_sel_oem_match(uint8_t *evt, struct ipmi_sel_oem_msg_rec rec)
+static int
+ipmi_sel_oem_match(uint8_t *evt, const struct ipmi_sel_oem_msg_rec *rec)
{
- if (evt[2] == rec.value[SEL_BYTE(3)] &&
- ((rec.value[SEL_BYTE(4)] < 0) || (evt[3] == rec.value[SEL_BYTE(4)])) &&
- ((rec.value[SEL_BYTE(5)] < 0) || (evt[4] == rec.value[SEL_BYTE(5)])) &&
- ((rec.value[SEL_BYTE(6)] < 0) || (evt[5] == rec.value[SEL_BYTE(6)])) &&
- ((rec.value[SEL_BYTE(7)] < 0) || (evt[6] == rec.value[SEL_BYTE(7)])) &&
- ((rec.value[SEL_BYTE(11)] < 0) || (evt[10] == rec.value[SEL_BYTE(11)])) &&
- ((rec.value[SEL_BYTE(12)] < 0) || (evt[11] == rec.value[SEL_BYTE(12)]))) {
+ if (evt[2] == rec->value[SEL_BYTE(3)]
+ && ((rec->value[SEL_BYTE(4)] < 0)
+ || (evt[3] == rec->value[SEL_BYTE(4)]))
+ && ((rec->value[SEL_BYTE(5)] < 0)
+ || (evt[4] == rec->value[SEL_BYTE(5)]))
+ && ((rec->value[SEL_BYTE(6)] < 0)
+ || (evt[5] == rec->value[SEL_BYTE(6)]))
+ && ((rec->value[SEL_BYTE(7)] < 0)
+ || (evt[6] == rec->value[SEL_BYTE(7)]))
+ && ((rec->value[SEL_BYTE(11)] < 0)
+ || (evt[10] == rec->value[SEL_BYTE(11)]))
+ && ((rec->value[SEL_BYTE(12)] < 0)
+ || (evt[11] == rec->value[SEL_BYTE(12)]))) {
return 1;
} else {
return 0;
@@ -191,7 +198,7 @@ static void ipmi_sel_oem_message(struct sel_event_record * evt, int verbose)
int i, j;
for (i=0; i < sel_oem_nrecs; i++) {
- if (ipmi_sel_oem_match((uint8_t *)evt, sel_oem_msg[i])) {
+ if (ipmi_sel_oem_match((uint8_t *)evt, &sel_oem_msg[i])) {
printf (csv_output ? ",\"%s\"" : " | %s", sel_oem_msg[i].text);
for (j=4; j<17; j++) {
if (sel_oem_msg[i].value[SEL_BYTE(j)] == -3) {
@@ -531,12 +538,10 @@ get_supermicro_evt_desc(struct ipmi_intf *intf, struct sel_event_record *rec)
struct ipmi_rs *rsp;
struct ipmi_rq req;
char *desc = NULL;
- char *str;
int chipset_type = 1;
int data1;
int data2;
int data3;
- int length;
int sensor_type;
uint8_t i = 0;
uint16_t oem_id = 0;
@@ -551,12 +556,12 @@ get_supermicro_evt_desc(struct ipmi_intf *intf, struct sel_event_record *rec)
return NULL;
}
/* Allocate mem for te Description string */
- desc = (char *)malloc(SIZE_OF_DESC);
+ desc = malloc(sizeof(char) * SIZE_OF_DESC);
if (desc == NULL) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
return NULL;
}
- memset(desc,0,SIZE_OF_DESC);
+ memset(desc, '\0', SIZE_OF_DESC);
sensor_type = rec->sel_type.standard_type.sensor_type;
switch (sensor_type) {
case SENSOR_TYPE_MEMORY:
@@ -587,17 +592,19 @@ get_supermicro_evt_desc(struct ipmi_intf *intf, struct sel_event_record *rec)
/* check the chipset type */
oem_id = ipmi_get_oem_id(intf);
if (oem_id == 0) {
+ if (desc != NULL) {
+ free(desc);
+ desc = NULL;
+ }
return NULL;
}
- length = sizeof(supermicro_X8);
- for (i = 0; i < length; i++) {
+ for (i = 0; supermicro_X8[i] != 0xFFFF; i++) {
if (oem_id == supermicro_X8[i]) {
chipset_type = 0;
break;
}
}
- length = sizeof(supermicro_x9);
- for (i = 0; i < length; i++) {
+ for (i = 0; supermicro_x9[i] != 0xFFFF; i++) {
if (oem_id == supermicro_x9[i]) {
chipset_type = 2;
break;
@@ -616,7 +623,8 @@ get_supermicro_evt_desc(struct ipmi_intf *intf, struct sel_event_record *rec)
(data2 >> 4) + 0x40 + (data3 & 0x3) * 3,
(data2 & 0xf) + 0x27, (data3 & 0x03) + 1);
} else {
- snprintf(desc, SIZE_OF_DESC, "");
+ /* No description. */
+ desc[0] = '\0';
}
break;
case SENSOR_TYPE_SUPERMICRO_OEM:
@@ -650,17 +658,13 @@ char * get_dell_evt_desc(struct ipmi_intf * intf, struct sel_event_record * rec)
unsigned char count;
unsigned char node;
- unsigned char num;
unsigned char dimmNum;
unsigned char dimmsPerNode;
char dimmStr[MAX_DIMM_STR];
- char cardStr[MAX_CARD_STR];
- char numStr[MAX_CARDNO_STR];
char tmpdesc[SIZE_OF_DESC];
char* str;
unsigned char incr = 0;
unsigned char i=0,j = 0;
- unsigned char postCode;
struct ipmi_rs *rsp;
struct ipmi_rq req;
char tmpData;
@@ -1234,6 +1238,8 @@ ipmi_get_event_desc(struct ipmi_intf * intf, struct sel_event_record * rec, char
sfx = ipmi_get_oem_desc(intf, rec);
break;
/* add your oem sensor assignation here */
+ default:
+ break;
}
if( evt == NULL ){
lprintf(LOG_DEBUG, "oem sensor type %x using standard type supplied description",
@@ -1247,6 +1253,8 @@ ipmi_get_event_desc(struct ipmi_intf * intf, struct sel_event_record * rec, char
code = rec->sel_type.standard_type.sensor_type;
sfx = ipmi_get_oem_desc(intf, rec);
break;
+ default:
+ break;
}
}
if( evt == NULL ){
@@ -1915,6 +1923,8 @@ ipmi_sel_print_std_entry(struct ipmi_intf * intf, struct sel_event_record * evt)
case IPMI_OEM_SUPERMICRO_47488:
print_sensor = 0;
break;
+ default:
+ break;
}
/*
* Sensor-Specific Discrete
@@ -2832,7 +2842,6 @@ ipmi_sel_delete(struct ipmi_intf * intf, int argc, char ** argv)
for (; argc != 0; argc--)
{
- id = (uint16_t) strtoul(argv[argc-1], NULL, 0);
if (str2ushort(argv[argc-1], &id) != 0) {
lprintf(LOG_ERR, "Given SEL ID '%s' is invalid.",
argv[argc-1]);
@@ -2869,25 +2878,27 @@ ipmi_sel_delete(struct ipmi_intf * intf, int argc, char ** argv)
static int
ipmi_sel_show_entry(struct ipmi_intf * intf, int argc, char ** argv)
{
- uint16_t id;
- int i, oldv;
- struct sel_event_record evt;
- struct sdr_record_list * sdr;
struct entity_id entity;
- struct sdr_record_list * list, * entry;
+ struct sdr_record_list *entry;
+ struct sdr_record_list *list;
+ struct sdr_record_list *sdr;
+ struct sel_event_record evt;
+ int i;
+ int oldv;
int rc = 0;
+ uint16_t id;
if (argc == 0 || strncmp(argv[0], "help", 4) == 0) {
lprintf(LOG_ERR, "usage: sel get <id>...<id>");
- return -1;
+ return (-1);
}
if (ipmi_sel_reserve(intf) == 0) {
lprintf(LOG_ERR, "Unable to reserve SEL");
- return -1;
+ return (-1);
}
- for (i=0; i<argc; i++) {
+ for (i = 0; i < argc; i++) {
if (str2ushort(argv[i], &id) != 0) {
lprintf(LOG_ERR, "Given SEL ID '%s' is invalid.",
argv[i]);
@@ -2903,23 +2914,28 @@ ipmi_sel_show_entry(struct ipmi_intf * intf, int argc, char ** argv)
rc = (-1);
continue;
}
- if (evt.sel_type.standard_type.sensor_num == 0 && evt.sel_type.standard_type.sensor_type == 0 && evt.record_type == 0) {
+ if (evt.sel_type.standard_type.sensor_num == 0
+ && evt.sel_type.standard_type.sensor_type == 0
+ && evt.record_type == 0) {
lprintf(LOG_WARN, "SEL Entry 0x%x not found", id);
- rc = -1;
+ rc = (-1);
continue;
}
/* lookup SDR entry based on sensor number and type */
ipmi_sel_print_extended_entry_verbose(intf, &evt);
- sdr = ipmi_sdr_find_sdr_bynumtype(intf, evt.sel_type.standard_type.gen_id, evt.sel_type.standard_type.sensor_num, evt.sel_type.standard_type.sensor_type);
+ sdr = ipmi_sdr_find_sdr_bynumtype(intf,
+ evt.sel_type.standard_type.gen_id,
+ evt.sel_type.standard_type.sensor_num,
+ evt.sel_type.standard_type.sensor_type);
if (sdr == NULL) {
continue;
}
/* print SDR entry */
oldv = verbose;
- verbose = verbose ? : 1;
+ verbose = verbose ? verbose : 1;
switch (sdr->type) {
case SDR_RECORD_TYPE_FULL_SENSOR:
case SDR_RECORD_TYPE_COMPACT_SENSOR:
@@ -2947,8 +2963,9 @@ ipmi_sel_show_entry(struct ipmi_intf * intf, int argc, char ** argv)
ipmi_fru_print(intf, entry->record.fruloc);
}
- if ((argc > 1) && (i<(argc-1)))
+ if ((argc > 1) && (i < (argc - 1))) {
printf("----------------------\n\n");
+ }
}
return rc;