@@ -33,7 +33,7 @@ int entropy_poll( void *data, unsigned char *output, size_t len, size_t *olen );
33
33
int f_send ( void * ctx , const unsigned char * buf , size_t len );
34
34
int f_recv (void * ctx , unsigned char * buf , size_t len );
35
35
36
- static int coap_security_handler_init (thread_security_t * sec ){
36
+ static int coap_security_handler_init (coap_security_t * sec ){
37
37
const char * pers = "dtls_client" ;
38
38
mbedtls_ssl_init ( & sec -> _ssl );
39
39
mbedtls_ssl_config_init ( & sec -> _conf );
@@ -61,15 +61,15 @@ static int coap_security_handler_init(thread_security_t *sec){
61
61
return 0 ;
62
62
}
63
63
64
- static void coap_security_handler_reset (thread_security_t * sec ){
64
+ static void coap_security_handler_reset (coap_security_t * sec ){
65
65
mbedtls_entropy_free ( & sec -> _entropy );
66
66
mbedtls_ctr_drbg_free ( & sec -> _ctr_drbg );
67
67
mbedtls_ssl_config_free (& sec -> _conf );
68
68
mbedtls_ssl_free (& sec -> _ssl );
69
69
}
70
70
71
71
72
- thread_security_t * thread_security_create (int8_t socket_id , int8_t timer_id , uint8_t * address_ptr , uint16_t port ,
72
+ coap_security_t * thread_security_create (int8_t socket_id , int8_t timer_id , uint8_t * address_ptr , uint16_t port ,
73
73
send_cb * send_cb ,
74
74
receive_cb * receive_cb ,
75
75
start_timer_cb * start_timer_cb ,
@@ -78,7 +78,7 @@ thread_security_t *thread_security_create(int8_t socket_id, int8_t timer_id, uin
78
78
if ( !address_ptr || send_cb == NULL || receive_cb == NULL || start_timer_cb == NULL || timer_status_cb == NULL ){
79
79
return NULL ;
80
80
}
81
- thread_security_t * this = ns_dyn_mem_alloc (sizeof (thread_security_t ));
81
+ coap_security_t * this = ns_dyn_mem_alloc (sizeof (coap_security_t ));
82
82
if ( !this ){
83
83
return NULL ;
84
84
}
@@ -88,6 +88,8 @@ thread_security_t *thread_security_create(int8_t socket_id, int8_t timer_id, uin
88
88
}
89
89
this -> _remote_port = port ;
90
90
memcpy (this -> _remote_address , address_ptr , 16 );
91
+ memset (this -> _pw , 0 , 64 );
92
+ this -> _pw_len = 0 ;
91
93
this -> _socket_id = socket_id ;
92
94
this -> _timer_id = timer_id ;
93
95
this -> _send_cb = send_cb ;
@@ -98,7 +100,7 @@ thread_security_t *thread_security_create(int8_t socket_id, int8_t timer_id, uin
98
100
return this ;
99
101
}
100
102
101
- void thread_security_destroy (thread_security_t * sec ){
103
+ void thread_security_destroy (coap_security_t * sec ){
102
104
if ( sec ){
103
105
coap_security_handler_reset (sec );
104
106
ns_dyn_mem_free (sec );
@@ -210,7 +212,7 @@ static int export_key_block(void *ctx,
210
212
*/
211
213
static void set_timer (void * sec_obj , uint32_t int_ms , uint32_t fin_ms )
212
214
{
213
- thread_security_t * sec = (thread_security_t * )sec_obj ;
215
+ coap_security_t * sec = (coap_security_t * )sec_obj ;
214
216
if ( sec -> _start_timer_cb ){
215
217
sec -> _start_timer_cb ( sec -> _timer_id , int_ms , fin_ms );
216
218
}
@@ -225,14 +227,14 @@ static void set_timer(void *sec_obj, uint32_t int_ms, uint32_t fin_ms)
225
227
*/
226
228
static int get_timer (void * sec_obj )
227
229
{
228
- thread_security_t * sec = (thread_security_t * )sec_obj ;
230
+ coap_security_t * sec = (coap_security_t * )sec_obj ;
229
231
if ( sec -> _timer_status_cb ){
230
232
return sec -> _timer_status_cb (sec -> _timer_id );
231
233
}
232
234
return -1 ;
233
235
}
234
236
235
- int coap_security_handler_connect (thread_security_t * sec , bool is_server , const unsigned char * pw , uint8_t len ){
237
+ int coap_security_handler_connect (coap_security_t * sec , bool is_server , const unsigned char * pw , uint8_t len ){
236
238
237
239
if ( !sec ){
238
240
return -1 ;
@@ -303,7 +305,7 @@ int coap_security_handler_connect(thread_security_t *sec, bool is_server, const
303
305
return ret ;
304
306
}
305
307
306
- int coap_security_handler_continue_connecting (thread_security_t * sec ){
308
+ int coap_security_handler_continue_connecting (coap_security_t * sec ){
307
309
int ret = -1 ;
308
310
while ( ret != MBEDTLS_ERR_SSL_WANT_READ ){
309
311
ret = mbedtls_ssl_handshake_step ( & sec -> _ssl );
@@ -333,7 +335,7 @@ int coap_security_handler_continue_connecting(thread_security_t *sec){
333
335
}
334
336
335
337
336
- int coap_security_handler_send_message (thread_security_t * sec , unsigned char * message , size_t len ){
338
+ int coap_security_handler_send_message (coap_security_t * sec , unsigned char * message , size_t len ){
337
339
int ret = -1 ;
338
340
339
341
if ( sec ){
@@ -345,7 +347,7 @@ int coap_security_handler_send_message(thread_security_t *sec, unsigned char *me
345
347
return ret ; //bytes written
346
348
}
347
349
348
- int thread_security_send_close_alert (thread_security_t * sec )
350
+ int thread_security_send_close_alert (coap_security_t * sec )
349
351
{
350
352
if ( !sec ){
351
353
return -1 ;
@@ -356,7 +358,7 @@ int thread_security_send_close_alert(thread_security_t *sec)
356
358
coap_security_handler_init (sec );
357
359
}
358
360
359
- int coap_security_handler_read (thread_security_t * sec , unsigned char * buffer , size_t len ){
361
+ int coap_security_handler_read (coap_security_t * sec , unsigned char * buffer , size_t len ){
360
362
int ret = -1 ;
361
363
362
364
if ( sec && buffer ){
@@ -370,12 +372,12 @@ int coap_security_handler_read(thread_security_t *sec, unsigned char* buffer, si
370
372
}
371
373
372
374
int f_send ( void * ctx , const unsigned char * buf , size_t len ){
373
- thread_security_t * sec = (thread_security_t * )ctx ;
375
+ coap_security_t * sec = (coap_security_t * )ctx ;
374
376
return sec -> _send_cb (sec -> _socket_id , sec -> _remote_address , sec -> _remote_port , buf , len );
375
377
}
376
378
377
379
int f_recv (void * ctx , unsigned char * buf , size_t len ){
378
- thread_security_t * sec = (thread_security_t * )ctx ;
380
+ coap_security_t * sec = (coap_security_t * )ctx ;
379
381
return sec -> _receive_cb (sec -> _socket_id , buf , len );
380
382
}
381
383
0 commit comments