Contiki-NG
Loading...
Searching...
No Matches
mbedtls-support.h File Reference

DTLS (Mbed TLS implementation) support for CoAP. More...

#include <MBEDTLS_CONFIG_FILE>
#include "mbedtls/ssl.h"
#include "mbedtls/entropy.h"
#include "mbedtls/ctr_drbg.h"
#include "mbedtls/timing.h"
#include "dtls-support-config.h"
#include "coap-endpoint.h"
#include "coap-keystore.h"

Go to the source code of this file.

Functions

void coap_dtls_init (void)
 Initializes CoAP-MbedTLS global info.
 
void coap_dtls_event_handler (void)
 Handler for timer, and process-poll events.
 
void coap_dtls_conn_init (struct uip_udp_conn *udp_conn, struct process *host_process)
 Registers, 1.
 
int coap_ep_dtls_write (const coap_endpoint_t *ep, const unsigned char *message, int len)
 Encrypt app.
 
int coap_ep_dtls_handle_message (const coap_endpoint_t *ep)
 Handler for new DTLS messages.
 
void coap_ep_dtls_disconnect (const coap_endpoint_t *ep)
 Disconnect a peer.
 
coap_dtls_session_info_t * coap_ep_get_dtls_session_info (const coap_endpoint_t *ep)
 Get session struct associated with CoAP endpoint.
 
bool coap_ep_is_dtls_peer (const coap_endpoint_t *ep)
 Check if a CoAP endpoint is a peer in the list of DTLS sessions.
 
bool coap_ep_is_dtls_connected (const coap_endpoint_t *ep)
 Check if a peer has completed the handshake successfully.
 
int coap_ep_get_dtls_state (const coap_endpoint_t *ep)
 Check in what DTLS state the peer is in.
 

Detailed Description

DTLS (Mbed TLS implementation) support for CoAP.

Author
Jayendra Ellamathy ejaye.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om

Definition in file mbedtls-support.h.

Function Documentation

◆ coap_dtls_conn_init()

void coap_dtls_conn_init ( struct uip_udp_conn * udp_conn,
struct process * host_process )

Registers, 1.

UDP port info. 2. Host process (Coap Engine).

Parameters
udp_connPointer to UDP port information. This will be used when CoAP-MbedTLS needs to send messages via UDP.
host_processPointer to the host process. This process will recieve a poll event when a DTLS message needs to be sent.

Definition at line 187 of file mbedtls-support.c.

◆ coap_dtls_event_handler()

void coap_dtls_event_handler ( void )

Handler for timer, and process-poll events.

Must be called by the host process (CoAP Engine).

Definition at line 314 of file mbedtls-support.c.

References CLOCK_SECOND, coap_ep_get_dtls_session_info(), etimer_expiration_time(), etimer_expired(), etimer_set(), heapmem_free(), list_head(), list_pop(), PROCESS_CURRENT, and process_poll().

◆ coap_dtls_init()

void coap_dtls_init ( void )

Initializes CoAP-MbedTLS global info.

Must be the first thing that is called before using CoAP-MbedTLS.

Definition at line 159 of file mbedtls-support.c.

References LIST_STRUCT_INIT.

Referenced by coap_transport_init().

◆ coap_ep_dtls_disconnect()

void coap_ep_dtls_disconnect ( const coap_endpoint_t * ep)

Disconnect a peer.

Sends a close notification message to peer. Followed by cleanup of session struct, free memory.

Parameters
epPointer of peer CoAP endpoint.

Definition at line 830 of file mbedtls-support.c.

References coap_ep_get_dtls_session_info(), etimer_stop(), list_remove(), and memb_free().

Referenced by coap_endpoint_disconnect(), and coap_ep_dtls_handle_message().

◆ coap_ep_dtls_handle_message()

int coap_ep_dtls_handle_message ( const coap_endpoint_t * ep)

Handler for new DTLS messages.

Handles both handshake and decryption of record layer messages.

Parameters
epPointer of source CoAP endpoint.
Returns
SUCCESS: 0 for Handshake; Number of bytes read for record layer packet. FAILURE: -1

Definition at line 772 of file mbedtls-support.c.

References coap_ep_dtls_disconnect(), coap_ep_get_dtls_session_info(), uip_appdata, and uip_datalen.

◆ coap_ep_dtls_write()

int coap_ep_dtls_write ( const coap_endpoint_t * ep,
const unsigned char * message,
int len )

Encrypt app.

data and send via UDP.

Parameters
epPointer to destination CoAP endpoint.
messagePointer to the buffer holding app. data.
lenLength of message to be sent.
Returns
SUCCESS: Number of bytes written. FAILURE: -1

Definition at line 734 of file mbedtls-support.c.

References coap_ep_get_dtls_session_info().

Referenced by coap_sendto().

◆ coap_ep_get_dtls_session_info()

coap_dtls_session_info_t * coap_ep_get_dtls_session_info ( const coap_endpoint_t * ep)

Get session struct associated with CoAP endpoint.

Parameters
epPointer of peer CoAP endpoint.

Definition at line 224 of file mbedtls-support.c.

References coap_endpoint_cmp(), and list_head().

Referenced by coap_dtls_event_handler(), coap_ep_dtls_disconnect(), coap_ep_dtls_handle_message(), coap_ep_dtls_write(), coap_ep_get_dtls_state(), and coap_ep_is_dtls_connected().

◆ coap_ep_get_dtls_state()

int coap_ep_get_dtls_state ( const coap_endpoint_t * ep)

Check in what DTLS state the peer is in.

Parameters
epPointer of peer CoAP endpoint.
Warning
Uses deprecated mbedtls getters
Returns
enum mbedtls_ssl_states

Definition at line 244 of file mbedtls-support.c.

References coap_ep_get_dtls_session_info().

◆ coap_ep_is_dtls_connected()

bool coap_ep_is_dtls_connected ( const coap_endpoint_t * ep)

Check if a peer has completed the handshake successfully.

Parameters
epPointer of peer CoAP endpoint.
Returns
SUCCESS: true FAILURE: false

Definition at line 237 of file mbedtls-support.c.

References coap_ep_get_dtls_session_info().

Referenced by coap_endpoint_is_connected().

◆ coap_ep_is_dtls_peer()

bool coap_ep_is_dtls_peer ( const coap_endpoint_t * ep)

Check if a CoAP endpoint is a peer in the list of DTLS sessions.

Parameters
epPointer of peer CoAP endpoint.
Returns
SUCCESS: true FAILURE: false

Definition at line 195 of file mbedtls-support.c.

References coap_endpoint_cmp(), and list_head().

Referenced by coap_endpoint_is_connected().