From d9b8ae74f68ad11f8bc1f99d973e6616f097d36f Mon Sep 17 00:00:00 2001 From: WanqQixiang Date: Fri, 16 May 2025 19:00:40 +0800 Subject: [PATCH] submodule: Update connectedhomeip to f1f3a55c9b esp_matter: Add support for disabling/enabling ICD server dynamically --- .gitlab-ci.yml | 2 +- README.md | 2 +- components/esp_matter/CMakeLists.txt | 4 ++++ components/esp_matter/esp_matter_core.cpp | 23 ++++++++++++++++++- components/esp_matter/esp_matter_endpoint.cpp | 11 +++++---- .../esp_matter_icd_configuration.cpp | 20 +++++++++++++--- .../esp_matter/esp_matter_icd_configuration.h | 9 ++++++++ connectedhomeip/connectedhomeip | 2 +- 8 files changed, 62 insertions(+), 11 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 94e6abd99..4b186de07 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -25,7 +25,7 @@ variables: IDF_CHECKOUT_REF: "v5.4.1" # This variable represents the short hash of the connectedhomeip submodule. # Note: Do change this short hash on submodule update MRs. - CHIP_SHORT_HASH: "19aeeb3ba0" + CHIP_SHORT_HASH: "f1f3a55c9b" DOCKER_IMAGE_NAME: "espressif/chip-idf" .add_gitlab_ssh_key: &add_gitlab_ssh_key | diff --git a/README.md b/README.md index 7fd510c15..b5d2213bf 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ section in the ESP-Matter Programming Guide. ## Supported ESP-IDF and connectedhomeip versions -- This SDK currently works with commit [19aeeb3ba0](https://github.com/project-chip/connectedhomeip/tree/19aeeb3ba0) of connectedhomeip. +- This SDK currently works with commit [f1f3a55c9b](https://github.com/project-chip/connectedhomeip/tree/f1f3a55c9b) of connectedhomeip. - For Matter projects development with this SDK, it is recommended to utilize ESP-IDF [v5.4.1](https://github.com/espressif/esp-idf/tree/v5.4.1). ## Documentation diff --git a/components/esp_matter/CMakeLists.txt b/components/esp_matter/CMakeLists.txt index 10ec0a947..cc74529ac 100644 --- a/components/esp_matter/CMakeLists.txt +++ b/components/esp_matter/CMakeLists.txt @@ -36,6 +36,10 @@ endif() set(REQUIRES_LIST chip bt esp_matter_console nvs_flash app_update esp_secure_cert_mgr mbedtls esp_system openthread json) +if ("${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}" VERSION_GREATER_EQUAL "5.0") + list(APPEND REQUIRES_LIST esp_rcp_update) +endif() + idf_component_register( SRC_DIRS ${SRC_DIRS_LIST} INCLUDE_DIRS ${INCLUDE_DIRS_LIST} EXCLUDE_SRCS ${EXCLUDE_SRCS_LIST} diff --git a/components/esp_matter/esp_matter_core.cpp b/components/esp_matter/esp_matter_core.cpp index 40b9e8cfa..11630852f 100644 --- a/components/esp_matter/esp_matter_core.cpp +++ b/components/esp_matter/esp_matter_core.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -781,6 +782,20 @@ static void esp_matter_chip_init_task(intptr_t context) if (GetDiagnosticDataProvider().GetBootReason(bootReason) == CHIP_NO_ERROR) { chip::app::Clusters::GeneralDiagnosticsServer::Instance().OnDeviceReboot(bootReason); } + +#if CHIP_CONFIG_ENABLE_ICD_SERVER + if (!icd::get_icd_server_enabled()) { + // ICD server has been initialized in chip::Server::GetInstance().Init(). disable it here if + // icd_server_enabled is set to false. + chip::app::InteractionModelEngine::GetInstance()->SetICDManager(nullptr); + chip::app::DnssdServer::Instance().SetICDManager(nullptr); + chip::TestEventTriggerDelegate *test_event_trigger = chip::Server::GetInstance().GetTestEventTriggerDelegate(); + if (test_event_trigger) { + test_event_trigger->RemoveHandler(&chip::Server::GetInstance().GetICDManager()); + } + chip::Server::GetInstance().GetICDManager().Shutdown(); + } +#endif // CHIP_CONFIG_ENABLE_ICD_SERVER PlatformMgr().ScheduleWork(deinit_ble_if_commissioned, reinterpret_cast(nullptr)); xTaskNotifyGive(task_to_notify); } @@ -839,7 +854,13 @@ static esp_err_t chip_init(event_callback_t callback, intptr_t callback_arg) #ifdef CONFIG_ESP_MATTER_ENABLE_OPENTHREAD VerifyOrReturnError(ThreadStackMgr().InitThreadStack() == CHIP_NO_ERROR, ESP_FAIL, ESP_LOGE(TAG, "Failed to initialize Thread stack")); #if CHIP_CONFIG_ENABLE_ICD_SERVER - VerifyOrReturnError(ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_SleepyEndDevice) == CHIP_NO_ERROR, ESP_FAIL, ESP_LOGE(TAG, "Failed to set the Thread device type")); + if (icd::get_icd_server_enabled()) { + VerifyOrReturnError(ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_SleepyEndDevice) == CHIP_NO_ERROR, + ESP_FAIL, ESP_LOGE(TAG, "Failed to set the Thread device type")); + } else { + VerifyOrReturnError(ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_MinimalEndDevice) == CHIP_NO_ERROR, + ESP_FAIL, ESP_LOGE(TAG, "Failed to set the Thread device type")); + } #elif CHIP_DEVICE_CONFIG_THREAD_FTD VerifyOrReturnError(ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_Router) == CHIP_NO_ERROR, ESP_FAIL, ESP_LOGE(TAG, "Failed to set the Thread device type")); diff --git a/components/esp_matter/esp_matter_endpoint.cpp b/components/esp_matter/esp_matter_endpoint.cpp index 3577ed2a1..a3168cdad 100644 --- a/components/esp_matter/esp_matter_endpoint.cpp +++ b/components/esp_matter/esp_matter_endpoint.cpp @@ -15,6 +15,7 @@ #include #include #include +#include static const char *TAG = "esp_matter_endpoint"; @@ -80,17 +81,19 @@ esp_err_t add(endpoint_t *endpoint, config_t *config) group_key_management::create(endpoint, CLUSTER_FLAG_SERVER); #if CHIP_CONFIG_ENABLE_ICD_SERVER - icd_management::create(endpoint, &(config->icd_management), CLUSTER_FLAG_SERVER, + if (icd::get_icd_server_enabled()) { + icd_management::create(endpoint, &(config->icd_management), CLUSTER_FLAG_SERVER, #if CHIP_CONFIG_ENABLE_ICD_LIT - icd_management::feature::long_idle_time_support::get_id() | + icd_management::feature::long_idle_time_support::get_id() | #if CHIP_CONFIG_ENABLE_ICD_CIP - icd_management::feature::check_in_protocol_support::get_id() | + icd_management::feature::check_in_protocol_support::get_id() | #endif // CHIP_CONFIG_ENABLE_ICD_CIP #if CHIP_CONFIG_ENABLE_ICD_UAT - icd_management::feature::user_active_mode_trigger::get_id() | + icd_management::feature::user_active_mode_trigger::get_id() | #endif // CHIP_CONFIG_ENABLE_ICD_UAT #endif // CHIP_CONFIG_ENABLE_ICD_LIT 0); + } #endif // CHIP_CONFIG_ENABLE_ICD_SERVER return ESP_OK; } diff --git a/components/esp_matter/esp_matter_icd_configuration.cpp b/components/esp_matter/esp_matter_icd_configuration.cpp index 60a869412..7001a3b05 100644 --- a/components/esp_matter/esp_matter_icd_configuration.cpp +++ b/components/esp_matter/esp_matter_icd_configuration.cpp @@ -107,17 +107,31 @@ static esp_err_t set_active_threshold(uint32_t active_threshold_ms) return chip::Test::ICDConfigurationDataTestAccess::SetActiveThreshold(Milliseconds32(active_threshold_ms)); } +static bool s_enable_icd_server = true; + +bool get_icd_server_enabled() +{ + return s_enable_icd_server; +} + esp_err_t set_configuration_data(config_t *config) { + ESP_RETURN_ON_FALSE(config, ESP_ERR_INVALID_ARG, TAG, "config cannot be NULL"); + if (!config->enable_icd_server) { + ESP_RETURN_ON_FALSE(!node::get(), ESP_ERR_INVALID_STATE, TAG, + "Could not disable ICD server after data model is created"); + } + s_enable_icd_server = config->enable_icd_server; ESP_RETURN_ON_FALSE(!is_started(), ESP_ERR_INVALID_STATE, TAG, "Could not change ICD configuration data after Matter is started"); - ESP_RETURN_ON_FALSE(config, ESP_ERR_INVALID_ARG, TAG, "config cannot be NULL"); ESP_RETURN_ON_ERROR(set_polling_intervals(config->fast_interval_ms, config->slow_interval_ms), TAG, "Failed to set polling intervals"); ESP_RETURN_ON_ERROR(set_mode_durations(config->active_mode_duration_ms, config->idle_mode_duration_s), TAG, "Failed to set mode durations"); - ESP_RETURN_ON_ERROR(set_active_threshold(config->active_threshold_ms.value()), TAG, - "Failed to set active threshold"); + if (config->active_threshold_ms.has_value()) { + ESP_RETURN_ON_ERROR(set_active_threshold(config->active_threshold_ms.value()), TAG, + "Failed to set active threshold"); + } return ESP_OK; } diff --git a/components/esp_matter/esp_matter_icd_configuration.h b/components/esp_matter/esp_matter_icd_configuration.h index 59f98efd1..60a131484 100644 --- a/components/esp_matter/esp_matter_icd_configuration.h +++ b/components/esp_matter/esp_matter_icd_configuration.h @@ -19,6 +19,7 @@ namespace esp_matter { namespace icd { typedef struct config { + bool enable_icd_server; std::optional fast_interval_ms; std::optional slow_interval_ms; std::optional active_mode_duration_ms; @@ -26,6 +27,14 @@ typedef struct config { std::optional active_threshold_ms; } config_t; +/** Get whether ICD server is enabled for Matter end-device + */ +bool get_icd_server_enabled(); + +/** Set ICD configuration data + * + * This function allows the user to enable or disable the ICD server and configure its settings at runtime, before creating the Matter data model. + */ esp_err_t set_configuration_data(config_t *config); } // namespace icd diff --git a/connectedhomeip/connectedhomeip b/connectedhomeip/connectedhomeip index 19aeeb3ba..f1f3a55c9 160000 --- a/connectedhomeip/connectedhomeip +++ b/connectedhomeip/connectedhomeip @@ -1 +1 @@ -Subproject commit 19aeeb3ba072250b47c21cd242e657d5949a97d3 +Subproject commit f1f3a55c9b7ab8f07a6d96a28190b02ec3d4939e