Skip to content

Commit

Permalink
examples/dtls-echo: Cleaning and upgrade to sock
Browse files Browse the repository at this point in the history
Due to all the changes, this is basically a new version for this
example. The main benefit is the use of sock_udp but also the client
side is now more robust and reliable.
  • Loading branch information
rfuentess authored and Raul Fuentes committed Dec 15, 2017
1 parent 979fcdd commit 8696c5e
Show file tree
Hide file tree
Showing 5 changed files with 656 additions and 550 deletions.
65 changes: 34 additions & 31 deletions examples/dtls-echo/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ RIOTBASE ?= $(CURDIR)/../..

# TinyDTLS only has support for 32-bit architectures ATM
BOARD_BLACKLIST := arduino-duemilanove arduino-mega2560 arduino-uno chronos \
msb-430 msb-430h telosb waspmote-pro wsn430-v1_3b wsn430-v1_4 \
z1
mips-malta msb-430 msb-430h pic32-clicker pic32-wifire \
telosb waspmote-pro wsn430-v1_3b wsn430-v1_4 z1

BOARD_INSUFFICIENT_MEMORY := airfy-beacon b-l072z-lrwan1 bluepill calliope-mini \
cc2650-launchpad cc2650stk maple-mini \
Expand All @@ -24,51 +24,54 @@ BOARD_INSUFFICIENT_MEMORY := airfy-beacon b-l072z-lrwan1 bluepill calliope-mini
# NOTE: 6LoWPAN will be included if IEEE802.15.4 devices are present
USEMODULE += gnrc_netdev_default
USEMODULE += auto_init_gnrc_netif
# Specify the mandatory networking modules for IPv6 and sUDP
# Specify the mandatory networking modules for IPv6 and UDP
USEMODULE += gnrc_ipv6_router_default
USEMODULE += gnrc_udp
# Add a routing protocol
USEMODULE += gnrc_sock_udp
# Add a routing protocol (optional)
USEMODULE += gnrc_rpl
# This application dumps received packets to STDIO using the pktdump module
USEMODULE += gnrc_pktdump

# Additional networking modules that can be dropped if not needed
USEMODULE += gnrc_icmpv6_echo
# Add also the shell, some shell commands
USEMODULE += shell
USEMODULE += shell_commands
USEMODULE += ps

#TinyDTLs (crypto.c) made use of pthread
ifneq ($(BOARD),native)
USEMODULE += pthread
endif
USEPKG += tinydtls

# Comment this out to disable code in RIOT that does safety checking
# which is not needed in a production environment but helps in the
# development process:
CFLAGS += -DDEVELHELP
# Uncomment to redefine port. Default: DTLS port (20220).
#DTLS_PORT = 20220
#CFLAGS += -DDTLS_DEFAULT_PORT=$(DTLS_PORT)

# NOTE: Add the package for TinyDTLS
USEPKG += tinydtls
# NOTE: If not cipher suite is selected, DTLS_PSK is used by default.
# This adds support for TLS_PSK_WITH_AES_128_CCM_8
# CFLAGS += -DDTLS_PSK
# This adds support for TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8
# CFLAGS += -DDTLS_ECC

# NOTE: Those are taken from TinyDTLS. As the original Makefiles are
# overwitten is a good idea to preserve them here.
CFLAGS += -DDTLSv12 -DWITH_SHA256
# Define the log entry for tinydtls.
# Values: 0:EMERG (Default), 1:ALERT 2:CRIT 3:WARN 4:NOTICE 5:INFO 6:DEBUG
# TINYDTLS_LOG = 0

# NOTE: This adds support for TLS_PSK_WITH_AES_128_CCM_8
CFLAGS += -DDTLS_PSK
# Enable this line for setting tinyDTLS in debug mode.
# This overrides TINYDTLS_LOG to 6
# CFLAGS += -DTINYDTLS_DEBUG

# NOTE: This adds support for TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8
CFLAGS += -DDTLS_ECC
# dtls-client.c will generate a "CoAP get /riot/value" message instead of
# sending the user input (ASCII).
# dtls-server.c will display hexadecimal characters instead of ASCII.
#CFLAGS += -DCOAP_MSG_SPOOF

# NOTE: If enabled TinyDTLS' log are disabled (if memory is a issue).
# WARNING: Sometimes the log leads to Stack pointer corrupted.
# The reason is not identified yet.
# If said issue appears, enable this line.
#CFLAGS += -DNDEBUG
# FIXME: This is a temporary patch
# TinyDTLS <= 0.8.6 requires around 426 bytes in RAM.
CFLAGS += -DTHREAD_STACKSIZE_MAIN=\(3*THREAD_STACKSIZE_DEFAULT\)
# TINYDTLS_EXTRA_BUFF can be used for increasing the server stack memory.
# CFLAGS += -DTINYDTLS_EXTRA_BUFF=\(512\)

