15
15
#define TRACE_GROUP "ThCH"
16
16
17
17
typedef struct internal_socket_s {
18
- thread_conn_handler_t * parent ;
18
+ coap_conn_handler_t * parent ;
19
19
20
20
uint16_t listen_port ;
21
21
int8_t listen_socket ;
@@ -79,8 +79,8 @@ static secure_session_t *secure_session_create(internal_socket_t *parent, uint8_
79
79
return NULL ;
80
80
}
81
81
82
- this -> sec_handler = thread_security_create (parent -> listen_socket , this -> timer .id , address_ptr , port , & send_to_socket ,
83
- & receive_from_socket , & start_timer , & timer_status );
82
+ this -> sec_handler = coap_security_create (parent -> listen_socket , this -> timer .id , address_ptr , port , ECJPAKE ,
83
+ & send_to_socket , & receive_from_socket , & start_timer , & timer_status );
84
84
if ( !this -> sec_handler ){
85
85
ns_dyn_mem_free (this );
86
86
return NULL ;
@@ -98,7 +98,7 @@ static void secure_session_delete(secure_session_t *this)
98
98
if (this ) {
99
99
ns_list_remove (& secure_session_list , this );
100
100
if ( this -> sec_handler ){
101
- thread_security_destroy (this -> sec_handler );
101
+ coap_security_destroy (this -> sec_handler );
102
102
this -> sec_handler = NULL ;
103
103
}
104
104
ns_dyn_mem_free (this );
@@ -318,6 +318,9 @@ static void timer_cb(int8_t timer_id, uint16_t slots)
318
318
/* Intermediate expiry */
319
319
sec -> timer .state = TIMER_STATE_INT_EXPIRY ;
320
320
}
321
+ //TODO: In case of DTLS and count == 1 || 4 we must call continue connecting of security so
322
+ //that mbedtls can handle timeout logic: resending etc...
323
+ //Not done, because timer should be refactored to be platform specific!
321
324
}
322
325
}
323
326
@@ -395,7 +398,11 @@ static void secure_recv_sckt_msg(void *cb_res)
395
398
uint8_t * pw = (uint8_t * )ns_dyn_mem_alloc (64 );
396
399
uint8_t pw_len ;
397
400
if ( sock -> parent -> _get_password_cb && 0 == sock -> parent -> _get_password_cb (sock -> listen_socket , src_address .address , src_address .identifier , pw , & pw_len )){
398
- coap_security_handler_connect (session -> sec_handler , true, pw , pw_len );
401
+ //TODO: get_password_cb should support certs and PSK also
402
+ coap_security_keys_t keys ;
403
+ keys ._priv = pw ;
404
+ keys ._priv_len = pw_len ;
405
+ coap_security_handler_connect_non_blocking (session -> sec_handler , true, DTLS , keys );
399
406
//TODO: error handling
400
407
}
401
408
ns_dyn_mem_free (pw );
@@ -447,7 +454,7 @@ static void recv_sckt_msg(void *cb_res)
447
454
}
448
455
}
449
456
450
- int coap_connection_handler_virtual_recv (thread_conn_handler_t * handler , uint8_t address [static 16 ], uint16_t port , uint8_t * data_ptr , uint16_t data_len )
457
+ int coap_connection_handler_virtual_recv (coap_conn_handler_t * handler , uint8_t address [static 16 ], uint16_t port , uint8_t * data_ptr , uint16_t data_len )
451
458
{
452
459
if ( !handler || !handler -> socket ){
453
460
return -1 ;
@@ -484,7 +491,11 @@ int coap_connection_handler_virtual_recv(thread_conn_handler_t *handler, uint8_t
484
491
uint8_t * pw = (uint8_t * )ns_dyn_mem_alloc (64 );
485
492
uint8_t pw_len ;
486
493
if ( sock -> parent -> _get_password_cb && 0 == sock -> parent -> _get_password_cb (sock -> listen_socket , address , port , pw , & pw_len )){
487
- coap_security_handler_connect (session -> sec_handler , true, pw , pw_len );
494
+ //TODO: get_password_cb should support certs and PSK also
495
+ coap_security_keys_t keys ;
496
+ keys ._priv = pw ;
497
+ keys ._priv_len = pw_len ;
498
+ coap_security_handler_connect_non_blocking (session -> sec_handler , true, DTLS , keys );
488
499
//TODO: error handling
489
500
ns_dyn_mem_free (pw );
490
501
return 0 ;
@@ -540,7 +551,7 @@ int coap_connection_handler_virtual_recv(thread_conn_handler_t *handler, uint8_t
540
551
return -1 ;
541
552
}
542
553
543
- thread_conn_handler_t * connection_handler_create (receive_from_socket_cb * recv_from_cb ,
554
+ coap_conn_handler_t * connection_handler_create (receive_from_socket_cb * recv_from_cb ,
544
555
send_to_socket_cb * send_to_cb ,
545
556
get_pw_cb * pw_cb ,
546
557
security_done_cb * done_cb )
@@ -549,11 +560,11 @@ thread_conn_handler_t *connection_handler_create(receive_from_socket_cb *recv_fr
549
560
return NULL ;
550
561
}
551
562
552
- thread_conn_handler_t * handler = ns_dyn_mem_alloc (sizeof (thread_conn_handler_t ));
563
+ coap_conn_handler_t * handler = ns_dyn_mem_alloc (sizeof (coap_conn_handler_t ));
553
564
if (!handler ){
554
565
return NULL ;
555
566
}
556
- memset (handler , 0 , sizeof (thread_conn_handler_t ));
567
+ memset (handler , 0 , sizeof (coap_conn_handler_t ));
557
568
handler -> socket = NULL ;
558
569
handler -> _recv_cb = recv_from_cb ;
559
570
handler -> _send_cb = send_to_cb ;
@@ -565,7 +576,7 @@ thread_conn_handler_t *connection_handler_create(receive_from_socket_cb *recv_fr
565
576
return handler ;
566
577
}
567
578
568
- void connection_handler_destroy (thread_conn_handler_t * handler )
579
+ void connection_handler_destroy (coap_conn_handler_t * handler )
569
580
{
570
581
if (handler ){
571
582
if ( handler -> socket && handler -> socket -> is_secure ){
@@ -575,7 +586,7 @@ void connection_handler_destroy(thread_conn_handler_t *handler)
575
586
576
587
while (session != NULL ){
577
588
if ( session && handler -> socket -> usage_counter == 1 ){ //Last connection
578
- thread_security_send_close_alert ( session -> sec_handler );
589
+ coap_security_send_close_alert ( session -> sec_handler );
579
590
}
580
591
581
592
if ( session ){
@@ -590,20 +601,20 @@ void connection_handler_destroy(thread_conn_handler_t *handler)
590
601
}
591
602
}
592
603
593
- void connection_handler_close_secure_connection ( thread_conn_handler_t * handler , ns_address_t * dest_addr )
604
+ void connection_handler_close_secure_connection ( coap_conn_handler_t * handler , ns_address_t * dest_addr )
594
605
{
595
606
if (handler ){
596
607
if ( handler -> socket && handler -> socket -> is_secure ){
597
608
secure_session_t * session = secure_session_find ( handler -> socket , dest_addr -> address ,
598
609
dest_addr -> identifier );
599
610
if ( session ){
600
- thread_security_send_close_alert ( session -> sec_handler );
611
+ coap_security_send_close_alert ( session -> sec_handler );
601
612
}
602
613
}
603
614
}
604
615
}
605
616
606
- int coap_connection_handler_open_connection (thread_conn_handler_t * handler , uint16_t listen_port , bool use_ephemeral_port , bool is_secure , bool is_real_socket , bool bypassSec )
617
+ int coap_connection_handler_open_connection (coap_conn_handler_t * handler , uint16_t listen_port , bool use_ephemeral_port , bool is_secure , bool is_real_socket , bool bypassSec )
607
618
{
608
619
if ( !handler ){
609
620
return -1 ;
@@ -632,7 +643,7 @@ int coap_connection_handler_open_connection(thread_conn_handler_t *handler, uint
632
643
return 0 ;
633
644
}
634
645
635
- int coap_connection_handler_send_data (thread_conn_handler_t * handler , ns_address_t * dest_addr , uint8_t * data_ptr , uint16_t data_len , bool bypass_link_sec )
646
+ int coap_connection_handler_send_data (coap_conn_handler_t * handler , ns_address_t * dest_addr , uint8_t * data_ptr , uint16_t data_len , bool bypass_link_sec )
636
647
{
637
648
if ( !handler || !handler -> socket || !dest_addr ){
638
649
return -1 ;
@@ -658,7 +669,11 @@ int coap_connection_handler_send_data(thread_conn_handler_t *handler, ns_address
658
669
}
659
670
uint8_t pw_len ;
660
671
if ( handler -> _get_password_cb && 0 == handler -> _get_password_cb (handler -> socket -> listen_socket , dest_addr -> address , dest_addr -> identifier , pw , & pw_len )){
661
- coap_security_handler_connect (session -> sec_handler , false, pw , pw_len );
672
+ //TODO: get_password_cb should support certs and PSK also
673
+ coap_security_keys_t keys ;
674
+ keys ._priv = pw ;
675
+ keys ._priv_len = pw_len ;
676
+ coap_security_handler_connect_non_blocking (session -> sec_handler , false, DTLS , keys );
662
677
ns_dyn_mem_free (pw );
663
678
return -2 ;
664
679
}else {
@@ -687,7 +702,7 @@ int coap_connection_handler_send_data(thread_conn_handler_t *handler, ns_address
687
702
}
688
703
}
689
704
690
- bool coap_connection_handler_socket_belongs_to (thread_conn_handler_t * handler , int8_t socket_id )
705
+ bool coap_connection_handler_socket_belongs_to (coap_conn_handler_t * handler , int8_t socket_id )
691
706
{
692
707
if ( !handler || !handler -> socket ){
693
708
return false;
0 commit comments