Commit 6017ed5b authored by Kishen Maloor's avatar Kishen Maloor

oc_tls:add API to close all TLS sessions

Signed-off-by: Kishen Maloor's avatarKishen Maloor <kishen.maloor@intel.com>
parent ccbd2dc8
......@@ -144,11 +144,18 @@ oc_send_message(oc_message_t *message)
#ifdef OC_SECURITY
void
oc_close_all_tls_sessions(size_t device)
oc_close_all_tls_sessions_for_device(size_t device)
{
oc_process_post(&message_buffer_handler, oc_events[TLS_CLOSE_ALL_SESSIONS],
(oc_process_data_t)device);
}
void
oc_close_all_tls_sessions(void)
{
oc_process_poll(&(oc_tls_handler));
_oc_signal_event_loop();
}
#endif /* OC_SECURITY */
OC_PROCESS_THREAD(message_buffer_handler, ev, data)
......
......@@ -42,7 +42,8 @@ void oc_message_unref(oc_message_t *message);
void oc_recv_message(oc_message_t *message);
void oc_send_message(oc_message_t *message);
void oc_close_all_tls_sessions(size_t device);
void oc_close_all_tls_sessions_for_device(size_t device);
void oc_close_all_tls_sessions(void);
#ifdef __cplusplus
}
......
......@@ -780,7 +780,7 @@ send_message:
#ifdef OC_SECURITY
if (coap_status_code == CLOSE_ALL_TLS_SESSIONS) {
oc_close_all_tls_sessions(msg->endpoint.device);
oc_close_all_tls_sessions_for_device(msg->endpoint.device);
}
#endif /* OC_SECURITY */
......
......@@ -192,7 +192,7 @@ oc_pstat_handle_state(oc_sec_pstat_t *ps, size_t device, bool from_storage,
oc_factory_presets_t *fp = oc_get_factory_presets_cb();
if (fp->cb != NULL) {
if (self_reset) {
oc_tls_close_all_connections(device);
oc_close_all_tls_sessions_for_device(device);
}
memcpy(&pstat[device], ps, sizeof(oc_sec_pstat_t));
OC_DBG("oc_pstat: invoking the factory presets callback");
......
......@@ -1247,20 +1247,6 @@ oc_tls_add_peer(oc_endpoint_t *endpoint, int role)
return peer;
}
void
oc_tls_close_all_connections(size_t device)
{
OC_DBG("oc_tls: closing all open (D)TLS sessions on device %zd", device);
oc_tls_peer_t *p = oc_list_head(tls_peers), *next;
while (p != NULL) {
next = p->next;
if (p->endpoint.device == device) {
oc_tls_close_connection(&p->endpoint);
}
p = next;
}
}
void
oc_tls_shutdown(void)
{
......@@ -1778,15 +1764,35 @@ oc_tls_recv_message(oc_message_t *message)
}
static void
close_all_active_tls_sessions(size_t device)
close_all_tls_sessions_for_device(size_t device)
{
oc_tls_close_all_connections(device);
OC_DBG("oc_tls: closing all open (D)TLS sessions on device %zd", device);
oc_tls_peer_t *p = oc_list_head(tls_peers), *next;
while (p != NULL) {
next = p->next;
if (p->endpoint.device == device) {
oc_tls_close_connection(&p->endpoint);
}
p = next;
}
}
static void
close_all_tls_sessions(void)
{
OC_DBG("oc_tls: closing all open (D)TLS sessions on all devices");
oc_tls_peer_t *p = oc_list_head(tls_peers), *next;
while (p != NULL) {
next = p->next;
oc_tls_close_connection(&p->endpoint);
p = next;
}
}
OC_PROCESS_THREAD(oc_tls_handler, ev, data)
{
OC_PROCESS_POLLHANDLER(close_all_tls_sessions());
OC_PROCESS_BEGIN();
while (1) {
OC_PROCESS_YIELD();
......@@ -1812,7 +1818,7 @@ OC_PROCESS_THREAD(oc_tls_handler, ev, data)
#endif /* OC_CLIENT */
else if (ev == oc_events[TLS_CLOSE_ALL_SESSIONS]) {
size_t device = (size_t)data;
close_all_active_tls_sessions(device);
close_all_tls_sessions_for_device(device);
}
}
......
......@@ -63,7 +63,7 @@ int oc_tls_init_context(void);
void oc_tls_shutdown(void);
void oc_tls_close_connection(oc_endpoint_t *endpoint);
void oc_tls_close_all_connections(size_t device);
bool oc_sec_derive_owner_psk(oc_endpoint_t *endpoint, const uint8_t *oxm,
const size_t oxm_len, const uint8_t *server_uuid,
const size_t server_uuid_len,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment