I was waiting to send this to the mailing list after the 1.8.9 release,
but since everyone is submitting patches, I figure I'll throw another
one in.

This adds FreeIPMI's library inband drivers as another interface for
Ipmitool to use (-I free).  I've been using this internally for some
time.  Looking at old e-mails, I told Duncan I would "soon submit a
patch" around two years ago.  Well, better late than never :-)

Patch was done against 1.8.8 but a recent test shows it patches into the
CVS HEAD cleanly.  

Al

-- 
Albert Chu
[EMAIL PROTECTED]
925-422-5311
Computer Scientist
High Performance Systems Division
Lawrence Livermore National Laboratory
diff -pruN ipmitool-1.8.8-orig/configure.in ipmitool-1.8.8-patched/configure.in
--- ipmitool-1.8.8-orig/configure.in	2006-05-02 09:26:13.000000000 -0700
+++ ipmitool-1.8.8-patched/configure.in	2007-02-05 10:44:40.998217000 -0800
@@ -208,6 +208,41 @@ AC_CHECK_HEADER([linux/ipmi.h],
 		[Define to 1 if you have the <sys/ipmi.h> header file.])],
 		[echo "** Unable to find OpenIPMI header files.  Using internal version."])])
 
+dnl look for FreeIPMI files
+AC_CHECK_LIB(freeipmi, ipmi_open_inband, [have_free=yes], [have_free=no])
+AC_ARG_ENABLE([intf-free],
+        [AC_HELP_STRING([--enable-intf-free],
+                        [enable FreeIPMI IPMI interface [default=auto]])],
+        [if test "x$enable_intf_free" != "xno" && test "x$have_free" != "xyes"; then
+            echo "** Unable to build FreeIPMI interface support!"
+            enable_intf_free=no
+        fi],
+        [enable_intf_free=$have_free])
+if test "x$enable_intf_free" = "xstatic" || test "x$enable_intf_free" = "xplugin"; then
+   enable_intf_free=yes
+fi
+if test "x$enable_intf_free" = "xyes"; then
+dnl Determine if you got the right FreeIPMI version  
+    AC_TRY_COMPILE([
+#include <freeipmi/freeipmi.h>
+#include <freeipmi/udm/ipmi-udm.h>
+    ], [
+    ipmi_device_t dev;
+    dev = ipmi_open_inband(IPMI_DEVICE_KCS,
+                           0,
+                           0,
+                           0,
+                           NULL,
+                           0);
+    ], ac_free_version_good=yes,ac_free_version_good=no)
+    if test "x$ac_free_version_good" = "xyes"; then
+       AC_DEFINE(IPMI_INTF_FREE, [1], [Define to 1 to enable FreeIPMI interface.])
+       AC_SUBST(INTF_FREE, [free])
+       AC_SUBST(INTF_FREE_LIB, [libintf_free.la])
+       IPMITOOL_INTF_LIB="$IPMITOOL_INTF_LIB free/libintf_free.la"
+    fi
+fi
+
 dnl look for termios header file
 AC_CHECK_HEADER([termios.h],
 	[AC_DEFINE(HAVE_TERMIOS_H, [1], [Define to 1 if you have <termios.h>.])],
@@ -344,6 +379,7 @@ AC_CONFIG_FILES([Makefile
 		src/plugins/lan/Makefile
                 src/plugins/lanplus/Makefile
 		src/plugins/open/Makefile
+                src/plugins/free/Makefile
 		src/plugins/imb/Makefile
 		src/plugins/bmc/Makefile
 		src/plugins/lipmi/Makefile])
@@ -357,6 +393,7 @@ AC_MSG_RESULT([Interfaces])
 AC_MSG_RESULT([  lan     : $enable_intf_lan])
 AC_MSG_RESULT([  lanplus : $enable_intf_lanplus])
 AC_MSG_RESULT([  open    : $enable_intf_open])
+AC_MSG_RESULT([  free    : $enable_intf_free])
 AC_MSG_RESULT([  imb     : $enable_intf_imb])
 AC_MSG_RESULT([  bmc     : $enable_intf_bmc])
 AC_MSG_RESULT([  lipmi   : $enable_intf_lipmi])
diff -pruN ipmitool-1.8.8-orig/doc/ipmitool.1 ipmitool-1.8.8-patched/doc/ipmitool.1
--- ipmitool-1.8.8-orig/doc/ipmitool.1	2006-04-27 11:05:57.000000000 -0700
+++ ipmitool-1.8.8-patched/doc/ipmitool.1	2007-02-02 17:01:12.506317000 -0800
@@ -1521,6 +1521,16 @@ on the cipher suite ID found in the IPMI
 22\-19.  The default cipher suite is \fI3\fP which specifies
 RAKP\-HMAC\-SHA1 authentication, HMAC\-SHA1\-96 integrity, and AES\-CBC\-128
 encryption algorightms.
+
+.SH "FREE INTERFACE"
+.LP
+The ipmitool \fIfree\fP interface utilizes the FreeIPMI libfreeipmi
+drivers.  
+.LP
+You can tell ipmitool to use the FreeIPMI interface with the -I option:
+.PP
+ipmitool \fB\-I\fR \fIfree\fP <\fIcommand\fP>
+
 .SH "EXAMPLES"
 .TP 
 \fIExample 1\fP: Listing remote sensors
@@ -1583,4 +1593,6 @@ http://www.intel.com/design/servers/ipmi
 .TP 
 OpenIPMI Homepage
 http://openipmi.sourceforge.net
-
+.TP
+FreeIPMI Homepage
+http://www.gnu.org/software/freeipmi/
diff -pruN ipmitool-1.8.8-orig/src/plugins/Makefile.am ipmitool-1.8.8-patched/src/plugins/Makefile.am
--- ipmitool-1.8.8-orig/src/plugins/Makefile.am	2006-03-19 09:59:39.000000000 -0800
+++ ipmitool-1.8.8-patched/src/plugins/Makefile.am	2007-02-02 17:01:55.894799000 -0800
@@ -32,8 +32,8 @@ MAINTAINERCLEANFILES		= Makefile.in
 
 INCLUDES			= -I$(top_srcdir)/include
 
-SUBDIRS				= @INTF_LAN@ @INTF_LANPLUS@ @INTF_OPEN@ @INTF_LIPMI@ @INTF_IMB@ @INTF_BMC@
-DIST_SUBDIRS			= lan lanplus open lipmi imb bmc
+SUBDIRS				= @INTF_LAN@ @INTF_LANPLUS@ @INTF_OPEN@ @INTF_LIPMI@ @INTF_IMB@ @INTF_BMC@ @INTF_FREE@
+DIST_SUBDIRS			= lan lanplus open lipmi imb bmc free
 
 noinst_LTLIBRARIES		= libintf.la
 libintf_la_SOURCES		= ipmi_intf.c
diff -pruN ipmitool-1.8.8-orig/src/plugins/free/Makefile.am ipmitool-1.8.8-patched/src/plugins/free/Makefile.am
--- ipmitool-1.8.8-orig/src/plugins/free/Makefile.am	1969-12-31 16:00:00.000000000 -0800
+++ ipmitool-1.8.8-patched/src/plugins/free/Makefile.am	2007-02-05 08:47:07.461993000 -0800
@@ -0,0 +1,9 @@
+MAINTAINERCLEANFILES           = Makefile.in
+
+INCLUDES                       = -I$(top_srcdir)/include
+
+EXTRA_LTLIBRARIES              = libintf_free.la
+noinst_LTLIBRARIES             = @INTF_FREE_LIB@
+libintf_free_la_LIBADD         = $(top_builddir)/lib/libipmitool.la
+libintf_free_la_SOURCES        = free.c
+libintf_free_la_LDFLAGS        = -lfreeipmi
diff -pruN ipmitool-1.8.8-orig/src/plugins/free/free.c ipmitool-1.8.8-patched/src/plugins/free/free.c
--- ipmitool-1.8.8-orig/src/plugins/free/free.c	1969-12-31 16:00:00.000000000 -0800
+++ ipmitool-1.8.8-patched/src/plugins/free/free.c	2007-02-05 17:32:37.495444000 -0800
@@ -0,0 +1,157 @@
+/*
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+
+#include <ipmitool/ipmi.h>
+#include <ipmitool/ipmi_intf.h>
+
+#include <freeipmi/freeipmi.h>
+#include <freeipmi/udm/ipmi-udm.h>
+
+#include <config.h>
+
+ipmi_device_t dev = NULL;
+
+extern int verbose;
+
+static int ipmi_free_open(struct ipmi_intf * intf)
+{
+        if (getuid() != 0) {
+                fprintf(stderr, "Permission denied, must be root\n");
+                return -1;
+        }
+
+        if (!(dev = ipmi_open_inband (IPMI_DEVICE_KCS,
+                                      0,
+                                      0,
+                                      0,
+                                      NULL,
+                                      IPMI_FLAGS_DEFAULT))) {
+                if (!(dev = ipmi_open_inband (IPMI_DEVICE_SSIF,
+                                              0,
+                                              0,
+                                              0,
+                                              NULL,
+                                              IPMI_FLAGS_DEFAULT))) {
+                        perror("ipmi_open_inband()");
+                        goto cleanup;
+                }
+        }
+
+	intf->opened = 1;
+	return 0;
+ cleanup:
+        if (dev)
+                ipmi_close_device(dev);
+        return -1;
+}
+
+static void ipmi_free_close(struct ipmi_intf * intf)
+{
+        if (dev)
+                ipmi_close_device(dev);
+	intf->opened = 0;
+}
+
+static struct ipmi_rs * ipmi_free_send_cmd(struct ipmi_intf * intf, struct ipmi_rq * req)
+{
+        u_int8_t lun = 0;
+        u_int8_t cmd = req->msg.cmd;
+        u_int8_t netfn = req->msg.netfn;
+        u_int8_t rq_buf[IPMI_BUF_SIZE];
+        u_int8_t rs_buf[IPMI_BUF_SIZE];
+        u_int32_t rs_buf_len = IPMI_BUF_SIZE;
+        int32_t rs_len;
+
+	static struct ipmi_rs rsp;	
+
+        /* achu: FreeIPMI requests have the cmd as the first byte of
+         * the data.  Responses have cmd as the first byte and
+         * completion code as the second byte.  This differs from some
+         * other APIs, so it must be compensated for within the ipmitool
+         * interface.
+         */
+
+	if (!intf || !req)
+		return NULL;
+
+	if (!intf->opened && intf->open && intf->open(intf) < 0)
+		return NULL;
+
+        if (req->msg.data_len > IPMI_BUF_SIZE)
+                return NULL;
+
+        memset(rq_buf, '\0', IPMI_BUF_SIZE);
+        memset(rs_buf, '\0', IPMI_BUF_SIZE);
+        memcpy(rq_buf, &cmd, 1);
+
+        if (req->msg.data)
+               memcpy(rq_buf + 1, req->msg.data, req->msg.data_len);
+
+        if ((rs_len = ipmi_cmd_raw(dev,
+                                   lun, 
+                                   netfn,                    
+                                   rq_buf, 
+                                   req->msg.data_len + 1,
+                                   rs_buf, 
+                                   rs_buf_len)) < 0) {
+                perror("ipmi_cmd_raw");
+                return NULL;
+        }
+
+        memset(&rsp, 0, sizeof(struct ipmi_rs));
+	rsp.ccode = (unsigned char)rs_buf[1];
+	rsp.data_len = (int)rs_len - 2;
+
+	if (!rsp.ccode && rsp.data_len)
+		memcpy(rsp.data, rs_buf + 2, rsp.data_len);
+
+	return &rsp;
+}
+
+struct ipmi_intf ipmi_free_intf = {
+	name:		"free",
+	desc:		"FreeIPMI IPMI Interface",
+	open:		ipmi_free_open,
+	close:		ipmi_free_close,
+	sendrecv:	ipmi_free_send_cmd,
+	target_addr:	IPMI_BMC_SLAVE_ADDR,
+};
+
diff -pruN ipmitool-1.8.8-orig/src/plugins/ipmi_intf.c ipmitool-1.8.8-patched/src/plugins/ipmi_intf.c
--- ipmitool-1.8.8-orig/src/plugins/ipmi_intf.c	2006-05-01 15:33:21.000000000 -0700
+++ ipmitool-1.8.8-patched/src/plugins/ipmi_intf.c	2007-02-05 08:47:48.444486000 -0800
@@ -59,6 +59,9 @@ extern struct ipmi_intf ipmi_lan_intf;
 #ifdef IPMI_INTF_LANPLUS
 extern struct ipmi_intf ipmi_lanplus_intf;
 #endif
+#ifdef IPMI_INTF_FREE
+extern struct ipmi_intf ipmi_free_intf;
+#endif
 
 struct ipmi_intf * ipmi_intf_table[] = {
 #ifdef IPMI_INTF_OPEN
@@ -79,6 +82,9 @@ struct ipmi_intf * ipmi_intf_table[] = {
 #ifdef IPMI_INTF_LANPLUS
 	&ipmi_lanplus_intf,
 #endif
+#ifdef IPMI_INTF_FREE
+	&ipmi_free_intf,
+#endif
 	NULL
 };
 
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Ipmitool-devel mailing list
Ipmitool-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ipmitool-devel

Reply via email to