# NOTE: The configuration for socket or non-socket communication in TinyDTLS.
CFLAGS += -DWITH_RIOT_GNRC
# Comment this out to disable code in RIOT that does safety checking
# which is not needed in a production environment but helps in the
# development process:
CFLAGS += -DDEVELHELP

# Change this to 0 show compiler invocation lines by default:
QUIET ?= 1
Expand Down
97 changes: 46 additions & 51 deletions examples/dtls-echo/README.md
Original file line number Diff line number Diff line change
@@ -1,77 +1,72 @@
# dtls_echo
# dtls_echo example

This example shows you how to use TinyDTLS with the non-socket approach.
This example shows you how to use TinyDTLS with the non-socket approach.

This code is based on ../gnrc_networking and ../gnrc_tftp.
Is a good idea to read their README.md's for any doubt of how making the
testings.
## SOCK vs. Socket

## SOCKET vs. Non-socket (GNRC)

This example is configured to use the GNRC instead of sockets (over GNRC).
At the moment, the configuration must be done manually in the Makefile of
this project.
This example is configured to use socks instead of sockets (over GNRC). It's
possible to use sockets (again, over GNRC), which give a more similar approach
to the original Linux version of TinyDTLS. However, is not tested yet.

## Fast configuration (Between RIOT instances):

Preparing the logical interfaces:

./../../dist/tools/tapsetup/tapsetup --create 2
```
./../../dist/tools/tapsetup/tapsetup --create 3
```

For the server instance:

make all; PORT=tap1 make term
dtlss start
ifconfig
```
PORT=tap1 make all term
dtlss start
ifconfig
```

Do not forget to copy the IPv6 addresses!

For the client:

PORT=tap0 make term
dtlsc <IPv6's server address> "DATA TO DATA TO DATA!"
```
PORT=tap0 make term
dtlsc <IPv6's server address> "DATA to send under encrypted channel!"
```

# Testings
## Boards

Those boards that do not support the `../gnrc_networking` example are included
in the `BOARD_INSUFFICIENT_MEMORY`, plus the board `cc2650stk`.
Boards that do not support the `../gnrc_networking` example are included
in the `BOARD_INSUFFICIENT_MEMORY`, plus the board `cc2650stk`.

There are certain boards that are having issues with `crypto.c` and
`dtls_time.h` Which for now are in the the `BOARD_BLACKLIST`.

The boards that requires `periph_conf.h` are not tested.

Boards with problem type 1 (`crypto.c`):
z1
wsn430-v1_4
wsn430-v1_3b
waspmote-pro
msb-430h
msb-430
chronos
arduino-mega2560

Boards with problem type 2 (`dtls_time.h`):
cc2538dk
msbiot
telosb

Boards with problem type 3 (Redifinition):
saml21-xpro
samr21-xpro
arduino-uno
arduino-duemilanove

NOTE: Those on type 1 can be benefit of the following PR:
https://github.com/RIOT-OS/RIOT/issues/2360
However, there are still issues to fix.

NOTE: Those on type 2 can be fixed with the patch at
https://github.com/RIOT-OS/RIOT/pull/5974

## FIT-LAB

The code has been tested in the FIT-LAB with M3 motes.
However, erros can occurrs. Enabling the line `CFLAGS += -DNDEBUG` in
the `Makefile` reduces the risk.
The code has been tested in the FIT IOT-LAB tesbed with the remote
`iotlab-m3` and `iotlab-a8-m3` boards and with local `samr21-xpro` boards.

## Handling the static memory allocation

TinyDTLS for RIOT O.S. is using the `sys/memarray` module and therefore there
are certain limits. Said resources are defined in
`pkg/tinydtls/platform-specific/riot_boards.h`, but can be overwritten at
compilation time. Their default values are considered for having two DTLS
contexts (for purpose of DTLS renegotiation).

The resources handled by memarray are:
* `DTLS_CONTEXT_MAX` (default 2) The maximum number of DTLS context at the
same time.
* `DTLS_PEER_MAX` (default 1) The maximum number DTLS peers (i.e. sessions).
* `DTLS_HANDSHAKE_MAX` (default 1) The maximum number of concurrent DTLS handshakes.
* `DTLS_SECURITY_MAX` (the sum of the previous two) The maximum number of
concurrently used cipher keys.
* `DTLS_HASH_MAX` (Default: `3 * DTLS_PEER_MAX`) The maximum number of hash
functions that can be used in parallel.

## Handling retransmissions

By default, the number of transmissions of any DTLS record is settled to just
one. This can be handled by DTLS_DEFAULT_MAX_RETRANSMIT (defined in
`pkg/tinydtls/platform-specific/riot_boards.h`).
Loading

0 comments on commit 8696c5e

Please sign in to comment.