diff --git a/components/mdns/Kconfig b/components/mdns/Kconfig index 7ceefd88d..def0d850d 100644 --- a/components/mdns/Kconfig +++ b/components/mdns/Kconfig @@ -5,7 +5,7 @@ menu "mDNS" range 1 9 default 3 help - Number of network interfaces to be served by the mdns library. + Number of network interfaces to be served by the mDNS library. Lowering this number helps to reduce some static RAM usage. config MDNS_MAX_SERVICES @@ -72,7 +72,7 @@ menu "mDNS" Currently the only strict feature: Do not repeat original questions in response packets (defined in RFC6762 sec. 6). Default configuration is 0, i.e. non-strict mode, since some implementations, - such as lwIP mdns resolver (used by standard POSIX API like getaddrinfo, gethostbyname) + such as lwIP mDNS resolver (used by standard POSIX API like getaddrinfo, gethostbyname) could not correctly resolve advertised names. config MDNS_TIMER_PERIOD_MS @@ -84,10 +84,10 @@ menu "mDNS" and schedules mDNS searches. config MDNS_NETWORKING_SOCKET - bool "Use BSD sockets for mdns networking" + bool "Use BSD sockets for mDNS networking" default n help - Enables optional mdns networking implementation using BSD sockets + Enables optional mDNS networking implementation using BSD sockets in UDP multicast mode. This option creates a new thread to serve receiving packets (TODO). This option uses additional N sockets, where N is number of interfaces. @@ -104,21 +104,22 @@ menu "mDNS" bool "Use predefined interface for WiFi Station" default y help - Set up mdns for the default WiFi station. + Set up mDNS for the default WiFi station. Disable this option if you do not need mDNS on default WiFi STA. config MDNS_PREDEF_NETIF_AP bool "Use predefined interface for WiFi Access Point" default y help - Set up mdns for the default WiFi Access Point. + Set up mDNS for the default WiFi Access Point. Disable this option if you do not need mDNS on default WiFi AP. config MDNS_PREDEF_NETIF_ETH bool "Use predefined interface for Ethernet" + depends on ETH_ENABLED default y help - Set up mdns for the default Ethernet interface. + Set up mDNS for the default Ethernet interface. Disable this option if you do not need mDNS on default Ethernet. endmenu # MDNS Predefined interfaces diff --git a/components/mdns/include/mdns.h b/components/mdns/include/mdns.h index 28cd2f2b4..7f81d0af8 100644 --- a/components/mdns/include/mdns.h +++ b/components/mdns/include/mdns.h @@ -722,9 +722,9 @@ esp_err_t mdns_query_aaaa(const char * host_name, uint32_t timeout, esp_ip6_addr /** * @brief Register custom esp_netif with mDNS functionality - * mDNS service runs by on default interfaces (STA, AP, ETH). This API enables running the service - * on any customized interface, either using standard WiFi or Ethernet driver or any kind of user - * defined driver. + * mDNS service runs by default on preconfigured interfaces (STA, AP, ETH). + * This API enables running the service on any customized interface, + * either using standard WiFi or Ethernet driver or any kind of user defined driver. * * @param esp_netif Pointer to esp-netif interface * @return @@ -732,7 +732,7 @@ esp_err_t mdns_query_aaaa(const char * host_name, uint32_t timeout, esp_ip6_addr * - ESP_ERR_INVALID_STATE mDNS is not running or this netif is already registered * - ESP_ERR_NO_MEM not enough memory for this in interface in the netif list (see CONFIG_MDNS_MAX_INTERFACES) */ -esp_err_t mdns_register_esp_netif(esp_netif_t *esp_netif); +esp_err_t mdns_register_netif(esp_netif_t *esp_netif); /** * @brief Unregister esp-netif already registered in mDNS service @@ -743,11 +743,19 @@ esp_err_t mdns_register_esp_netif(esp_netif_t *esp_netif); * - ESP_ERR_INVALID_STATE mDNS is not running * - ESP_ERR_NOT_FOUND this esp-netif was not registered in mDNS service */ -esp_err_t mdns_unregister_esp_netif(esp_netif_t *esp_netif); +esp_err_t mdns_unregister_netif(esp_netif_t *esp_netif); /** * @brief Set esp_netif to a desired state, or perform a desired action, such as enable/disable this interface * or send announcement packets to this netif + * + * * This function is used to enable (probe, resolve conflicts and announce), announce, or disable (send bye) mDNS + * services on the specified network interface. + * * This function must be called if users registers a specific interface using mdns_register_netif() + * to enable mDNS services on that interface. + * * This function could be used in IP/connection event handlers to automatically enable/announce mDNS services + * when network properties change and/or disable them on disconnection. + * * @param esp_netif Pointer to esp-netif interface * @param event_action Disable/Enable/Announce on this interface over IPv4/IPv6 protocol. * Actions enumerated in mdns_event_actions_t type. @@ -756,7 +764,7 @@ esp_err_t mdns_unregister_esp_netif(esp_netif_t *esp_netif); * - ESP_ERR_INVALID_STATE mDNS is not running or this netif is not registered * - ESP_ERR_NO_MEM memory error */ -esp_err_t mdns_set_esp_netif_action(esp_netif_t *esp_netif, mdns_event_actions_t event_action); +esp_err_t mdns_netif_action(esp_netif_t *esp_netif, mdns_event_actions_t event_action); #ifdef __cplusplus } diff --git a/components/mdns/mdns.c b/components/mdns/mdns.c index aad353811..15b32e338 100644 --- a/components/mdns/mdns.c +++ b/components/mdns/mdns.c @@ -68,9 +68,9 @@ typedef enum { typedef struct mdns_interfaces mdns_interfaces_t; struct mdns_interfaces { - bool predefined; + const bool predefined; esp_netif_t * netif; - mdns_predef_if_t predef_if; + const mdns_predef_if_t predef_if; mdns_if_t duplicate; }; @@ -91,10 +91,13 @@ static mdns_interfaces_t s_esp_netifs[MDNS_MAX_INTERFACES] = { }; -/* - * @brief Convert mdns if to esp-netif handle +/** + * @brief Convert Predefined interface to the netif id from the internal netif list + * @param predef_if Predefined interface enum + * @return Ordinal number of internal list of mdns network interface. + * Returns MDNS_MAX_INTERFACES if the predefined interface wasn't found in the list */ -static mdns_if_t mdns_if_from_predef_if(mdns_predef_if_t predef_if) +static mdns_if_t mdns_if_from_preset_if(mdns_predef_if_t predef_if) { for (int i=0; i "STA", "AP", "ETH" + * - if no entry in the list (NULL) -> check if the system added this netif + * - point to a custom netif -> just return the entry in the list + * - users is responsible for the lifetime of this netif (to be valid between mdns-init -> deinit) + * + * @param tcpip_if Ordinal number of the interface + * @return Pointer ot the esp_netif object if the interface is available, NULL otherwise + */ esp_netif_t *_mdns_get_esp_netif(mdns_if_t tcpip_if) { if (tcpip_if < MDNS_MAX_INTERFACES) { if (s_esp_netifs[tcpip_if].netif == NULL && s_esp_netifs[tcpip_if].predefined) { - // if a predefined interface face and used local copy is NULL, try to search for the default interface key + // If the local copy is NULL and this netif is predefined -> we can find it in the global netif list s_esp_netifs[tcpip_if].netif = esp_netif_from_preset_if(s_esp_netifs[tcpip_if].predef_if); + // failing to find it means that the netif is *not* available -> return NULL } return s_esp_netifs[tcpip_if].netif; } @@ -146,11 +167,12 @@ static inline void _mdns_clean_netif_ptr(mdns_if_t tcpip_if) { /* * @brief Convert esp-netif handle to mdns if */ -static mdns_if_t _mdns_get_if_from_esp_netif(esp_netif_t *interface) +static mdns_if_t _mdns_get_if_from_esp_netif(esp_netif_t *esp_netif) { for (int i=0; i