From 0602d32fb4056493578ff0109148c2e7aa661ca3 Mon Sep 17 00:00:00 2001 From: mahesh Date: Tue, 29 Jul 2025 11:59:36 +0530 Subject: [PATCH] components/esp_matter: Introduced set_server_init_params() api to allow setting custom ServerInitParams Submodule update for release-v1.4 --- .gitlab-ci.yml | 2 +- README.md | 2 +- components/esp_matter/esp_matter_core.cpp | 21 ++++++++++++++++--- components/esp_matter/esp_matter_core.h | 25 +++++++++++++++++++++++ connectedhomeip/connectedhomeip | 2 +- 5 files changed, 46 insertions(+), 6 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 48a35e437..0cbfc59ef 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: "87cf8e5030" + CHIP_SHORT_HASH: "7a54749dc9" DOCKER_IMAGE_NAME: "espressif/chip-idf" .add_gitlab_ssh_key: &add_gitlab_ssh_key | diff --git a/README.md b/README.md index e601396bc..fbb9ea1c2 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 [87cf8e5030](https://github.com/project-chip/connectedhomeip/tree/87cf8e5030) of connectedhomeip. +- This SDK currently works with commit [7a54749dc9](https://github.com/project-chip/connectedhomeip/tree/7a54749dc9) 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/esp_matter_core.cpp b/components/esp_matter/esp_matter_core.cpp index 11630852f..ae73e59d9 100644 --- a/components/esp_matter/esp_matter_core.cpp +++ b/components/esp_matter/esp_matter_core.cpp @@ -66,6 +66,7 @@ using chip::DeviceLayer::ThreadStackMgr; static const char *TAG = "esp_matter_core"; static bool esp_matter_started = false; +static chip::CommonCaseDeviceServerInitParams *s_server_init_params = nullptr; #ifndef CONFIG_ESP_MATTER_ENABLE_MATTER_SERVER // If Matter Server is disabled, these functions are required by InteractionModelEngine but not linked @@ -734,11 +735,18 @@ static void deinit_ble_if_commissioned(intptr_t unused) static void esp_matter_chip_init_task(intptr_t context) { TaskHandle_t task_to_notify = reinterpret_cast(context); - static chip::CommonCaseDeviceServerInitParams initParams; + static chip::CommonCaseDeviceServerInitParams defaultInitParams; + + chip::CommonCaseDeviceServerInitParams &initParams = + s_server_init_params ? *s_server_init_params : defaultInitParams; initParams.InitializeStaticResourcesBeforeServerInit(); - initParams.appDelegate = &s_app_delegate; - initParams.testEventTriggerDelegate = test_event_trigger::get_delegate(); + if (!initParams.appDelegate) { + initParams.appDelegate = &s_app_delegate; + } + if (!initParams.testEventTriggerDelegate) { + initParams.testEventTriggerDelegate = test_event_trigger::get_delegate(); + } #ifdef CONFIG_ESP_MATTER_ENABLE_DATA_MODEL // Group data provider injection for dynamic data model @@ -890,6 +898,13 @@ bool is_started() return esp_matter_started; } +esp_err_t set_server_init_params(chip::CommonCaseDeviceServerInitParams *server_init_params) +{ + VerifyOrReturnError(!esp_matter_started, ESP_ERR_INVALID_STATE, ESP_LOGE(TAG, "esp_matter has started")); + s_server_init_params = server_init_params; + return ESP_OK; +} + esp_err_t start(event_callback_t callback, intptr_t callback_arg) { VerifyOrReturnError(!esp_matter_started, ESP_ERR_INVALID_STATE, ESP_LOGE(TAG, "esp_matter has started")); diff --git a/components/esp_matter/esp_matter_core.h b/components/esp_matter/esp_matter_core.h index 116904be5..e9e59332a 100644 --- a/components/esp_matter/esp_matter_core.h +++ b/components/esp_matter/esp_matter_core.h @@ -23,6 +23,7 @@ #include #include #include +#include using chip::app::ConcreteCommandPath; using chip::DeviceLayer::ChipDeviceEvent; @@ -45,6 +46,30 @@ typedef handle_t command_t; /** Event handle */ typedef handle_t event_t; +/** + * @brief Set the server initialization parameters for Matter. + * + * This function must be called before Matter is started. `esp_matter::start()` + * Calling it after Matter has started will have no effect and will return an error. + * + * @note Starting Matter without valid initialization parameters may lead to undefined behavior or startup failure. + * + * @note The provided pointer is stored internally and used later during Matter initialization. + * It is not copied, so the caller must ensure that the memory pointed to by `server_init_params` + * remains valid and unmodified until Matter is started. + * + * @note If this function is called with a `nullptr`, it will still return ESP_OK. The system + * will proceed with default initialization behavior. + * + * @param[in] server_init_params Pointer to the server initialization parameters. May be nullptr. + * + * @return ESP_OK Successfully set the server initialization parameters. + * @return ESP_ERR_INVALID_STATE If called after Matter has already started. + * @return error in case of failure. + */ + +esp_err_t set_server_init_params(chip::CommonCaseDeviceServerInitParams *server_init_params); + /** Event callback * * @param[in] event event data pointer. diff --git a/connectedhomeip/connectedhomeip b/connectedhomeip/connectedhomeip index 87cf8e503..7a54749dc 160000 --- a/connectedhomeip/connectedhomeip +++ b/connectedhomeip/connectedhomeip @@ -1 +1 @@ -Subproject commit 87cf8e5030284e3357cfdff5e0b83eb9d5ff73c9 +Subproject commit 7a54749dc9df8706510767513f2f5656a3bd6f68