From 5403b2a211034144137ab0ec52b995a3c23d8e37 Mon Sep 17 00:00:00 2001 From: Arthur Fabre Date: Wed, 29 Jul 2015 16:37:09 +0100 Subject: [PATCH] Fix default CoAP header block2 size When a client sends a CoAP request with no block2 size, the default one would be set to REST_MAX_CHUNK_SIZE. However, this is not guaranteed to be a power of 2. This can lead to clients receiving a bigger payload than expected as part of the header, and ending up with duplicated content. Setting the default to COAP_MAX_BLOCK_SIZE, which is guaranteed to be a power of 2, fixes this. --- apps/er-coap/er-coap-engine.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/er-coap/er-coap-engine.c b/apps/er-coap/er-coap-engine.c index 4871368b4..2f58eda94 100644 --- a/apps/er-coap/er-coap-engine.c +++ b/apps/er-coap/er-coap-engine.c @@ -104,7 +104,7 @@ coap_receive(void) coap_new_transaction(message->mid, &UIP_IP_BUF->srcipaddr, UIP_UDP_BUF->srcport))) { uint32_t block_num = 0; - uint16_t block_size = REST_MAX_CHUNK_SIZE; + uint16_t block_size = COAP_MAX_BLOCK_SIZE; uint32_t block_offset = 0; int32_t new_offset = 0; @@ -125,8 +125,8 @@ coap_receive(void) if(coap_get_header_block2 (message, &block_num, NULL, &block_size, &block_offset)) { PRINTF("Blockwise: block request %lu (%u/%u) @ %lu bytes\n", - block_num, block_size, REST_MAX_CHUNK_SIZE, block_offset); - block_size = MIN(block_size, REST_MAX_CHUNK_SIZE); + block_num, block_size, COAP_MAX_BLOCK_SIZE, block_offset); + block_size = MIN(block_size, COAP_MAX_BLOCK_SIZE); new_offset = block_offset; }