mirror of
https://github.com/ipmitool/ipmitool.git
synced 2025-05-10 18:47:22 +00:00
add support for entering netfn as a string for raw commands
This commit is contained in:
parent
1fe48e8a36
commit
694f92918f
@ -48,6 +48,8 @@ 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);
|
||||||
|
|
||||||
|
|
||||||
uint16_t buf2short(uint8_t * buf);
|
uint16_t buf2short(uint8_t * buf);
|
||||||
uint32_t buf2long(uint8_t * buf);
|
uint32_t buf2long(uint8_t * buf);
|
||||||
|
@ -42,7 +42,7 @@
|
|||||||
extern const struct valstr completion_code_vals[];
|
extern const struct valstr completion_code_vals[];
|
||||||
extern const struct valstr entity_id_vals[];
|
extern const struct valstr entity_id_vals[];
|
||||||
extern const struct valstr entity_device_type_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_channel_activity_type_vals[];
|
||||||
extern const struct valstr ipmi_privlvl_vals[];
|
extern const struct valstr ipmi_privlvl_vals[];
|
||||||
extern const struct valstr impi_bit_rate_vals[];
|
extern const struct valstr impi_bit_rate_vals[];
|
||||||
|
@ -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)
|
const char * val2str(uint16_t val, const struct valstr *vs)
|
||||||
{
|
{
|
||||||
static char un_str[16];
|
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)
|
if (vs[i].val == val)
|
||||||
return vs[i].str;
|
return vs[i].str;
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(un_str, 0, 16);
|
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)
|
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)
|
if (strncasecmp(vs[i].str, str, __maxlen(str, vs[i].str)) == 0)
|
||||||
return vs[i].val;
|
return vs[i].val;
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return vs[i].val;
|
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
|
/* ipmi_csum - calculate an ipmi checksum
|
||||||
*
|
*
|
||||||
* @d: buffer to check
|
* @d: buffer to check
|
||||||
|
@ -43,6 +43,7 @@
|
|||||||
#include <ipmitool/helper.h>
|
#include <ipmitool/helper.h>
|
||||||
#include <ipmitool/ipmi_intf.h>
|
#include <ipmitool/ipmi_intf.h>
|
||||||
#include <ipmitool/ipmi_raw.h>
|
#include <ipmitool/ipmi_raw.h>
|
||||||
|
#include <ipmitool/ipmi_strings.h>
|
||||||
|
|
||||||
#define IPMI_I2C_MASTER_MAX_SIZE 0x40
|
#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;
|
struct ipmi_rq req;
|
||||||
uint8_t netfn, cmd;
|
uint8_t netfn, cmd;
|
||||||
int i;
|
int i;
|
||||||
|
unsigned long ufn;
|
||||||
|
|
||||||
uint8_t data[256];
|
uint8_t data[256];
|
||||||
|
|
||||||
if (argc < 2 || strncmp(argv[0], "help", 4) == 0) {
|
if (argc < 2 || strncmp(argv[0], "help", 4) == 0) {
|
||||||
lprintf(LOG_NOTICE, "RAW Commands: raw <netfn> <cmd> [data]");
|
lprintf(LOG_NOTICE, "RAW Commands: raw <netfn> <cmd> [data]");
|
||||||
|
print_valstr(ipmi_netfn_vals, "Network Function Codes", LOG_NOTICE);
|
||||||
|
lprintf(LOG_NOTICE, "(can also use raw hex values)");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
else if (argc > sizeof(data))
|
else if (argc > sizeof(data))
|
||||||
@ -219,7 +223,11 @@ ipmi_raw_main(struct ipmi_intf * intf, int argc, char ** argv)
|
|||||||
return -1;
|
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);
|
cmd = (uint8_t)strtol(argv[1], NULL, 0);
|
||||||
|
|
||||||
memset(data, 0, sizeof(data));
|
memset(data, 0, sizeof(data));
|
||||||
|
@ -39,6 +39,16 @@
|
|||||||
#include <ipmitool/ipmi_constants.h>
|
#include <ipmitool/ipmi_constants.h>
|
||||||
#include <ipmitool/ipmi_sensor.h>
|
#include <ipmitool/ipmi_sensor.h>
|
||||||
|
|
||||||
|
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
|
* From table 26-4 of the IPMI v2 specification
|
||||||
|
Loading…
x
Reference in New Issue
Block a user