From 0613015afb9e5b442c34448fe58d529649bbdcab Mon Sep 17 00:00:00 2001 From: Jon Shallow Date: Thu, 23 Nov 2023 12:57:25 +0000 Subject: [PATCH] block.c: Report 4.08 for missing Block1 chunks of data Not applied to RFC9177 Q-Block1 missing blocks which are handled in a different way. --- src/coap_block.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/coap_block.c b/src/coap_block.c index 012a174c76..ba2dbbbc15 100644 --- a/src/coap_block.c +++ b/src/coap_block.c @@ -2726,7 +2726,6 @@ coap_handle_request_put_block(coap_context_t *context, p->uri_path = coap_new_str_const(uri_path->s, uri_path->length); p->content_format = fmt; p->total_len = total; - p->amount_so_far = length; p->szx = block.szx; p->block_option = block_option; if (observe) { @@ -2749,6 +2748,19 @@ coap_handle_request_put_block(coap_context_t *context, response->code = COAP_RESPONSE_CODE(408); goto free_lg_srcv; } +#if COAP_Q_BLOCK_SUPPORT + if (block_option != COAP_OPTION_Q_BLOCK1) { +#endif /* COAP_Q_BLOCK_SUPPORT */ + if (offset > p->amount_so_far) { + coap_add_data(response, sizeof("Missing block")-1, + (const uint8_t *)"Missing block"); + response->code = COAP_RESPONSE_CODE(408); + goto free_lg_srcv; + } + p->amount_so_far += length; +#if COAP_Q_BLOCK_SUPPORT + } +#endif /* COAP_Q_BLOCK_SUPPORT */ #if COAP_Q_BLOCK_SUPPORT if (block_option == COAP_OPTION_Q_BLOCK1) { if (total != p->total_len) { @@ -2845,7 +2857,16 @@ coap_handle_request_put_block(coap_context_t *context, block.aszx), buf); response->code = COAP_RESPONSE_CODE(231); - goto skip_app_handler; + } else { +#if COAP_Q_BLOCK_SUPPORT + if (block_option != COAP_OPTION_Q_BLOCK1) { +#endif /* COAP_Q_BLOCK_SUPPORT */ + coap_add_data(response, sizeof("Missing interim block")-1, + (const uint8_t *)"Missing interim block"); + response->code = COAP_RESPONSE_CODE(408); +#if COAP_Q_BLOCK_SUPPORT + } +#endif /* COAP_Q_BLOCK_SUPPORT */ } goto skip_app_handler; }