[riot-notifications] [RIOT-OS/RIOT] sys/suit: initial support for SUIT firmware updates (#11818)

Francisco notifications at github.com
Mon Sep 30 15:35:53 CEST 2019


fjmolinas commented on this pull request.



> +    ssize_t res;
+    size_t pdu_len = (pkt->payload - (uint8_t *)pkt->hdr) + pkt->payload_len;
+    uint8_t *buf = (uint8_t*)pkt->hdr;
+
+    /* TODO: timeout random between between ACK_TIMEOUT and (ACK_TIMEOUT *
+     * ACK_RANDOM_FACTOR) */
+    uint32_t timeout = COAP_ACK_TIMEOUT * US_PER_SEC;
+    unsigned tries_left = COAP_MAX_RETRANSMIT + 1;  /* add 1 for initial transmit */
+    while (tries_left) {
+
+        res = sock_udp_send(sock, buf, pdu_len, NULL);
+        if (res <= 0) {
+            DEBUG("nanocoap: error sending coap request, %d\n", (int)res);
+            break;
+        }
+

Here is the suggested change.

<details><summary>PATCH</summary>

```
diff --git a/sys/suit/coap.c b/sys/suit/coap.c
index 9e86777b3..870bb8d7f 100644
--- a/sys/suit/coap.c
+++ b/sys/suit/coap.c
@@ -141,15 +141,20 @@ size_t coap_put_option_block(uint8_t *buf, uint16_t lastonum, unsigned blknum, u
 
 static ssize_t _nanocoap_request(sock_udp_t *sock, coap_pkt_t *pkt, size_t len)
 {
-    ssize_t res;
+    ssize_t res = 0;
     size_t pdu_len = (pkt->payload - (uint8_t *)pkt->hdr) + pkt->payload_len;
     uint8_t *buf = (uint8_t*)pkt->hdr;
 
     /* TODO: timeout random between between ACK_TIMEOUT and (ACK_TIMEOUT *
      * ACK_RANDOM_FACTOR) */
     uint32_t timeout = COAP_ACK_TIMEOUT * US_PER_SEC;
+    /* Timeout on incorrect block responses */
+    uint32_t block_timeout = timeout + xtimer_now_usec();
+    uint32_t id = coap_get_id(pkt);
+
     unsigned tries_left = COAP_MAX_RETRANSMIT + 1;  /* add 1 for initial transmit */
-    while (tries_left) {
+
+    while (tries_left && res) {
 
         res = sock_udp_send(sock, buf, pdu_len, NULL);
         if (res <= 0) {
@@ -157,27 +162,32 @@ static ssize_t _nanocoap_request(sock_udp_t *sock, coap_pkt_t *pkt, size_t len)
             break;
         }
 
-        res = sock_udp_recv(sock, buf, len, timeout, NULL);
-        if (res <= 0) {
-            if (res == -ETIMEDOUT) {
-                DEBUG("nanocoap: timeout\n");
-
-                timeout *= 2;
-                tries_left--;
-                if (!tries_left) {
-                    DEBUG("nanocoap: maximum retries reached\n");
+        while (block_timeout < xtimer_now_usec()) {
+            res = sock_udp_recv(sock, buf, len, timeout, NULL);
+            if (res <= 0) {
+                if (res == -ETIMEDOUT) {
+                    DEBUG("nanocoap: timeout\n");
+
+                    timeout *= 2;
+                    tries_left--;
+                    if (!tries_left) {
+                        DEBUG("nanocoap: maximum retries reached\n");
+                    }
+                    continue;
                 }
-                continue;
+                DEBUG("nanocoap: error receiving coap response, %d\n", (int)res);
+                break;
             }
-            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_parse(pkt, (uint8_t *)buf, res) < 0) {
+                    DEBUG("nanocoap: error parsing packet\n");
+                    res = -EBADMSG;
+                }
+                if (coap_get_id(pkt) != id) {
+                    res = -1;
+                }
+                break;
             }
-            break;
         }
     }

```

</details>

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/RIOT-OS/RIOT/pull/11818#discussion_r329579540
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20190930/b6ae5476/attachment.htm>


More information about the notifications mailing list