From 9fbab8f0f801779a98064c9cde8258438735b3d4 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Sun, 6 Jun 2021 00:20:13 +0200 Subject: [PATCH] drivers/slipdev: report NETOPT_ADDRESS to simulate l2 address A lot of things break if `GNRC_NETIF_FLAGS_HAS_L2ADDR` is not set. In order to handle router advertisements and auto-configureation, generate a faux l2 address based on the netdev ID. --- drivers/slipdev/Makefile.dep | 1 + drivers/slipdev/slipdev.c | 7 +++++++ makefiles/pseudomodules.inc.mk | 1 + sys/include/net/gnrc/netif/conf.h | 2 +- sys/net/gnrc/netif/gnrc_netif.c | 7 ++++++- sys/net/gnrc/netif/gnrc_netif_device_type.c | 5 +++++ sys/net/link_layer/l2util/l2util.c | 14 ++++++++++++++ 7 files changed, 35 insertions(+), 2 deletions(-) diff --git a/drivers/slipdev/Makefile.dep b/drivers/slipdev/Makefile.dep index 58336f4aa9..c428e3be6f 100644 --- a/drivers/slipdev/Makefile.dep +++ b/drivers/slipdev/Makefile.dep @@ -1,4 +1,5 @@ USEMODULE += tsrb +USEMODULE += eui_provider FEATURES_REQUIRED += periph_uart ifneq (,$(filter slipdev_stdio,$(USEMODULE))) diff --git a/drivers/slipdev/slipdev.c b/drivers/slipdev/slipdev.c index e02648f395..0e11fec7eb 100644 --- a/drivers/slipdev/slipdev.c +++ b/drivers/slipdev/slipdev.c @@ -21,6 +21,7 @@ #include "log.h" #include "slipdev.h" #include "slipdev_internal.h" +#include "net/eui_provider.h" /* XXX: BE CAREFUL ABOUT USING OUTPUT WITH MODULE_SLIPDEV_STDIO IN SENDING * FUNCTIONALITY! MIGHT CAUSE DEADLOCK!!!1!! */ @@ -231,6 +232,12 @@ static int _get(netdev_t *netdev, netopt_t opt, void *value, size_t max_len) assert(max_len == sizeof(uint16_t)); *((uint16_t *)value) = NETDEV_TYPE_SLIP; return sizeof(uint16_t); +#if IS_USED(MODULE_SLIPDEV_L2ADDR) + case NETOPT_ADDRESS_LONG: + assert(max_len == sizeof(eui64_t)); + netdev_eui64_get(netdev, value); + return sizeof(eui64_t); +#endif default: return -ENOTSUP; } diff --git a/makefiles/pseudomodules.inc.mk b/makefiles/pseudomodules.inc.mk index 3738999b53..645cb5b716 100644 --- a/makefiles/pseudomodules.inc.mk +++ b/makefiles/pseudomodules.inc.mk @@ -128,6 +128,7 @@ PSEUDOMODULES += sched_cb PSEUDOMODULES += semtech_loramac_rx PSEUDOMODULES += shell_hooks PSEUDOMODULES += slipdev_stdio +PSEUDOMODULES += slipdev_l2addr PSEUDOMODULES += sock PSEUDOMODULES += sock_async PSEUDOMODULES += sock_aux_local diff --git a/sys/include/net/gnrc/netif/conf.h b/sys/include/net/gnrc/netif/conf.h index 1ade168799..dc5556c77e 100644 --- a/sys/include/net/gnrc/netif/conf.h +++ b/sys/include/net/gnrc/netif/conf.h @@ -143,7 +143,7 @@ extern "C" { * address types are included */ #ifndef GNRC_NETIF_L2ADDR_MAXLEN -#if defined(MODULE_NETDEV_IEEE802154) || defined(MODULE_XBEE) +#if defined(MODULE_NETDEV_IEEE802154) || defined(MODULE_XBEE) || defined(MODULE_SLIPDEV_L2ADDR) #define GNRC_NETIF_L2ADDR_MAXLEN (IEEE802154_LONG_ADDRESS_LEN) #elif MODULE_NETDEV_ETH #define GNRC_NETIF_L2ADDR_MAXLEN (ETHERNET_ADDR_LEN) diff --git a/sys/net/gnrc/netif/gnrc_netif.c b/sys/net/gnrc/netif/gnrc_netif.c index 2f3e260029..22dab74ef8 100644 --- a/sys/net/gnrc/netif/gnrc_netif.c +++ b/sys/net/gnrc/netif/gnrc_netif.c @@ -1364,8 +1364,13 @@ static void _test_options(gnrc_netif_t *netif) assert(netif->flags & GNRC_NETIF_FLAGS_HAS_L2ADDR); assert(netif->l2addr_len >= 3U && netif->l2addr_len <= 5U); break; - case NETDEV_TYPE_LORA: /* LoRa doesn't provide L2 ADDR */ case NETDEV_TYPE_SLIP: +#if IS_USED(MODULE_SLIPDEV_L2ADDR) + assert(netif->flags & GNRC_NETIF_FLAGS_HAS_L2ADDR); + assert(8U == netif->l2addr_len); + break; +#endif /* IS_USED(MODULE_SLIPDEV_L2ADDR) */ + case NETDEV_TYPE_LORA: /* LoRa doesn't provide L2 ADDR */ assert(!(netif->flags & GNRC_NETIF_FLAGS_HAS_L2ADDR)); assert(0U == netif->l2addr_len); /* don't check MTU here for now since I'm not sure the current diff --git a/sys/net/gnrc/netif/gnrc_netif_device_type.c b/sys/net/gnrc/netif/gnrc_netif_device_type.c index 4d0e9ab842..3103bdf7bd 100644 --- a/sys/net/gnrc/netif/gnrc_netif_device_type.c +++ b/sys/net/gnrc/netif/gnrc_netif_device_type.c @@ -56,6 +56,11 @@ netopt_t gnrc_netif_get_l2addr_opt(const gnrc_netif_t *netif) } } break; +#endif +#if defined(MODULE_SLIPDEV_L2ADDR) + case NETDEV_TYPE_SLIP: + res = NETOPT_ADDRESS_LONG; + break; #endif default: break; diff --git a/sys/net/link_layer/l2util/l2util.c b/sys/net/link_layer/l2util/l2util.c index b4da4f62de..c1437d75ff 100644 --- a/sys/net/link_layer/l2util/l2util.c +++ b/sys/net/link_layer/l2util/l2util.c @@ -123,6 +123,11 @@ int l2util_eui64_from_addr(int dev_type, const uint8_t *addr, size_t addr_len, return -EINVAL; } #endif /* defined (MODULE_NRF24L01P_NG) */ +#if defined(MODULE_SLIPDEV_L2ADDR) + case NETDEV_TYPE_SLIP: + memcpy(eui64, addr, addr_len); + return sizeof(eui64_t); +#endif /* defined(MODULE_SLIPDEV_L2ADDR) */ default: (void)addr; (void)addr_len; @@ -230,6 +235,11 @@ int l2util_ipv6_iid_to_addr(int dev_type, const eui64_t *iid, uint8_t *addr) memcpy(&addr[addr_len - 3], &iid->uint8[5], 3); return addr_len; #endif /* defined(MODULE_NRF24L01P_NG) */ +#if defined(MODULE_SLIPDEV_L2ADDR) + case NETDEV_TYPE_SLIP: + memcpy(addr, iid, sizeof(eui64_t)); + return sizeof(eui64_t); +#endif /* defined(MODULE_SLIP) */ default: (void)iid; (void)addr; @@ -288,6 +298,10 @@ int l2util_ndp_addr_len_from_l2ao(int dev_type, (void)opt; return 5; /* maximum length */ #endif /* defined(MODULE_NRF24L01P_NG) */ +#if defined(MODULE_SLIPDEV_L2ADDR) + case NETDEV_TYPE_SLIP: + return sizeof(eui64_t); +#endif /* defined(MODULE_SLIPDEV_L2ADDR) */ default: (void)opt; #ifdef DEVELHELP