diff --git a/ipmitool/src/plugins/bmc/Makefile.am b/ipmitool/src/plugins/bmc/Makefile.am new file mode 100644 index 0000000..4336246 --- /dev/null +++ b/ipmitool/src/plugins/bmc/Makefile.am @@ -0,0 +1,45 @@ +# Copyright (c) 2004 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. + +MAINTAINERCLEANFILES = Makefile.in + +INCLUDES = -I$(top_srcdir)/include + +EXTRA_LTLIBRARIES = libintf_bmc.la +noinst_LTLIBRARIES = @INTF_BMC_LIB@ +libintf_bmc_la_LIBADD = $(top_builddir)/lib/libipmitool.la +libintf_bmc_la_SOURCES = \ + bmc.c bmc.h \ + bmc_intf.h + diff --git a/ipmitool/src/plugins/bmc/bmc.c b/ipmitool/src/plugins/bmc/bmc.c new file mode 100644 index 0000000..a997505 --- /dev/null +++ b/ipmitool/src/plugins/bmc/bmc.c @@ -0,0 +1,139 @@ +/* + * Copyright (c) 2004 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. + */ + + +/* + * interface routines between ipmitool and the bmc kernel driver + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include "bmc_intf.h" + +#include "bmc.h" + +static int curr_seq; +extern int verbose; + +struct ipmi_intf ipmi_bmc_intf = { + name: "bmc", + desc: "IPMI v2.0 BMC interface", + open: ipmi_bmc_open, + close: ipmi_bmc_close, + sendrecv: ipmi_bmc_send_cmd}; + +void +ipmi_bmc_close(struct ipmi_intf *intf) +{ + if (intf && intf->fd >= 0) + close(intf->fd); + + intf->opened = 0; + intf->fd = -1; +} + +int +ipmi_bmc_open(struct ipmi_intf *intf) +{ + if (!intf) + return -1; + + /* Open local device */ + intf->fd = open(BMC_DEV, O_RDWR); + + if (intf->fd <= 0) { + perror("Could not open bmc device"); + return (-1); + } + curr_seq = 0; + + intf->opened = 1; + return (intf->fd); +} + +struct ipmi_rs * +ipmi_bmc_send_cmd(struct ipmi_intf *intf, struct ipmi_rq *req) +{ + struct strioctl istr; + static struct bmc_reqrsp reqrsp; + static struct ipmi_rs rsp; + + /* If not already opened open the device or network connection */ + if (!intf->opened && intf->open && intf->open(intf) < 0) + return NULL; + + memset(&reqrsp, 0, sizeof (reqrsp)); + reqrsp.req.fn = req->msg.netfn; + reqrsp.req.lun = 0; + reqrsp.req.cmd = req->msg.cmd; + reqrsp.req.datalength = req->msg.data_len; + memcpy(reqrsp.req.data, req->msg.data, req->msg.data_len); + reqrsp.rsp.datalength = RECV_MAX_PAYLOAD_SIZE; + + istr.ic_cmd = IOCTL_IPMI_KCS_ACTION; + istr.ic_timout = 0; + istr.ic_dp = (char *)&reqrsp; + istr.ic_len = sizeof (struct bmc_reqrsp); + + if (verbose) { + printf("BMC req.fn : %x\n", reqrsp.req.fn); + printf("BMC req.lun : %x\n", reqrsp.req.lun); + printf("BMC req.cmd : %x\n", reqrsp.req.cmd); + printf("BMC req.datalength : %d\n", reqrsp.req.datalength); + } + if (ioctl(intf->fd, I_STR, &istr) < 0) { + perror("BMC IOCTL: I_STR"); + return (NULL); + } + memset(&rsp, 0, sizeof (struct ipmi_rs)); + rsp.ccode = reqrsp.rsp.ccode; + rsp.data_len = reqrsp.rsp.datalength; + + if (!rsp.ccode && rsp.data_len) + memcpy(rsp.data, reqrsp.rsp.data, rsp.data_len); + + return (&rsp); +} diff --git a/ipmitool/src/plugins/bmc/bmc.h b/ipmitool/src/plugins/bmc/bmc.h new file mode 100644 index 0000000..b9c7432 --- /dev/null +++ b/ipmitool/src/plugins/bmc/bmc.h @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2004 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_BMC_H_ +#define _IPMI_BMC_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#define BMC_DEV "/dev/bmc" + +struct ipmi_rs *ipmi_bmc_send_cmd(struct ipmi_intf *intf, struct ipmi_rq *req); +int ipmi_bmc_open(struct ipmi_intf *intf); +void ipmi_bmc_close(struct ipmi_intf *intf); + +#ifdef __cplusplus +} +#endif + +#endif /* _IPMI_BMC_H_ */ diff --git a/ipmitool/src/plugins/bmc/bmc_intf.h b/ipmitool/src/plugins/bmc/bmc_intf.h new file mode 100644 index 0000000..726d879 --- /dev/null +++ b/ipmitool/src/plugins/bmc/bmc_intf.h @@ -0,0 +1,185 @@ +/* + * Copyright (c) 2004 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 _BMC_INTF_H_ +#define _BMC_INTF_H_ + +#pragma ident "@(#)bmc_intf.h 1.2 04/08/25 SMI" + +#ifdef __cplusplus +extern "C" { +#endif + +#define BMC_SUCCESS 0x0 +#define BMC_FAILURE 0x1 + +#define IPMI_SUCCESS BMC_SUCCESS +#define IPMI_FAILURE BMC_FAILURE + +/* allau clean up */ +#define IPMI_FALSE 0 +#define IPMI_TRUE 1 + +#define BMC_NETFN_CHASSIS 0x0 +#define BMC_NETFN_BRIDGE 0x2 +#define BMC_NETFN_SE 0x4 +#define BMC_NETFN_APP 0x6 +#define BMC_NETFN_FIRMWARE 0x8 +#define BMC_NETFN_STORAGE 0xa +#define BMC_NETFN_TRANSPORT 0xc + +#define SEND_MAX_PAYLOAD_SIZE 34 /* MAX payload */ +#define RECV_MAX_PAYLOAD_SIZE 33 /* MAX payload */ +#define BMC_MIN_RESPONSE_SIZE 3 +#define BMC_MIN_REQUEST_SIZE 2 +#define BMC_MAX_RESPONSE_SIZE (BMC_MIN_RESPONSE_SIZE + RECV_MAX_PAYLOAD_SIZE) +#define BMC_MAX_REQUEST_SIZE (BMC_MIN_REQUEST_SIZE + BMC_MAX_RESPONSE_SIZE) + +#define BUF_SIZE 256 +#define MAX_BUF_SIZE 256 + +/* + * Useful macros + */ +#define FORM_NETFNLUN(net, lun) ((((net) << 2) | ((lun) & 0x3))) +#define GET_NETFN(netfn) (((netfn) >> 2) & 0x3f) +#define GET_LUN(netfn) (netfn & 0x3) +#define RESP_NETFN(nflun) ((nflun) | 1) +#define ISREQUEST(nl) (((nl) & 1) == 0) /* test for request */ +#define ISRESPONSE(nl) (((nl) & 1) == 1) /* test for response */ + + +/* for checking BMC specific stuff */ +#define BMC_GET_DEVICE_ID 0x1 /* GET DEVICE ID COMMAND */ +#define BMC_IPMI_15_VER 0x51 /* IPMI 1.5 definion */ + +/* BMC Completion Code and OEM Completion Code */ +#define BMC_IPMI_UNSPECIFIC_ERROR 0xFF /* Unspecific Error */ +#define BMC_IPMI_INVALID_COMMAND 0xC1 /* Invalid Command */ +#define BMC_IPMI_COMMAND_TIMEOUT 0xC3 /* Command Timeout */ +#define BMC_IPMI_DATA_LENGTH_EXCEED 0xC8 /* DataLength exceeded limit */ +#define BMC_IPMI_OEM_FAILURE_SENDBMC 0x7E /* Cannot send BMC req */ + + +#define IOCTL_IPMI_KCS_ACTION 0x01 + + +/* + * bmc_req_t is the data structure to send + * request packet from applications to the driver + * module. + * the request pkt is mainly for KCS-interface-BMC + * messages. Since the system interface is session-less + * connections, the packet won't have any session + * information. + * the data payload will be 2 bytes less than max + * BMC supported packet size. + * the address of the responder is always BMC and so + * rsSa field is not required. + */ +typedef struct bmc_req { + unsigned char fn; /* netFn for command */ + unsigned char lun; /* logical unit on responder */ + unsigned char cmd; /* command */ + unsigned char datalength; /* length of following data */ + unsigned char data[SEND_MAX_PAYLOAD_SIZE]; /* request data */ +} bmc_req_t; + +/* + * bmc_rsp_t is the data structure to send + * respond packet from applications to the driver + * module. + * + * the respond pkt is mainly for KCS-interface-BMC + * messages. Since the system interface is session-less + * connections, the packet won't have any session + * information. + * the data payload will be 2 bytes less than max + * BMC supported packet size. + */ +typedef struct bmc_rsp { + unsigned char fn; /* netFn for command */ + unsigned char lun; /* logical unit on responder */ + unsigned char cmd; /* command */ + unsigned char ccode; /* completion code */ + unsigned char datalength; /* Length */ + unsigned char data[RECV_MAX_PAYLOAD_SIZE]; /* response */ +} bmc_rsp_t; + +/* + * the data structure for synchronous operation. + */ +typedef struct bmc_reqrsp { + bmc_req_t req; /* request half */ + bmc_rsp_t rsp; /* response half */ +} bmc_reqrsp_t; + + +#ifdef _KERNEL + +/* + * data structure to send a message to BMC. + * Ref. IPMI Spec 9.2 + */ +typedef struct bmc_send { + unsigned char fnlun; /* Network Function and LUN */ + unsigned char cmd; /* command */ + unsigned char data[SEND_MAX_PAYLOAD_SIZE]; +} bmc_send_t; + +/* + * data structure to receive a message from BMC. + * Ref. IPMI Spec 9.3 + */ +typedef struct bmc_recv { + unsigned char fnlun; /* Network Function and LUN */ + unsigned char cmd; /* command */ + unsigned char ccode; /* completion code */ + unsigned char data[RECV_MAX_PAYLOAD_SIZE]; +} bmc_recv_t; + + +#endif /* _KERNEL */ + +#ifdef __cplusplus +} +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* _BMC_INTF_H_ */