Skip to content

Commit 1e9f83f

Browse files
authored
Merge pull request #12868 from teetak01/mbed-coap-v5.1.5-for-wisun
Update mbed-coap to version v5.1.5 for feature-wisun
2 parents e519efd + fab4092 commit 1e9f83f

File tree

4 files changed

+81
-21
lines changed

4 files changed

+81
-21
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
test/*
2+
test_modules/*
23
unittest/*

features/frameworks/mbed-coap/CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
# Change Log
22

3+
## [v5.1.5](https://github.com/ARMmbed/mbed-coap/releases/tag/v5.1.5)
4+
5+
- Added handling for duplicate message handling for Block2 messages. Previously CoAP was silently ignoring the duplicate messages. Now proper response will be sent.
6+
- Added extended version of `sn_coap_protocol_update_duplicate_package_data`, `sn_coap_protocol_update_duplicate_package_data_all` which will handle all CoAP data in the list.
7+
8+
## [v5.1.4](https://github.com/ARMmbed/mbed-coap/releases/tag/v5.1.4)
9+
10+
- Add also 4.13 (Request Entity Too Large) responses to duplicate info list.
11+
- Add client library configurations for `DEFAULT_RESPONSE_TIMEOUT` and `SN_COAP_DUPLICATION_MAX_TIME_MSGS_STORED`.
12+
- Increased the default timeouts of `DEFAULT_RESPONSE_TIMEOUT` and `SN_COAP_DUPLICATION_MAX_TIME_MSGS_STORED` to 300 seconds.
13+
* These two are critical parameters for low-bandwidth high-latency networks. The defaults should be more geared towards such networks that are likely to have issues with transmissions.
14+
* The increased defaults can increase the runtime HEAP usage when there is a lot of duplicates or retransmissions.
15+
316
## [v5.1.3](https://github.com/ARMmbed/mbed-coap/releases/tag/v5.1.3)
417

518
- Fix potential integer overflow when calculating CoAP data packet size: IOTCLT-3748 CVE-2019-17211 - mbed-coap integer overflow

features/frameworks/mbed-coap/mbed-coap/sn_config.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016 ARM Limited. All rights reserved.
2+
* Copyright (c) 2020 ARM Limited. All rights reserved.
33
* SPDX-License-Identifier: Apache-2.0
44
* Licensed under the Apache License, Version 2.0 (the License); you may
55
* not use this file except in compliance with the License.
@@ -98,6 +98,11 @@
9898
* \brief Sets the CoAP re-send interval in seconds.
9999
* By default is 10 seconds.
100100
*/
101+
102+
#ifdef MBED_CONF_MBED_CLIENT_DEFAULT_RESPONSE_TIMEOUT
103+
#define DEFAULT_RESPONSE_TIMEOUT MBED_CONF_MBED_CLIENT_DEFAULT_RESPONSE_TIMEOUT
104+
#endif
105+
101106
#ifndef DEFAULT_RESPONSE_TIMEOUT
102107
#define DEFAULT_RESPONSE_TIMEOUT 10 /**< Default re-sending timeout as seconds */
103108
#endif
@@ -219,8 +224,12 @@
219224
* \brief Maximum time in seconds howe long message is kept for duplicate detection.
220225
* By default 60 seconds.
221226
*/
227+
#ifdef MBED_CONF_MBED_CLIENT_SN_COAP_DUPLICATION_MAX_TIME_MSGS_STORED
228+
#define SN_COAP_DUPLICATION_MAX_TIME_MSGS_STORED MBED_CONF_MBED_CLIENT_SN_COAP_DUPLICATION_MAX_TIME_MSGS_STORED
229+
#endif
230+
222231
#ifndef SN_COAP_DUPLICATION_MAX_TIME_MSGS_STORED
223-
#define SN_COAP_DUPLICATION_MAX_TIME_MSGS_STORED 60 /** RESPONSE_TIMEOUT * RESPONSE_RANDOM_FACTOR * (2 ^ MAX_RETRANSMIT - 1) + the expected maximum round trip time **/
232+
#define SN_COAP_DUPLICATION_MAX_TIME_MSGS_STORED 300 /** RESPONSE_TIMEOUT * RESPONSE_RANDOM_FACTOR * (2 ^ MAX_RETRANSMIT - 1) + the expected maximum round trip time **/
224233
#endif
225234

