diff options
author | Aleksander Morgado <aleksander@aleksander.es> | 2017-06-21 21:13:14 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2017-06-23 13:34:07 +0200 |
commit | b2fb42fb63a838383873f9de1a4037d8403a5cec (patch) | |
tree | 7e0f60144cfd359e503708df478a6373dc7dfeed | |
parent | ed2f11bbe3ead86611afbef011d9c6ac72c376ff (diff) | |
download | barebox-b2fb42fb63a838383873f9de1a4037d8403a5cec.tar.gz barebox-b2fb42fb63a838383873f9de1a4037d8403a5cec.tar.xz |
ratp: fix single byte sending flagged with SO
When a single data byte is sent, it is flagged as SO and the actual
data goes in the length byte within the header.
Worth noting that this issue wasn't found in any barebox<->bbremote
interaction because all data packets sent between them always have
more than one byte (due to the barebox command specific header).
Signed-off-by: Aleksander Morgado <aleksander@aleksander.es>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r-- | lib/ratp.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/lib/ratp.c b/lib/ratp.c index c946bea1a5..846f8130cf 100644 --- a/lib/ratp.c +++ b/lib/ratp.c @@ -384,6 +384,7 @@ static int ratp_send_next_data(struct ratp_internal *ri) uint16_t crc; uint8_t control; struct ratp_header *hdr; + uint8_t *data; int pktlen; struct ratp_message *msg; int len; @@ -409,19 +410,19 @@ static int ratp_send_next_data(struct ratp_internal *ri) RATP_CONTROL_ACK; hdr = msg->buf; + data = (uint8_t *)(hdr + 1); if (msg->eor) control |= RATP_CONTROL_EOR; + pktlen = sizeof(struct ratp_header); if (len > 1) { - void *data = hdr + 1; - pktlen = sizeof(*hdr) + len + 2; + pktlen += len + 2; crc = cyg_crc16(data, len); put_unaligned_be16(crc, data + len); - } else { - pktlen = sizeof(struct ratp_header); + } else if (len == 1) { control |= RATP_CONTROL_SO; - len = 0; + len = *data; } ratp_create_packet(ri, hdr, control, len); |