libcoap 4.3.5-develop-ea01661
Loading...
Searching...
No Matches
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 * Copyright (C) 2023-2025 Jon Shallow <supjps-libcoap@jpshallow.com>
7 *
8 * SPDX-License-Identifier: BSD-2-Clause
9 *
10 * This file is part of the CoAP library libcoap. Please see README for terms
11 * of use.
12 */
13
19#ifndef COAP_DTLS_INTERNAL_H_
20#define COAP_DTLS_INTERNAL_H_
21
22#include "coap_internal.h"
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
35/* https://rfc-editor.org/rfc/rfc6347#section-4.2.4.1 */
36#ifndef COAP_DTLS_RETRANSMIT_MS
37#define COAP_DTLS_RETRANSMIT_MS 1000
38#endif
39#ifndef COAP_DTLS_RETRANSMIT_TOTAL_MS
40#define COAP_DTLS_RETRANSMIT_TOTAL_MS 60000
41#endif
42
43#define COAP_DTLS_RETRANSMIT_COAP_TICKS (COAP_DTLS_RETRANSMIT_MS * COAP_TICKS_PER_SECOND / 1000)
44
45/* For RFC9146 Connection ID support */
46#ifndef COAP_DTLS_CID_LENGTH
47#define COAP_DTLS_CID_LENGTH 8
48#endif
49
56
62
72
73#if COAP_SERVER_SUPPORT
86 coap_dtls_spsk_t *setup_data);
87#endif /* COAP_SERVER_SUPPORT */
88
89#if COAP_CLIENT_SUPPORT
102 coap_dtls_cpsk_t *setup_data);
103#endif /* COAP_CLIENT_SUPPORT */
104
123 const coap_dtls_pki_t *setup_data,
124 const coap_dtls_role_t role);
125
139 const char *ca_file,
140 const char *ca_dir);
141
151
162
168void coap_dtls_free_context(void *dtls_context);
169
170#if COAP_CLIENT_SUPPORT
180#endif /* COAP_CLIENT_SUPPORT */
181
182#if COAP_SERVER_SUPPORT
195#endif /* COAP_SERVER_SUPPORT */
196
204
212
223ssize_t coap_dtls_send(coap_session_t *coap_session,
224 const uint8_t *data,
225 size_t data_len);
226
234
243
253 coap_tick_t now);
254
263
275 const uint8_t *data,
276 size_t data_len);
277
278#if COAP_SERVER_SUPPORT
292 const uint8_t *data,
293 size_t data_len);
294#endif /* COAP_SERVER_SUPPORT */
295
309
315void coap_dtls_close(coap_session_t *session);
316
324unsigned int coap_dtls_get_overhead(coap_session_t *coap_session);
325
326#if COAP_CLIENT_SUPPORT
336#endif /* COAP_CLIENT_SUPPORT */
337
338#if COAP_SERVER_SUPPORT
348#endif /* COAP_SERVER_SUPPORT */
349
357
368ssize_t coap_tls_write(coap_session_t *coap_session,
369 const uint8_t *data,
370 size_t data_len
371 );
372
383ssize_t coap_tls_read(coap_session_t *coap_session,
384 uint8_t *data,
385 size_t data_len
386 );
387
401
407void coap_tls_close(coap_session_t *session);
408
417 const coap_session_t *coap_session);
418
427 const coap_session_t *coap_session);
428
437 const coap_session_t *coap_session);
438
447 const coap_session_t *coap_session);
448
453void coap_dtls_startup(void);
454
459void coap_dtls_shutdown(void);
460
470 coap_tls_library_t *tls_lib);
471
480 coap_dtls_key_t *key);
481
495 coap_dtls_key_t *key,
496 const coap_dtls_role_t role,
497 int ret);
498
508
511#ifdef __cplusplus
512}
513#endif
514
515#endif /* COAP_DTLS_INTERNAL_H */
Pulls together all the internal only header files.
uint64_t coap_tick_t
This data type represents internal timer ticks with COAP_TICKS_PER_SECOND resolution.
Definition coap_time.h:152
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...
void * coap_tls_new_server_session(coap_session_t *coap_session)
Create a TLS new server-side session.
coap_tick_t coap_dtls_get_context_timeout(void *dtls_context)
Do all pending retransmits and get next timeout.
const coap_bin_const_t * coap_get_session_client_psk_identity(const coap_session_t *coap_session)
Get the current client's PSK identity.
void coap_dtls_startup(void)
Initialize the underlying (D)TLS Library layer.
Definition coap_notls.c:154
coap_tick_t coap_dtls_get_timeout(coap_session_t *coap_session, coap_tick_t now)
Get next timeout for this session.
int coap_dtls_define_issue(coap_define_issue_key_t type, coap_define_issue_fail_t fail, coap_dtls_key_t *key, const coap_dtls_role_t role, int ret)
Report PKI DEFINE type issue.
Definition coap_dtls.c:165
coap_define_issue_key_t
void * coap_dtls_new_client_session(coap_session_t *coap_session)
Create a new client-side session.
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.
void coap_tls_establish(coap_session_t *session)
Layer function interface for layer below TLS accept/connect being established.
Definition coap_dtls.c:295
unsigned int coap_dtls_get_overhead(coap_session_t *coap_session)
Get DTLS overhead over cleartext PDUs.
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.
void coap_dtls_establish(coap_session_t *session)
Layer function interface for layer below DTLS connect being established.
Definition coap_dtls.c:266
void * coap_dtls_new_server_session(coap_session_t *coap_session)
Create a new DTLS server-side session.
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.
int coap_dtls_set_cid_tuple_change(coap_context_t *context, uint8_t every)
Set the Connection ID client tuple frequency change for testing CIDs.
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...
int coap_dtls_is_context_timeout(void)
Check if timeout is handled per CoAP session or per CoAP context.
Definition coap_notls.c:219
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.
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.
int coap_dtls_handle_timeout(coap_session_t *coap_session)
Handle a DTLS timeout expiration.
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.
void * coap_dtls_new_context(coap_context_t *coap_context)
Creates a new DTLS context for the given coap_context.
void coap_dtls_shutdown(void)
Close down the underlying (D)TLS Library layer.
Definition coap_notls.c:166
const coap_bin_const_t * coap_get_session_client_psk_key(const coap_session_t *coap_session)
Get the current client's PSK key.
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_define_issue_fail_t
void * coap_tls_new_client_session(coap_session_t *coap_session)
Create a new TLS client-side session.
void coap_dtls_map_key_type_to_define(const coap_dtls_pki_t *setup_data, coap_dtls_key_t *key)
Map the PKI key definitions to the new DEFINE format.
Definition coap_dtls.c:26
const coap_bin_const_t * coap_get_session_server_psk_key(const coap_session_t *coap_session)
Get the current server's PSK key.
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.
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.
void coap_dtls_free_context(void *dtls_context)
Releases the storage allocated for dtls_context.
void coap_tls_close(coap_session_t *session)
Layer function interface for TLS close for a session.
Definition coap_dtls.c:314
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.
int coap_dtls_receive(coap_session_t *coap_session, const uint8_t *data, size_t data_len)
Handling incoming data from a DTLS peer.
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.
void coap_dtls_close(coap_session_t *session)
Layer function interface for DTLS close for a session.
Definition coap_dtls.c:285
int coap_dtls_context_load_pki_trust_store(coap_context_t *coap_context)
Load dtls context's default trusted CAs for a client or server.
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_DEFINE_KEY_PRIVATE
@ COAP_DEFINE_KEY_ROOT_CA
@ COAP_DEFINE_KEY_CA
@ COAP_DEFINE_KEY_PUBLIC
@ COAP_DEFINE_FAIL_NONE
@ COAP_DEFINE_FAIL_NOT_SUPPORTED
@ COAP_DEFINE_FAIL_BAD
coap_dtls_role_t
Definition coap_dtls.h:48
coap_tls_library_t
Definition coap_dtls.h:74
CoAP binary data definition with const data.
Definition coap_str.h:67
The CoAP stack's global state is stored in a coap_context_t object.
The structure used for defining the Client PSK setup data to be used.
Definition coap_dtls.h:414
The structure that holds the PKI key information.
Definition coap_dtls.h:283
The structure used for defining the PKI setup data to be used.
Definition coap_dtls.h:316
The structure used for defining the Server PSK setup data to be used.
Definition coap_dtls.h:505
Abstraction of virtual session that can be attached to coap_context_t (client) or coap_endpoint_t (se...