tinydtls  0.8.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
dtls.h File Reference

High level DTLS API and visible structures. More...

#include <stdint.h>
#include "t_list.h"
#include "state.h"
#include "peer.h"
#include "uthash.h"
#include "alert.h"
#include "crypto.h"
#include "hmac.h"
#include "global.h"
#include "dtls_time.h"

Go to the source code of this file.

Data Structures

struct  dtls_ecdsa_key_t
 
struct  dtls_handler_t
 
struct  dtls_context_t
 

Macros

#define DTLS_VERSION   0xfefd /* DTLS v1.2 */
 
#define DTLS_COOKIE_SECRET_LENGTH   12
 
#define dtls_set_app_data(CTX, DATA)   ((CTX)->app = (DATA))
 
#define dtls_get_app_data(CTX)   ((CTX)->app)
 
#define DTLS_COOKIE_LENGTH   16
 
#define DTLS_CT_CHANGE_CIPHER_SPEC   20
 
#define DTLS_CT_ALERT   21
 
#define DTLS_CT_HANDSHAKE   22
 
#define DTLS_CT_APPLICATION_DATA   23
 
#define DTLS_HT_HELLO_REQUEST   0
 
#define DTLS_HT_CLIENT_HELLO   1
 
#define DTLS_HT_SERVER_HELLO   2
 
#define DTLS_HT_HELLO_VERIFY_REQUEST   3
 
#define DTLS_HT_CERTIFICATE   11
 
#define DTLS_HT_SERVER_KEY_EXCHANGE   12
 
#define DTLS_HT_CERTIFICATE_REQUEST   13
 
#define DTLS_HT_SERVER_HELLO_DONE   14
 
#define DTLS_HT_CERTIFICATE_VERIFY   15
 
#define DTLS_HT_CLIENT_KEY_EXCHANGE   16
 
#define DTLS_HT_FINISHED   20
 

Typedefs

typedef enum
dtls_credentials_type_t 
dtls_credentials_type_t
 
typedef struct dtls_ecdsa_key_t dtls_ecdsa_key_t
 
typedef struct dtls_context_t dtls_context_t
 

Enumerations

enum  dtls_credentials_type_t { DTLS_PSK_HINT, DTLS_PSK_IDENTITY, DTLS_PSK_KEY }
 

Functions

void dtls_init ()
 
dtls_context_tdtls_new_context (void *app_data)
 
void dtls_free_context (dtls_context_t *ctx)
 
static void dtls_set_handler (dtls_context_t *ctx, dtls_handler_t *h)
 
int dtls_connect (dtls_context_t *ctx, const session_t *dst)
 
int dtls_connect_peer (dtls_context_t *ctx, dtls_peer_t *peer)
 
int dtls_close (dtls_context_t *ctx, const session_t *remote)
 
int dtls_renegotiate (dtls_context_t *ctx, const session_t *dst)
 
int dtls_write (struct dtls_context_t *ctx, session_t *session, uint8 *buf, size_t len)
 
void dtls_check_retransmit (dtls_context_t *context, clock_time_t *next)
 
struct __attribute__ ((__packed__))
 
int dtls_handle_message (dtls_context_t *ctx, session_t *session, uint8 *msg, int msglen)
 
dtls_peer_tdtls_get_peer (const dtls_context_t *context, const session_t *session)
 

Variables

 dtls_record_header_t
 
 dtls_handshake_header_t
 
 dtls_client_hello_t
 
 dtls_hello_verify_t
 

Detailed Description

High level DTLS API and visible structures.

Definition in file dtls.h.

Macro Definition Documentation

#define DTLS_COOKIE_LENGTH   16

Definition at line 323 of file dtls.h.

#define DTLS_COOKIE_SECRET_LENGTH   12

Length of the secret that is used for generating Hello Verify cookies.

Definition at line 71 of file dtls.h.

#define DTLS_CT_ALERT   21

Definition at line 326 of file dtls.h.

#define DTLS_CT_APPLICATION_DATA   23

Definition at line 328 of file dtls.h.

#define DTLS_CT_CHANGE_CIPHER_SPEC   20

Definition at line 325 of file dtls.h.

#define DTLS_CT_HANDSHAKE   22

Definition at line 327 of file dtls.h.

#define dtls_get_app_data (   CTX)    ((CTX)->app)

Definition at line 259 of file dtls.h.

#define DTLS_HT_CERTIFICATE   11

Definition at line 346 of file dtls.h.

#define DTLS_HT_CERTIFICATE_REQUEST   13

Definition at line 348 of file dtls.h.

#define DTLS_HT_CERTIFICATE_VERIFY   15

Definition at line 350 of file dtls.h.

#define DTLS_HT_CLIENT_HELLO   1

Definition at line 343 of file dtls.h.

#define DTLS_HT_CLIENT_KEY_EXCHANGE   16

Definition at line 351 of file dtls.h.

#define DTLS_HT_FINISHED   20

Definition at line 352 of file dtls.h.

#define DTLS_HT_HELLO_REQUEST   0

Definition at line 342 of file dtls.h.

#define DTLS_HT_HELLO_VERIFY_REQUEST   3

Definition at line 345 of file dtls.h.

