summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/ratp/ratp.c2
-rw-r--r--lib/ratp.c26
-rw-r--r--scripts/remote/messages.py3
-rw-r--r--scripts/remote/ratp.py2
4 files changed, 21 insertions, 12 deletions
diff --git a/common/ratp/ratp.c b/common/ratp/ratp.c
index 424c9406d2..fddb286e01 100644
--- a/common/ratp/ratp.c
+++ b/common/ratp/ratp.c
@@ -486,7 +486,7 @@ int barebox_ratp(struct console_device *cdev)
ctx->cdev = cdev;
ctx->have_synch = 1;
- ret = ratp_establish(&ctx->ratp, false, 100);
+ ret = ratp_establish(&ctx->ratp, false, 1000);
if (ret < 0)
goto out;
diff --git a/lib/ratp.c b/lib/ratp.c
index ce30223bac..c597e96784 100644
--- a/lib/ratp.c
+++ b/lib/ratp.c
@@ -738,7 +738,7 @@ static int ratp_behaviour_c2(struct ratp_internal *ri, void *pkt)
control = RATP_CONTROL_RST | RATP_CONTROL_ACK |
ratp_set_sn(ratp_an(hdr)) | ratp_set_next_an(ratp_sn(hdr));
ratp_send_hdr(ri, control);
-
+ ri->sendbuf_len = 0;
ratp_state_change(ri, RATP_STATE_CLOSED);
return 1;
}
@@ -784,7 +784,7 @@ static int ratp_behaviour_d1(struct ratp_internal *ri, void *pkt)
ri->status = -ECONNREFUSED;
pr_debug("Error: connection refused\n");
-
+ ri->sendbuf_len = 0;
ratp_state_change(ri, RATP_STATE_CLOSED);
return 1;
@@ -812,6 +812,8 @@ static int ratp_behaviour_d2(struct ratp_internal *ri, void *pkt)
ri->status = -ECONNRESET;
pr_debug("connection reset\n");
+ ri->sendbuf_len = 0;
+ ratp_state_change(ri, RATP_STATE_CLOSED);
return 0;
}
@@ -879,7 +881,7 @@ static int ratp_behaviour_e(struct ratp_internal *ri, void *pkt)
ratp_send_hdr(ri, control);
pr_debug("connection reset\n");
-
+ ri->sendbuf_len = 0;
ratp_state_change(ri, RATP_STATE_CLOSED);
return 1;
@@ -924,8 +926,10 @@ static int ratp_behaviour_f1(struct ratp_internal *ri, void *pkt)
if (!(hdr->control & RATP_CONTROL_ACK))
return 1;
- if (ratp_an_expected(ri, hdr))
+ if (ratp_an_expected(ri, hdr)) {
+ ri->sendbuf_len = 0; /* packet succesfully received */
return 0;
+ }
control = RATP_CONTROL_RST | ratp_set_sn(ratp_an(hdr));
ratp_send_hdr(ri, control);
@@ -971,6 +975,7 @@ static int ratp_behaviour_f2(struct ratp_internal *ri, void *pkt)
if (ri->sendmsg_current)
ratp_msg_done(ri, ri->sendmsg_current, 0);
ri->sendmsg_current = NULL;
+ ri->sendbuf_len = 0; /* packet succesfully received */
return 0;
} else {
pr_vdebug("%s: an not expected\n", __func__);
@@ -1175,6 +1180,7 @@ static int ratp_behaviour_h3(struct ratp_internal *ri, void *pkt)
ratp_send_hdr(ri, control);
ri->status = -ECONNRESET;
pr_debug("Error: Connection reset\n");
+ ri->sendbuf_len = 0;
ratp_state_change(ri, RATP_STATE_CLOSED);
return 1;
}
@@ -1217,8 +1223,10 @@ static int ratp_behaviour_h4(struct ratp_internal *ri, void *pkt)
pr_debug("%s\n", __func__);
- if (ratp_an_expected(ri, hdr))
+ if (ratp_an_expected(ri, hdr)) {
+ ri->sendbuf_len = 0; /* packet succesfully received */
ratp_state_change(ri, RATP_STATE_CLOSED);
+ }
return 1;
}
@@ -1244,6 +1252,7 @@ static int ratp_behaviour_h5(struct ratp_internal *ri, void *pkt)
pr_debug("%s\n", __func__);
if (ratp_an_expected(ri, hdr)) {
+ ri->sendbuf_len = 0; /* packet succesfully received */
ratp_state_change(ri, RATP_STATE_TIME_WAIT);
ratp_start_time_wait_timer(ri);
}
@@ -1580,9 +1589,8 @@ int ratp_poll(struct ratp *ratp)
}
}
- if (ri->sendmsg_current && is_timeout(ri->retransmission_timer_start,
+ if (ri->sendbuf_len && is_timeout(ri->retransmission_timer_start,
ri->rto * MSECOND)) {
-
ri->retransmission_count++;
if (ri->retransmission_count == ri->max_retransmission) {
ri->status = ret = -ETIMEDOUT;
@@ -1601,7 +1609,7 @@ int ratp_poll(struct ratp *ratp)
goto out;
}
- if (!ri->sendmsg_current && !list_empty(&ri->sendmsg))
+ if (ri->sendbuf_len == 0 && !list_empty(&ri->sendmsg))
ratp_send_next_data(ri);
ret = 0;
@@ -1640,7 +1648,7 @@ int ratp_establish(struct ratp *ratp, bool active, int timeout_ms)
INIT_LIST_HEAD(&ri->sendmsg);
ri->max_retransmission = 100;
ri->srtt = 100;
- ri->rto = 100;
+ ri->rto = 200;
ri->active = active;
ri->in_ratp++;
diff --git a/scripts/remote/messages.py b/scripts/remote/messages.py
index 76cccad393..de15e72ed5 100644
--- a/scripts/remote/messages.py
+++ b/scripts/remote/messages.py
@@ -35,12 +35,13 @@ class BBType(object):
class BBPacket(object):
- def __init__(self, p_type=0, p_flags=0, payload="", raw=None):
+ def __init__(self, p_type=0, p_flags=0, payload=b"", raw=None):
self.p_type = p_type
self.p_flags = p_flags
if raw is not None:
self.unpack(raw)
else:
+ assert isinstance(payload, bytes)
self.payload = payload
def __repr__(self):
diff --git a/scripts/remote/ratp.py b/scripts/remote/ratp.py
index 25ca442d15..956c788234 100644
--- a/scripts/remote/ratp.py
+++ b/scripts/remote/ratp.py
@@ -345,7 +345,7 @@ class RatpConnection(object):
if r.c_rst or r.c_fin:
return False
- if r.c_syn:
+ if r.c_syn and not r.c_ack:
s = RatpPacket(flags='RA')
s.c_sn = r.c_an
s.c_an = (r.c_sn + 1) % 2