43#include "contiki-net.h"
49#include "mbedtls/debug.h"
50#include "mbedtls/error.h"
51#include "mbedtls/net_sockets.h"
52#include "mbedtls/version.h"
54#if !defined(MBEDTLS_SSL_PROTO_DTLS) || \
55 !(defined(MBEDTLS_TIMING_C) || defined(MBEDTLS_TIMING_ALT)) || \
56 !defined(MBEDTLS_ENTROPY_C) || !defined(MBEDTLS_CTR_DRBG_C)
57#error "Invalid MBEDTLS configuration."
60#ifdef COAP_DTLS_CONF_WITH_CLIENT
61#if !defined(MBEDTLS_SSL_CLI_C)
62#error "MBEDTLS_SSL_CLI_C not defined.";
66#ifdef COAP_DTLS_CONF_WITH_SERVER
67#if !defined(MBEDTLS_SSL_SRV_C) || !defined(MBEDTLS_SSL_COOKIE_C) || \
68 !defined(MBEDTLS_SSL_CACHE_C)
69#error "MBEDTLS_SSL_SRV_C and/or MBEDTLS_SSL_COOKIE_C and/or "
70 "MBEDTLS_SSL_CACHE_C not defined.";
75#ifdef COAP_DTLS_CONF_WITH_PSK
76#if !defined(MBEDTLS_KEY_EXCHANGE_PSK_ENABLED)
77#error "MBEDTLS_KEY_EXCHANGE_PSK_ENABLED not defined.";
81#ifdef COAP_DTLS_CONF_WITH_CERT
82#if !defined(MBEDTLS_X509_CRT_PARSE_C) || \
83 !defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) || \
84 !defined(MBEDTLS_PEM_PARSE_C)
85#error "MBEDTLS_X509_CRT_PARSE_C and/or "
86 "MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED and/or "
87 "MBEDTLS_PEM_PARSE_C not defined.\n");
91#if !defined(COAP_DTLS_PRNG_INSECURE) && !CSPRNG_ENABLED
92#error CSPRNG module needs to be enabled for DTLS. Set CSPRNG_CONF_ENABLED to 1.
95#if defined(MBEDTLS_ECDSA_VERIFY_ALT) || \
96 defined(MBEDTLS_ECDH_COMPUTE_SHARED_ALT)
97#include "nrf_crypto.h"
103#define LOG_MODULE "DTLS"
104#define LOG_LEVEL LOG_LEVEL_DTLS
106MEMB(dtls_session_info_memb, coap_dtls_session_info_t,
107 COAP_DTLS_MAX_SESSIONS);
109static coap_dtls_context_t dtls_context;
112#if defined(MBEDTLS_DEBUG_C)
114mbedtls_debug(
void *ctx,
int level,
115 const char *file,
int line,
const char *str)
117 LOG_DBG(
"%s:%d: %s", file, line, str);
121#if defined(MBEDTLS_NO_PLATFORM_ENTROPY)
123random_number_generator(
void *ctx,
unsigned char *buffer,
size_t length)
125#if COAP_DTLS_PRNG_INSECURE
127 uint16_t rand_num = 0;
130 while(length < (len +
sizeof(rand_num))) {
132 memcpy(buffer + len, &rand_num,
sizeof(rand_num));
133 len +=
sizeof(rand_num);
136 memcpy(buffer, &rand_num, length - len);
138 LOG_WARN(
"Missing CSPRNG: using %zu bytes of possibly non-random values!\n",
144#error CSPRNG module needs to be enabled for DTLS. Set CSPRNG_CONF_ENABLED to 1.
148 LOG_ERR(
"Failed to generate %zu bytes of random values\n", length);
149 return MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED;
151 LOG_DBG(
"Generated %zu bytes of random values\n", length);
163 mbedtls_version_get_string_full(version);
164 LOG_INFO(
"Initializing DTLS support with library \"%s\"\n", version);
166#if defined(MBEDTLS_DEBUG_C)
167 mbedtls_debug_set_threshold(COAP_MBEDTLS_LIB_DEBUG_LEVEL);
170#if defined(MBEDTLS_ECDSA_VERIFY_ALT) || \
171 defined(MBEDTLS_ECDH_COMPUTE_SHARED_ALT)
172 if(nrf_crypto_init() != NRF_SUCCESS) {
173 LOG_ERR(
"Unable to initialize nRF Crypto\n");
182 dtls_context.ready = 1;
188 struct process *host_process)
190 dtls_context.udp_conn = udp_conn;
191 dtls_context.host_process = host_process;
197 coap_dtls_session_info_t *info = NULL;
199 for(info =
list_head(dtls_context.sessions); info; info = info->next) {
207#ifdef COAP_DTLS_CONF_WITH_SERVER
208coap_dtls_session_info_t *
209coap_get_free_server_session(
void)
211 coap_dtls_session_info_t *info = NULL;
213 for(info =
list_head(dtls_context.sessions); info; info = info->next) {
214 if(info->role == COAP_MBEDTLS_ROLE_SERVER && !info->in_use) {
223coap_dtls_session_info_t *
226 coap_dtls_session_info_t *info = NULL;
228 for(info =
list_head(dtls_context.sessions); info; info = info->next) {
240 return info != NULL ? mbedtls_ssl_is_handshake_over(&info->ssl) : 0;
247 return info != NULL ? info->ssl.MBEDTLS_PRIVATE(state) : 0;
251perform_handshake(coap_dtls_session_info_t *session_info)
256 memset(&session_info->retransmission_et, 0,
sizeof(
struct etimer));
258#ifdef COAP_DTLS_CONF_WITH_SERVER
259 if(session_info->role == COAP_MBEDTLS_ROLE_SERVER) {
261 ret = mbedtls_ssl_set_client_transport_id(&session_info->ssl,
262 (
const unsigned char *)&session_info->ep,
263 sizeof(coap_endpoint_t));
265 LOG_DBG(
"mbedtls_ssl_set_client_transport_id() returned -0x%x\n",
271 LOG_INFO(
"Handshake starting\n");
272 ret = mbedtls_ssl_handshake(&session_info->ssl);
273 LOG_INFO(
"Handshake in progress, ending with completed = %d\n",
274 mbedtls_ssl_is_handshake_over(&session_info->ssl));
277 LOG_INFO(
"DTLS handshake succesful\n");
280 if(ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE) {
281#ifdef COAP_DTLS_CONF_WITH_CLIENT
284 if(session_info->role == COAP_MBEDTLS_ROLE_CLIENT) {
286 memb_free(&dtls_session_info_memb, session_info);
290#ifdef COAP_DTLS_CONF_WITH_SERVER
291 if(session_info->role == COAP_MBEDTLS_ROLE_SERVER) {
294 mbedtls_ssl_session_reset(&session_info->ssl);
295 if(ret != MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED) {
296 session_info->in_use =
false;
297 memset(&session_info->ep, 0,
sizeof(coap_endpoint_t));
304 LOG_ERR(
"DTLS handshake failed\n");
316 LOG_DBG(
"Call to %s\n", __func__);
319 coap_dtls_send_message_t *send_message =
list_pop(dtls_context.send_message_fifo);
320 if(send_message == NULL) {
321 LOG_DBG(
"No message in the FIFO\n");
323 uip_udp_packet_sendto(dtls_context.udp_conn, send_message->send_buf,
325 &send_message->ep.ipaddr, send_message->ep.port);
326 LOG_INFO(
"Sent DTLS message of len = %zu\n", send_message->len);
328 LOG_ERR(
"Failed to free a sent message\n");
339 uint32_t elapsed_ms = mbedtls_timing_get_timer(&info->timer.MBEDTLS_PRIVATE(
timer),
341 if(info->timer.MBEDTLS_PRIVATE(fin_ms) > 0) {
342 uint32_t time_left_ms = info->timer.MBEDTLS_PRIVATE(fin_ms) - elapsed_ms;
343 if(time_left_ms > 0) {
344 LOG_DBG(
"Updating re-transmission timer to %u ms\n",
345 (
unsigned int)time_left_ms);
351 if(
list_head(dtls_context.send_message_fifo) != NULL) {
352 if(COAP_MBEDTLS_FRAGMENT_TIMER > 0) {
355 LOG_DBG(
"Setting fragmentation timer to %u ms\n",
356 (
unsigned int)COAP_MBEDTLS_FRAGMENT_TIMER);
364 for(coap_dtls_session_info_t *info =
list_head(dtls_context.sessions);
369 LOG_INFO(
"Re-transmission timer expired\n");
371 perform_handshake(info);
380coap_ep_mbedtls_sendto(
void *ctx,
const unsigned char *buf,
size_t len)
382 LOG_DBG(
"Call to %s\n", __func__);
385 return MBEDTLS_ERR_NET_INVALID_CONTEXT;
388 coap_dtls_send_message_t *send_message = (coap_dtls_send_message_t *)
heapmem_alloc(
sizeof(coap_dtls_send_message_t));
389 if(send_message == NULL) {
390 LOG_ERR(
"Unable to allocate memory for DTLS message\n");
391 return MBEDTLS_ERR_NET_SEND_FAILED;
394 coap_dtls_session_info_t *session_info = (coap_dtls_session_info_t *)ctx;
395 memcpy(&send_message->ep, &session_info->ep,
sizeof(coap_endpoint_t));
396 memcpy(send_message->send_buf, buf, len);
397 send_message->len = len;
398 list_add(dtls_context.send_message_fifo, send_message);
406coap_ep_mbedtls_recv(
void *ctx,
unsigned char *buf,
size_t len)
408 LOG_DBG(
"Call to %s\n", __func__);
411 LOG_DBG(
"Input data length is 0\n");
412 return MBEDTLS_ERR_SSL_WANT_READ;
416 LOG_DBG(
"Session info is missing\n");
417 return MBEDTLS_ERR_NET_INVALID_CONTEXT;
419 coap_dtls_session_info_t *session_info = (coap_dtls_session_info_t *)ctx;
420 if(session_info->is_packet_consumed) {
421 LOG_DBG(
"The packet has been consumed\n");
422 return MBEDTLS_ERR_SSL_WANT_READ;
426 LOG_ERR(
"DTLS incoming buffer too small, len = %zu, uip_datalen = %d\n",
432 session_info->is_packet_consumed =
true;
434 LOG_DBG(
"Read of %d bytes completed\n",
uip_datalen());
438static coap_dtls_session_info_t *
439setup_session(
const coap_mbedtls_role_t role,
440 const coap_dtls_sec_mode_t sec_mode,
441 const void *keystore_entry)
444#if !defined(MBEDTLS_NO_PLATFORM_ENTROPY)
445 const char *pers =
"Contiki_DTLS";
447 coap_dtls_session_info_t *session_info = NULL;
450 session_info =
memb_alloc(&dtls_session_info_memb);
452 LOG_ERR(
"Unable to allocate memory for DTLS server session\n");
455 list_add(dtls_context.sessions, session_info);
457 session_info->role = role;
460 mbedtls_ssl_init(&session_info->ssl);
461 mbedtls_ssl_config_init(&session_info->conf);
463#if !defined(MBEDTLS_NO_PLATFORM_ENTROPY)
464 mbedtls_entropy_init(&session_info->entropy);
466 mbedtls_ctr_drbg_init(&session_info->ctr_drbg);
468#ifdef COAP_DTLS_CONF_WITH_CERT
469 if(sec_mode == COAP_DTLS_SEC_MODE_CERT) {
470 mbedtls_x509_crt_init(&session_info->ca_cert);
471 mbedtls_x509_crt_init(&session_info->own_cert);
472 mbedtls_pk_init(&session_info->pkey);
476#ifdef COAP_DTLS_CONF_WITH_SERVER
478 if(role == COAP_MBEDTLS_ROLE_SERVER) {
479 mbedtls_ssl_cookie_init(&session_info->cookie_ctx);
480#if defined(MBEDTLS_SSL_CACHE_C)
481 mbedtls_ssl_cache_init(&session_info->cache);
488#if !defined(MBEDTLS_NO_PLATFORM_ENTROPY)
489 if((ret = mbedtls_ctr_drbg_seed(&session_info->ctr_drbg,
490 mbedtls_entropy_func,
491 &session_info->entropy,
492 (
const unsigned char *)pers,
493 strlen(pers))) != 0) {
494 LOG_ERR(
"mbedtls_ctr_drbg_seed returned %d\n", ret);
495 goto clean_and_ret_err;
500 if((ret = mbedtls_ssl_config_defaults(&session_info->conf,
501 role == COAP_MBEDTLS_ROLE_CLIENT ?
502 MBEDTLS_SSL_IS_CLIENT : MBEDTLS_SSL_IS_SERVER,
503 MBEDTLS_SSL_TRANSPORT_DATAGRAM,
504 MBEDTLS_SSL_PRESET_DEFAULT)) != 0) {
505 LOG_ERR(
"mbedtls_ssl_config_defaults returned %d\n", ret);
506 goto clean_and_ret_err;
509#ifndef COAP_MBEDTLS_CONF_USE_ALL_CIPHERSUITES
510#ifdef COAP_DTLS_CONF_WITH_CERT
511 if(sec_mode == COAP_DTLS_SEC_MODE_CERT) {
512 session_info->ciphersuite = MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8;
515#ifdef COAP_DTLS_CONF_WITH_PSK
516 if(sec_mode == COAP_DTLS_SEC_MODE_PSK) {
517 session_info->ciphersuite = MBEDTLS_TLS_PSK_WITH_AES_256_CCM_8;
520 mbedtls_ssl_conf_ciphersuites(&session_info->conf,
521 (
const int *)&session_info->ciphersuite);
526 mbedtls_ssl_conf_authmode(&session_info->conf, MBEDTLS_SSL_VERIFY_REQUIRED);
527 mbedtls_ssl_conf_rng(&session_info->conf,
528#
if !defined(MBEDTLS_NO_PLATFORM_ENTROPY)
529 mbedtls_ctr_drbg_random,
531 random_number_generator,
533 &session_info->ctr_drbg);
534#ifdef COAP_DTLS_CONF_WITH_CERT
535 if(sec_mode == COAP_DTLS_SEC_MODE_CERT) {
538 if(ks->ca_cert == NULL || ks->own_cert == NULL || ks->priv_key == NULL) {
539 LOG_ERR(
"Certificate or private key missing!\n");
540 goto clean_and_ret_err;
544 ret = mbedtls_x509_crt_parse(&session_info->ca_cert,
545 (
const unsigned char *)ks->ca_cert,
548 LOG_ERR(
"mbedtls_x509_crt_parse failed for CA cert (error %d)\n", ret);
549 goto clean_and_ret_err;
552 mbedtls_ssl_conf_ca_chain(&session_info->conf, &session_info->ca_cert,
556 ret = mbedtls_x509_crt_parse(&session_info->own_cert,
557 (
const unsigned char *)ks->own_cert,
560 LOG_ERR(
"mbedtls_x509_crt_parse for own cert (error %d)\n", ret);
561 goto clean_and_ret_err;
564 ret = mbedtls_pk_parse_key(&session_info->pkey,
565 (
const unsigned char *)ks->priv_key,
566 ks->priv_key_len, NULL, 0,
567 mbedtls_entropy_func, NULL);
569 LOG_DBG(
"mbedtls_pk_parse_key returned %d\n", ret);
570 goto clean_and_ret_err;
573 ret = mbedtls_ssl_conf_own_cert(&session_info->conf,
574 &session_info->own_cert,
575 &session_info->pkey);
577 LOG_ERR(
"mbedtls_ssl_conf_own_cert returned %d\n", ret);
578 goto clean_and_ret_err;
582#ifdef COAP_DTLS_CONF_WITH_PSK
583 if(sec_mode == COAP_DTLS_SEC_MODE_PSK) {
588 if(ks->identity == NULL || ks->key == NULL) {
589 LOG_ERR(
"PSK identity or key missing\n");
590 goto clean_and_ret_err;
594 mbedtls_ssl_conf_psk(&session_info->conf,
595 (
const unsigned char *)ks->key,
597 (
const unsigned char *)ks->identity,
602 LOG_ERR(
"DTLS Security mode NOT specified!\n");
603 goto clean_and_ret_err;
606#if defined(MBEDTLS_DEBUG_C)
607 mbedtls_ssl_conf_dbg(&session_info->conf, mbedtls_debug, stdout);
609 mbedtls_ssl_conf_handshake_timeout(&session_info->conf,
610 COAP_MBEDTLS_HANDSHAKE_MIN_TIMEOUT_MS,
611 COAP_MBEDTLS_HANDSHAKE_MAX_TIMEOUT_MS);
613 mbedtls_ssl_conf_max_frag_len(&session_info->conf,
614 COAP_MBEDTLS_MAX_FRAG_LEN);
616#ifdef COAP_DTLS_CONF_WITH_SERVER
617 if(role == COAP_MBEDTLS_ROLE_SERVER) {
618#if defined(MBEDTLS_SSL_CACHE_C)
619 mbedtls_ssl_conf_session_cache(&session_info->conf, &session_info->cache,
620 mbedtls_ssl_cache_get,
621 mbedtls_ssl_cache_set);
624 ret = mbedtls_ssl_cookie_setup(&session_info->cookie_ctx,
625 mbedtls_ctr_drbg_random,
626 &session_info->ctr_drbg);
628 LOG_ERR(
"mbedtls_ssl_cookie_setup returned %d\n", ret);
629 goto clean_and_ret_err;
632 mbedtls_ssl_conf_dtls_cookies(&session_info->conf,
633 mbedtls_ssl_cookie_write,
634 mbedtls_ssl_cookie_check,
635 &session_info->cookie_ctx);
639 ret = mbedtls_ssl_setup(&session_info->ssl, &session_info->conf);
641 LOG_ERR(
"mbedtls_ssl_setup returned -0x%x\n", (
unsigned int)-ret);
642 goto clean_and_ret_err;
645#if defined(MBEDTLS_SSL_SERVER_NAME_INDICATION)
648 ret = mbedtls_ssl_set_hostname(&session_info->ssl,
651 LOG_ERR(
"mbedtls_ssl_set_hostname returned %d\n", ret);
655 mbedtls_ssl_set_bio(&session_info->ssl, session_info, coap_ep_mbedtls_sendto,
656 coap_ep_mbedtls_recv, NULL);
657 mbedtls_ssl_set_timer_cb(&session_info->ssl, &session_info->timer,
658 mbedtls_timing_set_delay, mbedtls_timing_get_delay);
659 mbedtls_ssl_set_mtu(&session_info->ssl, COAP_MBEDTLS_MTU);
664 memb_free(&dtls_session_info_memb, session_info);
671#ifdef COAP_DTLS_CONF_WITH_CLIENT
673coap_ep_dtls_connect(
const coap_endpoint_t *ep,
674 const coap_dtls_sec_mode_t sec_mode,
675 const void *keystore_entry)
677 if(!dtls_context.ready) {
678 LOG_WARN(
"DTLS not initialized but %s called!\n", __func__);
684 if(session_info == NULL) {
685 session_info = setup_session(COAP_MBEDTLS_ROLE_CLIENT,
686 sec_mode, keystore_entry);
687 if(session_info == NULL) {
690 memcpy(&session_info->ep, ep,
sizeof(coap_endpoint_t));
698 if((session_info->ssl.MBEDTLS_PRIVATE(state) == MBEDTLS_SSL_HELLO_REQUEST)
699 || mbedtls_ssl_is_handshake_over(&session_info->ssl)
700 || mbedtls_timing_get_delay(&session_info->timer) != 2) {
705 LOG_INFO(
"Re-transmission timer expired\n");
710 perform_handshake(session_info);
715#ifdef COAP_DTLS_CONF_WITH_SERVER
717coap_mbedtls_server_setup(
const coap_dtls_sec_mode_t sec_mode,
718 const void *keystore_entry)
721 coap_dtls_session_info_t *session_info = setup_session(COAP_MBEDTLS_ROLE_SERVER,
722 sec_mode, keystore_entry);
723 if(session_info == NULL) {
724 LOG_ERR(
"Unable to setup DTLS server\n");
728 LOG_INFO(
"DTLS server setup complete, ready to accept connections\n");
735 const unsigned char *message,
int len)
737 if(!dtls_context.ready) {
738 LOG_WARN(
"DTLS not initialized but %s called!\n", __func__);
743 LOG_ERR(
"Unable to find DTLS peer ");
744 LOG_ERR_6ADDR(&ep->ipaddr);
749 if(!mbedtls_ssl_is_handshake_over(&info->ssl)) {
750 LOG_ERR(
"DTLS handshake not complete yet, but %s called!\n", __func__);
754 int ret = mbedtls_ssl_get_max_out_record_payload(&info->ssl);
755 if(ret < len && ret >= 0) {
757 LOG_ERR(
"Payload too large to handle, Max allowed = %d, Given = %d\n",
762 ret = mbedtls_ssl_write(&info->ssl, message, len);
764 LOG_ERR(
"mbedtls_ssl_write returned 0x%x\n", ret);
774 if(!dtls_context.ready) {
775 LOG_WARN(
"Called %s without DTLS being initialized; dropping message\n",
780 LOG_INFO(
"Recieved DTLS message of len = %d\n",
uip_datalen());
785 if(session_info != NULL) {
788 if(!mbedtls_ssl_is_handshake_over(&session_info->ssl)) {
789 goto perform_handshake;
792#ifdef COAP_DTLS_CONF_WITH_SERVER
795 if((session_info = coap_get_free_server_session()) != NULL) {
796 memcpy(&session_info->ep, ep,
sizeof(coap_endpoint_t));
797 goto perform_handshake;
801 LOG_WARN(
"DTLS message recvd from ");
802 LOG_WARN_6ADDR(&ep->ipaddr);
803 LOG_WARN(
" without a session\n");
808 session_info->is_packet_consumed =
false;
810 int ret = mbedtls_ssl_read(&session_info->ssl,
uip_appdata,
811 UIP_CONF_BUFFER_SIZE);
812 if(ret == MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY) {
813 LOG_INFO(
"DTLS peer closed connection\n");
815 }
else if(ret <= 0) {
816 LOG_DBG(
"mbedtls_ssl_read returned %d\n", ret);
818 LOG_DBG(
"Read %d application data bytes\n", ret);
824 session_info->is_packet_consumed =
false;
825 perform_handshake(session_info);
834 mbedtls_ssl_close_notify(&info->ssl);
835#ifdef COAP_DTLS_CONF_WITH_CLIENT
836 if(info->role == COAP_MBEDTLS_ROLE_CLIENT) {
838 memb_free(&dtls_session_info_memb, info);
841#ifdef COAP_DTLS_CONF_WITH_SERVER
842 if(info->role == COAP_MBEDTLS_ROLE_SERVER) {
843 mbedtls_ssl_session_reset(&info->ssl);
844 info->in_use =
false;
845 memset(&info->ep, 0,
sizeof(coap_endpoint_t));
An OFB-AES-128-based CSPRNG.
unsigned short random_rand(void)
Generates a new random number using the cc2538 RNG.
#define CLOCK_SECOND
A second, measured in system clock time.
int coap_endpoint_cmp(const coap_endpoint_t *e1, const coap_endpoint_t *e2)
Compare two CoAP endpoints.
bool csprng_rand(uint8_t *result, size_t len)
Generates a cryptographic random number.
void etimer_stop(struct etimer *et)
Stop a pending event timer.
static bool etimer_expired(struct etimer *et)
Check if an event timer has expired.
void etimer_set(struct etimer *et, clock_time_t interval)
Set an event timer.
clock_time_t etimer_expiration_time(struct etimer *et)
Get the expiration time for the event timer.
#define heapmem_alloc(size)
Allocate a chunk of memory in the general zone of the heap.
bool heapmem_free(void *ptr)
Deallocate a chunk of memory.
void list_add(list_t list, void *item)
Add an item at the end of a list.
void list_remove(list_t list, const void *item)
Remove a specific element from a list.
void * list_pop(list_t list)
Remove the first object on a list.
#define LIST_STRUCT_INIT(struct_ptr, name)
Initialize a linked list that is part of a structure.
static void * list_head(const_list_t list)
Get a pointer to the first element of a list.
int memb_free(struct memb *m, void *ptr)
Deallocate a memory block from a memory block previously declared with MEMB().
void * memb_alloc(struct memb *m)
Allocate a memory block from a block of memory declared with MEMB().
#define MEMB(name, structure, num)
Declare a memory block.
#define PROCESS_CURRENT()
Get a pointer to the currently running process.
void process_poll(struct process *p)
Request a process to be polled.
void * uip_appdata
Pointer to the application data in the packet buffer.
#define uip_datalen()
The length of any incoming data that is currently available (if available) in the uip_appdata buffer.
Header file for the dynamic heap memory allocator.
Header file for the logging system.
void coap_dtls_conn_init(struct uip_udp_conn *udp_conn, struct process *host_process)
Registers, 1.
int coap_ep_get_dtls_state(const coap_endpoint_t *ep)
Check in what DTLS state the peer is in.
int coap_ep_dtls_write(const coap_endpoint_t *ep, const unsigned char *message, int len)
Encrypt app.
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.
void coap_dtls_init(void)
Initializes CoAP-MbedTLS global info.
void coap_ep_dtls_disconnect(const coap_endpoint_t *ep)
Disconnect a peer.
void coap_dtls_event_handler(void)
Handler for timer, and process-poll events.
int coap_ep_dtls_handle_message(const coap_endpoint_t *ep)
Handler for new DTLS messages.
coap_dtls_session_info_t * coap_ep_get_dtls_session_info(const coap_endpoint_t *ep)
Get session struct associated with CoAP endpoint.
DTLS (Mbed TLS implementation) support for CoAP.
The structure of a CoAP PKI certificate info.
The structure of a CoAP pre-shared key info.
Representation of a uIP UDP connection.