ID: 3597471 - 'lib/ipmi_mc.c' - needs a bit of re-work - rc, inv. options

Commit fixes 'help' and return codes(help =~ 0, invalid > 1). Indentation of
file as well as some formatting changes were made as well.
This commit is contained in:
Zdenek Styblik 2012-12-20 14:25:18 +00:00
parent 5dbb6b69de
commit 2bb3100395

View File

@ -169,6 +169,12 @@ struct bitfield_data mc_enables_bf[] = {
{ NULL }, { NULL },
}; };
static void
printf_mc_reset_usage(void)
{
lprintf(LOG_NOTICE, "usage: mc reset <warm|cold>");
} /* printf_mc_reset_usage(void) */
static void static void
printf_mc_usage(void) printf_mc_usage(void)
{ {
@ -207,7 +213,6 @@ print_watchdog_usage(void)
lprintf(LOG_NOTICE, " off : Shut off a running Watchdog timer"); lprintf(LOG_NOTICE, " off : Shut off a running Watchdog timer");
} }
/* ipmi_mc_get_enables - print out MC enables /* ipmi_mc_get_enables - print out MC enables
* *
* @intf: ipmi inteface * @intf: ipmi inteface
@ -263,7 +268,11 @@ ipmi_mc_set_enables(struct ipmi_intf * intf, int argc, char ** argv)
uint8_t en; uint8_t en;
int i; int i;
if (argc < 1 || strncmp(argv[0], "help", 4) == 0) { if (argc < 1) {
printf_mc_usage();
return (-1);
}
else if (strncmp(argv[0], "help", 4) == 0) {
printf_mc_usage(); printf_mc_usage();
return 0; return 0;
} }
@ -653,11 +662,10 @@ ipmi_mc_get_watchdog(struct ipmi_intf * intf)
printf("Pre-timeout interval: %d seconds\n", wdt_res->pre_timeout); printf("Pre-timeout interval: %d seconds\n", wdt_res->pre_timeout);
printf("Timer Expiration Flags: 0x%02x\n", wdt_res->timer_use_exp); printf("Timer Expiration Flags: 0x%02x\n", wdt_res->timer_use_exp);
printf("Initial Countdown: %i sec\n", printf("Initial Countdown: %i sec\n",
((wdt_res->initial_countdown_msb << 8) | wdt_res->initial_countdown_lsb)/10 ); ((wdt_res->initial_countdown_msb << 8) | wdt_res->initial_countdown_lsb)/10);
printf("Present Countdown: %i sec\n", printf("Present Countdown: %i sec\n",
(((wdt_res->present_countdown_msb << 8) | wdt_res->present_countdown_lsb)) / 10); (((wdt_res->present_countdown_msb << 8) | wdt_res->present_countdown_lsb)) / 10);
return 0; return 0;
} }
@ -695,10 +703,10 @@ ipmi_mc_shutoff_watchdog(struct ipmi_intf * intf)
msg_data[0] = IPM_WATCHDOG_SMS_OS; msg_data[0] = IPM_WATCHDOG_SMS_OS;
msg_data[1] = IPM_WATCHDOG_NO_ACTION; msg_data[1] = IPM_WATCHDOG_NO_ACTION;
msg_data[2] = 0x00; // pretimeout interval msg_data[2] = 0x00; /* pretimeout interval */
msg_data[3] = IPM_WATCHDOG_CLEAR_SMS_OS; msg_data[3] = IPM_WATCHDOG_CLEAR_SMS_OS;
msg_data[4] = 0xb8; // countdown lsb (100 ms/count) msg_data[4] = 0xb8; /* countdown lsb (100 ms/count) */
msg_data[5] = 0x0b; // countdown msb - 5 mins msg_data[5] = 0x0b; /* countdown msb - 5 mins */
rsp = intf->sendrecv(intf, &req); rsp = intf->sendrecv(intf, &req);
if (rsp == NULL) { if (rsp == NULL) {
@ -767,12 +775,24 @@ ipmi_mc_main(struct ipmi_intf * intf, int argc, char ** argv)
{ {
int rc = 0; int rc = 0;
if (argc < 1 || strncmp(argv[0], "help", 4) == 0) { if (argc < 1) {
lprintf(LOG_ERR, "Not enough parameters given.");
printf_mc_usage(); printf_mc_usage();
rc = (-1);
}
else if (strncmp(argv[0], "help", 4) == 0) {
printf_mc_usage();
rc = 0;
} }
else if (strncmp(argv[0], "reset", 5) == 0) { else if (strncmp(argv[0], "reset", 5) == 0) {
if (argc < 2 || strncmp(argv[1], "help", 4) == 0) { if (argc < 2) {
lprintf(LOG_ERR, "reset commands: warm, cold"); lprintf(LOG_ERR, "Not enough parameters given.");
printf_mc_reset_usage();
rc = (-1);
}
else if (strncmp(argv[1], "help", 4) == 0) {
printf_mc_reset_usage();
rc = 0;
} }
else if (strncmp(argv[1], "cold", 4) == 0) { else if (strncmp(argv[1], "cold", 4) == 0) {
rc = ipmi_mc_reset(intf, BMC_COLD_RESET); rc = ipmi_mc_reset(intf, BMC_COLD_RESET);
@ -781,7 +801,9 @@ ipmi_mc_main(struct ipmi_intf * intf, int argc, char ** argv)
rc = ipmi_mc_reset(intf, BMC_WARM_RESET); rc = ipmi_mc_reset(intf, BMC_WARM_RESET);
} }
else { else {
lprintf(LOG_ERR, "reset commands: warm, cold"); lprintf(LOG_ERR, "Invalid mc/bmc %s command: %s", argv[0], argv[1]);
printf_mc_reset_usage();
rc = (-1);
} }
} }
else if (strncmp(argv[0], "info", 4) == 0) { else if (strncmp(argv[0], "info", 4) == 0) {
@ -800,8 +822,14 @@ ipmi_mc_main(struct ipmi_intf * intf, int argc, char ** argv)
rc = ipmi_mc_get_selftest(intf); rc = ipmi_mc_get_selftest(intf);
} }
else if (!strncmp(argv[0], "watchdog", 8)) { else if (!strncmp(argv[0], "watchdog", 8)) {
if (argc < 2 || strncmp(argv[1], "help", 4) == 0) { if (argc < 2) {
lprintf(LOG_ERR, "Not enough parameters given.");
print_watchdog_usage(); print_watchdog_usage();
rc = (-1);
}
else if (strncmp(argv[1], "help", 4) == 0) {
print_watchdog_usage();
rc = 0;
} }
else if (strncmp(argv[1], "get", 3) == 0) { else if (strncmp(argv[1], "get", 3) == 0) {
rc = ipmi_mc_get_watchdog(intf); rc = ipmi_mc_get_watchdog(intf);
@ -813,22 +841,26 @@ ipmi_mc_main(struct ipmi_intf * intf, int argc, char ** argv)
rc = ipmi_mc_rst_watchdog(intf); rc = ipmi_mc_rst_watchdog(intf);
} }
else { else {
lprintf(LOG_ERR, "Invalid mc/bmc %s command: %s", argv[0], argv[1]);
print_watchdog_usage(); print_watchdog_usage();
rc = (-1);
} }
} }
else if (!strncmp(argv[0], "getsysinfo", 10) || else if (strncmp(argv[0], "getsysinfo", 10) == 0
!strncmp(argv[0], "setsysinfo", 10)) { || strncmp(argv[0], "setsysinfo", 10) == 0) {
rc = ipmi_sysinfo_main(intf, argc, argv); rc = ipmi_sysinfo_main(intf, argc, argv);
} }
else { else {
lprintf(LOG_ERR, "Invalid mc/bmc command: %s", argv[0]); lprintf(LOG_ERR, "Invalid mc/bmc command: %s", argv[0]);
rc = -1; printf_mc_usage();
rc = (-1);
} }
return rc; return rc;
} }
static int sysinfo_param(struct ipmi_intf *intf, const char *str, int *maxset) static int
sysinfo_param(struct ipmi_intf *intf, const char *str, int *maxset)
{ {
*maxset = 4; *maxset = 4;
if (!strcmp(str, "system_name")) if (!strcmp(str, "system_name"))
@ -850,21 +882,25 @@ static int sysinfo_param(struct ipmi_intf *intf, const char *str, int *maxset)
return -1; return -1;
} }
static void ipmi_sysinfo_usage() static void
ipmi_sysinfo_usage()
{ {
lprintf(LOG_NOTICE, "usage:"); lprintf(LOG_NOTICE, "usage:");
lprintf(LOG_NOTICE, " getsysinfo argument"); lprintf(LOG_NOTICE, " getsysinfo argument");
lprintf(LOG_NOTICE, " Retrieves system info from bmc for given argument"); lprintf(LOG_NOTICE, " Retrieves system info from bmc for given argument");
lprintf(LOG_NOTICE, " setsysinfo argument string"); lprintf(LOG_NOTICE, " setsysinfo argument string");
lprintf(LOG_NOTICE, " Stores system info string for given argument to bmc"); lprintf(LOG_NOTICE,
" Stores system info string for given argument to bmc");
lprintf(LOG_NOTICE, ""); lprintf(LOG_NOTICE, "");
lprintf(LOG_NOTICE, " Valid arguments are:"); lprintf(LOG_NOTICE, " Valid arguments are:");
lprintf(LOG_NOTICE, " primary_os_name Primary operating system name"); lprintf(LOG_NOTICE,
" primary_os_name Primary operating system name");
lprintf(LOG_NOTICE, " os_name Operating system name"); lprintf(LOG_NOTICE, " os_name Operating system name");
lprintf(LOG_NOTICE, " system_name System Name of server (vendor dependent"); lprintf(LOG_NOTICE,
lprintf(LOG_NOTICE, " delloem_os_version Running version of operating system"); " system_name System Name of server (vendor dependent");
lprintf(LOG_NOTICE,
" delloem_os_version Running version of operating system");
lprintf(LOG_NOTICE, " delloem_url Url of bmc webserver"); lprintf(LOG_NOTICE, " delloem_url Url of bmc webserver");
lprintf(LOG_NOTICE, ""); lprintf(LOG_NOTICE, "");
} }
@ -902,17 +938,20 @@ ipmi_getsysinfo(struct ipmi_intf * intf, int param, int block, int set,
if (verbose > 1) if (verbose > 1)
printf("getsysinfo: %.2x/%.2x/%.2x\n", param, block, set); printf("getsysinfo: %.2x/%.2x/%.2x\n", param, block, set);
data[0] = 0; // get/set
data[0] = 0; /* get/set */
data[1] = param; data[1] = param;
data[2] = block; data[2] = block;
data[3] = set; data[3] = set;
// Format of get output is: /*
// u8 param_rev * Format of get output is:
// u8 selector * u8 param_rev
// u8 encoding bit[0-3]; * u8 selector
// u8 length * u8 encoding bit[0-3];
// u8 data0[14] * u8 length
* u8 data0[14]
*/
rsp = intf->sendrecv(intf, &req); rsp = intf->sendrecv(intf, &req);
if (rsp != NULL) { if (rsp != NULL) {
if (rsp->ccode == 0) { if (rsp->ccode == 0) {
@ -952,10 +991,12 @@ ipmi_setsysinfo(struct ipmi_intf * intf, int len, void *buffer)
req.msg.data_len = len; req.msg.data_len = len;
req.msg.data = buffer; req.msg.data = buffer;
// Format of set input: /*
// u8 param rev * Format of set input:
// u8 selector * u8 param rev
// u8 data1[16] * u8 selector
* u8 data1[16]
*/
rsp = intf->sendrecv(intf, &req); rsp = intf->sendrecv(intf, &req);
if (rsp != NULL) { if (rsp != NULL) {
return rsp->ccode; return rsp->ccode;
@ -963,8 +1004,8 @@ ipmi_setsysinfo(struct ipmi_intf * intf, int len, void *buffer)
return -1; return -1;
} }
static int
static int ipmi_sysinfo_main(struct ipmi_intf *intf, int argc, char ** argv) ipmi_sysinfo_main(struct ipmi_intf *intf, int argc, char ** argv)
{ {
int param, isset; int param, isset;
char *str; char *str;
@ -975,11 +1016,12 @@ static int ipmi_sysinfo_main(struct ipmi_intf *intf, int argc, char ** argv)
/* Is this a setsysinfo or getsysinfo */ /* Is this a setsysinfo or getsysinfo */
isset = !strncmp(argv[0], "setsysinfo\0",11); isset = !strncmp(argv[0], "setsysinfo\0",11);
if (argc == 1 || strcmp(argv[1], "help") == 0 || if (argc == 1 || strcmp(argv[1], "help") == 0
argc < (isset ? 3 : 2)) { || argc < (isset ? 3 : 2)) {
ipmi_sysinfo_usage(); ipmi_sysinfo_usage();
return 0; return 0;
} }
memset(infostr, 0, sizeof(infostr)); memset(infostr, 0, sizeof(infostr));
/* Get Parameters */ /* Get Parameters */
@ -998,14 +1040,15 @@ static int ipmi_sysinfo_main(struct ipmi_intf *intf, int argc, char ** argv)
/* first block holds 14 bytes, all others hold 16 */ /* first block holds 14 bytes, all others hold 16 */
if (((len + 2) + 15) / 16 >= maxset) if (((len + 2) + 15) / 16 >= maxset)
len = maxset * 16 - 2; len = maxset * 16 - 2;
do { do {
memset(paramdata, 0, sizeof(paramdata)); memset(paramdata, 0, sizeof(paramdata));
paramdata[0] = param; paramdata[0] = param;
paramdata[1] = set; paramdata[1] = set;
if (set == 0) { if (set == 0) {
/* First block is special case */ /* First block is special case */
paramdata[2] = 0; // ascii encoding paramdata[2] = 0; /* ascii encoding */
paramdata[3] = len; // length; paramdata[3] = len; /* length */
strncpy(paramdata+4, str+pos, IPMI_SYSINFO_SET0_SIZE); strncpy(paramdata+4, str+pos, IPMI_SYSINFO_SET0_SIZE);
pos += IPMI_SYSINFO_SET0_SIZE; pos += IPMI_SYSINFO_SET0_SIZE;
} else { } else {
@ -1013,8 +1056,10 @@ static int ipmi_sysinfo_main(struct ipmi_intf *intf, int argc, char ** argv)
pos += IPMI_SYSINFO_SETN_SIZE; pos += IPMI_SYSINFO_SETN_SIZE;
} }
rc = ipmi_setsysinfo(intf, 18, paramdata); rc = ipmi_setsysinfo(intf, 18, paramdata);
if (rc) if (rc)
break; break;
set++; set++;
} while (pos < len); } while (pos < len);
} else { } else {
@ -1022,8 +1067,10 @@ static int ipmi_sysinfo_main(struct ipmi_intf *intf, int argc, char ** argv)
pos = 0; pos = 0;
for (set=0; set<maxset; set++) { for (set=0; set<maxset; set++) {
rc = ipmi_getsysinfo(intf, param, set, 0, 18, paramdata); rc = ipmi_getsysinfo(intf, param, set, 0, 18, paramdata);
if (rc) if (rc)
break; break;
if (set == 0) { if (set == 0) {
/* First block is special case */ /* First block is special case */
if ((paramdata[2] & 0xF) == 0) { if ((paramdata[2] & 0xF) == 0) {