diff --git a/pkg/lwip/contrib/netdev/lwip_netdev.c b/pkg/lwip/contrib/netdev/lwip_netdev.c index 5f8e9cb7d5..dedc2a9319 100644 --- a/pkg/lwip/contrib/netdev/lwip_netdev.c +++ b/pkg/lwip/contrib/netdev/lwip_netdev.c @@ -23,6 +23,7 @@ #include "lwip/err.h" #include "lwip/ethip6.h" #include "lwip/netif.h" +#include "lwip/netifapi.h" #include "lwip/netif/netdev.h" #include "lwip/opt.h" #include "lwip/pbuf.h" @@ -81,6 +82,7 @@ err_t lwip_netdev_init(struct netif *netif) LWIP_ASSERT("netif != NULL", (netif != NULL)); LWIP_ASSERT("netif->state != NULL", (netif->state != NULL)); netdev_t *netdev; + netopt_enable_t enabled = 0; uint16_t dev_type; err_t res = ERR_OK; @@ -186,7 +188,11 @@ err_t lwip_netdev_init(struct netif *netif) return ERR_IF; /* device type not supported yet */ } netif->flags |= NETIF_FLAG_UP; - netif->flags |= NETIF_FLAG_LINK_UP; + /* Set link state up if link state is unsupported, or if it is up */ + if (netdev->driver->get(netdev, NETOPT_LINK, &enabled, sizeof(enabled)) <= 0 || + enabled) { + netif->flags |= NETIF_FLAG_LINK_UP; + } netif->flags |= NETIF_FLAG_IGMP; netif->flags |= NETIF_FLAG_MLD6; netdev->context = netif; @@ -290,12 +296,17 @@ static void _event_cb(netdev_t *dev, netdev_event_t event) } break; } -#ifdef MODULE_LWIP_DHCP_AUTO case NETDEV_EVENT_LINK_UP: { - dhcp_start(netif); + netifapi_netif_set_link_up(netif); +#ifdef MODULE_LWIP_DHCP_AUTO + netifapi_dhcp_start(netif); +#endif + break; + } + case NETDEV_EVENT_LINK_DOWN: { + netifapi_netif_set_link_down(netif); break; } -#endif default: break; } diff --git a/pkg/lwip/include/lwipopts.h b/pkg/lwip/include/lwipopts.h index a7711e536c..bf7749146d 100644 --- a/pkg/lwip/include/lwipopts.h +++ b/pkg/lwip/include/lwipopts.h @@ -56,6 +56,12 @@ extern "C" { #define LWIP_ETHERNET 0 #endif /* MODULE_LWIP_ETHERNET */ +#ifdef MODULE_LWIP_NETIF +#define LWIP_NETIF_API 1 +#else /* MODULE_LWIP_NETIF */ +#define LWIP_NETIF_API 0 +#endif /* MODULE_LWIP_NETIF */ + #ifdef MODULE_LWIP_IGMP #define LWIP_IGMP 1 #else /* MODULE_LWIP_IGMP */