libcoap 4.3.2rc2

coap_dtls_internal.h
Go to the documentation of this file.
1/*
2 * coap_dtls_internal.h -- (Datagram) Transport Layer Support for libcoap
3 *
4 * Copyright (C) 2016 Olaf Bergmann <bergmann@tzi.org>
5 * Copyright (C) 2017 Jean-Claude Michelou <jcm@spinetix.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#ifndef COAP_DTLS_INTERNAL_H_
19#define COAP_DTLS_INTERNAL_H_
20
21#include "coap_internal.h"
22
30/* https://rfc-editor.org/rfc/rfc6347#section-4.2.4.1 */
31#ifndef COAP_DTLS_RETRANSMIT_MS
32#define COAP_DTLS_RETRANSMIT_MS 1000
33#endif
34#ifndef COAP_DTLS_RETRANSMIT_TOTAL_MS
35#define COAP_DTLS_RETRANSMIT_TOTAL_MS 60000
36#endif
37
38#define COAP_DTLS_RETRANSMIT_COAP_TICKS (COAP_DTLS_RETRANSMIT_MS * COAP_TICKS_PER_SECOND / 1000)
39
40/* For RFC9146 Connection ID support */
41#ifndef COAP_DTLS_CID_LENGTH
42#define COAP_DTLS_CID_LENGTH 6
43#endif
44
53 void *coap_dtls_new_context(coap_context_t *coap_context);
54
55#if COAP_SERVER_SUPPORT
67 int coap_dtls_context_set_spsk(coap_context_t *coap_context,
68 coap_dtls_spsk_t *setup_data);
69#endif /* COAP_SERVER_SUPPORT */
70
71#if COAP_CLIENT_SUPPORT
83 int coap_dtls_context_set_cpsk(coap_context_t *coap_context,
84 coap_dtls_cpsk_t *setup_data);
85#endif /* COAP_CLIENT_SUPPORT */
86
104 int coap_dtls_context_set_pki(coap_context_t *coap_context,
105 const coap_dtls_pki_t *setup_data,
106 const coap_dtls_role_t role);
107
120 int coap_dtls_context_set_pki_root_cas(coap_context_t *coap_context,
121 const char *ca_file,
122 const char *ca_dir);
123
133 int coap_dtls_context_check_keys_enabled(coap_context_t *coap_context);
134
140 void coap_dtls_free_context(void *dtls_context);
141
142#if COAP_CLIENT_SUPPORT
151 void *coap_dtls_new_client_session(coap_session_t *coap_session);
152#endif /* COAP_CLIENT_SUPPORT */
153
154#if COAP_SERVER_SUPPORT
166 void *coap_dtls_new_server_session(coap_session_t *coap_session);
167#endif /* COAP_SERVER_SUPPORT */
168
175 void coap_dtls_free_session(coap_session_t *coap_session);
176
183 void coap_dtls_session_update_mtu(coap_session_t *coap_session);
184
195ssize_t coap_dtls_send(coap_session_t *coap_session,
196 const uint8_t *data,
197 size_t data_len);
198
205 int coap_dtls_is_context_timeout(void);
206
214 coap_tick_t coap_dtls_get_context_timeout(void *dtls_context);
215
224 coap_tick_t coap_dtls_get_timeout(coap_session_t *coap_session,
225 coap_tick_t now);
226
234 int coap_dtls_handle_timeout(coap_session_t *coap_session);
235
246 int coap_dtls_receive(coap_session_t *coap_session,
247 const uint8_t *data,
248 size_t data_len);
249
250#if COAP_SERVER_SUPPORT
263 int coap_dtls_hello(coap_session_t *coap_session,
264 const uint8_t *data,
265 size_t data_len);
266#endif /* COAP_SERVER_SUPPORT */
267
280 void coap_dtls_establish(coap_session_t *session);
281
287 void coap_dtls_close(coap_session_t *session);
288
296 unsigned int coap_dtls_get_overhead(coap_session_t *coap_session);
297
298#if COAP_CLIENT_SUPPORT
307 void *coap_tls_new_client_session(coap_session_t *coap_session);
308#endif /* COAP_CLIENT_SUPPORT */
309
310#if COAP_SERVER_SUPPORT
319 void *coap_tls_new_server_session(coap_session_t *coap_session);
320#endif /* COAP_SERVER_SUPPORT */
321
328 void coap_tls_free_session(coap_session_t *coap_session);
329
340ssize_t coap_tls_write(coap_session_t *coap_session,
341 const uint8_t *data,
342 size_t data_len
343 );
344
355ssize_t coap_tls_read(coap_session_t *coap_session,
356 uint8_t *data,
357 size_t data_len
358 );
359
372 void coap_tls_establish(coap_session_t *session);
373
379 void coap_tls_close(coap_session_t *session);
380
388 const coap_bin_const_t *coap_get_session_client_psk_key(
389 const coap_session_t *coap_session);
390
398 const coap_bin_const_t *coap_get_session_client_psk_identity(
399 const coap_session_t *coap_session);
400
408 const coap_bin_const_t *coap_get_session_server_psk_key(
409 const coap_session_t *coap_session);
410
418 const coap_bin_const_t *coap_get_session_server_psk_hint(
419 const coap_session_t *coap_session);
420
425 void coap_dtls_startup(void);
426
431 void coap_dtls_shutdown(void);
432
441 void *coap_dtls_get_tls(const coap_session_t *session,
442 coap_tls_library_t *tls_lib);
443
446#endif /* COAP_DTLS_INTERNAL_H */
coap_internal.h
Pulls together all the internal only header files.
coap_tick_t
uint64_t coap_tick_t
This data type represents internal timer ticks with COAP_TICKS_PER_SECOND resolution.
Definition: coap_time.h:144
coap_tls_free_session
void coap_tls_free_session(coap_session_t *coap_session)
Terminates the TLS session (may send an ALERT if necessary) then frees the underlying TLS library obj...
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_get_context_timeout
coap_tick_t coap_dtls_get_context_timeout(void *dtls_context)
Do all pending retransmits and get next timeout.
coap_get_session_client_psk_identity
const coap_bin_const_t * coap_get_session_client_psk_identity(const coap_session_t *coap_session)
Get the current client's PSK identity.
Definition: coap_net.c:285
coap_dtls_startup
void coap_dtls_startup(void)
Initialize the underlying (D)TLS Library layer.
Definition: coap_notls.c:118
coap_dtls_get_timeout
coap_tick_t coap_dtls_get_timeout(coap_session_t *coap_session, coap_tick_t now)
Get next timeout for this session.
coap_dtls_new_client_session
void * coap_dtls_new_client_session(coap_session_t *coap_session)
Create a new client-side session.
coap_dtls_session_update_mtu
void coap_dtls_session_update_mtu(coap_session_t *coap_session)
Notify of a change in the CoAP session's MTU, for example after a PMTU update.
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_get_overhead
unsigned int coap_dtls_get_overhead(coap_session_t *coap_session)
Get DTLS overhead over cleartext PDUs.
coap_tls_write
ssize_t coap_tls_write(coap_session_t *coap_session, const uint8_t *data, size_t data_len)
Send data to a TLS peer, with implicit flush.
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_dtls_hello
int coap_dtls_hello(coap_session_t *coap_session, const uint8_t *data, size_t data_len)
Handling client HELLO messages from a new candiate peer.
coap_dtls_free_session
void coap_dtls_free_session(coap_session_t *coap_session)
Terminates the DTLS session (may send an ALERT if necessary) then frees the underlying TLS library ob...
coap_dtls_is_context_timeout
int coap_dtls_is_context_timeout(void)
Check if timeout is handled per CoAP session or per CoAP context.
Definition: coap_notls.c:182
coap_dtls_context_set_cpsk
int coap_dtls_context_set_cpsk(coap_context_t *coap_context, coap_dtls_cpsk_t *setup_data)
Set the DTLS context's default client PSK information.
coap_dtls_context_set_spsk
int coap_dtls_context_set_spsk(coap_context_t *coap_context, coap_dtls_spsk_t *setup_data)
Set the DTLS context's default server PSK information.
coap_dtls_handle_timeout
int coap_dtls_handle_timeout(coap_session_t *coap_session)
Handle a DTLS timeout expiration.
coap_dtls_context_set_pki_root_cas
int coap_dtls_context_set_pki_root_cas(coap_context_t *coap_context, const char *ca_file, const char *ca_dir)
Set the dtls context's default Root CA information for a client or server.
coap_dtls_new_context
void * coap_dtls_new_context(coap_context_t *coap_context)
Creates a new DTLS context for the given coap_context.
coap_dtls_shutdown
void coap_dtls_shutdown(void)
Close down the underlying (D)TLS Library layer.
Definition: coap_notls.c:130
coap_get_session_client_psk_key
const coap_bin_const_t * coap_get_session_client_psk_key(const coap_session_t *coap_session)
Get the current client's PSK key.
coap_tls_read
ssize_t coap_tls_read(coap_session_t *coap_session, uint8_t *data, size_t data_len)
Read some data from a TLS peer.
coap_tls_new_client_session
void * coap_tls_new_client_session(coap_session_t *coap_session)
Create a new TLS client-side session.
coap_get_session_server_psk_key
const coap_bin_const_t * coap_get_session_server_psk_key(const coap_session_t *coap_session)
Get the current server's PSK key.
coap_dtls_context_set_pki
int coap_dtls_context_set_pki(coap_context_t *coap_context, const coap_dtls_pki_t *setup_data, const coap_dtls_role_t role)
Set the DTLS context's default server PKI information.
coap_get_session_server_psk_hint
const coap_bin_const_t * coap_get_session_server_psk_hint(const coap_session_t *coap_session)
Get the current server's PSK identity hint.
coap_dtls_free_context
void coap_dtls_free_context(void *dtls_context)
Releases the storage allocated for dtls_context.
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_get_tls
void * coap_dtls_get_tls(const coap_session_t *session, coap_tls_library_t *tls_lib)
Get the actual (D)TLS object for the session.
coap_dtls_receive
int coap_dtls_receive(coap_session_t *coap_session, const uint8_t *data, size_t data_len)
Handling incoming data from a DTLS peer.
coap_dtls_context_check_keys_enabled
int coap_dtls_context_check_keys_enabled(coap_context_t *coap_context)
Check whether one of the coap_dtls_context_set_{psk|pki}() functions have been called.
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_dtls_send
ssize_t coap_dtls_send(coap_session_t *coap_session, const uint8_t *data, size_t data_len)
Send data to a DTLS peer.
coap_dtls_role_t
coap_dtls_role_t
Definition: coap_dtls.h:43
coap_tls_library_t
coap_tls_library_t
Definition: coap_dtls.h:92
coap_bin_const_t
CoAP binary data definition with const data.
Definition: coap_str.h:64
coap_context_t
The CoAP stack's global state is stored in a coap_context_t object.
Definition: coap_net_internal.h:49
coap_dtls_cpsk_t
The structure used for defining the Client PSK setup data to be used.
Definition: coap_dtls.h:378
coap_dtls_pki_t
The structure used for defining the PKI setup data to be used.
Definition: coap_dtls.h:284
coap_dtls_spsk_t
The structure used for defining the Server PSK setup data to be used.
Definition: coap_dtls.h:465
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