diff --git a/components/openthread/include/esp_openthread_border_router.h b/components/openthread/include/esp_openthread_border_router.h index 6fe915bc53..e78c28bddd 100644 --- a/components/openthread/include/esp_openthread_border_router.h +++ b/components/openthread/include/esp_openthread_border_router.h @@ -76,6 +76,14 @@ esp_netif_t *esp_openthread_get_backbone_netif(void); */ esp_err_t esp_openthread_set_meshcop_instance_name(const char *instance_name); +/** + * @brief Gets the meshcop(e) instance name. + * + * @return The instance name. + * + */ +const char* esp_openthread_get_meshcop_instance_name(void); + #ifdef __cplusplus } #endif diff --git a/components/openthread/include/esp_openthread_meshcop_mdns.h b/components/openthread/include/esp_openthread_meshcop_mdns.h new file mode 100644 index 0000000000..4e2c5926fa --- /dev/null +++ b/components/openthread/include/esp_openthread_meshcop_mdns.h @@ -0,0 +1,41 @@ +/* + * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include "esp_openthread.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Publishes the OpenThread meshcop service in mDNS + * + * @param[in] instance_name Instance name of meshcop mDNS service + * + * @return + * - ESP_OK success + * - ESP_ERR_NO_MEM memory error + * - ESP_FAIL failed to add service + * + */ +esp_err_t esp_openthread_publish_meshcop_mdns(const char *instance_name); + +/** + * @brief Removes the OpenThread meshcop service in mDNS + * + * @return + * - ESP_OK success + * - ESP_ERR_NO_MEM memory error + * - ESP_FAIL failed to remove service + * + */ +esp_err_t esp_openthread_remove_meshcop_mdns(void); + +#ifdef __cplusplus +} +#endif diff --git a/components/openthread/lib b/components/openthread/lib index 459448381b..fff1e900a1 160000 --- a/components/openthread/lib +++ b/components/openthread/lib @@ -1 +1 @@ -Subproject commit 459448381b89b7c8e82480e4836d0dc32eb9c68b +Subproject commit fff1e900a1169e76ea06246100f81d005d5f7f44 diff --git a/components/openthread/openthread b/components/openthread/openthread index ec2b0d4873..b945928d72 160000 --- a/components/openthread/openthread +++ b/components/openthread/openthread @@ -1 +1 @@ -Subproject commit ec2b0d487356d2955346457a6515201039140037 +Subproject commit b945928d722177cd9caeab2e1025499628c101ef diff --git a/components/openthread/private_include/esp_openthread_state.h b/components/openthread/private_include/esp_openthread_state.h index e2ee350805..91d69c4283 100644 --- a/components/openthread/private_include/esp_openthread_state.h +++ b/components/openthread/private_include/esp_openthread_state.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -10,6 +10,11 @@ #include #include +#define ESP_OPENTHREAD_BORDER_ROUTER_FLAG_OF_INTEREST \ + (OT_CHANGED_THREAD_ROLE | OT_CHANGED_THREAD_EXT_PANID | OT_CHANGED_THREAD_NETWORK_NAME | \ + OT_CHANGED_ACTIVE_DATASET | OT_CHANGED_THREAD_PARTITION_ID | OT_CHANGED_THREAD_BACKBONE_ROUTER_STATE | \ + OT_CHANGED_PSKC) + #ifdef __cplusplus extern "C" { #endif diff --git a/components/openthread/sbom_openthread.yml b/components/openthread/sbom_openthread.yml index 789349f827..51447eac61 100644 --- a/components/openthread/sbom_openthread.yml +++ b/components/openthread/sbom_openthread.yml @@ -5,4 +5,4 @@ supplier: 'Organization: Espressif Systems (Shanghai) CO LTD' originator: 'Organization: Google LLC' description: OpenThread released by Google is an open-source implementation of the Thread networking url: https://github.com/espressif/openthread -hash: ec2b0d487356d2955346457a6515201039140037 +hash: b945928d722177cd9caeab2e1025499628c101ef diff --git a/components/openthread/src/port/esp_openthread_state.c b/components/openthread/src/port/esp_openthread_state.c index 153d343ea1..bc2641d905 100644 --- a/components/openthread/src/port/esp_openthread_state.c +++ b/components/openthread/src/port/esp_openthread_state.c @@ -10,7 +10,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -19,6 +21,19 @@ #define TAG "OT_STATE" +#if CONFIG_OPENTHREAD_BORDER_ROUTER +static void handle_ot_border_router_state_changed(otInstance* instance) +{ + otDeviceRole role = otThreadGetDeviceRole(esp_openthread_get_instance()); + + if (role == OT_DEVICE_ROLE_CHILD || role == OT_DEVICE_ROLE_ROUTER || role == OT_DEVICE_ROLE_LEADER) { + esp_openthread_publish_meshcop_mdns(esp_openthread_get_meshcop_instance_name()); + } else { + esp_openthread_remove_meshcop_mdns(); + } +} +#endif + static void handle_ot_netif_state_change(otInstance* instance) { if (otIp6IsEnabled(instance)) { @@ -123,6 +138,12 @@ static void ot_state_change_callback(otChangedFlags changed_flags, void* ctx) return; } +#if CONFIG_OPENTHREAD_BORDER_ROUTER + if (changed_flags & ESP_OPENTHREAD_BORDER_ROUTER_FLAG_OF_INTEREST) { + handle_ot_border_router_state_changed(instance); + } +#endif + if (changed_flags & OT_CHANGED_THREAD_ROLE) { handle_ot_role_change(instance); }