mirror of
https://github.com/espressif/esp-matter.git
synced 2026-04-27 19:13:13 +00:00
Ensure backward compatibility for attributes stored in NVS with
primitive data type Removed config option ESP_MATTER_NVS_USE_COMPACT_ATTR_STORAGE. Previously, the ESP_MATTER_NVS_USE_COMPACT_ATTR_STORAGE option determined whether to store attributes as a blob or a primitive data type in NVS. Since this configuration is not backward compatible, we now read the attribute as a primitive data type if not found. If it's a blob, we read it and rewrite it as a primitive data type.
This commit is contained in:
@@ -210,18 +210,6 @@ menu "ESP Matter"
|
||||
|
||||
endchoice #ESP_MATTER_MEM_ALLOC_MODE
|
||||
|
||||
config ESP_MATTER_NVS_USE_COMPACT_ATTR_STORAGE
|
||||
bool "Use compact attribute storage"
|
||||
default n
|
||||
help
|
||||
Attributes can be stored as primitive data type or blob in NVS.
|
||||
This option lets you select which one to use.
|
||||
|
||||
If enabled, attributes are stored as primitive data types in NVS.
|
||||
If disabled, then attributes are stored as blob which consumes more space in NVS.
|
||||
|
||||
This option is kept disabled by default to maintain the backward compatibility.
|
||||
|
||||
config ESP_MATTER_ENABLE_DATA_MODEL
|
||||
bool "Use ESP-Matter data model"
|
||||
default y
|
||||
|
||||
@@ -45,6 +45,9 @@ static void get_attribute_key(uint16_t endpoint_id, uint32_t cluster_id, uint32_
|
||||
attribute_key[14] = 0;
|
||||
}
|
||||
|
||||
static esp_err_t nvs_store_val(const char *nvs_namespace, const char *attribute_key, const esp_matter_attr_val_t & val);
|
||||
static esp_err_t nvs_erase_val(const char *nvs_namespace, const char *attribute_key);
|
||||
|
||||
static esp_err_t nvs_get_val(const char *nvs_namespace, const char *attribute_key, esp_matter_attr_val_t & val)
|
||||
{
|
||||
nvs_handle_t handle;
|
||||
@@ -71,13 +74,18 @@ static esp_err_t nvs_get_val(const char *nvs_namespace, const char *attribute_ke
|
||||
val.val.a.n = len;
|
||||
val.val.a.t = len + (val.val.a.t - val.val.a.s);
|
||||
val.val.a.s = len;
|
||||
nvs_get_blob(handle, attribute_key, buffer, &len);
|
||||
err = nvs_get_blob(handle, attribute_key, buffer, &len);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Handling how to get attributes in NVS based on config option.
|
||||
#if CONFIG_ESP_MATTER_NVS_USE_COMPACT_ATTR_STORAGE
|
||||
// This switch case handles primitive data types
|
||||
|
||||
nvs_close(handle);
|
||||
return err;
|
||||
}
|
||||
|
||||
// This switch case handles primitive data types
|
||||
// if value is stored as primitive data type return it, else check if its stored as blob
|
||||
// and convert it to primitive data type
|
||||
{
|
||||
switch (val.type)
|
||||
{
|
||||
case ESP_MATTER_VAL_TYPE_BOOLEAN:
|
||||
@@ -173,17 +181,35 @@ static esp_err_t nvs_get_val(const char *nvs_namespace, const char *attribute_ke
|
||||
default:
|
||||
{
|
||||
// handle the case where the type is not recognized
|
||||
err = ESP_ERR_INVALID_ARG;
|
||||
nvs_close(handle);
|
||||
ESP_LOGE(TAG, "Invalid attribute type: %u", val.type);
|
||||
break;
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
}
|
||||
#else
|
||||
}
|
||||
|
||||
// Found the value as primitive data type
|
||||
if (err == ESP_OK) {
|
||||
nvs_close(handle);
|
||||
return err;
|
||||
}
|
||||
|
||||
if (err == ESP_ERR_NVS_NOT_FOUND) {
|
||||
// Read as blob, if found, write as primitive data type
|
||||
size_t len = sizeof(esp_matter_attr_val_t);
|
||||
err = nvs_get_blob(handle, attribute_key, &val, &len);
|
||||
#endif // CONFIG_ESP_MATTER_NVS_USE_COMPACT_ATTR_STORAGE
|
||||
if (err == ESP_OK) {
|
||||
// found it as a blob, close the handle
|
||||
nvs_close(handle);
|
||||
|
||||
// nvs_store_val always stores primitive value using primitive data type APIs
|
||||
err = nvs_store_val(nvs_namespace, attribute_key, val);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Failed to store as primitive data type");
|
||||
}
|
||||
}
|
||||
}
|
||||
nvs_close(handle);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -203,14 +229,12 @@ static esp_err_t nvs_store_val(const char *nvs_namespace, const char *attribute_
|
||||
/* Store only if value is not NULL */
|
||||
if (val.val.a.b) {
|
||||
err = nvs_set_blob(handle, attribute_key, val.val.a.b, val.val.a.s);
|
||||
nvs_commit(handle);
|
||||
} else {
|
||||
err = ESP_OK;
|
||||
}
|
||||
} else {
|
||||
// Handling how to store attributes in NVS based on config option.
|
||||
#if CONFIG_ESP_MATTER_NVS_USE_COMPACT_ATTR_STORAGE
|
||||
// This switch case handles primitive data types
|
||||
// always store values as primitive data type
|
||||
switch (val.type)
|
||||
{
|
||||
case ESP_MATTER_VAL_TYPE_BOOLEAN:
|
||||
@@ -306,12 +330,8 @@ static esp_err_t nvs_store_val(const char *nvs_namespace, const char *attribute_
|
||||
break;
|
||||
}
|
||||
}
|
||||
#else
|
||||
err = nvs_set_blob(handle, attribute_key, &val, sizeof(esp_matter_attr_val_t));
|
||||
#endif // CONFIG_ESP_MATTER_NVS_USE_COMPACT_ATTR_STORAGE
|
||||
|
||||
nvs_commit(handle);
|
||||
}
|
||||
nvs_commit(handle);
|
||||
nvs_close(handle);
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -38,9 +38,6 @@ CONFIG_ESP_WIFI_SOFTAP_SUPPORT=n
|
||||
# Disable DS Peripheral
|
||||
CONFIG_ESP_SECURE_CERT_DS_PERIPHERAL=n
|
||||
|
||||
# Use compact attribute storage mode
|
||||
CONFIG_ESP_MATTER_NVS_USE_COMPACT_ATTR_STORAGE=y
|
||||
|
||||
# Enable HKDF in mbedtls
|
||||
CONFIG_MBEDTLS_HKDF_C=y
|
||||
|
||||
|
||||
@@ -55,9 +55,6 @@ CONFIG_ESP_WIFI_SOFTAP_SUPPORT=n
|
||||
# Disable DS Peripheral
|
||||
CONFIG_ESP_SECURE_CERT_DS_PERIPHERAL=n
|
||||
|
||||
# Use compact attribute storage mode
|
||||
CONFIG_ESP_MATTER_NVS_USE_COMPACT_ATTR_STORAGE=y
|
||||
|
||||
# Enable HKDF in mbedtls
|
||||
CONFIG_MBEDTLS_HKDF_C=y
|
||||
|
||||
|
||||
@@ -41,9 +41,6 @@ CONFIG_ENABLE_CHIP_CONTROLLER_BUILD=y
|
||||
CONFIG_ESP_MATTER_CONTROLLER_ENABLE=y
|
||||
CONFIG_ESP_MATTER_COMMISSIONER_ENABLE=y
|
||||
|
||||
# Use compact attribute storage mode
|
||||
CONFIG_ESP_MATTER_NVS_USE_COMPACT_ATTR_STORAGE=y
|
||||
|
||||
# Enable HKDF in mbedtls
|
||||
CONFIG_MBEDTLS_HKDF_C=y
|
||||
|
||||
|
||||
@@ -67,9 +67,6 @@ CONFIG_BUILD_CHIP_TESTS=n
|
||||
# Disable OTA Requestor
|
||||
CONFIG_ENABLE_OTA_REQUESTOR=n
|
||||
|
||||
# Use compact attribute storage mode
|
||||
CONFIG_ESP_MATTER_NVS_USE_COMPACT_ATTR_STORAGE=y
|
||||
|
||||
# Disable route hook for matter since OTBR has already initialize the route hook
|
||||
CONFIG_ENABLE_ROUTE_HOOK=n
|
||||
|
||||
|
||||
@@ -46,9 +46,6 @@ CONFIG_FACTORY_DEVICE_INFO_PROVIDER=y
|
||||
CONFIG_FACTORY_DEVICE_INSTANCE_INFO_PROVIDER=y
|
||||
CONFIG_FACTORY_COMMISSIONABLE_DATA_PROVIDER=y
|
||||
|
||||
# Use compact attribute storage mode
|
||||
CONFIG_ESP_MATTER_NVS_USE_COMPACT_ATTR_STORAGE=y
|
||||
|
||||
# Enable HKDF in mbedtls
|
||||
CONFIG_MBEDTLS_HKDF_C=y
|
||||
|
||||
|
||||
@@ -31,9 +31,6 @@ CONFIG_ESP_WIFI_SOFTAP_SUPPORT=n
|
||||
# Disable DS Peripheral
|
||||
CONFIG_ESP_SECURE_CERT_DS_PERIPHERAL=n
|
||||
|
||||
# Use compact attribute storage mode
|
||||
CONFIG_ESP_MATTER_NVS_USE_COMPACT_ATTR_STORAGE=y
|
||||
|
||||
# Enable HKDF in mbedtls
|
||||
CONFIG_MBEDTLS_HKDF_C=y
|
||||
|
||||
|
||||
@@ -38,9 +38,6 @@ CONFIG_ESP_WIFI_SOFTAP_SUPPORT=n
|
||||
# Disable DS Peripheral
|
||||
CONFIG_ESP_SECURE_CERT_DS_PERIPHERAL=n
|
||||
|
||||
# Use compact attribute storage mode
|
||||
CONFIG_ESP_MATTER_NVS_USE_COMPACT_ATTR_STORAGE=y
|
||||
|
||||
# Enable HKDF in mbedtls
|
||||
CONFIG_MBEDTLS_HKDF_C=y
|
||||
|
||||
|
||||
@@ -45,9 +45,6 @@ CONFIG_ESP_WIFI_SOFTAP_SUPPORT=n
|
||||
# Disable DS Peripheral
|
||||
CONFIG_ESP_SECURE_CERT_DS_PERIPHERAL=n
|
||||
|
||||
# Use compact attribute storage mode
|
||||
CONFIG_ESP_MATTER_NVS_USE_COMPACT_ATTR_STORAGE=y
|
||||
|
||||
# Enable HKDF in mbedtls
|
||||
CONFIG_MBEDTLS_HKDF_C=y
|
||||
|
||||
|
||||
@@ -38,9 +38,6 @@ CONFIG_ESP_WIFI_SOFTAP_SUPPORT=n
|
||||
# Disable DS Peripheral
|
||||
CONFIG_ESP_SECURE_CERT_DS_PERIPHERAL=n
|
||||
|
||||
# Use compact attribute storage mode
|
||||
CONFIG_ESP_MATTER_NVS_USE_COMPACT_ATTR_STORAGE=y
|
||||
|
||||
# Enable HKDF in mbedtls
|
||||
CONFIG_MBEDTLS_HKDF_C=y
|
||||
|
||||
|
||||
@@ -41,8 +41,5 @@ CONFIG_ESP_WIFI_SOFTAP_SUPPORT=n
|
||||
# Disable DS Peripheral
|
||||
CONFIG_ESP_SECURE_CERT_DS_PERIPHERAL=n
|
||||
|
||||
# Use compact attribute storage mode
|
||||
CONFIG_ESP_MATTER_NVS_USE_COMPACT_ATTR_STORAGE=y
|
||||
|
||||
# Enable HKDF in mbedtls
|
||||
CONFIG_MBEDTLS_HKDF_C=y
|
||||
|
||||
@@ -38,9 +38,6 @@ CONFIG_ESP_WIFI_SOFTAP_SUPPORT=n
|
||||
# Disable DS Peripheral
|
||||
CONFIG_ESP_SECURE_CERT_DS_PERIPHERAL=n
|
||||
|
||||
# Use compact attribute storage mode
|
||||
CONFIG_ESP_MATTER_NVS_USE_COMPACT_ATTR_STORAGE=y
|
||||
|
||||
# Enable HKDF in mbedtls
|
||||
CONFIG_MBEDTLS_HKDF_C=y
|
||||
|
||||
|
||||
@@ -44,8 +44,5 @@ CONFIG_ESP_WIFI_SOFTAP_SUPPORT=n
|
||||
# Disable DS Peripheral
|
||||
CONFIG_ESP_SECURE_CERT_DS_PERIPHERAL=n
|
||||
|
||||
# Use compact attribute storage mode
|
||||
CONFIG_ESP_MATTER_NVS_USE_COMPACT_ATTR_STORAGE=y
|
||||
|
||||
# Enable HKDF in mbedtls
|
||||
CONFIG_MBEDTLS_HKDF_C=y
|
||||
|
||||
@@ -41,9 +41,6 @@ CONFIG_ZB_RADIO_MACSPLIT_UART=y
|
||||
# Disable DS Peripheral
|
||||
CONFIG_ESP_SECURE_CERT_DS_PERIPHERAL=n
|
||||
|
||||
# Use compact attribute storage mode
|
||||
CONFIG_ESP_MATTER_NVS_USE_COMPACT_ATTR_STORAGE=y
|
||||
|
||||
# Enable HKDF in mbedtls
|
||||
CONFIG_MBEDTLS_HKDF_C=y
|
||||
|
||||
|
||||
@@ -39,9 +39,6 @@ CONFIG_ESP_MATTER_ZIGBEE_BRIDGE_BOARD_DEV_KIT=y
|
||||
# USB Console
|
||||
CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG=y
|
||||
|
||||
# Use compact attribute storage mode
|
||||
CONFIG_ESP_MATTER_NVS_USE_COMPACT_ATTR_STORAGE=y
|
||||
|
||||
# Enable HKDF in mbedtls
|
||||
CONFIG_MBEDTLS_HKDF_C=y
|
||||
|
||||
|
||||
Reference in New Issue
Block a user