dtls: add DTLS prefix in front of header define

This define is there to prevent this actual header from being included
more than one time, but this should be unique in all header files used
in all code tinydtls is compiled with. Add a prefix to prevent
collisions with other code we do not control. This is one part to make
tinydtls work better in combination with libcoap.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
dtls: add dtls prefix to prng functions

This should prevent collisions with other code compiled with tinydtls
into one binary. The include from crypto.h was removed to prevent this
file from being included in user applications using tinydtls.

The functions and defines in prng.h got some changes to make the easier
to read. This is one part to make tinydtls work better in combination
with libcoap.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
debug: rename function dtls_alert() to dtls_send_alert()

This change was done to rename the alert() function to dtls_alert()
later, this functions is used to print alert messages.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
debug: add dtls prefix in front of debug functions

Do not use dsrv_log() directly and add a dtls prefix in front of all
the short logging functions. This should prevent name collisions with
other functions in other code. This should make it easier to remove all
debug outputs from tinydtls with a compile option.

This is one part to make tinydtls work better in combination with libcoap.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
debug: replace calls to dtls_dsrv_hexdump_log()

Do not use dtls_dsrv_hexdump_log() directly, but use a short logging
function. This should make it easier to remove all debug outputs from
tinydtls with a compile option.

This is one part to make tinydtls work better in combination with libcoap.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
debug: add DTLS prefix to log level

This will prevent name collisions with other code compiled with
tiyndtls.

This is one part to make tinydtls work better in combination with libcoap.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
test: remove PRINTF()

PRINTF() is already defined in debug.h

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
dtls: rename and move struct str

struct str is just used in the test client and not in the normal
tinydtls code, move it there. This also collides with some struct str
defined in the stdlib.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
dtls: fix DTLS_CLIENT and DTLS_SERVER comments

These were left over when DTLS_CLIENT and DTLS_SERVER where changed.

Thank you Andreas Bender for reporting this.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
dtls: use dtls_send() for sending a handshake message

This changes dtls_send() to dtls_send_multi() which is able to take an
array of buffers to send and not just one. This is now also used in
dtls_send_handshake_msg_hash() to send the handshake messages, because
dtls_send() also handles retransmission and handshake messages should
be retransmitted when needed.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
dtls: fix retransmission

dtls_prepare_record() was called with wrong arguments and the compile
warning was suppressed by the manual cast. node->data had to be
referenced one more time than it was done here. Now also an error
message is printed when we could not prepare this package for
retransmission.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
dtls: mark the dtls header structs packed

For some processor architectures like the MSP430X the compiler, in this
case gcc, optimizes the structs to align to full words length. This is
done because unaligned memory access is costly or not possible on some
architectures. GCC then adds some padding into structs which places
some members at different offsets and increases the size. This makes
the record header on the MSP430X 1 byte bigger for example, which is
wrong.

This patch adds the __packed__ attribute to the structs which are
representing a header defined in the DTLS RFC where the compiler should
not add any pads into the struct.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
dtls: do not reference pointer in record layer functions

These record layer functions will mostly be called by reference and not
by value, do not reference the input.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
dtls: use uint16_t for epoch

Using an int makes calculation much easier.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
dtls: replace rseq with uint64_t

Using an int makes calculation much easier.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
dtls: use uint16_t for mseq (handshake sequence number)

Using an int makes calculation much easier.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
dtls: remove inc_uint, it is not used any more

All the old callers are now using ints

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
dtls: add record header length to size check

This will prevent a buffer overflow.

Thank you Andreas Bender for reporting this.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>