From 76bb61de6c88fc55f5ed706c76c6645a50516b9d Mon Sep 17 00:00:00 2001 From: Albert Chu Date: Mon, 4 Jun 2007 18:03:52 +0000 Subject: [PATCH] support FreeIPMI 0.4.0 api --- ipmitool/configure.in | 34 +++++++++++++++++++++--- ipmitool/src/plugins/free/free.c | 45 ++++++++++++++++++++++++++++++-- 2 files changed, 73 insertions(+), 6 deletions(-) diff --git a/ipmitool/configure.in b/ipmitool/configure.in index 16a0380..ff6ddc0 100644 --- a/ipmitool/configure.in +++ b/ipmitool/configure.in @@ -239,7 +239,7 @@ if test "x$enable_intf_free" = "xstatic" || test "x$enable_intf_free" = "xplugin fi if test "x$enable_intf_free" = "xyes"; then dnl Determine if you got the right FreeIPMI version - AC_MSG_CHECKING([for good libfreeipmi version]) + AC_MSG_CHECKING([for libfreeipmi version 0.3.0]) AC_TRY_COMPILE([ #include /* For size_t */ #include /* For NULL */ @@ -253,13 +253,39 @@ dnl Determine if you got the right FreeIPMI version 0, NULL, 0); - ], ac_free_version_good=yes,ac_free_version_good=no) - AC_MSG_RESULT($ac_free_version_good) - if test "x$ac_free_version_good" = "xyes"; then + ], ac_free_version_0_3_0=yes,ac_free_version_0_3_0=no) + AC_MSG_RESULT($ac_free_version_0_3_0) + AC_MSG_CHECKING([for libfreeipmi version 0.4.0]) + AC_TRY_COMPILE([ +#include /* For size_t */ +#include /* For NULL */ +#include +#include + ], [ + ipmi_device_t dev = NULL; + int rv; + dev = ipmi_device_create(); + rv = ipmi_open_inband(dev, + IPMI_DEVICE_KCS, + 0, + 0, + 0, + NULL, + 0); + ], ac_free_version_0_4_0=yes,ac_free_version_0_4_0=no) + AC_MSG_RESULT($ac_free_version_0_4_0) + + if test "x$ac_free_version_0_3_0" = "xyes" || test "x$ac_free_version_0_4_0" = "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" + if test "x$ac_free_version_0_3_0" = "xyes"; then + AC_DEFINE(IPMI_INTF_FREE_VERSION_0_3_0, [1], [Define to 1 for FreeIPMI 0.3.0.]) + fi + if test "x$ac_free_version_0_4_0" = "xyes"; then + AC_DEFINE(IPMI_INTF_FREE_VERSION_0_4_0, [1], [Define to 1 for FreeIPMI 0.4.0.]) + fi else enable_intf_free=no fi diff --git a/ipmitool/src/plugins/free/free.c b/ipmitool/src/plugins/free/free.c index 8ce05b4..801befa 100644 --- a/ipmitool/src/plugins/free/free.c +++ b/ipmitool/src/plugins/free/free.c @@ -58,6 +58,7 @@ static int ipmi_free_open(struct ipmi_intf * intf) return -1; } +#if IPMI_INTF_FREE_VERSION_0_3_0 if (!(dev = ipmi_open_inband (IPMI_DEVICE_KCS, 0, 0, @@ -74,19 +75,53 @@ static int ipmi_free_open(struct ipmi_intf * intf) goto cleanup; } } +#elif IPMI_INTF_FREE_VERSION_0_4_0 + if (!(dev = ipmi_device_create())) { + perror("ipmi_open_inband()"); + goto cleanup; + } + if (ipmi_open_inband (dev, + IPMI_DEVICE_KCS, + 0, + 0, + 0, + NULL, + IPMI_FLAGS_DEFAULT) < 0) { + if (ipmi_open_inband (dev, + IPMI_DEVICE_SSIF, + 0, + 0, + 0, + NULL, + IPMI_FLAGS_DEFAULT) < 0) { + fprintf(stderr, + "ipmi_open_inband(): %s\n", + ipmi_device_strerror(ipmi_device_errnum(dev))); + goto cleanup; + } + } +#endif intf->opened = 1; return 0; cleanup: - if (dev) + if (dev) { ipmi_close_device(dev); +#if IPMI_INTF_FREE_VERSION_0_4_0 + ipmi_device_destroy(dev); +#endif + } return -1; } static void ipmi_free_close(struct ipmi_intf * intf) { - if (dev) + if (dev) { ipmi_close_device(dev); +#if IPMI_INTF_FREE_VERSION_0_4_0 + ipmi_device_destroy(dev); +#endif + } intf->opened = 0; } @@ -132,7 +167,13 @@ static struct ipmi_rs * ipmi_free_send_cmd(struct ipmi_intf * intf, struct ipmi_ req->msg.data_len + 1, rs_buf, rs_buf_len)) < 0) { +#if IPMI_INTF_FREE_VERSION_0_3_0 perror("ipmi_cmd_raw"); +#elif IPMI_INTF_FREE_VERSION_0_4_0 + fprintf(stderr, + "ipmi_cmd_raw: %s\n", + ipmi_device_strerror(ipmi_device_errnum(dev))); +#endif return NULL; }