#define DTLS_HT_SERVER_HELLO   2

Definition at line 344 of file dtls.h.

#define DTLS_HT_SERVER_HELLO_DONE   14

Definition at line 349 of file dtls.h.

#define DTLS_HT_SERVER_KEY_EXCHANGE   12

Definition at line 347 of file dtls.h.

#define dtls_set_app_data (   CTX,
  DATA 
)    ((CTX)->app = (DATA))

Definition at line 258 of file dtls.h.

#define DTLS_VERSION   0xfefd /* DTLS v1.2 */

Definition at line 56 of file dtls.h.

Typedef Documentation

Holds global information of the DTLS engine.

Enumeration Type Documentation

Enumerator
DTLS_PSK_HINT 
DTLS_PSK_IDENTITY 
DTLS_PSK_KEY 

Definition at line 59 of file dtls.h.

Function Documentation

struct __attribute__ ( (__packed__)  )

Generic header structure of the DTLS record layer.

Header structure for the DTLS handshake protocol.

Structure of the Client Hello message.

Structure of the Hello Verify Request.

< content type of the included message

< Protocol version

< counter for cipher state changes

< sequence number

< length of the following fragment

< Type of handshake message (one of DTLS_HT_)

< length of this message

< Message sequence number

< Fragment offset.

< Fragment length.

< Client version

< GMT time of the random byte creation

< Client random bytes

< Server version

< Length of the included cookie

< up to 32 bytes making up the cookie

Definition at line 331 of file dtls.h.

void dtls_check_retransmit ( dtls_context_t context,
clock_time_t next 
)

Checks sendqueue of given DTLS context object for any outstanding packets to be transmitted.

Parameters
contextThe DTLS context object to use.
nextIf not NULL, next is filled with the timestamp of the next scheduled retransmission, or 0 when no packets are waiting.

Definition at line 3957 of file dtls.c.

int dtls_close ( dtls_context_t ctx,
const session_t remote 
)

Closes the DTLS connection associated with remote. This function returns zero on success, and a value less than zero on error.

Definition at line 1494 of file dtls.c.

int dtls_connect ( dtls_context_t ctx,
const session_t dst 
)

Establishes a DTLS channel with the specified remote peer dst. This function returns 0 if that channel already exists, a value greater than zero when a new ClientHello message was sent, and a value less than zero on error.

Parameters
ctxThe DTLS context to use.
dstThe remote party to connect to.
Returns
A value less than zero on error, greater or equal otherwise.

Definition at line 3862 of file dtls.c.

int dtls_connect_peer ( dtls_context_t ctx,
dtls_peer_t peer 
)

Establishes a DTLS channel with the specified remote peer. This function returns 0 if that channel already exists, a value greater than zero when a new ClientHello message was sent, and a value less than zero on error.

Parameters
ctxThe DTLS context to use.
peerThe peer object that describes the session.
Returns
A value less than zero on error, greater or equal otherwise.

Definition at line 3826 of file dtls.c.

void dtls_free_context ( dtls_context_t ctx)

Releases any storage that has been allocated for ctx.

Definition at line 3802 of file dtls.c.

dtls_peer_t* dtls_get_peer ( const dtls_context_t context,
const session_t session 
)

Check if session is associated with a peer object in context. This function returns a pointer to the peer if found, NULL otherwise.

Parameters
contextThe DTLS context to search.
sessionThe remote address and local interface
Returns
A pointer to the peer associated with session or NULL if none exists.

Definition at line 212 of file dtls.c.

int dtls_handle_message ( dtls_context_t ctx,
session_t session,
uint8 msg,
int  msglen 
)

Handles incoming data as DTLS message from given peer.

Parameters
ctxThe dtls context to use.
sessionThe current session
msgThe received data
msglenThe actual length of msg.
Returns
A value less than zero on error, zero on success.

Handles incoming data as DTLS message from given peer.

Definition at line 3591 of file dtls.c.

void dtls_init ( )

This function initializes the tinyDTLS memory management and must be called first.

Definition at line 163 of file dtls.c.

dtls_context_t* dtls_new_context ( void *  app_data)

Creates a new context object. The storage allocated for the new object must be released with dtls_free_context().

Definition at line 3740 of file dtls.c.

int dtls_renegotiate ( dtls_context_t ctx,
const session_t dst 
)

Definition at line 2956 of file dtls.c.

static void dtls_set_handler ( dtls_context_t ctx,
dtls_handler_t h 
)
inlinestatic

Sets the callback handler object for ctx to h.

Definition at line 262 of file dtls.h.

int dtls_write ( struct dtls_context_t ctx,
session_t session,
uint8 buf,
size_t  len 
)

Writes the application data given in buf to the peer specified by session.

Parameters
ctxThe DTLS context to use.
sessionThe remote transport address and local interface.
bufThe data to write.
lenThe actual length of data.
Returns
The number of bytes written or -1 on error.

Definition at line 236 of file dtls.c.

Variable Documentation

dtls_client_hello_t

Definition at line 373 of file dtls.h.

dtls_handshake_header_t

Definition at line 362 of file dtls.h.

dtls_hello_verify_t

Definition at line 380 of file dtls.h.

dtls_record_header_t

Definition at line 338 of file dtls.h.