From 8fdae1364223062187bf334988e49db05c60fba2 Mon Sep 17 00:00:00 2001 From: Antti Yli-Tokola Date: Tue, 3 Apr 2018 13:58:40 +0300 Subject: [PATCH] Update mbed-coap to version 4.4.1 - Fixes error: IOTCLT-2539 Block wise messaging call-backs not working logically - Allow TCP+TLS transport method to send larger messages without blockwising. NOTE! These are internal changes required for cloud client. This has no direct relevance to any mbed-os functionality. --- .../FEATURE_COMMON_PAL/mbed-coap/CHANGELOG.md | 8 ++++++++ .../mbed-coap/mbed-coap/sn_config.h | 15 +++++++++++++++ .../FEATURE_COMMON_PAL/mbed-coap/module.json | 2 +- .../include/sn_coap_protocol_internal.h | 4 ++++ .../mbed-coap/source/sn_coap_builder.c | 4 +++- .../mbed-coap/source/sn_coap_protocol.c | 19 +++++++++++++++---- 6 files changed, 46 insertions(+), 6 deletions(-) diff --git a/features/FEATURE_COMMON_PAL/mbed-coap/CHANGELOG.md b/features/FEATURE_COMMON_PAL/mbed-coap/CHANGELOG.md index a3e87e1116..2bd63c3511 100644 --- a/features/FEATURE_COMMON_PAL/mbed-coap/CHANGELOG.md +++ b/features/FEATURE_COMMON_PAL/mbed-coap/CHANGELOG.md @@ -1,5 +1,13 @@ # Change Log +## [v4.4.1](https://github.com/ARMmbed/mbed-coap/releases/tag/v4.4.1) +**Closed issues:** + - IOTCLT-2539 Block wise messaging call-backs not working logically + + Improve TCP+TLS transport layer to allow send larger messages without blockwising. + +-[Full Changelog](https://github.com/ARMmbed/mbed-coap/compare/v4.4.0...v4.4.1) + ## [v4.4.0](https://github.com/ARMmbed/mbed-coap/releases/tag/v4.4.0) **New feature:** - Make sn_coap_protocol_send_rst as public needed for CoAP ping sending diff --git a/features/FEATURE_COMMON_PAL/mbed-coap/mbed-coap/sn_config.h b/features/FEATURE_COMMON_PAL/mbed-coap/mbed-coap/sn_config.h index 57fc98c8d4..6ffb73a162 100644 --- a/features/FEATURE_COMMON_PAL/mbed-coap/mbed-coap/sn_config.h +++ b/features/FEATURE_COMMON_PAL/mbed-coap/mbed-coap/sn_config.h @@ -92,6 +92,21 @@ */ #undef SN_COAP_MAX_INCOMING_MESSAGE_SIZE /* UINT16_MAX */ +/** + * \def SN_COAP_MAX_NONBLOCKWISE_PAYLOAD_SIZE + * \brief Sets the maximum payload size allowed before blockwising the message. + * This option should only be used when using TCP and TLS as transport + * with known maximum fragment size. This optimizes the number of messages + * if it is possible to send larger than 1kB messages without blockwise transfer. + * If payload length is larger than SN_COAP_MAX_NONBLOCKWISE_PAYLOAD_SIZE + * it will be sent using blockwise transfer. + * By default, this feature is disabled, 0 disables the feature, set to positive + * value larger than SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE to enable. + * Note that value should be less than transport layer maximum fragment size. + * Note that value has no effect if blockwise transfer is disabled. + */ +#undef SN_COAP_MAX_NONBLOCKWISE_PAYLOAD_SIZE /* 0 */ + #ifdef MBED_CLIENT_USER_CONFIG_FILE #include MBED_CLIENT_USER_CONFIG_FILE #endif diff --git a/features/FEATURE_COMMON_PAL/mbed-coap/module.json b/features/FEATURE_COMMON_PAL/mbed-coap/module.json index 333e89c82c..b8401cd41a 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.4.0", + "version": "4.4.1", "description": "COAP library", "keywords": [ "coap", diff --git a/features/FEATURE_COMMON_PAL/mbed-coap/source/include/sn_coap_protocol_internal.h b/features/FEATURE_COMMON_PAL/mbed-coap/source/include/sn_coap_protocol_internal.h index 986f8c844e..72ef2a5efe 100644 --- a/features/FEATURE_COMMON_PAL/mbed-coap/source/include/sn_coap_protocol_internal.h +++ b/features/FEATURE_COMMON_PAL/mbed-coap/source/include/sn_coap_protocol_internal.h @@ -117,6 +117,10 @@ struct sn_coap_hdr_; #define SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE 0 /**< Must be 2^x and x is at least 4. Suitable values: 0, 16, 32, 64, 128, 256, 512 and 1024 */ #endif +#ifndef SN_COAP_MAX_NONBLOCKWISE_PAYLOAD_SIZE +#define SN_COAP_MAX_NONBLOCKWISE_PAYLOAD_SIZE 0 +#endif + #ifdef MBED_CONF_MBED_CLIENT_SN_COAP_BLOCKWISE_MAX_TIME_DATA_STORED #define SN_COAP_BLOCKWISE_MAX_TIME_DATA_STORED MBED_CONF_MBED_CLIENT_SN_COAP_BLOCKWISE_MAX_TIME_DATA_STORED #endif diff --git a/features/FEATURE_COMMON_PAL/mbed-coap/source/sn_coap_builder.c b/features/FEATURE_COMMON_PAL/mbed-coap/source/sn_coap_builder.c index 726055ad6c..597f07eeac 100644 --- a/features/FEATURE_COMMON_PAL/mbed-coap/source/sn_coap_builder.c +++ b/features/FEATURE_COMMON_PAL/mbed-coap/source/sn_coap_builder.c @@ -341,7 +341,9 @@ uint16_t sn_coap_builder_calc_needed_packet_data_size_2(sn_coap_hdr_s *src_coap_ } } #if SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE - if ((src_coap_msg_ptr->payload_len > blockwise_payload_size) && (blockwise_payload_size > 0)) { + if ((src_coap_msg_ptr->payload_len > SN_COAP_MAX_NONBLOCKWISE_PAYLOAD_SIZE) && + (src_coap_msg_ptr->payload_len > blockwise_payload_size) && + (blockwise_payload_size > 0)) { returned_byte_count += blockwise_payload_size; } else { returned_byte_count += src_coap_msg_ptr->payload_len; 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 147a12292b..5804c45d0e 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 @@ -372,7 +372,9 @@ int8_t sn_coap_protocol_delete_retransmission(struct coap_s *handle, uint16_t ms #if SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE /* If Message blockwising is not used at all, this part of code will not be compiled */ int8_t prepare_blockwise_message(struct coap_s *handle, sn_coap_hdr_s *src_coap_msg_ptr) { - if ((src_coap_msg_ptr->payload_len > handle->sn_coap_block_data_size) && (handle->sn_coap_block_data_size > 0)) { + if ((src_coap_msg_ptr->payload_len > SN_COAP_MAX_NONBLOCKWISE_PAYLOAD_SIZE) && + (src_coap_msg_ptr->payload_len > handle->sn_coap_block_data_size) && + (handle->sn_coap_block_data_size > 0)) { /* * * * Add Blockwise option to send CoAP message * * */ /* Allocate memory for less used options */ @@ -436,15 +438,15 @@ int16_t sn_coap_protocol_build(struct coap_s *handle, sn_nsdl_addr_s *dst_addr_p } #if SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE /* If Message blockwising is not used at all, this part of code will not be compiled */ - /* If blockwising needed */ - if ((src_coap_msg_ptr->payload_len > handle->sn_coap_block_data_size) && (handle->sn_coap_block_data_size > 0)) { + if ((src_coap_msg_ptr->payload_len > SN_COAP_MAX_NONBLOCKWISE_PAYLOAD_SIZE) && + (src_coap_msg_ptr->payload_len > handle->sn_coap_block_data_size) && + (handle->sn_coap_block_data_size > 0)) { /* Store original Payload length */ original_payload_len = src_coap_msg_ptr->payload_len; /* Change Payload length of send message because Payload is blockwised */ src_coap_msg_ptr->payload_len = handle->sn_coap_block_data_size; } - #endif /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* * * * Build Packet data from CoAP message by using CoAP Header builder * * * */ @@ -1264,6 +1266,15 @@ static void sn_coap_protocol_linked_list_blockwise_payload_store(struct coap_s * return; } + // Do not add duplicates to list, this could happen if server needs to retransmit block message again + ns_list_foreach(coap_blockwise_payload_s, payload_info_ptr, &handle->linked_list_blockwise_received_payloads) { + if (0 == memcmp(addr_ptr->addr_ptr, payload_info_ptr->addr_ptr, addr_ptr->addr_len)) { + if (payload_info_ptr->port == addr_ptr->port && payload_info_ptr->block_number == block_number) { + return; + } + } + } + coap_blockwise_payload_s *stored_blockwise_payload_ptr = NULL; /* * * * Allocating memory for stored Payload * * * */