fix(mdns): Host test with IDFv5.1

This commit is contained in:
David Cermak
2023-01-13 20:32:07 +01:00
parent b87bef52e5
commit fb8a2f0198
34 changed files with 187 additions and 172 deletions

View File

@ -3,8 +3,8 @@ name: Host test
on: [push, pull_request] on: [push, pull_request]
jobs: jobs:
host_test: host_test_esp_modem:
name: Build and Test on Host name: esp-modem Build and Test on Host
runs-on: ubuntu-20.04 runs-on: ubuntu-20.04
container: espressif/idf:release-v4.3 container: espressif/idf:release-v4.3
env: env:
@ -38,3 +38,23 @@ jobs:
if: always() if: always()
with: with:
files: esp-protocols/components/esp_modem/test/host_test/junit.xml files: esp-protocols/components/esp_modem/test/host_test/junit.xml
host_test_mdns:
name: mdns Build and Test on Host
runs-on: ubuntu-20.04
container: espressif/idf:latest
steps:
- name: Checkout esp-protocols
uses: actions/checkout@master
with:
path: esp-protocols
- name: Build and Test
shell: bash
run: |
apt-get update && apt-get install -y dnsutils gcc g++
. ${IDF_PATH}/export.sh
cd $GITHUB_WORKSPACE/esp-protocols/components/mdns/tests/host_test
idf.py build
./build/mdns_host.elf & dig +short -p 5353 @224.0.0.251 myesp.local

View File

@ -6,7 +6,7 @@ endif()
idf_build_get_property(target IDF_TARGET) idf_build_get_property(target IDF_TARGET)
if(${target} STREQUAL "linux") if(${target} STREQUAL "linux")
set(dependencies esp_system_protocols_linux) set(dependencies esp_event esp_netif_linux esp_timer_linux esp_system)
set(srcs "mdns.c" ${MDNS_NETWORKING}) set(srcs "mdns.c" ${MDNS_NETWORKING})
else() else()
set(dependencies lwip console esp_netif) set(dependencies lwip console esp_netif)
@ -22,6 +22,11 @@ idf_component_register(
PRIV_REQUIRES ${private_dependencies}) PRIV_REQUIRES ${private_dependencies})
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format") target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")
if(${target} STREQUAL "linux")
target_link_libraries(${COMPONENT_LIB} PRIVATE "-lbsd")
endif()
if(CONFIG_ETH_ENABLED) if(CONFIG_ETH_ENABLED)
idf_component_optional_requires(PRIVATE esp_eth) idf_component_optional_requires(PRIVATE esp_eth)
endif() endif()

View File

@ -81,6 +81,20 @@ menu "mDNS"
This option creates a new thread to serve receiving packets (TODO). This option creates a new thread to serve receiving packets (TODO).
This option uses additional N sockets, where N is number of interfaces. This option uses additional N sockets, where N is number of interfaces.
config MDNS_SKIP_SUPPRESSING_OWN_QUERIES
bool "Skip suppressing our own packets"
default n
help
Enable only if the querier and the responder share the same IP address.
This usually happens in test mode, where we may run multiple instances of
responders/queriers on the same interface.
config MDNS_ENABLE_DEBUG_PRINTS
bool "Enable debug prints of mDNS packets"
default n
help
Enable for the library to log received and sent mDNS packets to stdout.
config MDNS_MULTIPLE_INSTANCE config MDNS_MULTIPLE_INSTANCE
bool "Multiple instances under the same service type" bool "Multiple instances under the same service type"
default y default y

View File

