From 66cb3143dced74849e5cee49a7e3a5708f7e4369 Mon Sep 17 00:00:00 2001 From: Duncan Laurie Date: Tue, 17 Jan 2006 17:25:23 +0000 Subject: [PATCH] send periodic keepalive packet when SOL is active to keep session open --- ipmitool/include/ipmitool/ipmi_sol.h | 1 + ipmitool/lib/ipmi_sol.c | 39 +++++++++++++++++++++++----- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/ipmitool/include/ipmitool/ipmi_sol.h b/ipmitool/include/ipmitool/ipmi_sol.h index 582ac69..c58d5b4 100644 --- a/ipmitool/include/ipmitool/ipmi_sol.h +++ b/ipmitool/include/ipmitool/ipmi_sol.h @@ -40,6 +40,7 @@ #include #define SOL_ESCAPE_CHARACTER_DEFAULT '~' +#define SOL_KEEPALIVE_TIMEOUT 30 #define IPMI_SOL_SERIAL_ALERT_MASK_SUCCEED 0x08 #define IPMI_SOL_SERIAL_ALERT_MASK_DEFERRED 0x04 diff --git a/ipmitool/lib/ipmi_sol.c b/ipmitool/lib/ipmi_sol.c index 5aa09a8..de8fab8 100644 --- a/ipmitool/lib/ipmi_sol.c +++ b/ipmitool/lib/ipmi_sol.c @@ -42,6 +42,7 @@ #include #include #include +#include #include #include @@ -81,6 +82,7 @@ const struct valstr sol_parameter_vals[] = { }; +static struct timeval _start_keepalive; static struct termios _saved_tio; static int _in_raw_mode = 0; @@ -1251,21 +1253,40 @@ processSolUserInput( if (! rsp) { - lprintf(LOG_ERR, "Error sending SOL data"); - retval = -1; + rsp = intf->send_sol(intf, &v2_payload); + lprintf(LOG_ERR, "Error sending SOL data: RETRY"); + if (! rsp) + { + lprintf(LOG_ERR, "Error sending SOL data: FAIL"); + retval = -1; + } } /* If the sequence number is set we know we have new data */ - else if ((rsp->session.authtype == IPMI_SESSION_AUTHTYPE_RMCP_PLUS) && - (rsp->session.payloadtype == IPMI_PAYLOAD_TYPE_SOL) && - (rsp->payload.sol_packet.packet_sequence_number)) - output(rsp); + if (retval == 0) + if ((rsp->session.authtype == IPMI_SESSION_AUTHTYPE_RMCP_PLUS) && + (rsp->session.payloadtype == IPMI_PAYLOAD_TYPE_SOL) && + (rsp->payload.sol_packet.packet_sequence_number)) + output(rsp); } return retval; } +static void +ipmi_sol_keepalive(struct ipmi_intf * intf) +{ + struct timeval end; + + gettimeofday(&end, 0); + + if (end.tv_sec - _start_keepalive.tv_sec > SOL_KEEPALIVE_TIMEOUT) { + intf->keepalive(intf); + gettimeofday(&_start_keepalive, 0); + } +} + /* * ipmi_sol_red_pill @@ -1289,6 +1310,9 @@ ipmi_sol_red_pill(struct ipmi_intf * intf) return -1; } + /* Initialize keepalive start time */ + gettimeofday(&_start_keepalive, 0); + enter_raw_mode(); while (! bShouldExit) @@ -1297,6 +1321,9 @@ ipmi_sol_red_pill(struct ipmi_intf * intf) FD_SET(0, &read_fds); FD_SET(intf->fd, &read_fds); + /* Send periodic keepalive packet */ + ipmi_sol_keepalive(intf); + /* Wait up to half a second */ tv.tv_sec = 0; tv.tv_usec = 500000;