mirror of
https://github.com/ipmitool/ipmitool.git
synced 2025-05-10 18:47:22 +00:00
let entity id be specified as string
This commit is contained in:
parent
bfe06ebd98
commit
1196369aaf
@ -49,6 +49,7 @@ struct valstr {
|
|||||||
const char * val2str(uint16_t val, const struct valstr * vs);
|
const char * val2str(uint16_t val, const struct valstr * vs);
|
||||||
uint16_t str2val(const char * str, 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(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);
|
uint16_t buf2short(uint8_t * buf);
|
||||||
|
@ -178,6 +178,54 @@ print_valstr(const struct valstr * vs, const char * title, int loglevel)
|
|||||||
lprintf(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
|
/* ipmi_csum - calculate an ipmi checksum
|
||||||
*
|
*
|
||||||
* @d: buffer to check
|
* @d: buffer to check
|
||||||
|
@ -3868,9 +3868,11 @@ ipmi_sdr_print_entity(struct ipmi_intf *intf, char *entitystr)
|
|||||||
unsigned instance = 0;
|
unsigned instance = 0;
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
|
|
||||||
if (entitystr == NULL) {
|
if (entitystr == NULL ||
|
||||||
lprintf(LOG_ERR, "No Entity ID supplied");
|
strncasecmp(entitystr, "help", 4) == 0 ||
|
||||||
return -1;
|
strncasecmp(entitystr, "list", 4) == 0) {
|
||||||
|
print_valstr_2col(entity_id_vals, "Entity IDs", -1);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sscanf(entitystr, "%u.%u", &id, &instance) != 2) {
|
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
|
* so set entity.instance = 0x7f to indicate this
|
||||||
*/
|
*/
|
||||||
if (sscanf(entitystr, "%u", &id) != 1) {
|
if (sscanf(entitystr, "%u", &id) != 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);
|
lprintf(LOG_ERR, "Invalid entity: %s", entitystr);
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
entity.id = id;
|
entity.id = id;
|
||||||
entity.instance = 0x7f;
|
entity.instance = 0x7f;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user