@ -17,10 +17,15 @@
#include "mdns_networking.h" #include "mdns_networking.h"
#include "esp_log.h" #include "esp_log.h"
#include "esp_random.h" #include "esp_random.h"
#if CONFIG_ETH_ENABLED #if __has_include("bsd/string.h")
#include "bsd/string.h"
#endif
#if CONFIG_ETH_ENABLED && CONFIG_MDNS_PREDEF_NETIF_ETH
#include "esp_eth.h" #include "esp_eth.h"
#endif #endif
#if CONFIG_MDNS_PREDEF_NETIF_STA || CONFIG_MDNS_PREDEF_NETIF_AP
#include "esp_wifi.h" #include "esp_wifi.h"
#endif
#ifdef MDNS_ENABLE_DEBUG #ifdef MDNS_ENABLE_DEBUG
@ -1102,10 +1107,11 @@ static uint16_t _mdns_append_question(uint8_t *packet, uint16_t *index, mdns_out
const char *str[6]; const char *str[6];
uint8_t str_index = 0; uint8_t str_index = 0;
uint8_t part_length; uint8_t part_length;
char *host_dup = NULL; // need to duplicate host-name for some cases
if (q->host && strstr(q->host, "in-addr")) { if (q->host && strstr(q->host, "in-addr")) {
char * host = strdup(q->host); host_dup = strdup(q->host);
char *rest = NULL; char *rest = NULL;
for (char *p = strtok_r(host,".", &rest); p != NULL; p = strtok_r(NULL, ".", &rest)) { for (char *p = strtok_r(host_dup, ".", &rest); p != NULL; p = strtok_r(NULL, ".", &rest)) {
str[str_index++] = p; str[str_index++] = p;
} }
if (q->domain) { if (q->domain) {
@ -1131,11 +1137,13 @@ static uint16_t _mdns_append_question(uint8_t *packet, uint16_t *index, mdns_out
part_length = _mdns_append_fqdn(packet, index, str, str_index, MDNS_MAX_PACKET_SIZE); part_length = _mdns_append_fqdn(packet, index, str, str_index, MDNS_MAX_PACKET_SIZE);
if (!part_length) { if (!part_length) {
free(host_dup);
return 0; return 0;
} }
part_length += _mdns_append_u16(packet, index, q->type); part_length += _mdns_append_u16(packet, index, q->type);
part_length += _mdns_append_u16(packet, index, q->unicast ? 0x8001 : 0x0001); part_length += _mdns_append_u16(packet, index, q->unicast ? 0x8001 : 0x0001);
free(host_dup);
return part_length; return part_length;
} }
@ -1213,17 +1221,17 @@ static uint8_t _mdns_append_host_answer(uint8_t *packet, uint16_t *index, mdns_h
return num_records; return num_records;
} }
static uint16_t _mdns_append_rev_ptr_record(uint8_t * packet, uint16_t * index, const char* name, bool flush, bool bye) static uint16_t _mdns_append_rev_ptr_record(uint8_t *packet, uint16_t *index, const char *name, bool flush, bool bye)
{ {
const char * str[6]; const char *str[6];
int i = 0; int i = 0;
if (strstr(name, "in-addr") == NULL) { if (strstr(name, "in-addr") == NULL) {
return 0; return 0;
} }
char * host = strdup(name); char *host = strdup(name);
char *rest = NULL; char *rest = NULL;
for (char *p = strtok_r(host,".", &rest); p != NULL; p = strtok_r(NULL, ".", &rest)) { for (char *p = strtok_r(host, ".", &rest); p != NULL; p = strtok_r(NULL, ".", &rest)) {
str[i++] = p; str[i++] = p;
} }
str[i++] = "arpa"; str[i++] = "arpa";
@ -1236,7 +1244,7 @@ static uint16_t _mdns_append_rev_ptr_record(uint8_t * packet, uint16_t * index,
} }
record_length += part_length; record_length += part_length;
part_length = _mdns_append_type(packet, index, MDNS_ANSWER_PTR, false, bye?0:MDNS_ANSWER_PTR_TTL); part_length = _mdns_append_type(packet, index, MDNS_ANSWER_PTR, false, bye ? 0 : MDNS_ANSWER_PTR_TTL);
if (!part_length) { if (!part_length) {
return 0; return 0;
} }
@ -1258,7 +1266,7 @@ static uint16_t _mdns_append_rev_ptr_record(uint8_t * packet, uint16_t * index,
} }
static uint8_t _mdns_append_reverse_ptr_record(uint8_t *packet, uint16_t *index, const char* name, bool flush, bool bye) static uint8_t _mdns_append_reverse_ptr_record(uint8_t *packet, uint16_t *index, const char *name, bool flush, bool bye)
{ {
uint8_t appended_answers = 0; uint8_t appended_answers = 0;
@ -1711,9 +1719,9 @@ static bool _mdns_create_answer_from_service(mdns_tx_packet_t *packet, mdns_serv
return true; return true;
} }
static bool _mdns_create_answer_from_reverse_query(mdns_tx_packet_t * packet, const char * hostname, bool send_flush) static bool _mdns_create_answer_from_reverse_query(mdns_tx_packet_t *packet, const char *hostname, bool send_flush)
{ {
mdns_host_item_t * host = mdns_get_host_item(hostname); mdns_host_item_t *host = mdns_get_host_item(hostname);
if (!_mdns_alloc_answer(&packet->answers, MDNS_TYPE_PTR, NULL, host, send_flush, false)) { if (!_mdns_alloc_answer(&packet->answers, MDNS_TYPE_PTR, NULL, host, send_flush, false)) {
return false; return false;
} }
@ -3394,6 +3402,7 @@ void mdns_parse_packet(mdns_rx_packet_t *packet)
mdns_debug_packet(data, len); mdns_debug_packet(data, len);
#endif #endif
#ifndef CONFIG_MDNS_SKIP_SUPPRESSING_OWN_QUERIES
// Check if the packet wasn't sent by us // Check if the packet wasn't sent by us
if (packet->ip_protocol == MDNS_IP_PROTOCOL_V4) { if (packet->ip_protocol == MDNS_IP_PROTOCOL_V4) {
esp_netif_ip_info_t if_ip_info; esp_netif_ip_info_t if_ip_info;
@ -3410,6 +3419,7 @@ void mdns_parse_packet(mdns_rx_packet_t *packet)
} }
#endif #endif
} }
#endif
// Check for the minimum size of mdns packet // Check for the minimum size of mdns packet
if (len <= MDNS_HEAD_ADDITIONAL_OFFSET) { if (len <= MDNS_HEAD_ADDITIONAL_OFFSET) {
@ -3977,6 +3987,7 @@ static inline void post_mdns_announce_pcb(mdns_predef_if_t preset_if, mdns_ip_pr
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); 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);
} }
#if CONFIG_MDNS_PREDEF_NETIF_STA || CONFIG_MDNS_PREDEF_NETIF_AP || CONFIG_MDNS_PREDEF_NETIF_ETH
void mdns_preset_if_handle_system_event(void *arg, esp_event_base_t event_base, void mdns_preset_if_handle_system_event(void *arg, esp_event_base_t event_base,
int32_t event_id, void *event_data) int32_t event_id, void *event_data)
{ {
@ -4054,6 +4065,7 @@ void mdns_preset_if_handle_system_event(void *arg, esp_event_base_t event_base,
} }
} }
} }
#endif /* CONFIG_MDNS_PREDEF_NETIF_STA || CONFIG_MDNS_PREDEF_NETIF_AP || CONFIG_MDNS_PREDEF_NETIF_ETH */
/* /*
* MDNS Search * MDNS Search
@ -6151,19 +6163,19 @@ void mdns_debug_packet(const uint8_t *data, size_t len)
_mdns_dbg_printf("Packet[%u]: ", t); _mdns_dbg_printf("Packet[%u]: ", t);
header.id = _mdns_read_u16(data, MDNS_HEAD_ID_OFFSET); header.id = _mdns_read_u16(data, MDNS_HEAD_ID_OFFSET);
header.flags.value = _mdns_read_u16(data, MDNS_HEAD_FLAGS_OFFSET); header.flags = _mdns_read_u16(data, MDNS_HEAD_FLAGS_OFFSET);
header.questions = _mdns_read_u16(data, MDNS_HEAD_QUESTIONS_OFFSET); header.questions = _mdns_read_u16(data, MDNS_HEAD_QUESTIONS_OFFSET);
header.answers = _mdns_read_u16(data, MDNS_HEAD_ANSWERS_OFFSET); header.answers = _mdns_read_u16(data, MDNS_HEAD_ANSWERS_OFFSET);
header.servers = _mdns_read_u16(data, MDNS_HEAD_SERVERS_OFFSET); header.servers = _mdns_read_u16(data, MDNS_HEAD_SERVERS_OFFSET);
header.additional = _mdns_read_u16(data, MDNS_HEAD_ADDITIONAL_OFFSET); header.additional = _mdns_read_u16(data, MDNS_HEAD_ADDITIONAL_OFFSET);
_mdns_dbg_printf("%s", _mdns_dbg_printf("%s",
(header.flags.value == MDNS_FLAGS_QR_AUTHORITATIVE) ? "AUTHORITATIVE\n" : (header.flags == MDNS_FLAGS_QR_AUTHORITATIVE) ? "AUTHORITATIVE\n" :
(header.flags.value == MDNS_FLAGS_DISTRIBUTED) ? "DISTRIBUTED\n" : (header.flags == MDNS_FLAGS_DISTRIBUTED) ? "DISTRIBUTED\n" :
(header.flags.value == 0) ? "\n" : " " (header.flags == 0) ? "\n" : " "
); );
if (header.flags.value && header.flags.value != MDNS_FLAGS_QR_AUTHORITATIVE) { if (header.flags && header.flags != MDNS_FLAGS_QR_AUTHORITATIVE) {
_mdns_dbg_printf("0x%04X\n", header.flags.value); _mdns_dbg_printf("0x%04X\n", header.flags);
} }
if (header.questions) { if (header.questions) {

View File

@ -14,10 +14,10 @@
#include "freertos/queue.h" #include "freertos/queue.h"
#include "freertos/semphr.h" #include "freertos/semphr.h"
#include "esp_timer.h" #include "esp_timer.h"
#include "esp_system.h"
//#define MDNS_ENABLE_DEBUG #ifdef CONFIG_MDNS_ENABLE_DEBUG_PRINTS
#define MDNS_ENABLE_DEBUG
#ifdef MDNS_ENABLE_DEBUG
#define _mdns_dbg_printf(...) printf(__VA_ARGS__) #define _mdns_dbg_printf(...) printf(__VA_ARGS__)
#endif #endif

View File

@ -1,5 +1,7 @@
cmake_minimum_required(VERSION 3.5) cmake_minimum_required(VERSION 3.5)
set(EXTRA_COMPONENT_DIRS "../..")
include($ENV{IDF_PATH}/tools/cmake/project.cmake) include($ENV{IDF_PATH}/tools/cmake/project.cmake)
set(COMPONENTS main) set(COMPONENTS main esp_netif_linux)
project(mdns_host) project(mdns_host)

View File

@ -1,7 +1,10 @@
# Setup dummy network interfaces # Setup dummy network interfaces
Note: Set two addresses so we could use one as source and another as destination
``` ```
sudo ip link add eth2 type dummy sudo ip link add eth2 type dummy
sudo ip addr add 192.168.1.200/24 dev eth2 sudo ip addr add 192.168.1.200/24 dev eth2
sudo ip addr add 192.168.1.201/24 dev eth2
sudo ip link set eth2 up sudo ip link set eth2 up
sudo ifconfig eth2 multicast sudo ifconfig eth2 multicast
``` ```
@ -12,6 +15,11 @@ sudo ifconfig eth2 multicast
dig +short -b 192.168.1.200 -p 5353 @224.0.0.251 myesp.local dig +short -b 192.168.1.200 -p 5353 @224.0.0.251 myesp.local
``` ```
or a reverse query:
```
dig +short -b 192.168.2.200 -p 5353 @224.0.0.251 -x 192.168.1.200
```
# Run avahi to browse services # Run avahi to browse services
Avahi needs the netif to have the "multicast" flag set Avahi needs the netif to have the "multicast" flag set

View File

@ -1,3 +1,3 @@
idf_component_register(SRCS esp_event_mock.c idf_component_register(SRCS esp_event_mock.c
INCLUDE_DIRS include INCLUDE_DIRS include
REQUIRES esp_system_protocols_linux) REQUIRES)

View File

@ -8,16 +8,12 @@
#include "stdbool.h" #include "stdbool.h"
#include "esp_err.h" #include "esp_err.h"
#include "esp_event_base.h" #include "esp_event_base.h"
#include "bsd_strings.h" //#include "bsd_strings.h"
#define ESP_EVENT_DECLARE_BASE(x)
#define ESP_EVENT_ANY_ID (-1)
typedef void *esp_event_base_t;
typedef void *system_event_t;
const char *WIFI_EVENT; //const char *WIFI_EVENT;
const char *IP_EVENT; //const char *IP_EVENT;
esp_err_t esp_event_handler_register(const char *event_base, int32_t event_id, void *event_handler, void *event_handler_arg); esp_err_t esp_event_handler_register(const char *event_base, int32_t event_id, void *event_handler, void *event_handler_arg);

View File

@ -11,3 +11,9 @@ typedef enum {
WIFI_EVENT_AP_START, /**< ESP32 soft-AP start */ WIFI_EVENT_AP_START, /**< ESP32 soft-AP start */
WIFI_EVENT_AP_STOP, /**< ESP32 soft-AP stop */ WIFI_EVENT_AP_STOP, /**< ESP32 soft-AP stop */
} mdns_used_event_t; } mdns_used_event_t;
#define ESP_EVENT_DECLARE_BASE(x)
#define ESP_EVENT_ANY_ID (-1)
typedef void *esp_event_base_t;
typedef void *system_event_t;

