@@ -46,13 +46,16 @@ static void own_free(void *ptr)
46
46
47
47
static NS_LIST_DEFINE (request_list , coap_transaction_t , link ) ;
48
48
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 )
50
50
{
51
+ (void ) address ;
52
+ (void ) port ;
51
53
coap_transaction_t * this = NULL ;
54
+
52
55
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 ) {
54
57
this = cur_ptr ;
55
- break ;
58
+ break ;
56
59
}
57
60
}
58
61
return this ;
@@ -147,12 +150,13 @@ static int8_t coap_rx_function(sn_coap_hdr_s *resp_ptr, sn_nsdl_addr_s *address_
147
150
coap_transaction_t * this = NULL ;
148
151
(void )address_ptr ;
149
152
(void )param ;
153
+
150
154
tr_warn ("transaction was not handled %d" , resp_ptr -> msg_id );
151
155
if (!resp_ptr ) {
152
156
return -1 ;
153
157
}
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 );
156
160
}
157
161
if (!this ) {
158
162
return 0 ;
@@ -278,6 +282,7 @@ int16_t coap_message_handler_coap_msg_process(coap_msg_handler_t *handle, int8_t
278
282
memcpy (transaction_ptr -> remote_address , source_addr_ptr , 16 );
279
283
if (coap_message -> token_len ) {
280
284
memcpy (transaction_ptr -> token , coap_message -> token_ptr , coap_message -> token_len );
285
+ transaction_ptr -> token_len = coap_message -> token_len ;
281
286
}
282
287
transaction_ptr -> remote_port = port ;
283
288
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
292
297
} else {
293
298
coap_transaction_t * this = NULL ;
294
299
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 );
296
301
}
297
302
if (!this ) {
298
303
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
352
357
353
358
do {
354
359
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 ));
356
361
memcpy (transaction_ptr -> token ,token ,4 );
362
+ transaction_ptr -> token_len = 4 ;
357
363
request .token_ptr = transaction_ptr -> token ;
358
364
request .token_len = 4 ;
359
365
@@ -464,7 +470,7 @@ int8_t coap_message_handler_response_send_by_msg_id(coap_msg_handler_t *handle,
464
470
response .payload_len = payload_len ;
465
471
response .payload_ptr = (uint8_t * ) payload_ptr ; // Cast away const and trust that nsdl doesn't modify...
466
472
response .content_format = content_type ;
467
- response .token_len = 4 ;
473
+ response .token_len = transaction_ptr -> token_len ;
468
474
response .token_ptr = transaction_ptr -> token ;
469
475
response .msg_code = message_code ;
470
476
if (transaction_ptr -> req_msg_type == COAP_MSG_TYPE_CONFIRMABLE ) {
0 commit comments