From 6453071ee030c45b81ea4d79254594219c32b125 Mon Sep 17 00:00:00 2001 From: liyashuai Date: Wed, 22 Feb 2023 16:14:26 +0800 Subject: [PATCH] update for matter 1.1 sve Fixes after reboot issues, INVALID attribute val type was set, failing to read attribute. Commissioner was reading attribute val by stripping first byte. Unable to update attribute val. Closes : https://github.com/espressif/esp-matter/issues/148 --- components/esp_matter/CMakeLists.txt | 3 -- components/esp_matter/esp_matter.h | 7 ----- .../esp_matter/esp_matter_attribute_utils.cpp | 4 +-- components/esp_matter/esp_matter_command.cpp | 11 ++----- components/esp_matter/esp_matter_core.cpp | 22 +++++++++++-- .../zap-generated/callback-stub.cpp | 31 ++----------------- connectedhomeip/connectedhomeip | 2 +- examples/light/main/app_driver.cpp | 2 ++ examples/light/partitions.csv | 1 + examples/light/sdkconfig.defaults | 5 +++ examples/light/sdkconfig.defaults.esp32h2 | 9 ++++-- export.sh | 2 +- 12 files changed, 43 insertions(+), 56 deletions(-) diff --git a/components/esp_matter/CMakeLists.txt b/components/esp_matter/CMakeLists.txt index 7bc078600..eea777020 100644 --- a/components/esp_matter/CMakeLists.txt +++ b/components/esp_matter/CMakeLists.txt @@ -27,9 +27,7 @@ set(SRC_DIRS_LIST "." "${MATTER_SDK_PATH}/src/app/clusters/general-commissioning-server" "${MATTER_SDK_PATH}/src/app/clusters/general-diagnostics-server" "${MATTER_SDK_PATH}/src/app/clusters/group-key-mgmt-server" - "${MATTER_SDK_PATH}/src/app/clusters/groups-client" "${MATTER_SDK_PATH}/src/app/clusters/groups-server" - "${MATTER_SDK_PATH}/src/app/clusters/identify-client" "${MATTER_SDK_PATH}/src/app/clusters/identify-server" "${MATTER_SDK_PATH}/src/app/clusters/keypad-input-server" "${MATTER_SDK_PATH}/src/app/clusters/level-control" @@ -49,7 +47,6 @@ set(SRC_DIRS_LIST "." "${MATTER_SDK_PATH}/src/app/clusters/pump-configuration-and-control-client" "${MATTER_SDK_PATH}/src/app/clusters/pump-configuration-and-control-server" "${MATTER_SDK_PATH}/src/app/clusters/scenes" - "${MATTER_SDK_PATH}/src/app/clusters/scenes-client" "${MATTER_SDK_PATH}/src/app/clusters/software-diagnostics-server" "${MATTER_SDK_PATH}/src/app/clusters/switch-server" "${MATTER_SDK_PATH}/src/app/clusters/target-navigator-server" diff --git a/components/esp_matter/esp_matter.h b/components/esp_matter/esp_matter.h index fda20102b..b98a91a32 100644 --- a/components/esp_matter/esp_matter.h +++ b/components/esp_matter/esp_matter.h @@ -55,13 +55,6 @@ typedef enum cluster_flags { CLUSTER_FLAG_INIT_FUNCTION = CLUSTER_MASK_INIT_FUNCTION, /* 0x01 */ /** The cluster has an attribute changed function (function_flag) */ CLUSTER_FLAG_ATTRIBUTE_CHANGED_FUNCTION = CLUSTER_MASK_ATTRIBUTE_CHANGED_FUNCTION, /* 0x02 */ - /** The cluster has a default response function (function_flag) */ - CLUSTER_FLAG_DEFAULT_RESPONSE_FUNCTION = CLUSTER_MASK_DEFAULT_RESPONSE_FUNCTION, /* 0x04 */ - /** The cluster has a message sent function (function_flag) */ - CLUSTER_FLAG_MESSAGE_SENT_FUNCTION = CLUSTER_MASK_MESSAGE_SENT_FUNCTION, /* 0x08 */ - /** The cluster has a manufacturer specific attribute changed function (function_flag) */ - CLUSTER_FLAG_MANUFACTURER_SPECIFIC_ATTRIBUTE_CHANGED_FUNCTION = - CLUSTER_MASK_MANUFACTURER_SPECIFIC_ATTRIBUTE_CHANGED_FUNCTION, /* 0x10 */ /** The cluster has a pre attribute changed function (function_flag) */ CLUSTER_FLAG_PRE_ATTRIBUTE_CHANGED_FUNCTION = CLUSTER_MASK_PRE_ATTRIBUTE_CHANGED_FUNCTION, /* 0x20 */ /** The cluster is a server cluster */ diff --git a/components/esp_matter/esp_matter_attribute_utils.cpp b/components/esp_matter/esp_matter_attribute_utils.cpp index 8435b76d8..d6a5a767a 100644 --- a/components/esp_matter/esp_matter_attribute_utils.cpp +++ b/components/esp_matter/esp_matter_attribute_utils.cpp @@ -1645,7 +1645,7 @@ esp_err_t get_val_raw(uint16_t endpoint_id, uint32_t cluster_id, uint32_t attrib return ESP_FAIL; } - EmberAfStatus status = emberAfReadServerAttribute(endpoint_id, cluster_id, attribute_id, value, attribute_size); + EmberAfStatus status = emberAfReadAttribute(endpoint_id, cluster_id, attribute_id, value, attribute_size); if (status != EMBER_ZCL_STATUS_SUCCESS) { ESP_LOGE(TAG, "Error getting raw value from matter: 0x%x", status); if (lock_status == lock::SUCCESS) { @@ -1687,7 +1687,7 @@ esp_err_t update(uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_i /* Update matter */ EmberAfStatus status = EMBER_ZCL_STATUS_SUCCESS; if (emberAfContainsServer(endpoint_id, cluster_id)) { - status = emberAfWriteServerAttribute(endpoint_id, cluster_id, attribute_id, value, attribute_type); + status = emberAfWriteAttribute(endpoint_id, cluster_id, attribute_id, value, attribute_type); if (status != EMBER_ZCL_STATUS_SUCCESS) { ESP_LOGE(TAG, "Error updating attribute to matter: 0x%X", status); free(value); diff --git a/components/esp_matter/esp_matter_command.cpp b/components/esp_matter/esp_matter_command.cpp index 85245591f..1b2c2b83c 100644 --- a/components/esp_matter/esp_matter_command.cpp +++ b/components/esp_matter/esp_matter_command.cpp @@ -20,7 +20,6 @@ #include #include #include -#include using namespace chip::app::Clusters; using chip::app::CommandHandler; @@ -56,8 +55,8 @@ void DispatchSingleClusterCommandCommon(const ConcreteCommandPath &command_path, } int flags = get_flags(command); if (flags & COMMAND_FLAG_CUSTOM) { - EmberAfStatus status = (err == ESP_OK) ? EMBER_ZCL_STATUS_SUCCESS : EMBER_ZCL_STATUS_FAILURE; - emberAfSendImmediateDefaultResponse(status); + CommandHandler *command_handler = (CommandHandler *)opaque_ptr; + command_handler->AddStatus(command_path, (err == ESP_OK) ? (chip::Protocols::InteractionModel::Status::Success) : (chip::Protocols::InteractionModel::Status::Failure)); } } @@ -70,11 +69,7 @@ namespace app { void DispatchSingleClusterCommand(const ConcreteCommandPath &command_path, TLVReader &tlv_data, CommandHandler *command_obj) { - Compatibility::SetupEmberAfCommandHandler(command_obj, command_path); - esp_matter::command::DispatchSingleClusterCommandCommon(command_path, tlv_data, command_obj); - - Compatibility::ResetEmberAfObjects(); } } /* namespace app */ @@ -1377,7 +1372,7 @@ namespace command { command_t *create_test_event_trigger(cluster_t *cluster) { - return esp_matter::command::create(cluster, GeneralDiagnostics::Commands::TestEventTrigger::Id, COMMAND_FLAG_ACCEPTED, + return esp_matter::command::create(cluster, GeneralDiagnostics::Commands::TestEventTrigger::Id, COMMAND_FLAG_ACCEPTED, esp_matter_command_callback_test_event_trigger); } diff --git a/components/esp_matter/esp_matter_core.cpp b/components/esp_matter/esp_matter_core.cpp index da82cf301..62007adfe 100644 --- a/components/esp_matter/esp_matter_core.cpp +++ b/components/esp_matter/esp_matter_core.cpp @@ -990,6 +990,17 @@ attribute_t *create(cluster_t *cluster, uint32_t attribute_id, uint8_t flags, es attribute->endpoint_id = current_cluster->endpoint_id; attribute->flags = flags; attribute->flags |= ATTRIBUTE_FLAG_EXTERNAL_STORAGE; + + // After reboot, string and array are treated as Invalid. So need to store val.type and size of attribute value. + attribute->val.type = val.type; + if (val.type == ESP_MATTER_VAL_TYPE_CHAR_STRING || + val.type == ESP_MATTER_VAL_TYPE_OCTET_STRING || + val.type == ESP_MATTER_VAL_TYPE_ARRAY) { + attribute->val.val.a.s = val.val.a.s; + attribute->val.val.a.n = val.val.a.n; + attribute->val.val.a.t = val.val.a.t; + } + if (attribute->flags & ATTRIBUTE_FLAG_NONVOLATILE) { esp_matter_attr_val_t val_nvs = esp_matter_invalid(NULL); esp_err_t err = get_val_from_nvs((attribute_t *)attribute, &val_nvs); @@ -1109,6 +1120,7 @@ esp_err_t set_val(attribute_t *attribute, esp_matter_attr_val_t *val) /* Free old buf */ if (current_attribute->val.val.a.b) { free(current_attribute->val.val.a.b); + current_attribute->val.val.a.b = NULL; } if (val->val.a.s > 0) { /* Alloc new buf */ @@ -1119,13 +1131,17 @@ esp_err_t set_val(attribute_t *attribute, esp_matter_attr_val_t *val) } /* Copy to new buf and assign */ memcpy(new_buf, val->val.a.b, val->val.a.s); - val->val.a.b = new_buf; + current_attribute->val.val.a.b = new_buf; + current_attribute->val.val.a.s = val->val.a.s; + current_attribute->val.val.a.n = val->val.a.n; + current_attribute->val.val.a.t = val->val.a.t; } else { ESP_LOGD(TAG, "Set val called with string with size 0"); - val->val.a.b = NULL; } + } else { + memcpy((void *)¤t_attribute->val, (void *)val, sizeof(esp_matter_attr_val_t)); } - memcpy((void *)¤t_attribute->val, (void *)val, sizeof(esp_matter_attr_val_t)); + if (current_attribute->flags & ATTRIBUTE_FLAG_NONVOLATILE) { store_val_in_nvs(attribute); } diff --git a/components/esp_matter/zap_common/zap-generated/callback-stub.cpp b/components/esp_matter/zap_common/zap-generated/callback-stub.cpp index 5f5713be1..497a13492 100644 --- a/components/esp_matter/zap_common/zap-generated/callback-stub.cpp +++ b/components/esp_matter/zap_common/zap-generated/callback-stub.cpp @@ -32,15 +32,11 @@ void emberAfClusterInitCallback(EndpointId endpoint, ClusterId clusterId) (void)clusterId; } -void __attribute__((weak)) emberAfAddToCurrentAppTasksCallback(EmberAfApplicationTask tasks) {} - -void __attribute__((weak)) emberAfRemoveFromCurrentAppTasksCallback(EmberAfApplicationTask tasks) {} - EmberAfAttributeWritePermission __attribute__((weak)) -emberAfAllowNetworkWriteAttributeCallback(EndpointId endpoint, ClusterId clusterId, AttributeId attributeId,uint8_t * value, +emberAfAllowNetworkWriteAttributeCallback(EndpointId endpoint, ClusterId clusterId, AttributeId attributeId,uint8_t * value, uint8_t type) { - return EMBER_ZCL_ATTRIBUTE_WRITE_PERMISSION_ALLOW_WRITE_NORMAL; // Default + return EmberAfAttributeWritePermission::AllowWriteNormal; // Default } bool __attribute__((weak)) emberAfAttributeReadAccessCallback(EndpointId endpoint, ClusterId clusterId, AttributeId attributeId) @@ -58,36 +54,13 @@ bool __attribute__((weak)) emberAfDefaultResponseCallback(ClusterId clusterId, C return false; } -bool __attribute__((weak)) emberAfPreMessageSendCallback(EmberAfMessageStruct * messageStruct, EmberStatus * status) -{ - return false; -} - -bool __attribute__((weak)) emberAfMessageSentCallback(const MessageSendDestination & destination, EmberApsFrame * apsFrame, - uint16_t msgLen, uint8_t * message, EmberStatus status) -{ - return false; -} - uint32_t __attribute__((weak)) emberAfGetCurrentTimeCallback() { return 0; } -bool __attribute__((weak)) -emberAfGetEndpointInfoCallback(EndpointId endpoint, uint8_t * returnNetworkIndex, EmberAfEndpointInfoStruct * returnEndpointInfo) -{ - return false; -} - void __attribute__((weak)) emberAfRegistrationAbortCallback() {} -EmberStatus __attribute__((weak)) -emberAfInterpanSendMessageCallback(EmberAfInterpanHeader * header, uint16_t messageLength, uint8_t * message) -{ - return EMBER_LIBRARY_NOT_PRESENT; -} - bool __attribute__((weak)) emberAfStartMoveCallback() { return false; diff --git a/connectedhomeip/connectedhomeip b/connectedhomeip/connectedhomeip index 7e69c66bb..b89e83be4 160000 --- a/connectedhomeip/connectedhomeip +++ b/connectedhomeip/connectedhomeip @@ -1 +1 @@ -Subproject commit 7e69c66bb44c91fe0b9bed7c7b8d272d3208c8dd +Subproject commit b89e83be43dde7a79d90823f4bc1279eb53f76de diff --git a/examples/light/main/app_driver.cpp b/examples/light/main/app_driver.cpp index 17cbc7acf..413e81472 100644 --- a/examples/light/main/app_driver.cpp +++ b/examples/light/main/app_driver.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include @@ -159,5 +160,6 @@ app_driver_handle_t app_driver_button_init() button_config_t config = button_driver_get_config(); button_handle_t handle = iot_button_create(&config); iot_button_register_cb(handle, BUTTON_PRESS_DOWN, app_driver_button_toggle_cb, NULL); + app_reset_button_register(handle); return (app_driver_handle_t)handle; } diff --git a/examples/light/partitions.csv b/examples/light/partitions.csv index 23795d153..3ef01f022 100644 --- a/examples/light/partitions.csv +++ b/examples/light/partitions.csv @@ -8,3 +8,4 @@ phy_init, data, phy, , 0x1000, ota_0, app, ota_0, 0x20000, 0x1E0000, ota_1, app, ota_1, 0x200000, 0x1E0000, fctry, data, nvs, 0x3E0000, 0x6000 +ot_storage,data, fat, , 0x6000, \ No newline at end of file diff --git a/examples/light/sdkconfig.defaults b/examples/light/sdkconfig.defaults index 1fa8a9ff4..fd927eeb9 100644 --- a/examples/light/sdkconfig.defaults +++ b/examples/light/sdkconfig.defaults @@ -37,3 +37,8 @@ CONFIG_ESP_WIFI_SOFTAP_SUPPORT=n # Disable DS Peripheral CONFIG_ESP_SECURE_CERT_DS_PERIPHERAL=n + +CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER=y +CONFIG_ENABLE_ESP32_DEVICE_INSTANCE_INFO_PROVIDER=y + +CONFIG_FACTORY_PARTITION_DAC_PROVIDER=y diff --git a/examples/light/sdkconfig.defaults.esp32h2 b/examples/light/sdkconfig.defaults.esp32h2 index 1ce0c71a5..5f07c9240 100644 --- a/examples/light/sdkconfig.defaults.esp32h2 +++ b/examples/light/sdkconfig.defaults.esp32h2 @@ -33,7 +33,7 @@ CONFIG_LWIP_IPV6_AUTOCONFIG=n # Use a custom partition table CONFIG_PARTITION_TABLE_CUSTOM=y -CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions_h2.csv" +CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv" # LwIP config for OpenThread CONFIG_LWIP_IPV6_NUM_ADDRESSES=8 @@ -55,7 +55,7 @@ CONFIG_USE_MINIMAL_MDNS=n CONFIG_ENABLE_EXTENDED_DISCOVERY=y # Enable OTA Requestor -CONFIG_ENABLE_OTA_REQUESTOR=n +CONFIG_ENABLE_OTA_REQUESTOR=y # Disable STA and AP for ESP32H2 CONFIG_ENABLE_WIFI_STATION=n @@ -68,3 +68,8 @@ CONFIG_BUTTON_LONG_PRESS_TIME_MS=5000 # Enable chip shell CONFIG_ENABLE_CHIP_SHELL=y +CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER=y +CONFIG_ENABLE_ESP32_DEVICE_INSTANCE_INFO_PROVIDER=y + +CONFIG_FACTORY_PARTITION_DAC_PROVIDER=y + diff --git a/export.sh b/export.sh index 631d19883..cbb9165eb 100644 --- a/export.sh +++ b/export.sh @@ -54,7 +54,7 @@ esp_matter_export_main() { export PATH=${PATH}:${ESP_MATTER_PATH}/connectedhomeip/connectedhomeip/out/host # export zap-cli path - export export ZAP_INSTALL_PATH=${ESP_MATTER_PATH}/zap + #export export ZAP_INSTALL_PATH=${ESP_MATTER_PATH}/zap } esp_matter_export_main