tinydtls  0.8.6
dtls_debug.h
Go to the documentation of this file.
1 /*******************************************************************************
2  *
3  * Copyright (c) 2011, 2012, 2013, 2014, 2015 Olaf Bergmann (TZI) and others.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
7  *
8  * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
9  * and the Eclipse Distribution License is available at
10  * http://www.eclipse.org/org/documents/edl-v10.php.
11  *
12  * Contributors:
13  * Olaf Bergmann - initial API and implementation
14  * Hauke Mehrtens - memory optimization, ECC integration
15  *
16  *******************************************************************************/
17 
18 #ifndef _DTLS_DEBUG_H_
19 #define _DTLS_DEBUG_H_
20 
21 #include <stdlib.h>
22 
23 #include "tinydtls.h"
24 #include "global.h"
25 #include "session.h"
26 
27 #ifdef WITH_CONTIKI
28 # ifndef DEBUG
29 # define DEBUG DEBUG_PRINT
30 # endif /* DEBUG */
31 #include "net/ip/uip-debug.h"
32 
33 #ifdef CONTIKI_TARGET_MBXXX
34 extern char __Stack_Init, _estack;
35 
36 static inline void check_stack(void) {
37  const char *p = &__Stack_Init;
38  while (p < &_estack && *p == 0x38) {
39  p++;
40  }
41 
42  PRINTF("Stack: %d bytes used (%d free)\n", &_estack - p, p - &__Stack_Init);
43 }
44 #else /* CONTIKI_TARGET_MBXXX */
45 static inline void check_stack(void) {
46 }
47 #endif /* CONTIKI_TARGET_MBXXX */
48 #else /* WITH_CONTKI */
49 #define PRINTF(...)
50 
51 static inline void check_stack(void) {
52 }
53 #endif
54 
58 } log_t;
59 
61 const char *dtls_package_name(void);
62 
64 const char *dtls_package_version(void);
65 
67 log_t dtls_get_log_level(void);
68 
70 void dtls_set_log_level(log_t level);
71 
76 #ifdef HAVE_VPRINTF
77 void dsrv_log(log_t level, char *format, ...);
78 #else
79 #define dsrv_log(level, format, ...) PRINTF(format, ##__VA_ARGS__)
80 #endif
81 
82 #ifndef NDEBUG
83 
84 void hexdump(const unsigned char *packet, int length);
85 
87 void dump(unsigned char *buf, size_t len);
88 
89 void dtls_dsrv_hexdump_log(log_t level, const char *name, const unsigned char *buf, size_t length, int extend);
90 
91 void dtls_dsrv_log_addr(log_t level, const char *name, const session_t *addr);
92 
93 #else /* NDEBUG */
94 
95 static inline void hexdump(const unsigned char *packet, int length)
96 {}
97 
98 static inline void dump(unsigned char *buf, size_t len)
99 {}
100 
101 static inline void
102 dtls_dsrv_hexdump_log(log_t level, const char *name, const unsigned char *buf, size_t length, int extend)
103 {}
104 
105 static inline void
106 dtls_dsrv_log_addr(log_t level, const char *name, const session_t *addr)
107 {}
108 
109 #endif /* NDEBUG */
110 
111 /* A set of convenience macros for common log levels. */
112 #define dtls_emerg(...) dsrv_log(DTLS_LOG_EMERG, __VA_ARGS__)
113 #define dtls_alert(...) dsrv_log(DTLS_LOG_ALERT, __VA_ARGS__)
114 #define dtls_crit(...) dsrv_log(DTLS_LOG_CRIT, __VA_ARGS__)
115 #define dtls_warn(...) dsrv_log(DTLS_LOG_WARN, __VA_ARGS__)
116 #define dtls_notice(...) dsrv_log(DTLS_LOG_NOTICE, __VA_ARGS__)
117 #define dtls_info(...) dsrv_log(DTLS_LOG_INFO, __VA_ARGS__)
118 #define dtls_debug(...) dsrv_log(DTLS_LOG_DEBUG, __VA_ARGS__)
119 #define dtls_debug_hexdump(name, buf, length) dtls_dsrv_hexdump_log(DTLS_LOG_DEBUG, name, buf, length, 1)
120 #define dtls_debug_dump(name, buf, length) dtls_dsrv_hexdump_log(DTLS_LOG_DEBUG, name, buf, length, 0)
121 
122 #endif /* _DTLS_DEBUG_H_ */
const char * dtls_package_version(void)
Definition: dtls_debug.c:48
public tinydtls API
void dsrv_log(log_t level, char *format,...)
Definition: dtls_debug.c:209
void dtls_set_log_level(log_t level)
Definition: dtls_debug.c:58
log_t dtls_get_log_level(void)
Definition: dtls_debug.c:53
static void check_stack(void)
Definition: dtls_debug.h:51
void dtls_dsrv_hexdump_log(log_t level, const char *name, const unsigned char *buf, size_t length, int extend)
Definition: dtls_debug.c:291
#define PRINTF(...)
Definition: dtls_debug.h:49
const char * dtls_package_name(void)
Definition: dtls_debug.c:44
void dtls_dsrv_log_addr(log_t level, const char *name, const session_t *addr)
Definition: dtls_debug.c:278
void hexdump(const unsigned char *packet, int length)
Definition: dtls_debug.c:253
log_t
Definition: dtls_debug.h:56
void dump(unsigned char *buf, size_t len)
Definition: dtls_debug.c:273