mirror of
https://github.com/ipmitool/ipmitool.git
synced 2025-05-11 11:07:23 +00:00
1887 lines
50 KiB
C
1887 lines
50 KiB
C
/* -*-mode: C; indent-tabs-mode: t; -*-
|
|
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions
|
|
* are met:
|
|
*
|
|
* Redistribution of source code must retain the above copyright
|
|
* notice, this list of conditions and the following disclaimer.
|
|
*
|
|
* Redistribution in binary form must reproduce the above copyright
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
* documentation and/or other materials provided with the distribution.
|
|
*
|
|
* Neither the name of Sun Microsystems, Inc. or the names of
|
|
* contributors may be used to endorse or promote products derived
|
|
* from this software without specific prior written permission.
|
|
*
|
|
* This software is provided "AS IS," without a warranty of any kind.
|
|
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
|
|
* INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
|
|
* PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED.
|
|
* SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE
|
|
* FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
|
|
* OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL
|
|
* SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA,
|
|
* OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
|
|
* PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF
|
|
* 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.
|
|
*/
|
|
|
|
#include <string.h>
|
|
#include <math.h>
|
|
#define __USE_XOPEN /* glibc2 needs this for strptime */
|
|
#include <time.h>
|
|
|
|
#include <ipmitool/helper.h>
|
|
#include <ipmitool/log.h>
|
|
#include <ipmitool/ipmi.h>
|
|
#include <ipmitool/ipmi_mc.h>
|
|
#include <ipmitool/ipmi_intf.h>
|
|
#include <ipmitool/ipmi_sel.h>
|
|
#include <ipmitool/ipmi_sdr.h>
|
|
#include <ipmitool/ipmi_fru.h>
|
|
#include <ipmitool/ipmi_sensor.h>
|
|
|
|
extern int verbose;
|
|
|
|
static int sel_extended = 0;
|
|
|
|
static FILE * fp;
|
|
static int sel_oem_nrecs = 0;
|
|
struct ipmi_sel_oem_msg_rec {
|
|
int value[14];
|
|
char *string[14];
|
|
char *text;
|
|
} *sel_oem_msg;
|
|
|
|
#define SEL_BYTE(n) (n-3) /* So we can refer to byte positions in log entries (byte 3 is at index 0, etc) */
|
|
|
|
/*
|
|
* Reads values found in message translation file. XX is a wildcard, R means reserved.
|
|
* Returns -1 for XX, -2 for R, -3 for non-hex (string), or positive integer from a hex value.
|
|
*/
|
|
static int ipmi_sel_oem_readval(char *str)
|
|
{
|
|
int ret;
|
|
if (!strcmp(str, "XX")) {
|
|
return -1;
|
|
}
|
|
if (!strcmp(str, "R")) {
|
|
return -2;
|
|
}
|
|
if (sscanf(str, "0x%x", &ret) != 1) {
|
|
return -3;
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
/*
|
|
* This is where the magic happens. SEL_BYTE is a bit ugly, but it allows
|
|
* reference to byte positions instead of array indexes which (hopefully)
|
|
* helps make the code easier to read.
|
|
*/
|
|
static int ipmi_sel_oem_match(uint8_t *evt, struct ipmi_sel_oem_msg_rec rec)
|
|
{
|
|
if (evt[2] == rec.value[SEL_BYTE(3)] &&
|
|
((rec.value[SEL_BYTE(4)] < 0) || (evt[3] == rec.value[SEL_BYTE(4)])) &&
|
|
((rec.value[SEL_BYTE(5)] < 0) || (evt[4] == rec.value[SEL_BYTE(5)])) &&
|
|
((rec.value[SEL_BYTE(6)] < 0) || (evt[5] == rec.value[SEL_BYTE(6)])) &&
|
|
((rec.value[SEL_BYTE(7)] < 0) || (evt[6] == rec.value[SEL_BYTE(7)])) &&
|
|
((rec.value[SEL_BYTE(11)] < 0) || (evt[10] == rec.value[SEL_BYTE(11)])) &&
|
|
((rec.value[SEL_BYTE(12)] < 0) || (evt[11] == rec.value[SEL_BYTE(12)]))) {
|
|
return 1;
|
|
} else {
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
int ipmi_sel_oem_init(const char * filename)
|
|
{
|
|
FILE * fp;
|
|
int i, j, k, n, byte;
|
|
char buf[15][150];
|
|
|
|
if (filename == NULL) {
|
|
lprintf(LOG_ERR, "No SEL OEM filename provided");
|
|
return -1;
|
|
}
|
|
|
|
fp = ipmi_open_file_read(filename);
|
|
if (fp == NULL) {
|
|
lprintf(LOG_ERR, "Could not open %s file", filename);
|
|
return;
|
|
}
|
|
|
|
/* count number of records (lines) in input file */
|
|
sel_oem_nrecs = 0;
|
|
while (fscanf(fp, "%*[^\n]\n", buf[0]) == 0) {
|
|
sel_oem_nrecs++;
|
|
}
|
|
|
|
rewind(fp);
|
|
sel_oem_msg = (struct ipmi_sel_oem_msg_rec *)calloc(sel_oem_nrecs,
|
|
sizeof(struct ipmi_sel_oem_msg_rec));
|
|
|
|
for (i=0; i < sel_oem_nrecs; i++) {
|
|
n=fscanf(fp, "\"%[^\"]\",\"%[^\"]\",\"%[^\"]\",\"%[^\"]\",\""
|
|
"%[^\"]\",\"%[^\"]\",\"%[^\"]\",\"%[^\"]\",\""
|
|
"%[^\"]\",\"%[^\"]\",\"%[^\"]\",\"%[^\"]\",\""
|
|
"%[^\"]\",\"%[^\"]\",\"%[^\"]\"\n",
|
|
buf[0], buf[1], buf[2], buf[3], buf[4], buf[5],
|
|
buf[6], buf[7], buf[8], buf[9], buf[10], buf[11],
|
|
buf[12], buf[13], buf[14]);
|
|
|
|
if (n != 15) {
|
|
lprintf (LOG_ERR, "Encountered problems reading line %d of %s",
|
|
i+1, filename);
|
|
fclose(fp);
|
|
fp = NULL;
|
|
sel_oem_nrecs = 0;
|
|
/* free all the memory allocated so far */
|
|
for (j=0; j<i ; j++) {
|
|
for (k=3; k<17; k++) {
|
|
if (sel_oem_msg[j].value[SEL_BYTE(k)] == -3) {
|
|
free(sel_oem_msg[j].string[SEL_BYTE(k)]);
|
|
}
|
|
}
|
|
}
|
|
free (sel_oem_msg);
|
|
return;
|
|
}
|
|
|
|
for (byte = 3; byte < 17; byte++) {
|
|
if ((sel_oem_msg[i].value[SEL_BYTE(byte)] =
|
|
ipmi_sel_oem_readval(buf[SEL_BYTE(byte)])) == -3) {
|
|
sel_oem_msg[i].string[SEL_BYTE(byte)] =
|
|
(char *)malloc(strlen(buf[SEL_BYTE(byte)]) + 1);
|
|
strcpy(sel_oem_msg[i].string[SEL_BYTE(byte)],
|
|
buf[SEL_BYTE(byte)]);
|
|
}
|
|
}
|
|
sel_oem_msg[i].text = (char *)malloc(strlen(buf[SEL_BYTE(17)]) + 1);
|
|
strcpy(sel_oem_msg[i].text, buf[SEL_BYTE(17)]);
|
|
}
|
|
fclose(fp);
|
|
fp = NULL;
|
|
}
|
|
|
|
static void ipmi_sel_oem_message(struct sel_event_record * evt, int verbose)
|
|
{
|
|
/*
|
|
* Note: although we have a verbose argument, currently the output
|
|
* isn't affected by it.
|
|
*/
|
|
int i, j;
|
|
|
|
for (i=0; i < sel_oem_nrecs; i++) {
|
|
if (ipmi_sel_oem_match((uint8_t *)evt, sel_oem_msg[i])) {
|
|
printf (csv_output ? ",\"%s\"" : " | %s", sel_oem_msg[i].text);
|
|
for (j=4; j<17; j++) {
|
|
if (sel_oem_msg[i].value[SEL_BYTE(j)] == -3) {
|
|
printf (csv_output ? ",%s=0x%x" : " %s = 0x%x",
|
|
sel_oem_msg[i].string[SEL_BYTE(j)],
|
|
((uint8_t *)evt)[SEL_BYTE(j)]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
static const struct valstr event_dir_vals[] = {
|
|
{ 0, "Assertion Event" },
|
|
{ 1, "Deassertion Event" },
|
|
{ 0, NULL },
|
|
};
|
|
|
|
static const char *
|
|
ipmi_get_event_type(uint8_t code)
|
|
{
|
|
if (code == 0)
|
|
return "Unspecified";
|
|
if (code == 1)
|
|
return "Threshold";
|
|
if (code >= 0x02 && code <= 0x0b)
|
|
return "Generic Discrete";
|
|
if (code == 0x6f)
|
|
return "Sensor-specific Discrete";
|
|
if (code >= 0x70 && code <= 0x7f)
|
|
return "OEM";
|
|
return "Reserved";
|
|
}
|
|
|
|
static char *
|
|
ipmi_sel_timestamp(uint32_t stamp)
|
|
{
|
|
static char tbuf[40];
|
|
time_t s = (time_t)stamp;
|
|
memset(tbuf, 0, 40);
|
|
strftime(tbuf, sizeof(tbuf), "%m/%d/%Y %H:%M:%S", localtime(&s));
|
|
return tbuf;
|
|
}
|
|
|
|
static char *
|
|
ipmi_sel_timestamp_date(uint32_t stamp)
|
|
{
|
|
static char tbuf[11];
|
|
time_t s = (time_t)stamp;
|
|
strftime(tbuf, sizeof(tbuf), "%m/%d/%Y", localtime(&s));
|
|
return tbuf;
|
|
}
|
|
|
|
static char *
|
|
ipmi_sel_timestamp_time(uint32_t stamp)
|
|
{
|
|
static char tbuf[9];
|
|
time_t s = (time_t)stamp;
|
|
strftime(tbuf, sizeof(tbuf), "%H:%M:%S", localtime(&s));
|
|
return tbuf;
|
|
}
|
|
|
|
static char *
|
|
hex2ascii (uint8_t * hexChars, uint8_t numBytes)
|
|
{
|
|
int count;
|
|
static char hexString[SEL_OEM_NOTS_DATA_LEN+1]; /*Max Size*/
|
|
|
|
if(numBytes > SEL_OEM_NOTS_DATA_LEN)
|
|
numBytes = SEL_OEM_NOTS_DATA_LEN;
|
|
|
|
for(count=0;count < numBytes;count++)
|
|
{
|
|
if((hexChars[count]<0x40)||(hexChars[count]>0x7e))
|
|
hexString[count]='.';
|
|
else
|
|
hexString[count]=hexChars[count];
|
|
}
|
|
hexString[numBytes]='\0';
|
|
return hexString;
|
|
}
|
|
|
|
IPMI_OEM
|
|
ipmi_get_oem(struct ipmi_intf * intf)
|
|
{
|
|
/* Execute a Get Device ID command to determine the OEM */
|
|
struct ipmi_rs * rsp;
|
|
struct ipmi_rq req;
|
|
struct ipm_devid_rsp *devid;
|
|
uint32_t manufacturer_id;
|
|
int i;
|
|
|
|
if (intf->fd == 0)
|
|
return IPMI_OEM_UNKNOWN;
|
|
|
|
memset(&req, 0, sizeof(req));
|
|
req.msg.netfn = IPMI_NETFN_APP;
|
|
req.msg.cmd = BMC_GET_DEVICE_ID;
|
|
req.msg.data_len = 0;
|
|
|
|
rsp = intf->sendrecv(intf, &req);
|
|
if (rsp == NULL) {
|
|
lprintf(LOG_ERR, "Get Device ID command failed");
|
|
return IPMI_OEM_UNKNOWN;
|
|
}
|
|
if (rsp->ccode > 0) {
|
|
lprintf(LOG_ERR, "Get Device ID command failed: %s",
|
|
val2str(rsp->ccode, completion_code_vals));
|
|
return IPMI_OEM_UNKNOWN;
|
|
}
|
|
|
|
devid = (struct ipm_devid_rsp *) rsp->data;
|
|
return IPM_DEV_MANUFACTURER_ID(devid->manufacturer_id);
|
|
}
|
|
|
|
|
|
static int
|
|
ipmi_sel_add_entry(struct ipmi_intf * intf, struct sel_event_record * rec)
|
|
{
|
|
struct ipmi_rs * rsp;
|
|
struct ipmi_rq req;
|
|
|
|
req.msg.netfn = IPMI_NETFN_STORAGE;
|
|
req.msg.cmd = IPMI_CMD_ADD_SEL_ENTRY;
|
|
req.msg.data = (unsigned char *)rec;
|
|
req.msg.data_len = 16;
|
|
|
|
ipmi_sel_print_std_entry(intf, rec);
|
|
|
|
rsp = intf->sendrecv(intf, &req);
|
|
if (rsp == NULL) {
|
|
lprintf(LOG_ERR, "Add SEL Entry failed");
|
|
return -1;
|
|
}
|
|
else if (rsp->ccode > 0) {
|
|
lprintf(LOG_ERR, "Add SEL Entry failed: %s",
|
|
val2str(rsp->ccode, completion_code_vals));
|
|
return -1;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
static int
|
|
ipmi_sel_add_entries_fromfile(struct ipmi_intf * intf, const char * filename)
|
|
{
|
|
FILE * fp;
|
|
char buf[1024];
|
|
char * ptr, * tok;
|
|
int i, j;
|
|
int rc = 0;
|
|
uint8_t rqdata[8];
|
|
struct sel_event_record sel_event;
|
|
|
|
if (filename == NULL)
|
|
return -1;
|
|
|
|
fp = ipmi_open_file_read(filename);
|
|
if (fp == NULL)
|
|
return -1;
|
|
|
|
while (feof(fp) == 0) {
|
|
if (fgets(buf, 1024, fp) == NULL)
|
|
continue;
|
|
|
|
/* clip off optional comment tail indicated by # */
|
|
ptr = strchr(buf, '#');
|
|
if (ptr)
|
|
*ptr = '\0';
|
|
else
|
|
ptr = buf + strlen(buf);
|
|
|
|
/* clip off trailing and leading whitespace */
|
|
ptr--;
|
|
while (isspace(*ptr) && ptr >= buf)
|
|
*ptr-- = '\0';
|
|
ptr = buf;
|
|
while (isspace(*ptr))
|
|
ptr++;
|
|
if (strlen(ptr) == 0)
|
|
continue;
|
|
|
|
/* parse the event, 7 bytes with optional comment */
|
|
/* 0x00 0x00 0x00 0x00 0x00 0x00 0x00 # event */
|
|
i = 0;
|
|
tok = strtok(ptr, " ");
|
|
while (tok) {
|
|
if (i == 7)
|
|
break;
|
|
j = i++;
|
|
rqdata[j] = (uint8_t)strtol(tok, NULL, 0);
|
|
tok = strtok(NULL, " ");
|
|
}
|
|
if (i < 7) {
|
|
lprintf(LOG_ERR, "Invalid Event: %s",
|
|
buf2str(rqdata, sizeof(rqdata)));
|
|
continue;
|
|
}
|
|
|
|
memset(&sel_event, 0, sizeof(struct sel_event_record));
|
|
sel_event.record_id = 0x0000;
|
|
sel_event.record_type = 0x02;
|
|
sel_event.sel_type.standard_type.gen_id = 0x00;
|
|
sel_event.sel_type.standard_type.evm_rev = rqdata[0];
|
|
sel_event.sel_type.standard_type.sensor_type = rqdata[1];
|
|
sel_event.sel_type.standard_type.sensor_num = rqdata[2];
|
|
sel_event.sel_type.standard_type.event_type = rqdata[3] & 0x7f;
|
|
sel_event.sel_type.standard_type.event_dir = (rqdata[3] & 0x80) >> 7;
|
|
sel_event.sel_type.standard_type.event_data[0] = rqdata[4];
|
|
sel_event.sel_type.standard_type.event_data[1] = rqdata[5];
|
|
sel_event.sel_type.standard_type.event_data[2] = rqdata[6];
|
|
|
|
rc = ipmi_sel_add_entry(intf, &sel_event);
|
|
if (rc < 0)
|
|
break;
|
|
}
|
|
|
|
fclose(fp);
|
|
return rc;
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
get_newisys_evt_desc(struct ipmi_intf * intf, struct sel_event_record * rec)
|
|
{
|
|
/*
|
|
* Newisys OEM event descriptions can be retrieved through an
|
|
* OEM IPMI command.
|
|
*/
|
|
struct ipmi_rs * rsp;
|
|
struct ipmi_rq req;
|
|
uint8_t msg_data[6];
|
|
char * description = NULL;
|
|
|
|
memset(&req, 0, sizeof(req));
|
|
req.msg.netfn = 0x2E;
|
|
req.msg.cmd = 0x01;
|
|
req.msg.data_len = sizeof(msg_data);
|
|
|
|
msg_data[0] = 0x15; /* IANA LSB */
|
|
msg_data[1] = 0x24; /* IANA */
|
|
msg_data[2] = 0x00; /* IANA MSB */
|
|
msg_data[3] = 0x01; /* Subcommand */
|
|
msg_data[4] = rec->record_id & 0x00FF; /* SEL Record ID LSB */
|
|
msg_data[5] = (rec->record_id & 0xFF00) >> 8; /* SEL Record ID MSB */
|
|
|
|
req.msg.data = msg_data;
|
|
|
|
rsp = intf->sendrecv(intf, &req);
|
|
if (rsp == NULL) {
|
|
if (verbose)
|
|
lprintf(LOG_ERR, "Error issuing OEM command");
|
|
return NULL;
|
|
}
|
|
if (rsp->ccode > 0) {
|
|
if (verbose)
|
|
lprintf(LOG_ERR, "OEM command returned error code: %s",
|
|
val2str(rsp->ccode, completion_code_vals));
|
|
return NULL;
|
|
}
|
|
|
|
/* Verify our response before we use it */
|
|
if (rsp->data_len < 5)
|
|
{
|
|
lprintf(LOG_ERR, "Newisys OEM response too short");
|
|
return NULL;
|
|
}
|
|
else if (rsp->data_len != (4 + rsp->data[3]))
|
|
{
|
|
lprintf(LOG_ERR, "Newisys OEM response has unexpected length");
|
|
return NULL;
|
|
}
|
|
else if (IPM_DEV_MANUFACTURER_ID(rsp->data) != IPMI_OEM_NEWISYS)
|
|
{
|
|
lprintf(LOG_ERR, "Newisys OEM response has unexpected length");
|
|
return NULL;
|
|
}
|
|
|
|
description = (char*)malloc(rsp->data[3] + 1);
|
|
memcpy(description, rsp->data + 4, rsp->data[3]);
|
|
description[rsp->data[3]] = 0;;
|
|
|
|
return description;
|
|
}
|
|
|
|
char *
|
|
ipmi_get_oem_desc(struct ipmi_intf * intf, struct sel_event_record * rec)
|
|
{
|
|
char * desc = NULL;
|
|
|
|
switch (ipmi_get_oem(intf))
|
|
{
|
|
case IPMI_OEM_NEWISYS:
|
|
desc = get_newisys_evt_desc(intf, rec);
|
|
break;
|
|
}
|
|
|
|
return desc;
|
|
}
|
|
|
|
|
|
void
|
|
ipmi_get_event_desc(struct ipmi_intf * intf, struct sel_event_record * rec, char ** desc)
|
|
{
|
|
uint8_t code, offset;
|
|
struct ipmi_event_sensor_types *evt;
|
|
|
|
if (desc == NULL)
|
|
return;
|
|
*desc = NULL;
|
|
|
|
if ((rec->sel_type.standard_type.event_type >= 0x70) && (rec->sel_type.standard_type.event_type < 0x7F)) {
|
|
*desc = ipmi_get_oem_desc(intf, rec);
|
|
return;
|
|
} else if (rec->sel_type.standard_type.event_type == 0x6f) {
|
|
evt = sensor_specific_types;
|
|
code = rec->sel_type.standard_type.sensor_type;
|
|
} else {
|
|
evt = generic_event_types;
|
|
code = rec->sel_type.standard_type.event_type;
|
|
}
|
|
|
|
offset = rec->sel_type.standard_type.event_data[0] & 0xf;
|
|
|
|
while (evt->type) {
|
|
if ((evt->code == code && evt->offset == offset && evt->desc != NULL) &&
|
|
((evt->data == ALL_OFFSETS_SPECIFIED) ||
|
|
((rec->sel_type.standard_type.event_data[0] & DATA_BYTE2_SPECIFIED_MASK) &&
|
|
(evt->data == rec->sel_type.standard_type.event_data[1]))))
|
|
{
|
|
*desc = (char *)malloc(strlen(evt->desc) + 48);
|
|
if (*desc == NULL) {
|
|
lprintf(LOG_ERR, "ipmitool: malloc failure");
|
|
return;
|
|
}
|
|
memset(*desc, 0, strlen(evt->desc)+48);
|
|
sprintf(*desc, "%s", evt->desc);
|
|
return;
|
|
}
|
|
evt++;
|
|
}
|
|
}
|
|
|
|
const char *
|
|
ipmi_sel_get_sensor_type(uint8_t code)
|
|
{
|
|
struct ipmi_event_sensor_types *st;
|
|
for (st = sensor_specific_types; st->type != NULL; st++)
|
|
if (st->code == code)
|
|
return st->type;
|
|
return "Unknown";
|
|
}
|
|
|
|
const char *
|
|
ipmi_sel_get_sensor_type_offset(uint8_t code, uint8_t offset)
|
|
{
|
|
struct ipmi_event_sensor_types *st;
|
|
for (st = sensor_specific_types; st->type != NULL; st++)
|
|
if (st->code == code && st->offset == (offset&0xf))
|
|
return st->type;
|
|
return ipmi_sel_get_sensor_type(code);
|
|
}
|
|
|
|
static int
|
|
ipmi_sel_get_info(struct ipmi_intf * intf)
|
|
{
|
|
struct ipmi_rs * rsp;
|
|
struct ipmi_rq req;
|
|
uint16_t e, f, version;
|
|
int pctfull = 0;
|
|
uint32_t fs = 0xffffffff;
|
|
uint32_t zeros = 0;
|
|
|
|
|
|
memset(&req, 0, sizeof(req));
|
|
req.msg.netfn = IPMI_NETFN_STORAGE;
|
|
req.msg.cmd = IPMI_CMD_GET_SEL_INFO;
|
|
|
|
rsp = intf->sendrecv(intf, &req);
|
|
if (rsp == NULL) {
|
|
lprintf(LOG_ERR, "Get SEL Info command failed");
|
|
return -1;
|
|
}
|
|
if (rsp->ccode > 0) {
|
|
lprintf(LOG_ERR, "Get SEL Info command failed: %s",
|
|
val2str(rsp->ccode, completion_code_vals));
|
|
return -1;
|
|
}
|
|
if (verbose > 2)
|
|
printbuf(rsp->data, rsp->data_len, "sel_info");
|
|
|
|
printf("SEL Information\n");
|
|
version = rsp->data[0];
|
|
printf("Version : %d.%d (%s)\n",
|
|
version & 0xf, (version>>4) & 0xf,
|
|
(version == 0x51 || version == 0x02) ? "v1.5, v2 compliant" : "Unknown");
|
|
|
|
/* save the entry count and free space to determine percent full */
|
|
e = buf2short(rsp->data + 1);
|
|
f = buf2short(rsp->data + 3);
|
|
printf("Entries : %d\n", e);
|
|
printf("Free Space : %d bytes\n", f);
|
|
if (e) {
|
|
e *= 16;
|
|
f += e;
|
|
pctfull = (int)(100 * ( (double)e / (double)f ));
|
|
}
|
|
printf("Percent Used : %d%%\n", pctfull);
|
|
|
|
|
|
if ((!memcmp(rsp->data + 5, &fs, 4)) ||
|
|
(!memcmp(rsp->data + 5, &zeros, 4)))
|
|
printf("Last Add Time : Not Available\n");
|
|
else
|
|
printf("Last Add Time : %s\n",
|
|
ipmi_sel_timestamp(buf2long(rsp->data + 5)));
|
|
|
|
if ((!memcmp(rsp->data + 9, &fs, 4)) ||
|
|
(!memcmp(rsp->data + 9, &zeros, 4)))
|
|
printf("Last Del Time : Not Available\n");
|
|
else
|
|
printf("Last Del Time : %s\n",
|
|
ipmi_sel_timestamp(buf2long(rsp->data + 9)));
|
|
|
|
|
|
printf("Overflow : %s\n",
|
|
rsp->data[13] & 0x80 ? "true" : "false");
|
|
printf("Supported Cmds : ");
|
|
if (rsp->data[13] & 0x0f)
|
|
{
|
|
if (rsp->data[13] & 0x08)
|
|
printf("'Delete' ");
|
|
if (rsp->data[13] & 0x04)
|
|
printf("'Partial Add' ");
|
|
if (rsp->data[13] & 0x02)
|
|
printf("'Reserve' ");
|
|
if (rsp->data[13] & 0x01)
|
|
printf("'Get Alloc Info' ");
|
|
}
|
|
else
|
|
printf("None");
|
|
printf("\n");
|
|
|
|
/* get sel allocation info if supported */
|
|
if (rsp->data[13] & 1) {
|
|
memset(&req, 0, sizeof(req));
|
|
req.msg.netfn = IPMI_NETFN_STORAGE;
|
|
req.msg.cmd = IPMI_CMD_GET_SEL_ALLOC_INFO;
|
|
|
|
rsp = intf->sendrecv(intf, &req);
|
|
if (rsp == NULL) {
|
|
lprintf(LOG_ERR,
|
|
"Get SEL Allocation Info command failed");
|
|
return -1;
|
|
}
|
|
if (rsp->ccode > 0) {
|
|
lprintf(LOG_ERR,
|
|
"Get SEL Allocation Info command failed: %s",
|
|
val2str(rsp->ccode, completion_code_vals));
|
|
return -1;
|
|
}
|
|
|
|
printf("# of Alloc Units : %d\n", buf2short(rsp->data));
|
|
printf("Alloc Unit Size : %d\n", buf2short(rsp->data + 2));
|
|
printf("# Free Units : %d\n", buf2short(rsp->data + 4));
|
|
printf("Largest Free Blk : %d\n", buf2short(rsp->data + 6));
|
|
printf("Max Record Size : %d\n", rsp->data[7]);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
uint16_t
|
|
ipmi_sel_get_std_entry(struct ipmi_intf * intf, uint16_t id,
|
|
struct sel_event_record * evt)
|
|
{
|
|
struct ipmi_rq req;
|
|
struct ipmi_rs * rsp;
|
|
uint8_t msg_data[6];
|
|
uint16_t next;
|
|
int data_count;
|
|
|
|
memset(msg_data, 0, 6);
|
|
msg_data[0] = 0x00; /* no reserve id, not partial get */
|
|
msg_data[1] = 0x00;
|
|
msg_data[2] = id & 0xff;
|
|
msg_data[3] = (id >> 8) & 0xff;
|
|
msg_data[4] = 0x00; /* offset */
|
|
msg_data[5] = 0xff; /* length */
|
|
|
|
memset(&req, 0, sizeof(req));
|
|
req.msg.netfn = IPMI_NETFN_STORAGE;
|
|
req.msg.cmd = IPMI_CMD_GET_SEL_ENTRY;
|
|
req.msg.data = msg_data;
|
|
req.msg.data_len = 6;
|
|
|
|
rsp = intf->sendrecv(intf, &req);
|
|
if (rsp == NULL) {
|
|
lprintf(LOG_ERR, "Get SEL Entry %x command failed", id);
|
|
return 0;
|
|
}
|
|
if (rsp->ccode > 0) {
|
|
lprintf(LOG_ERR, "Get SEL Entry %x command failed: %s",
|
|
id, val2str(rsp->ccode, completion_code_vals));
|
|
return 0;
|
|
}
|
|
|
|
/* save next entry id */
|
|
next = (rsp->data[1] << 8) | rsp->data[0];
|
|
|
|
lprintf(LOG_DEBUG, "SEL Entry: %s", buf2str(rsp->data+2, rsp->data_len-2));
|
|
memset(evt, 0, sizeof(*evt));
|
|
|
|
/*Clear SEL Structure*/
|
|
evt->record_id = 0;
|
|
evt->record_type = 0;
|
|
if (evt->record_type < 0xc0)
|
|
{
|
|
evt->sel_type.standard_type.timestamp = 0;
|
|
evt->sel_type.standard_type.gen_id = 0;
|
|
evt->sel_type.standard_type.evm_rev = 0;
|
|
evt->sel_type.standard_type.sensor_type = 0;
|
|
evt->sel_type.standard_type.sensor_num = 0;
|
|
evt->sel_type.standard_type.event_type = 0;
|
|
evt->sel_type.standard_type.event_dir = 0;
|
|
evt->sel_type.standard_type.event_data[0] = 0;
|
|
evt->sel_type.standard_type.event_data[1] = 0;
|
|
evt->sel_type.standard_type.event_data[2] = 0;
|
|
}
|
|
else if (evt->record_type < 0xe0)
|
|
{
|
|
evt->sel_type.oem_ts_type.timestamp = 0;
|
|
evt->sel_type.oem_ts_type.manf_id[0] = 0;
|
|
evt->sel_type.oem_ts_type.manf_id[1] = 0;
|
|
evt->sel_type.oem_ts_type.manf_id[2] = 0;
|
|
for(data_count=0; data_count < SEL_OEM_TS_DATA_LEN ; data_count++)
|
|
evt->sel_type.oem_ts_type.oem_defined[data_count] = 0;
|
|
}
|
|
else
|
|
{
|
|
for(data_count=0; data_count < SEL_OEM_NOTS_DATA_LEN ; data_count++)
|
|
evt->sel_type.oem_nots_type.oem_defined[data_count] = 0;
|
|
}
|
|
|
|
/* save response into SEL event structure */
|
|
evt->record_id = (rsp->data[3] << 8) | rsp->data[2];
|
|
evt->record_type = rsp->data[4];
|
|
if (evt->record_type < 0xc0)
|
|
{
|
|
evt->sel_type.standard_type.timestamp = (rsp->data[8] << 24) | (rsp->data[7] << 16) |
|
|
(rsp->data[6] << 8) | rsp->data[5];
|
|
evt->sel_type.standard_type.gen_id = (rsp->data[10] << 8) | rsp->data[9];
|
|
evt->sel_type.standard_type.evm_rev = rsp->data[11];
|
|
evt->sel_type.standard_type.sensor_type = rsp->data[12];
|
|
evt->sel_type.standard_type.sensor_num = rsp->data[13];
|
|
evt->sel_type.standard_type.event_type = rsp->data[14] & 0x7f;
|
|
evt->sel_type.standard_type.event_dir = (rsp->data[14] & 0x80) >> 7;
|
|
evt->sel_type.standard_type.event_data[0] = rsp->data[15];
|
|
evt->sel_type.standard_type.event_data[1] = rsp->data[16];
|
|
evt->sel_type.standard_type.event_data[2] = rsp->data[17];
|
|
}
|
|
else if (evt->record_type < 0xe0)
|
|
{
|
|
evt->sel_type.oem_ts_type.timestamp= (rsp->data[8] << 24) | (rsp->data[7] << 16) |
|
|
(rsp->data[6] << 8) | rsp->data[5];
|
|
evt->sel_type.oem_ts_type.manf_id[0]= rsp->data[11];
|
|
evt->sel_type.oem_ts_type.manf_id[1]= rsp->data[10];
|
|
evt->sel_type.oem_ts_type.manf_id[2]= rsp->data[9];
|
|
for(data_count=0; data_count < SEL_OEM_TS_DATA_LEN ; data_count++)
|
|
evt->sel_type.oem_ts_type.oem_defined[data_count] = rsp->data[(data_count+12)];
|
|
}
|
|
else
|
|
{
|
|
for(data_count=0; data_count < SEL_OEM_NOTS_DATA_LEN ; data_count++)
|
|
evt->sel_type.oem_nots_type.oem_defined[data_count] = rsp->data[(data_count+5)];
|
|
}
|
|
return next;
|
|
}
|
|
|
|
static void
|
|
ipmi_sel_print_event_file(struct ipmi_intf * intf, struct sel_event_record * evt, FILE * fp)
|
|
{
|
|
char * description;
|
|
|
|
if (fp == NULL)
|
|
return;
|
|
|
|
ipmi_get_event_desc(intf, evt, &description);
|
|
|
|
fprintf(fp, "0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x # %s #0x%02x %s\n",
|
|
evt->sel_type.standard_type.evm_rev,
|
|
evt->sel_type.standard_type.sensor_type,
|
|
evt->sel_type.standard_type.sensor_num,
|
|
evt->sel_type.standard_type.event_type | (evt->sel_type.standard_type.event_dir << 7),
|
|
evt->sel_type.standard_type.event_data[0],
|
|
evt->sel_type.standard_type.event_data[1],
|
|
evt->sel_type.standard_type.event_data[2],
|
|
ipmi_sel_get_sensor_type_offset(evt->sel_type.standard_type.sensor_type, evt->sel_type.standard_type.event_data[0]),
|
|
evt->sel_type.standard_type.sensor_num,
|
|
(description != NULL) ? description : "Unknown");
|
|
|
|
if (description != NULL)
|
|
free(description);
|
|
}
|
|
|
|
void
|
|
ipmi_sel_print_extended_entry(struct ipmi_intf * intf, struct sel_event_record * evt)
|
|
{
|
|
sel_extended++;
|
|
ipmi_sel_print_std_entry(intf, evt);
|
|
sel_extended--;
|
|
}
|
|
|
|
void
|
|
ipmi_sel_print_std_entry(struct ipmi_intf * intf, struct sel_event_record * evt)
|
|
{
|
|
char * description;
|
|
struct sdr_record_list * sdr = NULL;
|
|
int data_count;
|
|
|
|
if (sel_extended && (evt->record_type < 0xc0))
|
|
sdr = ipmi_sdr_find_sdr_bynumtype(intf, evt->sel_type.standard_type.sensor_num, evt->sel_type.standard_type.sensor_type);
|
|
|
|
|
|
if (!evt)
|
|
return;
|
|
|
|
if (csv_output)
|
|
printf("%x,", evt->record_id);
|
|
else
|
|
printf("%4x | ", evt->record_id);
|
|
|
|
if (evt->record_type == 0xf0)
|
|
{
|
|
if (csv_output)
|
|
printf(",,");
|
|
|
|
printf ("Linux kernel panic: %.11s\n", (char *) evt + 5);
|
|
return;
|
|
}
|
|
|
|
if (evt->record_type < 0xe0)
|
|
{
|
|
if ((evt->sel_type.standard_type.timestamp < 0x20000000)||(evt->sel_type.oem_ts_type.timestamp < 0x20000000)){
|
|
printf("Pre-Init Time-stamp");
|
|
if (csv_output)
|
|
printf(",,");
|
|
else
|
|
printf(" | ");
|
|
}
|
|
else {
|
|
if (evt->record_type < 0xc0)
|
|
printf("%s", ipmi_sel_timestamp_date(evt->sel_type.standard_type.timestamp));
|
|
else
|
|
printf("%s", ipmi_sel_timestamp_date(evt->sel_type.oem_ts_type.timestamp));
|
|
if (csv_output)
|
|
printf(",");
|
|
else
|
|
printf(" | ");
|
|
|
|
if (evt->record_type < 0xc0)
|
|
printf("%s", ipmi_sel_timestamp_time(evt->sel_type.standard_type.timestamp));
|
|
else
|
|
printf("%s", ipmi_sel_timestamp_time(evt->sel_type.oem_ts_type.timestamp));
|
|
|
|
if (csv_output)
|
|
printf(",");
|
|
else
|
|
printf(" | ");
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
if (csv_output)
|
|
printf(",,");
|
|
}
|
|
|
|
if (evt->record_type >= 0xc0)
|
|
{
|
|
printf ("OEM record %02x", evt->record_type);
|
|
if (csv_output)
|
|
printf(",");
|
|
else
|
|
printf(" | ");
|
|
|
|
if(evt->record_type < 0xdf)
|
|
{
|
|
printf ("%02x%02x%02x", evt->sel_type.oem_ts_type.manf_id[0], evt->sel_type.oem_ts_type.manf_id[1], evt->sel_type.oem_ts_type.manf_id[2]);
|
|
if (csv_output)
|
|
printf(",");
|
|
else
|
|
printf(" | ");
|
|
for(data_count=0;data_count < SEL_OEM_TS_DATA_LEN;data_count++)
|
|
printf("%02x", evt->sel_type.oem_ts_type.oem_defined[data_count]);
|
|
}
|
|
else
|
|
{
|
|
for(data_count=0;data_count < SEL_OEM_NOTS_DATA_LEN;data_count++)
|
|
printf("%02x", evt->sel_type.oem_nots_type.oem_defined[data_count]);
|
|
}
|
|
ipmi_sel_oem_message(evt, 0);
|
|
printf ("\n");
|
|
return;
|
|
}
|
|
|
|
/* lookup SDR entry based on sensor number and type */
|
|
if (sdr != NULL) {
|
|
printf("%s ", ipmi_sel_get_sensor_type_offset(evt->sel_type.standard_type.sensor_type, evt->sel_type.standard_type.event_data[0]));
|
|
switch (sdr->type) {
|
|
case SDR_RECORD_TYPE_FULL_SENSOR:
|
|
printf("%s", sdr->record.full->id_string);
|
|
break;
|
|
case SDR_RECORD_TYPE_COMPACT_SENSOR:
|
|
printf("%s", sdr->record.compact->id_string);
|
|
break;
|
|
case SDR_RECORD_TYPE_EVENTONLY_SENSOR:
|
|
printf("%s", sdr->record.eventonly->id_string);
|
|
break;
|
|
case SDR_RECORD_TYPE_FRU_DEVICE_LOCATOR:
|
|
printf("%s", sdr->record.fruloc->id_string);
|
|
break;
|
|
case SDR_RECORD_TYPE_MC_DEVICE_LOCATOR:
|
|
printf("%s", sdr->record.mcloc->id_string);
|
|
break;
|
|
case SDR_RECORD_TYPE_GENERIC_DEVICE_LOCATOR:
|
|
printf("%s", sdr->record.genloc->id_string);
|
|
break;
|
|
default:
|
|
printf("#%02x", evt->sel_type.standard_type.sensor_num);
|
|
break;
|
|
}
|
|
} else {
|
|
printf("%s", ipmi_sel_get_sensor_type_offset(evt->sel_type.standard_type.sensor_type, evt->sel_type.standard_type.event_data[0]));
|
|
if (evt->sel_type.standard_type.sensor_num != 0)
|
|
printf(" #0x%02x", evt->sel_type.standard_type.sensor_num);
|
|
}
|
|
|
|
if (csv_output)
|
|
printf(",");
|
|
else
|
|
printf(" | ");
|
|
|
|
ipmi_get_event_desc(intf, evt, &description);
|
|
if (description) {
|
|
printf("%s", description);
|
|
free(description);
|
|
}
|
|
|
|
if (evt->sel_type.standard_type.event_type == 0x6f) {
|
|
if (csv_output)
|
|
printf(",");
|
|
else
|
|
printf(" | ");
|
|
|
|
if (evt->sel_type.standard_type.event_dir)
|
|
printf("Deasserted");
|
|
else
|
|
printf("Asserted");
|
|
}
|
|
|
|
if (sdr != NULL && evt->sel_type.standard_type.event_type == 1) {
|
|
/*
|
|
* Threshold Event
|
|
*/
|
|
float trigger_reading = 0.0;
|
|
float threshold_reading = 0.0;
|
|
|
|
/* trigger reading in event data byte 2 */
|
|
if (((evt->sel_type.standard_type.event_data[0] >> 6) & 3) == 1) {
|
|
trigger_reading = sdr_convert_sensor_reading(
|
|
sdr->record.full, evt->sel_type.standard_type.event_data[1]);
|
|
}
|
|
|
|
/* trigger threshold in event data byte 3 */
|
|
if (((evt->sel_type.standard_type.event_data[0] >> 4) & 3) == 1) {
|
|
threshold_reading = sdr_convert_sensor_reading(
|
|
sdr->record.full, evt->sel_type.standard_type.event_data[2]);
|
|
}
|
|
|
|
if (csv_output)
|
|
printf(",");
|
|
else
|
|
printf(" | ");
|
|
|
|
printf("Reading %.*f %s Threshold %.*f %s",
|
|
(trigger_reading==(int)trigger_reading) ? 0 : 2,
|
|
trigger_reading,
|
|
((evt->sel_type.standard_type.event_data[0] & 0xf) % 2) ? ">" : "<",
|
|
(threshold_reading==(int)threshold_reading) ? 0 : 2,
|
|
threshold_reading,
|
|
ipmi_sdr_get_unit_string(sdr->record.full->unit.modifier,
|
|
sdr->record.full->unit.type.base,
|
|
sdr->record.full->unit.type.modifier));
|
|
}
|
|
else if (evt->sel_type.standard_type.event_type == 0x6f) {
|
|
/*
|
|
* Sensor-Specific Discrete
|
|
*/
|
|
if (evt->sel_type.standard_type.sensor_type == 0xC &&
|
|
evt->sel_type.standard_type.sensor_num == 0 &&
|
|
(evt->sel_type.standard_type.event_data[0] & 0x30) == 0x20) {
|
|
/* break down memory ECC reporting if we can */
|
|
if (csv_output)
|
|
printf(",");
|
|
else
|
|
printf(" | ");
|
|
|
|
printf("CPU %d DIMM %d",
|
|
evt->sel_type.standard_type.event_data[2] & 0x0f,
|
|
(evt->sel_type.standard_type.event_data[2] & 0xf0) >> 4);
|
|
}
|
|
}
|
|
|
|
printf("\n");
|
|
}
|
|
|
|
void
|
|
ipmi_sel_print_std_entry_verbose(struct ipmi_intf * intf, struct sel_event_record * evt)
|
|
{
|
|
char * description;
|
|
int data_count;
|
|
|
|
if (!evt)
|
|
return;
|
|
|
|
printf("SEL Record ID : %04x\n", evt->record_id);
|
|
|
|
if (evt->record_type == 0xf0)
|
|
{
|
|
printf (" Record Type : Linux kernel panic (OEM record %02x)\n", evt->record_type);
|
|
printf (" Panic string : %.11s\n\n", (char *) evt + 5);
|
|
return;
|
|
}
|
|
|
|
printf(" Record Type : %02x", evt->record_type);
|
|
if (evt->record_type >= 0xc0)
|
|
{
|
|
if (evt->record_type < 0xe0)
|
|
printf(" (OEM timestamped)");
|
|
else
|
|
printf(" (OEM non-timestamped)");
|
|
}
|
|
printf("\n");
|
|
|
|
if (evt->record_type < 0xe0)
|
|
{
|
|
printf(" Timestamp : ");
|
|
if (evt->record_type < 0xc0)
|
|
printf("%s %s", ipmi_sel_timestamp_date(evt->sel_type.standard_type.timestamp),
|
|
ipmi_sel_timestamp_time(evt->sel_type.standard_type.timestamp));
|
|
else
|
|
printf("%s %s", ipmi_sel_timestamp_date(evt->sel_type.oem_ts_type.timestamp),
|
|
ipmi_sel_timestamp_time(evt->sel_type.oem_ts_type.timestamp));
|
|
printf("\n");
|
|
}
|
|
|
|
if (evt->record_type >= 0xc0)
|
|
{
|
|
if(evt->record_type < 0xdf)
|
|
{
|
|
printf (" Manufactacturer ID : %02x%02x%02x\n", evt->sel_type.oem_ts_type.manf_id[0],
|
|
evt->sel_type.oem_ts_type.manf_id[1], evt->sel_type.oem_ts_type.manf_id[2]);
|
|
printf (" OEM Defined : ");
|
|
for(data_count=0;data_count < SEL_OEM_TS_DATA_LEN;data_count++)
|
|
printf("%02x", evt->sel_type.oem_ts_type.oem_defined[data_count]);
|
|
printf(" [%s]\n\n",hex2ascii (evt->sel_type.oem_ts_type.oem_defined, SEL_OEM_TS_DATA_LEN));
|
|
}
|
|
else
|
|
{
|
|
printf (" OEM Defined : ");
|
|
for(data_count=0;data_count < SEL_OEM_NOTS_DATA_LEN;data_count++)
|
|
printf("%02x", evt->sel_type.oem_nots_type.oem_defined[data_count]);
|
|
printf(" [%s]\n\n",hex2ascii (evt->sel_type.oem_nots_type.oem_defined, SEL_OEM_NOTS_DATA_LEN));
|
|
ipmi_sel_oem_message(evt, 1);
|
|
}
|
|
return;
|
|
}
|
|
|
|
printf(" Generator ID : %04x\n",
|
|
evt->sel_type.standard_type.gen_id);
|
|
printf(" EvM Revision : %02x\n",
|
|
evt->sel_type.standard_type.evm_rev);
|
|
printf(" Sensor Type : %s\n",
|
|
ipmi_sel_get_sensor_type_offset(evt->sel_type.standard_type.sensor_type, evt->sel_type.standard_type.event_data[0]));
|
|
printf(" Sensor Number : %02x\n",
|
|
evt->sel_type.standard_type.sensor_num);
|
|
printf(" Event Type : %s\n",
|
|
ipmi_get_event_type(evt->sel_type.standard_type.event_type));
|
|
printf(" Event Direction : %s\n",
|
|
val2str(evt->sel_type.standard_type.event_dir, event_dir_vals));
|
|
printf(" Event Data : %02x%02x%02x\n",
|
|
evt->sel_type.standard_type.event_data[0], evt->sel_type.standard_type.event_data[1], evt->sel_type.standard_type.event_data[2]);
|
|
ipmi_get_event_desc(intf, evt, &description);
|
|
printf(" Description : %s\n",
|
|
description ? description : "");
|
|
free(description);
|
|
|
|
printf("\n");
|
|
}
|
|
|
|
|
|
void
|
|
ipmi_sel_print_extended_entry_verbose(struct ipmi_intf * intf, struct sel_event_record * evt)
|
|
{
|
|
struct sdr_record_list * sdr;
|
|
char * description;
|
|
int data_count;
|
|
|
|
if (!evt)
|
|
return;
|
|
|
|
sdr = ipmi_sdr_find_sdr_bynumtype(intf, evt->sel_type.standard_type.sensor_num, evt->sel_type.standard_type.sensor_type);
|
|
if (sdr == NULL) {
|
|
ipmi_sel_print_std_entry_verbose(intf, evt);
|
|
return;
|
|
}
|
|
|
|
printf("SEL Record ID : %04x\n", evt->record_id);
|
|
|
|
if (evt->record_type == 0xf0)
|
|
{
|
|
printf (" Record Type : "
|
|
"Linux kernel panic (OEM record %02x)\n",
|
|
evt->record_type);
|
|
printf (" Panic string : %.11s\n\n",
|
|
(char *) evt + 5);
|
|
return;
|
|
}
|
|
|
|
printf(" Record Type : %02x\n", evt->record_type);
|
|
if (evt->record_type < 0xe0)
|
|
{
|
|
printf(" Timestamp : ");
|
|
printf("%s %s\n", ipmi_sel_timestamp_date(evt->sel_type.standard_type.timestamp),
|
|
ipmi_sel_timestamp_time(evt->sel_type.standard_type.timestamp));
|
|
}
|
|
|
|
|
|
printf(" Generator ID : %04x\n",
|
|
evt->sel_type.standard_type.gen_id);
|
|
printf(" EvM Revision : %02x\n",
|
|
evt->sel_type.standard_type.evm_rev);
|
|
printf(" Sensor Type : %s\n",
|
|
ipmi_sel_get_sensor_type_offset(evt->sel_type.standard_type.sensor_type, evt->sel_type.standard_type.event_data[0]));
|
|
printf(" Sensor Number : %02x\n",
|
|
evt->sel_type.standard_type.sensor_num);
|
|
printf(" Event Type : %s\n",
|
|
ipmi_get_event_type(evt->sel_type.standard_type.event_type));
|
|
printf(" Event Direction : %s\n",
|
|
val2str(evt->sel_type.standard_type.event_dir, event_dir_vals));
|
|
printf(" Event Data (RAW) : %02x%02x%02x\n",
|
|
evt->sel_type.standard_type.event_data[0], evt->sel_type.standard_type.event_data[1], evt->sel_type.standard_type.event_data[2]);
|
|
|
|
/* break down event data field
|
|
* as per IPMI Spec 2.0 Table 29-6 */
|
|
if (evt->sel_type.standard_type.event_type == 1 && sdr->type == SDR_RECORD_TYPE_FULL_SENSOR) {
|
|
/* Threshold */
|
|
switch ((evt->sel_type.standard_type.event_data[0] >> 6) & 3) { /* EV1[7:6] */
|
|
case 0:
|
|
/* unspecified byte 2 */
|
|
break;
|
|
case 1:
|
|
/* trigger reading in byte 2 */
|
|
printf(" Trigger Reading : %.3f",
|
|
sdr_convert_sensor_reading(sdr->record.full,
|
|
evt->sel_type.standard_type.event_data[1]));
|
|
/* determine units with possible modifiers */
|
|
switch (sdr->record.full->unit.modifier) {
|
|
case 2:
|
|
printf(" %s * %s\n",
|
|
unit_desc[sdr->record.full->unit.type.base],
|
|
unit_desc[sdr->record.full->unit.type.modifier]);
|
|
break;
|
|
case 1:
|
|
printf(" %s/%s\n",
|
|
unit_desc[sdr->record.full->unit.type.base],
|
|
unit_desc[sdr->record.full->unit.type.modifier]);
|
|
break;
|
|
case 0:
|
|
printf(" %s\n",
|
|
unit_desc[sdr->record.full->unit.type.base]);
|
|
break;
|
|
default:
|
|
printf("\n");
|
|
break;
|
|
}
|
|
break;
|
|
case 2:
|
|
/* oem code in byte 2 */
|
|
printf(" OEM Data : %02x\n",
|
|
evt->sel_type.standard_type.event_data[1]);
|
|
break;
|
|
case 3:
|
|
/* sensor-specific extension code in byte 2 */
|
|
printf(" Sensor Extension Code : %02x\n",
|
|
evt->sel_type.standard_type.event_data[1]);
|
|
break;
|
|
}
|
|
switch ((evt->sel_type.standard_type.event_data[0] >> 4) & 3) { /* EV1[5:4] */
|
|
case 0:
|
|
/* unspecified byte 3 */
|
|
break;
|
|
case 1:
|
|
/* trigger threshold value in byte 3 */
|
|
printf(" Trigger Threshold : %.3f",
|
|
sdr_convert_sensor_reading(sdr->record.full,
|
|
evt->sel_type.standard_type.event_data[2]));
|
|
/* determine units with possible modifiers */
|
|
switch (sdr->record.full->unit.modifier) {
|
|
case 2:
|
|
printf(" %s * %s\n",
|
|
unit_desc[sdr->record.full->unit.type.base],
|
|
unit_desc[sdr->record.full->unit.type.modifier]);
|
|
break;
|
|
case 1:
|
|
printf(" %s/%s\n",
|
|
unit_desc[sdr->record.full->unit.type.base],
|
|
unit_desc[sdr->record.full->unit.type.modifier]);
|
|
break;
|
|
case 0:
|
|
printf(" %s\n",
|
|
unit_desc[sdr->record.full->unit.type.base]);
|
|
break;
|
|
default:
|
|
printf("\n");
|
|
break;
|
|
}
|
|
break;
|
|
case 2:
|
|
/* OEM code in byte 3 */
|
|
printf(" OEM Data : %02x\n",
|
|
evt->sel_type.standard_type.event_data[2]);
|
|
break;
|
|
case 3:
|
|
/* sensor-specific extension code in byte 3 */
|
|
printf(" Sensor Extension Code : %02x\n",
|
|
evt->sel_type.standard_type.event_data[2]);
|
|
break;
|
|
}
|
|
} else if (evt->sel_type.standard_type.event_type >= 0x2 && evt->sel_type.standard_type.event_type <= 0xc) {
|
|
/* Generic Discrete */
|
|
} else if (evt->sel_type.standard_type.event_type == 0x6f) {
|
|
/* Sensor-Specific Discrete */
|
|
if (evt->sel_type.standard_type.sensor_type == 0xC &&
|
|
evt->sel_type.standard_type.sensor_num == 0 &&
|
|
(evt->sel_type.standard_type.event_data[0] & 0x30) == 0x20)
|
|
{
|
|
/* break down memory ECC reporting if we can */
|
|
printf(" Event Data : CPU %d DIMM %d\n",
|
|
evt->sel_type.standard_type.event_data[2] & 0x0f,
|
|
(evt->sel_type.standard_type.event_data[2] & 0xf0) >> 4);
|
|
}
|
|
} else if (evt->sel_type.standard_type.event_type >= 0x70 && evt->sel_type.standard_type.event_type <= 0x7f) {
|
|
/* OEM */
|
|
} else {
|
|
printf(" Event Data : %02x%02x%02x\n",
|
|
evt->sel_type.standard_type.event_data[0], evt->sel_type.standard_type.event_data[1], evt->sel_type.standard_type.event_data[2]);
|
|
}
|
|
|
|
ipmi_get_event_desc(intf, evt, &description);
|
|
printf(" Description : %s\n",
|
|
description ? description : "");
|
|
free(description);
|
|
|
|
printf("\n");
|
|
}
|
|
|
|
static int
|
|
__ipmi_sel_savelist_entries(struct ipmi_intf * intf, int count, const char * savefile,
|
|
int binary)
|
|
{
|
|
struct ipmi_rs * rsp;
|
|
struct ipmi_rq req;
|
|
uint16_t next_id = 0, curr_id = 0;
|
|
struct sel_event_record evt;
|
|
int n=0;
|
|
FILE * fp = NULL;
|
|
|
|
memset(&req, 0, sizeof(req));
|
|
req.msg.netfn = IPMI_NETFN_STORAGE;
|
|
req.msg.cmd = IPMI_CMD_GET_SEL_INFO;
|
|
|
|
rsp = intf->sendrecv(intf, &req);
|
|
if (rsp == NULL) {
|
|
lprintf(LOG_ERR, "Get SEL Info command failed");
|
|
return -1;
|
|
}
|
|
if (rsp->ccode > 0) {
|
|
lprintf(LOG_ERR, "Get SEL Info command failed: %s",
|
|
val2str(rsp->ccode, completion_code_vals));
|
|
return -1;
|
|
}
|
|
if (verbose > 2)
|
|
printbuf(rsp->data, rsp->data_len, "sel_info");
|
|
|
|
if (rsp->data[1] == 0 && rsp->data[2] == 0) {
|
|
lprintf(LOG_ERR, "SEL has no entries");
|
|
return -1;
|
|
}
|
|
|
|
memset(&req, 0, sizeof(req));
|
|
req.msg.netfn = IPMI_NETFN_STORAGE;
|
|
req.msg.cmd = IPMI_CMD_RESERVE_SEL;
|
|
|
|
rsp = intf->sendrecv(intf, &req);
|
|
if (rsp == NULL) {
|
|
lprintf(LOG_ERR, "Reserve SEL command failed");
|
|
return -1;
|
|
}
|
|
if (rsp->ccode > 0) {
|
|
lprintf(LOG_ERR, "Reserve SEL command failed: %s",
|
|
val2str(rsp->ccode, completion_code_vals));
|
|
return -1;
|
|
}
|
|
|
|
if (count < 0) {
|
|
/** Show only the most recent 'count' records. */
|
|
int delta;
|
|
uint16_t entries;
|
|
|
|
req.msg.cmd = IPMI_CMD_GET_SEL_INFO;
|
|
rsp = intf->sendrecv(intf, &req);
|
|
if (rsp == NULL) {
|
|
lprintf(LOG_ERR, "Get SEL Info command failed");
|
|
return -1;
|
|
}
|
|
if (rsp->ccode > 0) {
|
|
lprintf(LOG_ERR, "Get SEL Info command failed: %s",
|
|
val2str(rsp->ccode, completion_code_vals));
|
|
return -1;
|
|
}
|
|
entries = buf2short(rsp->data + 1);
|
|
if (-count > entries)
|
|
count = -entries;
|
|
|
|
/* Get first record. */
|
|
next_id = ipmi_sel_get_std_entry(intf, 0, &evt);
|
|
|
|
delta = next_id - evt.record_id;
|
|
|
|
/* Get last record. */
|
|
next_id = ipmi_sel_get_std_entry(intf, 0xffff, &evt);
|
|
|
|
next_id = evt.record_id + count * delta + delta;
|
|
}
|
|
|
|
if (savefile != NULL) {
|
|
fp = ipmi_open_file_write(savefile);
|
|
}
|
|
|
|
while (next_id != 0xffff) {
|
|
curr_id = next_id;
|
|
lprintf(LOG_DEBUG, "SEL Next ID: %04x", curr_id);
|
|
|
|
next_id = ipmi_sel_get_std_entry(intf, curr_id, &evt);
|
|
if (next_id == 0) {
|
|
/*
|
|
* usually next_id of zero means end but
|
|
* retry because some hardware has quirks
|
|
* and will return 0 randomly.
|
|
*/
|
|
next_id = ipmi_sel_get_std_entry(intf, curr_id, &evt);
|
|
if (next_id == 0)
|
|
break;
|
|
}
|
|
|
|
if (verbose)
|
|
ipmi_sel_print_std_entry_verbose(intf, &evt);
|
|
else
|
|
ipmi_sel_print_std_entry(intf, &evt);
|
|
|
|
if (fp != NULL) {
|
|
if (binary)
|
|
fwrite(&evt, 1, 16, fp);
|
|
else
|
|
ipmi_sel_print_event_file(intf, &evt, fp);
|
|
}
|
|
|
|
if (++n == count) {
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (fp != NULL)
|
|
fclose(fp);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int
|
|
ipmi_sel_list_entries(struct ipmi_intf * intf, int count)
|
|
{
|
|
return __ipmi_sel_savelist_entries(intf, count, NULL, 0);
|
|
}
|
|
|
|
static int
|
|
ipmi_sel_save_entries(struct ipmi_intf * intf, int count, const char * savefile)
|
|
{
|
|
return __ipmi_sel_savelist_entries(intf, count, savefile, 0);
|
|
}
|
|
|
|
|
|
static int
|
|
ipmi_sel_writeraw(struct ipmi_intf * intf, const char * savefile)
|
|
{
|
|
return __ipmi_sel_savelist_entries(intf, 0, savefile, 1);
|
|
}
|
|
|
|
|
|
static int
|
|
ipmi_sel_readraw(struct ipmi_intf * intf, const char * inputfile)
|
|
{
|
|
struct sel_event_record evt;
|
|
int ret = 0;
|
|
FILE* fp = 0;
|
|
|
|
fp = ipmi_open_file(inputfile, 0);
|
|
if (fp)
|
|
{
|
|
size_t bytesRead;
|
|
|
|
do {
|
|
if ((bytesRead = fread(&evt, 1, 16, fp)) == 16)
|
|
{
|
|
if (verbose)
|
|
ipmi_sel_print_std_entry_verbose(intf, &evt);
|
|
else
|
|
ipmi_sel_print_std_entry(intf, &evt);
|
|
}
|
|
else
|
|
{
|
|
if (bytesRead != 0)
|
|
{
|
|
lprintf(LOG_ERR, "ipmitool: incomplete record found in file.");
|
|
ret = -1;
|
|
}
|
|
|
|
break;
|
|
}
|
|
|
|
} while (1);
|
|
fclose(fp);
|
|
}
|
|
else
|
|
{
|
|
lprintf(LOG_ERR, "ipmitool: could not open input file.");
|
|
ret = -1;
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
|
|
|
|
static uint16_t
|
|
ipmi_sel_reserve(struct ipmi_intf * intf)
|
|
{
|
|
struct ipmi_rs * rsp;
|
|
struct ipmi_rq req;
|
|
|
|
memset(&req, 0, sizeof(req));
|
|
req.msg.netfn = IPMI_NETFN_STORAGE;
|
|
req.msg.cmd = IPMI_CMD_RESERVE_SEL;
|
|
|
|
rsp = intf->sendrecv(intf, &req);
|
|
if (rsp == NULL) {
|
|
lprintf(LOG_WARN, "Unable to reserve SEL");
|
|
return 0;
|
|
}
|
|
if (rsp->ccode > 0) {
|
|
printf("Unable to reserve SEL: %s",
|
|
val2str(rsp->ccode, completion_code_vals));
|
|
return 0;
|
|
}
|
|
|
|
return (rsp->data[0] | (rsp->data[1] << 8));
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
* ipmi_sel_get_time
|
|
*
|
|
* return 0 on success,
|
|
* -1 on error
|
|
*/
|
|
static int
|
|
ipmi_sel_get_time(struct ipmi_intf * intf)
|
|
{
|
|
struct ipmi_rs * rsp;
|
|
struct ipmi_rq req;
|
|
static char tbuf[40];
|
|
uint32_t timei;
|
|
time_t time;
|
|
|
|
memset(&req, 0, sizeof(req));
|
|
req.msg.netfn = IPMI_NETFN_STORAGE;
|
|
req.msg.cmd = IPMI_GET_SEL_TIME;
|
|
|
|
rsp = intf->sendrecv(intf, &req);
|
|
|
|
if (rsp == NULL) {
|
|
lprintf(LOG_ERR, "Get SEL Time command failed");
|
|
return -1;
|
|
}
|
|
if (rsp->ccode > 0) {
|
|
lprintf(LOG_ERR, "Get SEL Time command failed: %s",
|
|
val2str(rsp->ccode, completion_code_vals));
|
|
return -1;
|
|
}
|
|
if (rsp->data_len != 4) {
|
|
lprintf(LOG_ERR, "Get SEL Time command failed: "
|
|
"Invalid data length %d", rsp->data_len);
|
|
return -1;
|
|
}
|
|
|
|
memcpy(&timei, rsp->data, 4);
|
|
#if WORDS_BIGENDIAN
|
|
timei = BSWAP_32(time);
|
|
#endif
|
|
time = (time_t)timei;
|
|
|
|
strftime(tbuf, sizeof(tbuf), "%m/%d/%Y %H:%M:%S", localtime(&time));
|
|
printf("%s\n", tbuf);
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
* ipmi_sel_set_time
|
|
*
|
|
* return 0 on success,
|
|
* -1 on error
|
|
*/
|
|
static int
|
|
ipmi_sel_set_time(struct ipmi_intf * intf, const char * time_string)
|
|
{
|
|
struct ipmi_rs * rsp;
|
|
struct ipmi_rq req;
|
|
struct tm tm;
|
|
time_t t;
|
|
uint32_t timei;
|
|
const char * time_format = "%m/%d/%Y %H:%M:%S";
|
|
|
|
memset(&req, 0, sizeof(req));
|
|
req.msg.netfn = IPMI_NETFN_STORAGE;
|
|
req.msg.cmd = IPMI_SET_SEL_TIME;
|
|
|
|
/* See if user requested set to current client system time */
|
|
if (strncasecmp(time_string, "now", 3) == 0) {
|
|
t = time(NULL);
|
|
}
|
|
else {
|
|
/* Now how do we get our time_t from our ascii version? */
|
|
if (strptime(time_string, time_format, &tm) == 0) {
|
|
lprintf(LOG_ERR, "Specified time could not be parsed");
|
|
return -1;
|
|
}
|
|
t = mktime(&tm);
|
|
if (t < 0) {
|
|
lprintf(LOG_ERR, "Specified time could not be parsed");
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
timei = (uint32_t)t;
|
|
req.msg.data = (uint8_t *)&timei;
|
|
req.msg.data_len = 4;
|
|
|
|
#if WORDS_BIGENDIAN
|
|
timei = BSWAP_32(timei);
|
|
#endif
|
|
|
|
rsp = intf->sendrecv(intf, &req);
|
|
if (rsp == NULL) {
|
|
lprintf(LOG_ERR, "Set SEL Time command failed");
|
|
return -1;
|
|
}
|
|
if (rsp->ccode > 0) {
|
|
lprintf(LOG_ERR, "Set SEL Time command failed: %s",
|
|
val2str(rsp->ccode, completion_code_vals));
|
|
return -1;
|
|
}
|
|
|
|
ipmi_sel_get_time(intf);
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
ipmi_sel_clear(struct ipmi_intf * intf)
|
|
{
|
|
struct ipmi_rs * rsp;
|
|
struct ipmi_rq req;
|
|
uint16_t reserve_id;
|
|
uint8_t msg_data[6];
|
|
|
|
reserve_id = ipmi_sel_reserve(intf);
|
|
if (reserve_id == 0)
|
|
return -1;
|
|
|
|
memset(msg_data, 0, 6);
|
|
msg_data[0] = reserve_id & 0xff;
|
|
msg_data[1] = reserve_id >> 8;
|
|
msg_data[2] = 'C';
|
|
msg_data[3] = 'L';
|
|
msg_data[4] = 'R';
|
|
msg_data[5] = 0xaa;
|
|
|
|
memset(&req, 0, sizeof(req));
|
|
req.msg.netfn = IPMI_NETFN_STORAGE;
|
|
req.msg.cmd = IPMI_CMD_CLEAR_SEL;
|
|
req.msg.data = msg_data;
|
|
req.msg.data_len = 6;
|
|
|
|
rsp = intf->sendrecv(intf, &req);
|
|
if (rsp == NULL) {
|
|
lprintf(LOG_ERR, "Unable to clear SEL");
|
|
return -1;
|
|
}
|
|
if (rsp->ccode > 0) {
|
|
lprintf(LOG_ERR, "Unable to clear SEL: %s",
|
|
val2str(rsp->ccode, completion_code_vals));
|
|
return -1;
|
|
}
|
|
|
|
printf("Clearing SEL. Please allow a few seconds to erase.\n");
|
|
return 0;
|
|
}
|
|
|
|
static int
|
|
ipmi_sel_delete(struct ipmi_intf * intf, int argc, char ** argv)
|
|
{
|
|
struct ipmi_rs * rsp;
|
|
struct ipmi_rq req;
|
|
uint16_t id;
|
|
uint8_t msg_data[4];
|
|
int rc = 0;
|
|
|
|
if (argc == 0 || strncmp(argv[0], "help", 4) == 0) {
|
|
lprintf(LOG_ERR, "usage: delete <id>...<id>\n");
|
|
return -1;
|
|
}
|
|
|
|
id = ipmi_sel_reserve(intf);
|
|
if (id == 0)
|
|
return -1;
|
|
|
|
memset(msg_data, 0, 4);
|
|
msg_data[0] = id & 0xff;
|
|
msg_data[1] = id >> 8;
|
|
|
|
for (argc; argc != 0; argc--)
|
|
{
|
|
id = atoi(argv[argc-1]);
|
|
msg_data[2] = id & 0xff;
|
|
msg_data[3] = id >> 8;
|
|
|
|
memset(&req, 0, sizeof(req));
|
|
req.msg.netfn = IPMI_NETFN_STORAGE;
|
|
req.msg.cmd = IPMI_CMD_DELETE_SEL_ENTRY;
|
|
req.msg.data = msg_data;
|
|
req.msg.data_len = 4;
|
|
|
|
rsp = intf->sendrecv(intf, &req);
|
|
if (rsp == NULL) {
|
|
lprintf(LOG_ERR, "Unable to delete entry %d", id);
|
|
rc = -1;
|
|
}
|
|
else if (rsp->ccode > 0) {
|
|
lprintf(LOG_ERR, "Unable to delete entry %d: %s", id,
|
|
val2str(rsp->ccode, completion_code_vals));
|
|
rc = -1;
|
|
}
|
|
else {
|
|
printf("Deleted entry %d\n", id);
|
|
}
|
|
}
|
|
|
|
return rc;
|
|
}
|
|
|
|
static int
|
|
ipmi_sel_show_entry(struct ipmi_intf * intf, int argc, char ** argv)
|
|
{
|
|
uint16_t id;
|
|
int i, oldv;
|
|
struct sel_event_record evt;
|
|
struct sdr_record_list * sdr;
|
|
struct entity_id entity;
|
|
struct sdr_record_list * list, * entry;
|
|
int rc = 0;
|
|
|
|
if (argc == 0 || strncmp(argv[0], "help", 4) == 0) {
|
|
lprintf(LOG_ERR, "usage: sel get <id>...<id>");
|
|
return -1;
|
|
}
|
|
|
|
if (ipmi_sel_reserve(intf) == 0) {
|
|
lprintf(LOG_ERR, "Unable to reserve SEL");
|
|
return -1;
|
|
}
|
|
|
|
for (i=0; i<argc; i++) {
|
|
id = (uint16_t)strtol(argv[i], NULL, 0);
|
|
|
|
lprintf(LOG_DEBUG, "Looking up SEL entry 0x%x", id);
|
|
|
|
/* lookup SEL entry based on ID */
|
|
ipmi_sel_get_std_entry(intf, id, &evt);
|
|
if (evt.sel_type.standard_type.sensor_num == 0 && evt.sel_type.standard_type.sensor_type == 0 && evt.record_type == 0) {
|
|
lprintf(LOG_WARN, "SEL Entry 0x%x not found", id);
|
|
rc = -1;
|
|
continue;
|
|
}
|
|
|
|
/* lookup SDR entry based on sensor number and type */
|
|
ipmi_sel_print_extended_entry_verbose(intf, &evt);
|
|
|
|
sdr = ipmi_sdr_find_sdr_bynumtype(intf, evt.sel_type.standard_type.sensor_num, evt.sel_type.standard_type.sensor_type);
|
|
if (sdr == NULL) {
|
|
continue;
|
|
}
|
|
|
|
/* print SDR entry */
|
|
oldv = verbose;
|
|
verbose = verbose ? : 1;
|
|
switch (sdr->type) {
|
|
case SDR_RECORD_TYPE_FULL_SENSOR:
|
|
ipmi_sensor_print_full(intf, sdr->record.full);
|
|
entity.id = sdr->record.full->entity.id;
|
|
entity.instance = sdr->record.full->entity.instance;
|
|
break;
|
|
case SDR_RECORD_TYPE_COMPACT_SENSOR:
|
|
ipmi_sensor_print_compact(intf, sdr->record.compact);
|
|
entity.id = sdr->record.compact->entity.id;
|
|
entity.instance = sdr->record.compact->entity.instance;
|
|
break;
|
|
case SDR_RECORD_TYPE_EVENTONLY_SENSOR:
|
|
ipmi_sdr_print_sensor_eventonly(intf, sdr->record.eventonly);
|
|
entity.id = sdr->record.eventonly->entity.id;
|
|
entity.instance = sdr->record.eventonly->entity.instance;
|
|
break;
|
|
default:
|
|
verbose = oldv;
|
|
continue;
|
|
}
|
|
verbose = oldv;
|
|
|
|
/* lookup SDR entry based on entity id */
|
|
list = ipmi_sdr_find_sdr_byentity(intf, &entity);
|
|
for (entry=list; entry; entry=entry->next) {
|
|
/* print FRU devices we find for this entity */
|
|
if (entry->type == SDR_RECORD_TYPE_FRU_DEVICE_LOCATOR)
|
|
ipmi_fru_print(intf, entry->record.fruloc);
|
|
}
|
|
|
|
if ((argc > 1) && (i<(argc-1)))
|
|
printf("----------------------\n\n");
|
|
}
|
|
|
|
return rc;
|
|
}
|
|
|
|
static int make_int(const char *str, int *value)
|
|
{
|
|
char *tmp=NULL;
|
|
*value = strtol(str,&tmp,0);
|
|
if ( tmp-str != strlen(str) )
|
|
{
|
|
return -1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int ipmi_sel_main(struct ipmi_intf * intf, int argc, char ** argv)
|
|
{
|
|
int rc = 0;
|
|
|
|
if (argc == 0)
|
|
rc = ipmi_sel_get_info(intf);
|
|
else if (strncmp(argv[0], "help", 4) == 0)
|
|
lprintf(LOG_ERR, "SEL Commands: "
|
|
"info clear delete list elist get add time save readraw writeraw");
|
|
else if (strncmp(argv[0], "info", 4) == 0)
|
|
rc = ipmi_sel_get_info(intf);
|
|
else if (strncmp(argv[0], "save", 4) == 0) {
|
|
if (argc < 2) {
|
|
lprintf(LOG_NOTICE, "usage: sel save <filename>");
|
|
return 0;
|
|
}
|
|
rc = ipmi_sel_save_entries(intf, 0, argv[1]);
|
|
}
|
|
else if (strncmp(argv[0], "add", 3) == 0) {
|
|
if (argc < 2) {
|
|
lprintf(LOG_NOTICE, "usage: sel add <filename>");
|
|
return 0;
|
|
}
|
|
rc = ipmi_sel_add_entries_fromfile(intf, argv[1]);
|
|
}
|
|
else if (strncmp(argv[0], "writeraw", 8) == 0) {
|
|
if (argc < 2) {
|
|
lprintf(LOG_NOTICE, "usage: sel writeraw <filename>");
|
|
return 0;
|
|
}
|
|
rc = ipmi_sel_writeraw(intf, argv[1]);
|
|
}
|
|
else if (strncmp(argv[0], "readraw", 7) == 0) {
|
|
if (argc < 2) {
|
|
lprintf(LOG_NOTICE, "usage: sel readraw <filename>");
|
|
return 0;
|
|
}
|
|
rc = ipmi_sel_readraw(intf, argv[1]);
|
|
}
|
|
else if (strncmp(argv[0], "ereadraw", 8) == 0) {
|
|
if (argc < 2) {
|
|
lprintf(LOG_NOTICE, "usage: sel ereadraw <filename>");
|
|
return 0;
|
|
}
|
|
sel_extended = 1;
|
|
rc = ipmi_sel_readraw(intf, argv[1]);
|
|
}
|
|
else if (strncmp(argv[0], "list", 4) == 0 ||
|
|
strncmp(argv[0], "elist", 5) == 0) {
|
|
/*
|
|
* Usage:
|
|
* list - show all SEL entries
|
|
* list first <n> - show the first (oldest) <n> SEL entries
|
|
* list last <n> - show the last (newsest) <n> SEL entries
|
|
*/
|
|
int count = 0;
|
|
int sign = 1;
|
|
char *countstr = NULL;
|
|
|
|
if (strncmp(argv[0], "elist", 5) == 0)
|
|
sel_extended = 1;
|
|
else
|
|
sel_extended = 0;
|
|
|
|
if (argc == 2) {
|
|
countstr = argv[1];
|
|
}
|
|
else if (argc == 3) {
|
|
countstr = argv[2];
|
|
|
|
if (strncmp(argv[1], "last", 4) == 0) {
|
|
sign = -1;
|
|
}
|
|
else if (strncmp(argv[1], "first", 6) != 0) {
|
|
lprintf(LOG_ERR, "Unknown sel list option");
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
if (countstr) {
|
|
if (make_int(countstr,&count) < 0) {
|
|
lprintf(LOG_ERR, "Numeric argument required; got '%s'",
|
|
countstr);
|
|
return -1;
|
|
}
|
|
}
|
|
count *= sign;
|
|
|
|
rc = ipmi_sel_list_entries(intf,count);
|
|
}
|
|
else if (strncmp(argv[0], "clear", 5) == 0)
|
|
rc = ipmi_sel_clear(intf);
|
|
else if (strncmp(argv[0], "delete", 6) == 0) {
|
|
if (argc < 2)
|
|
lprintf(LOG_ERR, "usage: sel delete <id>...<id>");
|
|
else
|
|
rc = ipmi_sel_delete(intf, argc-1, &argv[1]);
|
|
}
|
|
else if (strncmp(argv[0], "get", 3) == 0) {
|
|
if (argc < 2)
|
|
lprintf(LOG_ERR, "usage: sel get <entry>");
|
|
else
|
|
rc = ipmi_sel_show_entry(intf, argc-1, &argv[1]);
|
|
}
|
|
else if (strncmp(argv[0], "time", 4) == 0) {
|
|
if (argc < 2)
|
|
lprintf(LOG_ERR, "sel time commands: get set");
|
|
else if (strncmp(argv[1], "get", 3) == 0)
|
|
ipmi_sel_get_time(intf);
|
|
else if (strncmp(argv[1], "set", 3) == 0) {
|
|
if (argc < 3)
|
|
lprintf(LOG_ERR, "usage: sel time set \"mm/dd/yyyy hh:mm:ss\"");
|
|
else
|
|
rc = ipmi_sel_set_time(intf, argv[2]);
|
|
} else {
|
|
lprintf(LOG_ERR, "sel time commands: get set");
|
|
}
|
|
}
|
|
else {
|
|
lprintf(LOG_ERR, "Invalid SEL command: %s", argv[0]);
|
|
rc = -1;
|
|
}
|
|
|
|
return rc;
|
|
}
|
|
|