Skip to content

Support for BLOCK2 blockwise messages GET request handling #5811

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 1 commit into from
Jan 11, 2018
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
10 changes: 7 additions & 3 deletions features/FEATURE_COMMON_PAL/mbed-coap/source/sn_coap_builder.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,22 @@ sn_coap_hdr_s *sn_coap_build_response(struct coap_s *handle, sn_coap_hdr_s *coap
return NULL;
}

if (coap_packet_ptr->msg_type == COAP_MSG_TYPE_CONFIRMABLE) {
if (msg_code == COAP_MSG_CODE_REQUEST_GET) {
// Blockwise message response is new GET
coap_res_ptr->msg_type = COAP_MSG_TYPE_CONFIRMABLE;
coap_res_ptr->msg_code = (sn_coap_msg_code_e)msg_code;
/* msg_id needs to be set by the caller in this case */
}
else if (coap_packet_ptr->msg_type == COAP_MSG_TYPE_CONFIRMABLE) {
coap_res_ptr->msg_type = COAP_MSG_TYPE_ACKNOWLEDGEMENT;
coap_res_ptr->msg_code = (sn_coap_msg_code_e)msg_code;
coap_res_ptr->msg_id = coap_packet_ptr->msg_id;
}

else if (coap_packet_ptr->msg_type == COAP_MSG_TYPE_NON_CONFIRMABLE) {
coap_res_ptr->msg_type = COAP_MSG_TYPE_NON_CONFIRMABLE;
coap_res_ptr->msg_code = (sn_coap_msg_code_e)msg_code;
/* msg_id needs to be set by the caller in this case */
}

else {
handle->sn_coap_protocol_free( coap_res_ptr );
return NULL;
Expand Down
43 changes: 29 additions & 14 deletions features/FEATURE_COMMON_PAL/mbed-coap/source/sn_coap_protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -1840,8 +1840,7 @@ static sn_coap_hdr_s *sn_coap_handle_blockwise_message(struct coap_s *handle, sn
src_addr_ptr,
received_coap_msg_ptr->payload_len,
received_coap_msg_ptr->payload_ptr,
received_coap_msg_ptr->options_list_ptr->block1 >> 4);

received_coap_msg_ptr->options_list_ptr->block2 >> 4);
/* If not last block (more value is set) */
if (received_coap_msg_ptr->options_list_ptr->block2 & 0x08) {
coap_blockwise_msg_s *previous_blockwise_msg_ptr = NULL;
Expand All @@ -1867,18 +1866,6 @@ static sn_coap_hdr_s *sn_coap_handle_blockwise_message(struct coap_s *handle, sn
return 0;
}

ns_list_remove(&handle->linked_list_blockwise_sent_msgs, previous_blockwise_msg_ptr);
if( previous_blockwise_msg_ptr->coap_msg_ptr ){
if(previous_blockwise_msg_ptr->coap_msg_ptr->payload_ptr){
handle->sn_coap_protocol_free(previous_blockwise_msg_ptr->coap_msg_ptr->payload_ptr);
previous_blockwise_msg_ptr->coap_msg_ptr->payload_ptr = 0;
}
sn_coap_parser_release_allocated_coap_msg_mem(handle, previous_blockwise_msg_ptr->coap_msg_ptr);
previous_blockwise_msg_ptr->coap_msg_ptr = 0;
}
handle->sn_coap_protocol_free(previous_blockwise_msg_ptr);
previous_blockwise_msg_ptr = 0;

/* * * Then build CoAP Acknowledgement message * * */

if (sn_coap_parser_alloc_options(handle, src_coap_blockwise_ack_msg_ptr) == NULL) {
Expand All @@ -1902,6 +1889,34 @@ static sn_coap_hdr_s *sn_coap_handle_blockwise_message(struct coap_s *handle, sn

src_coap_blockwise_ack_msg_ptr->options_list_ptr->block2 = (block_number << 4) | block_temp;


/* Set BLOCK2 (subsequent) GET msg code and copy uri path from previous msg*/
if (received_coap_msg_ptr->msg_code == COAP_MSG_CODE_RESPONSE_CONTENT) {
src_coap_blockwise_ack_msg_ptr->msg_code = COAP_MSG_CODE_REQUEST_GET;
if (previous_blockwise_msg_ptr->coap_msg_ptr->uri_path_ptr) {
src_coap_blockwise_ack_msg_ptr->uri_path_len = previous_blockwise_msg_ptr->coap_msg_ptr->uri_path_len;
src_coap_blockwise_ack_msg_ptr->uri_path_ptr = handle->sn_coap_protocol_malloc(previous_blockwise_msg_ptr->coap_msg_ptr->uri_path_len);
if (!src_coap_blockwise_ack_msg_ptr->uri_path_ptr) {
sn_coap_parser_release_allocated_coap_msg_mem(handle, src_coap_blockwise_ack_msg_ptr);
tr_error("sn_coap_handle_blockwise_message - failed to allocate for uri path ptr!");
return NULL;
}
memcpy(src_coap_blockwise_ack_msg_ptr->uri_path_ptr, previous_blockwise_msg_ptr->coap_msg_ptr->uri_path_ptr, previous_blockwise_msg_ptr->coap_msg_ptr->uri_path_len);
}
}

ns_list_remove(&handle->linked_list_blockwise_sent_msgs, previous_blockwise_msg_ptr);
if (previous_blockwise_msg_ptr->coap_msg_ptr) {
if (previous_blockwise_msg_ptr->coap_msg_ptr->payload_ptr) {
handle->sn_coap_protocol_free(previous_blockwise_msg_ptr->coap_msg_ptr->payload_ptr);
previous_blockwise_msg_ptr->coap_msg_ptr->payload_ptr = 0;
}
sn_coap_parser_release_allocated_coap_msg_mem(handle, previous_blockwise_msg_ptr->coap_msg_ptr);
previous_blockwise_msg_ptr->coap_msg_ptr = 0;
}
handle->sn_coap_protocol_free(previous_blockwise_msg_ptr);
previous_blockwise_msg_ptr = 0;

/* Then get needed memory count for Packet data */
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