libcoap  4.3.0rc3
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  * This file is part of the CoAP library libcoap. Please see README for terms
8  * of use.
9  */
10 
11 #ifndef COAP_DTLS_INTERNAL_H_
12 #define COAP_DTLS_INTERNAL_H_
13 
21 /* https://tools.ietf.org/html/rfc6347#section-4.2.4.1 */
22 #ifndef COAP_DTLS_RETRANSMIT_MS
23 #define COAP_DTLS_RETRANSMIT_MS 1000
24 #endif
25 #ifndef COAP_DTLS_RETRANSMIT_TOTAL_MS
26 #define COAP_DTLS_RETRANSMIT_TOTAL_MS 60000
27 #endif
28 
29 #define COAP_DTLS_RETRANSMIT_COAP_TICKS (COAP_DTLS_RETRANSMIT_MS * COAP_TICKS_PER_SECOND / 1000)
30 
39 void *
41 
53 int
55  coap_dtls_spsk_t *setup_data);
56 
68 int
70  coap_dtls_cpsk_t *setup_data);
71 
89 int
91  const coap_dtls_pki_t *setup_data,
92  const coap_dtls_role_t role);
93 
106 int
108  const char *ca_file,
109  const char *ca_dir);
110 
121 
127 void coap_dtls_free_context(void *dtls_context);
128 
138 
151 
159 
167 
178 int coap_dtls_send(coap_session_t *coap_session,
179  const uint8_t *data,
180  size_t data_len);
181 
189 
198 
208  coap_tick_t now);
209 
216 
228  const uint8_t *data,
229  size_t data_len);
230 
243 int coap_dtls_hello(coap_session_t *coap_session,
244  const uint8_t *data,
245  size_t data_len);
246 
254 unsigned int coap_dtls_get_overhead(coap_session_t *coap_session);
255 
266 void *coap_tls_new_client_session(coap_session_t *coap_session, int *connected);
267 
278 void *coap_tls_new_server_session(coap_session_t *coap_session, int *connected);
279 
286 void coap_tls_free_session( coap_session_t *coap_session );
287 
298 ssize_t coap_tls_write(coap_session_t *coap_session,
299  const uint8_t *data,
300  size_t data_len
301  );
302 
313 ssize_t coap_tls_read(coap_session_t *coap_session,
314  uint8_t *data,
315  size_t data_len
316  );
317 
322 void coap_dtls_startup(void);
323 
328 void coap_dtls_shutdown(void);
329 
338 void *coap_dtls_get_tls(const coap_session_t *session,
339  coap_tls_library_t *tls_lib);
340 
343 #endif /* COAP_DTLS_INTERNAL_H */
uint64_t coap_tick_t
This data type represents internal timer ticks with COAP_TICKS_PER_SECOND resolution.
Definition: coap_time.h:120
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_tick_t coap_dtls_get_context_timeout(void *dtls_context)
Do all pending retransmits and get next timeout.
void coap_dtls_startup(void)
Initialize the underlying (D)TLS Library layer.
Definition: coap_notls.c:70
void coap_dtls_handle_timeout(coap_session_t *coap_session)
Handle a DTLS timeout expiration.
coap_tick_t coap_dtls_get_timeout(coap_session_t *coap_session, coap_tick_t now)
Get next timeout for this 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.
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_tls_new_client_session(coap_session_t *coap_session, int *connected)
Create a new TLS client-side session.
int coap_dtls_send(coap_session_t *coap_session, const uint8_t *data, size_t data_len)
Send data to a DTLS peer.
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.
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.
void * coap_dtls_new_context(coap_context_t *coap_context)
Creates a new DTLS context for the given coap_context.
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:125
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_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_shutdown(void)
Close down the underlying (D)TLS Library layer.
Definition: coap_notls.c:81
ssize_t coap_tls_read(coap_session_t *coap_session, uint8_t *data, size_t data_len)
Read some data from a TLS peer.
void * coap_dtls_new_client_session(coap_session_t *coap_session)
Create a new client-side session.
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.
void coap_dtls_free_context(void *dtls_context)
Releases the storage allocated for dtls_context.
void * coap_tls_new_server_session(coap_session_t *coap_session, int *connected)
Create a TLS new server-side session.
void * coap_dtls_new_server_session(coap_session_t *coap_session)
Create a new DTLS server-side 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.
coap_dtls_role_t
Definition: coap_dtls.h:29
coap_tls_library_t
Definition: coap_dtls.h:50
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:336
The structure used for defining the PKI setup data to be used.
Definition: coap_dtls.h:242
The structure used for defining the Server PSK setup data to be used.
Definition: coap_dtls.h:423
Abstraction of virtual session that can be attached to coap_context_t (client) or coap_endpoint_t (se...