diff --git a/ipmitool/include/ipmitool/helper.h b/ipmitool/include/ipmitool/helper.h index 695837c..c8d1fff 100644 --- a/ipmitool/include/ipmitool/helper.h +++ b/ipmitool/include/ipmitool/helper.h @@ -48,6 +48,8 @@ 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); + uint16_t buf2short(uint8_t * buf); uint32_t buf2long(uint8_t * buf); diff --git a/ipmitool/include/ipmitool/ipmi_strings.h b/ipmitool/include/ipmitool/ipmi_strings.h index 65f88aa..c1bee9d 100644 --- a/ipmitool/include/ipmitool/ipmi_strings.h +++ b/ipmitool/include/ipmitool/ipmi_strings.h @@ -42,7 +42,7 @@ extern const struct valstr completion_code_vals[]; extern const struct valstr entity_id_vals[]; extern const struct valstr entity_device_type_vals[]; - +extern const struct valstr ipmi_netfn_vals[]; extern const struct valstr ipmi_channel_activity_type_vals[]; extern const struct valstr ipmi_privlvl_vals[]; extern const struct valstr impi_bit_rate_vals[]; diff --git a/ipmitool/lib/helper.c b/ipmitool/lib/helper.c index 16394ce..71c96f4 100644 --- a/ipmitool/lib/helper.c +++ b/ipmitool/lib/helper.c @@ -101,12 +101,11 @@ void printbuf(const uint8_t * buf, int len, const char * desc) const char * val2str(uint16_t val, const struct valstr *vs) { static char un_str[16]; - int i = 0; + int i; - while (vs[i].str != NULL) { + for (i = 0; vs[i].str != NULL; i++) { if (vs[i].val == val) return vs[i].str; - i++; } memset(un_str, 0, 16); @@ -117,17 +116,65 @@ const char * val2str(uint16_t val, const struct valstr *vs) uint16_t str2val(const char *str, const struct valstr *vs) { - int i = 0; + int i; - while (vs[i].str != NULL) { + for (i = 0; vs[i].str != NULL; i++) { if (strncasecmp(vs[i].str, str, __maxlen(str, vs[i].str)) == 0) return vs[i].val; - i++; } return vs[i].val; } +/* print_valstr - print value string list 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(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); + } + + if (loglevel < 0) { + printf(" VALUE\tHEX\tSTRING\n"); + printf("==============================================\n"); + } else { + lprintf(loglevel, " VAL\tHEX\tSTRING"); + lprintf(loglevel, "=============================================="); + } + + for (i = 0; vs[i].str != NULL; i++) { + if (loglevel < 0) { + if (vs[i].val < 256) + printf(" %d\t0x%02x\t%s\n", vs[i].val, vs[i].val, vs[i].str); + else + printf(" %d\t0x%04x\t%s\n", vs[i].val, vs[i].val, vs[i].str); + } else { + if (vs[i].val < 256) + lprintf(loglevel, " %d\t0x%02x\t%s", vs[i].val, vs[i].val, vs[i].str); + else + lprintf(loglevel, " %d\t0x%04x\t%s", vs[i].val, vs[i].val, vs[i].str); + } + } + + if (loglevel < 0) + printf("\n"); + else + lprintf(loglevel, ""); +} + /* ipmi_csum - calculate an ipmi checksum * * @d: buffer to check diff --git a/ipmitool/lib/ipmi_raw.c b/ipmitool/lib/ipmi_raw.c index c6dc72f..aa54157 100644 --- a/ipmitool/lib/ipmi_raw.c +++ b/ipmitool/lib/ipmi_raw.c @@ -43,6 +43,7 @@ #include #include #include +#include #define IPMI_I2C_MASTER_MAX_SIZE 0x40 @@ -206,11 +207,14 @@ ipmi_raw_main(struct ipmi_intf * intf, int argc, char ** argv) struct ipmi_rq req; uint8_t netfn, cmd; int i; + unsigned long ufn; uint8_t data[256]; if (argc < 2 || strncmp(argv[0], "help", 4) == 0) { lprintf(LOG_NOTICE, "RAW Commands: raw [data]"); + print_valstr(ipmi_netfn_vals, "Network Function Codes", LOG_NOTICE); + lprintf(LOG_NOTICE, "(can also use raw hex values)"); return -1; } else if (argc > sizeof(data)) @@ -219,7 +223,11 @@ ipmi_raw_main(struct ipmi_intf * intf, int argc, char ** argv) return -1; } - netfn = (uint8_t)strtol(argv[0], NULL, 0); + netfn = str2val(argv[0], ipmi_netfn_vals); + if (netfn == 0xff) { + netfn = (uint8_t)strtol(argv[0], NULL, 0); + } + cmd = (uint8_t)strtol(argv[1], NULL, 0); memset(data, 0, sizeof(data)); diff --git a/ipmitool/lib/ipmi_strings.c b/ipmitool/lib/ipmi_strings.c index 7d25528..51f006c 100644 --- a/ipmitool/lib/ipmi_strings.c +++ b/ipmitool/lib/ipmi_strings.c @@ -39,6 +39,16 @@ #include #include +const struct valstr ipmi_netfn_vals[] = { + { IPMI_NETFN_CHASSIS, "Chassis" }, + { IPMI_NETFN_BRIDGE, "Bridge" }, + { IPMI_NETFN_SE, "Sensor/Event" }, + { IPMI_NETFN_APP, "Application" }, + { IPMI_NETFN_FIRMWARE, "Firmware" }, + { IPMI_NETFN_STORAGE, "Storage" }, + { IPMI_NETFN_TRANSPORT, "Transport" }, + { 0xff, NULL }, +}; /* * From table 26-4 of the IPMI v2 specification