Skip to content

Commit 2f5df81

Browse files
committed
mimxrt: Add IPv6 support to ethernet driver.
Add IPv6 support by: - Including lwip/ethip6.h header when LWIP_IPV6 is enabled - Setting output_ip6 to ethip6_output for IPv6 packet handling - Adding NETIF_FLAG_MLD6 flag for IPv6 multicast support - Creating IPv6 link-local address after interface initialization - Remove redundant LWIP_IPV6 definition (now in common config) Signed-off-by: Andrew Leech <[email protected]>
1 parent b4dab66 commit 2f5df81

File tree

3 files changed

+30
-14
lines changed

3 files changed

+30
-14
lines changed

ports/mimxrt/eth.c

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@
5252
#include "lwip/dns.h"
5353
#include "lwip/dhcp.h"
5454
#include "netif/ethernet.h"
55+
#if LWIP_IPV6
56+
#include "lwip/ethip6.h"
57+
#endif
5558

5659
#include "ticks.h"
5760

@@ -541,6 +544,10 @@ static err_t eth_netif_init(struct netif *netif) {
541544
netif->output = etharp_output;
542545
netif->mtu = 1500;
543546
netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_ETHERNET | NETIF_FLAG_IGMP;
547+
#if LWIP_IPV6
548+
netif->output_ip6 = ethip6_output;
549+
netif->flags |= NETIF_FLAG_MLD6;
550+
#endif
544551
// Checksums only need to be checked on incoming frames, not computed on outgoing frames
545552
NETIF_SET_CHECKSUM_CTRL(netif,
546553
NETIF_CHECKSUM_CHECK_IP
@@ -556,25 +563,31 @@ static void eth_lwip_init(eth_t *self) {
556563
struct netif *n = &self->netif;
557564
ip_addr_t ipconfig[4];
558565

566+
#if LWIP_IPV6
567+
for (int i = 0; i < 4; i++) {
568+
IP_ADDR4(&ipconfig[i], 0, 0, 0, 0);
569+
}
570+
#endif
571+
559572
self->netif.hwaddr_len = 6;
560573
if (self == &eth_instance0) {
561574
memcpy(self->netif.hwaddr, hw_addr, 6);
562-
IP4_ADDR(&ipconfig[0], 192, 168, 0, 2);
575+
IP_ADDR4(&ipconfig[0], 192, 168, 0, 2);
563576
#if defined ENET_DUAL_PORT
564577
} else {
565578
memcpy(self->netif.hwaddr, hw_addr_1, 6);
566-
IP4_ADDR(&ipconfig[0], 192, 168, 0, 3);
579+
IP_ADDR4(&ipconfig[0], 192, 168, 0, 3);
567580
#endif
568581
}
569-
IP4_ADDR(&ipconfig[1], 255, 255, 255, 0);
570-
IP4_ADDR(&ipconfig[2], 192, 168, 0, 1);
571-
IP4_ADDR(&ipconfig[3], 8, 8, 8, 8);
582+
IP_ADDR4(&ipconfig[1], 255, 255, 255, 0);
583+
IP_ADDR4(&ipconfig[2], 192, 168, 0, 1);
584+
IP_ADDR4(&ipconfig[3], 8, 8, 8, 8);
572585

573586
MICROPY_PY_LWIP_ENTER
574587

575588
n->name[0] = 'e';
576589
n->name[1] = (self == &eth_instance0 ? '0' : '1');
577-
netif_add(n, &ipconfig[0], &ipconfig[1], &ipconfig[2], self, eth_netif_init, ethernet_input);
590+
netif_add(n, ip_2_ip4(&ipconfig[0]), ip_2_ip4(&ipconfig[1]), ip_2_ip4(&ipconfig[2]), self, eth_netif_init, ethernet_input);
578591
netif_set_hostname(n, mod_network_hostname_data);
579592
netif_set_default(n);
580593
netif_set_up(n);
@@ -585,6 +598,10 @@ static void eth_lwip_init(eth_t *self) {
585598

586599
netif_set_link_up(n);
587600

601+
#if LWIP_IPV6
602+
netif_create_ip6_linklocal_address(n, 1);
603+
#endif
604+
588605
MICROPY_PY_LWIP_EXIT
589606
}
590607

@@ -593,7 +610,7 @@ static void eth_lwip_deinit(eth_t *self) {
593610
for (struct netif *netif = netif_list; netif != NULL; netif = netif->next) {
594611
if (netif == &self->netif) {
595612
netif_remove(netif);
596-
netif->ip_addr.addr = 0;
613+
netif_set_addr(netif, IP4_ADDR_ANY4, IP4_ADDR_ANY4, IP4_ADDR_ANY4);
597614
netif->flags = 0;
598615
}
599616
}
@@ -608,7 +625,7 @@ int eth_link_status(eth_t *self) {
608625
struct netif *netif = &self->netif;
609626
if ((netif->flags & (NETIF_FLAG_UP | NETIF_FLAG_LINK_UP))
610627
== (NETIF_FLAG_UP | NETIF_FLAG_LINK_UP)) {
611-
if (netif->ip_addr.addr != 0) {
628+
if (!ip4_addr_isany_val(*netif_ip4_addr(netif))) {
612629
return 3; // link up
613630
} else {
614631
return 2; // link no-ip;

ports/mimxrt/lwip_inc/lwipopts.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
#define LWIP_NETIF_EXT_STATUS_CALLBACK 1
55

6-
#define LWIP_IPV6 0
7-
86
#define LWIP_RAND() trng_random_u32()
97

108
// Include common lwIP configuration.

ports/mimxrt/network_lan.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,14 @@ static void network_lan_print(const mp_print_t *print, mp_obj_t self_in, mp_prin
6464
network_lan_obj_t *self = MP_OBJ_TO_PTR(self_in);
6565
struct netif *netif = eth_netif(self->eth);
6666
int status = eth_link_status(self->eth);
67+
const ip4_addr_t *ip4 = netif_ip4_addr(netif);
6768
mp_printf(print, "<ETH%d status=%u ip=%u.%u.%u.%u>",
6869
self->eth == &eth_instance0 ? 0 : 1,
6970
status,
70-
netif->ip_addr.addr & 0xff,
71-
netif->ip_addr.addr >> 8 & 0xff,
72-
netif->ip_addr.addr >> 16 & 0xff,
73-
netif->ip_addr.addr >> 24
71+
ip4_addr1(ip4),
72+
ip4_addr2(ip4),
73+
ip4_addr3(ip4),
74+
ip4_addr4(ip4)
7475
);
7576
}
7677

0 commit comments

Comments
 (0)