mirror of
https://github.com/espressif/esp-matter.git
synced 2026-04-28 11:28:32 +00:00
controller: Add groupsettings command
controller: Add invoking commands and writing attributes commands for group_key_management cluster controller: Add invoking commands for groups cluster
This commit is contained in:
@@ -465,6 +465,75 @@ static esp_err_t write_attribute(uint64_t node_id, uint16_t endpoint_id, uint32_
|
||||
|
||||
} // namespace binding
|
||||
|
||||
namespace group_key_management {
|
||||
|
||||
using group_key_map_obj = GroupKeyManagement::Structs::GroupKeyMapStruct::Type;
|
||||
|
||||
constexpr size_t k_max_group_key_map_size = CHIP_CONFIG_MAX_GROUP_KEYS_PER_FABRIC;
|
||||
|
||||
typedef struct group_key_map_attr {
|
||||
group_key_map_obj group_key_map_array[k_max_group_key_map_size];
|
||||
} group_key_map_attr_t;
|
||||
|
||||
static void group_key_map_attr_free(void *ctx)
|
||||
{
|
||||
group_key_map_attr_t *attr_ptr = reinterpret_cast<group_key_map_attr_t *>(ctx);
|
||||
chip::Platform::Delete(attr_ptr);
|
||||
}
|
||||
|
||||
static esp_err_t parse_group_key_map_json(char *json_str, group_key_map_attr_t *group_key_map,
|
||||
size_t *group_key_map_size)
|
||||
{
|
||||
jparse_ctx_t jctx;
|
||||
ESP_RETURN_ON_FALSE(json_parse_start(&jctx, json_str, strlen(json_str)) == 0, ESP_ERR_INVALID_ARG, TAG,
|
||||
"Group key map json string is wrong");
|
||||
size_t index = 0;
|
||||
while (index < k_max_group_key_map_size && json_arr_get_object(&jctx, index) == 0) {
|
||||
int int_val;
|
||||
// Fabric
|
||||
if (json_obj_get_int(&jctx, "fabricIndex", &int_val) == 0) {
|
||||
group_key_map->group_key_map_array[index].fabricIndex = int_val;
|
||||
}
|
||||
ESP_RETURN_ON_FALSE(json_obj_get_int(&jctx, "groupId", &int_val) == 0, ESP_ERR_INVALID_ARG, TAG,
|
||||
"Failed to get groupId");
|
||||
group_key_map->group_key_map_array[index].groupId = int_val;
|
||||
ESP_RETURN_ON_FALSE(json_obj_get_int(&jctx, "groupKeySetID", &int_val) == 0, ESP_ERR_INVALID_ARG, TAG,
|
||||
"Failed to get groupKeySetId");
|
||||
group_key_map->group_key_map_array[index].groupKeySetID = int_val;
|
||||
json_arr_leave_object(&jctx);
|
||||
index++;
|
||||
}
|
||||
*group_key_map_size = index;
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t write_attribute(uint64_t node_id, uint16_t endpoint_id, uint32_t attribute_id, char *attribute_val_str)
|
||||
{
|
||||
esp_err_t err = ESP_OK;
|
||||
switch (attribute_id) {
|
||||
case GroupKeyManagement::Attributes::GroupKeyMap::Id: {
|
||||
size_t group_key_map_size = 0;
|
||||
group_key_map_attr_t *attr_val = chip::Platform::New<group_key_map_attr_t>();
|
||||
ESP_RETURN_ON_FALSE(attr_val, ESP_ERR_NO_MEM, TAG, "Failed to alloc group_key_map_attr_t");
|
||||
ESP_RETURN_ON_ERROR(parse_group_key_map_json(attribute_val_str, attr_val, &group_key_map_size), TAG,
|
||||
"Failed to parse group_key_map json string");
|
||||
List<group_key_map_obj> group_key_map_list(attr_val->group_key_map_array, group_key_map_size);
|
||||
write_command<List<group_key_map_obj>> *cmd = New<write_command<List<group_key_map_obj>>>(
|
||||
node_id, endpoint_id, GroupKeyManagement::Id, attribute_id, group_key_map_list);
|
||||
ESP_RETURN_ON_FALSE(cmd, ESP_ERR_NO_MEM, TAG, "Failed to alloc memory for write_command");
|
||||
cmd->set_attribute_free_handler(group_key_map_attr_free, attr_val);
|
||||
return cmd->send_command();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
err = ESP_ERR_NOT_SUPPORTED;
|
||||
break;
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
} // namespace group_key_management
|
||||
|
||||
} // namespace clusters
|
||||
|
||||
esp_err_t send_write_attr_command(uint64_t node_id, uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_id,
|
||||
@@ -486,6 +555,9 @@ esp_err_t send_write_attr_command(uint64_t node_id, uint16_t endpoint_id, uint32
|
||||
case Binding::Id:
|
||||
return clusters::binding::write_attribute(node_id, endpoint_id, attribute_id, attribute_val_str);
|
||||
break;
|
||||
case GroupKeyManagement::Id:
|
||||
return clusters::group_key_management::write_attribute(node_id, endpoint_id, attribute_id, attribute_val_str);
|
||||
break;
|
||||
default:
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user