From f96417dbf28617c533e4f2e65c65d1ed11f089fa Mon Sep 17 00:00:00 2001 From: Mark Seminatore Date: Mon, 31 Mar 2025 11:38:36 -0700 Subject: [PATCH] rp2/cyw43_configport: Fix cyw43 mDNS by properly starting mDNS on netif. The rp2 port has an incomplete mDNS implementation. The code in `main.c` calls `mdns_resp_init()` which opens the UDP socket for mDNS. However, no code in the cyw43 driver makes the proper calls to `mdns_resp_add_netif()` and `mdns_resp_remove_netif()` to send the announce packets. The wiznet5k driver does make these calls and was used as a model for these changes. This commit attempts to address this by very small changes to the `ports/rp2/cyw43_configport.h` file. The change uses new cyw43 driver hooks to map the driver macros `CYW43_CB_TCPIP_INIT_EXTRA` and `CYW43_CB_TCPIP_DEINIT_EXTRA` to the appropriate lwIP mDNS calls. Fixes issue #15297. Signed-off-by: Mark Seminatore --- ports/rp2/cyw43_configport.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/ports/rp2/cyw43_configport.h b/ports/rp2/cyw43_configport.h index ead1a3953d97e..5523305742325 100644 --- a/ports/rp2/cyw43_configport.h +++ b/ports/rp2/cyw43_configport.h @@ -33,6 +33,7 @@ #include "py/mphal.h" #include "py/runtime.h" #include "extmod/modnetwork.h" +#include "lwip/apps/mdns.h" #include "pendsv.h" #define CYW43_INCLUDE_LEGACY_F1_OVERFLOW_WORKAROUND_VARIABLES (1) @@ -167,4 +168,19 @@ static inline void cyw43_delay_ms(uint32_t ms) { #define CYW43_EVENT_POLL_HOOK mp_event_handle_nowait() +#if LWIP_MDNS_RESPONDER == 1 + +// Hook for any additional TCP/IP initialization than needs to be done. +// Called after the netif specified by `itf` has been set up. +#ifndef CYW43_CB_TCPIP_INIT_EXTRA +#define CYW43_CB_TCPIP_INIT_EXTRA(self, itf) mdns_resp_add_netif(&self->netif[itf], mod_network_hostname_data) +#endif + +// Hook for any additional TCP/IP deinitialization than needs to be done. +// Called before the netif specified by `itf` is removed. +#ifndef CYW43_CB_TCPIP_DEINIT_EXTRA +#define CYW43_CB_TCPIP_DEINIT_EXTRA(self, itf) mdns_resp_remove_netif(&self->netif[itf]) +#endif + +#endif #endif // MICROPY_INCLUDED_RP2_CYW43_CONFIGPORT_H