mirror of
https://github.com/espressif/esp-protocols.git
synced 2025-07-20 05:52:22 +02:00
mdns: Add API to control custom network interfaces
* Original commit: espressif/esp-idf@b02468dc98
This commit is contained in:
committed by
suren-gabrielyan-espressif
parent
e9a1c26e0c
commit
f836ae7f65
@ -720,9 +720,43 @@ esp_err_t mdns_query_aaaa(const char * host_name, uint32_t timeout, esp_ip6_addr
|
|||||||
#endif
|
#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);
|
* @brief Register custom esp_netif with mDNS functionality
|
||||||
esp_err_t mdns_delete_custom_netif(esp_netif_t *esp_netif);
|
* 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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -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)
|
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;
|
return;
|
||||||
}
|
}
|
||||||
if (action & MDNS_EVENT_ENABLE_IP4) {
|
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)
|
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) {
|
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));
|
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
|
* 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);
|
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) {
|
if (!_mdns_server) {
|
||||||
return ESP_ERR_INVALID_STATE;
|
return ESP_ERR_INVALID_STATE;
|
||||||
@ -5112,7 +5112,7 @@ esp_err_t mdns_add_custom_netif(esp_netif_t *esp_netif)
|
|||||||
return err;
|
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) {
|
if (!_mdns_server) {
|
||||||
return ESP_ERR_INVALID_STATE;
|
return ESP_ERR_INVALID_STATE;
|
||||||
|
@ -11,18 +11,13 @@
|
|||||||
|
|
||||||
static const char * ip_protocol_str[] = {"V4", "V6", "MAX"};
|
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)
|
static void mdns_print_results(mdns_result_t * results)
|
||||||
{
|
{
|
||||||
mdns_result_t * r = results;
|
mdns_result_t * r = results;
|
||||||
mdns_ip_addr_t * a = NULL;
|
mdns_ip_addr_t * a = NULL;
|
||||||
int i = 1;
|
int i = 1;
|
||||||
while (r) {
|
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) {
|
if (r->instance_name) {
|
||||||
printf(" PTR : %s\n", r->instance_name);
|
printf(" PTR : %s\n", r->instance_name);
|
||||||
}
|
}
|
||||||
|
@ -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,
|
/* 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
|
* 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_register_esp_netif(EXAMPLE_INTERFACE));
|
||||||
ESP_ERROR_CHECK(mdns_post_custom_action(EXAMPLE_INTERFACE, MDNS_EVENT_ENABLE_IP4));
|
ESP_ERROR_CHECK(mdns_set_esp_netif_action(EXAMPLE_INTERFACE, MDNS_EVENT_ENABLE_IP4));
|
||||||
ESP_ERROR_CHECK(mdns_post_custom_action(EXAMPLE_INTERFACE, MDNS_EVENT_ANNOUNCE_IP4));
|
ESP_ERROR_CHECK(mdns_set_esp_netif_action(EXAMPLE_INTERFACE, MDNS_EVENT_ANNOUNCE_IP4));
|
||||||
#endif
|
#endif
|
||||||
initialise_button();
|
initialise_button();
|
||||||
xTaskCreate(&mdns_example_task, "mdns_example_task", 2048, NULL, 5, NULL);
|
xTaskCreate(&mdns_example_task, "mdns_example_task", 2048, NULL, 5, NULL);
|
||||||
|
Reference in New Issue
Block a user