From 6f161569f469d8640a376ff8f5eb6e7cdcdb37cc Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Wed, 5 Jan 2022 22:31:55 +0100 Subject: [PATCH] suit/transport/coap: use nanocoap for request This changes the retransmission timeout behavior. In SUIT the timeout was uses as the maximum time *all* retransmissions could take, whereas in nanocoap the timeout was specified per retransmission. This means that SUIT now adopts the timeout behavior of nanocoap. --- sys/suit/transport/coap.c | 63 +-------------------------------------- 1 file changed, 1 insertion(+), 62 deletions(-) diff --git a/sys/suit/transport/coap.c b/sys/suit/transport/coap.c index c8fd03896f..73e0fd957b 100644 --- a/sys/suit/transport/coap.c +++ b/sys/suit/transport/coap.c @@ -133,67 +133,6 @@ static inline uint32_t deadline_left(uint32_t deadline) return left; } -static ssize_t _nanocoap_request(sock_udp_t *sock, coap_pkt_t *pkt, size_t len) -{ - ssize_t res = -EAGAIN; - size_t pdu_len = (pkt->payload - (uint8_t *)pkt->hdr) + pkt->payload_len; - uint8_t *buf = (uint8_t *)pkt->hdr; - uint32_t id = coap_get_id(pkt); - - /* TODO: timeout random between between ACK_TIMEOUT and (ACK_TIMEOUT * - * ACK_RANDOM_FACTOR) */ - uint32_t timeout = CONFIG_COAP_ACK_TIMEOUT * US_PER_SEC; - uint32_t deadline = deadline_from_interval(timeout); - - /* add 1 for initial transmit */ - unsigned tries_left = CONFIG_COAP_MAX_RETRANSMIT + 1; - - while (tries_left) { - if (res == -EAGAIN) { - res = sock_udp_send(sock, buf, pdu_len, NULL); - if (res <= 0) { - DEBUG("nanocoap: error sending coap request, %d\n", (int)res); - break; - } - } - - res = sock_udp_recv(sock, buf, len, deadline_left(deadline), NULL); - if (res <= 0) { - if (res == -ETIMEDOUT) { - DEBUG("nanocoap: timeout\n"); - - tries_left--; - if (!tries_left) { - DEBUG("nanocoap: maximum retries reached\n"); - break; - } - else { - timeout *= 2; - deadline = deadline_from_interval(timeout); - res = -EAGAIN; - continue; - } - } - DEBUG("nanocoap: error receiving coap response, %d\n", (int)res); - break; - } - else { - if (coap_parse(pkt, (uint8_t *)buf, res) < 0) { - DEBUG("nanocoap: error parsing packet\n"); - res = -EBADMSG; - } - else if (coap_get_id(pkt) != id) { - res = -EBADMSG; - continue; - } - - break; - } - } - - return res; -} - static int _fetch_block(coap_pkt_t *pkt, uint8_t *buf, sock_udp_t *sock, const char *path, coap_blksize_t blksize, size_t num) { @@ -212,7 +151,7 @@ static int _fetch_block(coap_pkt_t *pkt, uint8_t *buf, sock_udp_t *sock, pkt->payload = pktpos; pkt->payload_len = 0; - int res = _nanocoap_request(sock, pkt, 64 + (0x1 << (blksize + 4))); + int res = nanocoap_request(sock, pkt, 64 + (0x1 << (blksize + 4))); if (res < 0) { return res; }