View File

@ -1,3 +1,3 @@
idf_component_register(SRCS esp_netif_linux.c idf_component_register(SRCS esp_netif_linux.c
INCLUDE_DIRS include INCLUDE_DIRS include $ENV{IDF_PATH}/components/esp_netif/include
REQUIRES esp_system_protocols_linux) REQUIRES esp_event)

View File

@ -50,9 +50,7 @@ esp_err_t esp_netif_get_ip_info(esp_netif_t *esp_netif, esp_netif_ip_info_t *ip_
struct sockaddr_in *pAddr = (struct sockaddr_in *) tmp->ifa_addr; struct sockaddr_in *pAddr = (struct sockaddr_in *) tmp->ifa_addr;
inet_ntop(AF_INET, &pAddr->sin_addr, addr, sizeof(addr) ); inet_ntop(AF_INET, &pAddr->sin_addr, addr, sizeof(addr) );
if (strcmp(esp_netif->if_desc, tmp->ifa_name) == 0) { if (strcmp(esp_netif->if_desc, tmp->ifa_name) == 0) {
printf("AF_INET: %s: %s\n", tmp->ifa_name, addr);
memcpy(&ip_info->ip.addr, &pAddr->sin_addr, 4); memcpy(&ip_info->ip.addr, &pAddr->sin_addr, 4);
break;
} }
} }
tmp = tmp->ifa_next; tmp = tmp->ifa_next;

