36
36
#include " lwip/dns.h"
37
37
#include " lwip/udp.h"
38
38
39
- #include " ppp_lwip.h"
40
-
41
39
#include " LWIPStack.h"
42
40
43
41
LWIP::Interface *LWIP::Interface::list;
@@ -352,7 +350,7 @@ char *LWIP::Interface::get_gateway(char *buf, nsapi_size_t buflen)
352
350
LWIP::Interface::Interface () :
353
351
hw(NULL ), has_addr_state(0 ),
354
352
connected(NSAPI_STATUS_DISCONNECTED),
355
- dhcp_started(false ), dhcp_has_to_be_set(false ), blocking(true ), ppp (false )
353
+ dhcp_started(false ), dhcp_has_to_be_set(false ), blocking(true ), ppp_enabled (false )
356
354
{
357
355
memset (&netif, 0 , sizeof netif);
358
356
@@ -395,7 +393,7 @@ nsapi_error_t LWIP::add_ethernet_interface(EMAC &emac, bool default_if, OnboardN
395
393
}
396
394
interface->emac = &emac;
397
395
interface->memory_manager = &memory_manager;
398
- interface->ppp = false ;
396
+ interface->ppp_enabled = false ;
399
397
400
398
#if (MBED_MAC_ADDRESS_SUM != MBED_MAC_ADDR_INTERFACE)
401
399
netif->interface .hwaddr [0 ] = MBED_MAC_ADDR_0;
@@ -452,7 +450,7 @@ nsapi_error_t LWIP::add_l3ip_interface(L3IP &l3ip, bool default_if, OnboardNetwo
452
450
}
453
451
interface->l3ip = &l3ip;
454
452
interface->memory_manager = &memory_manager;
455
- interface->ppp = false ;
453
+ interface->ppp_enabled = false ;
456
454
457
455
458
456
@@ -462,7 +460,7 @@ nsapi_error_t LWIP::add_l3ip_interface(L3IP &l3ip, bool default_if, OnboardNetwo
462
460
#if LWIP_IPV4
463
461
0 , 0 , 0 ,
464
462
#endif
465
- interface, &LWIP::Interface::l3ip_if_init, tcpip_input )) {
463
+ interface, &LWIP::Interface::l3ip_if_init, ip_input )) {
466
464
return NSAPI_ERROR_DEVICE_ERROR;
467
465
}
468
466
@@ -521,21 +519,27 @@ nsapi_error_t LWIP::remove_l3ip_interface(OnboardNetworkStack::Interface **inter
521
519
522
520
#endif // LWIP_L3IP
523
521
}
524
- /* Internal API to preserve existing PPP functionality - revise to better match mbed_ipstak_add_ethernet_interface later */
525
- nsapi_error_t LWIP::_add_ppp_interface (void *hw, bool default_if, nsapi_ip_stack_t stack, LWIP::Interface **interface_out)
522
+
523
+
524
+ nsapi_error_t LWIP::add_ppp_interface (PPP &ppp, bool default_if, OnboardNetworkStack::Interface **interface_out)
526
525
{
527
- #if LWIP_PPP_API
526
+ #if PPP_SUPPORT
528
527
Interface *interface = new (std::nothrow) Interface ();
529
528
if (!interface) {
530
529
return NSAPI_ERROR_NO_MEMORY;
531
530
}
532
- interface->hw = hw;
533
- interface->ppp = true ;
531
+ interface->ppp = &ppp;
532
+ interface->memory_manager = &memory_manager;
533
+ interface->ppp_enabled = true ;
534
534
535
- nsapi_error_t ret = ppp_lwip_if_init (hw, &interface->netif , stack);
536
- if (ret != NSAPI_ERROR_OK) {
537
- free (interface);
538
- return ret;
535
+ // interface->netif.hwaddr_len = 0; should we set?
536
+
537
+ if (!netif_add (&interface->netif ,
538
+ #if LWIP_IPV4
539
+ 0 , 0 , 0 ,
540
+ #endif
541
+ interface, &LWIP::Interface::ppp_if_init, tcpip_input)) {
542
+ return NSAPI_ERROR_DEVICE_ERROR;
539
543
}
540
544
541
545
if (default_if) {
@@ -548,11 +552,62 @@ nsapi_error_t LWIP::_add_ppp_interface(void *hw, bool default_if, nsapi_ip_stack
548
552
549
553
*interface_out = interface;
550
554
555
+ // lwip_add_random_seed(seed); to do?
556
+
557
+ return NSAPI_ERROR_OK;
558
+
559
+ #else
560
+ return NSAPI_ERROR_UNSUPPORTED;
561
+
562
+ #endif // PPP_SUPPORT
563
+ }
564
+
565
+ nsapi_error_t LWIP::remove_ppp_interface (OnboardNetworkStack::Interface **interface_out)
566
+ {
567
+ #if PPP_SUPPORT
568
+ if ((interface_out != NULL ) && (*interface_out != NULL )) {
569
+
570
+ Interface *lwip = static_cast <Interface *>(*interface_out);
571
+ Interface *node = lwip->list ;
572
+
573
+ if (lwip->list != NULL ) {
574
+ if (lwip->list == lwip) {
575
+ // Power down PPP service
576
+ lwip->ppp ->power_down ();
577
+ if (netif_is_link_up (&lwip->netif )) {
578
+ // Wait PPP service to report link down
579
+ osSemaphoreAcquire (lwip->unlinked , osWaitForever);
580
+ }
581
+ netif_remove (&node->netif );
582
+ lwip->list = lwip->list ->next ;
583
+ delete node;
584
+ } else {
585
+ while (node->next != NULL && node->next != lwip) {
586
+ node = node->next ;
587
+ }
588
+ if (node->next != NULL && node->next == lwip) {
589
+ Interface *remove = node->next ;
590
+ // Power down PPP service
591
+ remove->ppp ->power_down ();
592
+ if (netif_is_link_up (&lwip->netif )) {
593
+ // Wait PPP service to report link down
594
+ osSemaphoreAcquire (lwip->unlinked , osWaitForever);
595
+ }
596
+ netif_remove (&remove->netif );
597
+ node->next = node->next ->next ;
598
+ delete remove;
599
+ }
600
+ }
601
+ }
602
+ }
603
+
551
604
return NSAPI_ERROR_OK;
552
605
#else
553
606
return NSAPI_ERROR_UNSUPPORTED;
554
- #endif // LWIP_PPP_API
607
+
608
+ #endif // PPP_SUPPORT
555
609
}
610
+
556
611
void LWIP::set_default_interface (OnboardNetworkStack::Interface *interface)
557
612
{
558
613
if (interface) {
@@ -609,7 +664,7 @@ nsapi_error_t LWIP::Interface::bringup(bool dhcp, const char *ip, const char *ne
609
664
610
665
#if LWIP_IPV4
611
666
if (stack != IPV6_STACK) {
612
- if (!dhcp && !ppp ) {
667
+ if (!dhcp && !ppp_enabled ) {
613
668
ip4_addr_t ip_addr;
614
669
ip4_addr_t netmask_addr;
615
670
ip4_addr_t gw_addr;
@@ -629,23 +684,10 @@ nsapi_error_t LWIP::Interface::bringup(bool dhcp, const char *ip, const char *ne
629
684
client_callback (NSAPI_EVENT_CONNECTION_STATUS_CHANGE, NSAPI_STATUS_CONNECTING);
630
685
}
631
686
632
- if (ppp) {
633
- err_t err = ppp_lwip_connect (hw);
634
- if (err) {
635
- connected = NSAPI_STATUS_DISCONNECTED;
636
- if (client_callback) {
637
- client_callback (NSAPI_EVENT_CONNECTION_STATUS_CHANGE, NSAPI_STATUS_DISCONNECTED);
638
- }
639
- return err_remap (err);
640
- }
641
- }
642
687
643
688
if (!netif_is_link_up (&netif)) {
644
689
if (blocking) {
645
690
if (osSemaphoreAcquire (linked, LINK_TIMEOUT * 1000 ) != osOK) {
646
- if (ppp) {
647
- (void ) ppp_lwip_disconnect (hw);
648
- }
649
691
return NSAPI_ERROR_NO_CONNECTION;
650
692
}
651
693
}
@@ -665,9 +707,6 @@ nsapi_error_t LWIP::Interface::bringup(bool dhcp, const char *ip, const char *ne
665
707
// If doesn't have address
666
708
if (!LWIP::get_ip_addr (true , &netif)) {
667
709
if (osSemaphoreAcquire (has_any_addr, DHCP_TIMEOUT * 1000 ) != osOK) {
668
- if (ppp) {
669
- (void ) ppp_lwip_disconnect (hw);
670
- }
671
710
return NSAPI_ERROR_DHCP_FAILURE;
672
711
}
673
712
}
@@ -713,21 +752,7 @@ nsapi_error_t LWIP::Interface::bringdown()
713
752
}
714
753
#endif
715
754
716
- if (ppp) {
717
- /* this is a blocking call, returns when PPP is properly closed */
718
- err_t err = ppp_lwip_disconnect (hw);
719
- if (err) {
720
- return err_remap (err);
721
- }
722
- MBED_ASSERT (!netif_is_link_up (&netif));
723
- /* if (netif_is_link_up(&netif)) {
724
- if (sys_arch_sem_wait(&unlinked, 15000) == SYS_ARCH_TIMEOUT) {
725
- return NSAPI_ERROR_DEVICE_ERROR;
726
- }
727
- }*/
728
- } else {
729
- netif_set_down (&netif);
730
- }
755
+ netif_set_down (&netif);
731
756
732
757
#if LWIP_IPV6
733
758
mbed_lwip_clear_ipv6_addresses (&netif);
0 commit comments