Skip to content

Commit

Permalink
Merge branch 'backport_node_label/v1.1' into 'release/v1.1'
Browse files Browse the repository at this point in the history
fix/node-label : [v.1.1] cherry-pick node-label fix to release/v1.1.

See merge request app-frameworks/esp-matter!631
  • Loading branch information
dhrishi committed Feb 26, 2024
2 parents 5abc309 + 2bb72e5 commit f511d22
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 11 deletions.
7 changes: 7 additions & 0 deletions components/esp_matter/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ menu "ESP Matter"
help
The maximum device type count supported per endpoint.

config ESP_MATTER_ATTRIBUTE_BUFFER_LARGEST
int "Largest attribute buffer size"
default 259
help
The Largest attribute size required for various attributes, the buffer will be used
for reading or writing attributes.

config ESP_MATTER_NVS_PART_NAME
string "ESP Matter NVS partition name"
default "nvs"
Expand Down
45 changes: 35 additions & 10 deletions components/esp_matter/esp_matter_attribute_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1106,21 +1106,40 @@ esp_err_t get_data_from_attr_val(esp_matter_attr_val_t *val, EmberAfAttributeTyp
if (value) {
int data_size_len = val->val.a.t - val->val.a.s;
memcpy(value, (uint8_t *)&val->val.a.s, data_size_len);
if (*attribute_size > CONFIG_ESP_MATTER_ATTRIBUTE_BUFFER_LARGEST)
{
ESP_LOGE(TAG, "Attribute buffer not enough, cannot copy the data to the attribute buffer."
"Please configure the buffer size through menuconfig ESP_MATTER_ATTRIBUTE_BUFFER_LARGEST");
return ESP_FAIL;
}
memcpy((value + data_size_len), (uint8_t *)val->val.a.b, (*attribute_size - data_size_len));
}
break;

case ESP_MATTER_VAL_TYPE_CHAR_STRING:
if (attribute_type) {
*attribute_type = ZCL_CHAR_STRING_ATTRIBUTE_TYPE;
}
if (attribute_size) {
*attribute_size = val->val.a.t;
}
if (value) {
int data_size_len = val->val.a.t - val->val.a.s;
memcpy(value, (uint8_t *)&val->val.a.s, data_size_len);
memcpy((value + data_size_len), (uint8_t *)val->val.a.b, (*attribute_size - data_size_len));
{
if (attribute_type) {
*attribute_type = ZCL_CHAR_STRING_ATTRIBUTE_TYPE;
}
size_t string_len = strnlen((const char *)val->val.a.b, val->val.a.s);
size_t data_size_len = val->val.a.t - val->val.a.s;
if (string_len >= UINT8_MAX || data_size_len != 1) {
return ESP_ERR_INVALID_ARG;
}
uint8_t data_size = string_len;
if (attribute_size) {
*attribute_size = string_len + data_size_len;
}
if (value) {
memcpy(value, (uint8_t *)&data_size, data_size_len);
if (*attribute_size > CONFIG_ESP_MATTER_ATTRIBUTE_BUFFER_LARGEST)
{
ESP_LOGE(TAG, "Attribute buffer not enough, cannot copy the data to the attribute buffer."
"Please configure the buffer size through menuconfig ESP_MATTER_ATTRIBUTE_BUFFER_LARGEST");
return ESP_FAIL;
}
memcpy((value + data_size_len), (uint8_t *)val->val.a.b, (*attribute_size - data_size_len));
}
}
break;

Expand All @@ -1134,6 +1153,12 @@ esp_err_t get_data_from_attr_val(esp_matter_attr_val_t *val, EmberAfAttributeTyp
if (value) {
int data_size_len = val->val.a.t - val->val.a.s;
memcpy(value, (uint8_t *)&val->val.a.s, data_size_len);
if (*attribute_size > CONFIG_ESP_MATTER_ATTRIBUTE_BUFFER_LARGEST)
{
ESP_LOGE(TAG, "Attribute buffer not enough, cannot copy the data to the attribute buffer."
"Please configure the buffer size through menuconfig ESP_MATTER_ATTRIBUTE_BUFFER_LARGEST");
return ESP_FAIL;
}
memcpy((value + data_size_len), (uint8_t *)val->val.a.b, (*attribute_size - data_size_len));
}
break;
Expand Down
7 changes: 7 additions & 0 deletions components/esp_matter/esp_matter_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,13 @@ esp_err_t enable(endpoint_t *endpoint)
attribute::get_data_from_attr_val(&attribute->val, &matter_attributes[attribute_index].attributeType,
&matter_attributes[attribute_index].size, NULL);

/* The length is not fixed for string attribute, so set it to the max size (32) to avoid overflow issue
* when writing a longer string.
*/
if (attribute->val.type == ESP_MATTER_VAL_TYPE_CHAR_STRING) {
matter_attributes[attribute_index].size = attribute->val.val.a.s;
}

matter_clusters[cluster_index].clusterSize += matter_attributes[attribute_index].size;
attribute = attribute->next;
attribute_index++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#define ZAP_FIXED_ENDPOINT_DATA_VERSION_COUNT 0

// Largest attribute size is needed for various buffers
#define ATTRIBUTE_LARGEST (259)
#define ATTRIBUTE_LARGEST CONFIG_ESP_MATTER_ATTRIBUTE_BUFFER_LARGEST

static_assert(ATTRIBUTE_LARGEST <= CHIP_CONFIG_MAX_ATTRIBUTE_STORE_ELEMENT_SIZE, "ATTRIBUTE_LARGEST larger than expected");

Expand Down

0 comments on commit f511d22

Please sign in to comment.