@@ -46,13 +46,16 @@ static void own_free(void *ptr)
4646
4747static NS_LIST_DEFINE (request_list , coap_transaction_t , link ) ;
4848
49- static coap_transaction_t * transaction_find_client_by_token (uint8_t token [ 4 ] )
49+ static coap_transaction_t * transaction_find_client_by_token (uint8_t * token , uint8_t token_len , const uint8_t address [ static 16 ], uint16_t port )
5050{
51+ (void ) address ;
52+ (void ) port ;
5153 coap_transaction_t * this = NULL ;
54+
5255 ns_list_foreach (coap_transaction_t , cur_ptr , & request_list ) {
53- if (memcmp (cur_ptr -> token ,token ,4 ) == 0 && cur_ptr -> client_request ) {
56+ if (( cur_ptr -> token_len == token_len ) && ( memcmp (cur_ptr -> token , token , token_len ) == 0 ) && cur_ptr -> client_request ) {
5457 this = cur_ptr ;
55- break ;
58+ break ;
5659 }
5760 }
5861 return this ;
@@ -147,12 +150,13 @@ static int8_t coap_rx_function(sn_coap_hdr_s *resp_ptr, sn_nsdl_addr_s *address_
147150 coap_transaction_t * this = NULL ;
148151 (void )address_ptr ;
149152 (void )param ;
153+
150154 tr_warn ("transaction was not handled %d" , resp_ptr -> msg_id );
151155 if (!resp_ptr ) {
152156 return -1 ;
153157 }
154- if ( resp_ptr -> token_ptr ){
155- this = transaction_find_client_by_token (resp_ptr -> token_ptr );
158+ if (resp_ptr -> token_ptr ){
159+ this = transaction_find_client_by_token (resp_ptr -> token_ptr , resp_ptr -> token_len , address_ptr -> addr_ptr , address_ptr -> port );
156160 }
157161 if (!this ) {
158162 return 0 ;
@@ -278,6 +282,7 @@ int16_t coap_message_handler_coap_msg_process(coap_msg_handler_t *handle, int8_t
278282 memcpy (transaction_ptr -> remote_address , source_addr_ptr , 16 );
279283 if (coap_message -> token_len ) {
280284 memcpy (transaction_ptr -> token , coap_message -> token_ptr , coap_message -> token_len );
285+ transaction_ptr -> token_len = coap_message -> token_len ;
281286 }
282287 transaction_ptr -> remote_port = port ;
283288 if (cb (socket_id , coap_message , transaction_ptr ) < 0 ) {
@@ -292,7 +297,7 @@ int16_t coap_message_handler_coap_msg_process(coap_msg_handler_t *handle, int8_t
292297 } else {
293298 coap_transaction_t * this = NULL ;
294299 if (coap_message -> token_ptr ) {
295- this = transaction_find_client_by_token (coap_message -> token_ptr );
300+ this = transaction_find_client_by_token (coap_message -> token_ptr , coap_message -> token_len , source_addr_ptr , port );
296301 }
297302 if (!this ) {
298303 tr_error ("client transaction not found" );
@@ -352,8 +357,9 @@ uint16_t coap_message_handler_request_send(coap_msg_handler_t *handle, int8_t se
352357
353358 do {
354359 randLIB_get_n_bytes_random (token ,4 );
355- }while (transaction_find_client_by_token (token ));
360+ }while (transaction_find_client_by_token (token , 4 , destination_addr , destination_port ));
356361 memcpy (transaction_ptr -> token ,token ,4 );
362+ transaction_ptr -> token_len = 4 ;
357363 request .token_ptr = transaction_ptr -> token ;
358364 request .token_len = 4 ;
359365
@@ -464,7 +470,7 @@ int8_t coap_message_handler_response_send_by_msg_id(coap_msg_handler_t *handle,
464470 response .payload_len = payload_len ;
465471 response .payload_ptr = (uint8_t * ) payload_ptr ; // Cast away const and trust that nsdl doesn't modify...
466472 response .content_format = content_type ;
467- response .token_len = 4 ;
473+ response .token_len = transaction_ptr -> token_len ;
468474 response .token_ptr = transaction_ptr -> token ;
469475 response .msg_code = message_code ;
470476 if (transaction_ptr -> req_msg_type == COAP_MSG_TYPE_CONFIRMABLE ) {
0 commit comments