View File

@ -1,3 +0,0 @@
idf_component_register(SRCS esp_log_impl.c strlcat.c
INCLUDE_DIRS include
REQUIRES esp_netif_linux esp_timer_linux freertos_linux esp_event_mock esp_netif log esp_common)

View File

@ -1,27 +0,0 @@
/*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "esp_err.h"
#include "esp_log.h"
#include <stdlib.h>
void _esp_error_check_failed(esp_err_t rc, const char *file, int line, const char *function, const char *expression)
{
ESP_LOGE("ESP_ERROR_CHECK", "Failed with esp_err_t: 0x%x", rc);
ESP_LOGE("ESP_ERROR_CHECK", "Expression: %s", expression);
ESP_LOGE("ESP_ERROR_CHECK", "Functions: %s %s(%d)", function, file, line);
abort();
}
void esp_log_buffer_hexdump_internal(const char *tag, const void *buffer, uint16_t buff_len, esp_log_level_t log_level)
{
if ( LOG_LOCAL_LEVEL >= log_level ) {
ESP_LOG_LEVEL(log_level, tag, "Buffer:%p length:%d", buffer, buff_len);
for (int i = 0; i < buff_len; ++i) {
printf("%02x ", ((uint8_t *)buffer)[i]);
}
printf("\n");
}
}

View File

@ -1,8 +0,0 @@
/*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
size_t strlcat(char *dest, const char *src, size_t size);

View File

@ -1,70 +0,0 @@
/* $OpenBSD: strlcat.c,v 1.2 1999/06/17 16:28:58 millert Exp $ */
/*-
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "string.h"
/*
* Appends src to string dst of size siz (unlike strncat, siz is the
* full size of dst, not space left). At most siz-1 characters
* will be copied. Always NUL terminates (unless siz <= strlen(dst)).
* Returns strlen(src) + MIN(siz, strlen(initial dst)).
* If retval >= siz, truncation occurred.
*/
size_t
strlcat(dst, src, siz)
char *dst;
const char *src;
size_t siz;
{
char *d = dst;
const char *s = src;
size_t n = siz;
size_t dlen;
/* Find the end of dst and adjust bytes left but don't go past end */
while (n-- != 0 && *d != '\0') {
d++;
}
dlen = d - dst;
n = siz - dlen;
if (n == 0) {
return (dlen + strlen(s));
}
while (*s != '\0') {
if (n != 1) {
*d++ = *s;
n--;
}
s++;
}
*d = '\0';
return (dlen + (s - src)); /* count does not include NUL */
}

