Skip to content

Fix lwIP PPP glue #7030

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 28 additions & 11 deletions features/FEATURE_LWIP/lwip-interface/LWIPInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,19 @@

#include "LWIPStack.h"

LWIP::Interface *LWIP::Interface::list;

LWIP::Interface *LWIP::Interface::our_if_from_netif(struct netif *netif)
{
for (Interface *interface = list; interface; interface = interface->next) {
if (netif == &interface->netif) {
return interface;
}
}

return NULL;
}

static void add_dns_addr_to_dns_list_index(const u8_t addr_type, const u8_t index)
{
#if LWIP_IPV6
Expand Down Expand Up @@ -152,7 +165,7 @@ nsapi_error_t LWIP::Interface::set_dhcp()

void LWIP::Interface::netif_link_irq(struct netif *netif)
{
LWIP::Interface *interface = static_cast<LWIP::Interface *>(netif->state);
LWIP::Interface *interface = our_if_from_netif(netif);

if (netif_is_link_up(&interface->netif)) {
nsapi_error_t dhcp_status = interface->set_dhcp();
Expand All @@ -170,7 +183,7 @@ void LWIP::Interface::netif_link_irq(struct netif *netif)

void LWIP::Interface::netif_status_irq(struct netif *netif)
{
LWIP::Interface *interface = static_cast<LWIP::Interface *>(netif->state);
LWIP::Interface *interface = our_if_from_netif(netif);

if (netif_is_up(&interface->netif)) {
bool dns_addr_has_to_be_added = false;
Expand Down Expand Up @@ -325,7 +338,8 @@ LWIP::Interface::Interface() :
has_both_addr = osSemaphoreNew(UINT16_MAX, 0, &attr);
#endif

netif.state = this;
next = list;
list = this;
}

nsapi_error_t LWIP::add_ethernet_interface(EMAC &emac, bool default_if, OnboardNetworkStack::Interface **interface_out)
Expand Down Expand Up @@ -385,33 +399,36 @@ nsapi_error_t LWIP::add_ethernet_interface(EMAC &emac, bool default_if, OnboardN
}

/* Internal API to preserve existing PPP functionality - revise to better match mbed_ipstak_add_ethernet_interface later */
nsapi_error_t LWIP::_add_ppp_interface(void *hw, bool default_if, LWIP::Interface **interface_out)
nsapi_error_t LWIP::_add_ppp_interface(void *hw, bool default_if, nsapi_ip_stack_t stack, LWIP::Interface **interface_out)
{
#if LWIP_PPP
Interface *interface = new (nothrow) Interface();
#if LWIP_PPP_API
Interface *interface = new (std::nothrow) Interface();
if (!interface) {
return NSAPI_ERROR_NO_MEMORY;
}
interface->hw = hw;
interface->ppp = true;

ret = ppp_lwip_if_init(hw, &interface->netif);
nsapi_error_t ret = ppp_lwip_if_init(hw, &interface->netif, stack);
if (ret != NSAPI_ERROR_OK) {
free(interface);
return ret;
}

if (default_if)
if (default_if) {
netif_set_default(&interface->netif);
default_interface = interface;
}

netif_set_link_callback(&interface->netif, mbed_lwip_netif_link_irq);
netif_set_status_callback(&interface->netif, mbed_lwip_netif_status_irq);
netif_set_link_callback(&interface->netif, &LWIP::Interface::netif_link_irq);
netif_set_status_callback(&interface->netif, &LWIP::Interface::netif_status_irq);

*interface_out = interface;

return NSAPI_ERROR_OK;
#else
return NSAPI_ERROR_UNSUPPORTED;
#endif //LWIP_PPP
#endif //LWIP_PPP_API
}


Expand Down
6 changes: 5 additions & 1 deletion features/FEATURE_LWIP/lwip-interface/LWIPStack.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ class LWIP : public OnboardNetworkStack, private mbed::NonCopyable<LWIP> {
nsapi_error_t set_dhcp();
static void netif_link_irq(struct netif *netif);
static void netif_status_irq(struct netif *netif);
static Interface *our_if_from_netif(struct netif *netif);

#if LWIP_ETHERNET
static err_t emac_low_level_output(struct netif *netif, struct pbuf *p);
Expand Down Expand Up @@ -165,6 +166,8 @@ class LWIP : public OnboardNetworkStack, private mbed::NonCopyable<LWIP> {
bool ppp;
mbed::Callback<void(nsapi_event_t, intptr_t)> client_callback;
struct netif netif;
static Interface *list;
Interface *next;
LWIPMemoryManager *memory_manager;
};

Expand Down Expand Up @@ -193,10 +196,11 @@ class LWIP : public OnboardNetworkStack, private mbed::NonCopyable<LWIP> {
*
* @param pcb PPP implementation specific user data; will be passed to PPP callbacks
* @param default_if true if the interface should be treated as the default one
* @param stack Allow manual selection of IPv4 and/or IPv6
* @param[out] interface_out set to interface handle that must be passed to subsequent mbed_stack calls
* @return NSAPI_ERROR_OK on success, or error code
*/
nsapi_error_t _add_ppp_interface(void *pcb, bool default_if, LWIP::Interface **interface_out);
nsapi_error_t _add_ppp_interface(void *pcb, bool default_if, nsapi_ip_stack_t stack, LWIP::Interface **interface_out);

/** Get a domain name server from a list of servers to query
*
Expand Down
2 changes: 1 addition & 1 deletion features/FEATURE_LWIP/lwip-interface/ppp_lwip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ nsapi_error_t nsapi_ppp_connect(FileHandle *stream, Callback<void(nsapi_event_t,

if (!my_interface) {
LWIP &lwip = LWIP::get_instance();
retcode = lwip._add_ppp_interface(stream, true, &my_interface);
retcode = lwip._add_ppp_interface(stream, true, stack, &my_interface);
if (retcode != NSAPI_ERROR_OK) {
my_interface = NULL;
return retcode;
Expand Down