From 3c7742a2ee2df03cdd58f131c0376141ec34d9b7 Mon Sep 17 00:00:00 2001 From: Jon Shallow Date: Tue, 11 Aug 2026 15:49:54 +0100 Subject: [PATCH] coap_block.c: Send 2.31 response if duplicate block received Only happens if the MID is different and this is not the final block. --- src/coap_block.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/coap_block.c b/src/coap_block.c index 709edb1e..17aace57 100644 --- a/src/coap_block.c +++ b/src/coap_block.c @@ -3589,6 +3589,25 @@ coap_handle_request_put_block(coap_context_t *context, } } } else { + /* + * Every block carried by this request had already been received, so there + * is no new data and the application must not see the request twice + * (RFC7252 4.5). The request still has to be answered: falling straight + * through to skip_app_handler leaves response->code at 0, which goes out + * as an Empty ACK. + * Re-issue the 2.31 Continue this block was given the first time. + */ + if (block.m) { + uint8_t buf[4]; + + coap_insert_option(response, block_option, + coap_encode_var_safe(buf, sizeof(buf), + (saved_num << 4) | + (1 << 3) | + lg_srcv->szx), + buf); + response->code = COAP_RESPONSE_CODE(231); + } goto skip_app_handler; }