mirror of
https://github.com/ipmitool/ipmitool.git
synced 2025-05-10 18:47:22 +00:00
fix sdr handling of sensors that do not return a reading
This commit is contained in:
parent
5c337dcdf6
commit
05df8eb9a2
@ -40,6 +40,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <netinet/in.h>
|
||||
#include <ipmitool/helper.h>
|
||||
|
||||
#define BUF_SIZE 256
|
||||
|
||||
@ -121,6 +122,6 @@ struct ipmi_intf {
|
||||
#define IPMI_BMC_SLAVE_ADDR 0x20
|
||||
#define IPMI_REMOTE_SWID 0x81
|
||||
|
||||
int handle_ipmi(struct ipmi_intf *intf, unsigned char * data, int data_len);
|
||||
const struct valstr completion_code_vals[25];
|
||||
|
||||
#endif /* IPMI_H */
|
||||
|
@ -44,6 +44,34 @@
|
||||
|
||||
extern int verbose;
|
||||
|
||||
const struct valstr completion_code_vals[] = {
|
||||
{ 0x00, "Command completed normally" },
|
||||
{ 0xc0, "Node busy" },
|
||||
{ 0xc1, "Invalid command" },
|
||||
{ 0xc2, "Invalid command on LUN" },
|
||||
{ 0xc3, "Timeout" },
|
||||
{ 0xc4, "Out of space" },
|
||||
{ 0xc5, "Reservation cancelled or invalid" },
|
||||
{ 0xc6, "Request data truncated" },
|
||||
{ 0xc7, "Request data length invalid" },
|
||||
{ 0xc8, "Request data field length limit exceeded" },
|
||||
{ 0xc9, "Parameter out of range" },
|
||||
{ 0xca, "Cannot return number of requested data bytes" },
|
||||
{ 0xcb, "Requested sensor, data, or record not found" },
|
||||
{ 0xcc, "Invalid data field in request" },
|
||||
{ 0xcd, "Command illegal for specified sensor or record type" },
|
||||
{ 0xce, "Command response could not be provided" },
|
||||
{ 0xcf, "Cannot execute duplicated request" },
|
||||
{ 0xd0, "SDR Repository in update mode" },
|
||||
{ 0xd1, "Device firmeware in update mode" },
|
||||
{ 0xd2, "BMC initialization in progress" },
|
||||
{ 0xd3, "Destination unavailable" },
|
||||
{ 0xd4, "Insufficient priviledge level" },
|
||||
{ 0xd5, "Command not supported in present state" },
|
||||
{ 0xff, "Unspecified error" },
|
||||
{ 0x00, NULL }
|
||||
};
|
||||
|
||||
static int ipmi_bmc_reset(struct ipmi_intf * intf, int cmd)
|
||||
{
|
||||
struct ipmi_rs * rsp;
|
||||
|
@ -86,9 +86,6 @@ ipmi_sdr_get_sensor_reading(struct ipmi_intf * intf, unsigned char sensor)
|
||||
|
||||
rsp = intf->sendrecv(intf, &req);
|
||||
|
||||
if (!rsp || rsp->ccode)
|
||||
return NULL;
|
||||
|
||||
return rsp;
|
||||
}
|
||||
|
||||
@ -343,7 +340,7 @@ ipmi_sdr_print_sensors(struct ipmi_intf * intf, int do_unit)
|
||||
struct sdr_get_rs * header;
|
||||
struct sdr_record_full_sensor * sensor;
|
||||
|
||||
int next = 0, i = 0, total;
|
||||
int next = 0, i = 0, total, validread;
|
||||
unsigned short reservation;
|
||||
float val;
|
||||
char sval[16], unitstr[16];
|
||||
@ -386,6 +383,7 @@ ipmi_sdr_print_sensors(struct ipmi_intf * intf, int do_unit)
|
||||
printf("SDR reserveration ID %04x\n", reservation);
|
||||
|
||||
while (next < total) {
|
||||
validread = 1;
|
||||
i = 0;
|
||||
|
||||
header = ipmi_sdr_get_header(intf, reservation, next);
|
||||
@ -421,14 +419,21 @@ ipmi_sdr_print_sensors(struct ipmi_intf * intf, int do_unit)
|
||||
|
||||
rsp = ipmi_sdr_get_sensor_reading(intf, sensor->keys.sensor_num);
|
||||
if (!rsp || rsp->ccode) {
|
||||
printf("error reading sensor\n");
|
||||
continue;
|
||||
if (rsp && rsp->ccode == 0xcb) {
|
||||
/* sensor not found */
|
||||
val = 0.0;
|
||||
validread = 0;
|
||||
} else {
|
||||
printf("Error reading sensor: %s\n",
|
||||
val2str(rsp->ccode, completion_code_vals));
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
/* convert RAW reading into units */
|
||||
val = rsp->data[0] ? sdr_convert_sensor_reading(sensor, rsp->data[0]) : 0;
|
||||
}
|
||||
|
||||
/* convert RAW reading into units */
|
||||
val = rsp->data[0] ? sdr_convert_sensor_reading(sensor, rsp->data[0]) : 0;
|
||||
|
||||
if (do_unit) {
|
||||
if (do_unit && validread) {
|
||||
memset(unitstr, 0, sizeof(unitstr));
|
||||
/* determine units with possible modifiers */
|
||||
switch (sensor->unit.modifier) {
|
||||
@ -462,11 +467,16 @@ ipmi_sdr_print_sensors(struct ipmi_intf * intf, int do_unit)
|
||||
sensor->id_code ? desc : NULL);
|
||||
|
||||
memset(sval, 0, sizeof(sval));
|
||||
i += snprintf(sval, sizeof(sval), "%.*f",
|
||||
(val==(int)val) ? 0 : 3, val);
|
||||
if (validread) {
|
||||
i += snprintf(sval, sizeof(sval), "%.*f",
|
||||
(val==(int)val) ? 0 : 3, val);
|
||||
} else {
|
||||
i += snprintf(sval, sizeof(sval), "no reading");
|
||||
i--;
|
||||
}
|
||||
printf("%s", sval);
|
||||
|
||||
if (do_unit)
|
||||
if (do_unit && validread)
|
||||
printf(" %s", unitstr);
|
||||
|
||||
if (csv_output)
|
||||
@ -487,8 +497,11 @@ ipmi_sdr_print_sensors(struct ipmi_intf * intf, int do_unit)
|
||||
printf("Entity | %d.%d (%s)\n",
|
||||
sensor->entity.id, sensor->entity.instance,
|
||||
val2str(sensor->entity.id, entity_id_vals));
|
||||
printf("Reading | %.*f %s\n",
|
||||
(val==(int)val) ? 0 : 3, val, unitstr);
|
||||
if (validread)
|
||||
printf("Reading | %.*f %s\n",
|
||||
(val==(int)val) ? 0 : 3, val, unitstr);
|
||||
else
|
||||
printf("Reading | not present\n");
|
||||
printf("Status | %s\n",
|
||||
ipmi_sdr_get_status(rsp->data[2]));
|
||||
printf("\n");
|
||||
|
Loading…
x
Reference in New Issue
Block a user