libcoap 4.3.3
coap_dtls.c
Go to the documentation of this file.
1/*
2 * coap_dtls.c -- (D)TLS functions for libcoap
3 *
4 * Copyright (C) 2023 Olaf Bergmann <bergmann@tzi.org>
5 * Copyright (C) 2023 Jon Shallow <supjps-libcoap@jpshallow.com>
6 *
7 * SPDX-License-Identifier: BSD-2-Clause
8 *
9 * This file is part of the CoAP library libcoap. Please see README for terms
10 * of use.
11 */
12
18#include "coap3/coap_internal.h"
19
20void
23#if COAP_CLIENT_SUPPORT
24 if (session->type == COAP_SESSION_TYPE_CLIENT)
25 session->tls = coap_dtls_new_client_session(session);
26#endif /* COAP_CLIENT_SUPPORT */
27#if COAP_SERVER_SUPPORT
28 if (session->type != COAP_SESSION_TYPE_CLIENT)
29 session->tls = coap_dtls_new_server_session(session);
30#endif /* COAP_SERVER_SUPPORT */
31
32 if (!session->tls) {
34 return;
35 }
36 coap_ticks(&session->last_rx_tx);
37}
38
39void
41 if (session->tls) {
43 session->tls = NULL;
44 }
45 session->sock.lfunc[COAP_LAYER_TLS].l_close(session);
46}
47
48#if !COAP_DISABLE_TCP
49void
52#if COAP_CLIENT_SUPPORT
53 if (session->type == COAP_SESSION_TYPE_CLIENT)
54 session->tls = coap_tls_new_client_session(session);
55#endif /* COAP_CLIENT_SUPPORT */
56#if COAP_SERVER_SUPPORT
57 if (session->type != COAP_SESSION_TYPE_CLIENT)
58 session->tls = coap_tls_new_server_session(session);
59#endif /* COAP_SERVER_SUPPORT */
60
61 if (!session->tls) {
63 return;
64 }
65 coap_ticks(&session->last_rx_tx);
66}
67
68void
70 if (session->tls) {
71 coap_tls_free_session(session);
72 session->tls = NULL;
73 }
74 session->sock.lfunc[COAP_LAYER_TLS].l_close(session);
75}
76#endif /* !COAP_DISABLE_TCP */
Pulls together all the internal only header files.
@ COAP_NACK_TLS_LAYER_FAILED
Definition: coap_io.h:76
@ COAP_LAYER_TLS
void coap_dtls_free_session(coap_session_t *coap_session COAP_UNUSED)
Definition: coap_notls.c:167
void coap_tls_free_session(coap_session_t *coap_session COAP_UNUSED)
Definition: coap_notls.c:243
void coap_ticks(coap_tick_t *)
Returns the current value of an internal tick counter.
void * coap_tls_new_server_session(coap_session_t *coap_session)
Create a TLS new server-side session.
void * coap_dtls_new_client_session(coap_session_t *coap_session)
Create a new client-side session.
void coap_tls_establish(coap_session_t *session)
Layer function interface for layer below TLS accept/connect being established.
Definition: coap_dtls.c:50
void coap_dtls_establish(coap_session_t *session)
Layer function interface for layer below DTLS connect being established.
Definition: coap_dtls.c:21
void * coap_dtls_new_server_session(coap_session_t *coap_session)
Create a new DTLS server-side session.
void * coap_tls_new_client_session(coap_session_t *coap_session)
Create a new TLS client-side session.
void coap_tls_close(coap_session_t *session)
Layer function interface for TLS close for a session.
Definition: coap_dtls.c:69
void coap_dtls_close(coap_session_t *session)
Layer function interface for DTLS close for a session.
Definition: coap_dtls.c:40
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
client-side
Definition: coap_session.h:45
@ COAP_SESSION_STATE_HANDSHAKE
Definition: coap_session.h:57
coap_layer_close_t l_close
Abstraction of virtual session that can be attached to coap_context_t (client) or coap_endpoint_t (se...
coap_socket_t sock
socket object for the session, if any
coap_session_state_t state
current state of relationship with peer
void * tls
security parameters
coap_session_type_t type
client or server side socket
coap_layer_func_t lfunc[COAP_LAYER_LAST]
Layer functions to use.