mirror of
https://github.com/ipmitool/ipmitool.git
synced 2025-05-10 18:47:22 +00:00
massive rework of many subsytems
handle errors better and return status codes correctly
This commit is contained in:
parent
b6852fc77b
commit
4db9739e17
@ -3,7 +3,7 @@ dnl autoconf for ipmitool
|
||||
dnl
|
||||
AC_INIT([src/ipmitool.c])
|
||||
AC_CANONICAL_SYSTEM
|
||||
AM_INIT_AUTOMAKE([ipmitool], [1.6.2])
|
||||
AM_INIT_AUTOMAKE([ipmitool], [1.6.2pre8])
|
||||
AM_CONFIG_HEADER(config.h)
|
||||
AC_CONFIG_SRCDIR([src/ipmitool.c])
|
||||
AC_PREREQ(2.50)
|
||||
@ -59,6 +59,7 @@ solaris*)
|
||||
LD=gld
|
||||
AR=gar
|
||||
# disable the linux-specific interfaces
|
||||
enable_intf_bmc=yes
|
||||
enable_intf_imb=no
|
||||
enable_intf_open=no
|
||||
enable_ipmievd=no
|
||||
@ -192,22 +193,37 @@ dnl enable Solaris LIPMI interface
|
||||
AC_CHECK_HEADER([sys/lipmi/lipmi_intf.h], [have_lipmi=yes], [have_lipmi=no])
|
||||
AC_ARG_ENABLE([intf-lipmi],
|
||||
[AC_HELP_STRING([--enable-intf-lipmi],
|
||||
[enable Solaris x86 IPMI interface [default=auto]])],
|
||||
[enable Solaris 9 x86 IPMI interface [default=no]])],
|
||||
[if test "x$enable_intf_lipmi" != "xno" && test "x$have_lipmi" != "xyes"; then
|
||||
echo "** Unable to build Solaris x86 IPMI interface support!"
|
||||
echo "** Unable to build Solaris 9 x86 IPMI interface support!"
|
||||
enable_intf_lipmi=no
|
||||
fi],
|
||||
[enable_intf_lipmi=$have_lipmi])
|
||||
[enable_intf_lipmi=no])
|
||||
if test "x$enable_intf_lipmi" = "xstatic" || test "x$enable_intf_lipmi" = "xplugin"; then
|
||||
enable_intf_lipmi=yes
|
||||
fi
|
||||
if test "x$enable_intf_lipmi" = "xyes"; then
|
||||
AC_DEFINE(IPMI_INTF_LIPMI, [1], [Define to 1 to enable Solaris LIPMI interface.])
|
||||
AC_DEFINE(IPMI_INTF_LIPMI, [1], [Define to 1 to enable Solaris 9 LIPMI interface.])
|
||||
AC_SUBST(INTF_LIPMI, [lipmi])
|
||||
AC_SUBST(INTF_LIPMI_LIB, [libintf_lipmi.la])
|
||||
IPMITOOL_INTF_LIB="$IPMITOOL_INTF_LIB lipmi/libintf_lipmi.la"
|
||||
fi
|
||||
|
||||
dnl enable Solaris BMC interface
|
||||
AC_ARG_ENABLE([intf-bmc],
|
||||
[AC_HELP_STRING([--enable-intf-bmc],
|
||||
[enable Solaris 10 x86 IPMI interface [default=no]])],,
|
||||
[enable_intf_bmc=no])
|
||||
if test "x$enable_intf_bmc" = "xstatic" || test "x$enable_intf_bmc" = "xplugin"; then
|
||||
enable_intf_bmc=yes
|
||||
fi
|
||||
if test "x$enable_intf_bmc" = "xyes"; then
|
||||
AC_DEFINE(IPMI_INTF_BMC, [1], [Define to 1 to enable Solaris 10 BMC interface.])
|
||||
AC_SUBST(INTF_BMC, [bmc])
|
||||
AC_SUBST(INTF_BMC_LIB, [libintf_bmc.la])
|
||||
IPMITOOL_INTF_LIB="$IPMITOOL_INTF_LIB bmc/libintf_bmc.la"
|
||||
fi
|
||||
|
||||
AC_SUBST(IPMITOOL_INTF_LIB)
|
||||
|
||||
dnl check for readline library to enable ipmi shell
|
||||
@ -260,6 +276,7 @@ AC_CONFIG_FILES([Makefile
|
||||
src/plugins/lanplus/Makefile
|
||||
src/plugins/open/Makefile
|
||||
src/plugins/imb/Makefile
|
||||
src/plugins/bmc/Makefile
|
||||
src/plugins/lipmi/Makefile])
|
||||
|
||||
AC_OUTPUT
|
||||
@ -272,6 +289,7 @@ AC_MSG_RESULT([ lan : $enable_intf_lan])
|
||||
AC_MSG_RESULT([ lanplus : $enable_intf_lanplus])
|
||||
AC_MSG_RESULT([ open : $enable_intf_open])
|
||||
AC_MSG_RESULT([ imb : $enable_intf_imb])
|
||||
AC_MSG_RESULT([ bmc : $enable_intf_bmc])
|
||||
AC_MSG_RESULT([ lipmi : $enable_intf_lipmi])
|
||||
AC_MSG_RESULT([])
|
||||
AC_MSG_RESULT([Extra tools])
|
||||
|
@ -41,7 +41,7 @@ Remote server address, can be IP address or hostname. This option is required f
|
||||
Remote username, default is NULL user.
|
||||
.TP
|
||||
\fB\-L\fR <\fIprivlvl\fP>
|
||||
Force sessin privilege level. Can be CALLBACK, USER, OPERATOR, ADMIN. Default is USER.
|
||||
Force sessin privilege level. Can be CALLBACK, USER, OPERATOR, ADMIN. Default is ADMIN.
|
||||
.TP
|
||||
\fB\-a\fR
|
||||
Promt for the remote server password, 16 character maximum. This is optional for the LAN interface, if a password is not provided the session will not be authenticated.
|
||||
|
@ -223,6 +223,6 @@ static const char * chassis_type_desc[] __attribute__((unused)) = {
|
||||
};
|
||||
|
||||
int ipmi_fru_main(struct ipmi_intf * intf, int argc, char ** argv);
|
||||
void ipmi_fru_print(struct ipmi_intf * intf, struct sdr_record_fru_locator * fru);
|
||||
int ipmi_fru_print(struct ipmi_intf * intf, struct sdr_record_fru_locator * fru);
|
||||
|
||||
#endif /* IPMI_FRU_H */
|
||||
|
@ -589,20 +589,20 @@ struct ipmi_sdr_iterator * ipmi_sdr_start(struct ipmi_intf * intf);
|
||||
struct sdr_get_rs * ipmi_sdr_get_next_header(struct ipmi_intf * intf, struct ipmi_sdr_iterator * i);
|
||||
unsigned char * ipmi_sdr_get_record(struct ipmi_intf * intf, struct sdr_get_rs * header, struct ipmi_sdr_iterator * i);
|
||||
void ipmi_sdr_end(struct ipmi_intf * intf, struct ipmi_sdr_iterator * i);
|
||||
void ipmi_sdr_print_sdr(struct ipmi_intf * intf, unsigned char type);
|
||||
void ipmi_sdr_print_rawentry(struct ipmi_intf * intf, unsigned char type, unsigned char * raw, int len);
|
||||
void ipmi_sdr_print_listentry(struct ipmi_intf * intf, struct sdr_record_list * entry);
|
||||
int ipmi_sdr_print_sdr(struct ipmi_intf * intf, unsigned char type);
|
||||
int ipmi_sdr_print_rawentry(struct ipmi_intf * intf, unsigned char type, unsigned char * raw, int len);
|
||||
int ipmi_sdr_print_listentry(struct ipmi_intf * intf, struct sdr_record_list * entry);
|
||||
const char * ipmi_sdr_get_status(unsigned char stat);
|
||||
float sdr_convert_sensor_reading(struct sdr_record_full_sensor * sensor, unsigned char val);
|
||||
unsigned char sdr_convert_sensor_value_to_raw(struct sdr_record_full_sensor * sensor, float val);
|
||||
struct ipmi_rs * ipmi_sdr_get_sensor_reading(struct ipmi_intf * intf, unsigned char sensor);
|
||||
const char * ipmi_sdr_get_sensor_type_desc(const unsigned char type);
|
||||
|
||||
void ipmi_sdr_print_sensor_full(struct ipmi_intf * intf, struct sdr_record_full_sensor * sensor);
|
||||
void ipmi_sdr_print_sensor_compact(struct ipmi_intf * intf, struct sdr_record_compact_sensor * sensor);
|
||||
void ipmi_sdr_print_sensor_eventonly(struct ipmi_intf * intf, struct sdr_record_eventonly_sensor * sensor);
|
||||
void ipmi_sdr_print_fru_locator(struct ipmi_intf * intf, struct sdr_record_fru_locator * fru);
|
||||
void ipmi_sdr_print_mc_locator(struct ipmi_intf * intf, struct sdr_record_mc_locator * mc);
|
||||
int ipmi_sdr_print_sensor_full(struct ipmi_intf * intf, struct sdr_record_full_sensor * sensor);
|
||||
int ipmi_sdr_print_sensor_compact(struct ipmi_intf * intf, struct sdr_record_compact_sensor * sensor);
|
||||
int ipmi_sdr_print_sensor_eventonly(struct ipmi_intf * intf, struct sdr_record_eventonly_sensor * sensor);
|
||||
int ipmi_sdr_print_sensor_fru_locator(struct ipmi_intf * intf, struct sdr_record_fru_locator * fru);
|
||||
int ipmi_sdr_print_sensor_mc_locator(struct ipmi_intf * intf, struct sdr_record_mc_locator * mc);
|
||||
|
||||
struct sdr_record_list * ipmi_sdr_find_sdr_byentity(struct ipmi_intf * intf, struct entity_id * entity);
|
||||
struct sdr_record_list * ipmi_sdr_find_sdr_bynumtype(struct ipmi_intf * intf, unsigned char num, unsigned char type);
|
||||
|
@ -35,6 +35,8 @@
|
||||
*/
|
||||
|
||||
#include <ipmitool/ipmi.h>
|
||||
#include <ipmitool/log.h>
|
||||
#include <ipmitool/helper.h>
|
||||
#include <ipmitool/ipmi_intf.h>
|
||||
#include <ipmitool/ipmi_fru.h>
|
||||
|
||||
@ -670,7 +672,8 @@ const struct valstr jedec_id5_vals[] = {
|
||||
{ 0x00, NULL },
|
||||
};
|
||||
|
||||
void ipmi_spd_print(struct ipmi_intf * intf, unsigned char id)
|
||||
int
|
||||
ipmi_spd_print(struct ipmi_intf * intf, unsigned char id)
|
||||
{
|
||||
struct ipmi_rs * rsp;
|
||||
struct ipmi_rq req;
|
||||
@ -687,14 +690,26 @@ void ipmi_spd_print(struct ipmi_intf * intf, unsigned char id)
|
||||
req.msg.data_len = 1;
|
||||
|
||||
rsp = intf->sendrecv(intf, &req);
|
||||
if (!rsp || rsp->ccode)
|
||||
return;
|
||||
if (rsp == NULL) {
|
||||
printf(" Device not present (No Response)\n");
|
||||
return -1;
|
||||
}
|
||||
if (rsp->ccode > 0) {
|
||||
printf(" Device not present (%s)\n",
|
||||
val2str(rsp->ccode, completion_code_vals));
|
||||
return -1;
|
||||
}
|
||||
|
||||
fru.size = (rsp->data[1] << 8) | rsp->data[0];
|
||||
fru.access = rsp->data[2] & 0x1;
|
||||
|
||||
if (verbose > 1)
|
||||
printf("fru.size = %d bytes (accessed by %s)\n",
|
||||
fru.size, fru.access ? "words" : "bytes");
|
||||
lprintf(LOG_DEBUG, "fru.size = %d bytes (accessed by %s)",
|
||||
fru.size, fru.access ? "words" : "bytes");
|
||||
|
||||
if (fru.size < 1) {
|
||||
lprintf(LOG_ERR, " Invalid FRU size %d", fru.size);
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(&req, 0, sizeof(req));
|
||||
req.msg.netfn = IPMI_NETFN_STORAGE;
|
||||
@ -711,14 +726,14 @@ void ipmi_spd_print(struct ipmi_intf * intf, unsigned char id)
|
||||
msg_data[3] = 32;
|
||||
|
||||
rsp = intf->sendrecv(intf, &req);
|
||||
if (!rsp) {
|
||||
if (rsp == NULL) {
|
||||
printf(" Device not present (No Response)\n");
|
||||
return;
|
||||
return -1;
|
||||
}
|
||||
if(rsp->ccode) {
|
||||
if (rsp->ccode > 0) {
|
||||
printf(" Device not present (%s)\n",
|
||||
val2str(rsp->ccode, completion_code_vals));
|
||||
return;
|
||||
return -1;
|
||||
}
|
||||
|
||||
len = rsp->data[0];
|
||||
@ -726,33 +741,43 @@ void ipmi_spd_print(struct ipmi_intf * intf, unsigned char id)
|
||||
offset += len;
|
||||
} while (offset < fru.size);
|
||||
|
||||
if (verbose)
|
||||
if (verbose > 1)
|
||||
printbuf(spd_data, offset, "SPD DATA");
|
||||
|
||||
if (offset < 92)
|
||||
return; /* we need first 91 bytes to do our thing */
|
||||
return -1; /* we need first 91 bytes to do our thing */
|
||||
|
||||
size = spd_data[5] * (spd_data[31] << 2);
|
||||
printf(" Memory Size : %d MB\n", size);
|
||||
printf(" Memory Type : %s\n", val2str(spd_data[2], spd_memtype_vals));
|
||||
printf(" Voltage Intf : %s\n", val2str(spd_data[8], spd_voltage_vals));
|
||||
printf(" Error Detect/Cor : %s\n", val2str(spd_data[11], spd_config_vals));
|
||||
printf(" Memory Type : %s\n",
|
||||
val2str(spd_data[2], spd_memtype_vals));
|
||||
printf(" Voltage Intf : %s\n",
|
||||
val2str(spd_data[8], spd_voltage_vals));
|
||||
printf(" Error Detect/Cor : %s\n",
|
||||
val2str(spd_data[11], spd_config_vals));
|
||||
|
||||
/* handle jedec table bank continuation values */
|
||||
printf(" Manufacturer : ");
|
||||
if (spd_data[64] != 0x7f)
|
||||
printf("%s\n", val2str(spd_data[64], jedec_id1_vals));
|
||||
printf("%s\n",
|
||||
val2str(spd_data[64], jedec_id1_vals));
|
||||
else {
|
||||
if (spd_data[65] != 0x7f)
|
||||
printf("%s\n", val2str(spd_data[65], jedec_id2_vals));
|
||||
printf("%s\n",
|
||||
val2str(spd_data[65], jedec_id2_vals));
|
||||
else {
|
||||
if (spd_data[66] != 0x7f)
|
||||
printf("%s\n", val2str(spd_data[66], jedec_id3_vals));
|
||||
printf("%s\n",
|
||||
val2str(spd_data[66], jedec_id3_vals));
|
||||
else {
|
||||
if (spd_data[67] != 0x7f)
|
||||
printf("%s\n", val2str(spd_data[67], jedec_id4_vals));
|
||||
printf("%s\n",
|
||||
val2str(spd_data[67],
|
||||
jedec_id4_vals));
|
||||
else
|
||||
printf("%s\n", val2str(spd_data[68], jedec_id5_vals));
|
||||
printf("%s\n",
|
||||
val2str(spd_data[68],
|
||||
jedec_id5_vals));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -763,4 +788,6 @@ void ipmi_spd_print(struct ipmi_intf * intf, unsigned char id)
|
||||
part[18] = 0;
|
||||
printf(" Part Number : %s\n", part);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -47,6 +47,8 @@
|
||||
|
||||
#include <ipmitool/helper.h>
|
||||
|
||||
extern int verbose;
|
||||
|
||||
uint32_t buf2long(unsigned char * buf)
|
||||
{
|
||||
return (uint32_t)(buf[3] << 24 | buf[2] << 16 | buf[1] << 8 | buf[0]);
|
||||
@ -79,16 +81,19 @@ void printbuf(const unsigned char * buf, int len, const char * desc)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (!len)
|
||||
if (len <= 0)
|
||||
return;
|
||||
|
||||
printf("%s (%d bytes)\n", desc, len);
|
||||
if (verbose < 1)
|
||||
return;
|
||||
|
||||
fprintf(stderr, "%s (%d bytes)\n", desc, len);
|
||||
for (i=0; i<len; i++) {
|
||||
if (((i%16) == 0) && (i != 0))
|
||||
printf("\n");
|
||||
printf(" %2.2x", buf[i]);
|
||||
fprintf(stderr, "\n");
|
||||
fprintf(stderr, " %2.2x", buf[i]);
|
||||
}
|
||||
printf("\n");
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
const char * val2str(unsigned short val, const struct valstr *vs)
|
||||
|
@ -48,6 +48,7 @@
|
||||
#include <ipmitool/ipmi.h>
|
||||
#include <ipmitool/ipmi_intf.h>
|
||||
#include <ipmitool/helper.h>
|
||||
#include <ipmitool/log.h>
|
||||
#include <ipmitool/ipmi_lanp.h>
|
||||
#include <ipmitool/ipmi_channel.h>
|
||||
#include <ipmitool/ipmi_strings.h>
|
||||
@ -61,23 +62,19 @@ void printf_channel_usage (void);
|
||||
* Create a string describing the supported authentication types as
|
||||
* specificed by the parameter n
|
||||
*/
|
||||
const char * ipmi_1_5_authtypes(unsigned char n)
|
||||
static const char *
|
||||
ipmi_1_5_authtypes(unsigned char n)
|
||||
{
|
||||
unsigned int i;
|
||||
static char supportedTypes[128];
|
||||
|
||||
bzero(supportedTypes, 128);
|
||||
|
||||
i = 0;
|
||||
while (ipmi_authtype_vals[i].val)
|
||||
{
|
||||
if (n & ipmi_authtype_vals[i].val)
|
||||
{
|
||||
for (i = 0; ipmi_authtype_vals[i].val != 0; i++) {
|
||||
if (n & ipmi_authtype_vals[i].val) {
|
||||
strcat(supportedTypes, ipmi_authtype_vals[i].str);
|
||||
strcat(supportedTypes, " ");
|
||||
}
|
||||
|
||||
++i;
|
||||
}
|
||||
|
||||
return supportedTypes;
|
||||
@ -91,16 +88,16 @@ const char * ipmi_1_5_authtypes(unsigned char n)
|
||||
* return 0 on success
|
||||
* -1 on failure
|
||||
*/
|
||||
int ipmi_get_channel_auth_cap(struct ipmi_intf * intf,
|
||||
unsigned char channel,
|
||||
unsigned char priv)
|
||||
int
|
||||
ipmi_get_channel_auth_cap(struct ipmi_intf * intf,
|
||||
unsigned char channel,
|
||||
unsigned char priv)
|
||||
{
|
||||
struct ipmi_rs * rsp;
|
||||
struct ipmi_rq req;
|
||||
struct get_channel_auth_cap_rsp auth_cap;
|
||||
|
||||
|
||||
unsigned char msg_data[2];
|
||||
|
||||
msg_data[0] = channel | 0x80; // Ask for IPMI v2 data as well
|
||||
msg_data[1] = priv;
|
||||
|
||||
@ -112,8 +109,7 @@ int ipmi_get_channel_auth_cap(struct ipmi_intf * intf,
|
||||
|
||||
rsp = intf->sendrecv(intf, &req);
|
||||
|
||||
if (!rsp || rsp->ccode)
|
||||
{
|
||||
if ((rsp == NULL) || (rsp->ccode > 0)) {
|
||||
/*
|
||||
* It's very possible that this failed because we asked for IPMI v2 data
|
||||
* Ask again, without requesting IPMI v2 data
|
||||
@ -121,16 +117,19 @@ int ipmi_get_channel_auth_cap(struct ipmi_intf * intf,
|
||||
msg_data[0] &= 0x7F;
|
||||
|
||||
rsp = intf->sendrecv(intf, &req);
|
||||
if (!rsp || rsp->ccode) {
|
||||
printf("Error:%x Get Channel Authentication Capabilities Command (0x%x)\n",
|
||||
rsp ? rsp->ccode : 0, channel);
|
||||
if (rsp == NULL) {
|
||||
lprintf(LOG_ERR, "Unable to Get Channel Authentication Capabilities");
|
||||
return -1;
|
||||
}
|
||||
if (rsp->ccode > 0) {
|
||||
lprintf(LOG_ERR, "Get Channel Authentication Capabilities failed: %s",
|
||||
val2str(rsp->ccode, completion_code_vals));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
memcpy(&auth_cap, rsp->data, sizeof(struct get_channel_auth_cap_rsp));
|
||||
|
||||
|
||||
printf("Channel number : %d\n",
|
||||
auth_cap.channel_number);
|
||||
printf("IPMI v1.5 auth types : %s\n",
|
||||
@ -152,8 +151,7 @@ int ipmi_get_channel_auth_cap(struct ipmi_intf * intf,
|
||||
printf("Anonymous login enabled : %s\n",
|
||||
(auth_cap.anon_login_enabled) ? "yes" : "no");
|
||||
|
||||
if (auth_cap.v20_data_available)
|
||||
{
|
||||
if (auth_cap.v20_data_available) {
|
||||
printf("Channel supports IPMI v1.5 : %s\n",
|
||||
(auth_cap.ipmiv15_support) ? "yes" : "no");
|
||||
printf("Channel supports IPMI v2.0 : %s\n",
|
||||
@ -164,8 +162,7 @@ int ipmi_get_channel_auth_cap(struct ipmi_intf * intf,
|
||||
* If there is support for an OEM authentication type, there is some
|
||||
* information.
|
||||
*/
|
||||
if (auth_cap.enabled_auth_types & IPMI_1_5_AUTH_TYPE_BIT_OEM)
|
||||
{
|
||||
if (auth_cap.enabled_auth_types & IPMI_1_5_AUTH_TYPE_BIT_OEM) {
|
||||
printf("IANA Number for OEM : %d\n",
|
||||
auth_cap.oem_id[0] |
|
||||
auth_cap.oem_id[1] << 8 |
|
||||
@ -202,17 +199,18 @@ ipmi_get_channel_info(struct ipmi_intf * intf, unsigned char channel)
|
||||
req.msg.data_len = 1;
|
||||
|
||||
rsp = intf->sendrecv(intf, &req);
|
||||
|
||||
if (!rsp || rsp->ccode) {
|
||||
printf("Error:%x Get Channel Info Command (0x%x)\n",
|
||||
rsp ? rsp->ccode : 0, channel);
|
||||
if (rsp == NULL) {
|
||||
lprintf(LOG_ERR, "Unable to Get Channel Info");
|
||||
return -1;
|
||||
}
|
||||
if (rsp->ccode > 0) {
|
||||
lprintf(LOG_ERR, "Get Channel Info failed: %s",
|
||||
val2str(rsp->ccode, completion_code_vals));
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
memcpy(&channel_info, rsp->data, sizeof(struct get_channel_info_rsp));
|
||||
|
||||
|
||||
printf("Channel 0x%x info:\n", channel_info.channel_number);
|
||||
|
||||
printf(" Channel Medium Type : %s\n",
|
||||
@ -260,7 +258,13 @@ ipmi_get_channel_info(struct ipmi_intf * intf, unsigned char channel)
|
||||
req.msg.data_len = 2;
|
||||
|
||||
rsp = intf->sendrecv(intf, &req);
|
||||
if (!rsp || rsp->ccode) {
|
||||
if (rsp == NULL) {
|
||||
lprintf(LOG_ERR, "Unable to Get Channel Access (volatile)");
|
||||
return -1;
|
||||
}
|
||||
if (rsp->ccode > 0) {
|
||||
lprintf(LOG_ERR, "Get Channel Access (volatile) failed: %s",
|
||||
val2str(rsp->ccode, completion_code_vals));
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -298,7 +302,13 @@ ipmi_get_channel_info(struct ipmi_intf * intf, unsigned char channel)
|
||||
|
||||
rqdata[1] = 0x40; /* 0x40=non-volatile */
|
||||
rsp = intf->sendrecv(intf, &req);
|
||||
if (!rsp || rsp->ccode) {
|
||||
if (rsp == NULL) {
|
||||
lprintf(LOG_ERR, "Unable to Get Channel Access (non-volatile)");
|
||||
return -1;
|
||||
}
|
||||
if (rsp->ccode > 0) {
|
||||
lprintf(LOG_ERR, "Get Channel Access (non-volatile) failed: %s",
|
||||
val2str(rsp->ccode, completion_code_vals));
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -331,7 +341,7 @@ ipmi_get_channel_info(struct ipmi_intf * intf, unsigned char channel)
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
@ -345,7 +355,7 @@ ipmi_get_user_access(struct ipmi_intf * intf, unsigned char channel, unsigned ch
|
||||
|
||||
ipmi_intf_session_set_privlvl(intf, IPMI_SESSION_PRIV_ADMIN);
|
||||
|
||||
curr_uid = userid ? userid : 1;
|
||||
curr_uid = userid ? : 1;
|
||||
|
||||
memset(&req1, 0, sizeof(req1));
|
||||
req1.msg.netfn = IPMI_NETFN_APP;
|
||||
@ -365,39 +375,53 @@ ipmi_get_user_access(struct ipmi_intf * intf, unsigned char channel, unsigned ch
|
||||
rqdata[1] = curr_uid & 0x3f;
|
||||
|
||||
rsp = intf->sendrecv(intf, &req1);
|
||||
if (!rsp || rsp->ccode) {
|
||||
printf("Error:%x Get User Access Command (0x%x)\n",
|
||||
rsp ? rsp->ccode : 0, channel);
|
||||
if (rsp == NULL) {
|
||||
lprintf(LOG_ERR, "Unable to Get User Access (channel %d id %d)",
|
||||
rqdata[0], rqdata[1]);
|
||||
return -1;
|
||||
}
|
||||
if (rsp->ccode > 0) {
|
||||
lprintf(LOG_ERR, "Get User Access (channel %d id %d) failed: %s",
|
||||
rqdata[0], rqdata[1],
|
||||
val2str(rsp->ccode, completion_code_vals));
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy(&user_access, rsp->data, sizeof(struct get_user_access_rsp));
|
||||
|
||||
|
||||
rqdata[0] = curr_uid & 0x3f;
|
||||
|
||||
rsp = intf->sendrecv(intf, &req2);
|
||||
if (!rsp || rsp->ccode) {
|
||||
printf("Error:%x Get User Name Command (0x%x)\n",
|
||||
rsp ? rsp->ccode : 0, channel);
|
||||
if (rsp == NULL) {
|
||||
lprintf(LOG_ERR, "Unable to Get User Name (id %d)", rqdata[0]);
|
||||
return -1;
|
||||
}
|
||||
if (rsp->ccode > 0) {
|
||||
lprintf(LOG_ERR, "Get User Name (id %d) failed: %s",
|
||||
rqdata[0], val2str(rsp->ccode, completion_code_vals));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (init)
|
||||
{
|
||||
if (init) {
|
||||
printf("Maximum User IDs : %d\n", user_access.max_user_ids);
|
||||
printf("Enabled User IDs : %d\n", user_access.enabled_user_ids);
|
||||
max_uid = user_access.max_user_ids;
|
||||
init = 0;
|
||||
}
|
||||
|
||||
printf("\nUser ID : %d\n", curr_uid);
|
||||
printf("\n");
|
||||
printf("User ID : %d\n", curr_uid);
|
||||
printf("User Name : %s\n", rsp->data);
|
||||
printf("Fixed Name : %s\n", curr_uid <= user_access.fixed_user_ids ? "Yes" : "No");
|
||||
printf("Access Available : %s\n", user_access.callin_callback ? "callback" : "call-in / callback");
|
||||
printf("Link Authentication : %sabled\n", user_access.link_auth ? "en" : "dis");
|
||||
printf("IPMI Messaging : %sabled\n", user_access.ipmi_messaging ? "en" : "dis");
|
||||
printf("Privilege Level : %s\n", val2str(user_access.privilege_limit, ipmi_privlvl_vals));
|
||||
printf("Fixed Name : %s\n",
|
||||
(curr_uid <= user_access.fixed_user_ids) ? "Yes" : "No");
|
||||
printf("Access Available : %s\n",
|
||||
(user_access.callin_callback) ? "callback" : "call-in / callback");
|
||||
printf("Link Authentication : %sabled\n",
|
||||
(user_access.link_auth) ? "en" : "dis");
|
||||
printf("IPMI Messaging : %sabled\n",
|
||||
(user_access.ipmi_messaging) ? "en" : "dis");
|
||||
printf("Privilege Level : %s\n",
|
||||
val2str(user_access.privilege_limit, ipmi_privlvl_vals));
|
||||
|
||||
curr_uid ++;
|
||||
|
||||
@ -406,7 +430,7 @@ ipmi_get_user_access(struct ipmi_intf * intf, unsigned char channel, unsigned ch
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
static int
|
||||
ipmi_set_user_access(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
{
|
||||
unsigned char channel, userid;
|
||||
@ -419,9 +443,9 @@ ipmi_set_user_access(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
|
||||
ipmi_intf_session_set_privlvl(intf, IPMI_SESSION_PRIV_ADMIN);
|
||||
|
||||
if (argc < 3 || !strncmp(argv[0], "help", 4)) {
|
||||
if ((argc < 3) || (strncmp(argv[0], "help", 4) == 0)) {
|
||||
printf_channel_usage();
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
channel = (unsigned char)strtol(argv[0], NULL, 0);
|
||||
@ -437,10 +461,16 @@ ipmi_set_user_access(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
rqdata[1] = userid & 0x3f;
|
||||
|
||||
rsp = intf->sendrecv(intf, &req);
|
||||
if (!rsp || rsp->ccode) {
|
||||
printf("Error:%x Get User Access Command (0x%x)\n",
|
||||
rsp ? rsp->ccode : 0, channel);
|
||||
return;
|
||||
if (rsp == NULL) {
|
||||
lprintf(LOG_ERR, "Unable to Get User Access (channel %d id %d)",
|
||||
rqdata[0], rqdata[1]);
|
||||
return -1;
|
||||
}
|
||||
if (rsp->ccode > 0) {
|
||||
lprintf(LOG_ERR, "Get User Access (channel %d id %d) failed: %s",
|
||||
rqdata[0], rqdata[1],
|
||||
val2str(rsp->ccode, completion_code_vals));
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy(&user_access, rsp->data, sizeof(struct get_user_access_rsp));
|
||||
@ -456,21 +486,21 @@ ipmi_set_user_access(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
|
||||
for (i = 2; i < argc; i ++)
|
||||
{
|
||||
if (!strncmp(argv[i], "callin=", 7)) {
|
||||
set_access.callin_callback = !strncmp (argv[i]+7, "off", 3);
|
||||
if (strncmp(argv[i], "callin=", 7) == 0) {
|
||||
set_access.callin_callback = !(strncmp (argv[i]+7, "off", 3));
|
||||
}
|
||||
else if (!strncmp(argv[i], "link=", 5)) {
|
||||
else if (strncmp(argv[i], "link=", 5) == 0) {
|
||||
set_access.link_auth = strncmp (argv[i]+5, "off", 3);
|
||||
}
|
||||
else if (!strncmp(argv[i], "ipmi=", 5)) {
|
||||
else if (strncmp(argv[i], "ipmi=", 5) == 0) {
|
||||
set_access.ipmi_messaging = strncmp (argv[i]+5, "off", 3);
|
||||
}
|
||||
else if (!strncmp(argv[i], "privilege=", 10)) {
|
||||
else if (strncmp(argv[i], "privilege=", 10) == 0) {
|
||||
set_access.privilege_limit = strtol (argv[i]+10, NULL, 0);
|
||||
}
|
||||
else {
|
||||
printf ("Invalid option: %s\n", argv [i]);
|
||||
return;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
@ -481,13 +511,19 @@ ipmi_set_user_access(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
req.msg.data_len = 4;
|
||||
|
||||
rsp = intf->sendrecv(intf, &req);
|
||||
if (!rsp || rsp->ccode) {
|
||||
printf("Error:%x Set User Access Command (0x%x)\n",
|
||||
rsp ? rsp->ccode : 0, channel);
|
||||
return;
|
||||
if (rsp == NULL) {
|
||||
lprintf(LOG_ERR, "Unable to Set User Access (channel %d id %d)",
|
||||
set_access.channel, set_access.user_id);
|
||||
return -1;
|
||||
}
|
||||
if (rsp->ccode > 0) {
|
||||
lprintf(LOG_ERR, "Set User Access (channel %d id %d) failed: %s",
|
||||
set_access.channel, set_access.user_id,
|
||||
val2str(rsp->ccode, completion_code_vals));
|
||||
return -1;
|
||||
}
|
||||
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
@ -513,11 +549,11 @@ ipmi_channel_main(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
{
|
||||
int retval = 0;
|
||||
|
||||
if (!argc || !strncmp(argv[0], "help", 4))
|
||||
if ((argc == 0) || (strncmp(argv[0], "help", 4) == 0))
|
||||
{
|
||||
printf_channel_usage();
|
||||
}
|
||||
else if (!strncmp(argv[0], "authcap", 7))
|
||||
else if (strncmp(argv[0], "authcap", 7) == 0)
|
||||
{
|
||||
if (argc != 3)
|
||||
printf_channel_usage();
|
||||
@ -526,9 +562,9 @@ ipmi_channel_main(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
(unsigned char)strtol(argv[1], NULL, 0),
|
||||
(unsigned char)strtol(argv[2], NULL, 0));
|
||||
}
|
||||
else if (!strncmp(argv[0], "getaccess", 10))
|
||||
else if (strncmp(argv[0], "getaccess", 10) == 0)
|
||||
{
|
||||
if (argc < 2 || argc > 3)
|
||||
if ((argc < 2) || (argc > 3))
|
||||
printf_channel_usage();
|
||||
else {
|
||||
unsigned char ch = (unsigned char)strtol(argv[1], NULL, 0);
|
||||
@ -538,11 +574,11 @@ ipmi_channel_main(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
retval = ipmi_get_user_access(intf, ch, id);
|
||||
}
|
||||
}
|
||||
else if (!strncmp(argv[0], "setaccess", 9))
|
||||
else if (strncmp(argv[0], "setaccess", 9) == 0)
|
||||
{
|
||||
ipmi_set_user_access(intf, argc-1, &(argv[1]));
|
||||
retval = ipmi_set_user_access(intf, argc-1, &(argv[1]));
|
||||
}
|
||||
else if (!strncmp(argv[0], "info", 4))
|
||||
else if (strncmp(argv[0], "info", 4) == 0)
|
||||
{
|
||||
if (argc > 2)
|
||||
printf_channel_usage();
|
||||
@ -557,7 +593,7 @@ ipmi_channel_main(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
{
|
||||
printf("Invalid CHANNEL command: %s\n", argv[0]);
|
||||
printf_channel_usage();
|
||||
retval = 1;
|
||||
retval = -1;
|
||||
}
|
||||
|
||||
return retval;
|
||||
|
@ -40,12 +40,14 @@
|
||||
|
||||
#include <ipmitool/helper.h>
|
||||
#include <ipmitool/ipmi.h>
|
||||
#include <ipmitool/log.h>
|
||||
#include <ipmitool/ipmi_intf.h>
|
||||
#include <ipmitool/ipmi_chassis.h>
|
||||
|
||||
extern int verbose;
|
||||
|
||||
static int ipmi_chassis_power_status(struct ipmi_intf * intf)
|
||||
static int
|
||||
ipmi_chassis_power_status(struct ipmi_intf * intf)
|
||||
{
|
||||
struct ipmi_rs * rsp;
|
||||
struct ipmi_rq req;
|
||||
@ -56,14 +58,19 @@ static int ipmi_chassis_power_status(struct ipmi_intf * intf)
|
||||
req.msg.data_len = 0;
|
||||
|
||||
rsp = intf->sendrecv(intf, &req);
|
||||
if (!rsp || rsp->ccode) {
|
||||
printf("error in Chassis Status Command\n");
|
||||
return 0;
|
||||
if (rsp == NULL) {
|
||||
lprintf(LOG_ERR, "Unable to get Chassis Power Status");
|
||||
return -1;
|
||||
}
|
||||
if (rsp->ccode > 0) {
|
||||
lprintf(LOG_ERR, "Get Chassis Power Status failed: %s",
|
||||
val2str(rsp->ccode, completion_code_vals));
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("Chassis Power is %s\n", (rsp->data[0] & 0x1) ? "on" : "off");
|
||||
|
||||
return rsp->data[0] & 0x1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct valstr ipmi_chassis_power_control_vals[] = {
|
||||
@ -76,7 +83,8 @@ static const struct valstr ipmi_chassis_power_control_vals[] = {
|
||||
{ 0x00, NULL },
|
||||
};
|
||||
|
||||
static void ipmi_chassis_power_control(struct ipmi_intf * intf, unsigned char ctl)
|
||||
static int
|
||||
ipmi_chassis_power_control(struct ipmi_intf * intf, unsigned char ctl)
|
||||
{
|
||||
struct ipmi_rs * rsp;
|
||||
struct ipmi_rq req;
|
||||
@ -90,18 +98,29 @@ static void ipmi_chassis_power_control(struct ipmi_intf * intf, unsigned char ct
|
||||
req.msg.data_len = 1;
|
||||
|
||||
rsp = intf->sendrecv(intf, &req);
|
||||
|
||||
if (!rsp || rsp->ccode) {
|
||||
printf("Unable to set Chassis Power Control to %s\n",
|
||||
val2str(ctl, ipmi_chassis_power_control_vals));
|
||||
} else {
|
||||
printf("Chassis Power Control: %s\n",
|
||||
val2str(ctl, ipmi_chassis_power_control_vals));
|
||||
intf->abort = 1;
|
||||
if (rsp == NULL) {
|
||||
lprintf(LOG_ERR, "Unable to set Chassis Power Control to %s",
|
||||
val2str(ctl, ipmi_chassis_power_control_vals));
|
||||
return -1;
|
||||
}
|
||||
if (rsp->ccode > 0) {
|
||||
lprintf(LOG_ERR, "Set Chassis Power Control to %s failed: %s",
|
||||
val2str(ctl, ipmi_chassis_power_control_vals),
|
||||
val2str(rsp->ccode, completion_code_vals));
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("Chassis Power Control: %s\n",
|
||||
val2str(ctl, ipmi_chassis_power_control_vals));
|
||||
|
||||
/* sessions often get lost when changing chassis power */
|
||||
intf->abort = 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void ipmi_chassis_identify(struct ipmi_intf * intf, char * arg)
|
||||
static int
|
||||
ipmi_chassis_identify(struct ipmi_intf * intf, char * arg)
|
||||
{
|
||||
struct ipmi_rq req;
|
||||
struct ipmi_rs * rsp;
|
||||
@ -117,17 +136,15 @@ static void ipmi_chassis_identify(struct ipmi_intf * intf, char * arg)
|
||||
req.msg.netfn = IPMI_NETFN_CHASSIS;
|
||||
req.msg.cmd = 0x4;
|
||||
|
||||
if (arg) {
|
||||
if (!strcmp(arg, "force")){
|
||||
identify_data.interval = 0;
|
||||
identify_data.force_on = 1;
|
||||
} else {
|
||||
identify_data.interval = (unsigned char)atoi(arg);
|
||||
identify_data.force_on = 0;
|
||||
}
|
||||
|
||||
if (arg != NULL) {
|
||||
if (strncmp(arg, "force", 5) == 0) {
|
||||
identify_data.interval = 0;
|
||||
identify_data.force_on = 1;
|
||||
} else {
|
||||
identify_data.interval = (unsigned char)atoi(arg);
|
||||
identify_data.force_on = 0;
|
||||
}
|
||||
req.msg.data = (unsigned char *)&identify_data;
|
||||
|
||||
/* The Force Identify On byte is optional and not
|
||||
* supported by all devices-- if force is not specified,
|
||||
* we pass only one data byte; if specified, we pass two
|
||||
@ -137,34 +154,41 @@ static void ipmi_chassis_identify(struct ipmi_intf * intf, char * arg)
|
||||
}
|
||||
|
||||
rsp = intf->sendrecv(intf, &req);
|
||||
if (!rsp || rsp->ccode) {
|
||||
printf("ERROR:%x Chassis Identify Command\n", rsp->ccode);
|
||||
if (identify_data.force_on) {
|
||||
if (rsp == NULL) {
|
||||
lprintf(LOG_ERR, "Unable to set Chassis Identify");
|
||||
return -1;
|
||||
}
|
||||
if (rsp->ccode > 0) {
|
||||
lprintf(LOG_ERR, "Set Chassis Identify failed: %s",
|
||||
val2str(rsp->ccode, completion_code_vals));
|
||||
if (identify_data.force_on != 0) {
|
||||
/* Intel SE7501WV2 F/W 1.2 returns CC 0xC7, but
|
||||
* the IPMI v1.5 spec does not standardize a CC
|
||||
* if unsupported, so we warn
|
||||
*/
|
||||
printf("Chassis may not support Force Identify On\n");
|
||||
lprintf(LOG_WARNING, "Chassis may not support Force Identify On\n");
|
||||
}
|
||||
return;
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("Chassis identify interval: ");
|
||||
if (!arg) {
|
||||
if (arg == NULL) {
|
||||
printf("default (15 seconds)\n");
|
||||
} else {
|
||||
if (identify_data.force_on) {
|
||||
if (identify_data.force_on != 0) {
|
||||
printf("indefinate\n");
|
||||
} else {
|
||||
if (identify_data.interval) {
|
||||
printf("%i seconds\n", identify_data.interval);
|
||||
} else {
|
||||
if (identify_data.interval == 0)
|
||||
printf("off\n");
|
||||
}
|
||||
else
|
||||
printf("%i seconds\n", identify_data.interval);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void ipmi_chassis_poh(struct ipmi_intf * intf)
|
||||
static int
|
||||
ipmi_chassis_poh(struct ipmi_intf * intf)
|
||||
{
|
||||
struct ipmi_rs * rsp;
|
||||
struct ipmi_rq req;
|
||||
@ -175,9 +199,15 @@ static void ipmi_chassis_poh(struct ipmi_intf * intf)
|
||||
req.msg.cmd = 0xf;
|
||||
|
||||
rsp = intf->sendrecv(intf, &req);
|
||||
|
||||
if (!rsp || rsp->ccode)
|
||||
return;
|
||||
if (rsp == NULL) {
|
||||
lprintf(LOG_ERR, "Unable to get Chassis Power-On-Hours");
|
||||
return -1;
|
||||
}
|
||||
if (rsp->ccode > 0) {
|
||||
lprintf(LOG_ERR, "Get Chassis Power-On-Hours failed: %s",
|
||||
val2str(rsp->ccode, completion_code_vals));
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy(&count, rsp->data+1, 4);
|
||||
|
||||
@ -185,7 +215,8 @@ static void ipmi_chassis_poh(struct ipmi_intf * intf)
|
||||
(long)count, (long)(count / 24), (long)(count % 24));
|
||||
}
|
||||
|
||||
static void ipmi_chassis_restart_cause(struct ipmi_intf * intf)
|
||||
static int
|
||||
ipmi_chassis_restart_cause(struct ipmi_intf * intf)
|
||||
{
|
||||
struct ipmi_rs * rsp;
|
||||
struct ipmi_rq req;
|
||||
@ -195,9 +226,15 @@ static void ipmi_chassis_restart_cause(struct ipmi_intf * intf)
|
||||
req.msg.cmd = 0x7;
|
||||
|
||||
rsp = intf->sendrecv(intf, &req);
|
||||
|
||||
if (!rsp || rsp->ccode)
|
||||
return;
|
||||
if (rsp == NULL) {
|
||||
lprintf(LOG_ERR, "Unable to get Chassis Restart Cause");
|
||||
return -1;
|
||||
}
|
||||
if (rsp->ccode > 0) {
|
||||
lprintf(LOG_ERR, "Get Chassis Restart Cause failed: %s",
|
||||
val2str(rsp->ccode, completion_code_vals));
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("System restart cause: ");
|
||||
|
||||
@ -233,11 +270,14 @@ static void ipmi_chassis_restart_cause(struct ipmi_intf * intf)
|
||||
printf("power-cycle via PEF\n");
|
||||
break;
|
||||
default:
|
||||
printf("error!\n");
|
||||
printf("invalid\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void ipmi_chassis_status(struct ipmi_intf * intf)
|
||||
static int
|
||||
ipmi_chassis_status(struct ipmi_intf * intf)
|
||||
{
|
||||
struct ipmi_rs * rsp;
|
||||
struct ipmi_rq req;
|
||||
@ -247,14 +287,14 @@ static void ipmi_chassis_status(struct ipmi_intf * intf)
|
||||
req.msg.cmd = 0x1;
|
||||
|
||||
rsp = intf->sendrecv(intf, &req);
|
||||
if (!rsp) {
|
||||
printf("Error sending Chassis Status command\n");
|
||||
return;
|
||||
if (rsp == NULL) {
|
||||
lprintf(LOG_ERR, "Error sending Chassis Status command");
|
||||
return -1;
|
||||
}
|
||||
if (rsp->ccode > 0) {
|
||||
printf("Error sending Chassis Status command: %s\n",
|
||||
val2str(rsp->ccode, completion_code_vals));
|
||||
return;
|
||||
lprintf(LOG_ERR, "Error sending Chassis Status command: %s",
|
||||
val2str(rsp->ccode, completion_code_vals));
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* byte 1 */
|
||||
@ -299,25 +339,27 @@ static void ipmi_chassis_status(struct ipmi_intf * intf)
|
||||
printf("Drive Fault : %s\n", (rsp->data[2] & 0x4) ? "true" : "false");
|
||||
printf("Cooling/Fan Fault : %s\n", (rsp->data[2] & 0x8) ? "true" : "false");
|
||||
|
||||
if (rsp->data_len > 3)
|
||||
{
|
||||
/* optional byte 4 */
|
||||
if (rsp->data[3] == 0) {
|
||||
printf("Front Panel Control : none\n");
|
||||
} else {
|
||||
printf("Sleep Button Disable : %s\n", (rsp->data[3] & 0x80) ? "allowed" : "not allowed");
|
||||
printf("Diag Button Disable : %s\n", (rsp->data[3] & 0x40) ? "allowed" : "not allowed");
|
||||
printf("Reset Button Disable : %s\n", (rsp->data[3] & 0x20) ? "allowed" : "not allowed");
|
||||
printf("Power Button Disable : %s\n", (rsp->data[3] & 0x10) ? "allowed" : "not allowed");
|
||||
printf("Sleep Button Disabled: %s\n", (rsp->data[3] & 0x80) ? "true" : "false");
|
||||
printf("Diag Button Disabled : %s\n", (rsp->data[3] & 0x40) ? "true" : "false");
|
||||
printf("Reset Button Disabled: %s\n", (rsp->data[3] & 0x20) ? "true" : "false");
|
||||
printf("Power Button Disabled: %s\n", (rsp->data[3] & 0x10) ? "true" : "false");
|
||||
}
|
||||
if (rsp->data_len > 3) {
|
||||
/* optional byte 4 */
|
||||
if (rsp->data[3] == 0) {
|
||||
printf("Front Panel Control : none\n");
|
||||
} else {
|
||||
printf("Sleep Button Disable : %s\n", (rsp->data[3] & 0x80) ? "allowed" : "not allowed");
|
||||
printf("Diag Button Disable : %s\n", (rsp->data[3] & 0x40) ? "allowed" : "not allowed");
|
||||
printf("Reset Button Disable : %s\n", (rsp->data[3] & 0x20) ? "allowed" : "not allowed");
|
||||
printf("Power Button Disable : %s\n", (rsp->data[3] & 0x10) ? "allowed" : "not allowed");
|
||||
printf("Sleep Button Disabled: %s\n", (rsp->data[3] & 0x80) ? "true" : "false");
|
||||
printf("Diag Button Disabled : %s\n", (rsp->data[3] & 0x40) ? "true" : "false");
|
||||
printf("Reset Button Disabled: %s\n", (rsp->data[3] & 0x20) ? "true" : "false");
|
||||
printf("Power Button Disabled: %s\n", (rsp->data[3] & 0x10) ? "true" : "false");
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void ipmi_chassis_set_bootparam(struct ipmi_intf * intf, unsigned char param, unsigned char * data, int len)
|
||||
static int
|
||||
ipmi_chassis_set_bootparam(struct ipmi_intf * intf, unsigned char param, unsigned char * data, int len)
|
||||
{
|
||||
struct ipmi_rs * rsp;
|
||||
struct ipmi_rq req;
|
||||
@ -336,21 +378,28 @@ static void ipmi_chassis_set_bootparam(struct ipmi_intf * intf, unsigned char pa
|
||||
req.msg.data_len = len + 1;
|
||||
|
||||
rsp = intf->sendrecv(intf, &req);
|
||||
if (!rsp || rsp->ccode) {
|
||||
printf("Error setting Chassis Boot Parameter %d\n", param);
|
||||
return;
|
||||
if (rsp == NULL) {
|
||||
lprintf(LOG_ERR, "Error setting Chassis Boot Parameter %d", param);
|
||||
return -1;
|
||||
}
|
||||
if (rsp->ccode > 0) {
|
||||
lprintf(LOG_ERR, "Set Chassis Boot Parameter %d failed: %s",
|
||||
param, val2str(rsp->ccode, completion_code_vals));
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("Chassis Set Boot Param %d to %s\n", param, data);
|
||||
printf("Chassis Set Boot Parameter %d to %s\n", param, data);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void ipmi_chassis_get_bootparam(struct ipmi_intf * intf, char * arg)
|
||||
static int
|
||||
ipmi_chassis_get_bootparam(struct ipmi_intf * intf, char * arg)
|
||||
{
|
||||
struct ipmi_rs * rsp;
|
||||
struct ipmi_rq req;
|
||||
unsigned char msg_data[3];
|
||||
|
||||
if (!arg)
|
||||
if (arg == NULL)
|
||||
return;
|
||||
|
||||
memset(msg_data, 0, 3);
|
||||
@ -366,8 +415,15 @@ static void ipmi_chassis_get_bootparam(struct ipmi_intf * intf, char * arg)
|
||||
req.msg.data_len = 3;
|
||||
|
||||
rsp = intf->sendrecv(intf, &req);
|
||||
if (!rsp || rsp->ccode)
|
||||
return;
|
||||
if (rsp == NULL) {
|
||||
lprintf(LOG_ERR, "Error Getting Chassis Boot Parameter %s", arg);
|
||||
return -1;
|
||||
}
|
||||
if (rsp->ccode > 0) {
|
||||
lprintf(LOG_ERR, "Get Chassis Boot Parameter %s failed: %s",
|
||||
arg, val2str(rsp->ccode, completion_code_vals));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (verbose > 2)
|
||||
printbuf(rsp->data, rsp->data_len, "Boot Option");
|
||||
@ -378,45 +434,47 @@ static void ipmi_chassis_get_bootparam(struct ipmi_intf * intf, char * arg)
|
||||
printf("Boot parameter data: %s\n", buf2str(rsp->data+2, rsp->data_len - 2));
|
||||
}
|
||||
|
||||
static void ipmi_chassis_set_bootflag(struct ipmi_intf * intf, char * arg)
|
||||
static int
|
||||
ipmi_chassis_set_bootflag(struct ipmi_intf * intf, char * arg)
|
||||
{
|
||||
unsigned char flags[5];
|
||||
int rc = 0;
|
||||
|
||||
ipmi_intf_session_set_privlvl(intf, IPMI_SESSION_PRIV_ADMIN);
|
||||
|
||||
if (!arg) {
|
||||
printf("Error: no bootflag argument supplied\n");
|
||||
return;
|
||||
if (arg == NULL) {
|
||||
lprintf(LOG_ERR, "No bootflag argument supplied");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!strncmp(arg, "force_pxe", 9)) {
|
||||
flags[1] = 0x04; // 00000100
|
||||
}
|
||||
else if (!strncmp(arg, "force_disk", 10)) {
|
||||
flags[1] = 0x08; // 00001000
|
||||
}
|
||||
else if (!strncmp(arg, "force_diag", 10)) {
|
||||
flags[1] = 0x10; // 00010000
|
||||
}
|
||||
else if (!strncmp(arg, "force_cdrom", 11)) {
|
||||
flags[1] = 0x14; // 00010100
|
||||
}
|
||||
else if (!strncmp(arg, "force_floppy", 12)) {
|
||||
flags[1] = 0x3c; // 00111100
|
||||
}
|
||||
if (strncmp(arg, "force_pxe", 9) == 0)
|
||||
flags[1] = 0x04;
|
||||
else if (strncmp(arg, "force_disk", 10) == 0)
|
||||
flags[1] = 0x08;
|
||||
else if (strncmp(arg, "force_diag", 10) == 0)
|
||||
flags[1] = 0x10;
|
||||
else if (strncmp(arg, "force_cdrom", 11) == 0)
|
||||
flags[1] = 0x14;
|
||||
else if (strncmp(arg, "force_floppy", 12) == 0)
|
||||
flags[1] = 0x3c;
|
||||
else {
|
||||
printf("Invalid bootflag: %s\n", arg);
|
||||
return;
|
||||
lprintf(LOG_ERR, "Invalid bootflag: %s", arg);
|
||||
return -1;
|
||||
}
|
||||
|
||||
flags[0] = 0x80; /* set flag valid bit */
|
||||
ipmi_chassis_set_bootparam(intf, 5, flags, 5);
|
||||
rc = ipmi_chassis_set_bootparam(intf, 5, flags, 5);
|
||||
|
||||
flags[0] = 0x08; /* don't automatically clear boot flag valid bit in 60 seconds */
|
||||
ipmi_chassis_set_bootparam(intf, 3, flags, 1);
|
||||
if (rc < 0) {
|
||||
flags[0] = 0x08; /* don't automatically clear boot flag valid bit in 60 seconds */
|
||||
rc = ipmi_chassis_set_bootparam(intf, 3, flags, 1);
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
static void ipmi_chassis_power_policy(struct ipmi_intf * intf, unsigned char policy)
|
||||
static int
|
||||
ipmi_chassis_power_policy(struct ipmi_intf * intf, unsigned char policy)
|
||||
{
|
||||
struct ipmi_rs * rsp;
|
||||
struct ipmi_rq req;
|
||||
@ -430,14 +488,15 @@ static void ipmi_chassis_power_policy(struct ipmi_intf * intf, unsigned char pol
|
||||
req.msg.data_len = 1;
|
||||
|
||||
rsp = intf->sendrecv(intf, &req);
|
||||
if (!rsp)
|
||||
return;
|
||||
if (rsp->ccode > 0) {
|
||||
printf("BMC Power Restore Policy command failed: %s\n",
|
||||
val2str(rsp->ccode, completion_code_vals));
|
||||
return;
|
||||
if (rsp == NULL) {
|
||||
lprintf(LOG_ERR, "Error in Power Restore Policy command");
|
||||
return -1;
|
||||
}
|
||||
if (rsp->ccode > 0) {
|
||||
lprintf(LOG_ERR, "Power Restore Policy command failed: %s",
|
||||
val2str(rsp->ccode, completion_code_vals));
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
if (policy == IPMI_CHASSIS_POLICY_NO_CHANGE) {
|
||||
printf("Supported chassis power policy: ");
|
||||
@ -465,121 +524,119 @@ static void ipmi_chassis_power_policy(struct ipmi_intf * intf, unsigned char pol
|
||||
printf("unknown\n");
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ipmi_chassis_main(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
int
|
||||
ipmi_chassis_main(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
{
|
||||
if (!argc || !strncmp(argv[0], "help", 4)) {
|
||||
printf("Chassis Commands: status, power, identify, policy, restart_cause, poh\n");
|
||||
return 0;
|
||||
int rc = 0;
|
||||
|
||||
if ((argc == 0) || (strncmp(argv[0], "help", 4) == 0)) {
|
||||
lprintf(LOG_NOTICE, "Chassis Commands: status, power, identify, policy, restart_cause, poh");
|
||||
}
|
||||
else if (!strncmp(argv[0], "status", 6)) {
|
||||
ipmi_chassis_status(intf);
|
||||
else if (strncmp(argv[0], "status", 6) == 0) {
|
||||
rc = ipmi_chassis_status(intf);
|
||||
}
|
||||
else if (!strncmp(argv[0], "power", 5)) {
|
||||
else if (strncmp(argv[0], "power", 5) == 0) {
|
||||
unsigned char ctl = 0;
|
||||
|
||||
if (argc < 2 || !strncmp(argv[1], "help", 4)) {
|
||||
printf("chassis power Commands: status, on, off, cycle, reset, diag, soft\n");
|
||||
if ((argc < 2) || (strncmp(argv[1], "help", 4) == 0)) {
|
||||
lprintf(LOG_NOTICE, "chassis power Commands: status, on, off, cycle, reset, diag, soft");
|
||||
return 0;
|
||||
}
|
||||
if (!strncmp(argv[1], "status", 6)) {
|
||||
ipmi_chassis_power_status(intf);
|
||||
return 0;
|
||||
if (strncmp(argv[1], "status", 6) == 0) {
|
||||
rc = ipmi_chassis_power_status(intf);
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (!strncmp(argv[1], "up", 2) || !strncmp(argv[1], "on", 2))
|
||||
if ((strncmp(argv[1], "up", 2) == 0) || (strncmp(argv[1], "on", 2) == 0))
|
||||
ctl = IPMI_CHASSIS_CTL_POWER_UP;
|
||||
else if (!strncmp(argv[1], "down", 4) || !strncmp(argv[1], "off", 3))
|
||||
else if ((strncmp(argv[1], "down", 4) == 0) || (strncmp(argv[1], "off", 3) == 0))
|
||||
ctl = IPMI_CHASSIS_CTL_POWER_DOWN;
|
||||
else if (!strncmp(argv[1], "cycle", 5))
|
||||
else if (strncmp(argv[1], "cycle", 5) == 0)
|
||||
ctl = IPMI_CHASSIS_CTL_POWER_CYCLE;
|
||||
else if (!strncmp(argv[1], "reset", 5))
|
||||
else if (strncmp(argv[1], "reset", 5) == 0)
|
||||
ctl = IPMI_CHASSIS_CTL_HARD_RESET;
|
||||
else if (!strncmp(argv[1], "diag", 5))
|
||||
else if (strncmp(argv[1], "diag", 4) == 0)
|
||||
ctl = IPMI_CHASSIS_CTL_PULSE_DIAG;
|
||||
else if (!strncmp (argv[1], "acpi", 4) || !strncmp(argv[1], "soft", 4))
|
||||
else if ((strncmp(argv[1], "acpi", 4) == 0) || (strncmp(argv[1], "soft", 4) == 0))
|
||||
ctl = IPMI_CHASSIS_CTL_ACPI_SOFT;
|
||||
else {
|
||||
printf("Invalid chassis power command: %s\n", argv[1]);
|
||||
lprintf(LOG_ERR, "Invalid chassis power command: %s", argv[1]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ipmi_chassis_power_control(intf, ctl);
|
||||
rc = ipmi_chassis_power_control(intf, ctl);
|
||||
}
|
||||
else if (!strncmp(argv[0], "identify", 8)) {
|
||||
else if (strncmp(argv[0], "identify", 8) == 0) {
|
||||
if (argc < 2) {
|
||||
ipmi_chassis_identify(intf, NULL);
|
||||
rc = ipmi_chassis_identify(intf, NULL);
|
||||
}
|
||||
else if (!strncmp(argv[1], "help", 4)) {
|
||||
printf("chassis identify <interval>\n");
|
||||
printf(" default is 15 seconds\n");
|
||||
printf(" 0 to turn off\n");
|
||||
printf(" force to turn on indefinitely\n");
|
||||
else if (strncmp(argv[1], "help", 4) == 0) {
|
||||
lprintf(LOG_NOTICE, "chassis identify <interval>");
|
||||
lprintf(LOG_NOTICE, " default is 15 seconds");
|
||||
lprintf(LOG_NOTICE, " 0 to turn off");
|
||||
lprintf(LOG_NOTICE, " force to turn on indefinitely");
|
||||
} else {
|
||||
ipmi_chassis_identify(intf, argv[1]);
|
||||
rc = ipmi_chassis_identify(intf, argv[1]);
|
||||
}
|
||||
}
|
||||
else if (!strncmp(argv[0], "poh", 3)) {
|
||||
ipmi_chassis_poh(intf);
|
||||
else if (strncmp(argv[0], "poh", 3) == 0) {
|
||||
rc = ipmi_chassis_poh(intf);
|
||||
}
|
||||
else if (!strncmp(argv[0], "restart_cause", 13)) {
|
||||
ipmi_chassis_restart_cause(intf);
|
||||
else if (strncmp(argv[0], "restart_cause", 13) == 0) {
|
||||
rc = ipmi_chassis_restart_cause(intf);
|
||||
}
|
||||
else if (!strncmp(argv[0], "policy", 4)) {
|
||||
if (argc < 2 || !strncmp(argv[1], "help", 4)) {
|
||||
printf("chassis policy <state>\n");
|
||||
printf(" list : return supported policies\n");
|
||||
printf(" always-on : turn on when power is restored\n");
|
||||
printf(" previous : return to previous state when power is restored\n");
|
||||
printf(" always-off : stay off after power is restored\n");
|
||||
else if (strncmp(argv[0], "policy", 4) == 0) {
|
||||
if ((argc < 2) || (strncmp(argv[1], "help", 4) == 0)) {
|
||||
lprintf(LOG_NOTICE, "chassis policy <state>");
|
||||
lprintf(LOG_NOTICE, " list : return supported policies");
|
||||
lprintf(LOG_NOTICE, " always-on : turn on when power is restored");
|
||||
lprintf(LOG_NOTICE, " previous : return to previous state when power is restored");
|
||||
lprintf(LOG_NOTICE, " always-off : stay off after power is restored");
|
||||
} else {
|
||||
unsigned char ctl;
|
||||
|
||||
if (!strncmp(argv[1], "list", 4))
|
||||
if (strncmp(argv[1], "list", 4) == 0)
|
||||
ctl = IPMI_CHASSIS_POLICY_NO_CHANGE;
|
||||
else if (!strncmp(argv[1], "always-on", 9))
|
||||
else if (strncmp(argv[1], "always-on", 9) == 0)
|
||||
ctl = IPMI_CHASSIS_POLICY_ALWAYS_ON;
|
||||
else if (!strncmp(argv[1], "previous", 8))
|
||||
else if (strncmp(argv[1], "previous", 8) == 0)
|
||||
ctl = IPMI_CHASSIS_POLICY_PREVIOUS;
|
||||
else if (!strncmp(argv[1], "always-off", 10))
|
||||
else if (strncmp(argv[1], "always-off", 10) == 0)
|
||||
ctl = IPMI_CHASSIS_POLICY_ALWAYS_OFF;
|
||||
else {
|
||||
printf("invalid chassis policy: %s\n", argv[1]);
|
||||
lprintf(LOG_ERR, "Invalid chassis policy: %s", argv[1]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ipmi_chassis_power_policy(intf, ctl);
|
||||
rc = ipmi_chassis_power_policy(intf, ctl);
|
||||
}
|
||||
}
|
||||
else if (!strncmp(argv[0], "bootparam", 7)) {
|
||||
if (argc < 3 || !strncmp(argv[1], "help", 4)) {
|
||||
printf("bootparam get|set <option> [value ...]\n");
|
||||
else if (strncmp(argv[0], "bootparam", 7) == 0) {
|
||||
if ((argc < 3) || (strncmp(argv[1], "help", 4) == 0)) {
|
||||
lprintf(LOG_NOTICE, "bootparam get|set <option> [value ...]");
|
||||
}
|
||||
else {
|
||||
if (!strncmp(argv[1], "get", 3)) {
|
||||
ipmi_chassis_get_bootparam(intf, argv[2]);
|
||||
if (strncmp(argv[1], "get", 3) == 0) {
|
||||
rc = ipmi_chassis_get_bootparam(intf, argv[2]);
|
||||
}
|
||||
else if (!strncmp(argv[1], "set", 3)) {
|
||||
else if (strncmp(argv[1], "set", 3) == 0) {
|
||||
if (argc < 4) {
|
||||
printf("bootparam set <option> [value ...]\n");
|
||||
lprintf(LOG_NOTICE, "bootparam set <option> [value ...]");
|
||||
} else {
|
||||
if (!strncmp(argv[2], "bootflag", 8)) {
|
||||
ipmi_chassis_set_bootflag(intf, argv[3]);
|
||||
}
|
||||
else {
|
||||
printf("bootparam set <option> [value ...]\n");
|
||||
}
|
||||
if (strncmp(argv[2], "bootflag", 8) == 0)
|
||||
rc = ipmi_chassis_set_bootflag(intf, argv[3]);
|
||||
else
|
||||
lprintf(LOG_NOTICE, "bootparam set <option> [value ...]");
|
||||
}
|
||||
}
|
||||
else {
|
||||
printf("bootparam get|set <option> [value]\n");
|
||||
}
|
||||
else
|
||||
lprintf(LOG_NOTICE, "bootparam get|set <option> [value ...]");
|
||||
}
|
||||
}
|
||||
else {
|
||||
printf("Invalid Chassis command: %s\n", argv[0]);
|
||||
lprintf(LOG_ERR, "Invalid Chassis command: %s", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
@ -48,6 +48,7 @@
|
||||
#include <ipmitool/ipmi.h>
|
||||
#include <ipmitool/ipmi_intf.h>
|
||||
#include <ipmitool/helper.h>
|
||||
#include <ipmitool/log.h>
|
||||
#include <ipmitool/ipmi_sel.h>
|
||||
#include <ipmitool/ipmi_strings.h>
|
||||
#include <ipmitool/ipmi_channel.h>
|
||||
@ -234,7 +235,7 @@ ipmi_event_fromfile(struct ipmi_intf * intf, char * file)
|
||||
tok = strtok(NULL, " ");
|
||||
}
|
||||
if (i < 7) {
|
||||
printf("Invalid Event: %s\n",
|
||||
lprintf(LOG_ERR, "Invalid Event: %s",
|
||||
buf2str(rqdata, sizeof(rqdata)));
|
||||
continue;
|
||||
}
|
||||
@ -256,11 +257,11 @@ ipmi_event_fromfile(struct ipmi_intf * intf, char * file)
|
||||
ipmi_sel_print_std_entry(&sel_event);
|
||||
|
||||
rsp = intf->sendrecv(intf, &req);
|
||||
if (!rsp)
|
||||
printf("Error in Platform Event Message Command\n");
|
||||
else if (rsp->ccode)
|
||||
printf("Error in Platform Event Message Command: %s\n",
|
||||
val2str(rsp->ccode, completion_code_vals));
|
||||
if (rsp == NULL)
|
||||
lprintf(LOG_ERR, "Platform Event Message command failed");
|
||||
else if (rsp->ccode > 0)
|
||||
lprintf(LOG_ERR, "Platform Event Message command failed: %s",
|
||||
val2str(rsp->ccode, completion_code_vals));
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -39,6 +39,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include <ipmitool/helper.h>
|
||||
#include <ipmitool/log.h>
|
||||
#include <ipmitool/ipmi.h>
|
||||
#include <ipmitool/ipmi_intf.h>
|
||||
#include <ipmitool/ipmi_mc.h>
|
||||
@ -46,7 +47,18 @@
|
||||
|
||||
extern int verbose;
|
||||
|
||||
static int ipmi_mc_reset(struct ipmi_intf * intf, int cmd)
|
||||
/* ipmi_mc_reset - attempt to reset an MC
|
||||
*
|
||||
* @intf: ipmi interface
|
||||
* @cmd: reset command to send
|
||||
* BMC_WARM_RESET or
|
||||
* BMC_COLD_RESET
|
||||
*
|
||||
* returns 0 on success
|
||||
* returns -1 on error
|
||||
*/
|
||||
static int
|
||||
ipmi_mc_reset(struct ipmi_intf * intf, int cmd)
|
||||
{
|
||||
struct ipmi_rs * rsp;
|
||||
struct ipmi_rq req;
|
||||
@ -57,12 +69,13 @@ static int ipmi_mc_reset(struct ipmi_intf * intf, int cmd)
|
||||
req.msg.data_len = 0;
|
||||
|
||||
rsp = intf->sendrecv(intf, &req);
|
||||
if (!rsp) {
|
||||
printf("Error in MC Reset Command\n");
|
||||
if (rsp == NULL) {
|
||||
lprintf(LOG_ERR, "Reset command failed");
|
||||
return -1;
|
||||
}
|
||||
if (rsp->ccode) {
|
||||
printf("MC Reset Command returned %x\n", rsp->ccode);
|
||||
if (rsp->ccode > 0) {
|
||||
lprintf(LOG_ERR, "Reset command failed: %s",
|
||||
val2str(rsp->ccode, completion_code_vals));
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -95,71 +108,71 @@ struct bitfield_data {
|
||||
const char * name;
|
||||
const char * desc;
|
||||
uint32_t mask;
|
||||
int write;
|
||||
};
|
||||
|
||||
struct bitfield_data bmc_enables_bf[] = {
|
||||
struct bitfield_data mc_enables_bf[] = {
|
||||
{
|
||||
name: "recv_msg_intr",
|
||||
desc: "Receive Message Queue Interrupt",
|
||||
mask: 1<<0,
|
||||
write: 1,
|
||||
},
|
||||
{
|
||||
name: "event_msg_intr",
|
||||
desc: "Event Message Buffer Full Interrupt",
|
||||
mask: 1<<1,
|
||||
write: 1,
|
||||
},
|
||||
{
|
||||
name: "event_msg",
|
||||
desc: "Event Message Buffer",
|
||||
mask: 1<<2,
|
||||
write: 1,
|
||||
},
|
||||
{
|
||||
name: "system_event_log",
|
||||
desc: "System Event Logging",
|
||||
mask: 1<<3,
|
||||
write: 1,
|
||||
},
|
||||
{
|
||||
name: "oem0",
|
||||
desc: "OEM 0",
|
||||
mask: 1<<5,
|
||||
write: 1,
|
||||
},
|
||||
{
|
||||
name: "oem1",
|
||||
desc: "OEM 1",
|
||||
mask: 1<<6,
|
||||
write: 1,
|
||||
},
|
||||
{
|
||||
name: "oem2",
|
||||
desc: "OEM 2",
|
||||
mask: 1<<7,
|
||||
write: 1,
|
||||
},
|
||||
{ NULL },
|
||||
};
|
||||
|
||||
static void printf_mc_usage()
|
||||
static void
|
||||
printf_mc_usage()
|
||||
{
|
||||
struct bitfield_data * bf;
|
||||
printf("BMC Commands:\n");
|
||||
printf("MC Commands:\n");
|
||||
printf(" reset <warm|cold>\n");
|
||||
printf(" info\n");
|
||||
printf(" getenables\n");
|
||||
printf(" setenables <option=on|off> ...\n");
|
||||
for (bf = bmc_enables_bf; bf->name; bf++) {
|
||||
if (!bf->write)
|
||||
continue;
|
||||
|
||||
for (bf = mc_enables_bf; bf->name != NULL; bf++) {
|
||||
printf(" %-20s %s\n", bf->name, bf->desc);
|
||||
}
|
||||
}
|
||||
|
||||
static int ipmi_bmc_get_enables(struct ipmi_intf * intf)
|
||||
/* ipmi_mc_get_enables - print out MC enables
|
||||
*
|
||||
* @intf: ipmi inteface
|
||||
*
|
||||
* returns 0 on success
|
||||
* returns -1 on error
|
||||
*/
|
||||
static int
|
||||
ipmi_mc_get_enables(struct ipmi_intf * intf)
|
||||
{
|
||||
struct ipmi_rs * rsp;
|
||||
struct ipmi_rq req;
|
||||
@ -170,17 +183,17 @@ static int ipmi_bmc_get_enables(struct ipmi_intf * intf)
|
||||
req.msg.cmd = BMC_GET_GLOBAL_ENABLES;
|
||||
|
||||
rsp = intf->sendrecv(intf, &req);
|
||||
if (!rsp) {
|
||||
printf("Error in BMC Get Global Enables Command\n");
|
||||
if (rsp == NULL) {
|
||||
lprintf(LOG_ERR, "Get Global Enables command failed");
|
||||
return -1;
|
||||
}
|
||||
if (rsp->ccode) {
|
||||
printf("BMC Get Global Enables command failed: %s\n",
|
||||
if (rsp->ccode > 0) {
|
||||
lprintf(LOG_ERR, "Get Global Enables command failed: %s",
|
||||
val2str(rsp->ccode, completion_code_vals));
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (bf = bmc_enables_bf; bf->name; bf++) {
|
||||
for (bf = mc_enables_bf; bf->name != NULL; bf++) {
|
||||
printf("%-40s : %sabled\n", bf->desc,
|
||||
rsp->data[0] & bf->mask ? "en" : "dis");
|
||||
}
|
||||
@ -188,7 +201,17 @@ static int ipmi_bmc_get_enables(struct ipmi_intf * intf)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ipmi_bmc_set_enables(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
/* ipmi_mc_set_enables - set MC enable flags
|
||||
*
|
||||
* @intf: ipmi inteface
|
||||
* @argc: argument count
|
||||
* @argv: argument list
|
||||
*
|
||||
* returns 0 on success
|
||||
* returns -1 on error
|
||||
*/
|
||||
static int
|
||||
ipmi_mc_set_enables(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
{
|
||||
struct ipmi_rs * rsp;
|
||||
struct ipmi_rq req;
|
||||
@ -198,7 +221,7 @@ static int ipmi_bmc_set_enables(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
|
||||
ipmi_intf_session_set_privlvl(intf, IPMI_SESSION_PRIV_ADMIN);
|
||||
|
||||
if (argc < 1 || !strncmp(argv[0], "help", 4)) {
|
||||
if (argc < 1 || strncmp(argv[0], "help", 4) == 0) {
|
||||
printf_mc_usage();
|
||||
return 0;
|
||||
}
|
||||
@ -208,12 +231,12 @@ static int ipmi_bmc_set_enables(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
req.msg.cmd = BMC_GET_GLOBAL_ENABLES;
|
||||
|
||||
rsp = intf->sendrecv(intf, &req);
|
||||
if (!rsp) {
|
||||
printf("Error in BMC Get Global Enables Command\n");
|
||||
if (rsp == NULL) {
|
||||
lprintf(LOG_ERR, "Get Global Enables command failed");
|
||||
return -1;
|
||||
}
|
||||
if (rsp->ccode) {
|
||||
printf("BMC Get Global Enables command failed: %s\n",
|
||||
if (rsp->ccode > 0) {
|
||||
lprintf(LOG_ERR, "Get Global Enables command failed: %s",
|
||||
val2str(rsp->ccode, completion_code_vals));
|
||||
return -1;
|
||||
}
|
||||
@ -221,27 +244,27 @@ static int ipmi_bmc_set_enables(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
en = rsp->data[0];
|
||||
|
||||
for (i = 0; i < argc; i++) {
|
||||
for (bf = bmc_enables_bf; bf->name; bf++) {
|
||||
for (bf = mc_enables_bf; bf->name != NULL; bf++) {
|
||||
int nl = strlen(bf->name);
|
||||
if (!strncmp(argv[i], bf->name, nl)) {
|
||||
if (!strncmp(argv[i]+nl+1, "off", 3)) {
|
||||
printf("Disabling %s\n", bf->desc);
|
||||
en &= ~bf->mask;
|
||||
}
|
||||
else if (!strncmp(argv[i]+nl+1, "on", 2)) {
|
||||
printf("Enabling %s\n", bf->desc);
|
||||
en |= bf->mask;
|
||||
}
|
||||
else {
|
||||
printf("Unrecognized option: %s\n", argv[i]);
|
||||
}
|
||||
if (strncmp(argv[i], bf->name, nl) != 0)
|
||||
continue;
|
||||
if (strncmp(argv[i]+nl+1, "off", 3) == 0) {
|
||||
printf("Disabling %s\n", bf->desc);
|
||||
en &= ~bf->mask;
|
||||
}
|
||||
else if (strncmp(argv[i]+nl+1, "on", 2) == 0) {
|
||||
printf("Enabling %s\n", bf->desc);
|
||||
en |= bf->mask;
|
||||
}
|
||||
else {
|
||||
lprintf(LOG_ERR, "Unrecognized option: %s", argv[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (en == rsp->data[0]) {
|
||||
printf("\nNothing to change...\n");
|
||||
ipmi_bmc_get_enables(intf);
|
||||
ipmi_mc_get_enables(intf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -250,15 +273,18 @@ static int ipmi_bmc_set_enables(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
req.msg.data_len = 1;
|
||||
|
||||
rsp = intf->sendrecv(intf, &req);
|
||||
if (!rsp)
|
||||
printf("Error in BMC Set Global Enables Command\n");
|
||||
else if (rsp->ccode)
|
||||
printf("BMC Set Global Enables command failed: %s\n",
|
||||
val2str(rsp->ccode, completion_code_vals));
|
||||
else {
|
||||
printf("\nVerifying...\n");
|
||||
ipmi_bmc_get_enables(intf);
|
||||
if (rsp == NULL) {
|
||||
lprintf(LOG_ERR, "Set Global Enables command failed");
|
||||
return -1;
|
||||
}
|
||||
else if (rsp->ccode > 0) {
|
||||
lprintf(LOG_ERR, "Set Global Enables command failed: %s",
|
||||
val2str(rsp->ccode, completion_code_vals));
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("\nVerifying...\n");
|
||||
ipmi_mc_get_enables(intf);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -275,7 +301,15 @@ const char *ipm_dev_adtl_dev_support[8] = {
|
||||
"Chassis Device" /* bit 7 */
|
||||
};
|
||||
|
||||
static int ipmi_mc_get_deviceid(struct ipmi_intf * intf)
|
||||
/* ipmi_mc_get_deviceid - print information about this MC
|
||||
*
|
||||
* @intf: ipmi interface
|
||||
*
|
||||
* returns 0 on success
|
||||
* returns -1 on error
|
||||
*/
|
||||
static int
|
||||
ipmi_mc_get_deviceid(struct ipmi_intf * intf)
|
||||
{
|
||||
struct ipmi_rs * rsp;
|
||||
struct ipmi_rq req;
|
||||
@ -288,12 +322,13 @@ static int ipmi_mc_get_deviceid(struct ipmi_intf * intf)
|
||||
req.msg.data_len = 0;
|
||||
|
||||
rsp = intf->sendrecv(intf, &req);
|
||||
if (!rsp) {
|
||||
printf("Error in MC Get Device ID Command\n");
|
||||
if (rsp == NULL) {
|
||||
lprintf(LOG_ERR, "Get Device ID command failed");
|
||||
return -1;
|
||||
}
|
||||
if (rsp->ccode) {
|
||||
printf("MC Get Device ID returned %x\n", rsp->ccode);
|
||||
if (rsp->ccode > 0) {
|
||||
lprintf(LOG_ERR, "Get Device ID command failed: %s",
|
||||
val2str(rsp->ccode, completion_code_vals));
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -335,34 +370,46 @@ static int ipmi_mc_get_deviceid(struct ipmi_intf * intf)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ipmi_mc_main(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
/* ipmi_mc_main - top-level handler for MC functions
|
||||
*
|
||||
* @intf: ipmi interface
|
||||
* @argc: number of arguments
|
||||
* @argv: argument list
|
||||
*
|
||||
* returns 0 on success
|
||||
* returns -1 on error
|
||||
*/
|
||||
int
|
||||
ipmi_mc_main(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
{
|
||||
if (!argc || !strncmp(argv[0], "help", 4)) {
|
||||
int rc = 0;
|
||||
|
||||
if (argc < 1 || strncmp(argv[0], "help", 4) == 0) {
|
||||
printf_mc_usage();
|
||||
return 0;
|
||||
}
|
||||
else if (!strncmp(argv[0], "reset", 5)) {
|
||||
if (argc < 2 || !strncmp(argv[1], "help", 4)) {
|
||||
printf("reset commands: warm, cold\n");
|
||||
else if (strncmp(argv[0], "reset", 5) == 0) {
|
||||
if (argc < 2 || strncmp(argv[1], "help", 4) == 0) {
|
||||
lprintf(LOG_ERR, "reset commands: warm, cold");
|
||||
}
|
||||
else if (!strncmp(argv[1], "cold", 4)) {
|
||||
ipmi_mc_reset(intf, BMC_COLD_RESET);
|
||||
else if (strncmp(argv[1], "cold", 4) == 0) {
|
||||
rc = ipmi_mc_reset(intf, BMC_COLD_RESET);
|
||||
}
|
||||
else if (!strncmp(argv[1], "warm", 4)) {
|
||||
ipmi_mc_reset(intf, BMC_WARM_RESET);
|
||||
else if (strncmp(argv[1], "warm", 4) == 0) {
|
||||
rc = ipmi_mc_reset(intf, BMC_WARM_RESET);
|
||||
}
|
||||
else {
|
||||
printf("reset commands: warm, cold\n");
|
||||
lprintf(LOG_ERR, "reset commands: warm, cold");
|
||||
}
|
||||
}
|
||||
else if (!strncmp(argv[0], "info", 4)) {
|
||||
ipmi_mc_get_deviceid(intf);
|
||||
else if (strncmp(argv[0], "info", 4) == 0) {
|
||||
rc = ipmi_mc_get_deviceid(intf);
|
||||
}
|
||||
else if (!strncmp(argv[0], "getenables", 7)) {
|
||||
ipmi_bmc_get_enables(intf);
|
||||
else if (strncmp(argv[0], "getenables", 10) == 0) {
|
||||
rc = ipmi_mc_get_enables(intf);
|
||||
}
|
||||
else if (!strncmp(argv[0], "setenables", 7)) {
|
||||
ipmi_bmc_set_enables(intf, argc-1, &(argv[1]));
|
||||
else if (strncmp(argv[0], "setenables", 10) == 0) {
|
||||
rc = ipmi_mc_set_enables(intf, argc-1, &(argv[1]));
|
||||
}
|
||||
return 0;
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
@ -39,10 +39,13 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include <ipmitool/ipmi.h>
|
||||
#include <ipmitool/log.h>
|
||||
#include <ipmitool/helper.h>
|
||||
#include <ipmitool/ipmi_intf.h>
|
||||
#include <ipmitool/ipmi_raw.h>
|
||||
|
||||
int ipmi_raw_main(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
int
|
||||
ipmi_raw_main(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
{
|
||||
struct ipmi_rs * rsp;
|
||||
struct ipmi_rq req;
|
||||
@ -50,8 +53,8 @@ int ipmi_raw_main(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
int i;
|
||||
unsigned char data[32];
|
||||
|
||||
if (argc < 2 || !strncmp(argv[0], "help", 4)) {
|
||||
printf("RAW Commands: raw <netfn> <cmd> [data]\n");
|
||||
if (argc < 2 || strncmp(argv[0], "help", 4) == 0) {
|
||||
lprintf(LOG_NOTICE, "RAW Commands: raw <netfn> <cmd> [data]");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -69,30 +72,31 @@ int ipmi_raw_main(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
req.msg.data[i-2] = val;
|
||||
req.msg.data_len++;
|
||||
}
|
||||
if (verbose && req.msg.data_len) {
|
||||
for (i=0; i<req.msg.data_len; i++) {
|
||||
if (((i%16) == 0) && (i != 0))
|
||||
printf("\n");
|
||||
printf(" %2.2x", req.msg.data[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
if (verbose)
|
||||
printf("RAW REQ (netfn=0x%x cmd=0x%x data_len=%d)\n",
|
||||
req.msg.netfn, req.msg.cmd, req.msg.data_len);
|
||||
lprintf(LOG_INFO, "RAW REQ (netfn=0x%x cmd=0x%x data_len=%d)",
|
||||
req.msg.netfn, req.msg.cmd, req.msg.data_len);
|
||||
|
||||
printbuf(req.msg.data, req.msg.data_len, "RAW REQUEST");
|
||||
|
||||
rsp = intf->sendrecv(intf, &req);
|
||||
|
||||
if (!rsp || rsp->ccode) {
|
||||
printf("Error:%x sending RAW command\n",
|
||||
rsp ? rsp->ccode : 0);
|
||||
if (rsp == NULL) {
|
||||
lprintf(LOG_ERR, "Unable to send RAW command "
|
||||
"(netfn=0x%x cmd=0x%x)",
|
||||
req.msg.netfn, req.msg.cmd);
|
||||
return -1;
|
||||
}
|
||||
if (rsp->ccode > 0) {
|
||||
lprintf(LOG_ERR, "Unable to send RAW command "
|
||||
"(netfn=0x%x cmd=0x%x): %s",
|
||||
req.msg.netfn, req.msg.cmd,
|
||||
val2str(rsp->ccode, completion_code_vals));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (verbose)
|
||||
printf("RAW RSP (%d bytes)\n", rsp->data_len);
|
||||
lprintf(LOG_INFO, "RAW RSP (%d bytes)", rsp->data_len);
|
||||
|
||||
/* print the raw response buffer */
|
||||
for (i=0; i<rsp->data_len; i++) {
|
||||
if (((i%16) == 0) && (i != 0))
|
||||
printf("\n");
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -40,6 +40,7 @@
|
||||
#include <time.h>
|
||||
|
||||
#include <ipmitool/helper.h>
|
||||
#include <ipmitool/log.h>
|
||||
#include <ipmitool/ipmi.h>
|
||||
#include <ipmitool/ipmi_intf.h>
|
||||
#include <ipmitool/ipmi_sel.h>
|
||||
@ -146,7 +147,7 @@ ipmi_sel_get_sensor_type(unsigned char code)
|
||||
return "Unknown";
|
||||
}
|
||||
|
||||
static void
|
||||
static int
|
||||
ipmi_sel_get_info(struct ipmi_intf * intf)
|
||||
{
|
||||
struct ipmi_rs * rsp;
|
||||
@ -159,12 +160,14 @@ ipmi_sel_get_info(struct ipmi_intf * intf)
|
||||
req.msg.cmd = IPMI_CMD_GET_SEL_INFO;
|
||||
|
||||
rsp = intf->sendrecv(intf, &req);
|
||||
if (!rsp)
|
||||
return;
|
||||
if (rsp->ccode) {
|
||||
printf("Error%x in Get SEL Info command\n",
|
||||
rsp ? rsp->ccode : 0);
|
||||
return;
|
||||
if (rsp == NULL) {
|
||||
lprintf(LOG_ERR, "Get SEL Info command failed");
|
||||
return -1;
|
||||
}
|
||||
if (rsp->ccode > 0) {
|
||||
lprintf(LOG_ERR, "Get SEL Info command failed: %s",
|
||||
val2str(rsp->ccode, completion_code_vals));
|
||||
return -1;
|
||||
}
|
||||
if (verbose > 2)
|
||||
printbuf(rsp->data, rsp->data_len, "sel_info");
|
||||
@ -173,6 +176,7 @@ ipmi_sel_get_info(struct ipmi_intf * intf)
|
||||
printf("Version : %x%x\n",
|
||||
(rsp->data[0] & 0xf0) >> 4, rsp->data[0] & 0xf);
|
||||
|
||||
/* save the entry count and free space to determine percent full */
|
||||
e = buf2short(rsp->data + 1);
|
||||
f = buf2short(rsp->data + 3);
|
||||
printf("Entries : %d\n", e);
|
||||
@ -199,19 +203,23 @@ ipmi_sel_get_info(struct ipmi_intf * intf)
|
||||
printf("Get Alloc Info : %ssupported\n",
|
||||
rsp->data[13] & 0x1 ? "" : "un");
|
||||
|
||||
if (rsp->data[13] & 0x1) {
|
||||
/* get sel allocation info */
|
||||
/* get sel allocation info if supported */
|
||||
if (rsp->data[13] & 1) {
|
||||
memset(&req, 0, sizeof(req));
|
||||
req.msg.netfn = IPMI_NETFN_STORAGE;
|
||||
req.msg.cmd = IPMI_CMD_GET_SEL_ALLOC_INFO;
|
||||
|
||||
rsp = intf->sendrecv(intf, &req);
|
||||
if (!rsp)
|
||||
return;
|
||||
if (rsp->ccode) {
|
||||
printf("error%d in Get SEL Allocation Info command\n",
|
||||
rsp ? rsp->ccode : 0);
|
||||
return;
|
||||
if (rsp == NULL) {
|
||||
lprintf(LOG_ERR,
|
||||
"Get SEL Allocation Info command failed");
|
||||
return -1;
|
||||
}
|
||||
if (rsp->ccode > 0) {
|
||||
lprintf(LOG_ERR,
|
||||
"Get SEL Allocation Info command failed: %s",
|
||||
val2str(rsp->ccode, completion_code_vals));
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("# of Alloc Units : %d\n", buf2short(rsp->data));
|
||||
@ -223,11 +231,13 @@ ipmi_sel_get_info(struct ipmi_intf * intf)
|
||||
}
|
||||
|
||||
static unsigned short
|
||||
ipmi_sel_get_std_entry(struct ipmi_intf * intf, unsigned short id, struct sel_event_record * evt)
|
||||
ipmi_sel_get_std_entry(struct ipmi_intf * intf, unsigned short id,
|
||||
struct sel_event_record * evt)
|
||||
{
|
||||
struct ipmi_rq req;
|
||||
struct ipmi_rs * rsp;
|
||||
unsigned char msg_data[6];
|
||||
unsigned short next;
|
||||
|
||||
memset(msg_data, 0, 6);
|
||||
msg_data[0] = 0x00; /* no reserve id, not partial get */
|
||||
@ -244,27 +254,33 @@ ipmi_sel_get_std_entry(struct ipmi_intf * intf, unsigned short id, struct sel_ev
|
||||
req.msg.data_len = 6;
|
||||
|
||||
rsp = intf->sendrecv(intf, &req);
|
||||
if (!rsp)
|
||||
return 0;
|
||||
if (rsp->ccode) {
|
||||
printf("Error %x in Get SEL Entry %x Command\n",
|
||||
rsp ? rsp->ccode : 0, id);
|
||||
if (rsp == NULL) {
|
||||
lprintf(LOG_ERR, "Get SEL Entry %x command failed", id);
|
||||
return 0;
|
||||
}
|
||||
if (rsp->ccode > 0) {
|
||||
lprintf(LOG_ERR, "Get SEL Entry %x command failed: %s",
|
||||
id, val2str(rsp->ccode, completion_code_vals));
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* save next entry id */
|
||||
next = (rsp->data[1] << 8) | rsp->data[0];
|
||||
|
||||
if (verbose > 2)
|
||||
printbuf(rsp->data, rsp->data_len, "SEL Entry");
|
||||
|
||||
|
||||
if (rsp->data[4] >= 0xc0) {
|
||||
if (verbose)
|
||||
printf("Entry %04xh not a standard SEL entry!\n", id);
|
||||
return (rsp->data[1] << 8) | rsp->data[0];
|
||||
lprintf(LOG_INFO, "Entry %x not a standard SEL entry", id);
|
||||
return next;
|
||||
}
|
||||
|
||||
/* save response into SEL event structure */
|
||||
memset(evt, 0, sizeof(*evt));
|
||||
evt->record_id = (rsp->data[3] << 8) | rsp->data[2];
|
||||
evt->record_type = rsp->data[4];
|
||||
evt->timestamp = (rsp->data[8] << 24) | (rsp->data[7] << 16) | (rsp->data[6] << 8) | rsp->data[5];
|
||||
evt->timestamp = (rsp->data[8] << 24) | (rsp->data[7] << 16) |
|
||||
(rsp->data[6] << 8) | rsp->data[5];
|
||||
evt->gen_id = (rsp->data[10] << 8) | rsp->data[9];
|
||||
evt->evm_rev = rsp->data[11];
|
||||
evt->sensor_type = rsp->data[12];
|
||||
@ -275,7 +291,7 @@ ipmi_sel_get_std_entry(struct ipmi_intf * intf, unsigned short id, struct sel_ev
|
||||
evt->event_data[1] = rsp->data[16];
|
||||
evt->event_data[2] = rsp->data[17];
|
||||
|
||||
return (rsp->data[1] << 8) | rsp->data[0];
|
||||
return next;
|
||||
}
|
||||
|
||||
void
|
||||
@ -415,21 +431,23 @@ ipmi_sel_print_extended_entry_verbose(struct sel_event_record * evt, struct sdr_
|
||||
|
||||
if (evt->record_type == 0xf0)
|
||||
{
|
||||
printf (" Record Type : Linux kernel panic (OEM record %02x)\n", evt->record_type);
|
||||
printf (" Panic string : %.11s\n\n", (char *) evt + 5);
|
||||
printf (" Record Type : "
|
||||
"Linux kernel panic (OEM record %02x)\n",
|
||||
evt->record_type);
|
||||
printf (" Panic string : %.11s\n\n",
|
||||
(char *) evt + 5);
|
||||
return;
|
||||
}
|
||||
|
||||
printf(" Record Type : ");
|
||||
if (evt->record_type >= 0xc0)
|
||||
printf(" Record Type : OEM record %02x\n", evt->record_type >= 0xc0);
|
||||
printf("OEM record %02x\n", evt->record_type >= 0xc0);
|
||||
else
|
||||
printf(" Record Type : %02x\n", evt->record_type);
|
||||
printf("%02x\n", evt->record_type);
|
||||
|
||||
if (evt->record_type < 0xe0)
|
||||
{
|
||||
printf(" Timestamp : %s\n",
|
||||
ipmi_sel_timestamp(evt->timestamp));
|
||||
}
|
||||
|
||||
if (evt->record_type >= 0xc0)
|
||||
{
|
||||
@ -556,7 +574,7 @@ ipmi_sel_print_extended_entry_verbose(struct sel_event_record * evt, struct sdr_
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
static void
|
||||
static int
|
||||
ipmi_sel_list_entries(struct ipmi_intf * intf)
|
||||
{
|
||||
struct ipmi_rs * rsp;
|
||||
@ -569,19 +587,21 @@ ipmi_sel_list_entries(struct ipmi_intf * intf)
|
||||
req.msg.cmd = IPMI_CMD_GET_SEL_INFO;
|
||||
|
||||
rsp = intf->sendrecv(intf, &req);
|
||||
if (!rsp)
|
||||
return;
|
||||
if (rsp->ccode) {
|
||||
printf("Error: %x from Get SEL Info command\n",
|
||||
rsp ? rsp->ccode : 0);
|
||||
return;
|
||||
if (rsp == NULL) {
|
||||
lprintf(LOG_ERR, "Get SEL Info command failed");
|
||||
return -1;
|
||||
}
|
||||
if (rsp->ccode > 0) {
|
||||
lprintf(LOG_ERR, "Get SEL Info command failed: %s",
|
||||
val2str(rsp->ccode, completion_code_vals));
|
||||
return -1;
|
||||
}
|
||||
if (verbose > 2)
|
||||
printbuf(rsp->data, rsp->data_len, "sel_info");
|
||||
|
||||
if (!rsp->data[1] && !rsp->data[2]) {
|
||||
printf("SEL has no entries\n");
|
||||
return;
|
||||
if (rsp->data[1] == 0 && rsp->data[2] == 0) {
|
||||
lprintf(LOG_ERR, "SEL has no entries");
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(&req, 0, sizeof(req));
|
||||
@ -589,24 +609,29 @@ ipmi_sel_list_entries(struct ipmi_intf * intf)
|
||||
req.msg.cmd = IPMI_CMD_RESERVE_SEL;
|
||||
|
||||
rsp = intf->sendrecv(intf, &req);
|
||||
if (!rsp)
|
||||
return;
|
||||
if (rsp->ccode) {
|
||||
printf("Error: %x from Reserve SEL command\n",
|
||||
rsp ? rsp->ccode : 0);
|
||||
return;
|
||||
if (rsp == NULL) {
|
||||
lprintf(LOG_ERR, "Reserve SEL command failed");
|
||||
return -1;
|
||||
}
|
||||
if (rsp->ccode > 0) {
|
||||
lprintf(LOG_ERR, "Reserve SEL command failed: %s",
|
||||
val2str(rsp->ccode, completion_code_vals));
|
||||
return -1;
|
||||
}
|
||||
|
||||
while (next_id != 0xffff) {
|
||||
curr_id = next_id;
|
||||
if (verbose > 1)
|
||||
printf("SEL Next ID: %04x\n", curr_id);
|
||||
lprintf(LOG_DEBUG, "SEL Next ID: %04x", curr_id);
|
||||
|
||||
next_id = ipmi_sel_get_std_entry(intf, curr_id, &evt);
|
||||
if (!next_id) {
|
||||
/* retry */
|
||||
if (next_id == 0) {
|
||||
/*
|
||||
* usually next_id of zero means end but
|
||||
* retry because some hardware has quirks
|
||||
* and will return 0 randomly.
|
||||
*/
|
||||
next_id = ipmi_sel_get_std_entry(intf, curr_id, &evt);
|
||||
if (!next_id)
|
||||
if (next_id == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
@ -628,15 +653,17 @@ ipmi_sel_reserve(struct ipmi_intf * intf)
|
||||
req.msg.cmd = IPMI_CMD_RESERVE_SEL;
|
||||
|
||||
rsp = intf->sendrecv(intf, &req);
|
||||
if (!rsp)
|
||||
if (rsp == NULL) {
|
||||
lprintf(LOG_WARN, "Unable to reserve SEL");
|
||||
return 0;
|
||||
if (rsp->ccode) {
|
||||
printf("Error:%x unable to reserve SEL\n",
|
||||
rsp ? rsp->ccode : 0);
|
||||
}
|
||||
if (rsp->ccode > 0) {
|
||||
printf("Unable to reserve SEL: %s",
|
||||
val2str(rsp->ccode, completion_code_vals));
|
||||
return 0;
|
||||
}
|
||||
|
||||
return rsp->data[0] | rsp->data[1] << 8;
|
||||
return (rsp->data[0] | (rsp->data[1] << 8));
|
||||
}
|
||||
|
||||
|
||||
@ -662,16 +689,18 @@ ipmi_sel_get_time(struct ipmi_intf * intf)
|
||||
|
||||
rsp = intf->sendrecv(intf, &req);
|
||||
|
||||
if (!rsp || rsp->ccode) {
|
||||
printf("Error:%x Get SEL Time Command\n", rsp ? rsp->ccode : 0);
|
||||
if (rsp == NULL) {
|
||||
lprintf(LOG_ERR, "Get SEL Time command failed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
if (rsp->data_len != 4)
|
||||
{
|
||||
printf("Error:Invalid data length (0x%x) from Get SEL Time Command\n",
|
||||
rsp->data_len);
|
||||
if (rsp->ccode > 0) {
|
||||
lprintf(LOG_ERR, "Get SEL Time command failed: %s",
|
||||
val2str(rsp->ccode, completion_code_vals));
|
||||
return -1;
|
||||
}
|
||||
if (rsp->data_len != 4) {
|
||||
lprintf(LOG_ERR, "Get SEL Time command failed: "
|
||||
"Invalid data length %d", rsp->data_len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -710,15 +739,14 @@ ipmi_sel_set_time(struct ipmi_intf * intf, const char * time_string)
|
||||
req.msg.cmd = IPMI_SET_SEL_TIME;
|
||||
|
||||
/* Now how do we get our time_t from our ascii version? */
|
||||
if (! strptime(time_string, time_format, &tm))
|
||||
{
|
||||
printf("Error. Specified time could not be parsed.\n");
|
||||
if (strptime(time_string, time_format, &tm) == 0) {
|
||||
lprintf(LOG_ERR, "Specified time could not be parsed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((time = mktime(&tm)) == 0xFFFFFFFF)
|
||||
{
|
||||
printf("Error. Specified time could not be parsed.\n");
|
||||
time = mktime(&tm);
|
||||
if (time < 0) {
|
||||
lprintf(LOG_ERR, "Specified time could not be parsed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -729,13 +757,15 @@ ipmi_sel_set_time(struct ipmi_intf * intf, const char * time_string)
|
||||
#if WORDS_BIGENDIAN
|
||||
time = BSWAP_32(time);
|
||||
#endif
|
||||
rsp = intf->sendrecv(intf, &req);
|
||||
|
||||
if (!rsp || rsp->ccode) {
|
||||
printf("Error in Set SEL Time Command");
|
||||
if (rsp)
|
||||
printf(": %s", val2str(rsp->ccode, completion_code_vals));
|
||||
printf("\n");
|
||||
rsp = intf->sendrecv(intf, &req);
|
||||
if (rsp == NULL) {
|
||||
lprintf(LOG_ERR, "Set SEL Time command failed");
|
||||
return -1;
|
||||
}
|
||||
if (rsp->ccode > 0) {
|
||||
lprintf(LOG_ERR, "Set SEL Time command failed: %s",
|
||||
val2str(rsp->ccode, completion_code_vals));
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -744,7 +774,7 @@ ipmi_sel_set_time(struct ipmi_intf * intf, const char * time_string)
|
||||
|
||||
|
||||
|
||||
static void
|
||||
static int
|
||||
ipmi_sel_clear(struct ipmi_intf * intf)
|
||||
{
|
||||
struct ipmi_rs * rsp;
|
||||
@ -756,7 +786,7 @@ ipmi_sel_clear(struct ipmi_intf * intf)
|
||||
|
||||
reserve_id = ipmi_sel_reserve(intf);
|
||||
if (reserve_id == 0)
|
||||
return;
|
||||
return -1;
|
||||
|
||||
memset(msg_data, 0, 6);
|
||||
msg_data[0] = reserve_id & 0xff;
|
||||
@ -773,38 +803,43 @@ ipmi_sel_clear(struct ipmi_intf * intf)
|
||||
req.msg.data_len = 6;
|
||||
|
||||
rsp = intf->sendrecv(intf, &req);
|
||||
if (!rsp)
|
||||
return;
|
||||
if (rsp->ccode) {
|
||||
printf("Error:%x unable to clear SEL\n", rsp ? rsp->ccode : 0);
|
||||
return;
|
||||
if (rsp == NULL) {
|
||||
lprintf(LOG_ERR, "Unable to clear SEL: %s");
|
||||
return -1;
|
||||
}
|
||||
if (rsp->ccode > 0) {
|
||||
lprintf(LOG_ERR, "Unable to clear SEL: %s",
|
||||
val2str(rsp->ccode, completion_code_vals));
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("Clearing SEL. Please allow a few seconds to erase.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
static int
|
||||
ipmi_sel_delete(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
{
|
||||
struct ipmi_rs * rsp;
|
||||
struct ipmi_rq req;
|
||||
unsigned short id;
|
||||
unsigned char msg_data[4];
|
||||
int rc = 0;
|
||||
|
||||
if (!argc || !strncmp(argv[0], "help", 4))
|
||||
{
|
||||
printf("usage: delete <id>...<id>\n");
|
||||
return;
|
||||
if (argc == 0 || strncmp(argv[0], "help", 4) == 0) {
|
||||
lprintf(LOG_ERR, "usage: delete <id>...<id>\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
id = ipmi_sel_reserve(intf);
|
||||
if (id == 0)
|
||||
return;
|
||||
return -1;
|
||||
|
||||
memset(msg_data, 0, 4);
|
||||
msg_data[0] = id & 0xff;
|
||||
msg_data[1] = id >> 8;
|
||||
while (argc)
|
||||
|
||||
for (argc; argc != 0; argc--)
|
||||
{
|
||||
id = atoi(argv[argc-1]);
|
||||
msg_data[2] = id & 0xff;
|
||||
@ -817,23 +852,24 @@ ipmi_sel_delete(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
req.msg.data_len = 4;
|
||||
|
||||
rsp = intf->sendrecv(intf, &req);
|
||||
if (!rsp)
|
||||
{
|
||||
printf("No response\n");
|
||||
if (rsp == NULL) {
|
||||
lprintf(LOG_ERR, "Unable to delete entry %d", id);
|
||||
rc = -1;
|
||||
}
|
||||
else if (rsp->ccode)
|
||||
{
|
||||
printf("Error %x unable to delete entry %d\n", rsp ? rsp->ccode : 0, id);
|
||||
else if (rsp->ccode > 0) {
|
||||
lprintf(LOG_ERR, "Unable to delete entry %d: %s", id,
|
||||
val2str(rsp->ccode, completion_code_vals));
|
||||
rc = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
printf("Deleted entry %d\n", id);
|
||||
}
|
||||
argc--;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
static void
|
||||
static int
|
||||
ipmi_sel_show_entry(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
{
|
||||
struct ipmi_rs * rsp;
|
||||
@ -844,27 +880,37 @@ ipmi_sel_show_entry(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
struct sdr_record_list * sdr;
|
||||
struct entity_id entity;
|
||||
struct sdr_record_list * list, * entry;
|
||||
int rc = 0;
|
||||
|
||||
if (!argc || !strncmp(argv[0], "help", 4))
|
||||
{
|
||||
printf("usage: sel get <id>...<id>\n");
|
||||
return;
|
||||
if (argc == 0 || strncmp(argv[0], "help", 4) == 0) {
|
||||
lprintf(LOG_ERR, "usage: sel get <id>...<id>");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!ipmi_sel_reserve(intf))
|
||||
return;
|
||||
if (ipmi_sel_reserve(intf) == 0)
|
||||
return -1;
|
||||
|
||||
for (i=0; i<argc; i++) {
|
||||
id = (unsigned short)strtol(argv[i], NULL, 0);
|
||||
|
||||
lprintf(LOG_DEBUG, "Looking up SEL entry 0x%x", id);
|
||||
|
||||
/* lookup SEL entry based on ID */
|
||||
ipmi_sel_get_std_entry(intf, id, &evt);
|
||||
if (evt.sensor_num == 0 && evt.sensor_type == 0) {
|
||||
lprintf(LOG_WARN, "SEL Entry 0x%x not found", id);
|
||||
rc = -1;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* lookup SDR entry based on sensor number and type */
|
||||
sdr = ipmi_sdr_find_sdr_bynumtype(intf, evt.sensor_num, evt.sensor_type);
|
||||
if (!sdr)
|
||||
if (sdr == NULL)
|
||||
continue;
|
||||
|
||||
/* print SEL extended entry */
|
||||
ipmi_sel_print_extended_entry_verbose(&evt, sdr);
|
||||
|
||||
/* print SDR entry */
|
||||
oldv = verbose;
|
||||
verbose = verbose ? : 1;
|
||||
@ -901,48 +947,55 @@ ipmi_sel_show_entry(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
if ((argc > 1) && (i<(argc-1)))
|
||||
printf("----------------------\n\n");
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
int ipmi_sel_main(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
{
|
||||
if (!argc)
|
||||
ipmi_sel_get_info(intf);
|
||||
else if (!strncmp(argv[0], "help", 4))
|
||||
printf("SEL Commands: info clear delete list time\n");
|
||||
else if (!strncmp(argv[0], "info", 4))
|
||||
ipmi_sel_get_info(intf);
|
||||
else if (!strncmp(argv[0], "list", 4))
|
||||
ipmi_sel_list_entries(intf);
|
||||
else if (!strncmp(argv[0], "clear", 5))
|
||||
ipmi_sel_clear(intf);
|
||||
else if (!strncmp(argv[0], "delete", 6)) {
|
||||
if (argc < 2)
|
||||
printf("usage: sel delete <id>...<id>\n");
|
||||
else
|
||||
ipmi_sel_delete(intf, argc-1, &argv[1]);
|
||||
}
|
||||
else if (!strncmp(argv[0], "get", 3)) {
|
||||
if (argc < 2)
|
||||
printf("usage: sel get <entry>\n");
|
||||
else
|
||||
ipmi_sel_show_entry(intf, argc-1, &argv[1]);
|
||||
}
|
||||
else if (!strncmp(argv[0], "time", 4)) {
|
||||
if (argc < 2)
|
||||
printf("sel time commands: get set\n");
|
||||
else if (!strncmp(argv[1], "get", 3))
|
||||
ipmi_sel_get_time(intf);
|
||||
else if (!strncmp(argv[1], "set", 3)) {
|
||||
if (argc < 3)
|
||||
printf("usage: sel time set \"mm/dd/yyyy hh:mm:ss\"\n");
|
||||
else
|
||||
ipmi_sel_set_time(intf, argv[2]);
|
||||
} else
|
||||
printf("sel time commands: get set\n");
|
||||
}
|
||||
int rc = 0;
|
||||
|
||||
else
|
||||
printf("Invalid SEL command: %s\n", argv[0]);
|
||||
return 0;
|
||||
if (argc == 0)
|
||||
rc = ipmi_sel_get_info(intf);
|
||||
else if (strncmp(argv[0], "help", 4) == 0)
|
||||
lprintf(LOG_ERR, "SEL Commands: info clear delete list time");
|
||||
else if (strncmp(argv[0], "info", 4) == 0)
|
||||
rc = ipmi_sel_get_info(intf);
|
||||
else if (strncmp(argv[0], "list", 4) == 0)
|
||||
rc = ipmi_sel_list_entries(intf);
|
||||
else if (strncmp(argv[0], "clear", 5) == 0)
|
||||
rc = ipmi_sel_clear(intf);
|
||||
else if (strncmp(argv[0], "delete", 6) == 0) {
|
||||
if (argc < 2)
|
||||
lprintf(LOG_ERR, "usage: sel delete <id>...<id>");
|
||||
else
|
||||
rc = ipmi_sel_delete(intf, argc-1, &argv[1]);
|
||||
}
|
||||
else if (strncmp(argv[0], "get", 3) == 0) {
|
||||
if (argc < 2)
|
||||
lprintf(LOG_ERR, "usage: sel get <entry>");
|
||||
else
|
||||
rc = ipmi_sel_show_entry(intf, argc-1, &argv[1]);
|
||||
}
|
||||
else if (strncmp(argv[0], "time", 4) == 0) {
|
||||
if (argc < 2)
|
||||
lprintf(LOG_ERR, "sel time commands: get set");
|
||||
else if (strncmp(argv[1], "get", 3) == 0)
|
||||
ipmi_sel_get_time(intf);
|
||||
else if (strncmp(argv[1], "set", 3) == 0) {
|
||||
if (argc < 3)
|
||||
lprintf(LOG_ERR, "usage: sel time set \"mm/dd/yyyy hh:mm:ss\"");
|
||||
else
|
||||
rc = ipmi_sel_set_time(intf, argv[2]);
|
||||
} else {
|
||||
lprintf(LOG_ERR, "sel time commands: get set");
|
||||
}
|
||||
}
|
||||
else {
|
||||
lprintf(LOG_ERR, "Invalid SEL command: %s", argv[0]);
|
||||
rc = -1;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
@ -636,10 +636,10 @@ static void ipmi_sensor_get(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
ipmi_sdr_print_sensor_eventonly(intf, sdr->record.eventonly);
|
||||
break;
|
||||
case SDR_RECORD_TYPE_FRU_DEVICE_LOCATOR:
|
||||
ipmi_sdr_print_fru_locator(intf, sdr->record.fruloc);
|
||||
ipmi_sdr_print_sensor_fru_locator(intf, sdr->record.fruloc);
|
||||
break;
|
||||
case SDR_RECORD_TYPE_MC_DEVICE_LOCATOR:
|
||||
ipmi_sdr_print_mc_locator(intf, sdr->record.mcloc);
|
||||
ipmi_sdr_print_sensor_mc_locator(intf, sdr->record.mcloc);
|
||||
break;
|
||||
}
|
||||
verbose = v;
|
||||
|
@ -42,6 +42,7 @@
|
||||
#include <ctype.h>
|
||||
|
||||
#include <ipmitool/helper.h>
|
||||
#include <ipmitool/log.h>
|
||||
#include <ipmitool/ipmi.h>
|
||||
#include <ipmitool/ipmi_intf.h>
|
||||
#include <ipmitool/ipmi_session.h>
|
||||
@ -77,9 +78,9 @@ static int rl_event_keepalive(void)
|
||||
{
|
||||
static int internal_timer = 0;
|
||||
|
||||
if (!shell_intf)
|
||||
if (shell_intf == NULL)
|
||||
return -1;
|
||||
if (!shell_intf->keepalive)
|
||||
if (shell_intf->keepalive == NULL)
|
||||
return 0;
|
||||
#if defined (RL_READLINE_VERSION) && RL_READLINE_VERSION >= 0x0402
|
||||
if (internal_timer++ < RL_TIMEOUT)
|
||||
@ -122,11 +123,13 @@ int ipmi_shell_main(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
free(pbuf);
|
||||
continue;
|
||||
}
|
||||
if (!strncmp(pbuf, "quit", 4) || !strncmp(pbuf, "exit", 4)) {
|
||||
if (strncmp(pbuf, "quit", 4) == 0 ||
|
||||
strncmp(pbuf, "exit", 4) == 0) {
|
||||
free(pbuf);
|
||||
return 0;
|
||||
}
|
||||
if (!strncmp(pbuf, "help", 4) || !strncmp(pbuf, "?", 1)) {
|
||||
if (strncmp(pbuf, "help", 4) == 0 ||
|
||||
strncmp(pbuf, "?", 1) == 0) {
|
||||
ipmi_cmd_print();
|
||||
free(pbuf);
|
||||
continue;
|
||||
@ -138,7 +141,9 @@ int ipmi_shell_main(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
__argc = 0;
|
||||
ap = __argv;
|
||||
|
||||
for (*ap = strtok(pbuf, " \t"); *ap != NULL; *ap = strtok(NULL, " \t")) {
|
||||
for (*ap = strtok(pbuf, " \t");
|
||||
*ap != NULL;
|
||||
*ap = strtok(NULL, " \t")) {
|
||||
__argc++;
|
||||
if (**ap != '\0') {
|
||||
if (++ap >= &__argv[20])
|
||||
@ -147,7 +152,10 @@ int ipmi_shell_main(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
}
|
||||
|
||||
if (__argc && __argv[0])
|
||||
rc = ipmi_cmd_run(intf, __argv[0], __argc-1, &(__argv[1]));
|
||||
rc = ipmi_cmd_run(intf,
|
||||
__argv[0],
|
||||
__argc-1,
|
||||
&(__argv[1]));
|
||||
|
||||
free(pbuf);
|
||||
}
|
||||
@ -156,44 +164,46 @@ int ipmi_shell_main(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
|
||||
#else /* HAVE_READLINE */
|
||||
|
||||
int ipmi_shell_main(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
int
|
||||
ipmi_shell_main(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
{
|
||||
printf("Compiled without readline support, shell is disabled.\n");
|
||||
lprintf(LOG_ERR, "Compiled without readline, shell is disabled");
|
||||
return -1;
|
||||
}
|
||||
|
||||
#endif /* HAVE_READLINE */
|
||||
|
||||
static void ipmi_set_usage(void)
|
||||
static void
|
||||
ipmi_set_usage(void)
|
||||
{
|
||||
printf("Usage: set <option> <value>\n\n");
|
||||
printf("Options are:\n");
|
||||
printf(" hostname <host> Session hostname\n");
|
||||
printf(" username <user> Session username\n");
|
||||
printf(" password <pass> Session password\n");
|
||||
printf(" privlvl <level> Session privilege level force\n");
|
||||
printf(" authtype <type> Authentication type force\n");
|
||||
printf(" localaddr <addr> Local IPMB address\n");
|
||||
printf(" targetaddr <addr> Remote target IPMB address\n");
|
||||
printf(" port <port> Remote RMCP port\n");
|
||||
printf(" csv [level] enable output in comma separated format\n");
|
||||
printf(" verbose [level] Verbose level\n");
|
||||
printf("\n");
|
||||
lprintf(LOG_NOTICE, "Usage: set <option> <value>\n");
|
||||
lprintf(LOG_NOTICE, "Options are:");
|
||||
lprintf(LOG_NOTICE, " hostname <host> Session hostname");
|
||||
lprintf(LOG_NOTICE, " username <user> Session username");
|
||||
lprintf(LOG_NOTICE, " password <pass> Session password");
|
||||
lprintf(LOG_NOTICE, " privlvl <level> Session privilege level force");
|
||||
lprintf(LOG_NOTICE, " authtype <type> Authentication type force");
|
||||
lprintf(LOG_NOTICE, " localaddr <addr> Local IPMB address");
|
||||
lprintf(LOG_NOTICE, " targetaddr <addr> Remote target IPMB address");
|
||||
lprintf(LOG_NOTICE, " port <port> Remote RMCP port");
|
||||
lprintf(LOG_NOTICE, " csv [level] enable output in comma separated format");
|
||||
lprintf(LOG_NOTICE, " verbose [level] Verbose level");
|
||||
lprintf(LOG_NOTICE, "");
|
||||
}
|
||||
|
||||
int ipmi_set_main(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
{
|
||||
if (!argc || !strncmp(argv[0], "help", 4)) {
|
||||
if (argc == 0 || strncmp(argv[0], "help", 4) == 0) {
|
||||
ipmi_set_usage();
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* these options can have no arguments */
|
||||
if (!strncmp(argv[0], "verbose", 7)) {
|
||||
if (strncmp(argv[0], "verbose", 7) == 0) {
|
||||
verbose = (argc > 1) ? atoi(argv[1]) : verbose+1;
|
||||
return 0;
|
||||
}
|
||||
if (!strncmp(argv[0], "csv", 3)) {
|
||||
if (strncmp(argv[0], "csv", 3) == 0) {
|
||||
csv_output = (argc > 1) ? atoi(argv[1]) : 1;
|
||||
return 0;
|
||||
}
|
||||
@ -204,42 +214,45 @@ int ipmi_set_main(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!strncmp(argv[0], "host", 4) || !strncmp(argv[0], "hostname", 8)) {
|
||||
if (strncmp(argv[0], "host", 4) == 0 ||
|
||||
strncmp(argv[0], "hostname", 8) == 0) {
|
||||
ipmi_intf_session_set_hostname(intf, argv[1]);
|
||||
printf("Set session hostname to %s\n", intf->session->hostname);
|
||||
}
|
||||
else if (!strncmp(argv[0], "user", 4) || !strncmp(argv[0], "username", 8)) {
|
||||
else if (strncmp(argv[0], "user", 4) == 0 ||
|
||||
strncmp(argv[0], "username", 8) == 0) {
|
||||
ipmi_intf_session_set_username(intf, argv[1]);
|
||||
printf("Set session username to %s\n", intf->session->username);
|
||||
}
|
||||
else if (!strncmp(argv[0], "pass", 4) || !strncmp(argv[0], "password", 8)) {
|
||||
else if (strncmp(argv[0], "pass", 4) == 0 ||
|
||||
strncmp(argv[0], "password", 8) == 0) {
|
||||
ipmi_intf_session_set_password(intf, argv[1]);
|
||||
printf("Set session password\n");
|
||||
}
|
||||
else if (!strncmp(argv[0], "authtype", 8)) {
|
||||
else if (strncmp(argv[0], "authtype", 8) == 0) {
|
||||
unsigned char authtype;
|
||||
authtype = (unsigned char)str2val(argv[1], ipmi_authtype_session_vals);
|
||||
ipmi_intf_session_set_authtype(intf, authtype);
|
||||
printf("Set session authtype to %s\n",
|
||||
val2str(intf->session->authtype_set, ipmi_authtype_session_vals));
|
||||
}
|
||||
else if (!strncmp(argv[0], "privlvl", 7)) {
|
||||
else if (strncmp(argv[0], "privlvl", 7) == 0) {
|
||||
unsigned char privlvl;
|
||||
privlvl = (unsigned char)str2val(argv[1], ipmi_privlvl_vals);
|
||||
ipmi_intf_session_set_privlvl(intf, privlvl);
|
||||
printf("Set session privilege level to %s\n",
|
||||
val2str(intf->session->privlvl, ipmi_privlvl_vals));
|
||||
}
|
||||
else if (!strncmp(argv[0], "port", 4)) {
|
||||
else if (strncmp(argv[0], "port", 4) == 0) {
|
||||
int port = atoi(argv[1]);
|
||||
ipmi_intf_session_set_port(intf, port);
|
||||
printf("Set session port to %d\n", intf->session->port);
|
||||
}
|
||||
else if (!strncmp(argv[0], "localaddr", 9)) {
|
||||
else if (strncmp(argv[0], "localaddr", 9) == 0) {
|
||||
intf->my_addr = (unsigned char)strtol(argv[1], NULL, 0);
|
||||
printf("Set local IPMB address to 0x%02x\n", intf->my_addr);
|
||||
}
|
||||
else if (!strncmp(argv[0], "targetaddr", 10)) {
|
||||
else if (strncmp(argv[0], "targetaddr", 10) == 0) {
|
||||
intf->target_addr = (unsigned char)strtol(argv[1], NULL, 0);
|
||||
printf("Set remote IPMB address to 0x%02x\n", intf->target_addr);
|
||||
}
|
||||
@ -260,15 +273,15 @@ int ipmi_exec_main(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
int rc=0;
|
||||
|
||||
if (argc < 1) {
|
||||
printf("Usage: exec <filename>\n");
|
||||
lprintf(LOG_ERR, "Usage: exec <filename>");
|
||||
return -1;
|
||||
}
|
||||
|
||||
fp = ipmi_open_file_read(argv[0]);
|
||||
if (!fp)
|
||||
if (fp == NULL)
|
||||
return -1;
|
||||
|
||||
while (!feof(fp)) {
|
||||
while (feof(fp) == 0) {
|
||||
ret = fgets(buf, EXEC_BUF_SIZE, fp);
|
||||
if (!ret)
|
||||
continue;
|
||||
@ -287,7 +300,7 @@ int ipmi_exec_main(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
ptr = buf;
|
||||
while (isspace(*ptr))
|
||||
ptr++;
|
||||
if (!strlen(ptr))
|
||||
if (strlen(ptr) == 0)
|
||||
continue;
|
||||
|
||||
/* parse it and make argument list */
|
||||
@ -314,6 +327,6 @@ int ipmi_exec_main(struct ipmi_intf * intf, int argc, char ** argv)
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
return 0;
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
@ -71,7 +71,11 @@
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#define OPTION_STRING "I:hVvcgsEaH:P:f:U:p:L:A:t:m:"
|
||||
#ifdef __sun
|
||||
# define OPTION_STRING "I:hVvcgsH:f:U:p:t:m:"
|
||||
#else
|
||||
# define OPTION_STRING "I:hVvcgsEaH:P:f:U:p:L:A:t:m:"
|
||||
#endif
|
||||
|
||||
int csv_output = 0;
|
||||
int verbose = 0;
|
||||
@ -86,27 +90,27 @@ extern int ipmi_exec_main(struct ipmi_intf * intf, int argc, char ** argv);
|
||||
|
||||
struct ipmi_cmd {
|
||||
int (*func)(struct ipmi_intf * intf, int argc, char ** argv);
|
||||
char * name;
|
||||
char * desc;
|
||||
const char * name;
|
||||
const char * desc;
|
||||
} ipmi_cmd_list[] = {
|
||||
{ ipmi_raw_main, "raw", "Send a RAW IPMI request and print response" },
|
||||
{ ipmi_lanp_main, "lan", "Configure LAN Channels" },
|
||||
{ ipmi_chassis_main, "chassis", "Get chassis status and set power state" },
|
||||
{ ipmi_event_main, "event", "Send pre-defined events to BMC" },
|
||||
{ ipmi_mc_main, "mc", "Management Controller status and global enables" },
|
||||
{ ipmi_sdr_main, "sdr", "Print Sensor Data Repository entries and readings" },
|
||||
{ ipmi_sensor_main, "sensor", "Print detailed sensor information" },
|
||||
{ ipmi_fru_main, "fru", "Print built-in FRU and scan SDR for FRU locators" },
|
||||
{ ipmi_sel_main, "sel", "Print System Evelnt Log" },
|
||||
{ ipmi_pef_main, "pef", "Configure Platform Event Filtering (PEF)" },
|
||||
{ ipmi_sol_main, "sol", "Configure IPMIv2.0 Serial-over-LAN" },
|
||||
{ ipmi_isol_main, "isol", "Configure Intel IPMIv1.5 Serial-over-LAN" },
|
||||
{ ipmi_user_main, "user", "Configure BMC users" },
|
||||
{ ipmi_channel_main, "channel", "Configure BMC channels" },
|
||||
{ ipmi_session_main, "session", "Print session information" },
|
||||
{ ipmi_shell_main, "shell", "Launch interactive IPMI shell" },
|
||||
{ ipmi_exec_main, "exec", "Run list of commands from file" },
|
||||
{ ipmi_set_main, "set", "Set runtime variable for shell and exec" },
|
||||
{ ipmi_raw_main, "raw", "Send a RAW IPMI request and print response" },
|
||||
{ ipmi_lanp_main, "lan", "Configure LAN Channels" },
|
||||
{ ipmi_chassis_main, "chassis", "Get chassis status and set power state" },
|
||||
{ ipmi_event_main, "event", "Send pre-defined events to MC" },
|
||||
{ ipmi_mc_main, "mc", "Management Controller status and global enables" },
|
||||
{ ipmi_sdr_main, "sdr", "Print Sensor Data Repository entries and readings" },
|
||||
{ ipmi_sensor_main, "sensor", "Print detailed sensor information" },
|
||||
{ ipmi_fru_main, "fru", "Print built-in FRU and scan SDR for FRU locators" },
|
||||
{ ipmi_sel_main, "sel", "Print System Event Log (SEL)" },
|
||||
{ ipmi_pef_main, "pef", "Configure Platform Event Filtering (PEF)" },
|
||||
{ ipmi_sol_main, "sol", "Configure IPMIv2.0 Serial-over-LAN" },
|
||||
{ ipmi_isol_main, "isol", "Configure Intel IPMIv1.5 Serial-over-LAN" },
|
||||
{ ipmi_user_main, "user", "Configure Management Controller users" },
|
||||
{ ipmi_channel_main, "channel", "Configure Management Controller channels" },
|
||||
{ ipmi_session_main, "session", "Print session information" },
|
||||
{ ipmi_shell_main, "shell", "Launch interactive IPMI shell" },
|
||||
{ ipmi_exec_main, "exec", "Run list of commands from file" },
|
||||
{ ipmi_set_main, "set", "Set runtime variable for shell and exec" },
|
||||
{ NULL },
|
||||
};
|
||||
|
||||
@ -114,105 +118,133 @@ struct ipmi_cmd {
|
||||
* Print all the commands in the above table to stderr
|
||||
* used for help text on command line and shell
|
||||
*/
|
||||
void ipmi_cmd_print(void)
|
||||
void
|
||||
ipmi_cmd_print(void)
|
||||
{
|
||||
struct ipmi_cmd * cmd;
|
||||
fprintf(stderr, "Commands:\n");
|
||||
lprintf(LOG_NOTICE, "Commands:");
|
||||
for (cmd=ipmi_cmd_list; cmd->func; cmd++) {
|
||||
if (cmd->desc == NULL)
|
||||
continue;
|
||||
fprintf(stderr, "\t%-12s %s\n", cmd->name, cmd->desc);
|
||||
lprintf(LOG_NOTICE, "\t%-12s %s", cmd->name, cmd->desc);
|
||||
}
|
||||
fprintf(stderr, "\n");
|
||||
lprintf(LOG_NOTICE, "");
|
||||
}
|
||||
|
||||
/*
|
||||
* ipmi_cmd_run - run a command from list based on parameters
|
||||
/* ipmi_cmd_run - run a command from list based on parameters
|
||||
* called from main()
|
||||
*
|
||||
* - iterate through ipmi_cmd_list matching on name
|
||||
* - call func() for that command
|
||||
* 1. iterate through ipmi_cmd_list matching on name
|
||||
* 2. call func() for that command
|
||||
*
|
||||
* @intf: ipmi interface
|
||||
* @name: command name
|
||||
* @argc: command argument count
|
||||
* @argv: command argument list
|
||||
*
|
||||
* returns value from func() of that commnad if found
|
||||
* returns -1 if command is not found
|
||||
*/
|
||||
int ipmi_cmd_run(struct ipmi_intf * intf, char * name, int argc, char ** argv)
|
||||
int
|
||||
ipmi_cmd_run(struct ipmi_intf * intf, char * name, int argc, char ** argv)
|
||||
{
|
||||
struct ipmi_cmd * cmd;
|
||||
|
||||
for (cmd=ipmi_cmd_list; cmd->func; cmd++) {
|
||||
for (cmd=ipmi_cmd_list; cmd->func != NULL; cmd++) {
|
||||
if (strncmp(name, cmd->name, strlen(cmd->name)) == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
if (cmd->func == NULL) {
|
||||
printf("Invalid command: %s\n", name);
|
||||
lprintf(LOG_ERR, "Invalid command: %s", name);
|
||||
return -1;
|
||||
}
|
||||
return cmd->func(intf, argc, argv);
|
||||
}
|
||||
|
||||
static void ipmitool_usage(void)
|
||||
/* ipmitool_usage - print usage help
|
||||
*/
|
||||
static void
|
||||
ipmitool_usage(void)
|
||||
{
|
||||
printf("ipmitool version %s\n", VERSION);
|
||||
printf("\n");
|
||||
printf("usage: ipmitool [options...] <command>\n");
|
||||
printf("\n");
|
||||
printf(" -h This help\n");
|
||||
printf(" -V Show version information\n");
|
||||
printf(" -v Verbose (can use multiple times)\n");
|
||||
printf(" -c Display output in comma separated format\n");
|
||||
printf(" -I intf Interface to use\n");
|
||||
printf(" -H hostname Remote host name for LAN interface\n");
|
||||
printf(" -p port Remote RMCP port [default=623]\n");
|
||||
printf(" -L level Remote session privilege level [default=USER]\n");
|
||||
printf(" -A authtype Force use of authentication type NONE, PASSWORD, MD2 or MD5\n");
|
||||
printf(" -U username Remote session username\n");
|
||||
printf(" -P password Remote session password\n");
|
||||
printf(" -f file Read remote session password from file\n");
|
||||
printf(" -a Prompt for remote password\n");
|
||||
printf(" -E Read password from IPMI_PASSWORD environment variable\n");
|
||||
printf(" -m address Set local IPMB address\n");
|
||||
printf(" -t address Bridge request to remote target address\n");
|
||||
printf("\n");
|
||||
lprintf(LOG_NOTICE, "ipmitool version %s\n", VERSION);
|
||||
lprintf(LOG_NOTICE, "usage: ipmitool [options...] <command>\n");
|
||||
lprintf(LOG_NOTICE, " -h This help");
|
||||
lprintf(LOG_NOTICE, " -V Show version information");
|
||||
lprintf(LOG_NOTICE, " -v Verbose (can use multiple times)");
|
||||
lprintf(LOG_NOTICE, " -c Display output in comma separated format");
|
||||
lprintf(LOG_NOTICE, " -I intf Interface to use");
|
||||
lprintf(LOG_NOTICE, " -H hostname Remote host name for LAN interface");
|
||||
lprintf(LOG_NOTICE, " -p port Remote RMCP port [default=623]");
|
||||
lprintf(LOG_NOTICE, " -U username Remote session username");
|
||||
#ifndef __sun
|
||||
lprintf(LOG_NOTICE, " -L level Remote session privilege level [default=USER]");
|
||||
lprintf(LOG_NOTICE, " -A authtype Force use of authentication type NONE, PASSWORD, MD2, MD5 or OEM");
|
||||
lprintf(LOG_NOTICE, " -P password Remote session password");
|
||||
lprintf(LOG_NOTICE, " -a Prompt for remote password");
|
||||
lprintf(LOG_NOTICE, " -E Read password from IPMI_PASSWORD environment variable");
|
||||
lprintf(LOG_NOTICE, " -f file Read remote session password from file");
|
||||
lprintf(LOG_NOTICE, " -m address Set local IPMB address");
|
||||
lprintf(LOG_NOTICE, " -t address Bridge request to remote target address\n");
|
||||
#endif
|
||||
ipmi_intf_print();
|
||||
ipmi_cmd_print();
|
||||
}
|
||||
|
||||
static char * ipmi_password_file_read(char * filename)
|
||||
/* ipmi_password_file_read - Open file and read password from it
|
||||
*
|
||||
* @filename: file name to read from
|
||||
*
|
||||
* returns pointer to allocated buffer containing password
|
||||
* (caller is expected to free when finished)
|
||||
* returns NULL on error
|
||||
*/
|
||||
static char *
|
||||
ipmi_password_file_read(char * filename)
|
||||
{
|
||||
FILE * fp;
|
||||
char * pass = NULL;
|
||||
int l;
|
||||
|
||||
pass = malloc(16);
|
||||
if (pass == NULL)
|
||||
if (pass == NULL) {
|
||||
lprintf(LOG_ERR, "ipmitool: malloc failure");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
fp = ipmi_open_file_read((const char *)filename);
|
||||
if (fp == NULL)
|
||||
if (fp == NULL) {
|
||||
lprintf(LOG_ERR, "Unable to open password file %s",
|
||||
filename);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* read in id */
|
||||
if (fgets(pass, 16, fp) == NULL) {
|
||||
lprintf(LOG_ERR, "Unable to read password from file %s",
|
||||
filename);
|
||||
fclose(fp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* remove trailing whitespace */
|
||||
l = strcspn(pass, " \r\n\t");
|
||||
if (l > 0)
|
||||
if (l > 0) {
|
||||
pass[l] = '\0';
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
return pass;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char ** argv)
|
||||
int
|
||||
main(int argc, char ** argv)
|
||||
{
|
||||
struct ipmi_intf * intf = NULL;
|
||||
unsigned char privlvl = 0;
|
||||
unsigned char target_addr = 0;
|
||||
unsigned char my_addr = 0;
|
||||
unsigned char authtype = 0;
|
||||
int authtype = -1;
|
||||
char * tmp = NULL;
|
||||
char * hostname = NULL;
|
||||
char * username = NULL;
|
||||
@ -221,7 +253,7 @@ int main(int argc, char ** argv)
|
||||
char * progname = NULL;
|
||||
int port = 0;
|
||||
int argflag, i;
|
||||
int rc = 0;
|
||||
int rc = -1;
|
||||
int thump = 0;
|
||||
int authspecial = 0;
|
||||
|
||||
@ -235,7 +267,7 @@ int main(int argc, char ** argv)
|
||||
case 'I':
|
||||
intfname = strdup(optarg);
|
||||
if (intfname == NULL) {
|
||||
fprintf(stderr, "ipmitool: malloc failure\n");
|
||||
lprintf(LOG_ERR, "ipmitool: malloc failure");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
break;
|
||||
@ -247,11 +279,8 @@ int main(int argc, char ** argv)
|
||||
printf("%s version %s\n", progname, VERSION);
|
||||
goto out_free;
|
||||
break;
|
||||
case 'g':
|
||||
thump = 1;
|
||||
break;
|
||||
case 's':
|
||||
authspecial = 1;
|
||||
case 'p':
|
||||
port = atoi(optarg);
|
||||
break;
|
||||
case 'v':
|
||||
verbose++;
|
||||
@ -262,67 +291,30 @@ int main(int argc, char ** argv)
|
||||
case 'H':
|
||||
hostname = strdup(optarg);
|
||||
if (hostname == NULL) {
|
||||
fprintf(stderr, "ipmitool: malloc failure\n");
|
||||
lprintf(LOG_ERR, "ipmitool: malloc failure");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
break;
|
||||
case 'P':
|
||||
if (password != NULL)
|
||||
free(password);
|
||||
password = strdup(optarg);
|
||||
if (password == NULL) {
|
||||
fprintf(stderr, "ipmitool: malloc failure\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* Prevent password snooping with ps */
|
||||
i = strlen(optarg);
|
||||
memset(optarg, 'X', i);
|
||||
break;
|
||||
case 'f':
|
||||
if (password != NULL)
|
||||
if (password)
|
||||
free(password);
|
||||
password = ipmi_password_file_read(optarg);
|
||||
if (password == NULL)
|
||||
fprintf(stderr, "Unable to read password from file %s\n", optarg);
|
||||
break;
|
||||
case 'E':
|
||||
if ((tmp = getenv("IPMITOOL_PASSWORD")))
|
||||
{
|
||||
if (password != NULL)
|
||||
free(password);
|
||||
password = strdup(tmp);
|
||||
if (password == NULL) {
|
||||
fprintf(stderr, "ipmitool: malloc failure\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
else if ((tmp = getenv("IPMI_PASSWORD")))
|
||||
{
|
||||
if (password != NULL)
|
||||
free(password);
|
||||
password = strdup(tmp);
|
||||
if (password == NULL) {
|
||||
fprintf(stderr, "ipmitool: malloc failure\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "Unable to read password from environment.\n");
|
||||
}
|
||||
lprintf(LOG_ERR, "Unable to read password "
|
||||
"from file %s", optarg);
|
||||
break;
|
||||
case 'a':
|
||||
#ifdef HAVE_GETPASSPHRASE
|
||||
if ((tmp = getpassphrase("Password: ")))
|
||||
tmp = getpassphrase("Password: ");
|
||||
#else
|
||||
if ((tmp = getpass("Password: ")))
|
||||
tmp = getpass("Password: ");
|
||||
#endif
|
||||
{
|
||||
if (password != NULL)
|
||||
if (tmp != NULL) {
|
||||
if (password)
|
||||
free(password);
|
||||
password = strdup(tmp);
|
||||
if (password == NULL) {
|
||||
fprintf(stderr, "ipmitool: malloc failure\n");
|
||||
lprintf(LOG_ERR, "ipmitool: malloc failure");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
@ -330,27 +322,70 @@ int main(int argc, char ** argv)
|
||||
case 'U':
|
||||
username = strdup(optarg);
|
||||
if (username == NULL) {
|
||||
fprintf(stderr, "ipmitool: malloc failure\n");
|
||||
lprintf(LOG_ERR, "ipmitool: malloc failure");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
break;
|
||||
#ifndef __sun /* some options not enabled on solaris yet */
|
||||
case 'g':
|
||||
thump = 1;
|
||||
break;
|
||||
case 's':
|
||||
authspecial = 1;
|
||||
break;
|
||||
case 'P':
|
||||
if (password)
|
||||
free(password);
|
||||
password = strdup(optarg);
|
||||
if (password == NULL) {
|
||||
lprintf(LOG_ERR, "ipmitool: malloc failure");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* Prevent password snooping with ps */
|
||||
i = strlen(optarg);
|
||||
memset(optarg, 'X', i);
|
||||
break;
|
||||
case 'E':
|
||||
if ((tmp = getenv("IPMITOOL_PASSWORD")))
|
||||
{
|
||||
if (password)
|
||||
free(password);
|
||||
password = strdup(tmp);
|
||||
if (password == NULL) {
|
||||
lprintf(LOG_ERR, "ipmitool: malloc failure");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
else if ((tmp = getenv("IPMI_PASSWORD")))
|
||||
{
|
||||
if (password)
|
||||
free(password);
|
||||
password = strdup(tmp);
|
||||
if (password == NULL) {
|
||||
lprintf(LOG_ERR, "ipmitool: malloc failure");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
else {
|
||||
lprintf(LOG_WARN, "Unable to read password from environment");
|
||||
}
|
||||
break;
|
||||
case 'L':
|
||||
privlvl = (unsigned char)str2val(optarg, ipmi_privlvl_vals);
|
||||
if (!privlvl)
|
||||
printf("Invalid privilege level %s!\n", optarg);
|
||||
lprintf(LOG_WARN, "Invalid privilege level %s", optarg);
|
||||
break;
|
||||
case 'A':
|
||||
authtype = (int)str2val(optarg, ipmi_authtype_session_vals);
|
||||
break;
|
||||
case 'p':
|
||||
port = atoi(optarg);
|
||||
break;
|
||||
case 't':
|
||||
target_addr = (unsigned char)strtol(optarg, NULL, 0);
|
||||
break;
|
||||
case 'm':
|
||||
my_addr = (unsigned char)strtol(optarg, NULL, 0);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
ipmitool_usage();
|
||||
goto out_free;
|
||||
@ -359,7 +394,7 @@ int main(int argc, char ** argv)
|
||||
|
||||
/* check for command before doing anything */
|
||||
if (argc-optind <= 0) {
|
||||
printf("No command provided!\n");
|
||||
lprintf(LOG_ERR, "No command provided!");
|
||||
ipmitool_usage();
|
||||
goto out_free;
|
||||
}
|
||||
@ -371,7 +406,7 @@ int main(int argc, char ** argv)
|
||||
/* load interface */
|
||||
intf = ipmi_intf_load(intfname);
|
||||
if (!intf) {
|
||||
printf("Error loading interface %s\n", intfname);
|
||||
lprintf(LOG_ERR, "Error loading interface %s", intfname);
|
||||
goto out_free;
|
||||
}
|
||||
|
||||
@ -385,18 +420,42 @@ int main(int argc, char ** argv)
|
||||
/* setup log */
|
||||
log_init(progname, 0, verbose);
|
||||
|
||||
/*
|
||||
* If the user has specified a hostname (-H option)
|
||||
* then this is a remote access session.
|
||||
*
|
||||
* If no password was specified by any other method
|
||||
* and the authtype was not explicitly set to NONE
|
||||
* then prompt the user.
|
||||
*/
|
||||
if (hostname != NULL && password == NULL &&
|
||||
(authtype != IPMI_SESSION_AUTHTYPE_NONE || authtype < 0)) {
|
||||
#ifdef HAVE_GETPASSPHRASE
|
||||
tmp = getpassphrase("Password: ");
|
||||
#else
|
||||
tmp = getpass("Password: ");
|
||||
#endif
|
||||
if (tmp != NULL) {
|
||||
password = strdup(tmp);
|
||||
if (password == NULL) {
|
||||
lprintf(LOG_ERR, "ipmitool: malloc failure");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* set session variables */
|
||||
if (hostname)
|
||||
if (hostname != NULL)
|
||||
ipmi_intf_session_set_hostname(intf, hostname);
|
||||
if (username)
|
||||
if (username != NULL)
|
||||
ipmi_intf_session_set_username(intf, username);
|
||||
if (password)
|
||||
if (password != NULL)
|
||||
ipmi_intf_session_set_password(intf, password);
|
||||
if (port)
|
||||
if (port > 0)
|
||||
ipmi_intf_session_set_port(intf, port);
|
||||
if (authtype)
|
||||
ipmi_intf_session_set_authtype(intf, authtype);
|
||||
if (privlvl)
|
||||
if (authtype >= 0)
|
||||
ipmi_intf_session_set_authtype(intf, (unsigned char)authtype);
|
||||
if (privlvl > 0)
|
||||
ipmi_intf_session_set_privlvl(intf, privlvl);
|
||||
else
|
||||
ipmi_intf_session_set_privlvl(intf,
|
||||
@ -404,9 +463,9 @@ int main(int argc, char ** argv)
|
||||
|
||||
/* setup IPMB local and target address if given */
|
||||
intf->my_addr = my_addr ? : IPMI_BMC_SLAVE_ADDR;
|
||||
if (target_addr) {
|
||||
if (target_addr > 0) {
|
||||
/* need to open the interface first */
|
||||
if (intf->open)
|
||||
if (intf->open != NULL)
|
||||
intf->open(intf);
|
||||
intf->target_addr = target_addr;
|
||||
/* must be admin level to do this over lan */
|
||||
@ -414,12 +473,16 @@ int main(int argc, char ** argv)
|
||||
}
|
||||
|
||||
/* now we finally run the command */
|
||||
ipmi_cmd_run(intf, argv[optind], argc-optind-1, &(argv[optind+1]));
|
||||
rc = ipmi_cmd_run(intf,
|
||||
argv[optind],
|
||||
argc-optind-1,
|
||||
&(argv[optind+1]));
|
||||
|
||||
/* clean repository caches */
|
||||
ipmi_cleanup(intf);
|
||||
|
||||
if (intf->opened && intf->close)
|
||||
/* call interface close function if available */
|
||||
if (intf->opened > 0 && intf->close != NULL)
|
||||
intf->close(intf);
|
||||
|
||||
out_free:
|
||||
|
@ -36,8 +36,8 @@ MAINTAINERCLEANFILES = Makefile.in
|
||||
|
||||
INCLUDES = -I$(top_srcdir)/include
|
||||
|
||||
SUBDIRS = @INTF_LAN@ @INTF_LANPLUS@ @INTF_OPEN@ @INTF_LIPMI@ @INTF_IMB@
|
||||
DIST_SUBDIRS = lan lanplus open lipmi imb
|
||||
SUBDIRS = @INTF_LAN@ @INTF_LANPLUS@ @INTF_OPEN@ @INTF_LIPMI@ @INTF_IMB@ @INTF_BMC@
|
||||
DIST_SUBDIRS = lan lanplus open lipmi imb bmc
|
||||
|
||||
noinst_LTLIBRARIES = libintf.la
|
||||
libintf_la_SOURCES = ipmi_intf.c
|
||||
|
@ -41,6 +41,7 @@
|
||||
#include <config.h>
|
||||
#include <ipmitool/ipmi_intf.h>
|
||||
#include <ipmitool/ipmi.h>
|
||||
#include <ipmitool/log.h>
|
||||
|
||||
#ifdef IPMI_INTF_OPEN
|
||||
extern struct ipmi_intf ipmi_open_intf;
|
||||
@ -51,6 +52,9 @@ extern struct ipmi_intf ipmi_imb_intf;
|
||||
#ifdef IPMI_INTF_LIPMI
|
||||
extern struct ipmi_intf ipmi_lipmi_intf;
|
||||
#endif
|
||||
#ifdef IPMI_INTF_BMC
|
||||
extern struct ipmi_intf ipmi_bmc_intf;
|
||||
#endif
|
||||
#ifdef IPMI_INTF_LAN
|
||||
extern struct ipmi_intf ipmi_lan_intf;
|
||||
#endif
|
||||
@ -68,6 +72,9 @@ struct ipmi_intf * ipmi_intf_table[] = {
|
||||
#ifdef IPMI_INTF_LIPMI
|
||||
&ipmi_lipmi_intf,
|
||||
#endif
|
||||
#ifdef IPMI_INTF_BMC
|
||||
&ipmi_bmc_intf,
|
||||
#endif
|
||||
#ifdef IPMI_INTF_LAN
|
||||
&ipmi_lan_intf,
|
||||
#endif
|
||||
@ -77,106 +84,141 @@ struct ipmi_intf * ipmi_intf_table[] = {
|
||||
NULL
|
||||
};
|
||||
|
||||
/* ipmi_intf_print - Print list of interfaces
|
||||
*
|
||||
* no meaningful return code
|
||||
*/
|
||||
void ipmi_intf_print(void)
|
||||
{
|
||||
struct ipmi_intf ** intf;
|
||||
int def = 1;
|
||||
|
||||
printf("Interfaces:\n");
|
||||
lprintf(LOG_NOTICE, "Interfaces:");
|
||||
|
||||
for (intf = ipmi_intf_table; intf && *intf; intf++) {
|
||||
printf("\t%-12s %s", (*intf)->name, (*intf)->desc);
|
||||
if (def) {
|
||||
printf(" [default]");
|
||||
def = 0;
|
||||
}
|
||||
printf("\n");
|
||||
lprintf(LOG_NOTICE, "\t%-12s %s %s",
|
||||
(*intf)->name, (*intf)->desc,
|
||||
def ? "[default]" : "");
|
||||
def = 0;
|
||||
}
|
||||
printf("\n");
|
||||
lprintf(LOG_NOTICE, "");
|
||||
}
|
||||
|
||||
/* Load an interface from the interface table above
|
||||
* If no interface name is given return first entry
|
||||
/* ipmi_intf_load - Load an interface from the interface table above
|
||||
* If no interface name is given return first entry
|
||||
*
|
||||
* @name: interface name to try and load
|
||||
*
|
||||
* returns pointer to inteface structure if found
|
||||
* returns NULL on error
|
||||
*/
|
||||
struct ipmi_intf * ipmi_intf_load(char * name)
|
||||
{
|
||||
struct ipmi_intf ** intf;
|
||||
struct ipmi_intf * i;
|
||||
|
||||
if (!name) {
|
||||
if (name == NULL) {
|
||||
i = ipmi_intf_table[0];
|
||||
if (i->setup && (i->setup(i) < 0)) {
|
||||
printf("ERROR: Unable to setup interface %s\n", name);
|
||||
if (i->setup != NULL && (i->setup(i) < 0)) {
|
||||
lprintf(LOG_ERR, "Unable to setup "
|
||||
"interface %s", name);
|
||||
return NULL;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
for (intf = ipmi_intf_table; intf && *intf ; intf++) {
|
||||
for (intf = ipmi_intf_table;
|
||||
((intf != NULL) && (*intf != NULL));
|
||||
intf++) {
|
||||
i = *intf;
|
||||
if (!strncmp(name, i->name, strlen(name))) {
|
||||
if (i->setup && (i->setup(i) < 0)) {
|
||||
printf("ERROR: Unable to setup interface %s\n", name);
|
||||
if (strncmp(name, i->name, strlen(name)) == 0) {
|
||||
if (i->setup != NULL && (i->setup(i) < 0)) {
|
||||
lprintf(LOG_ERR, "Unable to setup "
|
||||
"interface %s", name);
|
||||
return NULL;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void ipmi_intf_session_set_hostname(struct ipmi_intf * intf, char * hostname)
|
||||
void
|
||||
ipmi_intf_session_set_hostname(struct ipmi_intf * intf, char * hostname)
|
||||
{
|
||||
if (intf && intf->session) {
|
||||
memset(intf->session->hostname, 0, 16);
|
||||
if (hostname)
|
||||
memcpy(intf->session->hostname, hostname, min(strlen(hostname), 64));
|
||||
if (intf->session == NULL)
|
||||
return;
|
||||
|
||||
memset(intf->session->hostname, 0, 16);
|
||||
|
||||
if (hostname != NULL) {
|
||||
memcpy(intf->session->hostname, hostname,
|
||||
min(strlen(hostname), 64));
|
||||
}
|
||||
}
|
||||
|
||||
void ipmi_intf_session_set_username(struct ipmi_intf * intf, char * username)
|
||||
void
|
||||
ipmi_intf_session_set_username(struct ipmi_intf * intf, char * username)
|
||||
{
|
||||
if (intf && intf->session) {
|
||||
memset(intf->session->username, 0, 16);
|
||||
if (username)
|
||||
memcpy(intf->session->username, username, min(strlen(username), 16));
|
||||
}
|
||||
if (intf->session == NULL)
|
||||
return;
|
||||
|
||||
memset(intf->session->username, 0, 16);
|
||||
|
||||
if (username == NULL)
|
||||
return;
|
||||
|
||||
memcpy(intf->session->username, username, min(strlen(username), 16));
|
||||
}
|
||||
|
||||
void ipmi_intf_session_set_password(struct ipmi_intf * intf, char * password)
|
||||
void
|
||||
ipmi_intf_session_set_password(struct ipmi_intf * intf, char * password)
|
||||
{
|
||||
if (intf && intf->session) {
|
||||
memset(intf->session->authcode, 0, sizeof(intf->session->authcode));
|
||||
if (intf->session == NULL)
|
||||
return;
|
||||
|
||||
memset(intf->session->authcode, 0, IPMI_AUTHCODE_BUFFER_SIZE);
|
||||
|
||||
if (password == NULL) {
|
||||
intf->session->password = 0;
|
||||
if (password) {
|
||||
intf->session->password = 1;
|
||||
memset(intf->session->authcode, 0, IPMI_AUTHCODE_BUFFER_SIZE);
|
||||
memcpy(intf->session->authcode,
|
||||
password,
|
||||
min(strlen(password), IPMI_AUTHCODE_BUFFER_SIZE));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
intf->session->password = 1;
|
||||
memcpy(intf->session->authcode, password,
|
||||
min(strlen(password), IPMI_AUTHCODE_BUFFER_SIZE));
|
||||
}
|
||||
|
||||
void ipmi_intf_session_set_privlvl(struct ipmi_intf * intf, unsigned char level)
|
||||
void
|
||||
ipmi_intf_session_set_privlvl(struct ipmi_intf * intf, unsigned char level)
|
||||
{
|
||||
if (intf && intf->session)
|
||||
intf->session->privlvl = level;
|
||||
if (intf->session == NULL)
|
||||
return;
|
||||
|
||||
intf->session->privlvl = level;
|
||||
}
|
||||
|
||||
void ipmi_intf_session_set_port(struct ipmi_intf * intf, int port)
|
||||
void
|
||||
ipmi_intf_session_set_port(struct ipmi_intf * intf, int port)
|
||||
{
|
||||
if (intf && intf->session)
|
||||
intf->session->port = port;
|
||||
if (intf->session == NULL)
|
||||
return;
|
||||
|
||||
intf->session->port = port;
|
||||
}
|
||||
|
||||
void ipmi_intf_session_set_authtype(struct ipmi_intf * intf, unsigned char authtype)
|
||||
void
|
||||
ipmi_intf_session_set_authtype(struct ipmi_intf * intf, unsigned char authtype)
|
||||
{
|
||||
if (intf && intf->session)
|
||||
intf->session->authtype_set = authtype;
|
||||
if (intf->session == NULL)
|
||||
return;
|
||||
|
||||
intf->session->authtype_set = authtype;
|
||||
}
|
||||
|
||||
void ipmi_cleanup(struct ipmi_intf * intf)
|
||||
void
|
||||
ipmi_cleanup(struct ipmi_intf * intf)
|
||||
{
|
||||
ipmi_sdr_list_empty(intf);
|
||||
}
|
||||
|
@ -139,24 +139,25 @@ ipmi_req_add_entry(struct ipmi_intf * intf, struct ipmi_rq * req)
|
||||
{
|
||||
struct ipmi_rq_entry * e = malloc(sizeof(struct ipmi_rq_entry));
|
||||
|
||||
if (e == NULL)
|
||||
printf("WARNING: no memory!\n");
|
||||
else {
|
||||
memset(e, 0, sizeof(struct ipmi_rq_entry));
|
||||
memcpy(&e->req, req, sizeof(struct ipmi_rq));
|
||||
|
||||
e->intf = intf;
|
||||
|
||||
if (!ipmi_req_entries) {
|
||||
ipmi_req_entries = e;
|
||||
} else {
|
||||
ipmi_req_entries_tail->next = e;
|
||||
}
|
||||
ipmi_req_entries_tail = e;
|
||||
if (verbose > 3)
|
||||
printf("added list entry seq=0x%02x cmd=0x%02x\n",
|
||||
e->rq_seq, e->req.msg.cmd);
|
||||
if (e == NULL) {
|
||||
fprintf(stderr, "ipmitool: malloc failure\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(e, 0, sizeof(struct ipmi_rq_entry));
|
||||
memcpy(&e->req, req, sizeof(struct ipmi_rq));
|
||||
|
||||
e->intf = intf;
|
||||
|
||||
if (!ipmi_req_entries)
|
||||
ipmi_req_entries = e;
|
||||
else
|
||||
ipmi_req_entries_tail->next = e;
|
||||
|
||||
ipmi_req_entries_tail = e;
|
||||
if (verbose > 3)
|
||||
printf("added list entry seq=0x%02x cmd=0x%02x\n",
|
||||
e->rq_seq, e->req.msg.cmd);
|
||||
return e;
|
||||
}
|
||||
|
||||
@ -381,6 +382,10 @@ ipmi_lan_ping(struct ipmi_intf * intf)
|
||||
int rv;
|
||||
|
||||
data = malloc(len);
|
||||
if (data == NULL) {
|
||||
fprintf(stderr, "ipmitool: malloc failure\n");
|
||||
return -1;
|
||||
}
|
||||
memset(data, 0, len);
|
||||
memcpy(data, &rmcp_ping, sizeof(rmcp_ping));
|
||||
memcpy(data+sizeof(rmcp_ping), &asf_ping, sizeof(asf_ping));
|
||||
@ -591,6 +596,10 @@ ipmi_lan_build_cmd(struct ipmi_intf * intf, struct ipmi_rq * req)
|
||||
if (s->active && s->authtype)
|
||||
len += 16;
|
||||
msg = malloc(len);
|
||||
if (msg == NULL) {
|
||||
fprintf(stderr, "ipmitool: malloc failure\n");
|
||||
return NULL;
|
||||
}
|
||||
memset(msg, 0, len);
|
||||
|
||||
/* rmcp header */
|
||||
@ -719,8 +728,10 @@ ipmi_lan_send_cmd(struct ipmi_intf * intf, struct ipmi_rq * req)
|
||||
struct ipmi_rs * rsp;
|
||||
int try = 0;
|
||||
|
||||
if (!intf->opened && intf->open && intf->open(intf) < 0)
|
||||
return NULL;
|
||||
if (intf->opened == 0 && intf->open != NULL) {
|
||||
if (intf->open(intf) < 0)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
entry = ipmi_lan_build_cmd(intf, req);
|
||||
if (!entry) {
|
||||
@ -772,6 +783,10 @@ unsigned char * ipmi_lan_build_rsp(struct ipmi_intf * intf, struct ipmi_rs * rsp
|
||||
len += 16;
|
||||
|
||||
msg = malloc(len);
|
||||
if (msg == NULL) {
|
||||
fprintf(stderr, "ipmitool: malloc failure\n");
|
||||
return NULL;
|
||||
}
|
||||
memset(msg, 0, len);
|
||||
|
||||
/* rmcp header */
|
||||
@ -1413,6 +1428,10 @@ int ipmi_lan_open(struct ipmi_intf * intf)
|
||||
static int ipmi_lan_setup(struct ipmi_intf * intf)
|
||||
{
|
||||
intf->session = malloc(sizeof(struct ipmi_session));
|
||||
if (intf->session == NULL) {
|
||||
fprintf(stderr, "ipmitool: malloc failure\n");
|
||||
return -1;
|
||||
}
|
||||
memset(intf->session, 0, sizeof(struct ipmi_session));
|
||||
return (intf->session) ? 0 : -1;
|
||||
return 0;
|
||||
}
|
||||
|
@ -60,30 +60,35 @@
|
||||
extern int verbose;
|
||||
|
||||
#define IPMI_OPENIPMI_DEV "/dev/ipmi0"
|
||||
#define IPMI_OPENIPMI_DEVFS "/dev/ipmi/0"
|
||||
|
||||
static int ipmi_openipmi_open(struct ipmi_intf * intf)
|
||||
static int
|
||||
ipmi_openipmi_open(struct ipmi_intf * intf)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
intf->fd = open(IPMI_OPENIPMI_DEV, O_RDWR);
|
||||
|
||||
if (intf->fd < 0) {
|
||||
lperror(LOG_ERR, "Could not open ipmi device");
|
||||
intf->fd = open(IPMI_OPENIPMI_DEVFS, O_RDWR);
|
||||
lperror(LOG_ERR, "intf_open: Could not open device at %s or %s",
|
||||
IPMI_OPENIPMI_DEV, IPMI_OPENIPMI_DEVFS);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (ioctl(intf->fd, IPMICTL_SET_GETS_EVENTS_CMD, &i)) {
|
||||
lperror(LOG_ERR, "Could not set to get events");
|
||||
if (ioctl(intf->fd, IPMICTL_SET_GETS_EVENTS_CMD, &i) < 0) {
|
||||
lperror(LOG_ERR, "intf_open: Could not enable event receiver");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (intf->my_addr) {
|
||||
if (intf->my_addr != 0) {
|
||||
unsigned int a = intf->my_addr;
|
||||
if (ioctl(intf->fd, IPMICTL_SET_MY_ADDRESS_CMD, &a)) {
|
||||
lperror(LOG_ERR, "Could not set IPMB address");
|
||||
if (ioctl(intf->fd, IPMICTL_SET_MY_ADDRESS_CMD, &a) < 0) {
|
||||
lperror(LOG_ERR, "intf_open: Could not set IPMB address");
|
||||
return -1;
|
||||
}
|
||||
lprintf(LOG_DEBUG, "Set my IPMB address to 0x%x", intf->my_addr);
|
||||
lprintf(LOG_DEBUG, "intf_open: Set IPMB address to 0x%x",
|
||||
intf->my_addr);
|
||||
}
|
||||
|
||||
intf->opened = 1;
|
||||
@ -91,14 +96,19 @@ static int ipmi_openipmi_open(struct ipmi_intf * intf)
|
||||
return intf->fd;
|
||||
}
|
||||
|
||||
static void ipmi_openipmi_close(struct ipmi_intf * intf)
|
||||
static void
|
||||
ipmi_openipmi_close(struct ipmi_intf * intf)
|
||||
{
|
||||
if (intf && intf->fd >= 0)
|
||||
if (intf->fd >= 0) {
|
||||
close(intf->fd);
|
||||
intf->fd = -1;
|
||||
}
|
||||
|
||||
intf->opened = 0;
|
||||
}
|
||||
|
||||
static struct ipmi_rs *ipmi_openipmi_send_cmd(struct ipmi_intf * intf, struct ipmi_rq * req)
|
||||
static struct ipmi_rs *
|
||||
ipmi_openipmi_send_cmd(struct ipmi_intf * intf, struct ipmi_rq * req)
|
||||
{
|
||||
struct ipmi_recv recv;
|
||||
struct ipmi_addr addr;
|
||||
@ -114,13 +124,15 @@ static struct ipmi_rs *ipmi_openipmi_send_cmd(struct ipmi_intf * intf, struct ip
|
||||
static int curr_seq = 0;
|
||||
fd_set rset;
|
||||
|
||||
if (!intf || !req)
|
||||
return NULL;
|
||||
if (!intf->opened && intf->open && intf->open(intf) < 0)
|
||||
if (intf == NULL || req == NULL)
|
||||
return NULL;
|
||||
if (intf->opened == 0 && intf->open != NULL)
|
||||
if (intf->open(intf) < 0)
|
||||
return NULL;
|
||||
|
||||
if (verbose > 2)
|
||||
printbuf(req->msg.data, req->msg.data_len, "send_cmd");
|
||||
printbuf(req->msg.data, req->msg.data_len,
|
||||
"intf_open: request message");
|
||||
|
||||
/*
|
||||
* setup and send message
|
||||
@ -128,17 +140,18 @@ static struct ipmi_rs *ipmi_openipmi_send_cmd(struct ipmi_intf * intf, struct ip
|
||||
|
||||
memset(&_req, 0, sizeof(struct ipmi_req));
|
||||
|
||||
if (intf->target_addr &&
|
||||
if (intf->target_addr != 0 &&
|
||||
intf->target_addr != intf->my_addr) {
|
||||
/* use IPMB address if needed */
|
||||
ipmb_addr.slave_addr = intf->target_addr;
|
||||
_req.addr = (char *) &ipmb_addr;
|
||||
_req.addr_len = sizeof(ipmb_addr);
|
||||
lprintf(LOG_DEBUG, "Sending request to IPMB target @ 0x%x",
|
||||
intf->target_addr);
|
||||
lprintf(LOG_DEBUG, "intf_open: Sending request to "
|
||||
"IPMB target @ 0x%x", intf->target_addr);
|
||||
} else {
|
||||
/* otherwise use system interface */
|
||||
lprintf(LOG_DEBUG+2, "Sending request to System Interface");
|
||||
lprintf(LOG_DEBUG+2, "intf_open: Sending request to "
|
||||
"System Interface");
|
||||
_req.addr = (char *) &bmc_addr;
|
||||
_req.addr_len = sizeof(bmc_addr);
|
||||
}
|
||||
@ -150,7 +163,7 @@ static struct ipmi_rs *ipmi_openipmi_send_cmd(struct ipmi_intf * intf, struct ip
|
||||
_req.msg.data_len = req->msg.data_len;
|
||||
|
||||
if (ioctl(intf->fd, IPMICTL_SEND_COMMAND, &_req) < 0) {
|
||||
lperror(LOG_ERR, "Error sending command");
|
||||
lperror(LOG_ERR, "intf_open: Unable to send command");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -162,11 +175,11 @@ static struct ipmi_rs *ipmi_openipmi_send_cmd(struct ipmi_intf * intf, struct ip
|
||||
FD_SET(intf->fd, &rset);
|
||||
|
||||
if (select(intf->fd+1, &rset, NULL, NULL, NULL) < 0) {
|
||||
lperror(LOG_ERR, "Error doing select");
|
||||
lperror(LOG_ERR, "intf_open: I/O Error");
|
||||
return NULL;
|
||||
}
|
||||
if (!FD_ISSET(intf->fd, &rset)) {
|
||||
lprintf(LOG_ERR, "Error no data available");
|
||||
if (FD_ISSET(intf->fd, &rset) == 0) {
|
||||
lprintf(LOG_ERR, "intf_open: No data available");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -177,7 +190,7 @@ static struct ipmi_rs *ipmi_openipmi_send_cmd(struct ipmi_intf * intf, struct ip
|
||||
|
||||
/* get data */
|
||||
if (ioctl(intf->fd, IPMICTL_RECEIVE_MSG_TRUNC, &recv) < 0) {
|
||||
lperror(LOG_ERR, "Error receiving message");
|
||||
lperror(LOG_ERR, "intf_open: Error receiving message");
|
||||
if (errno != EMSGSIZE)
|
||||
return NULL;
|
||||
}
|
||||
@ -201,7 +214,7 @@ static struct ipmi_rs *ipmi_openipmi_send_cmd(struct ipmi_intf * intf, struct ip
|
||||
rsp.data_len = recv.msg.data_len - 1;
|
||||
|
||||
/* save response data for caller */
|
||||
if (!rsp.ccode && rsp.data_len) {
|
||||
if (rsp.ccode == 0 && rsp.data_len > 0) {
|
||||
memmove(rsp.data, rsp.data + 1, rsp.data_len);
|
||||
rsp.data[recv.msg.data_len] = 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user