From ee587244f46cb5bfd1456c25bd2422eab03df9ef Mon Sep 17 00:00:00 2001 From: Tomasz Bursztyka Date: Tue, 23 Feb 2016 17:11:44 +0100 Subject: [PATCH] net: ip: Enable Kconfig based debug options for the IP stack It will be possible to enable/disable debug messages from IP stack from make menuconfig, instead of modifying the relevant files to do so. Change-Id: I065f10bcc2bc3579081b2fcdb1c47e12d148e2f1 Signed-off-by: Tomasz Bursztyka --- net/ip/Kconfig | 1 + net/ip/Kconfig.debug | 97 +++++++++++++++++++++++++++++ net/ip/contiki/ip/uip-debug.h | 20 ++++-- net/ip/contiki/ipv4/uip.c | 4 +- net/ip/contiki/ipv4/uip_arp.c | 9 +-- net/ip/contiki/ipv6/uip-ds6-nbr.c | 4 +- net/ip/contiki/ipv6/uip-ds6-route.c | 5 +- net/ip/contiki/ipv6/uip-ds6.c | 4 +- net/ip/contiki/ipv6/uip-icmp6.c | 4 +- net/ip/contiki/ipv6/uip-nd6.c | 4 +- net/ip/contiki/ipv6/uip6.c | 4 +- 11 files changed, 138 insertions(+), 18 deletions(-) create mode 100644 net/ip/Kconfig.debug diff --git a/net/ip/Kconfig b/net/ip/Kconfig index 4f17ce69f08..734fdca10a0 100644 --- a/net/ip/Kconfig +++ b/net/ip/Kconfig @@ -435,5 +435,6 @@ config NET_15_4_LOOPBACK_NUM help Number of times loopback test runs, 0 means infinite. +source "net/ip/Kconfig.debug" endif diff --git a/net/ip/Kconfig.debug b/net/ip/Kconfig.debug new file mode 100644 index 00000000000..1e8a0c9a36d --- /dev/null +++ b/net/ip/Kconfig.debug @@ -0,0 +1,97 @@ +# Kconfig.debug - IP stack debugging configuration options + +# +# Copyright (c) 2016 Intel Corporation. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +menuconfig NETWORKING_IP_STACK_DEBUG + bool "IP stack Debuggging options" + default n + help + Enable the menu to select IP stack debugging part by part + +if NETWORKING_IP_STACK_DEBUG + +choice +prompt "General debug level" +help + Set the level of debugging you want. This will be generalized, + whatever the part you will be debugging. +default NETWORK_IP_STACK_DEBUG_PRINT +config NETWORK_IP_STACK_DEBUG_PRINT + bool "Print only debug messages" +config NETWORK_IP_STACK_DEBUG_ANNOTATE + bool "Print only annotations" +config NETWORK_IP_STACK_DEBUG_FULL + bool "Print both messages and annotations" +endchoice + +config NETWORK_IP_STACK_DEBUG_IPV6 + bool "Debug core IPv6" + depends on NETWORKING_WITH_IPV6 + default n + help + Enables core IPv6 code part to output debug messages + +config NETWORK_IP_STACK_DEBUG_IPV6_DS + bool "Debug IPv6 Data Structures" + depends on NETWORKING_WITH_IPV6 + default n + help + Enables IPv6 Data Structures code part to output debug messages + +config NETWORK_IP_STACK_DEBUG_IPV6_ICMPV6 + bool "Debug ICMPv6" + depends on NETWORKING_WITH_IPV6 + default n + help + Enables ICMPv6 code part to output debug messages + +config NETWORK_IP_STACK_DEBUG_IPV6_ND + bool "Debug IPv6 Neighbour Discovery" + depends on NETWORKING_WITH_IPV6 + default n + help + Enables IPv6 Neighbour Discovery code part to output debug messages + +config NETWORK_IP_STACK_DEBUG_IPV6_NBR_CACHE + bool "Debug IPv6 neighbour cache" + depends on NETWORKING_WITH_IPV6 + default n + help + Enables Neighbour Cache code part to output debug messages + +config NETWORK_IP_STACK_DEBUG_IPV6_ROUTE + bool "Debug IPv6 route" + depends on NETWORKING_WITH_IPV6 + default n + help + Enables IPv6 route code part to output debug messages + +config NETWORK_IP_STACK_DEBUG_IPV4 + bool "Debug core IPv4" + depends on NETWORKING_WITH_IPV4 + default n + help + Enables core IPv4 code part to output debug messages + +config NETWORK_IP_STACK_DEBUG_IPV4_ARP + bool "Debug IPv4 ARP" + depends on NETWORKING_WITH_IPV4 + default n + help + Enables core ARP code part to output debug messages + +endif diff --git a/net/ip/contiki/ip/uip-debug.h b/net/ip/contiki/ip/uip-debug.h index ba989255355..64af051059d 100644 --- a/net/ip/contiki/ip/uip-debug.h +++ b/net/ip/contiki/ip/uip-debug.h @@ -61,6 +61,18 @@ void uip_debug_hex_dump(const unsigned char *buffer, int len); #define DEBUG_ANNOTATE 2 #define DEBUG_FULL DEBUG_ANNOTATE | DEBUG_PRINT +#if (DEBUG == 1) +#if defined(CONFIG_NETWORK_IP_STACK_DEBUG_PRINT) +#define _DEBUG_ DEBUG_PRINT +#elif defined(CONFIG_NETWORK_IP_STACK_DEBUG_ANNOTATE) +#define _DEBUG_ DEBUG_ANNOTATE +#elif defined(CONFIG_NETWORK_IP_STACK_DEBUG_FULL) +#define _DEBUG_ DEBUG_FULL +#else +#define _DEBUG_ DEBUG_NONE +#endif +#endif + /* PRINTA will always print if the debug routines are called directly */ #ifdef __AVR__ #include @@ -69,7 +81,7 @@ void uip_debug_hex_dump(const unsigned char *buffer, int len); #define PRINTA(...) PRINT(__VA_ARGS__) #endif -#if (DEBUG) & DEBUG_ANNOTATE +#if (_DEBUG_) & DEBUG_ANNOTATE #ifdef __AVR__ #define ANNOTATE(FORMAT,args...) printf_P(PSTR(FORMAT),##args) #else @@ -77,9 +89,9 @@ void uip_debug_hex_dump(const unsigned char *buffer, int len); #endif #else #define ANNOTATE(...) -#endif /* (DEBUG) & DEBUG_ANNOTATE */ +#endif /* (_DEBUG_) & DEBUG_ANNOTATE */ -#if (DEBUG) & DEBUG_PRINT +#if (_DEBUG_) & DEBUG_PRINT #ifdef __AVR__ #define PRINTF(FORMAT,args...) printf_P(PSTR(FORMAT),##args) #else @@ -91,6 +103,6 @@ void uip_debug_hex_dump(const unsigned char *buffer, int len); #define PRINTF(...) #define PRINT6ADDR(addr) #define PRINTLLADDR(lladdr) -#endif /* (DEBUG) & DEBUG_PRINT */ +#endif /* (_DEBUG_) & DEBUG_PRINT */ #endif diff --git a/net/ip/contiki/ipv4/uip.c b/net/ip/contiki/ipv4/uip.c index dcfeba9ffe7..fdb02858c36 100644 --- a/net/ip/contiki/ipv4/uip.c +++ b/net/ip/contiki/ipv4/uip.c @@ -76,7 +76,9 @@ #include "contiki/ipv4/uip-neighbor.h" -#define DEBUG DEBUG_NONE +#ifdef CONFIG_NETWORK_IP_STACK_DEBUG_IPV4 +#define DEBUG 1 +#endif #include "contiki/ip/uip-debug.h" #include diff --git a/net/ip/contiki/ipv4/uip_arp.c b/net/ip/contiki/ipv4/uip_arp.c index f24d75a6e49..097d4ee4107 100644 --- a/net/ip/contiki/ipv4/uip_arp.c +++ b/net/ip/contiki/ipv4/uip_arp.c @@ -113,13 +113,10 @@ static uint8_t tmpage; #define BUF(buf) ((struct arp_hdr *)&uip_buf(buf)[0]) #define IPBUF(buf) ((struct ethip_hdr *)&uip_buf(buf)[0]) -#define DEBUG 0 -#if DEBUG -#include -#define PRINTF(...) printf(__VA_ARGS__) -#else -#define PRINTF(...) +#ifdef CONFIG_NETWORK_IP_STACK_DEBUG_IPV4_ARP +#define DEBUG 1 #endif +#include "contiki/ip/uip-debug.h" /*-----------------------------------------------------------------------------------*/ /** diff --git a/net/ip/contiki/ipv6/uip-ds6-nbr.c b/net/ip/contiki/ipv6/uip-ds6-nbr.c index 6007bc18456..411ee3fa712 100644 --- a/net/ip/contiki/ipv6/uip-ds6-nbr.c +++ b/net/ip/contiki/ipv6/uip-ds6-nbr.c @@ -51,7 +51,9 @@ #include "contiki/packetbuf.h" #include "contiki/ipv6/uip-ds6-nbr.h" -#define DEBUG DEBUG_NONE +#ifdef CONFIG_NETWORK_IP_STACK_DEBUG_IPV6_NBR_CACHE +#define DEBUG 1 +#endif #include "contiki/ip/uip-debug.h" #ifdef UIP_CONF_DS6_NEIGHBOR_STATE_CHANGED diff --git a/net/ip/contiki/ipv6/uip-ds6-route.c b/net/ip/contiki/ipv6/uip-ds6-route.c index 0b68d20ea7f..6b78e8d2267 100644 --- a/net/ip/contiki/ipv6/uip-ds6-route.c +++ b/net/ip/contiki/ipv6/uip-ds6-route.c @@ -72,8 +72,9 @@ LIST(notificationlist); static int num_routes = 0; -#undef DEBUG -#define DEBUG DEBUG_NONE +#ifdef CONFIG_NETWORK_IP_STACK_DEBUG_IPV6_ROUTE +#define DEBUG 1 +#endif #include "contiki/ip/uip-debug.h" static void rm_routelist_callback(nbr_table_item_t *ptr); diff --git a/net/ip/contiki/ipv6/uip-ds6.c b/net/ip/contiki/ipv6/uip-ds6.c index 0a0e86281ce..417c47ebaf3 100644 --- a/net/ip/contiki/ipv6/uip-ds6.c +++ b/net/ip/contiki/ipv6/uip-ds6.c @@ -50,7 +50,9 @@ #include "contiki/ipv6/uip-ds6.h" #include "contiki/ip/uip-packetqueue.h" -#define DEBUG DEBUG_NONE +#ifdef CONFIG_NETWORK_IP_STACK_DEBUG_IPV6_DS +#define DEBUG 1 +#endif #include "contiki/ip/uip-debug.h" struct etimer uip_ds6_timer_periodic; /** \brief Timer for maintenance of data structures */ diff --git a/net/ip/contiki/ipv6/uip-icmp6.c b/net/ip/contiki/ipv6/uip-icmp6.c index d12899a9811..2ac5eb1aa46 100644 --- a/net/ip/contiki/ipv6/uip-icmp6.c +++ b/net/ip/contiki/ipv6/uip-icmp6.c @@ -49,7 +49,9 @@ #include "contiki/ipv6/uip-icmp6.h" #include "contiki-default-conf.h" -#define DEBUG DEBUG_NONE +#ifdef CONFIG_NETWORK_IP_STACK_DEBUG_IPV6_ICMPV6 +#define DEBUG 1 +#endif #include "contiki/ip/uip-debug.h" #define UIP_IP_BUF(buf) ((struct uip_ip_hdr *)&uip_buf(buf)[UIP_LLH_LEN]) diff --git a/net/ip/contiki/ipv6/uip-nd6.c b/net/ip/contiki/ipv6/uip-nd6.c index 7b51e5a4baf..e8fc1de86d3 100644 --- a/net/ip/contiki/ipv6/uip-nd6.c +++ b/net/ip/contiki/ipv6/uip-nd6.c @@ -78,7 +78,9 @@ #include "lib/random.h" /*------------------------------------------------------------------*/ -#define DEBUG 0 +#ifdef CONFIG_NETWORK_IP_STACK_DEBUG_IPV6_ND +#define DEBUG 1 +#endif #include "contiki/ip/uip-debug.h" #if UIP_LOGGING diff --git a/net/ip/contiki/ipv6/uip6.c b/net/ip/contiki/ipv6/uip6.c index 9224951ef5b..6d48ecd2422 100644 --- a/net/ip/contiki/ipv6/uip6.c +++ b/net/ip/contiki/ipv6/uip6.c @@ -86,7 +86,9 @@ /* For Debug, logging, statistics */ /*---------------------------------------------------------------------------*/ -#define DEBUG DEBUG_NONE +#ifdef CONFIG_NETWORK_IP_STACK_DEBUG_IPV6 +#define DEBUG 1 +#endif #include "contiki/ip/uip-debug.h" #if UIP_CONF_IPV6_RPL