1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

Merge pull request #18069 from yarrick/lwip_netif_opt

pkg/lwip: Add basic version of netif_get/set_opt
This commit is contained in:
Martine Lenders 2022-05-10 01:36:16 +02:00 committed by GitHub
commit ad1c5fb391
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -13,6 +13,7 @@
*
* @file
* @author Benjamin Valentin <benjamin.valentin@ml-pa.com>
* @author Erik Ekman <eekman@google.com>
*/
#include "fmt.h"
@ -32,4 +33,54 @@ 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;
struct netdev *dev = netif->state;
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;
}
if (res == -ENOTSUP) {
// Ask underlying netdev
res = dev->driver->get(dev, opt, value, max_len);
}
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;
}
/** @} */