diff --git a/features/FEATURE_COMMON_PAL/mbed-coap/CHANGELOG.md b/features/FEATURE_COMMON_PAL/mbed-coap/CHANGELOG.md index 9b2c59ed47..f4f7ad8162 100644 --- a/features/FEATURE_COMMON_PAL/mbed-coap/CHANGELOG.md +++ b/features/FEATURE_COMMON_PAL/mbed-coap/CHANGELOG.md @@ -1,5 +1,12 @@ # Change Log +## [v4.0.4](https://github.com/ARMmbed/mbed-coap/releases/tag/v4.0.4) + +-[Full Changelog](https://github.com/ARMmbed/mbed-coap/compare/v4.0.3...v4.0.4) + + **Closed issues:** + - https://github.com/ARMmbed/mbed-client/issues/481 - Obs Con blockwise fails to transmit 2nd block + ## [v4.0.3](https://github.com/ARMmbed/mbed-coap/releases/tag/v4.0.3) -[Full Changelog](https://github.com/ARMmbed/mbed-coap/compare/v4.0.2...v4.0.3) 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 2df34e3dd3..4c61b3fa70 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 @@ -474,7 +474,6 @@ 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; - ns_list_add_to_end(&handle->linked_list_blockwise_sent_msgs, stored_blockwise_msg_ptr); } @@ -499,7 +498,6 @@ int16_t sn_coap_protocol_build(struct coap_s *handle, sn_nsdl_addr_s *dst_addr_p } stored_blockwise_msg_ptr->coap = handle; - ns_list_add_to_end(&handle->linked_list_blockwise_sent_msgs, stored_blockwise_msg_ptr); } @@ -641,11 +639,21 @@ sn_coap_hdr_s *sn_coap_protocol_parse(struct coap_s *handle, sn_nsdl_addr_s *src break; } } - + /* Remove from the list if not an notification message. + * Initial notification message is needed for sending rest of the blocks (GET request). + */ + bool remove_from_the_list = false; if (stored_blockwise_msg_temp_ptr) { - tr_debug("sn_coap_protocol_parse - remove block message %d", stored_blockwise_msg_temp_ptr->coap_msg_ptr->msg_id); + if (stored_blockwise_msg_temp_ptr->coap_msg_ptr && + stored_blockwise_msg_temp_ptr->coap_msg_ptr->options_list_ptr && + stored_blockwise_msg_temp_ptr->coap_msg_ptr->options_list_ptr->observe != COAP_OBSERVE_NONE) { + remove_from_the_list = false; + } else { + remove_from_the_list = true; + } + } + if (remove_from_the_list) { ns_list_remove(&handle->linked_list_blockwise_sent_msgs, stored_blockwise_msg_temp_ptr); - if (stored_blockwise_msg_temp_ptr->coap_msg_ptr) { if(stored_blockwise_msg_temp_ptr->coap_msg_ptr->payload_ptr){ handle->sn_coap_protocol_free(stored_blockwise_msg_temp_ptr->coap_msg_ptr->payload_ptr); @@ -733,6 +741,10 @@ int8_t sn_coap_protocol_exec(struct coap_s *handle, uint32_t current_time) uint16_t temp_msg_id = (stored_msg_ptr->send_msg_ptr->packet_ptr[2] << 8); temp_msg_id += (uint16_t)stored_msg_ptr->send_msg_ptr->packet_ptr[3]; + /* Remove message from Linked list */ + ns_list_remove(&handle->linked_list_resent_msgs, stored_msg_ptr); + --handle->count_resent_msgs; + /* If RX callback have been defined.. */ if (stored_msg_ptr->coap->sn_coap_rx_callback != 0) { sn_coap_hdr_s *tmp_coap_hdr_ptr; @@ -747,8 +759,9 @@ int8_t sn_coap_protocol_exec(struct coap_s *handle, uint32_t current_time) sn_coap_parser_release_allocated_coap_msg_mem(stored_msg_ptr->coap, tmp_coap_hdr_ptr); } } - /* Remove message from Linked list */ - sn_coap_protocol_linked_list_send_msg_remove(handle, stored_msg_ptr->send_msg_ptr->dst_addr_ptr, temp_msg_id); + + /* Free memory of stored message */ + sn_coap_protocol_release_allocated_send_msg_mem(handle, stored_msg_ptr); } else { /* Send message */ stored_msg_ptr->coap->sn_coap_tx_callback(stored_msg_ptr->send_msg_ptr->packet_ptr, @@ -1801,7 +1814,6 @@ 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; - ns_list_add_to_end(&handle->linked_list_blockwise_sent_msgs, stored_blockwise_msg_ptr); /* * * Then release memory of CoAP Acknowledgement message * * */ @@ -1903,6 +1915,21 @@ static sn_coap_hdr_s *sn_coap_handle_blockwise_message(struct coap_s *handle, sn src_coap_blockwise_ack_msg_ptr->payload_ptr = stored_blockwise_msg_temp_ptr->coap_msg_ptr->payload_ptr + (block_size * block_number); } + /* Update token to match one which is in GET request. + * This is needed only in case of notification message. + */ + if (src_coap_blockwise_ack_msg_ptr->options_list_ptr && + src_coap_blockwise_ack_msg_ptr->options_list_ptr->observe != COAP_OBSERVE_NONE) { + if (received_coap_msg_ptr->token_len && src_coap_blockwise_ack_msg_ptr->token_ptr) { + handle->sn_coap_protocol_free(src_coap_blockwise_ack_msg_ptr->token_ptr); + src_coap_blockwise_ack_msg_ptr->token_ptr = handle->sn_coap_protocol_malloc(received_coap_msg_ptr->token_len); + if (src_coap_blockwise_ack_msg_ptr->token_ptr) { + memcpy(src_coap_blockwise_ack_msg_ptr->token_ptr, received_coap_msg_ptr->token_ptr, received_coap_msg_ptr->token_len); + src_coap_blockwise_ack_msg_ptr->token_len = received_coap_msg_ptr->token_len; + } + } + } + /* Build and send block message */ dst_packed_data_needed_mem = sn_coap_builder_calc_needed_packet_data_size_2(src_coap_blockwise_ack_msg_ptr, handle->sn_coap_block_data_size);