Skip to content

Commit 5d8570b

Browse files
authored
Merge pull request #7030 from kjbracey-arm/emac_ppp_fix
Fix lwIP PPP glue
2 parents 501a7b6 + cedbf72 commit 5d8570b

File tree

3 files changed

+34
-13
lines changed

3 files changed

+34
-13
lines changed

features/FEATURE_LWIP/lwip-interface/LWIPInterface.cpp

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,19 @@
4040

4141
#include "LWIPStack.h"
4242

43+
LWIP::Interface *LWIP::Interface::list;
44+
45+
LWIP::Interface *LWIP::Interface::our_if_from_netif(struct netif *netif)
46+
{
47+
for (Interface *interface = list; interface; interface = interface->next) {
48+
if (netif == &interface->netif) {
49+
return interface;
50+
}
51+
}
52+
53+
return NULL;
54+
}
55+
4356
static void add_dns_addr_to_dns_list_index(const u8_t addr_type, const u8_t index)
4457
{
4558
#if LWIP_IPV6
@@ -152,7 +165,7 @@ nsapi_error_t LWIP::Interface::set_dhcp()
152165

153166
void LWIP::Interface::netif_link_irq(struct netif *netif)
154167
{
155-
LWIP::Interface *interface = static_cast<LWIP::Interface *>(netif->state);
168+
LWIP::Interface *interface = our_if_from_netif(netif);
156169

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

171184
void LWIP::Interface::netif_status_irq(struct netif *netif)
172185
{
173-
LWIP::Interface *interface = static_cast<LWIP::Interface *>(netif->state);
186+
LWIP::Interface *interface = our_if_from_netif(netif);
174187

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

328-
netif.state = this;
341+
next = list;
342+
list = this;
329343
}
330344

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

387401
/* Internal API to preserve existing PPP functionality - revise to better match mbed_ipstak_add_ethernet_interface later */
388-
nsapi_error_t LWIP::_add_ppp_interface(void *hw, bool default_if, LWIP::Interface **interface_out)
402+
nsapi_error_t LWIP::_add_ppp_interface(void *hw, bool default_if, nsapi_ip_stack_t stack, LWIP::Interface **interface_out)
389403
{
390-
#if LWIP_PPP
391-
Interface *interface = new (nothrow) Interface();
404+
#if LWIP_PPP_API
405+
Interface *interface = new (std::nothrow) Interface();
392406
if (!interface) {
393407
return NSAPI_ERROR_NO_MEMORY;
394408
}
395409
interface->hw = hw;
396410
interface->ppp = true;
397411

398-
ret = ppp_lwip_if_init(hw, &interface->netif);
412+
nsapi_error_t ret = ppp_lwip_if_init(hw, &interface->netif, stack);
399413
if (ret != NSAPI_ERROR_OK) {
400414
free(interface);
401415
return ret;
402416
}
403417

404-
if (default_if)
418+
if (default_if) {
405419
netif_set_default(&interface->netif);
420+
default_interface = interface;
421+
}
406422

407-
netif_set_link_callback(&interface->netif, mbed_lwip_netif_link_irq);
408-
netif_set_status_callback(&interface->netif, mbed_lwip_netif_status_irq);
423+
netif_set_link_callback(&interface->netif, &LWIP::Interface::netif_link_irq);
424+
netif_set_status_callback(&interface->netif, &LWIP::Interface::netif_status_irq);
409425

410426
*interface_out = interface;
411427

428+
return NSAPI_ERROR_OK;
412429
#else
413430
return NSAPI_ERROR_UNSUPPORTED;
414-
#endif //LWIP_PPP
431+
#endif //LWIP_PPP_API
415432
}
416433

417434

features/FEATURE_LWIP/lwip-interface/LWIPStack.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ class LWIP : public OnboardNetworkStack, private mbed::NonCopyable<LWIP> {
118118
nsapi_error_t set_dhcp();
119119
static void netif_link_irq(struct netif *netif);
120120
static void netif_status_irq(struct netif *netif);
121+
static Interface *our_if_from_netif(struct netif *netif);
121122

122123
#if LWIP_ETHERNET
123124
static err_t emac_low_level_output(struct netif *netif, struct pbuf *p);
@@ -165,6 +166,8 @@ class LWIP : public OnboardNetworkStack, private mbed::NonCopyable<LWIP> {
165166
bool ppp;
166167
mbed::Callback<void(nsapi_event_t, intptr_t)> client_callback;
167168
struct netif netif;
169+
static Interface *list;
170+
Interface *next;
168171
LWIPMemoryManager *memory_manager;
169172
};
170173

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

201205
/** Get a domain name server from a list of servers to query
202206
*

features/FEATURE_LWIP/lwip-interface/ppp_lwip.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ nsapi_error_t nsapi_ppp_connect(FileHandle *stream, Callback<void(nsapi_event_t,
370370

371371
if (!my_interface) {
372372
LWIP &lwip = LWIP::get_instance();
373-
retcode = lwip._add_ppp_interface(stream, true, &my_interface);
373+
retcode = lwip._add_ppp_interface(stream, true, stack, &my_interface);
374374
if (retcode != NSAPI_ERROR_OK) {
375375
my_interface = NULL;
376376
return retcode;

0 commit comments

Comments
 (0)