From 078ead24f392deedaad2f391baac4aaefe96f49b Mon Sep 17 00:00:00 2001 From: Jared Hancock Date: Mon, 14 Oct 2024 09:19:10 -0500 Subject: [PATCH] extmod/network_wiznet5k: Reset mDNS when interface is brought up. The LwIP interface is removed in wiznet5k_deinit() which is called as part of the init sequence. Therefore, if using mDNS, then the interface will need to be re-added when bringing the interface up. Additionally, this allows to set the hostname from MicroPython code prior to bringing the interface up and mDNS responding to the (new) hostname. This allows the hostname to be configured and saved on the flash or be based on dynamic information such as the MAC or unique_id(). Signed-off-by: Jared Hancock --- extmod/network_wiznet5k.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/extmod/network_wiznet5k.c b/extmod/network_wiznet5k.c index 96f9b6131..533d39a18 100644 --- a/extmod/network_wiznet5k.c +++ b/extmod/network_wiznet5k.c @@ -58,6 +58,7 @@ #include "shared/netutils/netutils.h" #include "lib/wiznet5k/Ethernet/wizchip_conf.h" #include "lib/wiznet5k/Ethernet/socket.h" +#include "lwip/apps/mdns.h" #include "lwip/err.h" #include "lwip/dns.h" #include "lwip/dhcp.h" @@ -201,6 +202,9 @@ static void wiznet5k_config_interrupt(bool enabled) { void wiznet5k_deinit(void) { for (struct netif *netif = netif_list; netif != NULL; netif = netif->next) { if (netif == &wiznet5k_obj.netif) { + #if LWIP_MDNS_RESPONDER + mdns_resp_remove_netif(&wiznet5k_obj.netif); + #endif netif_remove(netif); netif->flags = 0; break; @@ -334,6 +338,12 @@ static void wiznet5k_lwip_init(wiznet5k_obj_t *self) { self->netif.flags |= NETIF_FLAG_UP; dhcp_start(&self->netif); self->netif.flags &= ~NETIF_FLAG_UP; + + #if LWIP_MDNS_RESPONDER + // NOTE: interface is removed in ::wiznet5k_deinit(), which is called as + // part of the init sequence. + mdns_resp_add_netif(&self->netif, mod_network_hostname_data); + #endif } void wiznet5k_poll(void) {