Commit 6562b78c authored by Niclas Finne's avatar Niclas Finne
Browse files

Updated DTLS support for new logging system

parent b4d69603
......@@ -70,7 +70,6 @@
#ifdef WITH_DTLS
#include "tinydtls.h"
#include "dtls.h"
#include "dtls_debug.h"
#endif /* WITH_DTLS */
/* sanity check for configured values */
......@@ -346,7 +345,6 @@ coap_transport_init(void)
process_start(&coap_engine, NULL);
#ifdef WITH_DTLS
dtls_init();
dtls_set_log_level(8);
#if COAP_DTLS_KEYSTORE_CONF_WITH_SIMPLE
coap_keystore_simple_init();
......
......@@ -39,7 +39,10 @@
#ifndef DTLS_SUPPORT_CONF_H_
#define DTLS_SUPPORT_CONF_H_
#undef HAVE_VPRINTF
/* Use same log level as CoAP as default */
#define LOG_LEVEL_DTLS LOG_LEVEL_COAP
#define DTLS_LOG_CONF_PATH "coap-log.h"
#include "coap-endpoint.h"
......@@ -58,8 +61,6 @@ typedef struct {
typedef clock_time_t dtls_tick_t;
#define WITH_CONTIKI 1
#define HAVE_ASSERT_H 1
#endif /* DTLS_SUPPORT_CONF_H_ */
......@@ -41,8 +41,11 @@
#include <stdio.h>
#include <stdarg.h>
#define DEBUG DEBUG_FULLY
#include "dtls_debug.h"
/* Log configuration */
#define LOG_MODULE "dtls-support"
#define LOG_LEVEL LOG_LEVEL_DTLS
#include "dtls-log.h"
#include "coap-log.h"
static dtls_context_t the_dtls_context;
static dtls_cipher_context_t cipher_context;
......@@ -55,7 +58,7 @@ dtls_context_acquire(void)
return NULL;
}
lock_context = 1;
PRINTF("DS: Allocated context\n");
LOG_DBG("Allocated context\n");
return &the_dtls_context;
}
/*---------------------------------------------------------------------------*/
......@@ -140,13 +143,13 @@ dtls_session_equals(const session_t *a, const session_t *b)
coap_endpoint_t *e1 = (coap_endpoint_t *)a;
coap_endpoint_t *e2 = (coap_endpoint_t *)b;
#if DEBUG
printf(" **** EP:");
coap_endpoint_print(e1);
printf(" =?= ");
coap_endpoint_print(e2);
printf(" => %d\n", coap_endpoint_cmp(e1, e2));
#endif /* DEBUG */
if(LOG_DBG_ENABLED) {
LOG_DBG(" **** EP:");
LOG_DBG_COAP_EP(e1);
LOG_DBG_(" =?= ");
LOG_DBG_COAP_EP(e2);
LOG_DBG_(" => %d\n", coap_endpoint_cmp(e1, e2));
}
return coap_endpoint_cmp(e1, e2);
}
......@@ -170,90 +173,15 @@ dtls_session_print(const session_t *a)
coap_endpoint_print((const coap_endpoint_t *)a);
}
/*---------------------------------------------------------------------------*/
size_t
dsrv_print_addr(const session_t *addr, char *buf, size_t len)
{
if(len > 1) {
/* TODO print endpoint */
buf[0] = '[';
buf[1] = ']';
return 2;
}
return 0;
}
/*---------------------------------------------------------------------------*/
extern char *loglevels[];
static inline size_t
print_timestamp(log_t level)
{
dtls_tick_t now;
dtls_ticks(&now);
if(level <= DTLS_LOG_DEBUG) {
printf("%s ", loglevels[level]);
}
return printf("%5lu ", (unsigned long)now);
}
/*---------------------------------------------------------------------------*/
#ifdef HAVE_VPRINTF
void
dsrv_log(log_t level, char *format, ...)
{
va_list ap;
if(dtls_get_log_level() < level) {
return;
}
print_timestamp(level);
va_start(ap, format);
vprintf(format, ap);
va_end(ap);
}
#endif /* HAVE_VPRINTF */
/*---------------------------------------------------------------------------*/
void
dtls_dsrv_hexdump_log(log_t level, const char *name, const unsigned char *buf, size_t length, int extend)
dtls_session_log(const session_t *a)
{
int n = 0;
if(dtls_get_log_level() < level) {
return;
}
print_timestamp(level);
if(extend) {
printf("%s: (%zu bytes):\n", name, length);
while(length--) {
if(n % 16 == 0) {
printf("%08X ", n);
}
printf("%02X ", *buf++);
n++;
if(n % 8 == 0) {
if(n % 16 == 0) {
printf("\n");
} else {
printf(" ");
}
}
}
} else {
printf("%s: (%zu bytes): ", name, length);
while(length--) {
printf("%02X", *buf++);
}
}
printf("\n");
coap_endpoint_log((const coap_endpoint_t *)a);
}
/*---------------------------------------------------------------------------*/
void
dtls_support_init(void)
{
dtls_info("dtls_support_init.\n");
LOG_INFO("init\n");
}
/*---------------------------------------------------------------------------*/
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment