diff options
Diffstat (limited to 'lib/ipmi_sel.c')
-rw-r--r-- | lib/ipmi_sel.c | 750 |
1 files changed, 380 insertions, 370 deletions
diff --git a/lib/ipmi_sel.c b/lib/ipmi_sel.c index b6629a2..31c0eea 100644 --- a/lib/ipmi_sel.c +++ b/lib/ipmi_sel.c @@ -29,7 +29,6 @@ * LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. */ -#define _BSD_SOURCE #include <string.h> #include <strings.h> @@ -38,6 +37,7 @@ #include <time.h> #include <ctype.h> #include <errno.h> +#include <stdbool.h> #include <ipmitool/helper.h> #include <ipmitool/log.h> @@ -49,8 +49,10 @@ #include <ipmitool/ipmi_sdr.h> #include <ipmitool/ipmi_fru.h> #include <ipmitool/ipmi_sensor.h> +#include <ipmitool/ipmi_strings.h> +#include <ipmitool/ipmi_quantaoem.h> +#include <ipmitool/ipmi_time.h> -extern int verbose; static int sel_extended = 0; static int sel_oem_nrecs = 0; @@ -122,13 +124,13 @@ int ipmi_sel_oem_init(const char * filename) int i, j, k, n, byte; char buf[15][150]; - if (filename == NULL) { + if (!filename) { lprintf(LOG_ERR, "No SEL OEM filename provided"); return -1; } fp = ipmi_open_file_read(filename); - if (fp == NULL) { + if (!fp) { lprintf(LOG_ERR, "Could not open %s file", filename); return -1; } @@ -192,7 +194,7 @@ int ipmi_sel_oem_init(const char * filename) return 0; } -static void ipmi_sel_oem_message(struct sel_event_record * evt, int verbose) +static void ipmi_sel_oem_message(struct sel_event_record * evt) { /* * Note: although we have a verbose argument, currently the output @@ -237,34 +239,6 @@ ipmi_get_event_type(uint8_t code) } static char * -ipmi_sel_timestamp(uint32_t stamp) -{ - static char tbuf[40]; - time_t s = (time_t)stamp; - memset(tbuf, 0, 40); - strftime(tbuf, sizeof(tbuf), "%m/%d/%Y %H:%M:%S", gmtime(&s)); - return tbuf; -} - -static char * -ipmi_sel_timestamp_date(uint32_t stamp) -{ - static char tbuf[11]; - time_t s = (time_t)stamp; - strftime(tbuf, sizeof(tbuf), "%m/%d/%Y", gmtime(&s)); - return tbuf; -} - -static char * -ipmi_sel_timestamp_time(uint32_t stamp) -{ - static char tbuf[9]; - time_t s = (time_t)stamp; - strftime(tbuf, sizeof(tbuf), "%H:%M:%S", gmtime(&s)); - return tbuf; -} - -static char * hex2ascii (uint8_t * hexChars, uint8_t numBytes) { int count; @@ -314,11 +288,11 @@ ipmi_get_oem(struct ipmi_intf * intf) req.msg.data_len = 0; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Get Device ID command failed"); return IPMI_OEM_UNKNOWN; } - if (rsp->ccode > 0) { + if (rsp->ccode) { lprintf(LOG_ERR, "Get Device ID command failed: %#x %s", rsp->ccode, val2str(rsp->ccode, completion_code_vals)); return IPMI_OEM_UNKNOWN; @@ -347,11 +321,11 @@ ipmi_sel_add_entry(struct ipmi_intf * intf, struct sel_event_record * rec) ipmi_sel_print_std_entry(intf, rec); rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Add SEL Entry failed"); return -1; } - else if (rsp->ccode > 0) { + else if (rsp->ccode) { lprintf(LOG_ERR, "Add SEL Entry failed: %s", val2str(rsp->ccode, completion_code_vals)); return -1; @@ -372,15 +346,15 @@ ipmi_sel_add_entries_fromfile(struct ipmi_intf * intf, const char * filename) uint8_t rqdata[8]; struct sel_event_record sel_event; - if (filename == NULL) + if (!filename) return -1; fp = ipmi_open_file_read(filename); - if (fp == NULL) + if (!fp) return -1; while (feof(fp) == 0) { - if (fgets(buf, 1024, fp) == NULL) + if (!fgets(buf, 1024, fp)) continue; /* clip off optional comment tail indicated by # */ @@ -446,24 +420,26 @@ ipmi_sel_add_entries_fromfile(struct ipmi_intf * intf, const char * filename) return rc; } -static struct ipmi_event_sensor_types oem_kontron_event_reading_types[] __attribute__((unused)) = { - { 0x70 , 0x00 , 0xff, IPMI_EVENT_CLASS_DISCRETE , "OEM Firmware Info 1", "Code Assert" }, - { 0x71 , 0x00 , 0xff, IPMI_EVENT_CLASS_DISCRETE , "OEM Firmware Info 2", "Code Assert" }, +static struct ipmi_event_sensor_types __UNUSED__(oem_kontron_event_reading_types[]) = { + { 0x70 , 0x00 , 0xff, "Code Assert" }, + { 0x71 , 0x00 , 0xff, "Code Assert" }, + { 0, 0, 0xFF, NULL } }; - + +/* NOTE: unused paramter kept in for consistency. */ char * -get_kontron_evt_desc(struct ipmi_intf * intf, struct sel_event_record * rec) +get_kontron_evt_desc(struct ipmi_intf *__UNUSED__(intf), struct sel_event_record *rec) { - char * description = NULL; + char *description = NULL; /* * Kontron OEM events are described in the product's user manual, but are limited in favor of - * sensor specific + * sensor specific */ /* Only standard records are defined so far */ if( rec->record_type < 0xC0 ){ - struct ipmi_event_sensor_types *st=NULL; - for ( st=oem_kontron_event_reading_types ; st->type != NULL; st++){ + const struct ipmi_event_sensor_types *st=NULL; + for (st = oem_kontron_event_types; st->desc; st++){ if (st->code == rec->sel_type.standard_type.event_type ){ size_t len =strlen(st->desc); description = (char*)malloc( len + 1 ); @@ -478,10 +454,10 @@ get_kontron_evt_desc(struct ipmi_intf * intf, struct sel_event_record * rec) } char * -get_newisys_evt_desc(struct ipmi_intf * intf, struct sel_event_record * rec) +get_viking_evt_desc(struct ipmi_intf * intf, struct sel_event_record * rec) { /* - * Newisys OEM event descriptions can be retrieved through an + * Viking OEM event descriptions can be retrieved through an * OEM IPMI command. */ struct ipmi_rs * rsp; @@ -504,12 +480,12 @@ get_newisys_evt_desc(struct ipmi_intf * intf, struct sel_event_record * rec) req.msg.data = msg_data; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { if (verbose) lprintf(LOG_ERR, "Error issuing OEM command"); return NULL; } - if (rsp->ccode > 0) { + if (rsp->ccode) { if (verbose) lprintf(LOG_ERR, "OEM command returned error code: %s", val2str(rsp->ccode, completion_code_vals)); @@ -519,17 +495,17 @@ get_newisys_evt_desc(struct ipmi_intf * intf, struct sel_event_record * rec) /* Verify our response before we use it */ if (rsp->data_len < 5) { - lprintf(LOG_ERR, "Newisys OEM response too short"); + lprintf(LOG_ERR, "Viking OEM response too short"); return NULL; } else if (rsp->data_len != (4 + rsp->data[3])) { - lprintf(LOG_ERR, "Newisys OEM response has unexpected length"); + lprintf(LOG_ERR, "Viking OEM response has unexpected length"); return NULL; } - else if (IPM_DEV_MANUFACTURER_ID(rsp->data) != IPMI_OEM_NEWISYS) + else if (IPM_DEV_MANUFACTURER_ID(rsp->data) != IPMI_OEM_VIKING) { - lprintf(LOG_ERR, "Newisys OEM response has unexpected length"); + lprintf(LOG_ERR, "Viking OEM response has unexpected length"); return NULL; } @@ -546,7 +522,7 @@ get_supermicro_evt_desc(struct ipmi_intf *intf, struct sel_event_record *rec) struct ipmi_rs *rsp; struct ipmi_rq req; char *desc = NULL; - int chipset_type = 1; + int chipset_type = 4; int data1; int data2; int data3; @@ -563,9 +539,9 @@ get_supermicro_evt_desc(struct ipmi_intf *intf, struct sel_event_record *rec) if (rec->sel_type.standard_type.event_type != 0x6F) { return NULL; } - /* Allocate mem for te Description string */ + /* Allocate mem for the Description string */ desc = malloc(sizeof(char) * SIZE_OF_DESC); - if (desc == NULL) { + if (!desc) { lprintf(LOG_ERR, "ipmitool: malloc failure"); return NULL; } @@ -581,17 +557,17 @@ get_supermicro_evt_desc(struct ipmi_intf *intf, struct sel_event_record *rec) req.msg.data_len = 0; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, " Error getting system info"); - if (desc != NULL) { + if (desc) { free(desc); desc = NULL; } return NULL; - } else if (rsp->ccode > 0) { + } else if (rsp->ccode) { lprintf(LOG_ERR, " Error getting system info: %s", val2str(rsp->ccode, completion_code_vals)); - if (desc != NULL) { + if (desc) { free(desc); desc = NULL; } @@ -600,7 +576,7 @@ 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) { + if (desc) { free(desc); desc = NULL; } @@ -612,12 +588,48 @@ get_supermicro_evt_desc(struct ipmi_intf *intf, struct sel_event_record *rec) break; } } + for (i = 0; supermicro_older[i] != 0xFFFF; i++) { + if (oem_id == supermicro_older[i]) { + chipset_type = 0; + break; + } + } + for (i = 0; supermicro_romely[i] != 0xFFFF; i++) { + if (oem_id == supermicro_romely[i]) { + chipset_type = 1; + break; + } + } for (i = 0; supermicro_x9[i] != 0xFFFF; i++) { if (oem_id == supermicro_x9[i]) { chipset_type = 2; break; } } + for (i = 0; supermicro_brickland[i] != 0xFFFF; i++) { + if (oem_id == supermicro_brickland[i]) { + chipset_type = 3; + break; + } + } + for (i = 0; supermicro_x10QRH[i] != 0xFFFF; i++) { + if (oem_id == supermicro_x10QRH[i]) { + chipset_type = 4; + break; + } + } + for (i = 0; supermicro_x10QBL[i] != 0xFFFF; i++) { + if (oem_id == supermicro_x10QBL[i]) { + chipset_type = 4; + break; + } + } + for (i = 0; supermicro_x10OBi[i] != 0xFFFF; i++) { + if (oem_id == supermicro_x10OBi[i]) { + chipset_type = 5; + break; + } + } if (chipset_type == 0) { snprintf(desc, SIZE_OF_DESC, "@DIMM%2X(CPU%x)", data2, @@ -630,6 +642,21 @@ get_supermicro_evt_desc(struct ipmi_intf *intf, struct sel_event_record *rec) snprintf(desc, SIZE_OF_DESC, "@DIMM%c%c(CPU%x)", (data2 >> 4) + 0x40 + (data3 & 0x3) * 3, (data2 & 0xf) + 0x27, (data3 & 0x03) + 1); + } else if (chipset_type == 3) { + snprintf(desc, SIZE_OF_DESC, "@DIMM%c%d(P%dM%d)", + ((data2 & 0xf) >> 4) > 4 + ? '@' - 4 + ((data2 & 0xff) >> 4) + : '@' + ((data2 & 0xff) >> 4), + (data2 & 0xf) - 0x09, (data3 & 0x0f) + 1, + (data2 & 0xff) >> 4 > 4 ? 2 : 1); + } else if (chipset_type == 4) { + snprintf(desc, SIZE_OF_DESC, "@DIMM%c%c(CPU%x)", + (data2 >> 4) + 0x40, + (data2 & 0xf) + 0x27, (data3 & 0x03) + 1); + } else if (chipset_type == 5) { + snprintf(desc, SIZE_OF_DESC, "@DIMM%c%c(CPU%x)", + (data2 >> 4) + 0x40, + (data2 & 0xf) + 0x27, (data3 & 0x07) + 1); } else { /* No description. */ desc[0] = '\0'; @@ -652,7 +679,7 @@ get_supermicro_evt_desc(struct ipmi_intf *intf, struct sel_event_record *rec) /* * Function : Decoding the SEL OEM Bytes for the DELL Platforms. - * Description : The below fucntion will decode the SEL Events OEM Bytes for the Dell specific Sensors only. + * Description : The below function will decode the SEL Events OEM Bytes for the Dell specific Sensors only. * The below function will append the additional information Strings/description to the normal sel desc. * With this the SEL will display additional information sent via OEM Bytes of the SEL Record. * NOTE : Specific to DELL Platforms only. @@ -685,7 +712,7 @@ char * get_dell_evt_desc(struct ipmi_intf * intf, struct sel_event_record * rec) if (0x6F == rec->sel_type.standard_type.event_type) { sensor_type = rec->sel_type.standard_type.sensor_type; - /* Allocate mem for te Description string */ + /* Allocate mem for the Description string */ desc = (char*)malloc(SIZE_OF_DESC); if(NULL == desc) return NULL; @@ -734,17 +761,17 @@ char * get_dell_evt_desc(struct ipmi_intf * intf, struct sel_event_record * rec) if (NULL == rsp) { lprintf(LOG_ERR, " Error getting system info"); - if (desc != NULL) { + if (desc) { free(desc); desc = NULL; } return NULL; } - else if (rsp->ccode > 0) + else if (rsp->ccode) { lprintf(LOG_ERR, " Error getting system info: %s", val2str(rsp->ccode, completion_code_vals)); - if (desc != NULL) { + if (desc) { free(desc); desc = NULL; } @@ -843,11 +870,11 @@ char * get_dell_evt_desc(struct ipmi_intf * intf, struct sel_event_record * rec) if(SENSOR_TYPE_EVT_LOG == sensor_type) { if(0x03 == (data1 & MASK_LOWER_NIBBLE)) - snprintf(desc,SIZE_OF_DESC,"All Even Logging Dissabled"); + snprintf(desc,SIZE_OF_DESC,"All Even Logging Disabled"); } } /* - * Based on the above error, we need to find whcih memory slot or + * Based on the above error, we need to find which memory slot or * Card has got the Errors/Sel Generated. */ if(data1 & OEM_CODE_IN_BYTE2 ) @@ -989,7 +1016,7 @@ char * get_dell_evt_desc(struct ipmi_intf * intf, struct sel_event_record * rec) } break; - /* This Event is for BMC to Othe Hardware or CPU . */ + /* This Event is for BMC to other Hardware or CPU . */ case SENSOR_TYPE_VER_CHANGE: if((0x02 == (data1 & MASK_LOWER_NIBBLE))&&((data1 & OEM_CODE_IN_BYTE2) && (data1 & OEM_CODE_IN_BYTE3))) { @@ -1178,8 +1205,8 @@ ipmi_get_oem_desc(struct ipmi_intf * intf, struct sel_event_record * rec) switch (ipmi_get_oem(intf)) { - case IPMI_OEM_NEWISYS: - desc = get_newisys_evt_desc(intf, rec); + case IPMI_OEM_VIKING: + desc = get_viking_evt_desc(intf, rec); break; case IPMI_OEM_KONTRON: desc = get_kontron_evt_desc(intf, rec); @@ -1191,6 +1218,9 @@ ipmi_get_oem_desc(struct ipmi_intf * intf, struct sel_event_record * rec) case IPMI_OEM_SUPERMICRO_47488: desc = get_supermicro_evt_desc(intf, rec); break; + case IPMI_OEM_QUANTA: + desc = oem_qct_get_evt_desc(intf, rec); + break; case IPMI_OEM_UNKNOWN: default: break; @@ -1200,15 +1230,75 @@ ipmi_get_oem_desc(struct ipmi_intf * intf, struct sel_event_record * rec) } +const struct ipmi_event_sensor_types * +ipmi_get_first_event_sensor_type(struct ipmi_intf *intf, + uint8_t sensor_type, uint8_t event_type) +{ + const struct ipmi_event_sensor_types *evt, *start, *next = NULL; + uint8_t code; + + if (event_type == 0x6f) { + if (sensor_type >= 0xC0 + && sensor_type < 0xF0 + && ipmi_get_oem(intf) == IPMI_OEM_KONTRON) { + /* check Kontron OEM sensor event types */ + start = oem_kontron_event_types; + } else if (intf->vita_avail) { + /* check VITA sensor event types first */ + start = vita_sensor_event_types; + + /* then check generic sensor types */ + next = sensor_specific_event_types; + } else { + /* check generic sensor types */ + start = sensor_specific_event_types; + } + code = sensor_type; + } else { + start = generic_event_types; + code = event_type; + } + + for (evt = start; evt->desc || next; evt++) { + /* check if VITA sensor event types has finished */ + if (!evt->desc) { + /* proceed with next table */ + evt = next; + next = NULL; + } + + if (code == evt->code) + return evt; + } + + return NULL; +} + + +const struct ipmi_event_sensor_types * +ipmi_get_next_event_sensor_type(const struct ipmi_event_sensor_types *evt) +{ + const struct ipmi_event_sensor_types *start = evt; + + for (evt = start + 1; evt->desc; evt++) { + if (evt->code == start->code) { + return evt; + } + } + + return NULL; +} + + void ipmi_get_event_desc(struct ipmi_intf * intf, struct sel_event_record * rec, char ** desc) { - uint8_t code, offset; - struct ipmi_event_sensor_types *evt = NULL; + uint8_t offset; + const struct ipmi_event_sensor_types *evt = NULL; char *sfx = NULL; /* This will be assigned if the Platform is DELL, additional info is appended to the current Description */ - if (desc == NULL) + if (!desc) return; *desc = NULL; @@ -1223,86 +1313,68 @@ ipmi_get_event_desc(struct ipmi_intf * intf, struct sel_event_record * rec, char case IPMI_OEM_KONTRON: lprintf(LOG_DEBUG, "oem sensor type %x %d using oem type supplied description", rec->sel_type.standard_type.sensor_type , iana); - - evt = oem_kontron_event_types; - code = rec->sel_type.standard_type.sensor_type; break; case IPMI_OEM_DELL: /* OEM Bytes Decoding for DELLi */ - evt = sensor_specific_types; - code = rec->sel_type.standard_type.sensor_type; if ( (OEM_CODE_IN_BYTE2 == (rec->sel_type.standard_type.event_data[0] & DATA_BYTE2_SPECIFIED_MASK)) || (OEM_CODE_IN_BYTE3 == (rec->sel_type.standard_type.event_data[0] & DATA_BYTE3_SPECIFIED_MASK)) ) { - if(rec->sel_type.standard_type.event_data[0] & DATA_BYTE2_SPECIFIED_MASK) - evt->data = rec->sel_type.standard_type.event_data[1]; - sfx = ipmi_get_oem_desc(intf, rec); } break; case IPMI_OEM_SUPERMICRO: case IPMI_OEM_SUPERMICRO_47488: - evt = sensor_specific_types; - code = rec->sel_type.standard_type.sensor_type; sfx = ipmi_get_oem_desc(intf, rec); break; /* add your oem sensor assignation here */ + case IPMI_OEM_QUANTA: + sfx = ipmi_get_oem_desc(intf, rec); + break; default: + lprintf(LOG_DEBUG, "oem sensor type %x using standard type supplied description", + rec->sel_type.standard_type.sensor_type ); break; - } - if( evt == NULL ){ - lprintf(LOG_DEBUG, "oem sensor type %x using standard type supplied description", - rec->sel_type.standard_type.sensor_type ); } } else { switch (ipmi_get_oem(intf)) { case IPMI_OEM_SUPERMICRO: case IPMI_OEM_SUPERMICRO_47488: - evt = sensor_specific_types; - code = rec->sel_type.standard_type.sensor_type; sfx = ipmi_get_oem_desc(intf, rec); - break; + break; + case IPMI_OEM_QUANTA: + sfx = ipmi_get_oem_desc(intf, rec); + break; default: - break; + break; } } - if( evt == NULL ){ - evt = sensor_specific_types; - code = rec->sel_type.standard_type.sensor_type; - } /* * Check for the OEM DELL Interface based on the Dell Specific Vendor Code. * If its Dell Platform, do the OEM Byte decode from the SEL Records. * Additional information should be written by the ipmi_get_oem_desc() */ if(ipmi_get_oem(intf) == IPMI_OEM_DELL) { - code = rec->sel_type.standard_type.sensor_type; if ( (OEM_CODE_IN_BYTE2 == (rec->sel_type.standard_type.event_data[0] & DATA_BYTE2_SPECIFIED_MASK)) || (OEM_CODE_IN_BYTE3 == (rec->sel_type.standard_type.event_data[0] & DATA_BYTE3_SPECIFIED_MASK)) ) { - if(rec->sel_type.standard_type.event_data[0] & DATA_BYTE2_SPECIFIED_MASK) - evt->data = rec->sel_type.standard_type.event_data[1]; - sfx = ipmi_get_oem_desc(intf, rec); - + sfx = ipmi_get_oem_desc(intf, rec); } else if(SENSOR_TYPE_OEM_SEC_EVENT == rec->sel_type.standard_type.event_data[0]) { /* 0x23 : Sensor Number.*/ if(0x23 == rec->sel_type.standard_type.sensor_num) - { - evt->data = rec->sel_type.standard_type.event_data[1]; sfx = ipmi_get_oem_desc(intf, rec); - } } } - } else { - evt = generic_event_types; - code = rec->sel_type.standard_type.event_type; } offset = rec->sel_type.standard_type.event_data[0] & 0xf; - while (evt->type) { - if ((evt->code == code && evt->offset == offset && evt->desc != NULL) && + for (evt = ipmi_get_first_event_sensor_type(intf, + rec->sel_type.standard_type.sensor_type, + rec->sel_type.standard_type.event_type); + evt; evt = ipmi_get_next_event_sensor_type(evt)) + { + if ((evt->offset == offset && evt->desc) && ((evt->data == ALL_OFFSETS_SPECIFIED) || ((rec->sel_type.standard_type.event_data[0] & DATA_BYTE2_SPECIFIED_MASK) && (evt->data == rec->sel_type.standard_type.event_data[1])))) @@ -1326,15 +1398,14 @@ ipmi_get_event_desc(struct ipmi_intf * intf, struct sel_event_record * rec, char sprintf(*desc, "%s", evt->desc); } return; - } - evt++; + } } /* The Above while Condition was not met beacouse the below sensor type were Newly defined OEM Secondary Events. 0xC1, 0xC2, 0xC3. */ if((sfx) && (0x6F == rec->sel_type.standard_type.event_type)) { uint8_t flag = 0x00; - switch(code) + switch(rec->sel_type.standard_type.sensor_type) { case SENSOR_TYPE_FRM_PROG: if(0x0F == offset) @@ -1379,74 +1450,58 @@ ipmi_get_event_desc(struct ipmi_intf * intf, struct sel_event_record * rec, char } -const char * -ipmi_sel_get_oem_sensor_type(IPMI_OEM iana, uint8_t code) +const char* +ipmi_get_generic_sensor_type(uint8_t code) { - struct ipmi_event_sensor_types *st = NULL; - - switch(iana){ - case IPMI_OEM_KONTRON: - st = oem_kontron_event_types; - break; - /* add you oem sensor type lookup assignement here */ - default: - lprintf(LOG_DEBUG, "ipmitool: missing OEM sensor type for %ul",iana); - break; + if (code <= SENSOR_TYPE_MAX) { + return ipmi_generic_sensor_type_vals[code]; } - if( st != NULL ) - for (; st->type != NULL; st++) - if (st->code == code) - return st->type; - - return ipmi_sel_get_sensor_type(code); + return NULL; } + const char * -ipmi_sel_get_oem_sensor_type_offset(IPMI_OEM iana, uint8_t code, uint8_t offset) +ipmi_get_oem_sensor_type(struct ipmi_intf *intf, uint8_t code) { - struct ipmi_event_sensor_types *st = NULL; + const struct oemvalstr *v, *found = NULL; + uint32_t iana = ipmi_get_oem(intf); - switch(iana){ - case IPMI_OEM_KONTRON: - st = oem_kontron_event_types; - break; - /* add you oem sensor type lookup assignement here */ - default: - lprintf(LOG_DEBUG, - "ipmitool: missing OEM sensor type offset for %ul",iana); - break; - } + for (v = ipmi_oem_sensor_type_vals; v->str; v++) { + if (v->oem == iana && v->val == code) { + return v->str; + } - if( st != NULL ) - for (; st->type != NULL; st++) - { - if (st->code == code && st->offset == (offset&0xf)) - return st->type; + if ((intf->picmg_avail + && v->oem == IPMI_OEM_PICMG + && v->val == code) + || (intf->vita_avail + && v->oem == IPMI_OEM_VITA + && v->val == code)) { + found = v; } + } - return ipmi_sel_get_oem_sensor_type(iana,code); + return found ? found->str : NULL; } -const char * -ipmi_sel_get_sensor_type(uint8_t code) -{ - struct ipmi_event_sensor_types *st; - for (st = sensor_specific_types; st->type != NULL; st++) - if (st->code == code) - return st->type; - return "Unknown"; -} const char * -ipmi_sel_get_sensor_type_offset(uint8_t code, uint8_t offset) +ipmi_get_sensor_type(struct ipmi_intf *intf, uint8_t code) { - struct ipmi_event_sensor_types *st; - for (st = sensor_specific_types; st->type != NULL; st++) - if (st->code == code && st->offset == (offset&0xf)) - return st->type; + const char *type; + + if (code >= 0xC0) { + type = ipmi_get_oem_sensor_type(intf, code); + } else { + type = ipmi_get_generic_sensor_type(code); + } + + if (!type) { + type = "Unknown"; + } - return ipmi_sel_get_sensor_type(code); + return type; } static int @@ -1466,10 +1521,10 @@ ipmi_sel_get_info(struct ipmi_intf * intf) req.msg.cmd = IPMI_CMD_GET_SEL_INFO; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Get SEL Info command failed"); return -1; - } else if (rsp->ccode > 0) { + } else if (rsp->ccode) { lprintf(LOG_ERR, "Get SEL Info command failed: %s", val2str(rsp->ccode, completion_code_vals)); return -1; @@ -1512,14 +1567,14 @@ ipmi_sel_get_info(struct ipmi_intf * intf) printf("Last Add Time : Not Available\n"); else printf("Last Add Time : %s\n", - ipmi_sel_timestamp(buf2long(rsp->data + 5))); + ipmi_timestamp_numeric(buf2long(rsp->data + 5))); if ((!memcmp(rsp->data + 9, &fs, 4)) || (!memcmp(rsp->data + 9, &zeros, 4))) printf("Last Del Time : Not Available\n"); else printf("Last Del Time : %s\n", - ipmi_sel_timestamp(buf2long(rsp->data + 9))); + ipmi_timestamp_numeric(buf2long(rsp->data + 9))); printf("Overflow : %s\n", @@ -1547,12 +1602,12 @@ ipmi_sel_get_info(struct ipmi_intf * intf) req.msg.cmd = IPMI_CMD_GET_SEL_ALLOC_INFO; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Get SEL Allocation Info command failed"); return -1; } - if (rsp->ccode > 0) { + if (rsp->ccode) { lprintf(LOG_ERR, "Get SEL Allocation Info command failed: %s", val2str(rsp->ccode, completion_code_vals)); @@ -1593,11 +1648,11 @@ ipmi_sel_get_std_entry(struct ipmi_intf * intf, uint16_t id, req.msg.data_len = 6; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Get SEL Entry %x command failed", id); return 0; } - if (rsp->ccode > 0) { + if (rsp->ccode) { lprintf(LOG_ERR, "Get SEL Entry %x command failed: %s", id, val2str(rsp->ccode, completion_code_vals)); return 0; @@ -1680,7 +1735,7 @@ ipmi_sel_print_event_file(struct ipmi_intf * intf, struct sel_event_record * evt { char * description; - if (fp == NULL) + if (!fp) return; ipmi_get_event_desc(intf, evt, &description); @@ -1693,17 +1748,11 @@ ipmi_sel_print_event_file(struct ipmi_intf * intf, struct sel_event_record * evt evt->sel_type.standard_type.event_data[0], evt->sel_type.standard_type.event_data[1], evt->sel_type.standard_type.event_data[2], - ( - (evt->sel_type.standard_type.sensor_type >=0xC0 && evt->sel_type.standard_type.sensor_type < 0xF0) - ? - ipmi_sel_get_oem_sensor_type_offset(ipmi_get_oem(intf),evt->sel_type.standard_type.sensor_type, evt->sel_type.standard_type.event_data[0]) - : - ipmi_sel_get_sensor_type_offset(evt->sel_type.standard_type.sensor_type, evt->sel_type.standard_type.event_data[0]) - ), + ipmi_get_sensor_type(intf, evt->sel_type.standard_type.sensor_type), evt->sel_type.standard_type.sensor_num, - (description != NULL) ? description : "Unknown"); + description ? description : "Unknown"); - if (description != NULL) { + if (description) { free(description); description = NULL; } @@ -1763,18 +1812,19 @@ ipmi_sel_print_std_entry(struct ipmi_intf * intf, struct sel_event_record * evt) } else { if (evt->record_type < 0xc0) - printf("%s", ipmi_sel_timestamp_date(evt->sel_type.standard_type.timestamp)); + printf("%s", ipmi_timestamp_date(evt->sel_type.standard_type.timestamp)); else - printf("%s", ipmi_sel_timestamp_date(evt->sel_type.oem_ts_type.timestamp)); + printf("%s", ipmi_timestamp_date(evt->sel_type.oem_ts_type.timestamp)); + if (csv_output) printf(","); else printf(" | "); - + if (evt->record_type < 0xc0) - printf("%s", ipmi_sel_timestamp_time(evt->sel_type.standard_type.timestamp)); + printf("%s", ipmi_timestamp_time(evt->sel_type.standard_type.timestamp)); else - printf("%s", ipmi_sel_timestamp_time(evt->sel_type.oem_ts_type.timestamp)); + printf("%s", ipmi_timestamp_time(evt->sel_type.oem_ts_type.timestamp)); if (csv_output) printf(","); @@ -1812,22 +1862,15 @@ ipmi_sel_print_std_entry(struct ipmi_intf * intf, struct sel_event_record * evt) for(data_count=0;data_count < SEL_OEM_NOTS_DATA_LEN;data_count++) printf("%02x", evt->sel_type.oem_nots_type.oem_defined[data_count]); } - ipmi_sel_oem_message(evt, 0); + ipmi_sel_oem_message(evt); printf ("\n"); return; } /* lookup SDR entry based on sensor number and type */ - if (sdr != NULL) { - printf("%s ", - ( - (evt->sel_type.standard_type.sensor_type >=0xC0 && evt->sel_type.standard_type.sensor_type < 0xF0) - ? - ipmi_sel_get_oem_sensor_type_offset(ipmi_get_oem(intf),evt->sel_type.standard_type.sensor_type, evt->sel_type.standard_type.event_data[0]) - : - ipmi_sel_get_sensor_type_offset(evt->sel_type.standard_type.sensor_type, evt->sel_type.standard_type.event_data[0]) - ) - ); + if (sdr) { + printf("%s ", ipmi_get_sensor_type(intf, + evt->sel_type.standard_type.sensor_type)); switch (sdr->type) { case SDR_RECORD_TYPE_FULL_SENSOR: printf("%s", sdr->record.full->id_string); @@ -1852,13 +1895,8 @@ ipmi_sel_print_std_entry(struct ipmi_intf * intf, struct sel_event_record * evt) break; } } else { - printf("%s",( - (evt->sel_type.standard_type.sensor_type >=0xC0 && evt->sel_type.standard_type.sensor_type < 0xF0) - ? - ipmi_sel_get_oem_sensor_type_offset(ipmi_get_oem(intf),evt->sel_type.standard_type.sensor_type, evt->sel_type.standard_type.event_data[0]) - : - ipmi_sel_get_sensor_type_offset(evt->sel_type.standard_type.sensor_type, evt->sel_type.standard_type.event_data[0]) - )); + printf("%s", ipmi_get_sensor_type(intf, + evt->sel_type.standard_type.sensor_type)); if (evt->sel_type.standard_type.sensor_num != 0) printf(" #0x%02x", evt->sel_type.standard_type.sensor_num); } @@ -1887,7 +1925,7 @@ ipmi_sel_print_std_entry(struct ipmi_intf * intf, struct sel_event_record * evt) printf("Asserted"); } - if (sdr != NULL && evt->sel_type.standard_type.event_type == 1) { + if (sdr && evt->sel_type.standard_type.event_type == 1) { /* * Threshold Event */ @@ -1917,8 +1955,20 @@ ipmi_sel_print_std_entry(struct ipmi_intf * intf, struct sel_event_record * evt) (trigger_reading==(int)trigger_reading) ? 0 : 2, trigger_reading); if (threshold_reading_provided) { + /* According to Table 29-6, Event Data byte 1 contains, + * among other info, the offset from the Threshold type + * code. According to Table 42-2, all even offsets + * are 'going low', and all odd offsets are 'going high' + */ + bool going_high = + (evt->sel_type.standard_type.event_data[0] + & EVENT_OFFSET_MASK) % 2; + if (evt->sel_type.standard_type.event_dir) { + /* Event is de-asserted so the inequality is reversed */ + going_high = !going_high; + } printf(" %s Threshold %.*f %s", - ((evt->sel_type.standard_type.event_data[0] & 0xf) % 2) ? ">" : "<", + going_high ? ">" : "<", (threshold_reading==(int)threshold_reading) ? 0 : 2, threshold_reading, ipmi_sdr_get_unit_string(sdr->record.common->unit.pct, @@ -1933,9 +1983,12 @@ ipmi_sel_print_std_entry(struct ipmi_intf * intf, struct sel_event_record * evt) case IPMI_OEM_SUPERMICRO: case IPMI_OEM_SUPERMICRO_47488: print_sensor = 0; - break; + break; + case IPMI_OEM_QUANTA: + print_sensor = 0; + break; default: - break; + break; } /* * Sensor-Specific Discrete @@ -1990,11 +2043,11 @@ ipmi_sel_print_std_entry_verbose(struct ipmi_intf * intf, struct sel_event_recor { printf(" Timestamp : "); if (evt->record_type < 0xc0) - printf("%s %s", ipmi_sel_timestamp_date(evt->sel_type.standard_type.timestamp), - ipmi_sel_timestamp_time(evt->sel_type.standard_type.timestamp)); + printf("%s %s", ipmi_timestamp_date(evt->sel_type.standard_type.timestamp), + ipmi_timestamp_time(evt->sel_type.standard_type.timestamp)); else - printf("%s %s", ipmi_sel_timestamp_date(evt->sel_type.oem_ts_type.timestamp), - ipmi_sel_timestamp_time(evt->sel_type.oem_ts_type.timestamp)); + printf("%s %s", ipmi_timestamp_date(evt->sel_type.oem_ts_type.timestamp), + ipmi_timestamp_time(evt->sel_type.oem_ts_type.timestamp)); printf("\n"); } @@ -2015,7 +2068,7 @@ ipmi_sel_print_std_entry_verbose(struct ipmi_intf * intf, struct sel_event_recor for(data_count=0;data_count < SEL_OEM_NOTS_DATA_LEN;data_count++) printf("%02x", evt->sel_type.oem_nots_type.oem_defined[data_count]); printf(" [%s]\n\n",hex2ascii (evt->sel_type.oem_nots_type.oem_defined, SEL_OEM_NOTS_DATA_LEN)); - ipmi_sel_oem_message(evt, 1); + ipmi_sel_oem_message(evt); } return; } @@ -2025,14 +2078,8 @@ ipmi_sel_print_std_entry_verbose(struct ipmi_intf * intf, struct sel_event_recor printf(" EvM Revision : %02x\n", evt->sel_type.standard_type.evm_rev); printf(" Sensor Type : %s\n", - ( - (evt->sel_type.standard_type.sensor_type >=0xC0 && evt->sel_type.standard_type.sensor_type < 0xF0) - ? - ipmi_sel_get_oem_sensor_type_offset(ipmi_get_oem(intf),evt->sel_type.standard_type.sensor_type, evt->sel_type.standard_type.event_data[0]) - : - ipmi_sel_get_sensor_type_offset(evt->sel_type.standard_type.sensor_type, evt->sel_type.standard_type.event_data[0]) - ) - ); + ipmi_get_sensor_type(intf, + evt->sel_type.standard_type.sensor_type)); printf(" Sensor Number : %02x\n", evt->sel_type.standard_type.sensor_num); printf(" Event Type : %s\n", @@ -2064,7 +2111,7 @@ ipmi_sel_print_extended_entry_verbose(struct ipmi_intf * intf, struct sel_event_ evt->sel_type.standard_type.gen_id, evt->sel_type.standard_type.sensor_num, evt->sel_type.standard_type.sensor_type); - if (sdr == NULL) + if (!sdr) { ipmi_sel_print_std_entry_verbose(intf, evt); return; @@ -2086,8 +2133,8 @@ ipmi_sel_print_extended_entry_verbose(struct ipmi_intf * intf, struct sel_event_ if (evt->record_type < 0xe0) { printf(" Timestamp : "); - printf("%s %s\n", ipmi_sel_timestamp_date(evt->sel_type.standard_type.timestamp), - ipmi_sel_timestamp_time(evt->sel_type.standard_type.timestamp)); + printf("%s %s\n", ipmi_timestamp_date(evt->sel_type.standard_type.timestamp), + ipmi_timestamp_time(evt->sel_type.standard_type.timestamp)); } @@ -2096,7 +2143,7 @@ ipmi_sel_print_extended_entry_verbose(struct ipmi_intf * intf, struct sel_event_ printf(" EvM Revision : %02x\n", evt->sel_type.standard_type.evm_rev); printf(" Sensor Type : %s\n", - ipmi_sel_get_sensor_type_offset(evt->sel_type.standard_type.sensor_type, evt->sel_type.standard_type.event_data[0])); + ipmi_get_sensor_type(intf, evt->sel_type.standard_type.sensor_type)); printf(" Sensor Number : %02x\n", evt->sel_type.standard_type.sensor_num); printf(" Event Type : %s\n", @@ -2221,11 +2268,11 @@ __ipmi_sel_savelist_entries(struct ipmi_intf * intf, int count, const char * sav req.msg.cmd = IPMI_CMD_GET_SEL_INFO; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Get SEL Info command failed"); return -1; } - if (rsp->ccode > 0) { + if (rsp->ccode) { lprintf(LOG_ERR, "Get SEL Info command failed: %s", val2str(rsp->ccode, completion_code_vals)); return -1; @@ -2238,33 +2285,18 @@ __ipmi_sel_savelist_entries(struct ipmi_intf * intf, int count, const char * sav return 0; } - memset(&req, 0, sizeof(req)); - req.msg.netfn = IPMI_NETFN_STORAGE; - req.msg.cmd = IPMI_CMD_RESERVE_SEL; - - rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { - lprintf(LOG_ERR, "Reserve SEL command failed"); - return -1; - } - if (rsp->ccode > 0) { - lprintf(LOG_ERR, "Reserve SEL command failed: %s", - val2str(rsp->ccode, completion_code_vals)); - return -1; - } - if (count < 0) { /** Show only the most recent 'count' records. */ - int delta; + int i; uint16_t entries; req.msg.cmd = IPMI_CMD_GET_SEL_INFO; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Get SEL Info command failed"); return -1; } - if (rsp->ccode > 0) { + if (rsp->ccode) { lprintf(LOG_ERR, "Get SEL Info command failed: %s", val2str(rsp->ccode, completion_code_vals)); return -1; @@ -2273,18 +2305,23 @@ __ipmi_sel_savelist_entries(struct ipmi_intf * intf, int count, const char * sav if (-count > entries) count = -entries; - /* Get first record. */ - next_id = ipmi_sel_get_std_entry(intf, 0, &evt); - - delta = next_id - evt.record_id; - - /* Get last record. */ - next_id = ipmi_sel_get_std_entry(intf, 0xffff, &evt); - - next_id = evt.record_id + count * delta + delta; + for(i = 0; i < entries + count; i++) { + next_id = ipmi_sel_get_std_entry(intf, next_id, &evt); + if (next_id == 0) { + /* + * usually next_id of zero means end but + * retry because some hardware has quirks + * and will return 0 randomly. + */ + next_id = ipmi_sel_get_std_entry(intf, next_id, &evt); + if (next_id == 0) { + break; + } + } + } } - if (savefile != NULL) { + if (savefile) { fp = ipmi_open_file_write(savefile); } @@ -2309,7 +2346,7 @@ __ipmi_sel_savelist_entries(struct ipmi_intf * intf, int count, const char * sav else ipmi_sel_print_std_entry(intf, &evt); - if (fp != NULL) { + if (fp) { if (binary) fwrite(&evt, 1, 16, fp); else @@ -2321,7 +2358,7 @@ __ipmi_sel_savelist_entries(struct ipmi_intf * intf, int count, const char * sav } } - if (fp != NULL) + if (fp) fclose(fp); return 0; @@ -2358,7 +2395,7 @@ ipmi_sel_interpret(struct ipmi_intf *intf, unsigned long iana, * the command line */ sel_iana = iana; - if (strncmp("pps", format, 3) == 0) { + if (!strcmp("pps", format)) { /* Parser for the following format */ /* 0x001F: Event: at Mar 27 06:41:10 2007;from:(0x9a,0,7); * sensor:(0xc3,119); event:0x6f(asserted): 0xA3 0x00 0x88 @@ -2366,13 +2403,13 @@ ipmi_sel_interpret(struct ipmi_intf *intf, unsigned long iana, * Supports a tweak for hotswap events that are already interpreted. */ fp = ipmi_open_file(readfile, 0); - if (fp == NULL) { + if (!fp) { lprintf(LOG_ERR, "Failed to open file '%s' for reading.", readfile); return (-1); } buffer = (char *)malloc((size_t)256); - if (buffer == NULL) { + if (!buffer) { lprintf(LOG_ERR, "ipmitool: malloc failure"); fclose(fp); return (-1); @@ -2381,7 +2418,7 @@ ipmi_sel_interpret(struct ipmi_intf *intf, unsigned long iana, /* Only allow complete lines to be parsed, * hardcoded maximum line length */ - if (fgets(buffer, 256, fp) == NULL) { + if (!fgets(buffer, 256, fp)) { status = (-1); break; } @@ -2402,7 +2439,7 @@ ipmi_sel_interpret(struct ipmi_intf *intf, unsigned long iana, evt.sel_type.standard_type.evm_rev = 4; /* FIXME: convert*/ - evt.sel_type.standard_type.timestamp; + /* evt.sel_type.standard_type.timestamp; */ /* skip timestamp */ cursor = index((const char *)cursor, ';'); @@ -2635,11 +2672,11 @@ ipmi_sel_reserve(struct ipmi_intf * intf) req.msg.cmd = IPMI_CMD_RESERVE_SEL; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_WARN, "Unable to reserve SEL"); return 0; } - if (rsp->ccode > 0) { + if (rsp->ccode) { printf("Unable to reserve SEL: %s", val2str(rsp->ccode, completion_code_vals)); return 0; @@ -2661,8 +2698,6 @@ ipmi_sel_get_time(struct ipmi_intf * intf) { struct ipmi_rs * rsp; struct ipmi_rq req; - static char tbuf[40]; - uint32_t timei; time_t time; memset(&req, 0, sizeof(req)); @@ -2671,13 +2706,12 @@ ipmi_sel_get_time(struct ipmi_intf * intf) rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { - lprintf(LOG_ERR, "Get SEL Time command failed"); - return -1; - } - if (rsp->ccode > 0) { + if (!rsp || rsp->ccode) { lprintf(LOG_ERR, "Get SEL Time command failed: %s", - val2str(rsp->ccode, completion_code_vals)); + rsp + ? val2str(rsp->ccode, completion_code_vals) + : "Unknown" + ); return -1; } if (rsp->data_len != 4) { @@ -2686,15 +2720,8 @@ ipmi_sel_get_time(struct ipmi_intf * intf) return -1; } - memcpy(&timei, rsp->data, 4); -#if WORDS_BIGENDIAN - time = (time_t)(BSWAP_32(timei)); -#else - time = (time_t)timei; -#endif - - strftime(tbuf, sizeof(tbuf), "%m/%d/%Y %H:%M:%S", gmtime(&time)); - printf("%s\n", tbuf); + time = ipmi32toh(rsp->data); + printf("%s\n", ipmi_timestamp_numeric(time)); return 0; } @@ -2710,76 +2737,65 @@ ipmi_sel_get_time(struct ipmi_intf * intf) static int ipmi_sel_set_time(struct ipmi_intf * intf, const char * time_string) { - struct ipmi_rs * rsp; - struct ipmi_rq req; - struct tm tm = {0}; - time_t t; - uint32_t timei; - const char * time_format = "%m/%d/%Y %H:%M:%S"; + struct ipmi_rs *rsp; + struct ipmi_rq req; + struct tm tm = {0}; + uint8_t msg_data[4] = {0}; + time_t t; + const char *time_format = "%x %X"; /* Use locale-defined format */ memset(&req, 0, sizeof(req)); req.msg.netfn = IPMI_NETFN_STORAGE; req.msg.cmd = IPMI_SET_SEL_TIME; /* See if user requested set to current client system time */ - if (strncasecmp(time_string, "now", 3) == 0) { + if (strcasecmp(time_string, "now") == 0) { t = time(NULL); + /* + * Now we have local time in t, but BMC requires UTC + */ + t = ipmi_localtime2utc(t); } else { - /* Now how do we get our time_t from our ascii version? */ - if (strptime(time_string, time_format, &tm) == 0) { - lprintf(LOG_ERR, "Specified time could not be parsed"); - return -1; + bool error = true; /* Assume the string is invalid */ + /* Now let's extract time_t from the supplied string */ + if (strptime(time_string, time_format, &tm) != NULL) { + tm.tm_isdst = (-1); /* look up DST information */ + t = mktime(&tm); + if (t >= 0) { + /* Surprisingly, the user hasn't mistaken ;) */ + error = false; + } } - tm.tm_isdst = (-1); /* look up DST information */ - t = mktime(&tm); - if (t < 0) { + + if (error) { lprintf(LOG_ERR, "Specified time could not be parsed"); return -1; } + + /* + * If `-c` wasn't specified then t we've just got is in local timesone + */ + if (!time_in_utc) { + t = ipmi_localtime2utc(t); + } } - { - //modify UTC time to local time expressed in number of seconds from 1/1/70 0:0:0 1970 GMT - struct tm * tm_tmp = {0}; - int gt_year,gt_yday,gt_hour,gt_min,lt_year,lt_yday,lt_hour,lt_min; - int delta_hour; - tm_tmp=gmtime(&t); - gt_year=tm_tmp->tm_year; - gt_yday=tm_tmp->tm_yday; - gt_hour=tm_tmp->tm_hour; - gt_min=tm_tmp->tm_min; - memset(&*tm_tmp, 0, sizeof(struct tm)); - tm_tmp=localtime(&t); - lt_year=tm_tmp->tm_year; - lt_yday=tm_tmp->tm_yday; - lt_hour=tm_tmp->tm_hour; - lt_min=tm_tmp->tm_min; - delta_hour=lt_hour - gt_hour; - if ( (lt_year > gt_year) || ((lt_year == gt_year) && (lt_yday > gt_yday)) ) - delta_hour += 24; - if ( (lt_year < gt_year) || ((lt_year == gt_year) && (lt_yday < gt_yday)) ) - delta_hour -= 24; - - t += (delta_hour * 60 * 60) + (lt_min - gt_min) * 60; - } - - timei = (uint32_t)t; - req.msg.data = (uint8_t *)&timei; - req.msg.data_len = 4; - -#if WORDS_BIGENDIAN - timei = BSWAP_32(timei); -#endif + /* + * At this point `t` is UTC. Convert it to LE and send. + */ + + req.msg.data = msg_data; + htoipmi32(t, req.msg.data); + req.msg.data_len = sizeof(msg_data); rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { - lprintf(LOG_ERR, "Set SEL Time command failed"); - return -1; - } - if (rsp->ccode > 0) { + if (!rsp || rsp->ccode) { lprintf(LOG_ERR, "Set SEL Time command failed: %s", - val2str(rsp->ccode, completion_code_vals)); + rsp + ? val2str(rsp->ccode, completion_code_vals) + : "Unknown" + ); return -1; } @@ -2788,8 +2804,6 @@ ipmi_sel_set_time(struct ipmi_intf * intf, const char * time_string) return 0; } - - static int ipmi_sel_clear(struct ipmi_intf * intf) { @@ -2817,11 +2831,11 @@ ipmi_sel_clear(struct ipmi_intf * intf) req.msg.data_len = 6; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Unable to clear SEL"); return -1; } - if (rsp->ccode > 0) { + if (rsp->ccode) { lprintf(LOG_ERR, "Unable to clear SEL: %s", val2str(rsp->ccode, completion_code_vals)); return -1; @@ -2840,7 +2854,7 @@ ipmi_sel_delete(struct ipmi_intf * intf, int argc, char ** argv) uint8_t msg_data[4]; int rc = 0; - if (argc == 0 || strncmp(argv[0], "help", 4) == 0) { + if (!argc || !strcmp(argv[0], "help")) { lprintf(LOG_ERR, "usage: delete <id>...<id>\n"); return -1; } @@ -2871,11 +2885,11 @@ ipmi_sel_delete(struct ipmi_intf * intf, int argc, char ** argv) req.msg.data_len = 4; rsp = intf->sendrecv(intf, &req); - if (rsp == NULL) { + if (!rsp) { lprintf(LOG_ERR, "Unable to delete entry %d", id); rc = -1; } - else if (rsp->ccode > 0) { + else if (rsp->ccode) { lprintf(LOG_ERR, "Unable to delete entry %d: %s", id, val2str(rsp->ccode, completion_code_vals)); rc = -1; @@ -2901,16 +2915,11 @@ ipmi_sel_show_entry(struct ipmi_intf * intf, int argc, char ** argv) int rc = 0; uint16_t id; - if (argc == 0 || strncmp(argv[0], "help", 4) == 0) { + if (!argc || !strcmp(argv[0], "help")) { lprintf(LOG_ERR, "usage: sel get <id>...<id>"); return (-1); } - if (ipmi_sel_reserve(intf) == 0) { - lprintf(LOG_ERR, "Unable to reserve SEL"); - return (-1); - } - for (i = 0; i < argc; i++) { if (str2ushort(argv[i], &id) != 0) { lprintf(LOG_ERR, "Given SEL ID '%s' is invalid.", @@ -2942,7 +2951,7 @@ ipmi_sel_show_entry(struct ipmi_intf * intf, int argc, char ** argv) evt.sel_type.standard_type.gen_id, evt.sel_type.standard_type.sensor_num, evt.sel_type.standard_type.sensor_type); - if (sdr == NULL) { + if (!sdr) { continue; } @@ -2990,10 +2999,10 @@ int ipmi_sel_main(struct ipmi_intf * intf, int argc, char ** argv) if (argc == 0) rc = ipmi_sel_get_info(intf); - else if (strncmp(argv[0], "help", 4) == 0) + else if (!strcmp(argv[0], "help")) lprintf(LOG_ERR, "SEL Commands: " "info clear delete list elist get add time save readraw writeraw interpret"); - else if (strncmp(argv[0], "interpret", 9) == 0) { + else if (!strcmp(argv[0], "interpret")) { uint32_t iana = 0; if (argc < 4) { lprintf(LOG_NOTICE, "usage: sel interpret iana filename format(pps)"); @@ -3006,37 +3015,37 @@ int ipmi_sel_main(struct ipmi_intf * intf, int argc, char ** argv) } rc = ipmi_sel_interpret(intf, iana, argv[2], argv[3]); } - else if (strncmp(argv[0], "info", 4) == 0) + else if (!strcmp(argv[0], "info")) rc = ipmi_sel_get_info(intf); - else if (strncmp(argv[0], "save", 4) == 0) { + else if (!strcmp(argv[0], "save")) { if (argc < 2) { lprintf(LOG_NOTICE, "usage: sel save <filename>"); return 0; } rc = ipmi_sel_save_entries(intf, 0, argv[1]); } - else if (strncmp(argv[0], "add", 3) == 0) { + else if (!strcmp(argv[0], "add")) { if (argc < 2) { lprintf(LOG_NOTICE, "usage: sel add <filename>"); return 0; } rc = ipmi_sel_add_entries_fromfile(intf, argv[1]); } - else if (strncmp(argv[0], "writeraw", 8) == 0) { + else if (!strcmp(argv[0], "writeraw")) { if (argc < 2) { lprintf(LOG_NOTICE, "usage: sel writeraw <filename>"); return 0; } rc = ipmi_sel_writeraw(intf, argv[1]); } - else if (strncmp(argv[0], "readraw", 7) == 0) { + else if (!strcmp(argv[0], "readraw")) { if (argc < 2) { lprintf(LOG_NOTICE, "usage: sel readraw <filename>"); return 0; } rc = ipmi_sel_readraw(intf, argv[1]); } - else if (strncmp(argv[0], "ereadraw", 8) == 0) { + else if (!strcmp(argv[0], "ereadraw")) { if (argc < 2) { lprintf(LOG_NOTICE, "usage: sel ereadraw <filename>"); return 0; @@ -3044,8 +3053,9 @@ int ipmi_sel_main(struct ipmi_intf * intf, int argc, char ** argv) sel_extended = 1; rc = ipmi_sel_readraw(intf, argv[1]); } - else if (strncmp(argv[0], "list", 4) == 0 || - strncmp(argv[0], "elist", 5) == 0) { + else if (!strcmp(argv[0], "list") + || !strcmp(argv[0], "elist")) + { /* * Usage: * list - show all SEL entries @@ -3056,7 +3066,7 @@ int ipmi_sel_main(struct ipmi_intf * intf, int argc, char ** argv) int sign = 1; char *countstr = NULL; - if (strncmp(argv[0], "elist", 5) == 0) + if (!strcmp(argv[0], "elist")) sel_extended = 1; else sel_extended = 0; @@ -3067,10 +3077,10 @@ int ipmi_sel_main(struct ipmi_intf * intf, int argc, char ** argv) else if (argc == 3) { countstr = argv[2]; - if (strncmp(argv[1], "last", 4) == 0) { + if (!strcmp(argv[1], "last")) { sign = -1; } - else if (strncmp(argv[1], "first", 5) != 0) { + else if (strcmp(argv[1], "first")) { lprintf(LOG_ERR, "Unknown sel list option"); return -1; } @@ -3087,26 +3097,26 @@ int ipmi_sel_main(struct ipmi_intf * intf, int argc, char ** argv) rc = ipmi_sel_list_entries(intf,count); } - else if (strncmp(argv[0], "clear", 5) == 0) + else if (!strcmp(argv[0], "clear")) rc = ipmi_sel_clear(intf); - else if (strncmp(argv[0], "delete", 6) == 0) { + else if (!strcmp(argv[0], "delete")) { if (argc < 2) lprintf(LOG_ERR, "usage: sel delete <id>...<id>"); else rc = ipmi_sel_delete(intf, argc-1, &argv[1]); } - else if (strncmp(argv[0], "get", 3) == 0) { + else if (!strcmp(argv[0], "get")) { if (argc < 2) lprintf(LOG_ERR, "usage: sel get <entry>"); else rc = ipmi_sel_show_entry(intf, argc-1, &argv[1]); } - else if (strncmp(argv[0], "time", 4) == 0) { + else if (!strcmp(argv[0], "time")) { if (argc < 2) lprintf(LOG_ERR, "sel time commands: get set"); - else if (strncmp(argv[1], "get", 3) == 0) + else if (!strcmp(argv[1], "get")) ipmi_sel_get_time(intf); - else if (strncmp(argv[1], "set", 3) == 0) { + else if (!strcmp(argv[1], "set")) { if (argc < 3) lprintf(LOG_ERR, "usage: sel time set \"mm/dd/yyyy hh:mm:ss\""); else |