mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-12-25 06:23:53 +01:00
pkg/lwip: add support for slipdev
This commit is contained in:
parent
6ec3f54b3c
commit
32d17f5313
@ -62,6 +62,15 @@ static err_t _eth_link_output(struct netif *netif, struct pbuf *p);
|
||||
#ifdef MODULE_LWIP_SIXLOWPAN
|
||||
static err_t _ieee802154_link_output(struct netif *netif, struct pbuf *p);
|
||||
#endif
|
||||
#ifdef MODULE_SLIPDEV
|
||||
static err_t _slip_link_output(struct netif *netif, struct pbuf *p);
|
||||
#if LWIP_IPV4
|
||||
static err_t slip_output4(struct netif *netif, struct pbuf *q, const ip4_addr_t *ipaddr);
|
||||
#endif
|
||||
#if LWIP_IPV6
|
||||
static err_t slip_output6(struct netif *netif, struct pbuf *q, const ip6_addr_t *ip6addr);
|
||||
#endif
|
||||
#endif
|
||||
static void _event_cb(netdev_t *dev, netdev_event_t event);
|
||||
static void *_event_loop(void *arg);
|
||||
|
||||
@ -183,6 +192,47 @@ err_t lwip_netdev_init(struct netif *netif)
|
||||
#endif /* LWIP_IPV6_AUTOCONFIG */
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#ifdef MODULE_SLIPDEV
|
||||
case NETDEV_TYPE_SLIP:
|
||||
netif->name[0] = 'S';
|
||||
netif->name[1] = 'L';
|
||||
|
||||
/* TODO: get from driver (currently not in netdev_eth) */
|
||||
netif->mtu = ETHERNET_DATA_LEN;
|
||||
netif->linkoutput = _slip_link_output;
|
||||
#if LWIP_IPV4
|
||||
netif->output = slip_output4;
|
||||
#endif
|
||||
#if LWIP_IPV6
|
||||
netif->output_ip6 = slip_output6;
|
||||
|
||||
if (IS_USED(MODULE_SLIPDEV_L2ADDR)) {
|
||||
netif->hwaddr_len = (u8_t)netdev->driver->get(netdev, NETOPT_ADDRESS_LONG,
|
||||
netif->hwaddr,
|
||||
sizeof(netif->hwaddr));
|
||||
if (netif->hwaddr_len > sizeof(netif->hwaddr)) {
|
||||
res = ERR_IF;
|
||||
goto free;
|
||||
}
|
||||
|
||||
/* netif_create_ip6_linklocal_address() does weird byte-swapping
|
||||
* with full IIDs, so let's do it ourselves */
|
||||
ip6_addr_t *addr = ip_2_ip6(&(netif->ip6_addr[0]));
|
||||
/* addr->addr is a uint32_t array */
|
||||
if (l2util_ipv6_iid_from_addr(dev_type,
|
||||
netif->hwaddr, netif->hwaddr_len,
|
||||
(eui64_t *)&addr->addr[2]) < 0) {
|
||||
res = ERR_IF;
|
||||
goto free;
|
||||
}
|
||||
ipv6_addr_set_link_local_prefix((ipv6_addr_t *)&addr->addr[0]);
|
||||
ip6_addr_assign_zone(addr, IP6_UNICAST, netif);
|
||||
/* Consider address valid. */
|
||||
netif->ip6_addr_state[0] = IP6_ADDR_PREFERRED;
|
||||
}
|
||||
#endif /* LWIP_IPV6 */
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
res = ERR_IF;
|
||||
@ -257,6 +307,38 @@ static err_t _ieee802154_link_output(struct netif *netif, struct pbuf *p)
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef MODULE_SLIPDEV
|
||||
#if LWIP_IPV4
|
||||
static err_t slip_output4(struct netif *netif, struct pbuf *q, const ip4_addr_t *ipaddr)
|
||||
{
|
||||
(void)ipaddr;
|
||||
return netif->linkoutput(netif, q);
|
||||
}
|
||||
#endif
|
||||
#if LWIP_IPV6
|
||||
static err_t slip_output6(struct netif *netif, struct pbuf *q, const ip6_addr_t *ip6addr)
|
||||
{
|
||||
(void)ip6addr;
|
||||
return netif->linkoutput(netif, q);
|
||||
}
|
||||
#endif
|
||||
|
||||
static err_t _slip_link_output(struct netif *netif, struct pbuf *p)
|
||||
{
|
||||
LWIP_ASSERT("p->next == NULL", p->next == NULL);
|
||||
netdev_t *netdev = netif->state;
|
||||
iolist_t pkt = {
|
||||
.iol_base = p->payload,
|
||||
.iol_len = p->len,
|
||||
};
|
||||
|
||||
lwip_netif_dev_acquire(netif);
|
||||
err_t res = (netdev->driver->send(netdev, &pkt) >= 0) ? ERR_OK : ERR_BUF;
|
||||
lwip_netif_dev_release(netif);
|
||||
return res;
|
||||
}
|
||||
#endif
|
||||
|
||||
static struct pbuf *_get_recv_pkt(netdev_t *dev)
|
||||
{
|
||||
lwip_netif_t *compat_netif = dev->context;
|
||||
|
||||
44
pkg/lwip/init_devs/auto_init_slipdev.c
Normal file
44
pkg/lwip/init_devs/auto_init_slipdev.c
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (C) 2023 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 sys_auto_init_lwip_netif
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Auto initialization for the SLIP module
|
||||
*
|
||||
* @author Benjamin Valentin <benjamin.valentin@ml-pa.com>
|
||||
*/
|
||||
|
||||
#include "slipdev.h"
|
||||
#include "slipdev_params.h"
|
||||
|
||||
#include "lwip_init_devs.h"
|
||||
|
||||
#define ENABLE_DEBUG 0
|
||||
#include "debug.h"
|
||||
|
||||
#define NETIF_SLIPDEV_NUMOF ARRAY_SIZE(slipdev_params)
|
||||
|
||||
static lwip_netif_t netif[NETIF_SLIPDEV_NUMOF];
|
||||
static slipdev_t slipdev_devs[NETIF_SLIPDEV_NUMOF];
|
||||
|
||||
static void auto_init_slipdev(void)
|
||||
{
|
||||
for (unsigned i = 0; i < NETIF_SLIPDEV_NUMOF; i++) {
|
||||
slipdev_setup(&slipdev_devs[i], &slipdev_params[i], i);
|
||||
if (lwip_add_ethernet(&netif[i], &slipdev_devs[i].netdev) == NULL) {
|
||||
DEBUG("Could not add slipdev device\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LWIP_INIT_ETH_NETIF(auto_init_slipdev);
|
||||
/** @} */
|
||||
Loading…
x
Reference in New Issue
Block a user