summaryrefslogtreecommitdiff
path: root/extmod/network_wiznet5k.c
diff options
context:
space:
mode:
authorJared Hancock <jared@greezybacon.me>2024-08-17 23:09:52 -0500
committerDamien George <damien@micropython.org>2024-08-26 13:02:44 +1000
commite901ff85573d4cbec1e2656aea2e5603d6bf5bd9 (patch)
tree584b4fcd8663eb3a79bc4502cc981839dc3799f8 /extmod/network_wiznet5k.c
parentb82c9ca706a675b53200d8df27ee3903ff521c2d (diff)
extmod/network_wiznet5k: Add support for IPv6.
This adds support for the WIZNET5K nic to use IPv6 with the LWIP stack. Additionally, if LWIP_IPV6 is disabled, the device is configured to drop all IPv6 packets to reduce load on the MCU. Signed-off-by: Jared Hancock <jared@greezybacon.me>
Diffstat (limited to 'extmod/network_wiznet5k.c')
-rw-r--r--extmod/network_wiznet5k.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/extmod/network_wiznet5k.c b/extmod/network_wiznet5k.c
index 1eaabe9eb..96f9b6131 100644
--- a/extmod/network_wiznet5k.c
+++ b/extmod/network_wiznet5k.c
@@ -61,6 +61,7 @@
#include "lwip/err.h"
#include "lwip/dns.h"
#include "lwip/dhcp.h"
+#include "lwip/ethip6.h"
#include "netif/etharp.h"
#define TRACE_ETH_TX (0x0002)
@@ -297,13 +298,21 @@ static err_t wiznet5k_netif_init(struct netif *netif) {
netif->hwaddr_len = sizeof(netif->hwaddr);
int ret = WIZCHIP_EXPORT(socket)(0, Sn_MR_MACRAW, 0, 0);
if (ret != 0) {
- printf("WIZNET fatal error in netifinit: %d\n", ret);
+ printf("WIZNET fatal error in netif_init: %d\n", ret);
return ERR_IF;
}
// Enable MAC filtering so we only get frames destined for us, to reduce load on lwIP
setSn_MR(0, getSn_MR(0) | Sn_MR_MFEN);
+ #if LWIP_IPV6
+ netif->output_ip6 = ethip6_output;
+ netif->flags |= NETIF_FLAG_MLD6;
+ #else
+ // Drop IPv6 packets if firmware does not support it
+ setSn_MR(0, getSn_MR(0) | Sn_MR_MIP6B);
+ #endif
+
return ERR_OK;
}
@@ -847,6 +856,10 @@ static mp_obj_t wiznet5k_active(size_t n_args, const mp_obj_t *args) {
setSHAR(mac);
}
+ #if WIZNET5K_WITH_LWIP_STACK && LWIP_IPV6
+ netif_create_ip6_linklocal_address(&self->netif, 1);
+ #endif
+
// seems we need a small delay after init
mp_hal_delay_ms(250);