summaryrefslogtreecommitdiff
path: root/lib/ipmi_sol.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/ipmi_sol.c')
-rw-r--r--lib/ipmi_sol.c106
1 files changed, 51 insertions, 55 deletions
diff --git a/lib/ipmi_sol.c b/lib/ipmi_sol.c
index 3acd5bb..8e7285c 100644
--- a/lib/ipmi_sol.c
+++ b/lib/ipmi_sol.c
@@ -29,11 +29,6 @@
* LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE,
* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*/
-#define _XOPEN_SOURCE
-#define _BSD_SOURCE || \
- (_XOPEN_SOURCE >= 500 || \
- _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED) && \
- !(_POSIX_C_SOURCE >= 200809L || _XOPEN_SOURCE >= 700)
#include <stdlib.h>
#include <string.h>
@@ -130,11 +125,11 @@ ipmi_sol_payload_access(struct ipmi_intf * intf, uint8_t channel,
/* payload 1 is SOL */
data[2] = 0x02;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error %sabling SOL payload for user %d on channel %d",
enable ? "en" : "dis", userid, channel);
rc = (-1);
- } else if (rsp->ccode != 0) {
+ } else if (rsp->ccode) {
lprintf(LOG_ERR, "Error %sabling SOL payload for user %d on channel %d: %s",
enable ? "en" : "dis", userid, channel,
val2str(rsp->ccode, completion_code_vals));
@@ -164,7 +159,7 @@ ipmi_sol_payload_access_status(struct ipmi_intf * intf,
data[1] = userid & 0x3f; /* user id */
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error. No valid response received.");
return -1;
}
@@ -219,7 +214,7 @@ ipmi_get_sol_info(
data[3] = 0x00; /* block selector */
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error: No response requesting SOL parameter '%s'",
val2str(data[1], sol_parameter_vals));
return (-1);
@@ -257,7 +252,7 @@ ipmi_get_sol_info(
data[3] = 0x00; /* block selector */
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error: No response requesting SOL parameter '%s'",
val2str(data[1], sol_parameter_vals));
return (-1);
@@ -295,7 +290,7 @@ ipmi_get_sol_info(
data[3] = 0x00; /* block selector */
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error: No response requesting SOL parameter '%s'",
val2str(data[1], sol_parameter_vals));
return (-1);
@@ -335,7 +330,7 @@ ipmi_get_sol_info(
data[3] = 0x00; /* block selector */
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error: No response requesting SOL parameter '%s'",
val2str(data[1], sol_parameter_vals));
return (-1);
@@ -374,7 +369,7 @@ ipmi_get_sol_info(
data[3] = 0x00; /* block selector */
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error: No response requesting SOL parameter '%s'",
val2str(data[1], sol_parameter_vals));
return (-1);
@@ -413,7 +408,7 @@ ipmi_get_sol_info(
data[3] = 0x00; /* block selector */
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error: No response requesting SOL parameter '%s'",
val2str(data[1], sol_parameter_vals));
return (-1);
@@ -451,7 +446,7 @@ ipmi_get_sol_info(
data[3] = 0x00; /* block selector */
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error: No response requesting SOL parameter '%s'",
val2str(data[1], sol_parameter_vals));
return (-1);
@@ -489,7 +484,7 @@ ipmi_get_sol_info(
data[3] = 0x00; /* block selector */
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error: No response requesting SOL parameter '%s'",
val2str(data[1], sol_parameter_vals));
return (-1);
@@ -528,7 +523,7 @@ ipmi_get_sol_info(
data[3] = 0x00; /* block selector */
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error: No response requesting SOL parameter '%s'",
val2str(data[1], sol_parameter_vals));
return (-1);
@@ -546,7 +541,7 @@ ipmi_get_sol_info(
}
break;
case 0x80:
- if( intf->session != NULL ) {
+ if (intf->session) {
lprintf(LOG_ERR, "Info: SOL parameter '%s' not supported - defaulting to %d",
val2str(data[1], sol_parameter_vals), intf->ssn_params.port);
params->payload_port = intf->ssn_params.port;
@@ -653,13 +648,14 @@ ipmi_print_sol_info(struct ipmi_intf * intf, uint8_t channel)
*
* function will return -1 if value is not valid, or
* will return 0 if valid.
+ *
+ * base parameter currently unused, left in for extension.
*/
-int ipmi_sol_set_param_isvalid_uint8_t( const char *strval,
- const char *name,
- int base,
- uint8_t minval,
- uint8_t maxval,
- uint8_t *out_value)
+int ipmi_sol_set_param_isvalid_uint8_t(const char *strval,
+ const char *name,
+ uint8_t minval,
+ uint8_t maxval,
+ uint8_t *out_value)
{
if (str2uchar(strval, out_value) != 0 || (*out_value < minval)
|| (*out_value > maxval)) {
@@ -871,7 +867,7 @@ ipmi_sol_set_param(struct ipmi_intf * intf,
data[1] = SOL_PARAMETER_CHARACTER_INTERVAL;
/* validate user-supplied input */
- if (ipmi_sol_set_param_isvalid_uint8_t(value, param, 0, 1, 255, &data[2]))
+ if (ipmi_sol_set_param_isvalid_uint8_t(value, param, 1, 255, &data[2]))
return -1;
/* We need other values to complete the request */
@@ -897,7 +893,7 @@ ipmi_sol_set_param(struct ipmi_intf * intf,
data[1] = SOL_PARAMETER_CHARACTER_INTERVAL;
/* validate user-supplied input */
- if (ipmi_sol_set_param_isvalid_uint8_t(value, param, 0, 0, 255, &data[3]))
+ if (ipmi_sol_set_param_isvalid_uint8_t(value, param, 0, 255, &data[3]))
return -1;
/* We need other values to complete the request */
@@ -923,7 +919,7 @@ ipmi_sol_set_param(struct ipmi_intf * intf,
data[1] = SOL_PARAMETER_SOL_RETRY;
/* validate user input, 7 is max value */
- if (ipmi_sol_set_param_isvalid_uint8_t(value, param, 0, 0, 7, &data[2]))
+ if (ipmi_sol_set_param_isvalid_uint8_t(value, param, 0, 7, &data[2]))
return -1;
/* We need other values to complete the request */
@@ -949,7 +945,7 @@ ipmi_sol_set_param(struct ipmi_intf * intf,
data[1] = SOL_PARAMETER_SOL_RETRY;
/* validate user-supplied input */
- if (ipmi_sol_set_param_isvalid_uint8_t(value, param, 0, 0, 255, &data[3]))
+ if (ipmi_sol_set_param_isvalid_uint8_t(value, param, 0, 255, &data[3]))
return -1;
/* We need other values to complete the request */
@@ -1073,13 +1069,13 @@ ipmi_sol_set_param(struct ipmi_intf * intf,
/* The command proper */
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error setting SOL parameter '%s'", param);
return -1;
}
- if (!(!strncmp(param, "set-in-progress", 15) && !strncmp(value, "commit-write", 12)) &&
- rsp->ccode > 0) {
+ if (!(!strcmp(param, "set-in-progress") && !strcmp(value, "commit-write")) &&
+ rsp->ccode) {
switch (rsp->ccode) {
case 0x80:
lprintf(LOG_ERR, "Error setting SOL parameter '%s': "
@@ -1491,7 +1487,7 @@ ipmi_sol_keepalive_using_sol(struct ipmi_intf * intf)
if (end.tv_sec - _start_keepalive.tv_sec > SOL_KEEPALIVE_TIMEOUT) {
memset(&v2_payload, 0, sizeof(v2_payload));
v2_payload.payload.sol_packet.character_count = 0;
- if (intf->send_sol(intf, &v2_payload) == NULL)
+ if (!intf->send_sol(intf, &v2_payload))
return -1;
/* good return, reset start time */
gettimeofday(&_start_keepalive, 0);
@@ -1542,7 +1538,7 @@ ipmi_sol_red_pill(struct ipmi_intf * intf, int instance)
buffer_size -= 4;
buffer = (char*)malloc(buffer_size);
- if (buffer == NULL) {
+ if (!buffer) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
return -1;
}
@@ -1709,7 +1705,7 @@ ipmi_sol_activate(struct ipmi_intf * intf, int looptest, int interval,
* This command is only available over RMCP+ (the lanplus
* interface).
*/
- if (strncmp(intf->name, "lanplus", 7) != 0)
+ if (strcmp(intf->name, "lanplus"))
{
lprintf(LOG_ERR, "Error: This command is only available over the "
"lanplus interface");
@@ -1822,9 +1818,6 @@ ipmi_sol_activate(struct ipmi_intf * intf, int looptest, int interval,
(ap_rsp.payload_udp_port[1] << 8) |
ap_rsp.payload_udp_port[0];
- intf->session->timeout = 1;
-
-
/* NOTE: the spec does allow for SOL traffic to be sent on
* a different port. we do not yet support that feature. */
if (intf->session->sol_data.port != intf->ssn_params.port)
@@ -1915,10 +1908,13 @@ int
ipmi_sol_main(struct ipmi_intf * intf, int argc, char ** argv)
{
int retval = 0;
- if (!argc || !strncmp(argv[0], "help", 4)) {
+ const char *instance_kw = "instance=";
+ size_t instance_len = strlen(instance_kw);
+
+ if (!argc || !strcmp(argv[0], "help")) {
/* Help */
print_sol_usage();
- } else if (!strncmp(argv[0], "info", 4)) {
+ } else if (!strcmp(argv[0], "info")) {
/* Info */
uint8_t channel;
if (argc == 1) {
@@ -1933,7 +1929,7 @@ ipmi_sol_main(struct ipmi_intf * intf, int argc, char ** argv)
return -1;
}
retval = ipmi_print_sol_info(intf, channel);
- } else if (!strncmp(argv[0], "payload", 7)) {
+ } else if (!strcmp(argv[0], "payload")) {
/* Payload enable or disable */
uint8_t channel = 0xe;
uint8_t userid = 1;
@@ -1952,25 +1948,25 @@ ipmi_sol_main(struct ipmi_intf * intf, int argc, char ** argv)
return (-1);
}
}
- if (!strncmp(argv[1], "enable", 6)) {
+ if (!strcmp(argv[1], "enable")) {
enable = 1;
- } else if (!strncmp(argv[1], "disable", 7)) {
+ } else if (!strcmp(argv[1], "disable")) {
enable = 0;
- } else if (!strncmp(argv[1], "status", 6)) {
+ } else if (!strcmp(argv[1], "status")) {
return ipmi_sol_payload_access_status(intf, channel, userid);
} else {
print_sol_usage();
return -1;
}
retval = ipmi_sol_payload_access(intf, channel, userid, enable);
- } else if (!strncmp(argv[0], "set", 3)) {
+ } else if (!strcmp(argv[0], "set")) {
/* Set a parameter value */
uint8_t channel = 0xe;
uint8_t guard = 1;
if (argc == 3) {
channel = 0xe;
} else if (argc == 4) {
- if (!strncmp(argv[3], "noguard", 7)) {
+ if (!strcmp(argv[3], "noguard")) {
guard = 0;
} else {
if (is_ipmi_channel_num(argv[3], &channel) != 0) {
@@ -1981,7 +1977,7 @@ ipmi_sol_main(struct ipmi_intf * intf, int argc, char ** argv)
if (is_ipmi_channel_num(argv[3], &channel) != 0) {
return (-1);
}
- if (!strncmp(argv[4], "noguard", 7)) {
+ if (!strcmp(argv[4], "noguard")) {
guard = 0;
}
} else {
@@ -1989,16 +1985,16 @@ ipmi_sol_main(struct ipmi_intf * intf, int argc, char ** argv)
return -1;
}
retval = ipmi_sol_set_param(intf, channel, argv[1], argv[2], guard);
- } else if (!strncmp(argv[0], "activate", 8)) {
+ } else if (!strcmp(argv[0], "activate")) {
/* Activate */
int i;
uint8_t instance = 1;
for (i = 1; i < argc; i++) {
- if (!strncmp(argv[i], "usesolkeepalive", 15)) {
+ if (!strcmp(argv[i], "usesolkeepalive")) {
_use_sol_for_keepalive = 1;
- } else if (!strncmp(argv[i], "nokeepalive", 11)) {
+ } else if (!strcmp(argv[i], "nokeepalive")) {
_disable_keepalive = 1;
- } else if (!strncmp(argv[i], "instance=", 9)) {
+ } else if (!strncmp(argv[i], instance_kw, instance_len)) {
if (str2uchar(argv[i] + 9, &instance) != 0) {
lprintf(LOG_ERR, "Given instance '%s' is invalid.", argv[i] + 9);
print_sol_usage();
@@ -2010,12 +2006,12 @@ ipmi_sol_main(struct ipmi_intf * intf, int argc, char ** argv)
}
}
retval = ipmi_sol_activate(intf, 0, 0, instance);
- } else if (!strncmp(argv[0], "deactivate", 10)) {
- /* Dectivate */
+ } else if (!strcmp(argv[0], "deactivate")) {
+ /* Deactivate */
int i;
uint8_t instance = 1;
for (i = 1; i < argc; i++) {
- if (!strncmp(argv[i], "instance=", 9)) {
+ if (!strncmp(argv[i], instance_kw, instance_len)) {
if (str2uchar(argv[i] + 9, &instance) != 0) {
lprintf(LOG_ERR,
"Given instance '%s' is invalid.",
@@ -2029,8 +2025,8 @@ ipmi_sol_main(struct ipmi_intf * intf, int argc, char ** argv)
}
}
retval = ipmi_sol_deactivate(intf, instance);
- } else if (!strncmp(argv[0], "looptest", 8)) {
- /* SOL loop test: Activate and then Dectivate */
+ } else if (!strcmp(argv[0], "looptest")) {
+ /* SOL loop test: Activate and then Deactivate */
int cnt = 200;
int interval = 100; /* Unit is: ms */
uint8_t instance = 1;