Skip to content

Commit

Permalink
Merge branch 'icd/update_features' into 'main'
Browse files Browse the repository at this point in the history
Update features for ICD Management cluster

See merge request app-frameworks/esp-matter!698
  • Loading branch information
chshu committed Apr 23, 2024
2 parents 8c101ca + eadcdc6 commit c0fb895
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 65 deletions.
75 changes: 34 additions & 41 deletions components/esp_matter/esp_matter_attribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -588,65 +588,58 @@ attribute_t *create_max_group_keys_per_fabric(cluster_t *cluster, uint16_t value

namespace icd_management {
namespace attribute {
attribute_t *create_idle_mode_duration(cluster_t *cluster, uint32_t value, uint32_t min, uint32_t max)
attribute_t *create_idle_mode_duration(cluster_t *cluster, uint32_t value)
{
attribute_t *attribute = esp_matter::attribute::create(cluster, IcdManagement::Attributes::IdleModeDuration::Id,
ATTRIBUTE_FLAG_NONE, esp_matter_uint32(value));
if (!attribute) {
ESP_LOGE(TAG, "Could not create attribute");
return NULL;
}
esp_matter::attribute::add_bounds(attribute, esp_matter_uint32(min), esp_matter_uint32(max));
return attribute;
return esp_matter::attribute::create(cluster, IcdManagement::Attributes::IdleModeDuration::Id,
ATTRIBUTE_FLAG_NONE, esp_matter_uint32(value));
}

attribute_t *create_active_mode_duration(cluster_t *cluster, uint32_t value, uint32_t min)
attribute_t *create_active_mode_duration(cluster_t *cluster, uint32_t value)
{
attribute_t *attribute = esp_matter::attribute::create(cluster, IcdManagement::Attributes::ActiveModeDuration::Id,
ATTRIBUTE_FLAG_NONE, esp_matter_uint32(value));
if (!attribute) {
ESP_LOGE(TAG, "Could not create attribute");
return NULL;
}
esp_matter::attribute::add_bounds(attribute, esp_matter_uint32(min), esp_matter_uint32(UINT32_MAX));
return attribute;
return esp_matter::attribute::create(cluster, IcdManagement::Attributes::ActiveModeDuration::Id,
ATTRIBUTE_FLAG_NONE, esp_matter_uint32(value));
}

attribute_t *create_active_mode_threshold(cluster_t *cluster, uint16_t value, uint16_t min)
attribute_t *create_active_mode_threshold(cluster_t *cluster, uint16_t value)
{
attribute_t *attribute = esp_matter::attribute::create(cluster, IcdManagement::Attributes::ActiveModeThreshold::Id,
ATTRIBUTE_FLAG_NONE, esp_matter_uint16(value));
if (!attribute) {
ESP_LOGE(TAG, "Could not create attribute");
return NULL;
}
esp_matter::attribute::add_bounds(attribute, esp_matter_uint16(min), esp_matter_uint16(UINT16_MAX));
return attribute;
return esp_matter::attribute::create(cluster, IcdManagement::Attributes::ActiveModeThreshold::Id,
ATTRIBUTE_FLAG_NONE, esp_matter_uint16(value));
}

attribute_t *create_registered_clients(cluster_t *cluster, uint8_t *value, uint16_t length, uint16_t count)
{
return esp_matter::attribute::create(cluster, IcdManagement::Attributes::RegisteredClients::Id, ATTRIBUTE_FLAG_NONVOLATILE,
esp_matter_array(value,length, count));
return esp_matter::attribute::create(cluster, IcdManagement::Attributes::RegisteredClients::Id,
ATTRIBUTE_FLAG_NONVOLATILE, esp_matter_array(value,length, count));
}

attribute_t *create_icd_counter(cluster_t *cluster,uint32_t value)
attribute_t *create_icd_counter(cluster_t *cluster, uint32_t value)
{
return esp_matter::attribute::create(cluster, IcdManagement::Attributes::ICDCounter::Id, ATTRIBUTE_FLAG_NONVOLATILE,
esp_matter_uint32(value));
return esp_matter::attribute::create(cluster, IcdManagement::Attributes::ICDCounter::Id,
ATTRIBUTE_FLAG_NONVOLATILE, esp_matter_uint32(value));
}

attribute_t *create_clients_supported_per_fabric(cluster_t *cluster, uint16_t value, uint16_t min)
attribute_t *create_clients_supported_per_fabric(cluster_t *cluster, uint16_t value)
{
attribute_t *attribute = esp_matter::attribute::create(cluster, IcdManagement::Attributes::ClientsSupportedPerFabric::Id,
ATTRIBUTE_FLAG_NONE, esp_matter_uint16(value));
if (!attribute) {
ESP_LOGE(TAG, "Could not create attribute");
return NULL;
}
esp_matter::attribute::add_bounds(attribute, esp_matter_uint16(min), esp_matter_uint16(UINT16_MAX));
return attribute;
return esp_matter::attribute::create(cluster, IcdManagement::Attributes::ClientsSupportedPerFabric::Id,
ATTRIBUTE_FLAG_NONE, esp_matter_uint16(value));
}

attribute_t *create_user_active_mode_trigger_hint(cluster_t *cluster, uint32_t value)
{
return esp_matter::attribute::create(cluster, IcdManagement::Attributes::UserActiveModeTriggerHint::Id,
ATTRIBUTE_FLAG_NONE, esp_matter_bitmap32(value));
}

attribute_t *create_user_active_mode_trigger_instruction(cluster_t *cluster, char *value, uint16_t length)
{
return esp_matter::attribute::create(cluster, IcdManagement::Attributes::UserActiveModeTriggerInstruction::Id,
ATTRIBUTE_FLAG_NONE, esp_matter_char_str(value, length));
}

attribute_t *create_operating_mode(cluster_t *cluster, uint8_t value)
{
return esp_matter::attribute::create(cluster, IcdManagement::Attributes::OperatingMode::Id,
ATTRIBUTE_FLAG_NONE, esp_matter_enum8(value));
}

} /* attribute */
Expand Down
13 changes: 8 additions & 5 deletions components/esp_matter/esp_matter_attribute.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,15 @@ attribute_t *create_max_group_keys_per_fabric(cluster_t *cluster, uint16_t value

namespace icd_management {
namespace attribute {
attribute_t *create_idle_mode_duration(cluster_t *cluster, uint32_t value, uint32_t min, uint32_t max);
attribute_t *create_active_mode_duration(cluster_t *cluster, uint32_t value, uint32_t min);
attribute_t *create_active_mode_threshold(cluster_t *cluster, uint16_t value, uint16_t min);
attribute_t *create_idle_mode_duration(cluster_t *cluster, uint32_t value);
attribute_t *create_active_mode_duration(cluster_t *cluster, uint32_t value);
attribute_t *create_active_mode_threshold(cluster_t *cluster, uint16_t value);
attribute_t *create_registered_clients(cluster_t *cluster, uint8_t *value, uint16_t length, uint16_t count);
attribute_t *create_icd_counter(cluster_t *cluster,uint32_t value);
attribute_t *create_clients_supported_per_fabric(cluster_t *cluster, uint16_t value, uint16_t min);
attribute_t *create_icd_counter(cluster_t *cluster, uint32_t value);
attribute_t *create_clients_supported_per_fabric(cluster_t *cluster, uint16_t value);
attribute_t *create_user_active_mode_trigger_hint(cluster_t *cluster, uint32_t value);
attribute_t *create_user_active_mode_trigger_instruction(cluster_t *cluster, char *value, uint16_t length);
attribute_t *create_operating_mode(cluster_t *cluster, uint8_t value);
} /* attribute */
} /* icd_management */

Expand Down
17 changes: 11 additions & 6 deletions components/esp_matter/esp_matter_cluster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -985,22 +985,27 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags, uint32_
if (flags & CLUSTER_FLAG_SERVER) {
/* Attributes managed internally */
global::attribute::create_feature_map(cluster, 0);
attribute::create_idle_mode_duration(cluster, CONFIG_ICD_ACTIVE_MODE_INTERVAL_MS);
attribute::create_active_mode_duration(cluster, CONFIG_ICD_IDLE_MODE_INTERVAL_SEC);
attribute::create_active_mode_threshold(cluster, CONFIG_ICD_ACTIVE_MODE_THRESHOLD_MS);

/* Attributes not managed internally */
if (config) {
global::attribute::create_cluster_revision(cluster, config->cluster_revision);
attribute::create_idle_mode_duration(cluster, config->idle_mode_interval, 500, 64800000);
attribute::create_active_mode_duration(cluster, config->active_mode_interval, 300);
attribute::create_active_mode_threshold(cluster, config->active_mode_threshold, 300);
} else {
ESP_LOGE(TAG, "Config is NULL. Cannot add some attributes.");
}
}

#if defined(CHIP_CONFIG_ENABLE_ICD_CIP) && CHIP_CONFIG_ENABLE_ICD_CIP
if (features & feature::check_in_protocol_support::get_id()) {
feature::check_in_protocol_support::config_t cip_config;
feature::check_in_protocol_support::add(cluster, &cip_config);
if (features & feature::long_idle_time_support::get_id()) {
feature::long_idle_time_support::add(cluster);
if (features & feature::user_active_mode_trigger::get_id()) {
feature::user_active_mode_trigger::add(cluster, &config->user_active_mode_trigger);
}
if (features & feature::check_in_protocol_support::get_id()) {
feature::check_in_protocol_support::add(cluster);
}
}
#endif // defined(CHIP_CONFIG_ENABLE_ICD_CIP) && CHIP_CONFIG_ENABLE_ICD_CIP
#endif // CONFIG_ENABLE_ICD_SERVER
Expand Down
6 changes: 2 additions & 4 deletions components/esp_matter/esp_matter_cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,8 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags, uint32_
namespace icd_management {
typedef struct config {
uint16_t cluster_revision;
uint32_t idle_mode_interval;
uint32_t active_mode_interval;
uint16_t active_mode_threshold;
config() : cluster_revision(2), idle_mode_interval(5000), active_mode_interval(300), active_mode_threshold(300) {}
feature::user_active_mode_trigger::config_t user_active_mode_trigger;
config() : cluster_revision(2) {}
} config_t;

cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags, uint32_t features);
Expand Down
11 changes: 9 additions & 2 deletions components/esp_matter/esp_matter_endpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,15 @@ esp_err_t add(endpoint_t *endpoint, config_t *config)
#endif
#if CHIP_CONFIG_ENABLE_ICD_SERVER
icd_management::create(endpoint, &(config->icd_management), CLUSTER_FLAG_SERVER,
icd_management::feature::check_in_protocol_support::get_id());
#endif
#if CHIP_CONFIG_ENABLE_ICD_LIT
icd_management::feature::long_idle_time_support::get_id()
#if CHIP_CONFIG_ENABLE_ICD_CIP
| icd_management::feature::check_in_protocol_support::get_id());
#endif // CHIP_CONFIG_ENABLE_ICD_CIP
#else
0);
#endif // CHIP_CONFIG_ENABLE_ICD_LIT
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER

return ESP_OK;
}
Expand Down
69 changes: 65 additions & 4 deletions components/esp_matter/esp_matter_feature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,20 +269,24 @@ uint32_t get_id()
return (uint32_t)IcdManagement::Feature::kCheckInProtocolSupport;
}

