mirror of
https://github.com/espressif/esp-protocols.git
synced 2025-07-20 05:52:22 +02:00
mdns: Fix copyright messages, update API descrition
* Impove docs and comments on custom netifs * Make predef interfaces const, minor docs fixes * Original commit: espressif/esp-idf@42ba8a8338
This commit is contained in:
committed by
suren-gabrielyan-espressif
parent
f836ae7f65
commit
2c764b1b7a
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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<MDNS_MAX_INTERFACES; ++i) {
|
||||
if (s_esp_netifs[i].predefined && s_esp_netifs[i].predef_if == predef_if) {
|
||||
@ -104,9 +107,14 @@ static mdns_if_t mdns_if_from_predef_if(mdns_predef_if_t predef_if)
|
||||
return MDNS_MAX_INTERFACES;
|
||||
}
|
||||
|
||||
static inline esp_netif_t *esp_netif_from_preset_if(mdns_predef_if_t preset_if)
|
||||
/**
|
||||
* @brief Convert Predefined interface to esp-netif handle
|
||||
* @param predef_if Predefined interface enum
|
||||
* @return esp_netif pointer from system list of network interfaces
|
||||
*/
|
||||
static inline esp_netif_t *esp_netif_from_preset_if(mdns_predef_if_t predef_if)
|
||||
{
|
||||
switch (preset_if) {
|
||||
switch (predef_if) {
|
||||
case MDNS_IF_STA:
|
||||
return esp_netif_get_handle_from_ifkey("WIFI_STA_DEF");
|
||||
case MDNS_IF_AP:
|
||||
@ -120,12 +128,25 @@ static inline esp_netif_t *esp_netif_from_preset_if(mdns_predef_if_t preset_if)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Gets the actual esp_netif pointer from the internal network interface list
|
||||
*
|
||||
* The supplied ordinal number could
|
||||
* - point to a predef netif -> "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,12 +167,13 @@ 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<MDNS_MAX_INTERFACES; ++i) {
|
||||
if (interface == s_esp_netifs[i].netif)
|
||||
if (esp_netif == s_esp_netifs[i].netif) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return MDNS_MAX_INTERFACES;
|
||||
}
|
||||
|
||||
@ -3852,17 +3874,17 @@ static void perform_event_action(mdns_if_t mdns_if, mdns_event_actions_t action)
|
||||
*/
|
||||
static inline void post_mdns_disable_pcb(mdns_predef_if_t preset_if, mdns_ip_protocol_t protocol)
|
||||
{
|
||||
mdns_post_custom_action_tcpip_if(mdns_if_from_predef_if(preset_if), protocol==MDNS_IP_PROTOCOL_V4 ? MDNS_EVENT_DISABLE_IP4 : MDNS_EVENT_DISABLE_IP6);
|
||||
mdns_post_custom_action_tcpip_if(mdns_if_from_preset_if(preset_if), protocol == MDNS_IP_PROTOCOL_V4 ? MDNS_EVENT_DISABLE_IP4 : MDNS_EVENT_DISABLE_IP6);
|
||||
}
|
||||
|
||||
static inline void post_mdns_enable_pcb(mdns_predef_if_t preset_if, mdns_ip_protocol_t protocol)
|
||||
{
|
||||
mdns_post_custom_action_tcpip_if(mdns_if_from_predef_if(preset_if), protocol==MDNS_IP_PROTOCOL_V4 ? MDNS_EVENT_ENABLE_IP4 : MDNS_EVENT_ENABLE_IP6);
|
||||
mdns_post_custom_action_tcpip_if(mdns_if_from_preset_if(preset_if), protocol == MDNS_IP_PROTOCOL_V4 ? MDNS_EVENT_ENABLE_IP4 : MDNS_EVENT_ENABLE_IP6);
|
||||
}
|
||||
|
||||
static inline void post_mdns_announce_pcb(mdns_predef_if_t preset_if, mdns_ip_protocol_t protocol)
|
||||
{
|
||||
mdns_post_custom_action_tcpip_if(mdns_if_from_predef_if(preset_if), protocol==MDNS_IP_PROTOCOL_V4 ? MDNS_EVENT_ANNOUNCE_IP4 : MDNS_EVENT_ANNOUNCE_IP6);
|
||||
mdns_post_custom_action_tcpip_if(mdns_if_from_preset_if(preset_if), protocol == MDNS_IP_PROTOCOL_V4 ? MDNS_EVENT_ANNOUNCE_IP4 : MDNS_EVENT_ANNOUNCE_IP6);
|
||||
}
|
||||
|
||||
void mdns_preset_if_handle_system_event(void *arg, esp_event_base_t event_base,
|
||||
@ -5081,12 +5103,12 @@ static inline void unregister_predefined_handlers(void)
|
||||
* Public Methods
|
||||
* */
|
||||
|
||||
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)
|
||||
{
|
||||
return mdns_post_custom_action_tcpip_if(_mdns_get_if_from_esp_netif(esp_netif), event_action);
|
||||
}
|
||||
|
||||
esp_err_t mdns_register_esp_netif(esp_netif_t *esp_netif)
|
||||
esp_err_t mdns_register_netif(esp_netif_t *esp_netif)
|
||||
{
|
||||
if (!_mdns_server) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
@ -5112,7 +5134,7 @@ esp_err_t mdns_register_esp_netif(esp_netif_t *esp_netif)
|
||||
return err;
|
||||
}
|
||||
|
||||
esp_err_t mdns_unregister_esp_netif(esp_netif_t *esp_netif)
|
||||
esp_err_t mdns_unregister_netif(esp_netif_t *esp_netif)
|
||||
{
|
||||
if (!_mdns_server) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
@ -270,9 +270,13 @@ 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_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));
|
||||
ESP_ERROR_CHECK(mdns_register_netif(EXAMPLE_INTERFACE));
|
||||
/* It is not enough to just register the interface, we have to enable is manually.
|
||||
* This is typically performed in "GOT_IP" event handler, but we call it here directly
|
||||
* since the `EXAMPLE_INTERFACE` netif is connected already, to keep the example simple.
|
||||
*/
|
||||
ESP_ERROR_CHECK(mdns_netif_action(EXAMPLE_INTERFACE, MDNS_EVENT_ENABLE_IP4));
|
||||
ESP_ERROR_CHECK(mdns_netif_action(EXAMPLE_INTERFACE, MDNS_EVENT_ANNOUNCE_IP4));
|
||||
#endif
|
||||
initialise_button();
|
||||
xTaskCreate(&mdns_example_task, "mdns_example_task", 2048, NULL, 5, NULL);
|
||||
|
Reference in New Issue
Block a user