diff --git a/ipmitool/include/ipmitool/helper.h b/ipmitool/include/ipmitool/helper.h index c8d1fff..470c61b 100644 --- a/ipmitool/include/ipmitool/helper.h +++ b/ipmitool/include/ipmitool/helper.h @@ -49,6 +49,7 @@ struct valstr { const char * val2str(uint16_t val, const struct valstr * vs); uint16_t str2val(const char * str, const struct valstr * vs); void print_valstr(const struct valstr * vs, const char * title, int loglevel); +void print_valstr_2col(const struct valstr * vs, const char * title, int loglevel); uint16_t buf2short(uint8_t * buf); diff --git a/ipmitool/lib/helper.c b/ipmitool/lib/helper.c index 759bf74..adf3c72 100644 --- a/ipmitool/lib/helper.c +++ b/ipmitool/lib/helper.c @@ -178,6 +178,54 @@ print_valstr(const struct valstr * vs, const char * title, int loglevel) lprintf(loglevel, ""); } +/* print_valstr_2col - print value string list in two columns to log or stdout + * + * @vs: value string list to print + * @title: name of this value string list + * @loglevel: what log level to print, -1 for stdout + */ +void +print_valstr_2col(const struct valstr * vs, const char * title, int loglevel) +{ + int i; + + if (vs == NULL) + return; + + if (title != NULL) { + if (loglevel < 0) + printf("\n%s:\n\n"); + else + lprintf(loglevel, "\n%s:\n", title); + } + + for (i = 0; vs[i].str != NULL; i++) { + if (vs[i+1].str == NULL) { + /* last one */ + if (loglevel < 0) { + printf(" %4d %-32s\n", vs[i].val, vs[i].str); + } else { + lprintf(loglevel, " %4d %-32s\n", vs[i].val, vs[i].str); + } + } + else { + if (loglevel < 0) { + printf(" %4d %-32s %4d %-32s\n", + vs[i].val, vs[i].str, vs[i+1].val, vs[i+1].str); + } else { + lprintf(loglevel, " %4d %-32s %4d %-32s\n", + vs[i].val, vs[i].str, vs[i+1].val, vs[i+1].str); + } + i++; + } + } + + if (loglevel < 0) + printf("\n"); + else + lprintf(loglevel, ""); +} + /* ipmi_csum - calculate an ipmi checksum * * @d: buffer to check diff --git a/ipmitool/lib/ipmi_sdr.c b/ipmitool/lib/ipmi_sdr.c index 5d32d46..99f0b2d 100644 --- a/ipmitool/lib/ipmi_sdr.c +++ b/ipmitool/lib/ipmi_sdr.c @@ -3868,9 +3868,11 @@ ipmi_sdr_print_entity(struct ipmi_intf *intf, char *entitystr) unsigned instance = 0; int rc = 0; - if (entitystr == NULL) { - lprintf(LOG_ERR, "No Entity ID supplied"); - return -1; + if (entitystr == NULL || + strncasecmp(entitystr, "help", 4) == 0 || + strncasecmp(entitystr, "list", 4) == 0) { + print_valstr_2col(entity_id_vals, "Entity IDs", -1); + return 0; } if (sscanf(entitystr, "%u.%u", &id, &instance) != 2) { @@ -3879,8 +3881,21 @@ ipmi_sdr_print_entity(struct ipmi_intf *intf, char *entitystr) * so set entity.instance = 0x7f to indicate this */ if (sscanf(entitystr, "%u", &id) != 1) { - lprintf(LOG_ERR, "Invalid entity: %s", entitystr); - return -1; + int i, j=0; + + /* now try string input */ + for (i = 0; entity_id_vals[i].str != NULL; i++) { + if (strncasecmp(entitystr, entity_id_vals[i].str, + __maxlen(entitystr, entity_id_vals[i].str)) == 0) { + entity.id = entity_id_vals[i].val; + entity.instance = 0x7f; + j=1; + } + } + if (j == 0) { + lprintf(LOG_ERR, "Invalid entity: %s", entitystr); + return -1; + } } else { entity.id = id; entity.instance = 0x7f;