226235
/**
@@ -234,7 +243,7 @@
234243
#endif
235244

236245
#ifndef SN_COAP_BLOCKWISE_MAX_TIME_DATA_STORED
237-
#define SN_COAP_BLOCKWISE_MAX_TIME_DATA_STORED 60 /**< Maximum time in seconds of data (messages and payload) to be stored for blockwising */
246+
#define SN_COAP_BLOCKWISE_MAX_TIME_DATA_STORED 300 /**< Maximum time in seconds of data (messages and payload) to be stored for blockwising */
238247
#endif
239248

240249
/**

features/frameworks/mbed-coap/source/sn_coap_protocol.c

Lines changed: 55 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ static coap_duplication_info_s *sn_coap_protocol_linked_list_duplication_info_se
5353
static void sn_coap_protocol_linked_list_duplication_info_remove_old_ones(struct coap_s *handle);
5454
static void sn_coap_protocol_duplication_info_free(struct coap_s *handle, coap_duplication_info_s *duplication_info_ptr);
5555
static bool sn_coap_protocol_update_duplicate_package_data(const struct coap_s *handle, const sn_nsdl_addr_s *dst_addr_ptr, const sn_coap_hdr_s *coap_msg_ptr, const int16_t data_size, const uint8_t *dst_packet_data_ptr);
56+
static bool sn_coap_protocol_update_duplicate_package_data_all(const struct coap_s *handle, const sn_nsdl_addr_s *dst_addr_ptr, const sn_coap_hdr_s *coap_msg_ptr, const int16_t data_size, const uint8_t *dst_packet_data_ptr);
57+
5658
#endif
5759

5860
#if SN_COAP_BLOCKWISE_ENABLED || SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE /* If Message blockwising is not enabled, this part of code will not be compiled */
@@ -690,6 +692,8 @@ sn_coap_hdr_s *sn_coap_protocol_parse(struct coap_s *handle, sn_nsdl_addr_s *src
690692
tr_debug("sn_coap_protocol_parse - send ack for duplicate message");
691693
handle->sn_coap_tx_callback(response->packet_ptr,
692694
response->packet_len, response->address, response->param);
695+
} else {
696+
tr_error("sn_coap_protocol_parse - response not yet build");
693697
}
694698
}
695699

@@ -759,6 +763,14 @@ sn_coap_hdr_s *sn_coap_protocol_parse(struct coap_s *handle, sn_nsdl_addr_s *src
759763
goto cleanup;
760764
}
761765

766+
#if SN_COAP_DUPLICATION_MAX_MSGS_COUNT
767+
// copy data buffer to duplicate list for resending purposes
768+
if (!sn_coap_protocol_update_duplicate_package_data(handle, src_addr_ptr, resp, packet_data_size, packet_data_ptr)) {
769+
tr_error("sn_coap_protocol_parse - failed to update duplicate info!");
770+
goto cleanup;
771+
}
772+
#endif
773+
762774
sn_coap_parser_release_allocated_coap_msg_mem(handle, resp);
763775

764776
handle->sn_coap_tx_callback(packet_data_ptr, packet_data_size, src_addr_ptr, param);
@@ -2227,6 +2239,20 @@ static sn_coap_hdr_s *sn_coap_handle_blockwise_message(struct coap_s *handle, sn
22272239
}
22282240

