From 8796293c5a6b2f72dafbee9f56c201434e7b8abb Mon Sep 17 00:00:00 2001 From: Erik Ekman Date: Mon, 11 Oct 2021 22:40:01 +0200 Subject: [PATCH 1/3] pkg/lwip: Implement getting option NETOPT_IPV6_ADDR --- pkg/lwip/contrib/_netif.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/pkg/lwip/contrib/_netif.c b/pkg/lwip/contrib/_netif.c index ec0d8b14aa..4ba0fbaa25 100644 --- a/pkg/lwip/contrib/_netif.c +++ b/pkg/lwip/contrib/_netif.c @@ -13,6 +13,7 @@ * * @file * @author Benjamin Valentin + * @author Erik Ekman */ #include "fmt.h" @@ -32,4 +33,37 @@ int netif_get_name(netif_t *iface, char *name) return res; } +int netif_get_opt(netif_t *iface, netopt_t opt, uint16_t context, + void *value, size_t max_len) +{ + (void)context; + lwip_netif_t *lwip_netif = (lwip_netif_t*) iface; + struct netif *netif = &lwip_netif->lwip_netif; + int res = -ENOTSUP; + switch (opt) { +#ifdef MODULE_LWIP_IPV6 + case NETOPT_IPV6_ADDR: { + assert(max_len >= sizeof(ipv6_addr_t)); + ipv6_addr_t *tgt = value; + + res = 0; + for (unsigned i = 0; + ((res + sizeof(ipv6_addr_t)) <= max_len) && + (i < LWIP_IPV6_NUM_ADDRESSES); + i++) { + if (netif_ip6_addr_state(netif, i) != IP6_ADDR_INVALID) { + memcpy(tgt, &(netif_ip6_addr(netif, i)->addr), sizeof(ipv6_addr_t)); + res += sizeof(ipv6_addr_t); + tgt++; + } + } + } + break; +#endif + default: + break; + } + return res; +} + /** @} */ From 4679d3d06eeb4007a0cb3cc48dc28d2ad213b758 Mon Sep 17 00:00:00 2001 From: Erik Ekman Date: Mon, 11 Oct 2021 22:53:11 +0200 Subject: [PATCH 2/3] pkg/lwip: Fall back to netdev when getting options Adds support for mac address, link state and more --- pkg/lwip/contrib/_netif.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/lwip/contrib/_netif.c b/pkg/lwip/contrib/_netif.c index 4ba0fbaa25..9aacbf6b6d 100644 --- a/pkg/lwip/contrib/_netif.c +++ b/pkg/lwip/contrib/_netif.c @@ -39,6 +39,7 @@ int netif_get_opt(netif_t *iface, netopt_t opt, uint16_t context, (void)context; lwip_netif_t *lwip_netif = (lwip_netif_t*) iface; struct netif *netif = &lwip_netif->lwip_netif; + struct netdev *dev = netif->state; int res = -ENOTSUP; switch (opt) { #ifdef MODULE_LWIP_IPV6 @@ -63,6 +64,10 @@ int netif_get_opt(netif_t *iface, netopt_t opt, uint16_t context, default: break; } + if (res == -ENOTSUP) { + // Ask underlying netdev + res = dev->driver->get(dev, opt, value, max_len); + } return res; } From 7b84b3a3f56e175accd577c66137647ce1cf16a2 Mon Sep 17 00:00:00 2001 From: Erik Ekman Date: Mon, 11 Oct 2021 23:01:46 +0200 Subject: [PATCH 3/3] pkg/lwip: Add empty netif_setopt To fully implement net/netif.h --- pkg/lwip/contrib/_netif.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pkg/lwip/contrib/_netif.c b/pkg/lwip/contrib/_netif.c index 9aacbf6b6d..2a30b36c38 100644 --- a/pkg/lwip/contrib/_netif.c +++ b/pkg/lwip/contrib/_netif.c @@ -71,4 +71,16 @@ int netif_get_opt(netif_t *iface, netopt_t opt, uint16_t context, return res; } +int netif_set_opt(netif_t *iface, netopt_t opt, uint16_t context, + void *value, size_t value_len) +{ + (void)iface; + (void)opt; + (void)context; + (void)value; + (void)value_len; + + return -ENOTSUP; +} + /** @} */