esp_err_t add(cluster_t *cluster, config_t *config)
esp_err_t add(cluster_t *cluster)
{
if (!cluster) {
ESP_LOGE(TAG, "Cluster cannot be NULL");
return ESP_ERR_INVALID_ARG;
}
uint32_t lits_feature_map = feature::long_idle_time_support::get_id();
if ((get_feature_map_value(cluster) & lits_feature_map) != lits_feature_map) {
ESP_LOGE(TAG, "Long Idle Time Support feature should be added to this cluster");
return ESP_ERR_INVALID_STATE;
}

update_feature_map(cluster, get_id());

/* Attributes managed internally */
attribute::create_registered_clients(cluster, NULL, 0, 0);
attribute::create_icd_counter(cluster, 0);

/* Attribute not managed internally*/
attribute::create_clients_supported_per_fabric(cluster, config->clients_supported_per_fabric, 1);
attribute::create_clients_supported_per_fabric(cluster, 0);

/* Commands */
command::create_register_client(cluster);
Expand All @@ -293,6 +297,63 @@ esp_err_t add(cluster_t *cluster, config_t *config)
}

} /* check_in_protocol_support */

namespace user_active_mode_trigger {

uint32_t get_id()
{
return (uint32_t)IcdManagement::Feature::kUserActiveModeTrigger;
}

esp_err_t add(cluster_t *cluster, config_t *config)
{
if (!cluster) {
ESP_LOGE(TAG, "Cluster cannot be NULL");
return ESP_ERR_INVALID_ARG;
}
if (!config) {
ESP_LOGE(TAG, "config cannot be NULL");
return ESP_ERR_INVALID_ARG;
}
uint32_t lits_feature_map = feature::long_idle_time_support::get_id();
if ((get_feature_map_value(cluster) & lits_feature_map) != lits_feature_map) {
ESP_LOGE(TAG, "Long Idle Time Support feature should be added to this cluster");
return ESP_ERR_INVALID_STATE;
}

update_feature_map(cluster, get_id());

/* Attributes not managed internally */
attribute::create_user_active_mode_trigger_hint(cluster, config->user_active_mode_trigger_hint);
attribute::create_user_active_mode_trigger_instruction(cluster, config->user_active_mode_trigger_instruction,
strlen(config->user_active_mode_trigger_instruction));

return ESP_OK;
}

} /* user_active_mode_trigger */

