summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHannes Reinecke <hare@suse.de>2022-04-11 16:19:50 +0200
committerGerd Hoffmann <kraxel@redhat.com>2022-04-22 14:52:30 +0200
commit9cf44be87fb50ce116e1cbfbff1fa3e8771c15a4 (patch)
tree16f0b015baa283775be8be3b52148908994a9068
parente5a8f42c1a8bd2ae29d3e826fb3a7cf71a0c3068 (diff)
downloadamtterm-9cf44be87fb50ce116e1cbfbff1fa3e8771c15a4.tar.gz
redir: add ider reset handling
-rw-r--r--RedirectionConstants.h7
-rw-r--r--amtider.c1
-rw-r--r--redir.c54
-rw-r--r--redir.h7
4 files changed, 63 insertions, 6 deletions
diff --git a/RedirectionConstants.h b/RedirectionConstants.h
index b05060f..e5db8aa 100644
--- a/RedirectionConstants.h
+++ b/RedirectionConstants.h
@@ -67,12 +67,19 @@
#define IDER_DATA_FROM_HOST 0x53
#define IDER_DATA_TO_HOST 0x54
+/* IDER disable/enable features sub commands */
+#define IDER_FEATURE_GET_SUPPORTED 0x01
+#define IDER_FEATURE_GET_REGISTER_STATE 0x02
+#define IDER_FEATURE_SET_REGISTER_STATE 0x03
+#define IDER_FEATURE_ENABLE 0x01
+
#define START_IDER_REDIRECTION_LENGTH 18
#define START_IDER_REDIRECTION_REPLY_LENGTH 30 //TODO: There is a OEM Defined data field that we are assuming to be 0 bytes..
#define END_IDER_REDIRECTION_LENGTH 8
#define END_IDER_REDIRECTION_REPLY_LENGTH 8
#define IDER_RESET_OCCURED_LENGTH 9
#define IDER_RESET_OCCURED_RESPONSE_LENGTH 8
+#define IDER_DISABLE_ENABLE_FEATURES_LENGTH 13
#define IDER_DISABLE_ENABLE_FEATURES_REPLY_LENGTH 13
#define IDER_COMMAND_END_RESPONSE_LENGTH 31
#define IDER_GET_DATA_FROM_HOST_LENGTH 31
diff --git a/amtider.c b/amtider.c
index 9601132..b62a4d5 100644
--- a/amtider.c
+++ b/amtider.c
@@ -198,6 +198,7 @@ int main(int argc, char *argv[])
r.cb_data = &r;
r.cb_recv = recv_ider;
r.cb_state = state_ider;
+ r.enable_options = 0x18;
if (NULL != (h = getenv("AMT_PASSWORD")))
snprintf(r.pass, sizeof(r.pass), "%s", h);
diff --git a/redir.c b/redir.c
index b191f65..780a065 100644
--- a/redir.c
+++ b/redir.c
@@ -44,6 +44,7 @@ static const char *state_name[] = {
[ REDIR_INIT_SOL ] = "INIT_SOL",
[ REDIR_RUN_SOL ] = "RUN_SOL",
[ REDIR_INIT_IDER ] = "INIT_IDER",
+ [ REDIR_CFG_IDER ] = "CFG_IDER",
[ REDIR_RUN_IDER ] = "RUN_IDER",
[ REDIR_CLOSING ] = "CLOSING",
[ REDIR_CLOSED ] = "CLOSED",
@@ -58,6 +59,7 @@ static const char *state_desc[] = {
[ REDIR_INIT_SOL ] = "serial-over-lan initialization",
[ REDIR_RUN_SOL ] = "serial-over-lan active",
[ REDIR_INIT_IDER ] = "IDE redirect initialization",
+ [ REDIR_CFG_IDER ] = "IDE redirect configuration",
[ REDIR_RUN_IDER ] = "IDE redirect active",
[ REDIR_CLOSING ] = "redirection shutdown",
[ REDIR_CLOSED ] = "connection closed",
@@ -314,6 +316,17 @@ int redir_sol_start(struct redir *r)
return redir_write(r, request, sizeof(request));
}
+int redir_sol_stop(struct redir *r)
+{
+ unsigned char request[END_SOL_REDIRECTION_LENGTH] = {
+ END_SOL_REDIRECTION, 0, 0, 0,
+ 0, 0, 0, 0,
+ };
+
+ redir_state(r, REDIR_CLOSING);
+ return redir_write(r, request, sizeof(request));
+}
+
int redir_ider_start(struct redir *r)
{
unsigned char request[START_IDER_REDIRECTION_LENGTH] = {
@@ -331,14 +344,28 @@ int redir_ider_start(struct redir *r)
return redir_write(r, request, sizeof(request));
}
-int redir_sol_stop(struct redir *r)
+int redir_ider_config(struct redir *r)
{
- unsigned char request[END_SOL_REDIRECTION_LENGTH] = {
- END_SOL_REDIRECTION, 0, 0, 0,
- 0, 0, 0, 0,
+ unsigned char request[IDER_DISABLE_ENABLE_FEATURES_LENGTH] = {
+ IDER_DISABLE_ENABLE_FEATURES, 0, 0, 0,
+ r->seqno & 0xff, (r->seqno >> 8) && 0xff,
+ (r->seqno >> 16) & 0xff, (r->seqno >> 24) & 0xff,
+ IDER_FEATURE_SET_REGISTER_STATE,
+ IDER_FEATURE_ENABLE | r->enable_options, 0, 0, 0
+ };
+ r->seqno++;
+ redir_state(r, REDIR_CFG_IDER);
+ return redir_write(r, request, sizeof(request));
+}
+
+int redir_ider_reset(struct redir *r)
+{
+ unsigned char request[IDER_RESET_OCCURED_RESPONSE_LENGTH] = {
+ IDER_RESET_OCCURED_RESPONSE, 0, 0, 0,
+ r->seqno & 0xff, (r->seqno >> 8) & 0xff,
+ (r->seqno >> 16) & 0xff, (r->seqno >> 24) & 0xff,
};
- redir_state(r, REDIR_CLOSING);
return redir_write(r, request, sizeof(request));
}
@@ -574,8 +601,25 @@ repeat:
(unsigned int)r->buf[19] << 8;
fprintf(stderr,"IDE redirection enabled, features %d iana %02x%02x%02x%02x\n",
r->buf[21], r->buf[25], r->buf[26], r->buf[27], r->buf[28]);
+ if (-1 == redir_ider_config(r))
+ goto err;
+ break;
+ case IDER_DISABLE_ENABLE_FEATURES_REPLY:
+ bshift = r->blen;
+ if (r->blen < IDER_DISABLE_ENABLE_FEATURES_REPLY_LENGTH)
+ goto again;
redir_state(r, REDIR_RUN_IDER);
break;
+ case IDER_RESET_OCCURED:
+ bshift = r->blen;
+ r->seqno = (unsigned int)r->buf[4] |
+ (unsigned int)r->buf[5] << 8 |
+ (unsigned int)r->buf[6] << 16 |
+ (unsigned int)r->buf[7] << 24;
+ fprintf(stderr, "reset, mask %u\n", r->buf[8]);
+ if (-1 == redir_ider_reset(r))
+ goto err;
+ break;
case IDER_DATA_FROM_HOST:
if (r->blen < 10) /* header length */
goto again;
diff --git a/redir.h b/redir.h
index 618154f..9644441 100644
--- a/redir.h
+++ b/redir.h
@@ -9,7 +9,8 @@ enum redir_state {
REDIR_INIT_SOL = 10,
REDIR_RUN_SOL = 11,
REDIR_INIT_IDER = 20,
- REDIR_RUN_IDER = 21,
+ REDIR_CFG_IDER = 21,
+ REDIR_RUN_IDER = 22,
REDIR_CLOSING = 30,
REDIR_CLOSED = 31,
REDIR_ERROR = 40,
@@ -34,10 +35,12 @@ struct redir {
unsigned char filename[256];
unsigned int tx_bufsize;
unsigned int rx_bufsize;
+ unsigned int enable_options;
int sock;
unsigned char buf[64];
unsigned int blen;
+ unsigned int seqno;
void *cacert;
void *ctx;
@@ -68,6 +71,8 @@ int redir_sol_start(struct redir *r);
int redir_sol_stop(struct redir *r);
int redir_sol_send(struct redir *r, unsigned char *buf, int blen);
int redir_ider_start(struct redir *r);
+int redir_ider_config(struct redir *r);
+int redir_ider_reset(struct redir *r);
int redir_ider_stop(struct redir *r);
int redir_ider_send(struct redir *r, unsigned char *buf, int blen);
int redir_data(struct redir *r);