[PATCH 10/16] ratp: fix sending ACKs without data

Aleksander Morgado aleksander at aleksander.es
Thu Jun 15 04:14:14 PDT 2017


All ACKs without data must be built in the same way from the input
message:
     <SN=received AN><AN=received SN+1 modulo 2><CTL=ACK>

The code was actually doing this instead:
     <SN=0><AN=SN><CTL=ACK>

Signed-off-by: Aleksander Morgado <aleksander at aleksander.es>
---
 lib/ratp.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/lib/ratp.c b/lib/ratp.c
index 321721ab7..5c52d3b5f 100644
--- a/lib/ratp.c
+++ b/lib/ratp.c
@@ -364,13 +364,12 @@ static bool ratp_sn_expected(struct ratp_internal *ri, struct ratp_header *hdr)
 
 static int ratp_send_ack(struct ratp_internal *ri, struct ratp_header *hdr)
 {
-	uint8_t control = RATP_CONTROL_ACK;
+	uint8_t control;
 	int ret;
 
-	if (hdr->control & RATP_CONTROL_SN)
-		control |= RATP_CONTROL_AN;
-	else
-		control |= 0;
+	control = ratp_set_sn(ratp_an(hdr)) |
+		ratp_set_an(ratp_sn(hdr) + 1) |
+		RATP_CONTROL_ACK;
 
 	ret = ratp_send_hdr(ri, control);
 	if (ret)
-- 
2.13.1




More information about the barebox mailing list