4040#include "lwip/dns.h"
4141#include "lwip/dhcp.h"
4242#include "netif/ethernet.h"
43+ #if LWIP_IPV6
44+ #include "lwip/ethip6.h"
45+ #endif
4346
4447// ETH DMA RX and TX descriptor definitions
4548#if defined(STM32H5 )
@@ -764,6 +767,10 @@ static err_t eth_netif_init(struct netif *netif) {
764767 netif -> output = etharp_output ;
765768 netif -> mtu = 1500 ;
766769 netif -> flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_ETHERNET | NETIF_FLAG_IGMP ;
770+ #if LWIP_IPV6
771+ netif -> output_ip6 = ethip6_output ;
772+ netif -> flags |= NETIF_FLAG_MLD6 ;
773+ #endif
767774 // Checksums only need to be checked on incoming frames, not computed on outgoing frames
768775 NETIF_SET_CHECKSUM_CTRL (netif ,
769776 NETIF_CHECKSUM_CHECK_IP
@@ -776,17 +783,22 @@ static err_t eth_netif_init(struct netif *netif) {
776783
777784static void eth_lwip_init (eth_t * self ) {
778785 ip_addr_t ipconfig [4 ];
779- IP4_ADDR (& ipconfig [0 ], 0 , 0 , 0 , 0 );
780- IP4_ADDR (& ipconfig [2 ], 192 , 168 , 0 , 1 );
781- IP4_ADDR (& ipconfig [1 ], 255 , 255 , 255 , 0 );
782- IP4_ADDR (& ipconfig [3 ], 8 , 8 , 8 , 8 );
786+ #if LWIP_IPV6
787+ for (int i = 0 ; i < 4 ; i ++ ) {
788+ IP_ADDR4 (& ipconfig [i ], 0 , 0 , 0 , 0 );
789+ }
790+ #endif
791+ IP_ADDR4 (& ipconfig [0 ], 0 , 0 , 0 , 0 );
792+ IP_ADDR4 (& ipconfig [2 ], 192 , 168 , 0 , 1 );
793+ IP_ADDR4 (& ipconfig [1 ], 255 , 255 , 255 , 0 );
794+ IP_ADDR4 (& ipconfig [3 ], 8 , 8 , 8 , 8 );
783795
784796 MICROPY_PY_LWIP_ENTER
785797
786798 struct netif * n = & self -> netif ;
787799 n -> name [0 ] = 'e' ;
788800 n -> name [1 ] = '0' ;
789- netif_add (n , & ipconfig [0 ], & ipconfig [1 ], & ipconfig [2 ], self , eth_netif_init , ethernet_input );
801+ netif_add (n , ip_2_ip4 ( & ipconfig [0 ]), ip_2_ip4 ( & ipconfig [1 ]), ip_2_ip4 ( & ipconfig [2 ]) , self , eth_netif_init , ethernet_input );
790802 netif_set_hostname (n , mod_network_hostname_data );
791803 netif_set_default (n );
792804 netif_set_up (n );
@@ -797,6 +809,10 @@ static void eth_lwip_init(eth_t *self) {
797809
798810 netif_set_link_up (n );
799811
812+ #if LWIP_IPV6
813+ netif_create_ip6_linklocal_address (n , 1 );
814+ #endif
815+
800816 MICROPY_PY_LWIP_EXIT
801817}
802818
@@ -805,7 +821,7 @@ static void eth_lwip_deinit(eth_t *self) {
805821 for (struct netif * netif = netif_list ; netif != NULL ; netif = netif -> next ) {
806822 if (netif == & self -> netif ) {
807823 netif_remove (netif );
808- netif -> ip_addr . addr = 0 ;
824+ netif_set_addr ( netif , IP4_ADDR_ANY4 , IP4_ADDR_ANY4 , IP4_ADDR_ANY4 ) ;
809825 netif -> flags = 0 ;
810826 }
811827 }
@@ -835,7 +851,7 @@ int eth_link_status(eth_t *self) {
835851 struct netif * netif = & self -> netif ;
836852 if ((netif -> flags & (NETIF_FLAG_UP | NETIF_FLAG_LINK_UP ))
837853 == (NETIF_FLAG_UP | NETIF_FLAG_LINK_UP )) {
838- if (netif -> ip_addr . addr != 0 ) {
854+ if (! ip4_addr_isany_val ( * netif_ip4_addr ( netif )) ) {
839855 return 3 ; // link up
840856 } else {
841857 return 2 ; // link no-ip;
0 commit comments