From a56df3a244e89f4234d11751854150fc7090f891 Mon Sep 17 00:00:00 2001 From: Jon Cassorla Date: Fri, 23 Jan 2004 05:11:32 +0000 Subject: [PATCH] begin work on sensor command --- ipmitool/include/ipmitool/ipmi_sensor.h | 51 ++++++++ ipmitool/lib/ipmi_sensor.c | 155 ++++++++++++++++++++++++ 2 files changed, 206 insertions(+) create mode 100644 ipmitool/include/ipmitool/ipmi_sensor.h create mode 100644 ipmitool/lib/ipmi_sensor.c diff --git a/ipmitool/include/ipmitool/ipmi_sensor.h b/ipmitool/include/ipmitool/ipmi_sensor.h new file mode 100644 index 0000000..fc43357 --- /dev/null +++ b/ipmitool/include/ipmitool/ipmi_sensor.h @@ -0,0 +1,51 @@ +/* + * 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. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + */ + +#ifndef IPMI_SENSOR_H +#define IPMI_SENSOR_H + +#include +#include +#include + +#define GET_SENSOR_READING 0x2d +#define GET_SENSOR_FACTORS 0x23 +#define GET_SENSOR_THRES 0x27 +#define GET_SENSOR_TYPE 0x2f + +int ipmi_sensor_main(struct ipmi_intf *, int, char **); + +#endif /* IPMI_SENSOR_H */ diff --git a/ipmitool/lib/ipmi_sensor.c b/ipmitool/lib/ipmi_sensor.c new file mode 100644 index 0000000..2fc40b3 --- /dev/null +++ b/ipmitool/lib/ipmi_sensor.c @@ -0,0 +1,155 @@ +/* + * 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. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + */ + +#include +#include + +#include +#include +#include + +extern int verbose; + +#define READING_UNAVAILABLE 0x20 +#define SCANNING_DISABLED 0x80 + +static void +ipmi_get_sensor_info_compact(struct ipmi_intf * intf, + struct sdr_record_compact_sensor * sensor) +{ +} + +static void +ipmi_get_sensor_info_full(struct ipmi_intf * intf, + struct sdr_record_full_sensor * sensor) +{ + struct ipmi_rs * rsp; + char sval[16], unitstr[16], desc[17]; + float val, tol; + unsigned raw_tol; + int i=0, not_available=0; + + memset(desc, 0, sizeof(desc)); + memcpy(desc, sensor->id_string, 16); + + rsp = ipmi_sdr_get_sensor_reading(intf, sensor->keys.sensor_num); + if ((rsp && (rsp->data[1] & READING_UNAVAILABLE)) || + (rsp && !(rsp->data[1] & SCANNING_DISABLED))) + not_available = 1; + else { + memset(unitstr, 0, sizeof(unitstr)); + /* determine units with possible modifiers */ + switch (sensor->unit.modifier) { + case 2: + i += snprintf(unitstr, sizeof(unitstr), "%s * %s", + unit_desc[sensor->unit.type.base], + unit_desc[sensor->unit.type.modifier]); + break; + case 1: + i += snprintf(unitstr, sizeof(unitstr), "%s/%s", + unit_desc[sensor->unit.type.base], + unit_desc[sensor->unit.type.modifier]); + break; + case 0: + default: + i += snprintf(unitstr, sizeof(unitstr), "%s", + unit_desc[sensor->unit.type.base]); + break; + } + + val = sdr_convert_sensor_reading(sensor, rsp->data[0]); + raw_tol = (sensor->mtol & 0x3f00) >> 8; + tol = sdr_convert_sensor_reading(sensor, raw_tol * 2); + } + + if (!verbose) { + /* + * print sensor name, reading, state + */ + printf("%-16s | ", sensor->id_code ? desc : NULL); + + i = 0; + memset(sval, 0, sizeof(sval)); + if (not_available) { + i += snprintf(sval, sizeof(sval), "no reading "); + } else { + i += snprintf(sval, sizeof(sval), "%.*f %s", (val==(int)val) ? 0 : 3, val, unitstr); + } + printf("%s", sval); + + i--; + for (; idata[2])); + printf("\n"); + } else { + printf("Sensor ID : %s (0x%x)\n", desc, sensor->keys.sensor_num); + if (not_available) + printf("Sensor Reading : Unavailable"); + else + printf("Sensor Reading : %.*f (+/- %.*f) %s\n", + (val==(int)val) ? 0 : 3, + val, + (tol==(int)tol) ? 0 : 3, + tol, + unitstr); + printf("\n"); + } +} + +static void +ipmi_sensor_list(struct ipmi_intf * intf) +{ + ipmi_sdr_print_sdr(intf, 0xff); +} + +int +ipmi_sensor_main(struct ipmi_intf * intf, int argc, char ** argv) +{ + if (!argc) + ipmi_sensor_list(intf); + else if (!strncmp(argv[0], "help", 4)) { + printf("Sensor Commands: list\n"); + } + else if (!strncmp(argv[0], "list", 4)) { + ipmi_sensor_list(intf); + } + else + printf("Invalid sensor command: %s\n", argv[0]); + return 0; +}