summaryrefslogtreecommitdiff
path: root/lib/ipmi_sdr.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/ipmi_sdr.c')
-rw-r--r--lib/ipmi_sdr.c735
1 files changed, 425 insertions, 310 deletions
diff --git a/lib/ipmi_sdr.c b/lib/ipmi_sdr.c
index 2a9cbe3..42ae9f9 100644
--- a/lib/ipmi_sdr.c
+++ b/lib/ipmi_sdr.c
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2012 Hewlett-Packard Development Company, L.P.
+ * Copyright 2020 Joyent, Inc.
*
* Based on code from
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
@@ -32,7 +33,6 @@
* LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE,
* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*/
-#define _BSD_SOURCE
#include <string.h>
@@ -53,6 +53,7 @@
#include <ipmitool/ipmi_entity.h>
#include <ipmitool/ipmi_constants.h>
#include <ipmitool/ipmi_strings.h>
+#include <ipmitool/ipmi_time.h>
#if HAVE_CONFIG_H
# include <config.h>
@@ -68,41 +69,211 @@ static struct sdr_record_list *sdr_list_head = NULL;
static struct sdr_record_list *sdr_list_tail = NULL;
static struct ipmi_sdr_iterator *sdr_list_itr = NULL;
-void printf_sdr_usage();
+/* IPMI 2.0 Table 43-15, Sensor Unit Type Codes */
+#define UNIT_TYPE_MAX 92 /* This is the ID of "grams" */
+#define UNIT_TYPE_LONGEST_NAME 19 /* This is the length of "color temp deg K" */
+static const char *unit_desc[] = {
+ "unspecified",
+ "degrees C",
+ "degrees F",
+ "degrees K",
+ "Volts",
+ "Amps",
+ "Watts",
+ "Joules",
+ "Coulombs",
+ "VA",
+ "Nits",
+ "lumen",
+ "lux",
+ "Candela",
+ "kPa",
+ "PSI",
+ "Newton",
+ "CFM",
+ "RPM",
+ "Hz",
+ "microsecond",
+ "millisecond",
+ "second",
+ "minute",
+ "hour",
+ "day",
+ "week",
+ "mil",
+ "inches",
+ "feet",
+ "cu in",
+ "cu feet",
+ "mm",
+ "cm",
+ "m",
+ "cu cm",
+ "cu m",
+ "liters",
+ "fluid ounce",
+ "radians",
+ "steradians",
+ "revolutions",
+ "cycles",
+ "gravities",
+ "ounce",
+ "pound",
+ "ft-lb",
+ "oz-in",
+ "gauss",
+ "gilberts",
+ "henry",
+ "millihenry",
+ "farad",
+ "microfarad",
+ "ohms",
+ "siemens",
+ "mole",
+ "becquerel",
+ "PPM",
+ "reserved",
+ "Decibels",
+ "DbA",
+ "DbC",
+ "gray",
+ "sievert",
+ "color temp deg K",
+ "bit",
+ "kilobit",
+ "megabit",
+ "gigabit",
+ "byte",
+ "kilobyte",
+ "megabyte",
+ "gigabyte",
+ "word",
+ "dword",
+ "qword",
+ "line",
+ "hit",
+ "miss",
+ "retry",
+ "reset",
+ "overflow",
+ "underrun",
+ "collision",
+ "packets",
+ "messages",
+ "characters",
+ "error",
+ "correctable error",
+ "uncorrectable error",
+ "fatal error",
+ "grams"
+};
+
+/* sensor type codes (IPMI v1.5 table 36.3)
+ / Updated to v2.0 Table 42-3, Sensor Type Codes */
+static const char *sensor_type_desc[] = {
+ "reserved",
+ "Temperature",
+ "Voltage",
+ "Current",
+ "Fan",
+ "Physical Security",
+ "Platform Security",
+ "Processor",
+ "Power Supply",
+ "Power Unit",
+ "Cooling Device",
+ "Other",
+ "Memory",
+ "Drive Slot / Bay",
+ "POST Memory Resize",
+ "System Firmwares",
+ "Event Logging Disabled",
+ "Watchdog1",
+ "System Event",
+ "Critical Interrupt",
+ "Button",
+ "Module / Board",
+ "Microcontroller",
+ "Add-in Card",
+ "Chassis",
+ "Chip Set",
+ "Other FRU",
+ "Cable / Interconnect",
+ "Terminator",
+ "System Boot Initiated",
+ "Boot Error",
+ "OS Boot",
+ "OS Critical Stop",
+ "Slot / Connector",
+ "System ACPI Power State",
+ "Watchdog2",
+ "Platform Alert",
+ "Entity Presence",
+ "Monitor ASIC",
+ "LAN",
+ "Management Subsys Health",
+ "Battery",
+ "Session Audit",
+ "Version Change",
+ "FRU State"
+};
-/* From src/plugins/ipmi_intf.c: */
-uint16_t
-ipmi_intf_get_max_response_data_size(struct ipmi_intf * intf);
+void printf_sdr_usage();
-/* ipmi_sdr_get_unit_string - return units for base/modifier
+/** ipmi_sdr_get_unit_string - return units for base/modifier
*
- * @pct: units are a percentage
- * @type: unit type
- * @base: base
- * @modifier: modifier
+ * @param[in] pct Indicates that units are a percentage
+ * @param[in] relation Modifier unit to base unit relation
+ * (SDR_UNIT_MOD_NONE, SDR_UNIT_MOD_MUL,
+ * or SDR_UNIT_MOD_DIV)
+ * @param[in] base The base unit type id
+ * @param[in] modifier The modifier unit type id
*
- * returns pointer to static string
+ * @returns a pointer to static string
*/
const char *
-ipmi_sdr_get_unit_string(uint8_t pct, uint8_t type, uint8_t base, uint8_t modifier)
+ipmi_sdr_get_unit_string(bool pct, uint8_t relation,
+ uint8_t base, uint8_t modifier)
{
- static char unitstr[16];
+ /*
+ * Twice as long as the longest possible unit name, plus
+ * two characters for '%' and relation (either '*' or '/'),
+ * plus the terminating null-byte.
+ */
+ static char unitstr[2 * UNIT_TYPE_LONGEST_NAME + 2 + 1];
+
/*
* By default, if units are supposed to be percent, we will pre-pend
* the percent string to the textual representation of the units.
*/
- char *pctstr = pct ? "% " : "";
- memset(unitstr, 0, sizeof (unitstr));
- switch (type) {
- case 2:
- snprintf(unitstr, sizeof (unitstr), "%s%s * %s",
- pctstr, unit_desc[base], unit_desc[modifier]);
+ const char *pctstr = pct ? "% " : "";
+ const char *basestr;
+ const char *modstr;
+
+ if (base <= UNIT_TYPE_MAX) {
+ basestr = unit_desc[base];
+ }
+ else {
+ basestr = "invalid";
+ }
+
+ if (modifier <= UNIT_TYPE_MAX) {
+ modstr = unit_desc[modifier];
+ }
+ else {
+ modstr = "invalid";
+ }
+
+ switch (relation) {
+ case SDR_UNIT_MOD_MUL:
+ snprintf(unitstr, sizeof (unitstr), "%s%s*%s",
+ pctstr, basestr, modstr);
break;
- case 1:
+ case SDR_UNIT_MOD_DIV:
snprintf(unitstr, sizeof (unitstr), "%s%s/%s",
- pctstr, unit_desc[base], unit_desc[modifier]);
+ pctstr, basestr, modstr);
break;
- case 0:
+ case SDR_UNIT_MOD_NONE:
default:
/*
* Display the text "percent" only when the Base unit is
@@ -111,8 +282,8 @@ ipmi_sdr_get_unit_string(uint8_t pct, uint8_t type, uint8_t base, uint8_t modifi
if (base == 0 && pct) {
snprintf(unitstr, sizeof(unitstr), "percent");
} else {
- snprintf(unitstr, sizeof (unitstr), "%s%s",
- pctstr, unit_desc[base]);
+ snprintf(unitstr, sizeof (unitstr), "%s%s",
+ pctstr, basestr);
}
break;
}
@@ -138,8 +309,8 @@ sdr_sensor_has_analog_reading(struct ipmi_intf *intf,
* But... HP didn't interpret this as meaning that "Only Threshold
* Sensors" can provide analog readings. So, HP packed analog
* readings into some of their non-Threshold Sensor. There is
- * nothing that explictly prohibits this in the spec, so if
- * an Analog reading is available in a Non-Threshod sensor and
+ * nothing that explicitly prohibits this in the spec, so if
+ * an Analog reading is available in a Non-Threshold sensor and
* there are units specified for identifying the reading then
* we do an analog conversion even though the sensor is
* non-Threshold. To be safe, we provide this extension for
@@ -205,7 +376,7 @@ sdr_convert_sensor_reading(struct sdr_record_full_sensor *sensor, uint8_t val)
case 1:
if (val & 0x80)
val++;
- /* Deliberately fall through to case 2. */
+ /* fall through */
case 2:
result = (double) (((m * (int8_t) val) +
(b * pow(10, k1))) * pow(10, k2));
@@ -285,7 +456,7 @@ sdr_convert_sensor_hysterisis(struct sdr_record_full_sensor *sensor, uint8_t val
case 1:
if (val & 0x80)
val++;
- /* Deliberately fall through to case 2. */
+ /* fall through */
case 2:
result = (double) (((m * (int8_t) val) ) * pow(10, k2));
break;
@@ -360,7 +531,7 @@ sdr_convert_sensor_tolerance(struct sdr_record_full_sensor *sensor, uint8_t val)
case 1:
if (val & 0x80)
val++;
- /* Deliberately fall through to case 2. */
+ /* fall through */
case 2:
result = (double) (((m * ((double)((int8_t) val)/2))) * pow(10, k2));
break;
@@ -691,7 +862,7 @@ ipmi_sdr_get_sensor_event_enable(struct ipmi_intf *intf, uint8_t sensor,
/* ipmi_sdr_get_thresh_status - threshold status indicator
*
- * @rsp: response from Get Sensor Reading comand
+ * @rsp: response from Get Sensor Reading command
* @validread: validity of the status field argument
* @invalidstr: string to return if status field is not valid
*
@@ -756,7 +927,7 @@ ipmi_sdr_get_thresh_status(struct sensor_reading *sr, const char *invalidstr)
return "ok";
}
-/* ipmi_sdr_get_header - retreive SDR record header
+/* ipmi_sdr_get_header - retrieve SDR record header
*
* @intf: ipmi interface
* @itr: sdr iterator
@@ -793,7 +964,7 @@ ipmi_sdr_get_header(struct ipmi_intf *intf, struct ipmi_sdr_iterator *itr)
for (try = 0; try < 5; try++) {
sdr_rq.reserve_id = itr->reservation;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Get SDR %04x command failed",
itr->next);
continue;
@@ -811,7 +982,7 @@ ipmi_sdr_get_header(struct ipmi_intf *intf, struct ipmi_sdr_iterator *itr)
"Unable to renew SDR reservation");
return NULL;
}
- } else if (rsp->ccode > 0) {
+ } else if (rsp->ccode) {
lprintf(LOG_ERR, "Get SDR %04x command failed: %s",
itr->next, val2str(rsp->ccode,
completion_code_vals));
@@ -859,7 +1030,7 @@ ipmi_sdr_get_header(struct ipmi_intf *intf, struct ipmi_sdr_iterator *itr)
return &sdr_rs;
}
-/* ipmi_sdr_get_next_header - retreive next SDR header
+/* ipmi_sdr_get_next_header - retrieve next SDR header
*
* @intf: ipmi interface
* @itr: sdr iterator
@@ -876,7 +1047,7 @@ ipmi_sdr_get_next_header(struct ipmi_intf *intf, struct ipmi_sdr_iterator *itr)
return NULL;
header = ipmi_sdr_get_header(intf, itr);
- if (header == NULL)
+ if (!header)
return NULL;
itr->next = header->next;
@@ -959,13 +1130,13 @@ ipmi_sdr_print_sensor_event_status(struct ipmi_intf *intf,
rsp = ipmi_sdr_get_sensor_event_status(intf, sensor_num,
target, lun, channel);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_DEBUG,
"Error reading event status for sensor #%02x",
sensor_num);
return -1;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_DEBUG,
"Error reading event status for sensor #%02x: %s",
sensor_num, val2str(rsp->ccode, completion_code_vals));
@@ -1173,13 +1344,13 @@ ipmi_sdr_print_sensor_event_enable(struct ipmi_intf *intf,
rsp = ipmi_sdr_get_sensor_event_enable(intf, sensor_num,
target, lun, channel);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_DEBUG,
"Error reading event enable for sensor #%02x",
sensor_num);
return -1;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_DEBUG,
"Error reading event enable for sensor #%02x: %s",
sensor_num, val2str(rsp->ccode, completion_code_vals));
@@ -1399,7 +1570,7 @@ ipmi_sdr_read_sensor_value(struct ipmi_intf *intf,
{
static struct sensor_reading sr;
- if (sensor == NULL)
+ if (!sensor)
return NULL;
/* Initialize to reading valid value of zero */
@@ -1439,7 +1610,7 @@ ipmi_sdr_read_sensor_value(struct ipmi_intf *intf,
sr.s_a_units = ""; /* no converted analog units units */
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_DEBUG, "Error reading sensor %s (#%02x)",
sr.s_id, sensor->keys.sensor_num);
return &sr;
@@ -1525,7 +1696,7 @@ ipmi_sdr_print_sensor_fc(struct ipmi_intf *intf,
sr = ipmi_sdr_read_sensor_value(intf, sensor, sdr_record_type, 2);
- if (sr == NULL)
+ if (!sr)
return -1;
target = sensor->keys.owner_id;
@@ -1978,7 +2149,7 @@ ipmi_sdr_print_discrete_state_mini(struct ipmi_intf *intf,
printf("%s", header);
for (evt = ipmi_get_first_event_sensor_type(intf, sensor_type, event_type);
- evt != NULL; evt = ipmi_get_next_event_sensor_type(evt)) {
+ evt; evt = ipmi_get_next_event_sensor_type(evt)) {
if (evt->data != 0xFF) {
continue;
}
@@ -2028,7 +2199,7 @@ ipmi_sdr_print_discrete_state(struct ipmi_intf *intf, const char *desc,
return;
for (evt = ipmi_get_first_event_sensor_type(intf, sensor_type, event_type);
- evt != NULL; evt = ipmi_get_next_event_sensor_type(evt)) {
+ evt; evt = ipmi_get_next_event_sensor_type(evt)) {
if (evt->data != 0xFF) {
continue;
}
@@ -2080,11 +2251,11 @@ ipmi_sdr_print_sensor_eventonly(struct ipmi_intf *intf,
{
char desc[17];
- if (sensor == NULL)
+ if (!sensor)
return -1;
memset(desc, 0, sizeof (desc));
- snprintf(desc, (sensor->id_code & 0x1f) + 1, "%s", sensor->id_string);
+ snprintf(desc, sizeof(desc), "%.*s", (sensor->id_code & 0x1f) + 1, sensor->id_string);
if (verbose) {
printf("Sensor ID : %s (0x%x)\n",
@@ -2119,23 +2290,21 @@ ipmi_sdr_print_sensor_eventonly(struct ipmi_intf *intf,
/* ipmi_sdr_print_sensor_mc_locator - print SDR MC locator record
*
- * @intf: ipmi interface
* @mc: mc locator sdr record
*
* returns 0 on success
* returns -1 on error
*/
int
-ipmi_sdr_print_sensor_mc_locator(struct ipmi_intf *intf,
- struct sdr_record_mc_locator *mc)
+ipmi_sdr_print_sensor_mc_locator(struct sdr_record_mc_locator *mc)
{
char desc[17];
- if (mc == NULL)
+ if (!mc)
return -1;
memset(desc, 0, sizeof (desc));
- snprintf(desc, (mc->id_code & 0x1f) + 1, "%s", mc->id_string);
+ snprintf(desc, sizeof(desc), "%.*s", (mc->id_code & 0x1f) + 1, mc->id_string);
if (verbose == 0) {
if (csv_output)
@@ -2215,20 +2384,18 @@ ipmi_sdr_print_sensor_mc_locator(struct ipmi_intf *intf,
/* ipmi_sdr_print_sensor_generic_locator - print generic device locator record
*
- * @intf: ipmi interface
* @gen: generic device locator sdr record
*
* returns 0 on success
* returns -1 on error
*/
int
-ipmi_sdr_print_sensor_generic_locator(struct ipmi_intf *intf,
- struct sdr_record_generic_locator *dev)
+ipmi_sdr_print_sensor_generic_locator(struct sdr_record_generic_locator *dev)
{
char desc[17];
memset(desc, 0, sizeof (desc));
- snprintf(desc, (dev->id_code & 0x1f) + 1, "%s", dev->id_string);
+ snprintf(desc, sizeof(desc), "%.*s", (dev->id_code & 0x1f) + 1, dev->id_string);
if (!verbose) {
if (csv_output)
@@ -2272,20 +2439,18 @@ ipmi_sdr_print_sensor_generic_locator(struct ipmi_intf *intf,
/* ipmi_sdr_print_sensor_fru_locator - print FRU locator record
*
- * @intf: ipmi interface
* @fru: fru locator sdr record
*
* returns 0 on success
* returns -1 on error
*/
int
-ipmi_sdr_print_sensor_fru_locator(struct ipmi_intf *intf,
- struct sdr_record_fru_locator *fru)
+ipmi_sdr_print_sensor_fru_locator(struct sdr_record_fru_locator *fru)
{
char desc[17];
memset(desc, 0, sizeof (desc));
- snprintf(desc, (fru->id_code & 0x1f) + 1, "%s", fru->id_string);
+ snprintf(desc, sizeof(desc), "%.*s", (fru->id_code & 0x1f) + 1, fru->id_string);
if (!verbose) {
if (csv_output)
@@ -2329,32 +2494,15 @@ ipmi_sdr_print_sensor_fru_locator(struct ipmi_intf *intf,
return 0;
}
-/* ipmi_sdr_print_sensor_entity_assoc - print SDR entity association record
- *
- * @intf: ipmi interface
- * @mc: entity association sdr record
- *
- * returns 0 on success
- * returns -1 on error
- */
-int
-ipmi_sdr_print_sensor_entity_assoc(struct ipmi_intf *intf,
- struct sdr_record_entity_assoc *assoc)
-{
- return 0;
-}
-
/* ipmi_sdr_print_sensor_oem_intel - print Intel OEM sensors
*
- * @intf: ipmi interface
* @oem: oem sdr record
*
* returns 0 on success
* returns -1 on error
*/
static int
-ipmi_sdr_print_sensor_oem_intel(struct ipmi_intf *intf,
- struct sdr_record_oem *oem)
+ipmi_sdr_print_sensor_oem_intel(struct sdr_record_oem *oem)
{
switch (oem->data[3]) { /* record sub-type */
case 0x02: /* Power Unit Map */
@@ -2435,20 +2583,19 @@ ipmi_sdr_print_sensor_oem_intel(struct ipmi_intf *intf,
* a particular BMC might stuff into its OEM records. The
* records are keyed off manufacturer ID and record subtypes.
*
- * @intf: ipmi interface
* @oem: oem sdr record
*
* returns 0 on success
* returns -1 on error
*/
static int
-ipmi_sdr_print_sensor_oem(struct ipmi_intf *intf, struct sdr_record_oem *oem)
+ipmi_sdr_print_sensor_oem(struct sdr_record_oem *oem)
{
int rc = 0;
- if (oem == NULL)
+ if (!oem)
return -1;
- if (oem->data_len == 0 || oem->data == NULL)
+ if (oem->data_len == 0 || !oem->data)
return -1;
if (verbose > 2)
@@ -2457,7 +2604,7 @@ ipmi_sdr_print_sensor_oem(struct ipmi_intf *intf, struct sdr_record_oem *oem)
/* intel manufacturer id */
if (oem->data[0] == 0x57 &&
oem->data[1] == 0x01 && oem->data[2] == 0x00) {
- rc = ipmi_sdr_print_sensor_oem_intel(intf, oem);
+ rc = ipmi_sdr_print_sensor_oem_intel(oem);
}
return rc;
@@ -2465,7 +2612,6 @@ ipmi_sdr_print_sensor_oem(struct ipmi_intf *intf, struct sdr_record_oem *oem)
/* ipmi_sdr_print_name_from_rawentry - Print SDR name from raw data
*
- * @intf: ipmi interface
* @type: sensor type
* @raw: raw sensor data
*
@@ -2473,7 +2619,7 @@ ipmi_sdr_print_sensor_oem(struct ipmi_intf *intf, struct sdr_record_oem *oem)
* returns -1 on error
*/
int
-ipmi_sdr_print_name_from_rawentry(struct ipmi_intf *intf, uint16_t id,
+ipmi_sdr_print_name_from_rawentry(uint16_t id,
uint8_t type, uint8_t *raw)
{
union {
@@ -2489,35 +2635,43 @@ ipmi_sdr_print_name_from_rawentry(struct ipmi_intf *intf, uint16_t id,
int rc =0;
char desc[17];
+ const char *id_string;
+ uint8_t id_code;
memset(desc, ' ', sizeof (desc));
switch ( type) {
case SDR_RECORD_TYPE_FULL_SENSOR:
record.full = (struct sdr_record_full_sensor *) raw;
- snprintf(desc, (record.full->id_code & 0x1f) +1, "%s",
- (const char *)record.full->id_string);
+ id_code = record.full->id_code;
+ id_string = record.full->id_string;
break;
+
case SDR_RECORD_TYPE_COMPACT_SENSOR:
record.compact = (struct sdr_record_compact_sensor *) raw ;
- snprintf(desc, (record.compact->id_code & 0x1f) +1, "%s",
- (const char *)record.compact->id_string);
+ id_code = record.compact->id_code;
+ id_string = record.compact->id_string;
break;
+
case SDR_RECORD_TYPE_EVENTONLY_SENSOR:
record.eventonly = (struct sdr_record_eventonly_sensor *) raw ;
- snprintf(desc, (record.eventonly->id_code & 0x1f) +1, "%s",
- (const char *)record.eventonly->id_string);
- break;
+ id_code = record.eventonly->id_code;
+ id_string = record.eventonly->id_string;
+ break;
+
case SDR_RECORD_TYPE_MC_DEVICE_LOCATOR:
record.mcloc = (struct sdr_record_mc_locator *) raw ;
- snprintf(desc, (record.mcloc->id_code & 0x1f) +1, "%s",
- (const char *)record.mcloc->id_string);
+ id_code = record.mcloc->id_code;
+ id_string = record.mcloc->id_string;
break;
+
default:
rc = -1;
- break;
- }
+ }
+ if (!rc) {
+ snprintf(desc, sizeof(desc), "%.*s", (id_code & 0x1f) + 1, id_string);
+ }
- lprintf(LOG_INFO, "ID: 0x%04x , NAME: %-16s", id, desc);
+ lprintf(LOG_INFO, "ID: 0x%04x , NAME: %-16s", id, desc);
return rc;
}
@@ -2551,35 +2705,27 @@ ipmi_sdr_print_rawentry(struct ipmi_intf *intf, uint8_t type,
*) raw);
break;
case SDR_RECORD_TYPE_GENERIC_DEVICE_LOCATOR:
- rc = ipmi_sdr_print_sensor_generic_locator(intf,
- (struct
+ rc = ipmi_sdr_print_sensor_generic_locator((struct
sdr_record_generic_locator
*) raw);
break;
case SDR_RECORD_TYPE_FRU_DEVICE_LOCATOR:
- rc = ipmi_sdr_print_sensor_fru_locator(intf,
- (struct
+ rc = ipmi_sdr_print_sensor_fru_locator((struct
sdr_record_fru_locator
*) raw);
break;
case SDR_RECORD_TYPE_MC_DEVICE_LOCATOR:
- rc = ipmi_sdr_print_sensor_mc_locator(intf,
- (struct
+ rc = ipmi_sdr_print_sensor_mc_locator((struct
sdr_record_mc_locator *)
raw);
break;
case SDR_RECORD_TYPE_ENTITY_ASSOC:
- rc = ipmi_sdr_print_sensor_entity_assoc(intf,
- (struct
- sdr_record_entity_assoc
- *) raw);
break;
case SDR_RECORD_TYPE_OEM:{
struct sdr_record_oem oem;
oem.data = raw;
oem.data_len = len;
- rc = ipmi_sdr_print_sensor_oem(intf,
- (struct sdr_record_oem *)
+ rc = ipmi_sdr_print_sensor_oem((struct sdr_record_oem *)
&oem);
break;
}
@@ -2616,24 +2762,19 @@ ipmi_sdr_print_listentry(struct ipmi_intf *intf, struct sdr_record_list *entry)
entry->record.eventonly);
break;
case SDR_RECORD_TYPE_GENERIC_DEVICE_LOCATOR:
- rc = ipmi_sdr_print_sensor_generic_locator(intf,
- entry->record.
+ rc = ipmi_sdr_print_sensor_generic_locator(entry->record.
genloc);
break;
case SDR_RECORD_TYPE_FRU_DEVICE_LOCATOR:
- rc = ipmi_sdr_print_sensor_fru_locator(intf,
- entry->record.fruloc);
+ rc = ipmi_sdr_print_sensor_fru_locator(entry->record.fruloc);
break;
case SDR_RECORD_TYPE_MC_DEVICE_LOCATOR:
- rc = ipmi_sdr_print_sensor_mc_locator(intf,
- entry->record.mcloc);
+ rc = ipmi_sdr_print_sensor_mc_locator(entry->record.mcloc);
break;
case SDR_RECORD_TYPE_ENTITY_ASSOC:
- rc = ipmi_sdr_print_sensor_entity_assoc(intf,
- entry->record.entassoc);
break;
case SDR_RECORD_TYPE_OEM:
- rc = ipmi_sdr_print_sensor_oem(intf, entry->record.oem);
+ rc = ipmi_sdr_print_sensor_oem(entry->record.oem);
break;
case SDR_RECORD_TYPE_DEVICE_ENTITY_ASSOC:
case SDR_RECORD_TYPE_MC_CONFIRMATION:
@@ -2662,15 +2803,15 @@ ipmi_sdr_print_sdr(struct ipmi_intf *intf, uint8_t type)
lprintf(LOG_DEBUG, "Querying SDR for sensor list");
- if (sdr_list_itr == NULL) {
+ if (!sdr_list_itr) {
sdr_list_itr = ipmi_sdr_start(intf, 0);
- if (sdr_list_itr == NULL) {
+ if (!sdr_list_itr) {
lprintf(LOG_ERR, "Unable to open SDR for reading");
return -1;
}
}
- for (e = sdr_list_head; e != NULL; e = e->next) {
+ for (e = sdr_list_head; e; e = e->next) {
if (type != e->type && type != 0xff && type != 0xfe)
continue;
if (type == 0xfe &&
@@ -2681,21 +2822,21 @@ ipmi_sdr_print_sdr(struct ipmi_intf *intf, uint8_t type)
rc = -1;
}
- while ((header = ipmi_sdr_get_next_header(intf, sdr_list_itr)) != NULL) {
+ while ((header = ipmi_sdr_get_next_header(intf, sdr_list_itr))) {
uint8_t *rec;
struct sdr_record_list *sdrr;
rec = ipmi_sdr_get_record(intf, header, sdr_list_itr);
- if (rec == NULL) {
+ if (!rec) {
lprintf(LOG_ERR, "ipmitool: ipmi_sdr_get_record() failed");
rc = -1;
continue;
}
sdrr = malloc(sizeof (struct sdr_record_list));
- if (sdrr == NULL) {
+ if (!sdrr) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
- if (rec != NULL) {
+ if (rec) {
free(rec);
rec = NULL;
}
@@ -2734,7 +2875,7 @@ ipmi_sdr_print_sdr(struct ipmi_intf *intf, uint8_t type)
default:
free(rec);
rec = NULL;
- if (sdrr != NULL) {
+ if (sdrr) {
free(sdrr);
sdrr = NULL;
}
@@ -2753,7 +2894,7 @@ ipmi_sdr_print_sdr(struct ipmi_intf *intf, uint8_t type)
}
/* add to global record liset */
- if (sdr_list_head == NULL)
+ if (!sdr_list_head)
sdr_list_head = sdrr;
else
sdr_list_tail->next = sdrr;
@@ -2792,9 +2933,9 @@ ipmi_sdr_get_reservation(struct ipmi_intf *intf, int use_builtin,
rsp = intf->sendrecv(intf, &req);
/* be slient for errors, they are handled by calling function */
- if (rsp == NULL)
+ if (!rsp)
return -1;
- if (rsp->ccode > 0)
+ if (rsp->ccode)
return -1;
*reserve_id = ((struct sdr_reserve_repo_rs *) &(rsp->data))->reserve_id;
@@ -2820,7 +2961,7 @@ ipmi_sdr_start(struct ipmi_intf *intf, int use_builtin)
struct ipm_devid_rsp *devid;
itr = malloc(sizeof (struct ipmi_sdr_iterator));
- if (itr == NULL) {
+ if (!itr) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
return NULL;
}
@@ -2833,13 +2974,13 @@ ipmi_sdr_start(struct ipmi_intf *intf, int use_builtin)
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Get Device ID command failed");
free(itr);
itr = NULL;
return NULL;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Get Device ID command failed: %#x %s",
rsp->ccode, val2str(rsp->ccode, completion_code_vals));
free(itr);
@@ -2875,13 +3016,13 @@ ipmi_sdr_start(struct ipmi_intf *intf, int use_builtin)
req.msg.cmd = GET_SDR_REPO_INFO;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error obtaining SDR info");
free(itr);
itr = NULL;
return NULL;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Error obtaining SDR info: %s",
val2str(rsp->ccode, completion_code_vals));
free(itr);
@@ -2973,7 +3114,7 @@ ipmi_sdr_get_record(struct ipmi_intf * intf, struct sdr_get_rs * header,
return NULL;
data = malloc(len + 1);
- if (data == NULL) {
+ if (!data) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
return NULL;
}
@@ -3019,7 +3160,8 @@ ipmi_sdr_get_record(struct ipmi_intf * intf, struct sdr_get_rs * header,
sdr_rq.length, sdr_rq.offset);
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+
+ if (!rsp || rsp->ccode == IPMI_CC_CANT_RET_NUM_REQ_BYTES) {
sdr_max_read_len = sdr_rq.length - 1;
if (sdr_max_read_len > 0) {
/* no response may happen if requests are bridged
@@ -3030,14 +3172,7 @@ ipmi_sdr_get_record(struct ipmi_intf * intf, struct sdr_get_rs * header,
data = NULL;
return NULL;
}
- }
-
- switch (rsp->ccode) {
- case 0xca:
- /* read too many bytes at once */
- sdr_max_read_len = sdr_rq.length - 1;
- continue;
- case 0xc5:
+ } else if (rsp->ccode == IPMI_CC_RES_CANCELED) {
/* lost reservation */
lprintf(LOG_DEBUG, "SDR reservation cancelled. "
"Sleeping a bit and retrying...");
@@ -3055,14 +3190,14 @@ ipmi_sdr_get_record(struct ipmi_intf * intf, struct sdr_get_rs * header,
}
/* special completion codes handled above */
- if (rsp->ccode > 0 || rsp->data_len == 0) {
+ if (rsp->ccode || rsp->data_len == 0) {
free(data);
data = NULL;
return NULL;
}
memcpy(data + i, rsp->data + 2, sdr_rq.length);
- i += sdr_max_read_len;
+ i += sdr_rq.length;
}
return data;
@@ -3070,13 +3205,12 @@ ipmi_sdr_get_record(struct ipmi_intf * intf, struct sdr_get_rs * header,
/* ipmi_sdr_end - cleanup SDR iterator
*
- * @intf: ipmi interface
* @itr: SDR iterator
*
* no meaningful return code
*/
void
-ipmi_sdr_end(struct ipmi_intf *intf, struct ipmi_sdr_iterator *itr)
+ipmi_sdr_end(struct ipmi_sdr_iterator *itr)
{
if (itr) {
free(itr);
@@ -3098,11 +3232,11 @@ __sdr_list_add(struct sdr_record_list *head, struct sdr_record_list *entry)
struct sdr_record_list *e;
struct sdr_record_list *new;
- if (head == NULL)
+ if (!head)
return -1;
new = malloc(sizeof (struct sdr_record_list));
- if (new == NULL) {
+ if (!new) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
return -1;
}
@@ -3127,7 +3261,7 @@ static void
__sdr_list_empty(struct sdr_record_list *head)
{
struct sdr_record_list *e, *f;
- for (e = head; e != NULL; e = f) {
+ for (e = head; e; e = f) {
f = e->next;
free(e);
e = NULL;
@@ -3137,18 +3271,16 @@ __sdr_list_empty(struct sdr_record_list *head)
/* ipmi_sdr_list_empty - clean global SDR list
*
- * @intf: ipmi interface
- *
* no meaningful return code
*/
void
-ipmi_sdr_list_empty(struct ipmi_intf *intf)
+ipmi_sdr_list_empty(void)
{
struct sdr_record_list *list, *next;
- ipmi_sdr_end(intf, sdr_list_itr);
+ ipmi_sdr_end(sdr_list_itr);
- for (list = sdr_list_head; list != NULL; list = next) {
+ for (list = sdr_list_head; list; list = next) {
switch (list->type) {
case SDR_RECORD_TYPE_FULL_SENSOR:
case SDR_RECORD_TYPE_COMPACT_SENSOR:
@@ -3215,16 +3347,16 @@ ipmi_sdr_find_sdr_bynumtype(struct ipmi_intf *intf, uint16_t gen_id, uint8_t num
struct sdr_record_list *e;
int found = 0;
- if (sdr_list_itr == NULL) {
+ if (!sdr_list_itr) {
sdr_list_itr = ipmi_sdr_start(intf, 0);
- if (sdr_list_itr == NULL) {
+ if (!sdr_list_itr) {
lprintf(LOG_ERR, "Unable to open SDR for reading");
return NULL;
}
}
/* check what we've already read */
- for (e = sdr_list_head; e != NULL; e = e->next) {
+ for (e = sdr_list_head; e; e = e->next) {
switch (e->type) {
case SDR_RECORD_TYPE_FULL_SENSOR:
case SDR_RECORD_TYPE_COMPACT_SENSOR:
@@ -3243,12 +3375,12 @@ ipmi_sdr_find_sdr_bynumtype(struct ipmi_intf *intf, uint16_t gen_id, uint8_t num
}
/* now keep looking */
- while ((header = ipmi_sdr_get_next_header(intf, sdr_list_itr)) != NULL) {
+ while ((header = ipmi_sdr_get_next_header(intf, sdr_list_itr))) {
uint8_t *rec;
struct sdr_record_list *sdrr;
sdrr = malloc(sizeof (struct sdr_record_list));
- if (sdrr == NULL) {
+ if (!sdrr) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
break;
}
@@ -3257,8 +3389,8 @@ ipmi_sdr_find_sdr_bynumtype(struct ipmi_intf *intf, uint16_t gen_id, uint8_t num
sdrr->type = header->type;
rec = ipmi_sdr_get_record(intf, header, sdr_list_itr);
- if (rec == NULL) {
- if (sdrr != NULL) {
+ if (!rec) {
+ if (sdrr) {
free(sdrr);
sdrr = NULL;
}
@@ -3302,7 +3434,7 @@ ipmi_sdr_find_sdr_bynumtype(struct ipmi_intf *intf, uint16_t gen_id, uint8_t num
default:
free(rec);
rec = NULL;
- if (sdrr != NULL) {
+ if (sdrr) {
free(sdrr);
sdrr = NULL;
}
@@ -3310,7 +3442,7 @@ ipmi_sdr_find_sdr_bynumtype(struct ipmi_intf *intf, uint16_t gen_id, uint8_t num
}
/* put in the global record list */
- if (sdr_list_head == NULL)
+ if (!sdr_list_head)
sdr_list_head = sdrr;
else
sdr_list_tail->next = sdrr;
@@ -3339,9 +3471,9 @@ ipmi_sdr_find_sdr_bysensortype(struct ipmi_intf *intf, uint8_t type)
struct sdr_get_rs *header;
struct sdr_record_list *e;
- if (sdr_list_itr == NULL) {
+ if (!sdr_list_itr) {
sdr_list_itr = ipmi_sdr_start(intf, 0);
- if (sdr_list_itr == NULL) {
+ if (!sdr_list_itr) {
lprintf(LOG_ERR, "Unable to open SDR for reading");
return NULL;
}
@@ -3349,13 +3481,13 @@ ipmi_sdr_find_sdr_bysensortype(struct ipmi_intf *intf, uint8_t type)
/* check what we've already read */
head = malloc(sizeof (struct sdr_record_list));
- if (head == NULL) {
+ if (!head) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
return NULL;
}
memset(head, 0, sizeof (struct sdr_record_list));
- for (e = sdr_list_head; e != NULL; e = e->next) {
+ for (e = sdr_list_head; e; e = e->next) {
switch (e->type) {
case SDR_RECORD_TYPE_FULL_SENSOR:
case SDR_RECORD_TYPE_COMPACT_SENSOR:
@@ -3370,12 +3502,12 @@ ipmi_sdr_find_sdr_bysensortype(struct ipmi_intf *intf, uint8_t type)
}
/* now keep looking */
- while ((header = ipmi_sdr_get_next_header(intf, sdr_list_itr)) != NULL) {
+ while ((header = ipmi_sdr_get_next_header(intf, sdr_list_itr))) {
uint8_t *rec;
struct sdr_record_list *sdrr;
sdrr = malloc(sizeof (struct sdr_record_list));
- if (sdrr == NULL) {
+ if (!sdrr) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
break;
}
@@ -3384,8 +3516,8 @@ ipmi_sdr_find_sdr_bysensortype(struct ipmi_intf *intf, uint8_t type)
sdrr->type = header->type;
rec = ipmi_sdr_get_record(intf, header, sdr_list_itr);
- if (rec == NULL) {
- if (sdrr != NULL) {
+ if (!rec) {
+ if (sdrr) {
free(sdrr);
sdrr = NULL;
}
@@ -3425,7 +3557,7 @@ ipmi_sdr_find_sdr_bysensortype(struct ipmi_intf *intf, uint8_t type)
default:
free(rec);
rec = NULL;
- if (sdrr != NULL) {
+ if (sdrr) {
free(sdrr);
sdrr = NULL;
}
@@ -3433,7 +3565,7 @@ ipmi_sdr_find_sdr_bysensortype(struct ipmi_intf *intf, uint8_t type)
}
/* put in the global record list */
- if (sdr_list_head == NULL)
+ if (!sdr_list_head)
sdr_list_head = sdrr;
else
sdr_list_tail->next = sdrr;
@@ -3459,23 +3591,23 @@ ipmi_sdr_find_sdr_byentity(struct ipmi_intf *intf, struct entity_id *entity)
struct sdr_record_list *e;
struct sdr_record_list *head;
- if (sdr_list_itr == NULL) {
+ if (!sdr_list_itr) {
sdr_list_itr = ipmi_sdr_start(intf, 0);
- if (sdr_list_itr == NULL) {
+ if (!sdr_list_itr) {
lprintf(LOG_ERR, "Unable to open SDR for reading");
return NULL;
}
}
head = malloc(sizeof (struct sdr_record_list));
- if (head == NULL) {
+ if (!head) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
return NULL;
}
memset(head, 0, sizeof (struct sdr_record_list));
/* check what we've already read */
- for (e = sdr_list_head; e != NULL; e = e->next) {
+ for (e = sdr_list_head; e; e = e->next) {
switch (e->type) {
case SDR_RECORD_TYPE_FULL_SENSOR:
case SDR_RECORD_TYPE_COMPACT_SENSOR:
@@ -3524,12 +3656,12 @@ ipmi_sdr_find_sdr_byentity(struct ipmi_intf *intf, struct entity_id *entity)
}
/* now keep looking */
- while ((header = ipmi_sdr_get_next_header(intf, sdr_list_itr)) != NULL) {
+ while ((header = ipmi_sdr_get_next_header(intf, sdr_list_itr))) {
uint8_t *rec;
struct sdr_record_list *sdrr;
sdrr = malloc(sizeof (struct sdr_record_list));
- if (sdrr == NULL) {
+ if (!sdrr) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
break;
}
@@ -3538,8 +3670,8 @@ ipmi_sdr_find_sdr_byentity(struct ipmi_intf *intf, struct entity_id *entity)
sdrr->type = header->type;
rec = ipmi_sdr_get_record(intf, header, sdr_list_itr);
- if (rec == NULL) {
- if (sdrr != NULL) {
+ if (!rec) {
+ if (sdrr) {
free(sdrr);
sdrr = NULL;
}
@@ -3605,7 +3737,7 @@ ipmi_sdr_find_sdr_byentity(struct ipmi_intf *intf, struct entity_id *entity)
default:
free(rec);
rec = NULL;
- if (sdrr != NULL) {
+ if (sdrr) {
free(sdrr);
sdrr = NULL;
}
@@ -3613,7 +3745,7 @@ ipmi_sdr_find_sdr_byentity(struct ipmi_intf *intf, struct entity_id *entity)
}
/* add to global record list */
- if (sdr_list_head == NULL)
+ if (!sdr_list_head)
sdr_list_head = sdrr;
else
sdr_list_tail->next = sdrr;
@@ -3639,33 +3771,33 @@ ipmi_sdr_find_sdr_bytype(struct ipmi_intf *intf, uint8_t type)
struct sdr_record_list *e;
struct sdr_record_list *head;
- if (sdr_list_itr == NULL) {
+ if (!sdr_list_itr) {
sdr_list_itr = ipmi_sdr_start(intf, 0);
- if (sdr_list_itr == NULL) {
+ if (!sdr_list_itr) {
lprintf(LOG_ERR, "Unable to open SDR for reading");
return NULL;
}
}
head = malloc(sizeof (struct sdr_record_list));
- if (head == NULL) {
+ if (!head) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
return NULL;
}
memset(head, 0, sizeof (struct sdr_record_list));
/* check what we've already read */
- for (e = sdr_list_head; e != NULL; e = e->next)
+ for (e = sdr_list_head; e; e = e->next)
if (e->type == type)
__sdr_list_add(head, e);
/* now keep looking */
- while ((header = ipmi_sdr_get_next_header(intf, sdr_list_itr)) != NULL) {
+ while ((header = ipmi_sdr_get_next_header(intf, sdr_list_itr))) {
uint8_t *rec;
struct sdr_record_list *sdrr;
sdrr = malloc(sizeof (struct sdr_record_list));
- if (sdrr == NULL) {
+ if (!sdrr) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
break;
}
@@ -3674,8 +3806,8 @@ ipmi_sdr_find_sdr_bytype(struct ipmi_intf *intf, uint8_t type)
sdrr->type = header->type;
rec = ipmi_sdr_get_record(intf, header, sdr_list_itr);
- if (rec == NULL) {
- if (sdrr != NULL) {
+ if (!rec) {
+ if (sdrr) {
free(sdrr);
sdrr = NULL;
}
@@ -3711,7 +3843,7 @@ ipmi_sdr_find_sdr_bytype(struct ipmi_intf *intf, uint8_t type)
default:
free(rec);
rec = NULL;
- if (sdrr != NULL) {
+ if (sdrr) {
free(sdrr);
sdrr = NULL;
}
@@ -3722,7 +3854,7 @@ ipmi_sdr_find_sdr_bytype(struct ipmi_intf *intf, uint8_t type)
__sdr_list_add(head, sdrr);
/* add to global record list */
- if (sdr_list_head == NULL)
+ if (!sdr_list_head)
sdr_list_head = sdrr;
else
sdr_list_tail->next = sdrr;
@@ -3749,21 +3881,21 @@ ipmi_sdr_find_sdr_byid(struct ipmi_intf *intf, char *id)
int found = 0;
int idlen;
- if (id == NULL)
+ if (!id)
return NULL;
idlen = strlen(id);
- if (sdr_list_itr == NULL) {
+ if (!sdr_list_itr) {
sdr_list_itr = ipmi_sdr_start(intf, 0);
- if (sdr_list_itr == NULL) {
+ if (!sdr_list_itr) {
lprintf(LOG_ERR, "Unable to open SDR for reading");
return NULL;
}
}
/* check what we've already read */
- for (e = sdr_list_head; e != NULL; e = e->next) {
+ for (e = sdr_list_head; e; e = e->next) {
switch (e->type) {
case SDR_RECORD_TYPE_FULL_SENSOR:
if (!strncmp((const char *)e->record.full->id_string,
@@ -3805,12 +3937,12 @@ ipmi_sdr_find_sdr_byid(struct ipmi_intf *intf, char *id)
}
/* now keep looking */
- while ((header = ipmi_sdr_get_next_header(intf, sdr_list_itr)) != NULL) {
+ while ((header = ipmi_sdr_get_next_header(intf, sdr_list_itr))) {
uint8_t *rec;
struct sdr_record_list *sdrr;
sdrr = malloc(sizeof (struct sdr_record_list));
- if (sdrr == NULL) {
+ if (!sdrr) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
break;
}
@@ -3819,8 +3951,8 @@ ipmi_sdr_find_sdr_byid(struct ipmi_intf *intf, char *id)
sdrr->type = header->type;
rec = ipmi_sdr_get_record(intf, header, sdr_list_itr);
- if (rec == NULL) {
- if (sdrr != NULL) {
+ if (!rec) {
+ if (sdrr) {
free(sdrr);
sdrr = NULL;
}
@@ -3891,7 +4023,7 @@ ipmi_sdr_find_sdr_byid(struct ipmi_intf *intf, char *id)
default:
free(rec);
rec = NULL;
- if (sdrr != NULL) {
+ if (sdrr) {
free(sdrr);
sdrr = NULL;
}
@@ -3899,7 +4031,7 @@ ipmi_sdr_find_sdr_byid(struct ipmi_intf *intf, char *id)
}
/* add to global record liset */
- if (sdr_list_head == NULL)
+ if (!sdr_list_head)
sdr_list_head = sdrr;
else
sdr_list_tail->next = sdrr;
@@ -3915,14 +4047,13 @@ ipmi_sdr_find_sdr_byid(struct ipmi_intf *intf, char *id)
/* ipmi_sdr_list_cache_fromfile - generate SDR cache for fast lookup from local file
*
- * @intf: ipmi interface
* @ifile: input filename
*
* returns pointer to SDR list
* returns NULL on error
*/
int
-ipmi_sdr_list_cache_fromfile(struct ipmi_intf *intf, const char *ifile)
+ipmi_sdr_list_cache_fromfile(const char *ifile)
{
FILE *fp;
struct __sdr_header {
@@ -3935,13 +4066,13 @@ ipmi_sdr_list_cache_fromfile(struct ipmi_intf *intf, const char *ifile)
uint8_t *rec;
int ret = 0, count = 0, bc = 0;
- if (ifile == NULL) {
+ if (!ifile) {
lprintf(LOG_ERR, "No SDR cache filename given");
return -1;
}
fp = ipmi_open_file_read(ifile);
- if (fp == NULL) {
+ if (!fp) {
lprintf(LOG_ERR, "Unable to open SDR cache %s for reading",
ifile);
return -1;
@@ -3973,7 +4104,7 @@ ipmi_sdr_list_cache_fromfile(struct ipmi_intf *intf, const char *ifile)
}
sdrr = malloc(sizeof (struct sdr_record_list));
- if (sdrr == NULL) {
+ if (!sdrr) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
ret = -1;
break;
@@ -3984,10 +4115,10 @@ ipmi_sdr_list_cache_fromfile(struct ipmi_intf *intf, const char *ifile)
sdrr->type = header.type;
rec = malloc(header.length + 1);
- if (rec == NULL) {
+ if (!rec) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
ret = -1;
- if (sdrr != NULL) {
+ if (sdrr) {
free(sdrr);
sdrr = NULL;
}
@@ -4001,11 +4132,11 @@ ipmi_sdr_list_cache_fromfile(struct ipmi_intf *intf, const char *ifile)
"record %04x read %d bytes, expected %d",
header.id, bc, header.length);
ret = -1;
- if (sdrr != NULL) {
+ if (sdrr) {
free(sdrr);
sdrr = NULL;
}
- if (rec != NULL) {
+ if (rec) {
free(rec);
rec = NULL;
}
@@ -4041,7 +4172,7 @@ ipmi_sdr_list_cache_fromfile(struct ipmi_intf *intf, const char *ifile)
default:
free(rec);
rec = NULL;
- if (sdrr != NULL) {
+ if (sdrr) {
free(sdrr);
sdrr = NULL;
}
@@ -4049,7 +4180,7 @@ ipmi_sdr_list_cache_fromfile(struct ipmi_intf *intf, const char *ifile)
}
/* add to global record liset */
- if (sdr_list_head == NULL)
+ if (!sdr_list_head)
sdr_list_head = sdrr;
else
sdr_list_tail->next = sdrr;
@@ -4062,9 +4193,9 @@ ipmi_sdr_list_cache_fromfile(struct ipmi_intf *intf, const char *ifile)
sdrr->id);
}
- if (sdr_list_itr == NULL) {
+ if (!sdr_list_itr) {
sdr_list_itr = malloc(sizeof (struct ipmi_sdr_iterator));
- if (sdr_list_itr != NULL) {
+ if (sdr_list_itr) {
sdr_list_itr->reservation = 0;
sdr_list_itr->total = count;
sdr_list_itr->next = 0xffff;
@@ -4087,20 +4218,20 @@ ipmi_sdr_list_cache(struct ipmi_intf *intf)
{
struct sdr_get_rs *header;
- if (sdr_list_itr == NULL) {
+ if (!sdr_list_itr) {
sdr_list_itr = ipmi_sdr_start(intf, 0);
- if (sdr_list_itr == NULL) {
+ if (!sdr_list_itr) {
lprintf(LOG_ERR, "Unable to open SDR for reading");
return -1;
}
}
- while ((header = ipmi_sdr_get_next_header(intf, sdr_list_itr)) != NULL) {
+ while ((header = ipmi_sdr_get_next_header(intf, sdr_list_itr))) {
uint8_t *rec;
struct sdr_record_list *sdrr;
sdrr = malloc(sizeof (struct sdr_record_list));
- if (sdrr == NULL) {
+ if (!sdrr) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
break;
}
@@ -4109,8 +4240,8 @@ ipmi_sdr_list_cache(struct ipmi_intf *intf)
sdrr->type = header->type;
rec = ipmi_sdr_get_record(intf, header, sdr_list_itr);
- if (rec == NULL) {
- if (sdrr != NULL) {
+ if (!rec) {
+ if (sdrr) {
free(sdrr);
sdrr = NULL;
}
@@ -4146,7 +4277,7 @@ ipmi_sdr_list_cache(struct ipmi_intf *intf)
default:
free(rec);
rec = NULL;
- if (sdrr != NULL) {
+ if (sdrr) {
free(sdrr);
sdrr = NULL;
}
@@ -4154,7 +4285,7 @@ ipmi_sdr_list_cache(struct ipmi_intf *intf)
}
/* add to global record liset */
- if (sdr_list_head == NULL)
+ if (!sdr_list_head)
sdr_list_head = sdrr;
else
sdr_list_tail->next = sdrr;
@@ -4192,11 +4323,11 @@ ipmi_sdr_get_info(struct ipmi_intf *intf,
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Get SDR Repository Info command failed");
return -1;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Get SDR Repository Info command failed: %s",
val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -4210,24 +4341,6 @@ ipmi_sdr_get_info(struct ipmi_intf *intf,
return 0;
}
-/* ipmi_sdr_timestamp - return string from timestamp value
- *
- * @stamp: 32bit timestamp
- *
- * returns pointer to static buffer
- */
-static char *
-ipmi_sdr_timestamp(uint32_t stamp)
-{
- static char tbuf[40];
- time_t s = (time_t) stamp;
- memset(tbuf, 0, 40);
- if (stamp)
- strftime(tbuf, sizeof (tbuf), "%m/%d/%Y %H:%M:%S",
- gmtime(&s));
- return tbuf;
-}
-
/*
* ipmi_sdr_print_info
*
@@ -4240,7 +4353,7 @@ ipmi_sdr_timestamp(uint32_t stamp)
int
ipmi_sdr_print_info(struct ipmi_intf *intf)
{
- uint32_t timestamp;
+ time_t timestamp;
uint16_t free_space;
struct get_sdr_repository_info_rsp sdr_repository_info;
@@ -4274,21 +4387,26 @@ ipmi_sdr_print_info(struct ipmi_intf *intf)
break;
}
- timestamp =
- (sdr_repository_info.most_recent_addition_timestamp[3] << 24) |
- (sdr_repository_info.most_recent_addition_timestamp[2] << 16) |
- (sdr_repository_info.most_recent_addition_timestamp[1] << 8) |
- sdr_repository_info.most_recent_addition_timestamp[0];
- printf("Most recent Addition : %s\n",
- ipmi_sdr_timestamp(timestamp));
+ printf("Most recent Addition : ");
+ if (sdr_repository_info.partial_add_sdr_supported)
+ {
+ timestamp = ipmi32toh(sdr_repository_info
+ .most_recent_addition_timestamp);
+ printf("%s\n", ipmi_timestamp_numeric(timestamp));
+ }
+ else {
+ printf("NA\n");
+ }
- timestamp =
- (sdr_repository_info.most_recent_erase_timestamp[3] << 24) |
- (sdr_repository_info.most_recent_erase_timestamp[2] << 16) |
- (sdr_repository_info.most_recent_erase_timestamp[1] << 8) |
- sdr_repository_info.most_recent_erase_timestamp[0];
- printf("Most recent Erase : %s\n",
- ipmi_sdr_timestamp(timestamp));
+ printf("Most recent Erase : ");
+ if(sdr_repository_info.delete_sdr_supported) {
+ timestamp = ipmi32toh(sdr_repository_info
+ .most_recent_erase_timestamp);
+ printf("%s\n", ipmi_timestamp_numeric(timestamp));
+ }
+ else {
+ printf("NA\n");
+ }
printf("SDR overflow : %s\n",
(sdr_repository_info.overflow_flag ? "yes" : "no"));
@@ -4321,7 +4439,7 @@ ipmi_sdr_print_info(struct ipmi_intf *intf)
reserve_sdr_repository_supported ? "yes" : "no");
printf("SDR Repository Alloc info supported : %s\n",
sdr_repository_info.
- get_sdr_repository_allo_info_supported ? "yes" : "no");
+ get_sdr_repository_allo_info_supported ? "yes" : "no");
return 0;
}
@@ -4347,7 +4465,7 @@ ipmi_sdr_dump_bin(struct ipmi_intf *intf, const char *ofile)
/* open connection to SDR */
itr = ipmi_sdr_start(intf, 0);
- if (itr == NULL) {
+ if (!itr) {
lprintf(LOG_ERR, "Unable to open SDR for reading");
return -1;
}
@@ -4355,9 +4473,9 @@ ipmi_sdr_dump_bin(struct ipmi_intf *intf, const char *ofile)
printf("Dumping Sensor Data Repository to '%s'\n", ofile);
/* generate list of records */
- while ((header = ipmi_sdr_get_next_header(intf, itr)) != NULL) {
+ while ((header = ipmi_sdr_get_next_header(intf, itr))) {
sdrr = malloc(sizeof(struct sdr_record_list));
- if (sdrr == NULL) {
+ if (!sdrr) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
return -1;
}
@@ -4372,16 +4490,16 @@ ipmi_sdr_dump_bin(struct ipmi_intf *intf, const char *ofile)
sdrr->length = header->length;
sdrr->raw = ipmi_sdr_get_record(intf, header, itr);
- if (sdrr->raw == NULL) {
+ if (!sdrr->raw) {
lprintf(LOG_ERR, "ipmitool: cannot obtain SDR record %04x", header->id);
- if (sdrr != NULL) {
+ if (sdrr) {
free(sdrr);
sdrr = NULL;
}
return -1;
}
- if (sdr_list_head == NULL)
+ if (!sdr_list_head)
sdr_list_head = sdrr;
else
sdr_list_tail->next = sdrr;
@@ -4389,14 +4507,14 @@ ipmi_sdr_dump_bin(struct ipmi_intf *intf, const char *ofile)
sdr_list_tail = sdrr;
}
- ipmi_sdr_end(intf, itr);
+ ipmi_sdr_end(itr);
/* now write to file */
fp = ipmi_open_file_write(ofile);
- if (fp == NULL)
+ if (!fp)
return -1;
- for (sdrr = sdr_list_head; sdrr != NULL; sdrr = sdrr->next) {
+ for (sdrr = sdr_list_head; sdrr; sdrr = sdrr->next) {
int r;
uint8_t h[5];
@@ -4451,9 +4569,9 @@ ipmi_sdr_print_type(struct ipmi_intf *intf, char *type)
int x;
uint8_t sensor_type = 0;
- if (type == NULL ||
- strncasecmp(type, "help", 4) == 0 ||
- strncasecmp(type, "list", 4) == 0) {
+ if (!type ||
+ strcasecmp(type, "help") == 0 ||
+ strcasecmp(type, "list") == 0) {
printf("Sensor Types:\n");
for (x = 1; x < SENSOR_TYPE_MAX; x += 2) {
printf("\t%-25s (0x%02x) %-25s (0x%02x)\n",
@@ -4463,7 +4581,7 @@ ipmi_sdr_print_type(struct ipmi_intf *intf, char *type)
return 0;
}
- if (strncmp(type, "0x", 2) == 0) {
+ if (!strcmp(type, "0x")) {
/* begins with 0x so let it be entered as raw hex value */
if (str2uchar(type, &sensor_type) != 0) {
lprintf(LOG_ERR,
@@ -4473,9 +4591,7 @@ ipmi_sdr_print_type(struct ipmi_intf *intf, char *type)
}
} else {
for (x = 1; x < SENSOR_TYPE_MAX; x++) {
- if (strncasecmp(sensor_type_desc[x], type,
- __maxlen(type,
- sensor_type_desc[x])) == 0) {
+ if (strcasecmp(sensor_type_desc[x], type) == 0) {
sensor_type = x;
break;
}
@@ -4495,7 +4611,7 @@ ipmi_sdr_print_type(struct ipmi_intf *intf, char *type)
list = ipmi_sdr_find_sdr_bysensortype(intf, sensor_type);
- for (entry = list; entry != NULL; entry = entry->next) {
+ for (entry = list; entry; entry = entry->next) {
rc = ipmi_sdr_print_listentry(intf, entry);
}
@@ -4521,9 +4637,9 @@ ipmi_sdr_print_entity(struct ipmi_intf *intf, char *entitystr)
unsigned instance = 0;
int rc = 0;
- if (entitystr == NULL ||
- strncasecmp(entitystr, "help", 4) == 0 ||
- strncasecmp(entitystr, "list", 4) == 0) {
+ if (!entitystr ||
+ strcasecmp(entitystr, "help") == 0 ||
+ strcasecmp(entitystr, "list") == 0) {
print_valstr_2col(entity_id_vals, "Entity IDs", -1);
return 0;
}
@@ -4537,9 +4653,8 @@ ipmi_sdr_print_entity(struct ipmi_intf *intf, char *entitystr)
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) {
+ for (i = 0; entity_id_vals[i].str; i++) {
+ if (strcasecmp(entitystr, entity_id_vals[i].str) == 0) {
entity.id = entity_id_vals[i].val;
entity.instance = 0x7f;
j=1;
@@ -4560,7 +4675,7 @@ ipmi_sdr_print_entity(struct ipmi_intf *intf, char *entitystr)
list = ipmi_sdr_find_sdr_byentity(intf, &entity);
- for (entry = list; entry != NULL; entry = entry->next) {
+ for (entry = list; entry; entry = entry->next) {
rc = ipmi_sdr_print_listentry(intf, entry);
}
@@ -4595,7 +4710,7 @@ ipmi_sdr_print_entry_byid(struct ipmi_intf *intf, int argc, char **argv)
for (i = 0; i < argc; i++) {
sdr = ipmi_sdr_find_sdr_byid(intf, argv[i]);
- if (sdr == NULL) {
+ if (!sdr) {
lprintf(LOG_ERR, "Unable to find sensor id '%s'",
argv[i]);
} else {
@@ -4626,41 +4741,41 @@ ipmi_sdr_main(struct ipmi_intf *intf, int argc, char **argv)
/* initialize random numbers used later */
srand(time(NULL));
- if (argc == 0)
+ if (argc == 0) {
return ipmi_sdr_print_sdr(intf, 0xfe);
- else if (strncmp(argv[0], "help", 4) == 0) {
+ } else if (!strcmp(argv[0], "help")) {
printf_sdr_usage();
- } else if (strncmp(argv[0], "list", 4) == 0
- || strncmp(argv[0], "elist", 5) == 0) {
-
- if (strncmp(argv[0], "elist", 5) == 0)
+ } else if (!strcmp(argv[0], "list")
+ || !strcmp(argv[0], "elist"))
+ {
+ if (!strcmp(argv[0], "elist"))
sdr_extended = 1;
else
sdr_extended = 0;
if (argc <= 1)
rc = ipmi_sdr_print_sdr(intf, 0xfe);
- else if (strncmp(argv[1], "all", 3) == 0)
+ else if (!strcmp(argv[1], "all"))
rc = ipmi_sdr_print_sdr(intf, 0xff);
- else if (strncmp(argv[1], "full", 4) == 0)
+ else if (!strcmp(argv[1], "full"))
rc = ipmi_sdr_print_sdr(intf,
SDR_RECORD_TYPE_FULL_SENSOR);
- else if (strncmp(argv[1], "compact", 7) == 0)
+ else if (!strcmp(argv[1], "compact"))
rc = ipmi_sdr_print_sdr(intf,
SDR_RECORD_TYPE_COMPACT_SENSOR);
- else if (strncmp(argv[1], "event", 5) == 0)
+ else if (!strcmp(argv[1], "event"))
rc = ipmi_sdr_print_sdr(intf,
SDR_RECORD_TYPE_EVENTONLY_SENSOR);
- else if (strncmp(argv[1], "mcloc", 5) == 0)
+ else if (!strcmp(argv[1], "mcloc"))
rc = ipmi_sdr_print_sdr(intf,
SDR_RECORD_TYPE_MC_DEVICE_LOCATOR);
- else if (strncmp(argv[1], "fru", 3) == 0)
+ else if (!strcmp(argv[1], "fru"))
rc = ipmi_sdr_print_sdr(intf,
SDR_RECORD_TYPE_FRU_DEVICE_LOCATOR);
- else if (strncmp(argv[1], "generic", 7) == 0)
+ else if (!strcmp(argv[1], "generic"))
rc = ipmi_sdr_print_sdr(intf,
SDR_RECORD_TYPE_GENERIC_DEVICE_LOCATOR);
- else if (strcmp(argv[1], "help") == 0) {
+ else if (!strcmp(argv[1], "help")) {
lprintf(LOG_NOTICE,
"usage: sdr %s [all|full|compact|event|mcloc|fru|generic]",
argv[0]);
@@ -4675,35 +4790,35 @@ ipmi_sdr_main(struct ipmi_intf *intf, int argc, char **argv)
argv[0]);
return (-1);
}
- } else if (strncmp(argv[0], "type", 4) == 0) {
+ } else if (!strcmp(argv[0], "type")) {
sdr_extended = 1;
rc = ipmi_sdr_print_type(intf, argv[1]);
- } else if (strncmp(argv[0], "entity", 6) == 0) {
+ } else if (!strcmp(argv[0], "entity")) {
sdr_extended = 1;
rc = ipmi_sdr_print_entity(intf, argv[1]);
- } else if (strncmp(argv[0], "info", 4) == 0) {
+ } else if (!strcmp(argv[0], "info")) {
rc = ipmi_sdr_print_info(intf);
- } else if (strncmp(argv[0], "get", 3) == 0) {
+ } else if (!strcmp(argv[0], "get")) {
rc = ipmi_sdr_print_entry_byid(intf, argc - 1, &argv[1]);
- } else if (strncmp(argv[0], "dump", 4) == 0) {
+ } else if (!strcmp(argv[0], "dump")) {
if (argc < 2) {
lprintf(LOG_ERR, "Not enough parameters given.");
lprintf(LOG_NOTICE, "usage: sdr dump <file>");
return (-1);
}
rc = ipmi_sdr_dump_bin(intf, argv[1]);
- } else if (strncmp(argv[0], "fill", 4) == 0) {
+ } else if (!strcmp(argv[0], "fill")) {
if (argc <= 1) {
lprintf(LOG_ERR, "Not enough parameters given.");
lprintf(LOG_NOTICE, "usage: sdr fill sensors");
lprintf(LOG_NOTICE, "usage: sdr fill file <file>");
lprintf(LOG_NOTICE, "usage: sdr fill range <range>");
return (-1);
- } else if (strncmp(argv[1], "sensors", 7) == 0) {
+ } else if (!strcmp(argv[1], "sensors")) {
rc = ipmi_sdr_add_from_sensors(intf, 21);
- } else if (strncmp(argv[1], "nosat", 5) == 0) {
+ } else if (!strcmp(argv[1], "nosat")) {
rc = ipmi_sdr_add_from_sensors(intf, 0);
- } else if (strncmp(argv[1], "file", 4) == 0) {
+ } else if (!strcmp(argv[1], "file")) {
if (argc < 3) {
lprintf(LOG_ERR,
"Not enough parameters given.");
@@ -4712,7 +4827,7 @@ ipmi_sdr_main(struct ipmi_intf *intf, int argc, char **argv)
return (-1);
}
rc = ipmi_sdr_add_from_file(intf, argv[2]);
- } else if (strncmp(argv[1], "range", 4) == 0) {
+ } else if (!strcmp(argv[1], "range")) {
if (argc < 3) {
lprintf(LOG_ERR,
"Not enough parameters given.");