22292241
sn_coap_builder_2(dst_ack_packet_data_ptr, src_coap_blockwise_ack_msg_ptr, handle->sn_coap_block_data_size);
2242+
2243+
#if SN_COAP_DUPLICATION_MAX_MSGS_COUNT
2244+
// copy coap data buffer to duplicate list for resending purposes
2245+
if (!sn_coap_protocol_update_duplicate_package_data_all(handle,
2246+
src_addr_ptr,
2247+
src_coap_blockwise_ack_msg_ptr,
2248+
dst_packed_data_needed_mem,
2249+
dst_ack_packet_data_ptr)) {
2250+
sn_coap_parser_release_allocated_coap_msg_mem(handle, src_coap_blockwise_ack_msg_ptr);
2251+
handle->sn_coap_protocol_free(dst_ack_packet_data_ptr);
2252+
return NULL;
2253+
}
2254+
#endif
2255+
22302256
handle->sn_coap_tx_callback(dst_ack_packet_data_ptr, dst_packed_data_needed_mem, src_addr_ptr, param);
22312257

22322258
handle->sn_coap_protocol_free(dst_ack_packet_data_ptr);
@@ -2426,27 +2452,38 @@ static sn_coap_hdr_s *sn_coap_protocol_copy_header(struct coap_s *handle, const
24262452

24272453
#if SN_COAP_DUPLICATION_MAX_MSGS_COUNT
24282454
static bool sn_coap_protocol_update_duplicate_package_data(const struct coap_s *handle,
2429-
const sn_nsdl_addr_s *dst_addr_ptr,
2430-
const sn_coap_hdr_s *coap_msg_ptr,
2431-
const int16_t data_size,
2432-
const uint8_t *dst_packet_data_ptr)
2455+
const sn_nsdl_addr_s *dst_addr_ptr,
2456+
const sn_coap_hdr_s *coap_msg_ptr,
2457+
const int16_t data_size,
2458+
const uint8_t *dst_packet_data_ptr)
24332459
{
24342460
if (coap_msg_ptr->msg_type == COAP_MSG_TYPE_ACKNOWLEDGEMENT &&
24352461
handle->sn_coap_duplication_buffer_size != 0) {
2436-
coap_duplication_info_s* info = sn_coap_protocol_linked_list_duplication_info_search(handle,
2437-
dst_addr_ptr,
2438-
coap_msg_ptr->msg_id);
2439-
2440-
/* Update package data to duplication info struct if it's not there yet */
2441-
if (info && info->packet_ptr == NULL) {
2442-
info->packet_ptr = handle->sn_coap_protocol_malloc(data_size);
2443-
if (info->packet_ptr) {
2444-
memcpy(info->packet_ptr, dst_packet_data_ptr, data_size);
2445-
info->packet_len = data_size;
2446-
} else {
2447-
tr_error("sn_coap_protocol_update_duplication_package_data - failed to allocate duplication info!");
2448-
return false;
2449-
}
2462+
return sn_coap_protocol_update_duplicate_package_data_all(handle, dst_addr_ptr, coap_msg_ptr, data_size, dst_packet_data_ptr);
2463+
}
2464+
return true;
2465+
}
2466+
2467+
static bool sn_coap_protocol_update_duplicate_package_data_all(const struct coap_s *handle,
2468+
const sn_nsdl_addr_s *dst_addr_ptr,
2469+
const sn_coap_hdr_s *coap_msg_ptr,
2470+
const int16_t data_size,
2471+
const uint8_t *dst_packet_data_ptr)
2472+
{
2473+
coap_duplication_info_s* info = sn_coap_protocol_linked_list_duplication_info_search(handle,
2474+
dst_addr_ptr,
2475+
coap_msg_ptr->msg_id);
2476+
2477+
/* Update package data to duplication info struct if it's not there yet */
2478+
if (info && info->packet_ptr == NULL) {
2479+
info->packet_ptr = handle->sn_coap_protocol_malloc(data_size);
2480+
if (info->packet_ptr) {
2481+
tr_debug("sn_coap_protocol_update_duplication_package_data - added to duplicate list!");
2482+
memcpy(info->packet_ptr, dst_packet_data_ptr, data_size);
2483+
info->packet_len = data_size;
2484+
} else {
2485+
tr_error("sn_coap_protocol_update_duplication_package_data - failed to allocate duplication info!");
2486+
return false;
24502487
}
24512488
}
24522489
return true;

0 commit comments

Comments
 (0)