View File

@ -1,6 +1,6 @@
idf_component_register(SRCS esp_timer_linux.c timer_task.cpp idf_component_register(SRCS esp_timer_linux.c timer_task.cpp
INCLUDE_DIRS include INCLUDE_DIRS include
REQUIRES esp_system_protocols_linux freertos_linux) REQUIRES esp_event)
set_target_properties(${COMPONENT_LIB} PROPERTIES set_target_properties(${COMPONENT_LIB} PROPERTIES
CXX_STANDARD 17 CXX_STANDARD 17

View File

@ -16,7 +16,7 @@ typedef void (*cb_t)(void *arg);
class TimerTaskMock { class TimerTaskMock {
public: public:
TimerTaskMock(cb_t cb): cb(cb), t(run_static, this), active(false), ms(INT32_MAX) {} TimerTaskMock(cb_t cb): cb(cb), active(false), ms(INT32_MAX) {}
~TimerTaskMock(void) ~TimerTaskMock(void)
{ {
active = false; active = false;
@ -27,6 +27,7 @@ public:
{ {
ms = m; ms = m;
active = true; active = true;
t = std::thread(run_static, this);
} }
private: private:

View File

@ -1,6 +1,6 @@
idf_component_register(SRCS freertos_linux.c queue_unique_ptr.cpp idf_component_register(SRCS freertos_linux.c queue_unique_ptr.cpp
INCLUDE_DIRS include INCLUDE_DIRS include
REQUIRES esp_system_protocols_linux) REQUIRES)
set(THREADS_PREFER_PTHREAD_FLAG ON) set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED) find_package(Threads REQUIRED)

View File

@ -158,15 +158,15 @@ void xTaskCreate(TaskFunction_t pvTaskCode, const char *const pcName, const uint
} }
} }
uint32_t esp_get_free_heap_size(void) //uint32_t esp_get_free_heap_size(void)
{ //{
return 0; // return 0;
} //}
//
uint32_t esp_random(void) //uint32_t esp_random(void)
{ //{
return rand(); // return rand();
} //}
void xTaskNotifyGive(TaskHandle_t task) void xTaskNotifyGive(TaskHandle_t task)
{ {

View File

@ -32,3 +32,4 @@ typedef int BaseType_t;
uint32_t esp_get_free_heap_size(void); uint32_t esp_get_free_heap_size(void);
uint32_t esp_random(void); uint32_t esp_random(void);
void vTaskSuspendAll(void);

View File

@ -0,0 +1,13 @@
/*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
//
// Created by david on 1/13/23.
//
#ifndef _QUEUE_H_
#define _QUEUE_H_
#endif //_QUEUE_H_

View File

@ -0,0 +1,13 @@
/*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
//
// Created by david on 1/13/23.
//
#ifndef _SEMAPHR_H_
#define _SEMAPHR_H_
#endif //_SEMAPHR_H_

View File

@ -0,0 +1,15 @@
menu "Test Configuration"
config TEST_HOSTNAME
string "mDNS Hostname"
default "esp32-mdns"
help
mDNS Hostname for example to use
config TEST_NETIF_NAME
string "Network interface name"
default "eth2"
help
Name/ID if the network interface on which we run the mDNS host test
endmenu

View File

@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Unlicense OR CC0-1.0 * SPDX-License-Identifier: Unlicense OR CC0-1.0
*/ */
@ -35,27 +35,34 @@ int main(int argc, char *argv[])
{ {
setvbuf(stdout, NULL, _IONBF, 0); setvbuf(stdout, NULL, _IONBF, 0);
const esp_netif_inherent_config_t base_cg = { .if_key = "WIFI_STA_DEF", .if_desc = "eth2" }; const esp_netif_inherent_config_t base_cg = { .if_key = "WIFI_STA_DEF", .if_desc = CONFIG_TEST_NETIF_NAME };
esp_netif_config_t cfg = { .base = &base_cg }; esp_netif_config_t cfg = { .base = &base_cg };
esp_netif_t *sta = esp_netif_new(&cfg); esp_netif_t *sta = esp_netif_new(&cfg);
ESP_ERROR_CHECK(mdns_init());
ESP_ERROR_CHECK(mdns_register_netif(sta));
ESP_ERROR_CHECK(mdns_netif_action(sta, MDNS_EVENT_ENABLE_IP4));
mdns_init(); mdns_hostname_set(CONFIG_TEST_HOSTNAME);
ESP_LOGI(TAG, "mdns hostname set to: [%s]", CONFIG_TEST_HOSTNAME);
mdns_ip_addr_t addr4 = { .addr.u_addr.ip4.addr = 0x1020304 };
addr4.addr.type = ESP_IPADDR_TYPE_V4;
const char *delegated_hostname = "200.0.168.192.in-addr";
addr4.addr.type = ESP_IPADDR_TYPE_V4;
ESP_ERROR_CHECK( mdns_delegate_hostname_add(delegated_hostname, &addr4) );
mdns_hostname_set("myesp");
ESP_LOGI(TAG, "mdns hostname set to: [%s]", "myesp");
//set default mDNS instance name //set default mDNS instance name
mdns_instance_name_set("myesp-inst"); //mdns_instance_name_set("myesp-inst");
//structure with TXT records //structure with TXT records
mdns_txt_item_t serviceTxtData[3] = { // mdns_txt_item_t serviceTxtData[3] = {
{"board", "esp32"}, // {"board", "esp32"},
{"u", "user"}, // {"u", "user"},
{"p", "password"} // {"p", "password"}
}; // };
vTaskDelay(1000); // vTaskDelay(pdMS_TO_TICKS(1000));
ESP_ERROR_CHECK(mdns_service_add("myesp-service2", "_http", "_tcp", 80, serviceTxtData, 3)); vTaskDelay(pdMS_TO_TICKS(10000));
vTaskDelay(2000); // ESP_ERROR_CHECK(mdns_service_add("myesp-service2", "_http", "_tcp", 80, serviceTxtData, 3));
// vTaskDelay(2000);
query_mdns_host("david-comp"); query_mdns_host("david-work");
vTaskDelay(2000); vTaskDelay(2000);
esp_netif_destroy(sta); esp_netif_destroy(sta);
mdns_free(); mdns_free();

View File

@ -0,0 +1,5 @@
sudo ip link add eth2 type dummy
sudo ip addr add 192.168.1.200/24 dev eth2
sudo ip addr add 192.168.1.201/24 dev eth2
sudo ip link set eth2 up
sudo ifconfig eth2 multicast

View File

@ -0,0 +1,7 @@
CONFIG_IDF_TARGET="linux"
CONFIG_MDNS_NETWORKING_SOCKET=y
CONFIG_MDNS_SKIP_SUPPRESSING_OWN_QUERIES=y
CONFIG_TEST_NETIF_NAME="eth0"
CONFIG_TEST_HOSTNAME="myesp"
# CONFIG_MDNS_PREDEF_NETIF_STA is not set
# CONFIG_MDNS_PREDEF_NETIF_AP is not set