49
49
50
50
#if SN_COAP_DUPLICATION_MAX_MSGS_COUNT /* If Message duplication detection is not used at all, this part of code will not be compiled */
51
51
static void sn_coap_protocol_linked_list_duplication_info_store (struct coap_s * handle , sn_nsdl_addr_s * src_addr_ptr , uint16_t msg_id , void * param );
52
- static coap_duplication_info_s * sn_coap_protocol_linked_list_duplication_info_search (struct coap_s * handle , sn_nsdl_addr_s * scr_addr_ptr , uint16_t msg_id );
52
+ static coap_duplication_info_s * sn_coap_protocol_linked_list_duplication_info_search (const struct coap_s * handle , const sn_nsdl_addr_s * scr_addr_ptr , const uint16_t msg_id );
53
53
static void sn_coap_protocol_linked_list_duplication_info_remove (struct coap_s * handle , uint8_t * scr_addr_ptr , uint16_t port , uint16_t msg_id );
54
54
static void sn_coap_protocol_linked_list_duplication_info_remove_old_ones (struct coap_s * handle );
55
+ static bool sn_coap_protocol_update_duplicate_package_data (const struct coap_s * handle , const sn_nsdl_addr_s * dst_addr_ptr , const sn_coap_hdr_s * coap_msg_ptr , const int16_t data_size , const uint8_t * dst_packet_data_ptr );
55
56
#endif
57
+
56
58
#if SN_COAP_BLOCKWISE_ENABLED || SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE /* If Message blockwising is not enabled, this part of code will not be compiled */
57
59
static void sn_coap_protocol_linked_list_blockwise_msg_remove (struct coap_s * handle , coap_blockwise_msg_s * removed_msg_ptr );
58
60
static void sn_coap_protocol_linked_list_blockwise_payload_store (struct coap_s * handle , sn_nsdl_addr_s * addr_ptr , uint16_t stored_payload_len , uint8_t * stored_payload_ptr , uint8_t * token_ptr , uint8_t token_len , uint32_t block_number );
@@ -65,6 +67,7 @@ static void sn_coap_protocol_handle_blockwise_timout(struct coa
65
67
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 );
66
68
static sn_coap_hdr_s * sn_coap_protocol_copy_header (struct coap_s * handle , sn_coap_hdr_s * source_header_ptr );
67
69
#endif
70
+
68
71
#if ENABLE_RESENDINGS
69
72
static uint8_t sn_coap_protocol_linked_list_send_msg_store (struct coap_s * handle , sn_nsdl_addr_s * dst_addr_ptr , uint16_t send_packet_data_len , uint8_t * send_packet_data_ptr , uint32_t sending_time , void * param );
70
73
static sn_nsdl_transmit_s * sn_coap_protocol_linked_list_send_msg_search (struct coap_s * handle ,sn_nsdl_addr_s * src_addr_ptr , uint16_t msg_id );
@@ -506,23 +509,12 @@ int16_t sn_coap_protocol_build(struct coap_s *handle, sn_nsdl_addr_s *dst_addr_p
506
509
#endif /* ENABLE_RESENDINGS */
507
510
508
511
#if SN_COAP_DUPLICATION_MAX_MSGS_COUNT
509
- if (src_coap_msg_ptr -> msg_type == COAP_MSG_TYPE_ACKNOWLEDGEMENT &&
510
- handle -> sn_coap_duplication_buffer_size != 0 ) {
511
- coap_duplication_info_s * info = sn_coap_protocol_linked_list_duplication_info_search (handle ,
512
- dst_addr_ptr ,
513
- src_coap_msg_ptr -> msg_id );
514
- /* Update package data to duplication info struct if it's not there yet */
515
- if (info && info -> packet_ptr == NULL ) {
516
- info -> packet_ptr = handle -> sn_coap_protocol_malloc (byte_count_built );
517
- if (info -> packet_ptr ) {
518
- memcpy (info -> packet_ptr , dst_packet_data_ptr , byte_count_built );
519
- info -> packet_len = byte_count_built ;
520
- } else {
521
- tr_error ("sn_coap_protocol_build - failed to allocate duplication info!" );
522
- return -4 ;
523
- }
524
- }
512
+
513
+ // copy coap data buffer to duplicate list for resending purposes
514
+ if (!sn_coap_protocol_update_duplicate_package_data (handle , dst_addr_ptr , src_coap_msg_ptr , byte_count_built , dst_packet_data_ptr )) {
515
+ return -4 ;
525
516
}
517
+
526
518
#endif
527
519
528
520
#if SN_COAP_BLOCKWISE_ENABLED || SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE /* If Message blockwising is not enabled, this part of code will not be compiled */
@@ -725,6 +717,7 @@ sn_coap_hdr_s *sn_coap_protocol_parse(struct coap_s *handle, sn_nsdl_addr_s *src
725
717
if (response ) {
726
718
/* Check that response has been created */
727
719
if (response -> packet_ptr ) {
720
+ tr_debug ("sn_coap_protocol_parse - send ack for duplicate message" );
728
721
response -> coap -> sn_coap_tx_callback (response -> packet_ptr ,
729
722
response -> packet_len , response -> address , response -> param );
730
723
}
@@ -1154,7 +1147,7 @@ static void sn_coap_protocol_linked_list_duplication_info_store(struct coap_s *h
1154
1147
}
1155
1148
1156
1149
/**************************************************************************/ /**
1157
- * \fn static int8_t sn_coap_protocol_linked_list_duplication_info_search(sn_nsdl_addr_s *addr_ptr, uint16_t msg_id)
1150
+ * \fn static coap_duplication_info_s * sn_coap_protocol_linked_list_duplication_info_search(const struct coap_s *handle, const sn_nsdl_addr_s *scr_addr_ptr, const uint16_t msg_id)
1158
1151
*
1159
1152
* \brief Searches stored message from Linked list (Address and Message ID as key)
1160
1153
*
@@ -1164,8 +1157,8 @@ static void sn_coap_protocol_linked_list_duplication_info_store(struct coap_s *h
1164
1157
* \return Return value is 0 when message found and -1 if not found
1165
1158
*****************************************************************************/
1166
1159
1167
- static coap_duplication_info_s * sn_coap_protocol_linked_list_duplication_info_search (struct coap_s * handle ,
1168
- sn_nsdl_addr_s * addr_ptr , uint16_t msg_id )
1160
+ static coap_duplication_info_s * sn_coap_protocol_linked_list_duplication_info_search (const struct coap_s * handle ,
1161
+ const sn_nsdl_addr_s * addr_ptr , const uint16_t msg_id )
1169
1162
{
1170
1163
/* Loop all nodes in Linked list for searching Message ID */
1171
1164
ns_list_foreach (coap_duplication_info_s , stored_duplication_info_ptr , & handle -> linked_list_duplication_msgs ) {
@@ -2013,6 +2006,19 @@ static sn_coap_hdr_s *sn_coap_handle_blockwise_message(struct coap_s *handle, sn
2013
2006
}
2014
2007
2015
2008
sn_coap_builder_2 (dst_ack_packet_data_ptr , src_coap_blockwise_ack_msg_ptr , handle -> sn_coap_block_data_size );
2009
+
2010
+ #if SN_COAP_DUPLICATION_MAX_MSGS_COUNT
2011
+ // copy coap data buffer to duplicate list for resending purposes
2012
+ if (!sn_coap_protocol_update_duplicate_package_data (handle ,
2013
+ src_addr_ptr ,
2014
+ src_coap_blockwise_ack_msg_ptr ,
2015
+ dst_packed_data_needed_mem ,
2016
+ dst_ack_packet_data_ptr )) {
2017
+ sn_coap_parser_release_allocated_coap_msg_mem (handle , src_coap_blockwise_ack_msg_ptr );
2018
+ handle -> sn_coap_protocol_free (dst_ack_packet_data_ptr );
2019
+ return NULL ;
2020
+ }
2021
+ #endif
2016
2022
handle -> sn_coap_tx_callback (dst_ack_packet_data_ptr , dst_packed_data_needed_mem , src_addr_ptr , param );
2017
2023
2018
2024
sn_coap_parser_release_allocated_coap_msg_mem (handle , src_coap_blockwise_ack_msg_ptr );
@@ -2509,3 +2515,32 @@ static sn_coap_hdr_s *sn_coap_protocol_copy_header(struct coap_s *handle, sn_coa
2509
2515
return destination_header_ptr ;
2510
2516
}
2511
2517
#endif
2518
+
2519
+ #if SN_COAP_DUPLICATION_MAX_MSGS_COUNT
2520
+ static bool sn_coap_protocol_update_duplicate_package_data (const struct coap_s * handle ,
2521
+ const sn_nsdl_addr_s * dst_addr_ptr ,
2522
+ const sn_coap_hdr_s * coap_msg_ptr ,
2523
+ const int16_t data_size ,
2524
+ const uint8_t * dst_packet_data_ptr )
2525
+ {
2526
+ if (coap_msg_ptr -> msg_type == COAP_MSG_TYPE_ACKNOWLEDGEMENT &&
2527
+ handle -> sn_coap_duplication_buffer_size != 0 ) {
2528
+ coap_duplication_info_s * info = sn_coap_protocol_linked_list_duplication_info_search (handle ,
2529
+ dst_addr_ptr ,
2530
+ coap_msg_ptr -> msg_id );
2531
+
2532
+ /* Update package data to duplication info struct if it's not there yet */
2533
+ if (info && info -> packet_ptr == NULL ) {
2534
+ info -> packet_ptr = handle -> sn_coap_protocol_malloc (data_size );
2535
+ if (info -> packet_ptr ) {
2536
+ memcpy (info -> packet_ptr , dst_packet_data_ptr , data_size );
2537
+ info -> packet_len = data_size ;
2538
+ } else {
2539
+ tr_error ("sn_coap_protocol_update_duplication_package_data - failed to allocate duplication info!" );
2540
+ return false;
2541
+ }
2542
+ }
2543
+ }
2544
+ return true;
2545
+ }
2546
+ #endif
0 commit comments