From fe80b6751a3ccce9312733cb5e7495d2510051a8 Mon Sep 17 00:00:00 2001 From: Jani Suonpera Date: Wed, 17 Jan 2018 10:39:16 +0200 Subject: [PATCH] Update CoAP to 4.0.11 This PR implement https://tools.ietf.org/html/rfc7959#section-2.5 "The error code 4.13 (Request Entity Too Large) can be returned at any time by a server that does not currently have the resources to store blocks for a block-wise request payload transfer that it would intend to implement in an atomic fashion. (Note that a 4.13 response to a request that does not employ Block1 is a hint for the client to try sending Block1, and a 4.13 response with a smaller SZX in its Block1 Option than requested is a hint to try a smaller SZX.) --- features/FEATURE_COMMON_PAL/mbed-coap/module.json | 2 +- .../mbed-coap/source/sn_coap_protocol.c | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/features/FEATURE_COMMON_PAL/mbed-coap/module.json b/features/FEATURE_COMMON_PAL/mbed-coap/module.json index 265a343e7a..454251ee02 100644 --- a/features/FEATURE_COMMON_PAL/mbed-coap/module.json +++ b/features/FEATURE_COMMON_PAL/mbed-coap/module.json @@ -1,6 +1,6 @@ { "name": "mbed-coap", - "version": "4.0.10", + "version": "4.0.11", "description": "COAP library", "keywords": [ "coap", diff --git a/features/FEATURE_COMMON_PAL/mbed-coap/source/sn_coap_protocol.c b/features/FEATURE_COMMON_PAL/mbed-coap/source/sn_coap_protocol.c index 1e14055faf..234de67866 100644 --- a/features/FEATURE_COMMON_PAL/mbed-coap/source/sn_coap_protocol.c +++ b/features/FEATURE_COMMON_PAL/mbed-coap/source/sn_coap_protocol.c @@ -1756,6 +1756,15 @@ static sn_coap_hdr_s *sn_coap_handle_blockwise_message(struct coap_s *handle, sn /* Check block size */ block_temp = (src_coap_blockwise_ack_msg_ptr->options_list_ptr->block1 & 0x07); + uint16_t block_size = 1u << (block_temp + 4); + if (block_size > handle->sn_coap_block_data_size) { + // Include maximum size that stack can handle into response + tr_error("sn_coap_handle_blockwise_message - (recv block1) COAP_MSG_CODE_RESPONSE_REQUEST_ENTITY_TOO_LARGE!"); + src_coap_blockwise_ack_msg_ptr->msg_code = COAP_MSG_CODE_RESPONSE_REQUEST_ENTITY_TOO_LARGE; + src_coap_blockwise_ack_msg_ptr->options_list_ptr->size1 = handle->sn_coap_block_data_size; + sn_coap_protocol_linked_list_blockwise_payload_remove_oldest(handle); + } + if (block_temp > sn_coap_convert_block_size(handle->sn_coap_block_data_size)) { src_coap_blockwise_ack_msg_ptr->options_list_ptr->block1 &= 0xFFFFF8; src_coap_blockwise_ack_msg_ptr->options_list_ptr->block1 |= sn_coap_convert_block_size(handle->sn_coap_block_data_size);