diff --git a/components/mdns/include/mdns.h b/components/mdns/include/mdns.h index 58121135a5..28cd2f2b4f 100644 --- a/components/mdns/include/mdns.h +++ b/components/mdns/include/mdns.h @@ -720,9 +720,43 @@ esp_err_t mdns_query_aaaa(const char * host_name, uint32_t timeout, esp_ip6_addr #endif -esp_err_t mdns_add_custom_netif(esp_netif_t *esp_netif); -esp_err_t mdns_post_custom_action(esp_netif_t *esp_netif, mdns_event_actions_t event_action); -esp_err_t mdns_delete_custom_netif(esp_netif_t *esp_netif); +/** + * @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. + * + * @param esp_netif Pointer to esp-netif interface + * @return + * - ESP_OK success + * - 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); + +/** + * @brief Unregister esp-netif already registered in mDNS service + * + * @param esp_netif Pointer to esp-netif interface + * @return + * - ESP_OK success + * - 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); + +/** + * @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 + * @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. + * @return + * - ESP_OK success + * - 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); #ifdef __cplusplus } diff --git a/components/mdns/mdns.c b/components/mdns/mdns.c index 519365397c..aad3538113 100644 --- a/components/mdns/mdns.c +++ b/components/mdns/mdns.c @@ -3824,7 +3824,7 @@ void _mdns_disable_pcb(mdns_if_t tcpip_if, mdns_ip_protocol_t ip_protocol) */ static void perform_event_action(mdns_if_t mdns_if, mdns_event_actions_t action) { - if (!_mdns_server || mdns_if > MDNS_MAX_INTERFACES) { + if (!_mdns_server || mdns_if >= MDNS_MAX_INTERFACES) { return; } if (action & MDNS_EVENT_ENABLE_IP4) { @@ -5028,7 +5028,7 @@ static esp_err_t _mdns_service_task_stop(void) static esp_err_t mdns_post_custom_action_tcpip_if(mdns_if_t mdns_if, mdns_event_actions_t event_action) { if (!_mdns_server || mdns_if >= MDNS_MAX_INTERFACES) { - return ESP_FAIL; + return ESP_ERR_INVALID_STATE; } mdns_action_t * action = (mdns_action_t *)calloc(1, sizeof(mdns_action_t)); @@ -5081,12 +5081,12 @@ static inline void unregister_predefined_handlers(void) * Public Methods * */ -esp_err_t mdns_post_custom_action(esp_netif_t *esp_netif, mdns_event_actions_t event_action) +esp_err_t mdns_set_esp_netif_action(esp_netif_t *esp_netif, mdns_event_actions_t event_action) { return mdns_post_custom_action_tcpip_if(_mdns_get_if_from_esp_netif(esp_netif), event_action); } -esp_err_t mdns_add_custom_netif(esp_netif_t *esp_netif) +esp_err_t mdns_register_esp_netif(esp_netif_t *esp_netif) { if (!_mdns_server) { return ESP_ERR_INVALID_STATE; @@ -5112,7 +5112,7 @@ esp_err_t mdns_add_custom_netif(esp_netif_t *esp_netif) return err; } -esp_err_t mdns_delete_custom_netif(esp_netif_t *esp_netif) +esp_err_t mdns_unregister_esp_netif(esp_netif_t *esp_netif) { if (!_mdns_server) { return ESP_ERR_INVALID_STATE; diff --git a/components/mdns/mdns_console.c b/components/mdns/mdns_console.c index 16379fadee..f677e337c6 100644 --- a/components/mdns/mdns_console.c +++ b/components/mdns/mdns_console.c @@ -11,18 +11,13 @@ static const char * ip_protocol_str[] = {"V4", "V6", "MAX"}; -static const char * if_str(esp_netif_t *netif) -{ - return esp_netif_get_ifkey(netif); -} - static void mdns_print_results(mdns_result_t * results) { mdns_result_t * r = results; mdns_ip_addr_t * a = NULL; int i = 1; while (r) { - printf("%d: Interface: %s, Type: %s\n", i++, if_str(r->esp_netif), ip_protocol_str[r->ip_protocol]); + printf("%d: Interface: %s, Type: %s\n", i++, esp_netif_get_ifkey(r->esp_netif), ip_protocol_str[r->ip_protocol]); if (r->instance_name) { printf(" PTR : %s\n", r->instance_name); } diff --git a/examples/protocols/mdns/main/mdns_example_main.c b/examples/protocols/mdns/main/mdns_example_main.c index c1a9ba8686..ee8c77519e 100644 --- a/examples/protocols/mdns/main/mdns_example_main.c +++ b/examples/protocols/mdns/main/mdns_example_main.c @@ -270,9 +270,9 @@ void app_main(void) /* Demonstration of adding a custom netif to mdns service, but we're adding the default example one, * so we must disable all predefined interfaces (PREDEF_NETIF_STA, AP and ETH) first */ - ESP_ERROR_CHECK(mdns_add_custom_netif(EXAMPLE_INTERFACE)); - ESP_ERROR_CHECK(mdns_post_custom_action(EXAMPLE_INTERFACE, MDNS_EVENT_ENABLE_IP4)); - ESP_ERROR_CHECK(mdns_post_custom_action(EXAMPLE_INTERFACE, MDNS_EVENT_ANNOUNCE_IP4)); + ESP_ERROR_CHECK(mdns_register_esp_netif(EXAMPLE_INTERFACE)); + ESP_ERROR_CHECK(mdns_set_esp_netif_action(EXAMPLE_INTERFACE, MDNS_EVENT_ENABLE_IP4)); + ESP_ERROR_CHECK(mdns_set_esp_netif_action(EXAMPLE_INTERFACE, MDNS_EVENT_ANNOUNCE_IP4)); #endif initialise_button(); xTaskCreate(&mdns_example_task, "mdns_example_task", 2048, NULL, 5, NULL);