Skip to content

Commit ab2d132

Browse files
author
Mika Tervonen
committed
Merge pull request #9 from ARMmbed/secure-close
Remove Nanostack dependency from service api
2 parents 71640e5 + 120293c commit ab2d132

File tree

6 files changed

+12
-26
lines changed

6 files changed

+12
-26
lines changed

coap-service/coap_service_api.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ extern void coap_service_delete( int8_t service_id );
139139
*
140140
* \param service_id Id number of the current service.
141141
*/
142-
extern void coap_service_close_secure_connection(int8_t service_id, ns_address_t *dest_addr);
142+
extern void coap_service_close_secure_connection(int8_t service_id, uint8_t destination_addr_ptr[static 16], uint16_t port);
143143

144144
/**
145145
* \brief Sets password for device

source/coap_connection_handler.c

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ static void clear_secure_sessions(internal_socket_t *this){
112112
if( this ){
113113
ns_list_foreach_safe(secure_session_t, cur_ptr, &secure_session_list) {
114114
if( cur_ptr->parent == this ){
115+
coap_security_send_close_alert( cur_ptr->sec_handler );
115116
secure_session_delete(cur_ptr);
116117
}
117118
}
@@ -579,34 +580,17 @@ coap_conn_handler_t *connection_handler_create(receive_from_socket_cb *recv_from
579580
void connection_handler_destroy(coap_conn_handler_t *handler)
580581
{
581582
if(handler){
582-
if( handler->socket && handler->socket->is_secure){
583-
//If nothing is sent, there is no address to find.
584-
//This case is handled in int_socket_delete.
585-
secure_session_t *session = secure_session_find_by_parent( handler->socket);
586-
587-
while(session != NULL ){
588-
if( session && handler->socket->usage_counter == 1){ //Last connection
589-
coap_security_send_close_alert( session->sec_handler );
590-
}
591-
592-
if( session){
593-
secure_session_delete(session);
594-
}
595-
session = secure_session_find_by_parent( handler->socket);
596-
}
597-
}
598583
int_socket_delete(handler->socket);
599584
handler->socket = NULL;
600585
ns_dyn_mem_free(handler);
601586
}
602587
}
603588

604-
void connection_handler_close_secure_connection( coap_conn_handler_t *handler, ns_address_t *dest_addr )
589+
void connection_handler_close_secure_connection( coap_conn_handler_t *handler, uint8_t destination_addr_ptr[static 16], uint16_t port )
605590
{
606591
if(handler){
607592
if( handler->socket && handler->socket->is_secure){
608-
secure_session_t *session = secure_session_find( handler->socket, dest_addr->address,
609-
dest_addr->identifier);
593+
secure_session_t *session = secure_session_find( handler->socket, destination_addr_ptr, port);
610594
if( session ){
611595
coap_security_send_close_alert( session->sec_handler );
612596
}

source/coap_message_handler.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ static void transaction_delete(coap_transaction_t *this)
8282
{
8383
if (this) {
8484
ns_list_remove(&request_list, this);
85+
if(this->data_ptr){
86+
ns_dyn_mem_free(this->data_ptr);
87+
}
8588
ns_dyn_mem_free(this);
8689
}
8790

source/coap_service_api.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,14 +344,14 @@ void coap_service_delete(int8_t service_id)
344344
return;
345345
}
346346

347-
void coap_service_close_secure_connection(int8_t service_id, ns_address_t *dest_addr)
347+
extern void coap_service_close_secure_connection(int8_t service_id, uint8_t destination_addr_ptr[static 16], uint16_t port)
348348
{
349349
coap_service_t *this = service_find(service_id);
350-
if (!this || !dest_addr) {
350+
if (!this || !destination_addr_ptr) {
351351
return;
352352
}
353353
if (this->conn_handler){
354-
connection_handler_close_secure_connection(this->conn_handler, dest_addr);
354+
connection_handler_close_secure_connection(this->conn_handler, destination_addr_ptr, port);
355355
}
356356
}
357357

source/include/coap_connection_handler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ coap_conn_handler_t *connection_handler_create(receive_from_socket_cb *recv_from
4747

4848
void connection_handler_destroy( coap_conn_handler_t *handler );
4949

50-
void connection_handler_close_secure_connection(coap_conn_handler_t *handler, ns_address_t *dest_addr);
50+
void connection_handler_close_secure_connection( coap_conn_handler_t *handler, uint8_t destination_addr_ptr[static 16], uint16_t port );
5151

5252
int coap_connection_handler_open_connection(coap_conn_handler_t *handler, uint16_t listen_port, bool use_ephemeral_port, bool is_secure, bool real_socket, bool bypassSec);
5353

test/coap-service/unittest/stub/coap_connection_handler_stub.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ void connection_handler_destroy(coap_conn_handler_t *handler)
3636
{
3737

3838
}
39-
40-
void connection_handler_close_secure_connection( coap_conn_handler_t *handler, ns_address_t *dest_addr )
39+
void connection_handler_close_secure_connection( coap_conn_handler_t *handler, uint8_t destination_addr_ptr[static 16], uint16_t port )
4140
{
4241

4342
}

0 commit comments

Comments
 (0)