namespace long_idle_time_support {

uint32_t get_id()
{
return (uint32_t)IcdManagement::Feature::kLongIdleTimeSupport;
}

esp_err_t add(cluster_t *cluster)
{
if (!cluster) {
ESP_LOGE(TAG, "Cluster cannot be NULL");
return ESP_ERR_INVALID_ARG;
}
update_feature_map(cluster, get_id());

/* Attributes not managed internally */
attribute::create_operating_mode(cluster, 0);
return ESP_OK;
}

} /* long_idle_time_support */
} /* feature */
} /* icd_management */

Expand Down
24 changes: 21 additions & 3 deletions components/esp_matter/esp_matter_feature.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,32 @@ esp_err_t add(cluster_t *cluster);
namespace icd_management {
namespace feature {
namespace check_in_protocol_support {
typedef struct config {
uint16_t clients_supported_per_fabric;

uint32_t get_id();
esp_err_t add(cluster_t *cluster);

} /* check_in_protocol_support */

constexpr size_t k_max_user_active_mode_trigger_instruction_length = 128;

namespace user_active_mode_trigger {
typedef struct {
uint32_t user_active_mode_trigger_hint;
char user_active_mode_trigger_instruction[k_max_user_active_mode_trigger_instruction_length + 1];
} config_t;

uint32_t get_id();
esp_err_t add(cluster_t *cluster, config_t *config);

} /* check_in_protocol_support */
} /* user_active_mode_trigger */

namespace long_idle_time_support {

uint32_t get_id();
esp_err_t add(cluster_t *cluster);

} /* long_idle_time_support */

} /* feature */
} /* icd_management */

Expand Down

0 comments on commit c0fb895

Please sign in to comment.