Skip to content

Fix for blockwise observation failure #4332

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions features/FEATURE_COMMON_PAL/mbed-coap/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
41 changes: 33 additions & 8 deletions features/FEATURE_COMMON_PAL/mbed-coap/source/sn_coap_protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand Down Expand Up @@ -641,11 +639,19 @@ 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 = true;
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;
}
}
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);
Expand Down Expand Up @@ -733,6 +739,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;
Expand All @@ -747,8 +757,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,
Expand Down Expand Up @@ -1801,7 +1812,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 * * */
Expand Down Expand Up @@ -1903,6 +1913,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);

Expand Down