diff --git a/components/esp_matter/esp_matter_command.cpp b/components/esp_matter/esp_matter_command.cpp index 73e776548b..1c739819ea 100644 --- a/components/esp_matter/esp_matter_command.cpp +++ b/components/esp_matter/esp_matter_command.cpp @@ -49,8 +49,14 @@ void DispatchSingleClusterCommandCommon(const ConcreteCommandPath &command_path, return; } esp_err_t err = ESP_OK; - callback_t callback = get_callback(command); + TLVReader tlv_reader; + tlv_reader.Init(tlv_data); + callback_t callback = get_user_callback(command); if (callback) { + err = callback(command_path, tlv_reader, opaque_ptr); + } + callback = get_callback(command); + if ((err == ESP_OK) && callback) { err = callback(command_path, tlv_data, opaque_ptr); } int flags = get_flags(command); diff --git a/components/esp_matter/esp_matter_core.cpp b/components/esp_matter/esp_matter_core.cpp index 2041ed3f16..e02c84b92f 100644 --- a/components/esp_matter/esp_matter_core.cpp +++ b/components/esp_matter/esp_matter_core.cpp @@ -157,6 +157,7 @@ typedef struct _command { uint32_t command_id; uint16_t flags; command::callback_t callback; + command::callback_t user_callback; struct _command *next; } _command_t; @@ -1397,6 +1398,7 @@ command_t *create(cluster_t *cluster, uint32_t command_id, uint8_t flags, callba command->command_id = command_id; command->flags = flags; command->callback = callback; + command->user_callback = NULL; /* Add */ _command_t *previous_command = NULL; @@ -1484,6 +1486,25 @@ callback_t get_callback(command_t *command) return current_command->callback; } +callback_t get_user_callback(command_t *command) +{ + if (!command) { + ESP_LOGE(TAG, "Command cannot be NULL"); + return NULL; + } + _command_t *current_command = (_command_t *)command; + return current_command->user_callback; +} + +void set_user_callback(command_t *command, callback_t user_callback) +{ + if (!command) { + ESP_LOGE(TAG, "Command cannot be NULL"); + } + _command_t *current_command = (_command_t *)command; + current_command->user_callback = user_callback; +} + uint16_t get_flags(command_t *command) { if (!command) { diff --git a/components/esp_matter/esp_matter_core.h b/components/esp_matter/esp_matter_core.h index 7459c91ba9..d37227dec5 100644 --- a/components/esp_matter/esp_matter_core.h +++ b/components/esp_matter/esp_matter_core.h @@ -676,6 +676,28 @@ uint32_t get_id(command_t *command); */ callback_t get_callback(command_t *command); +/** Get command user_callback + * + * Get the command user_callback for the command. + * + * @param[in] command Command handle. + * + * @return Command user_callback on success. + * @return NULL in case of failure or if the callback was not set when creating the command. + */ +callback_t get_user_callback(command_t *command); + +/** Set command user_callback + * + * Set the user_callback for the command. + * + * @param[in] command Command handle. + * @param[in] user_callback callback_t. + * + * @return void + */ +void set_user_callback(command_t *command, callback_t user_callback); + /** Get command flags * * Get the command flags for the command.