From 2ab696dc17d6a998ba0ec61b6728f1f122ced0d1 Mon Sep 17 00:00:00 2001 From: Duncan Laurie Date: Thu, 15 Apr 2004 19:57:05 +0000 Subject: [PATCH] add ipmi_event file for event generation --- ipmitool/include/ipmitool/Makefile.am | 2 +- ipmitool/include/ipmitool/ipmi_event.h | 47 +++++++++ ipmitool/lib/Makefile.am | 2 +- ipmitool/lib/ipmi_event.c | 140 +++++++++++++++++++++++++ 4 files changed, 189 insertions(+), 2 deletions(-) create mode 100644 ipmitool/include/ipmitool/ipmi_event.h create mode 100644 ipmitool/lib/ipmi_event.c diff --git a/ipmitool/include/ipmitool/Makefile.am b/ipmitool/include/ipmitool/Makefile.am index 228a44c..7732e0b 100644 --- a/ipmitool/include/ipmitool/Makefile.am +++ b/ipmitool/include/ipmitool/Makefile.am @@ -39,5 +39,5 @@ ipmitooldir = $(includedir)/ipmitool noinst_HEADERS = bswap.h helper.h ipmi.h ipmi_intf.h \ ipmi_chassis.h ipmi_entity.h ipmi_fru.h ipmi_lanp.h \ ipmi_sdr.h ipmi_sel.h ipmi_sol.h ipmi_bmc.h \ - ipmi_channel.h ipmi_sensor.h + ipmi_channel.h ipmi_sensor.h ipmi_event.h diff --git a/ipmitool/include/ipmitool/ipmi_event.h b/ipmitool/include/ipmitool/ipmi_event.h new file mode 100644 index 0000000..b50eb6d --- /dev/null +++ b/ipmitool/include/ipmitool/ipmi_event.h @@ -0,0 +1,47 @@ +/* + * 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_EVENT_H +#define IPMI_EVENT_H + +#if HAVE_CONFIG_H +# include +#endif +#include + +int ipmi_event_main(struct ipmi_intf *, int, char **); + +#endif /*IPMI_EVENT_H*/ diff --git a/ipmitool/lib/Makefile.am b/ipmitool/lib/Makefile.am index 8ff6c1e..ec99631 100644 --- a/ipmitool/lib/Makefile.am +++ b/ipmitool/lib/Makefile.am @@ -38,7 +38,7 @@ MAINTAINERCLEANFILES = Makefile.in noinst_LTLIBRARIES = libipmitool.la libipmitool_la_SOURCES = helper.c ipmi_sdr.c ipmi_sel.c ipmi_sol.c ipmi_lanp.c \ ipmi_fru.c ipmi_chassis.c ipmi_bmc.c dimm_spd.c ipmi_sensor.c \ - ipmi_channel.c + ipmi_channel.c ipmi_event.c libipmitool_la_LDFLAGS = -export-dynamic libipmitool_la_LIBADD = -lm libipmitool_la_DEPENDENCIES = diff --git a/ipmitool/lib/ipmi_event.c b/ipmitool/lib/ipmi_event.c new file mode 100644 index 0000000..e48c365 --- /dev/null +++ b/ipmitool/lib/ipmi_event.c @@ -0,0 +1,140 @@ +/* + * 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 +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +static int +ipmi_send_platform_event(struct ipmi_intf * intf, int num) +{ + struct ipmi_rs * rsp; + struct ipmi_rq req; + unsigned char rqdata[8]; + + memset(&req, 0, sizeof(req)); + memset(rqdata, 0, 8); + + printf("Sending "); + + /* IPMB/LAN/etc */ + switch (num) { + case 0: /* temperature */ + printf("Temperature"); + rqdata[0] = 0x04; /* EvMRev */ + rqdata[1] = 0x01; /* Sensor Type */ + rqdata[2] = 0x30; /* Sensor # */ + rqdata[3] = 0x04; /* Event Dir / Event Type */ + rqdata[4] = 0x00; /* Event Data 1 */ + rqdata[5] = 0x00; /* Event Data 2 */ + rqdata[6] = 0x00; /* Event Data 3 */ + break; + case 1: /* correctable ECC */ + printf("Memory Correctable ECC"); + rqdata[0] = 0x04; /* EvMRev */ + rqdata[1] = 0x0c; /* Sensor Type */ + rqdata[2] = 0x01; /* Sensor # */ + rqdata[3] = 0x6f; /* Event Dir / Event Type */ + rqdata[4] = 0x00; /* Event Data 1 */ + rqdata[5] = 0x00; /* Event Data 2 */ + rqdata[6] = 0x00; /* Event Data 3 */ + break; + case 2: /* uncorrectable ECC */ + printf("Memory Uncorrectable ECC"); + rqdata[0] = 0x04; /* EvMRev */ + rqdata[1] = 0x0c; /* Sensor Type */ + rqdata[2] = 0x01; /* Sensor # */ + rqdata[3] = 0x6f; /* Event Dir / Event Type */ + rqdata[4] = 0x01; /* Event Data 1 */ + rqdata[5] = 0x00; /* Event Data 2 */ + rqdata[6] = 0x00; /* Event Data 3 */ + break; + case 3: /* parity error */ + printf("Memory Parity Error"); + rqdata[0] = 0x04; /* EvMRev */ + rqdata[1] = 0x0c; /* Sensor Type */ + rqdata[2] = 0x01; /* Sensor # */ + rqdata[3] = 0x6f; /* Event Dir / Event Type */ + rqdata[4] = 0x02; /* Event Data 1 */ + rqdata[5] = 0x00; /* Event Data 2 */ + rqdata[6] = 0x00; /* Event Data 3 */ + break; + default: + printf("Invalid event number: %d\n", num); + return -1; + } + + printf(" event to BMC\n"); + + req.msg.netfn = IPMI_NETFN_SE; + req.msg.cmd = 0x02; + req.msg.data = rqdata; + req.msg.data_len = 7; + + rsp = intf->sendrecv(intf, &req); + if (!rsp || rsp->ccode) { + printf("Error:%x Platform Event Message Command\n", rsp?rsp->ccode:0); + return -1; + } + + return 0; +} + +int ipmi_event_main(struct ipmi_intf * intf, int argc, char ** argv) +{ + unsigned char c; + + if (!argc || !strncmp(argv[0], "help", 4)) + printf("usage: event \n"); + else { + c = (unsigned char)strtol(argv[optind+1], NULL, 0); + ipmi_send_platform_event(intf, c); + } + + return 0; +}