Skip to content

Commit

Permalink
Merge pull request #6883 from anttiylitokola/master
Browse files Browse the repository at this point in the history
Update mbed-coap to version 4.4.3
  • Loading branch information
Cruz Monrreal committed May 14, 2018
2 parents d3cc4e1 + 511df14 commit 9923899
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 16 deletions.
8 changes: 8 additions & 0 deletions features/frameworks/mbed-coap/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Change Log

## [v4.4.3](https://github.com/ARMmbed/mbed-coap/releases/tag/v4.4.3)
**Closed issues:**
- IOTCLT-2506 [GitHub] Cannot set registration time if server does not use max age option

Extend blockwise message transfer status to have states for sending as well.

-[Full Changelog](https://github.com/ARMmbed/mbed-coap/compare/v4.4.2...v4.4.3)

## [v4.4.2](https://github.com/ARMmbed/mbed-coap/releases/tag/v4.4.2)
**Closed issues:**
- IOTCLT-2469 CoAP UDP retransmission does not work for blocks after first one for requests (Eg. registration POST)
Expand Down
10 changes: 9 additions & 1 deletion features/frameworks/mbed-coap/mbed-coap/sn_coap_header.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,16 @@ typedef enum sn_coap_status_ {
COAP_STATUS_PARSER_BLOCKWISE_MSG_REJECTED = 5, /**< Blockwise message received but not supported by compiling switch */
COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED = 6, /**< Blockwise message fully received and returned to app.
User must take care of releasing whole payload of the blockwise messages */
COAP_STATUS_BUILDER_MESSAGE_SENDING_FAILED = 7 /**< When re-transmissions have been done and ACK not received, CoAP library calls
COAP_STATUS_BUILDER_MESSAGE_SENDING_FAILED = 7, /**< When re-transmissions have been done and ACK not received, CoAP library calls
RX callback with this status */

COAP_STATUS_BUILDER_BLOCK_SENDING_FAILED = 8, /**< Blockwise message sending timeout.
The msg_id in sn_coap_hdr_s* parameter of RX callback is set to the same value
as in the first block sent, and parameter sn_nsdl_addr_s* is set as NULL. */
COAP_STATUS_BUILDER_BLOCK_SENDING_DONE = 9 /**< Blockwise message sending, last block sent.
The msg_id in sn_coap_hdr_s* parameter of RX callback is set to the same value
as in the first block sent, and parameter sn_nsdl_addr_s* is set as NULL. */

} sn_coap_status_e;


Expand Down
2 changes: 1 addition & 1 deletion features/frameworks/mbed-coap/module.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mbed-coap",
"version": "4.4.2",
"version": "4.4.3",
"description": "COAP library",
"keywords": [
"coap",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,10 @@ typedef struct coap_blockwise_msg_ {
sn_coap_hdr_s *coap_msg_ptr;
struct coap_s *coap; /* CoAP library handle */

ns_list_link_t link;
void *param;
uint16_t msg_id;

ns_list_link_t link;
} coap_blockwise_msg_s;

typedef NS_LIST_HEAD(coap_blockwise_msg_s, link) coap_blockwise_msg_list_t;
Expand Down
2 changes: 1 addition & 1 deletion features/frameworks/mbed-coap/source/sn_coap_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ sn_coap_options_list_s *sn_coap_parser_alloc_options(struct coap_s *handle, sn_c
/* XXX not technically legal to memset pointers to 0 */
memset(coap_msg_ptr->options_list_ptr, 0x00, sizeof(sn_coap_options_list_s));

coap_msg_ptr->options_list_ptr->max_age = COAP_OPTION_MAX_AGE_DEFAULT;
coap_msg_ptr->options_list_ptr->max_age = 0;
coap_msg_ptr->options_list_ptr->uri_port = COAP_OPTION_URI_PORT_NONE;
coap_msg_ptr->options_list_ptr->observe = COAP_OBSERVE_NONE;
coap_msg_ptr->options_list_ptr->accept = COAP_CT_NONE;
Expand Down
46 changes: 34 additions & 12 deletions features/frameworks/mbed-coap/source/sn_coap_protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static bool sn_coap_protocol_linked_list_blockwise_payload_comp
static void sn_coap_protocol_linked_list_blockwise_payload_remove(struct coap_s *handle, coap_blockwise_payload_s *removed_payload_ptr);
static void sn_coap_protocol_linked_list_blockwise_payload_remove_oldest(struct coap_s *handle);
static uint32_t sn_coap_protocol_linked_list_blockwise_payloads_get_len(struct coap_s *handle, sn_nsdl_addr_s *src_addr_ptr);
static void sn_coap_protocol_linked_list_blockwise_remove_old_data(struct coap_s *handle);
static void sn_coap_protocol_handle_blockwise_timout(struct coap_s *handle);
static sn_coap_hdr_s *sn_coap_handle_blockwise_message(struct coap_s *handle, sn_nsdl_addr_s *src_addr_ptr, sn_coap_hdr_s *received_coap_msg_ptr, void *param);
static sn_coap_hdr_s *sn_coap_protocol_copy_header(struct coap_s *handle, sn_coap_hdr_s *source_header_ptr);
#endif
Expand Down Expand Up @@ -538,6 +538,8 @@ int16_t sn_coap_protocol_build(struct coap_s *handle, sn_nsdl_addr_s *dst_addr_p
memcpy(stored_blockwise_msg_ptr->coap_msg_ptr->payload_ptr, src_coap_msg_ptr->payload_ptr, stored_blockwise_msg_ptr->coap_msg_ptr->payload_len);

stored_blockwise_msg_ptr->coap = handle;
stored_blockwise_msg_ptr->param = param;
stored_blockwise_msg_ptr->msg_id = stored_blockwise_msg_ptr->coap_msg_ptr->msg_id;
ns_list_add_to_end(&handle->linked_list_blockwise_sent_msgs, stored_blockwise_msg_ptr);
}

Expand All @@ -564,6 +566,8 @@ int16_t sn_coap_protocol_build(struct coap_s *handle, sn_nsdl_addr_s *dst_addr_p
}

stored_blockwise_msg_ptr->coap = handle;
stored_blockwise_msg_ptr->param = param;
stored_blockwise_msg_ptr->msg_id = stored_blockwise_msg_ptr->coap_msg_ptr->msg_id;
ns_list_add_to_end(&handle->linked_list_blockwise_sent_msgs, stored_blockwise_msg_ptr);
}

Expand Down Expand Up @@ -794,12 +798,12 @@ int8_t sn_coap_protocol_exec(struct coap_s *handle, uint32_t current_time)

/* * * * Store current System time * * * */
handle->system_time = current_time;

#if SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE
/* * * * Remove old blocwise data * * * */
sn_coap_protocol_linked_list_blockwise_remove_old_data(handle);
/* * * * Handle block transfer timed outs * * * */
sn_coap_protocol_handle_blockwise_timout(handle);
#endif


#if SN_COAP_DUPLICATION_MAX_MSGS_COUNT
/* * * * Remove old duplication messages * * * */
sn_coap_protocol_linked_list_duplication_info_remove_old_ones(handle);
Expand Down Expand Up @@ -1455,20 +1459,29 @@ static uint32_t sn_coap_protocol_linked_list_blockwise_payloads_get_len(struct c
}

/**************************************************************************//**
* \fn static void sn_coap_protocol_linked_list_blockwise_remove_old_data(struct coap_s *handle)
* \fn static void sn_coap_protocol_handle_blockwise_timout(struct coap_s *handle)
*
* \brief Removes old stored Blockwise messages and payloads from Linked list
* \brief Check incoming and outgoing blockwise messages for time out.
* Remove timed out messages from lists. Notify application if
* outgoing message times out.
*****************************************************************************/

static void sn_coap_protocol_linked_list_blockwise_remove_old_data(struct coap_s *handle)
static void sn_coap_protocol_handle_blockwise_timout(struct coap_s *handle)
{
/* Loop all stored Blockwise messages in Linked list */
/* Loop all outgoing blockwise messages */
ns_list_foreach_safe(coap_blockwise_msg_s, removed_blocwise_msg_ptr, &handle->linked_list_blockwise_sent_msgs) {
if ((handle->system_time - removed_blocwise_msg_ptr->timestamp) > SN_COAP_BLOCKWISE_MAX_TIME_DATA_STORED) {
//TODO: Check do we need to check handle == removed_blocwise_msg_ptr->coap here?

/* * * * Old Blockise message found, remove it from Linked list * * * */
/* * * * This messages has timed out, remove it from Linked list * * * */
if( removed_blocwise_msg_ptr->coap_msg_ptr ){

if (handle->sn_coap_rx_callback) {
/* Notify the application about the time out */
removed_blocwise_msg_ptr->coap_msg_ptr->coap_status = COAP_STATUS_BUILDER_BLOCK_SENDING_FAILED;
removed_blocwise_msg_ptr->coap_msg_ptr->msg_id = removed_blocwise_msg_ptr->msg_id;
handle->sn_coap_rx_callback(removed_blocwise_msg_ptr->coap_msg_ptr, NULL, removed_blocwise_msg_ptr->param);
}

if(removed_blocwise_msg_ptr->coap_msg_ptr->payload_ptr){
handle->sn_coap_protocol_free(removed_blocwise_msg_ptr->coap_msg_ptr->payload_ptr);
removed_blocwise_msg_ptr->coap_msg_ptr->payload_ptr = 0;
Expand All @@ -1480,10 +1493,10 @@ static void sn_coap_protocol_linked_list_blockwise_remove_old_data(struct coap_s
}
}

/* Loop all stored Blockwise payloads in Linked list */
/* Loop all incoming Blockwise messages */
ns_list_foreach_safe(coap_blockwise_payload_s, removed_blocwise_payload_ptr, &handle->linked_list_blockwise_received_payloads) {
if ((handle->system_time - removed_blocwise_payload_ptr->timestamp) > SN_COAP_BLOCKWISE_MAX_TIME_DATA_STORED) {
/* * * * Old Blockise payload found, remove it from Linked list * * * */
/* * * * This messages has timed out, remove it from Linked list * * * */
sn_coap_protocol_linked_list_blockwise_payload_remove(handle, removed_blocwise_payload_ptr);
}
}
Expand Down Expand Up @@ -2056,6 +2069,8 @@ static sn_coap_hdr_s *sn_coap_handle_blockwise_message(struct coap_s *handle, sn

stored_blockwise_msg_ptr->coap_msg_ptr = src_coap_blockwise_ack_msg_ptr;
stored_blockwise_msg_ptr->coap = handle;
stored_blockwise_msg_ptr->param = param;
stored_blockwise_msg_ptr->msg_id = stored_blockwise_msg_ptr->coap_msg_ptr->msg_id;
ns_list_add_to_end(&handle->linked_list_blockwise_sent_msgs, stored_blockwise_msg_ptr);

/* * * Then release memory of CoAP Acknowledgement message * * */
Expand Down Expand Up @@ -2201,6 +2216,13 @@ static sn_coap_hdr_s *sn_coap_handle_blockwise_message(struct coap_s *handle, sn
stored_blockwise_msg_temp_ptr->coap_msg_ptr->payload_ptr = original_payload_ptr;

if ((block_size * (block_number + 1)) >= stored_blockwise_msg_temp_ptr->coap_msg_ptr->payload_len) {

if (handle->sn_coap_rx_callback) {
stored_blockwise_msg_temp_ptr->coap_msg_ptr->coap_status = COAP_STATUS_BUILDER_BLOCK_SENDING_DONE;
stored_blockwise_msg_temp_ptr->coap_msg_ptr->msg_id = stored_blockwise_msg_temp_ptr->msg_id;
handle->sn_coap_rx_callback(stored_blockwise_msg_temp_ptr->coap_msg_ptr, NULL, stored_blockwise_msg_temp_ptr->param);
}

sn_coap_protocol_linked_list_blockwise_msg_remove(handle, stored_blockwise_msg_temp_ptr);
}

Expand Down

0 comments on commit 9923899

Please sign in to comment.