dtls.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2019 HAW Hamburg
3  * Freie Universit├Ąt Berlin
4  * Inria
5  * Daniele Lacamera
6  * Ken Bannister
7  *
8  * This file is subject to the terms and conditions of the GNU Lesser
9  * General Public License v2.1. See the file LICENSE in the top level
10  * directory for more details.
11  */
12 
522 #ifndef NET_SOCK_DTLS_H
523 #define NET_SOCK_DTLS_H
524 
525 #include <assert.h>
526 #include <errno.h>
527 #include <stdint.h>
528 #include <stdlib.h>
529 #include <sys/types.h>
530 
531 /* net/sock/async/types.h included by net/sock.h needs to re-typedef the
532  * `sock_dtls_t` to prevent cyclic includes */
533 #if defined (__clang__)
534 # pragma clang diagnostic push
535 # pragma clang diagnostic ignored "-Wtypedef-redefinition"
536 #endif
537 
538 #include "net/sock.h"
539 #include "net/sock/udp.h"
540 #include "net/credman.h"
541 
542 #ifdef __cplusplus
543 extern "C" {
544 #endif
545 
559 #ifndef CONFIG_DTLS_HANDSHAKE_BUFSIZE_EXP
560 #define CONFIG_DTLS_HANDSHAKE_BUFSIZE_EXP 8
561 #endif
567 #ifndef DTLS_HANDSHAKE_BUFSIZE
568 #define DTLS_HANDSHAKE_BUFSIZE (1 << CONFIG_DTLS_HANDSHAKE_BUFSIZE_EXP)
569 #endif
570 
574 #define SOCK_DTLS_HANDSHAKE (EXDEV)
575 
581 enum {
585 };
593 enum {
596 };
605 typedef struct sock_dtls sock_dtls_t;
606 
607 #if defined (__clang__)
608 # pragma clang diagnostic pop
609 #endif
610 
615 
625 
635 
641 void sock_dtls_init(void);
642 
666  credman_tag_t tag, unsigned version, unsigned role);
667 
678 
697  sock_dtls_session_t *remote);
698 
713 
723  sock_udp_ep_t *ep);
724 
737  const sock_udp_ep_t *ep);
738 
769  void *data, size_t maxlen, uint32_t timeout,
770  sock_dtls_aux_rx_t *aux);
771 
799 static inline ssize_t sock_dtls_recv(sock_dtls_t *sock,
800  sock_dtls_session_t *remote,
801  void *data, size_t maxlen,
802  uint32_t timeout)
803 {
804  return sock_dtls_recv_aux(sock, remote, data, maxlen, timeout, NULL);
805 }
806 
850  void **data, void **buf_ctx, uint32_t timeout,
851  sock_dtls_aux_rx_t *aux);
852 
893 static inline ssize_t sock_dtls_recv_buf(sock_dtls_t *sock,
894  sock_dtls_session_t *remote,
895  void **data, void **buf_ctx,
896  uint32_t timeout)
897 {
898  return sock_dtls_recv_buf_aux(sock, remote, data, buf_ctx, timeout, NULL);
899 }
900 
936  const void *data, size_t len, uint32_t timeout,
937  sock_dtls_aux_tx_t *aux);
938 
979 static inline ssize_t sock_dtls_send(sock_dtls_t *sock,
980  sock_dtls_session_t *remote,
981  const void *data, size_t len,
982  uint32_t timeout)
983 {
984  return sock_dtls_send_aux(sock, remote, data, len, timeout, NULL);
985 }
986 
1000 
1001 #include "sock_dtls_types.h"
1002 
1003 #ifdef __cplusplus
1004 }
1005 #endif
1006 
1007 #endif /* NET_SOCK_DTLS_H */
POSIX.1-2008 compliant version of the assert macro.
(D)TLS credentials management module definitions
uint16_t credman_tag_t
Tag of the credential.
Definition: credman.h:96
static ssize_t sock_dtls_recv_buf(sock_dtls_t *sock, sock_dtls_session_t *remote, void **data, void **buf_ctx, uint32_t timeout)
Decrypts and provides stack-internal buffer space containing a message from a remote peer.
Definition: dtls.h:893
int sock_dtls_create(sock_dtls_t *sock, sock_udp_t *udp_sock, credman_tag_t tag, unsigned version, unsigned role)
Creates a new DTLS sock object.
ssize_t sock_dtls_recv_buf_aux(sock_dtls_t *sock, sock_dtls_session_t *remote, void **data, void **buf_ctx, uint32_t timeout, sock_dtls_aux_rx_t *aux)
Decrypts and provides stack-internal buffer space containing a message from a remote peer.
sock_udp_t * sock_dtls_get_udp_sock(sock_dtls_t *sock)
Get underlying UDP sock.
void sock_dtls_close(sock_dtls_t *sock)
Closes a DTLS sock.
void sock_dtls_init(void)
Called exactly once during auto_init.
void sock_dtls_session_destroy(sock_dtls_t *sock, sock_dtls_session_t *remote)
Destroys an existing DTLS session.
static ssize_t sock_dtls_send(sock_dtls_t *sock, sock_dtls_session_t *remote, const void *data, size_t len, uint32_t timeout)
Encrypts and sends a message to a remote peer.
Definition: dtls.h:979
int sock_dtls_session_init(sock_dtls_t *sock, const sock_udp_ep_t *ep, sock_dtls_session_t *remote)
Initialize session handshake.
ssize_t sock_dtls_send_aux(sock_dtls_t *sock, sock_dtls_session_t *remote, const void *data, size_t len, uint32_t timeout, sock_dtls_aux_tx_t *aux)
Encrypts and sends a message to a remote peer.
static ssize_t sock_dtls_recv(sock_dtls_t *sock, sock_dtls_session_t *remote, void *data, size_t maxlen, uint32_t timeout)
Receive handshake messages and application data from remote peer.
Definition: dtls.h:799
ssize_t sock_dtls_recv_aux(sock_dtls_t *sock, sock_dtls_session_t *remote, void *data, size_t maxlen, uint32_t timeout, sock_dtls_aux_rx_t *aux)
Receive handshake messages and application data from remote peer.
sock_udp_aux_rx_t sock_dtls_aux_rx_t
Auxiliary data provided when receiving using an DTLS sock object.
Definition: dtls.h:624
sock_udp_aux_tx_t sock_dtls_aux_tx_t
Auxiliary data provided when sending using an DTLS sock object.
Definition: dtls.h:634
void sock_dtls_session_get_udp_ep(const sock_dtls_session_t *session, sock_udp_ep_t *ep)
Get the remote UDP endpoint from a session.
void sock_dtls_session_set_udp_ep(sock_dtls_session_t *session, const sock_udp_ep_t *ep)
Set the remote UDP endpoint from a session.
@ SOCK_DTLS_CLIENT
Endpoint client role.
Definition: dtls.h:594
@ SOCK_DTLS_SERVER
Endpoint server role.
Definition: dtls.h:595
@ SOCK_DTLS_1_0
DTLS version 1.0.
Definition: dtls.h:582
@ SOCK_DTLS_1_2
DTLS version 1.2.
Definition: dtls.h:583
@ SOCK_DTLS_1_3
DTLS version 1.3.
Definition: dtls.h:584
UDP sock definitions.
Common sock API definitions.
tinydtls-specific types and functions definitions
Common IP-based transport layer end point.
Definition: sock.h:214
Information about remote client connected to the server.
Information about DTLS sock.
Auxiliary data provided when receiving using an UDP sock object.
Definition: udp.h:306
Auxiliary data provided when sending using an UDP sock object.
Definition: udp.h:337
UDP sock type.
Definition: sock_types.h:128