Compare commits

..

10 Commits

Author SHA1 Message Date
ee2fbbbee7 Merge pull request #756 from david-cermak/feat/mdns_alloc_task
[mdns]: support allocating mDNS task with caps
2025-02-10 11:50:59 +01:00
cb061c9c38 bump(mdns): 1.5.3 -> 1.6.0
1.6.0
Features
- support allocating mDNS task from SPIRAM (8fcad10c)
Bug Fixes
- Use correct task delete function (eb4ab524)
Updated
- ci(mdns): Fix mdns host test layers with static task creation (0690eba3)
2025-02-10 11:18:55 +01:00
0690eba3a8 ci(mdns): Fix mdns host test layers with static task creation 2025-02-10 11:18:19 +01:00
eb4ab52487 fix(mdns): Use correct task delete function 2025-02-10 11:18:19 +01:00
zwx
8fcad10ccf feat(mdns): support allocating mDNS task from SPIRAM 2025-02-10 11:18:19 +01:00
936e43f9d8 Merge pull request #758 from david-cermak/fix/mdns_ignore_only_invalid_queries
[mdns]: Fix the responder to ignore only invalid queries
2025-02-07 15:11:14 +01:00
64d818b2d3 bump(mdns): 1.5.2 -> 1.5.3
1.5.3
Bug Fixes
- Fix responder to ignore only invalid queries (cd07228f, #754)
2025-02-07 14:31:18 +01:00
cd07228f81 fix(mdns): Fix responder to ignore only invalid queries
not the entire packet, so we can still reply to next questions

Closes https://github.com/espressif/esp-protocols/issues/754
2025-02-07 14:30:10 +01:00
1c6580e22b Merge pull request #753 from david-cermak/fix/ci_mosq
[mosquitto]: Fix minor CI issue
2025-02-03 14:54:07 +01:00
87f835af0f fix(mosq): Run IDF build test only on master or labeled PRs 2025-01-31 11:19:00 +01:00
11 changed files with 153 additions and 25 deletions

View File

@ -103,6 +103,9 @@ jobs:
echo "Versions are consistent: $CONFIG_VERSION"
build_idf_tests_with_mosq:
if: |
github.repository == 'espressif/esp-protocols' &&
( contains(github.event.pull_request.labels.*.name, 'mosquitto') || github.event_name == 'push' )
name: Build IDF tests
strategy:
matrix:

View File

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@ -212,6 +212,20 @@ void *pthread_task(void *params)
return NULL;
}
TaskHandle_t xTaskCreateStaticPinnedToCore( TaskFunction_t pxTaskCode,
const char *const pcName,
const uint32_t ulStackDepth,
void *const pvParameters,
UBaseType_t uxPriority,
StackType_t *const puxStackBuffer,
StaticTask_t *const pxTaskBuffer,
const BaseType_t xCoreID )
{
static TaskHandle_t pvCreatedTask;
xTaskCreate(pxTaskCode, pcName, ulStackDepth, pvParameters, uxPriority, &pvCreatedTask);
return pvCreatedTask;
}
BaseType_t xTaskCreatePinnedToCore( TaskFunction_t pvTaskCode,
const char *const pcName,
const uint32_t usStackDepth,

View File

@ -1,11 +1,12 @@
/*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include "freertos/FreeRTOS.h"
#include "esp_heap_caps.h"
#ifdef __cplusplus
extern "C" {
@ -15,6 +16,9 @@ extern "C" {
#define TaskHandle_t TaskHandle_t
#define vSemaphoreDelete( xSemaphore ) vQueueDelete( ( QueueHandle_t ) ( xSemaphore ) )
typedef void *StackType_t;
typedef void *StaticTask_t;
void vTaskDelay( const TickType_t xTicksToDelay );
void xTaskNotifyGive(TaskHandle_t task);
@ -25,6 +29,15 @@ TaskHandle_t xTaskGetCurrentTaskHandle(void);
BaseType_t xTaskNotifyWait(uint32_t bits_entry_clear, uint32_t bits_exit_clear, uint32_t *value, TickType_t wait_time );
TaskHandle_t xTaskCreateStaticPinnedToCore( TaskFunction_t pxTaskCode,
const char *const pcName,
const uint32_t ulStackDepth,
void *const pvParameters,
UBaseType_t uxPriority,
StackType_t *const puxStackBuffer,
StaticTask_t *const pxTaskBuffer,
const BaseType_t xCoreID );
BaseType_t xTaskCreatePinnedToCore( TaskFunction_t pvTaskCode,
const char *const pcName,
const uint32_t usStackDepth,
@ -81,6 +94,9 @@ EventBits_t xEventGroupSetBits( EventGroupHandle_t xEventGroup,
uint32_t xQueueSendToBack(QueueHandle_t xQueue, const void *pvItemToQueue, TickType_t xTicksToWait );
void *heap_caps_malloc( size_t size, uint32_t caps);
void heap_caps_free( void *ptr);
#ifdef __cplusplus
}
#endif //__cplusplus

View File

@ -3,6 +3,6 @@ commitizen:
bump_message: 'bump(mdns): $current_version -> $new_version'
pre_bump_hooks: python ../../ci/changelog.py mdns
tag_format: mdns-v$version
version: 1.5.2
version: 1.6.0
version_files:
- idf_component.yml

View File

@ -1,5 +1,25 @@
# Changelog
## [1.6.0](https://github.com/espressif/esp-protocols/commits/mdns-v1.6.0)
### Features
- support allocating mDNS task from SPIRAM ([8fcad10c](https://github.com/espressif/esp-protocols/commit/8fcad10c))
### Bug Fixes
- Use correct task delete function ([eb4ab524](https://github.com/espressif/esp-protocols/commit/eb4ab524))
### Updated
- ci(mdns): Fix mdns host test layers with static task creation ([0690eba3](https://github.com/espressif/esp-protocols/commit/0690eba3))
## [1.5.3](https://github.com/espressif/esp-protocols/commits/mdns-v1.5.3)
### Bug Fixes
- Fix responder to ignore only invalid queries ([cd07228f](https://github.com/espressif/esp-protocols/commit/cd07228f), [#754](https://github.com/espressif/esp-protocols/issues/754))
## [1.5.2](https://github.com/espressif/esp-protocols/commits/mdns-v1.5.2)
### Bug Fixes

View File

@ -61,6 +61,16 @@ menu "mDNS"
default 0x0 if MDNS_TASK_AFFINITY_CPU0
default 0x1 if MDNS_TASK_AFFINITY_CPU1
choice MDNS_TASK_MEMORY_ALLOC_FROM
prompt "Select mDNS task create on which type of memory"
default MDNS_TASK_CREATE_FROM_INTERNAL
config MDNS_TASK_CREATE_FROM_SPIRAM
bool "mDNS task creates on the SPIRAM"
depends on (SPIRAM_USE_CAPS_ALLOC || SPIRAM_USE_MALLOC)
config MDNS_TASK_CREATE_FROM_INTERNAL
bool "mDNS task creates on the internal RAM"
endchoice
config MDNS_SERVICE_ADD_TIMEOUT_MS
int "mDNS adding service timeout (ms)"
range 10 30000

View File

@ -1,4 +1,4 @@
version: "1.5.2"
version: "1.6.0"
description: "Multicast UDP service used to provide local network service and host discovery."
url: "https://github.com/espressif/esp-protocols/tree/master/components/mdns"
issues: "https://github.com/espressif/esp-protocols/issues"

View File

@ -62,6 +62,7 @@ static const char *TAG = "mdns";
static volatile TaskHandle_t _mdns_service_task_handle = NULL;
static SemaphoreHandle_t _mdns_service_semaphore = NULL;
static StackType_t *_mdns_stack_buffer;
static void _mdns_search_finish_done(void);
static mdns_search_once_t *_mdns_search_find_from(mdns_search_once_t *search, mdns_name_t *name, uint16_t type, mdns_if_t tcpip_if, mdns_ip_protocol_t ip_protocol);
@ -1879,7 +1880,11 @@ static void _mdns_create_answer_from_parsed_packet(mdns_parsed_packet_t *parsed_
shared = q->type == MDNS_TYPE_PTR || q->type == MDNS_TYPE_SDPTR || !parsed_packet->probe;
if (q->type == MDNS_TYPE_SRV || q->type == MDNS_TYPE_TXT) {
mdns_srv_item_t *service = _mdns_get_service_item_instance(q->host, q->service, q->proto, NULL);
if (service == NULL || !_mdns_create_answer_from_service(packet, service->service, q, shared, send_flush)) {
if (service == NULL) { // Service not found, but we continue to the next question
q = q->next;
continue;
}
if (!_mdns_create_answer_from_service(packet, service->service, q, shared, send_flush)) {
_mdns_free_tx_packet(packet);
return;
} else {
@ -5458,6 +5463,26 @@ static esp_err_t _mdns_stop_timer(void)
return err;
}
static esp_err_t _mdns_task_create_with_caps(void)
{
ESP_LOGI(TAG, "mDNS task will be created from %s", MDNS_TASK_MEMORY_LOG);
esp_err_t ret = ESP_OK;
static StaticTask_t mdns_task_buffer;
// Allocate memory for the mDNS task's stack using the MDNS_TASK_MEMORY_CAPS
_mdns_stack_buffer = heap_caps_malloc(MDNS_SERVICE_STACK_DEPTH, MDNS_TASK_MEMORY_CAPS);
ESP_GOTO_ON_FALSE(_mdns_stack_buffer != NULL, ESP_FAIL, err, TAG, "failed to allocate memory for the mDNS task's stack");
_mdns_service_task_handle = xTaskCreateStaticPinnedToCore( _mdns_service_task, "mdns", MDNS_SERVICE_STACK_DEPTH, NULL, MDNS_TASK_PRIORITY, _mdns_stack_buffer, &mdns_task_buffer, MDNS_TASK_AFFINITY );
ESP_GOTO_ON_FALSE(_mdns_service_task_handle != NULL, ESP_FAIL, err, TAG, "failed to create task for the mDNS");
return ret;
err:
heap_caps_free(_mdns_stack_buffer);
return ret;
}
/**
* @brief Start the service thread if not running
*
@ -5467,30 +5492,35 @@ static esp_err_t _mdns_stop_timer(void)
*/
static esp_err_t _mdns_service_task_start(void)
{
esp_err_t ret = ESP_OK;
if (!_mdns_service_semaphore) {
_mdns_service_semaphore = xSemaphoreCreateMutex();
if (!_mdns_service_semaphore) {
return ESP_FAIL;
}
ESP_RETURN_ON_FALSE(_mdns_service_semaphore != NULL, ESP_FAIL, TAG, "Failed to create the mDNS service lock");
}
MDNS_SERVICE_LOCK();
if (_mdns_start_timer()) {
MDNS_SERVICE_UNLOCK();
return ESP_FAIL;
}
ESP_GOTO_ON_ERROR(_mdns_start_timer(), err, TAG, "Failed to start the mDNS service timer");
if (!_mdns_service_task_handle) {
xTaskCreatePinnedToCore(_mdns_service_task, "mdns", MDNS_SERVICE_STACK_DEPTH, NULL, MDNS_TASK_PRIORITY,
(TaskHandle_t *const)(&_mdns_service_task_handle), MDNS_TASK_AFFINITY);
if (!_mdns_service_task_handle) {
_mdns_stop_timer();
MDNS_SERVICE_UNLOCK();
vSemaphoreDelete(_mdns_service_semaphore);
_mdns_service_semaphore = NULL;
return ESP_FAIL;
}
ESP_GOTO_ON_ERROR(_mdns_task_create_with_caps(), err_stop_timer, TAG, "Failed to start the mDNS service task");
#ifdef MDNS_ENABLE_DEBUG
#if !CONFIG_IDF_TARGET_LINUX
StackType_t *mdns_debug_stack_buffer;
StaticTask_t *mdns_debug_task_buffer;
xTaskGetStaticBuffers(_mdns_service_task_handle, &mdns_debug_stack_buffer, &mdns_debug_task_buffer);
_mdns_dbg_printf("mdns_debug_stack_buffer:%p mdns_debug_task_buffer:%p\n", mdns_debug_stack_buffer, mdns_debug_task_buffer);
#endif // CONFIG_IDF_TARGET_LINUX
#endif // MDNS_ENABLE_DEBUG
}
MDNS_SERVICE_UNLOCK();
return ESP_OK;
return ret;
err_stop_timer:
_mdns_stop_timer();
err:
MDNS_SERVICE_UNLOCK();
vSemaphoreDelete(_mdns_service_semaphore);
_mdns_service_semaphore = NULL;
return ret;
}
/**
@ -5737,6 +5767,8 @@ void mdns_free(void)
mdns_service_remove_all();
free_delegated_hostnames();
_mdns_service_task_stop();
// at this point, the service task is deleted, so we can destroy the stack size
heap_caps_free(_mdns_stack_buffer);
for (i = 0; i < MDNS_MAX_INTERFACES; i++) {
for (j = 0; j < MDNS_IP_PROTOCOL_MAX; j++) {
mdns_pcb_deinit_local(i, j);

View File

@ -21,6 +21,21 @@
#define _mdns_dbg_printf(...) printf(__VA_ARGS__)
#endif
#if CONFIG_MDNS_TASK_CREATE_FROM_SPIRAM
#define MDNS_TASK_MEMORY_CAPS (MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT)
#define MDNS_TASK_MEMORY_LOG "SPIRAM"
#endif
#if CONFIG_MDNS_TASK_CREATE_FROM_INTERNAL
#define MDNS_TASK_MEMORY_CAPS (MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT)
#define MDNS_TASK_MEMORY_LOG "internal RAM"
#endif
// Allocate memory from internal heap as default.
#ifndef MDNS_TASK_MEMORY_CAPS
#define MDNS_TASK_MEMORY_CAPS (MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT)
#define MDNS_TASK_MEMORY_LOG "internal RAM"
#endif
/** Number of predefined interfaces */
#ifndef CONFIG_MDNS_PREDEF_NETIF_STA
#define CONFIG_MDNS_PREDEF_NETIF_STA 0

View File

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
@ -125,3 +125,13 @@ uint32_t esp_log_timestamp(void)
{
return 0;
}
void *heap_caps_malloc(size_t size, uint32_t caps)
{
return malloc(size);
}
void heap_caps_free( void *ptr)
{
free(ptr);
}

View File

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@ -38,6 +38,10 @@
#define ESP_ERR_INVALID_RESPONSE 0x108
#define ESP_ERR_INVALID_CRC 0x109
#define MDNS_TASK_MEMORY_LOG "internal RAM"
#define MALLOC_CAP_8BIT (1<<2)
#define MALLOC_CAP_INTERNAL (1<<11)
#define pdTRUE true
#define pdFALSE false
#define pdPASS ( pdTRUE )
@ -62,6 +66,7 @@
#define vSemaphoreDelete(s) free(s)
#define queueQUEUE_TYPE_MUTEX ( ( uint8_t ) 1U
#define xTaskCreatePinnedToCore(a,b,c,d,e,f,g) *(f) = malloc(1)
#define xTaskCreateStaticPinnedToCore(a,b,c,d,e,f,g,h) true
#define vTaskDelay(m) usleep((m)*0)
#define esp_random() (rand()%UINT32_MAX)
@ -79,7 +84,8 @@ typedef void *QueueHandle_t;
typedef void *TaskHandle_t;
typedef int BaseType_t;
typedef uint32_t TickType_t;
typedef void *StackType_t;
typedef void *StaticTask_t;
struct udp_pcb {
uint8_t dummy;
@ -132,5 +138,7 @@ esp_err_t esp_event_handler_unregister(const char *event_base, int32_t event_id,
TaskHandle_t xTaskGetCurrentTaskHandle(void);
void xTaskNotifyGive(TaskHandle_t task);
BaseType_t xTaskNotifyWait(uint32_t bits_entry_clear, uint32_t bits_exit_clear, uint32_t *value, TickType_t wait_time );
void *heap_caps_malloc(size_t size, uint32_t caps);
void heap_caps_free(void *ptr);
#endif //_ESP32_COMPAT_H_