Skip to content

Commit f1ecb51

Browse files
authored
Merge pull request #5811 from anttiylitokola/coap_change
Support for BLOCK2 blockwise messages GET request handling
2 parents 6c855e1 + 7fedd98 commit f1ecb51

File tree

2 files changed

+36
-17
lines changed

2 files changed

+36
-17
lines changed

features/FEATURE_COMMON_PAL/mbed-coap/source/sn_coap_builder.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,22 @@ sn_coap_hdr_s *sn_coap_build_response(struct coap_s *handle, sn_coap_hdr_s *coap
6363
return NULL;
6464
}
6565

66-
if (coap_packet_ptr->msg_type == COAP_MSG_TYPE_CONFIRMABLE) {
66+
if (msg_code == COAP_MSG_CODE_REQUEST_GET) {
67+
// Blockwise message response is new GET
68+
coap_res_ptr->msg_type = COAP_MSG_TYPE_CONFIRMABLE;
69+
coap_res_ptr->msg_code = (sn_coap_msg_code_e)msg_code;
70+
/* msg_id needs to be set by the caller in this case */
71+
}
72+
else if (coap_packet_ptr->msg_type == COAP_MSG_TYPE_CONFIRMABLE) {
6773
coap_res_ptr->msg_type = COAP_MSG_TYPE_ACKNOWLEDGEMENT;
6874
coap_res_ptr->msg_code = (sn_coap_msg_code_e)msg_code;
6975
coap_res_ptr->msg_id = coap_packet_ptr->msg_id;
7076
}
71-
7277
else if (coap_packet_ptr->msg_type == COAP_MSG_TYPE_NON_CONFIRMABLE) {
7378
coap_res_ptr->msg_type = COAP_MSG_TYPE_NON_CONFIRMABLE;
7479
coap_res_ptr->msg_code = (sn_coap_msg_code_e)msg_code;
7580
/* msg_id needs to be set by the caller in this case */
7681
}
77-
7882
else {
7983
handle->sn_coap_protocol_free( coap_res_ptr );
8084
return NULL;

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

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1840,8 +1840,7 @@ static sn_coap_hdr_s *sn_coap_handle_blockwise_message(struct coap_s *handle, sn
18401840
src_addr_ptr,
18411841
received_coap_msg_ptr->payload_len,
18421842
received_coap_msg_ptr->payload_ptr,
1843-
received_coap_msg_ptr->options_list_ptr->block1 >> 4);
1844-
1843+
received_coap_msg_ptr->options_list_ptr->block2 >> 4);
18451844
/* If not last block (more value is set) */
18461845
if (received_coap_msg_ptr->options_list_ptr->block2 & 0x08) {
18471846
coap_blockwise_msg_s *previous_blockwise_msg_ptr = NULL;
@@ -1867,18 +1866,6 @@ static sn_coap_hdr_s *sn_coap_handle_blockwise_message(struct coap_s *handle, sn
18671866
return 0;
18681867
}
18691868

1870-
ns_list_remove(&handle->linked_list_blockwise_sent_msgs, previous_blockwise_msg_ptr);
1871-
if( previous_blockwise_msg_ptr->coap_msg_ptr ){
1872-
if(previous_blockwise_msg_ptr->coap_msg_ptr->payload_ptr){
1873-
handle->sn_coap_protocol_free(previous_blockwise_msg_ptr->coap_msg_ptr->payload_ptr);
1874-
previous_blockwise_msg_ptr->coap_msg_ptr->payload_ptr = 0;
1875-
}
1876-
sn_coap_parser_release_allocated_coap_msg_mem(handle, previous_blockwise_msg_ptr->coap_msg_ptr);
1877-
previous_blockwise_msg_ptr->coap_msg_ptr = 0;
1878-
}
1879-
handle->sn_coap_protocol_free(previous_blockwise_msg_ptr);
1880-
previous_blockwise_msg_ptr = 0;
1881-
18821869
/* * * Then build CoAP Acknowledgement message * * */
18831870

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

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

1892+
1893+
/* Set BLOCK2 (subsequent) GET msg code and copy uri path from previous msg*/
1894+
if (received_coap_msg_ptr->msg_code == COAP_MSG_CODE_RESPONSE_CONTENT) {
1895+
src_coap_blockwise_ack_msg_ptr->msg_code = COAP_MSG_CODE_REQUEST_GET;
1896+
if (previous_blockwise_msg_ptr->coap_msg_ptr->uri_path_ptr) {
1897+
src_coap_blockwise_ack_msg_ptr->uri_path_len = previous_blockwise_msg_ptr->coap_msg_ptr->uri_path_len;
1898+
src_coap_blockwise_ack_msg_ptr->uri_path_ptr = handle->sn_coap_protocol_malloc(previous_blockwise_msg_ptr->coap_msg_ptr->uri_path_len);
1899+
if (!src_coap_blockwise_ack_msg_ptr->uri_path_ptr) {
1900+
sn_coap_parser_release_allocated_coap_msg_mem(handle, src_coap_blockwise_ack_msg_ptr);
1901+
tr_error("sn_coap_handle_blockwise_message - failed to allocate for uri path ptr!");
1902+
return NULL;
1903+
}
1904+
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);
1905+
}
1906+
}
1907+
1908+
ns_list_remove(&handle->linked_list_blockwise_sent_msgs, previous_blockwise_msg_ptr);
1909+
if (previous_blockwise_msg_ptr->coap_msg_ptr) {
1910+
if (previous_blockwise_msg_ptr->coap_msg_ptr->payload_ptr) {
1911+
handle->sn_coap_protocol_free(previous_blockwise_msg_ptr->coap_msg_ptr->payload_ptr);
1912+
previous_blockwise_msg_ptr->coap_msg_ptr->payload_ptr = 0;
1913+
}
1914+
sn_coap_parser_release_allocated_coap_msg_mem(handle, previous_blockwise_msg_ptr->coap_msg_ptr);
1915+
previous_blockwise_msg_ptr->coap_msg_ptr = 0;
1916+
}
1917+
handle->sn_coap_protocol_free(previous_blockwise_msg_ptr);
1918+
previous_blockwise_msg_ptr = 0;
1919+
19051920
/* Then get needed memory count for Packet data */
19061921
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);
19071922

0 commit comments

Comments
 (0)