40
40
41
41
#include " LWIPStack.h"
42
42
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
+
43
56
static void add_dns_addr_to_dns_list_index (const u8_t addr_type, const u8_t index)
44
57
{
45
58
#if LWIP_IPV6
@@ -152,7 +165,7 @@ nsapi_error_t LWIP::Interface::set_dhcp()
152
165
153
166
void LWIP::Interface::netif_link_irq (struct netif *netif)
154
167
{
155
- LWIP::Interface *interface = static_cast <LWIP::Interface *> (netif-> state );
168
+ LWIP::Interface *interface = our_if_from_netif (netif);
156
169
157
170
if (netif_is_link_up (&interface->netif )) {
158
171
nsapi_error_t dhcp_status = interface->set_dhcp ();
@@ -170,7 +183,7 @@ void LWIP::Interface::netif_link_irq(struct netif *netif)
170
183
171
184
void LWIP::Interface::netif_status_irq (struct netif *netif)
172
185
{
173
- LWIP::Interface *interface = static_cast <LWIP::Interface *> (netif-> state );
186
+ LWIP::Interface *interface = our_if_from_netif (netif);
174
187
175
188
if (netif_is_up (&interface->netif )) {
176
189
bool dns_addr_has_to_be_added = false ;
@@ -325,7 +338,8 @@ LWIP::Interface::Interface() :
325
338
has_both_addr = osSemaphoreNew (UINT16_MAX, 0 , &attr);
326
339
#endif
327
340
328
- netif.state = this ;
341
+ next = list;
342
+ list = this ;
329
343
}
330
344
331
345
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
385
399
}
386
400
387
401
/* 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)
389
403
{
390
- #if LWIP_PPP
391
- Interface *interface = new (nothrow) Interface ();
404
+ #if LWIP_PPP_API
405
+ Interface *interface = new (std:: nothrow) Interface ();
392
406
if (!interface) {
393
407
return NSAPI_ERROR_NO_MEMORY;
394
408
}
395
409
interface->hw = hw;
396
410
interface->ppp = true ;
397
411
398
- ret = ppp_lwip_if_init (hw, &interface->netif );
412
+ nsapi_error_t ret = ppp_lwip_if_init (hw, &interface->netif , stack );
399
413
if (ret != NSAPI_ERROR_OK) {
400
414
free (interface);
401
415
return ret;
402
416
}
403
417
404
- if (default_if)
418
+ if (default_if) {
405
419
netif_set_default (&interface->netif );
420
+ default_interface = interface;
421
+ }
406
422
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 );
409
425
410
426
*interface_out = interface;
411
427
428
+ return NSAPI_ERROR_OK;
412
429
#else
413
430
return NSAPI_ERROR_UNSUPPORTED;
414
- #endif // LWIP_PPP
431
+ #endif // LWIP_PPP_API
415
432
}
416
433
417
434
0 commit comments