Loading...
Searching...
No Matches
coap_dtls.c
Go to the documentation of this file.
/*
* coap_dtls.c -- (D)TLS functions for libcoap
*
* Copyright (C) 2023 Olaf Bergmann <bergmann@tzi.org>
* Copyright (C) 2023 Jon Shallow <supjps-libcoap@jpshallow.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*
* This file is part of the CoAP library libcoap. Please see README for terms
* of use.
*/
#include "coap3/coap_internal.h"
void
coap_dtls_establish(coap_session_t *session) {
session->state = COAP_SESSION_STATE_HANDSHAKE;
#if COAP_CLIENT_SUPPORT
if (session->type == COAP_SESSION_TYPE_CLIENT)
session->tls = coap_dtls_new_client_session(session);
#endif /* COAP_CLIENT_SUPPORT */
#if COAP_SERVER_SUPPORT
if (session->type != COAP_SESSION_TYPE_CLIENT)
session->tls = coap_dtls_new_server_session(session);
#endif /* COAP_SERVER_SUPPORT */
if (!session->tls) {
coap_session_disconnected(session, COAP_NACK_TLS_LAYER_FAILED);
return;
}
coap_ticks(&session->last_rx_tx);
}
void
coap_dtls_close(coap_session_t *session) {
if (session->tls) {
coap_dtls_free_session(session);
session->tls = NULL;
}
session->sock.lfunc[COAP_LAYER_TLS].l_close(session);
}
#if !COAP_DISABLE_TCP
void
coap_tls_establish(coap_session_t *session) {
session->state = COAP_SESSION_STATE_HANDSHAKE;
#if COAP_CLIENT_SUPPORT
if (session->type == COAP_SESSION_TYPE_CLIENT)
session->tls = coap_tls_new_client_session(session);
#endif /* COAP_CLIENT_SUPPORT */
#if COAP_SERVER_SUPPORT
if (session->type != COAP_SESSION_TYPE_CLIENT)
session->tls = coap_tls_new_server_session(session);
#endif /* COAP_SERVER_SUPPORT */
if (!session->tls) {
coap_session_disconnected(session, COAP_NACK_TLS_LAYER_FAILED);
return;
}
coap_ticks(&session->last_rx_tx);
}
void
coap_tls_close(coap_session_t *session) {
if (session->tls) {
coap_tls_free_session(session);
session->tls = NULL;
}
session->sock.lfunc[COAP_LAYER_TLS].l_close(session);
}
#endif /* !COAP_DISABLE_TCP */
coap_internal.h
Pulls together all the internal only header files.
COAP_NACK_TLS_LAYER_FAILED
@ COAP_NACK_TLS_LAYER_FAILED
Definition coap_io.h:76
COAP_LAYER_TLS
@ COAP_LAYER_TLS
Definition coap_layers_internal.h:25
coap_dtls_free_session
void coap_dtls_free_session(coap_session_t *coap_session COAP_UNUSED)
Definition coap_notls.c:168
coap_tls_free_session
void coap_tls_free_session(coap_session_t *coap_session COAP_UNUSED)
Definition coap_notls.c:244
coap_ticks
void coap_ticks(coap_tick_t *)
Returns the current value of an internal tick counter.
coap_tls_new_server_session
void * coap_tls_new_server_session(coap_session_t *coap_session)
Create a TLS new server-side session.
coap_dtls_new_client_session
void * coap_dtls_new_client_session(coap_session_t *coap_session)
Create a new client-side session.
coap_tls_establish
void coap_tls_establish(coap_session_t *session)
Layer function interface for layer below TLS accept/connect being established.
Definition coap_dtls.c:50
coap_dtls_establish
void coap_dtls_establish(coap_session_t *session)
Layer function interface for layer below DTLS connect being established.
Definition coap_dtls.c:21
coap_dtls_new_server_session
void * coap_dtls_new_server_session(coap_session_t *coap_session)
Create a new DTLS server-side session.
coap_tls_new_client_session
void * coap_tls_new_client_session(coap_session_t *coap_session)
Create a new TLS client-side session.
coap_tls_close
void coap_tls_close(coap_session_t *session)
Layer function interface for TLS close for a session.
Definition coap_dtls.c:69
coap_dtls_close
void coap_dtls_close(coap_session_t *session)
Layer function interface for DTLS close for a session.
Definition coap_dtls.c:40
coap_session_disconnected
void coap_session_disconnected(coap_session_t *session, coap_nack_reason_t reason)
Notify session that it has failed.
Definition coap_session.c:848
COAP_SESSION_TYPE_CLIENT
@ COAP_SESSION_TYPE_CLIENT
client-side
Definition coap_session.h:45
COAP_SESSION_STATE_HANDSHAKE
@ COAP_SESSION_STATE_HANDSHAKE
Definition coap_session.h:57
coap_layer_func_t::l_close
coap_layer_close_t l_close
Definition coap_layers_internal.h:110
coap_session_t
Abstraction of virtual session that can be attached to coap_context_t (client) or coap_endpoint_t (se...
Definition coap_session_internal.h:68
coap_session_t::last_rx_tx
coap_tick_t last_rx_tx
Definition coap_session_internal.h:111
coap_session_t::sock
coap_socket_t sock
socket object for the session, if any
Definition coap_session_internal.h:81
coap_session_t::state
coap_session_state_t state
current state of relationship with peer
Definition coap_session_internal.h:71
coap_session_t::tls
void * tls
security parameters
Definition coap_session_internal.h:87
coap_session_t::type
coap_session_type_t type
client or server side socket
Definition coap_session_internal.h:70
coap_socket_t::lfunc
coap_layer_func_t lfunc[COAP_LAYER_LAST]
Layer functions to use.
Definition coap_io_internal.h:55