diff --git a/dist/tools/uhcpd/Makefile b/dist/tools/uhcpd/Makefile index 177b3434f1..2224017986 100644 --- a/dist/tools/uhcpd/Makefile +++ b/dist/tools/uhcpd/Makefile @@ -11,7 +11,7 @@ RIOT_INCLUDE=$(RIOTBASE)/sys/include SRCS:=$(UHCP_DIR)/uhcp.c uhcpd.c HDRS:=$(RIOT_INCLUDE)/net/uhcp.h bin/uhcpd: $(SRCS) $(HDRS) - $(CC) $(CFLAGS) $(CFLAGS_EXTRA) -I$(RIOT_INCLUDE) $(SRCS) -o $@ + $(CC) $(CFLAGS) $(CFLAGS_EXTRA) -I$(RIOT_INCLUDE) -I. $(SRCS) -o $@ clean: rm -f bin/uhcpd diff --git a/dist/tools/uhcpd/log.h b/dist/tools/uhcpd/log.h new file mode 100644 index 0000000000..2010dfc8d0 --- /dev/null +++ b/dist/tools/uhcpd/log.h @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2020 ML!PA Consulting GmbH + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup core_util + * @{ + * + * @file + * @brief System logging dummy header + * + * This header offers a bunch of "LOG_*" functions that just use printf, + * without honouring a verbosity level. + * + * This is a dummy header for the purpose of sharing code that uses the + * LOG_xxx() functions between RIOT and host utilities without having to + * manually include all dependencies of the 'real' log module. + * + * @author Benjamin Valentin + */ + +#ifndef LOG_H +#define LOG_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @name Logging convenience defines + * @{ + */ +#define LOG_ERROR(...) printf(__VA_ARGS__) +#define LOG_WARNING(...) printf(__VA_ARGS__) +#define LOG_INFO(...) printf(__VA_ARGS__) +#define LOG_DEBUG(...) printf(__VA_ARGS__) +/** @} */ + +#endif /* LOG_H */ +/** @} */ diff --git a/sys/net/application_layer/uhcp/uhcp.c b/sys/net/application_layer/uhcp/uhcp.c index 6f4ea7b162..3c5b554b49 100644 --- a/sys/net/application_layer/uhcp/uhcp.c +++ b/sys/net/application_layer/uhcp/uhcp.c @@ -6,29 +6,28 @@ * directory for more details. */ -#include - #include #include #include +#include "log.h" #include "net/uhcp.h" void uhcp_handle_udp(uint8_t *buf, size_t len, uint8_t *src, uint16_t port, uhcp_iface_t iface) { char addr_str[INET6_ADDRSTRLEN]; inet_ntop(AF_INET6, src, addr_str, INET6_ADDRSTRLEN); - printf("got packet from %s port %u\n", addr_str, (unsigned)port); + LOG_INFO("got packet from %s port %u\n", addr_str, (unsigned)port); if (len < sizeof(uhcp_req_t)) { - puts("error: packet too small."); + LOG_ERROR("error: packet too small.\n"); return; } uhcp_hdr_t *hdr = (uhcp_hdr_t *)buf; if (! (ntohl(hdr->uhcp_magic) == UHCP_MAGIC)) { - puts("error: wrong magic number."); + LOG_ERROR("error: wrong magic number.\n"); return; } @@ -37,14 +36,14 @@ void uhcp_handle_udp(uint8_t *buf, size_t len, uint8_t *src, uint16_t port, uhcp type = hdr->ver_type & 0xF; if (ver != UHCP_VER) { - puts("error: wrong protocol version."); + LOG_ERROR("error: wrong protocol version.\n"); } switch(type) { #ifdef UHCP_SERVER case UHCP_REQ: if (len < sizeof(uhcp_req_t)) { - puts("error: request too small\n"); + LOG_ERROR("error: request too small\n"); } else { uhcp_handle_req((uhcp_req_t*)hdr, src, port, iface); @@ -58,7 +57,7 @@ void uhcp_handle_udp(uint8_t *buf, size_t len, uint8_t *src, uint16_t port, uhcp if ((len < sizeof(uhcp_push_t)) || (len < (sizeof(uhcp_push_t) + (push->prefix_len >> 3))) ) { - puts("error: request too small\n"); + LOG_ERROR("error: request too small\n"); } else { uhcp_handle_push(push, src, port, iface); @@ -67,7 +66,7 @@ void uhcp_handle_udp(uint8_t *buf, size_t len, uint8_t *src, uint16_t port, uhcp } #endif default: - puts("error: unexpected type\n"); + LOG_ERROR("error: unexpected type\n"); } } @@ -87,7 +86,7 @@ void uhcp_handle_req(uhcp_req_t *req, uint8_t *src, uint16_t port, uhcp_iface_t int res = udp_sendto(packet, sizeof(packet), src, port, iface); if (res == -1) { - printf("uhcp_handle_req(): udp_sendto() res=%i\n", res); + LOG_ERROR("uhcp_handle_req(): udp_sendto() res=%i\n", res); } } #endif /* UHCP_SERVER */ @@ -105,7 +104,7 @@ void uhcp_handle_push(uhcp_push_t *req, uint8_t *src, uint16_t port, uhcp_iface_ inet_ntop(AF_INET6, prefix, prefix_str, INET6_ADDRSTRLEN); - printf("uhcp: push from %s:%u prefix=%s/%u\n", addr_str, (unsigned)port, prefix_str, req->prefix_len); + LOG_INFO("uhcp: push from %s:%u prefix=%s/%u\n", addr_str, (unsigned)port, prefix_str, req->prefix_len); uhcp_handle_prefix(prefix, req->prefix_len, 0xFFFF, src, iface); } #endif diff --git a/sys/net/application_layer/uhcp/uhcpc.c b/sys/net/application_layer/uhcp/uhcpc.c index a5b8d33fe2..3b287844f9 100644 --- a/sys/net/application_layer/uhcp/uhcpc.c +++ b/sys/net/application_layer/uhcp/uhcpc.c @@ -7,8 +7,8 @@ */ #include -#include +#include "log.h" #include "net/af.h" #include "net/sock/udp.h" #include "net/uhcp.h" @@ -39,14 +39,14 @@ void uhcp_client(uhcp_iface_t iface) /* create listening socket */ int res = sock_udp_create(&sock, &local, NULL, 0); if (res < 0) { - puts("uhcp_client(): cannot create listening socket"); + LOG_ERROR("uhcp_client(): cannot create listening socket\n"); return; } uint8_t buf[sizeof(uhcp_push_t) + 16]; while(1) { - puts("uhcp_client(): sending REQ..."); + LOG_INFO("uhcp_client(): sending REQ...\n"); sock_udp_send(&sock, &req, sizeof(uhcp_req_t), &req_target); res = sock_udp_recv(&sock, buf, sizeof(buf), 10U*US_PER_SEC, &remote); if (res > 0) { @@ -54,7 +54,7 @@ void uhcp_client(uhcp_iface_t iface) xtimer_sleep(60); } else { - puts("uhcp_client(): no reply received"); + LOG_ERROR("uhcp_client(): no reply received\n"); } } } diff --git a/sys/net/gnrc/application_layer/uhcpc/gnrc_uhcpc.c b/sys/net/gnrc/application_layer/uhcpc/gnrc_uhcpc.c index 007a12ea1c..c0bf12c90e 100644 --- a/sys/net/gnrc/application_layer/uhcpc/gnrc_uhcpc.c +++ b/sys/net/gnrc/application_layer/uhcpc/gnrc_uhcpc.c @@ -146,8 +146,8 @@ void uhcp_handle_prefix(uint8_t *prefix, uint8_t prefix_len, uint16_t lifetime, if ((_prefix_len == prefix_len) && (ipv6_addr_match_prefix(&_prefix, (ipv6_addr_t *)prefix) >= prefix_len)) { - LOG_WARNING("gnrc_uhcpc: uhcp_handle_prefix(): got same prefix " - "again\n"); + LOG_INFO("gnrc_uhcpc: uhcp_handle_prefix(): got same prefix " + "again\n"); #ifdef MODULE_GNRC_SIXLOWPAN_CTX if (gnrc_netif_is_6ln(gnrc_netif_get_by_pid(gnrc_wireless_interface))) { /* always update 6LoWPAN compression context so it does not time