Merge branch 'bugfix/parent_endpoint' into 'main'

esp_matter_core: Fix parent_endpoint_id

See merge request app-frameworks/esp-matter!212
This commit is contained in:
Hrishikesh Dhayagude
2022-11-17 20:43:02 +08:00
4 changed files with 45 additions and 8 deletions
+17 -4
View File
@@ -157,6 +157,7 @@ typedef struct _endpoint {
EmberAfEndpointType *endpoint_type;
DataVersion *data_versions_ptr;
EmberAfDeviceType *device_types_ptr;
uint16_t parent_endpoint_id;
void *priv_data;
struct _endpoint *next;
} _endpoint_t;
@@ -433,7 +434,7 @@ static esp_err_t disable(endpoint_t *endpoint)
return ESP_OK;
}
esp_err_t enable(endpoint_t *endpoint, uint16_t parent_endpoint_id)
esp_err_t enable(endpoint_t *endpoint)
{
if (!endpoint) {
ESP_LOGE(TAG, "Endpoint cannot be NULL");
@@ -623,7 +624,7 @@ esp_err_t enable(endpoint_t *endpoint, uint16_t parent_endpoint_id)
/* Add Endpoint */
endpoint_index = endpoint::get_next_index();
status = emberAfSetDynamicEndpoint(endpoint_index, current_endpoint->endpoint_id, endpoint_type, data_versions,
device_types, parent_endpoint_id);
device_types, current_endpoint->parent_endpoint_id);
if (status != EMBER_ZCL_STATUS_SUCCESS) {
ESP_LOGE(TAG, "Error adding dynamic endpoint %d: 0x%x", current_endpoint->endpoint_id, status);
err = ESP_FAIL;
@@ -689,8 +690,7 @@ static esp_err_t enable_all()
endpoint_t *endpoint = get_first(node);
while (endpoint) {
/* The normal endpoints do not have parent endpoint */
enable(endpoint, chip::kInvalidEndpointId);
enable(endpoint);
endpoint = get_next(endpoint);
}
return ESP_OK;
@@ -1661,6 +1661,7 @@ endpoint_t *create(node_t *node, uint8_t flags, void *priv_data)
/* Set */
endpoint->endpoint_id = current_node->min_unused_endpoint_id++;
endpoint->device_type_count = 0;
endpoint->parent_endpoint_id = chip::kInvalidEndpointId;
endpoint->flags = flags;
endpoint->priv_data = priv_data;
@@ -1877,6 +1878,18 @@ uint8_t *get_device_type_versions(endpoint_t *endpoint, uint8_t *device_type_cou
return current_endpoint->device_type_versions;
}
esp_err_t set_parent_endpoint(endpoint_t *endpoint, endpoint_t *parent_endpoint)
{
if (!endpoint || !parent_endpoint) {
ESP_LOGE(TAG, "Endpoint or parent_endpoint cannot be NULL");
return ESP_ERR_INVALID_ARG;
}
_endpoint_t *current_endpoint = (_endpoint_t *)endpoint;
_endpoint_t *current_parent_endpoint = (_endpoint_t *)parent_endpoint;
current_endpoint->parent_endpoint_id = current_parent_endpoint->endpoint_id;
return ESP_OK;
}
void *get_priv_data(uint16_t endpoint_id)
{
node_t *node = node::get();
+14 -2
View File
@@ -248,6 +248,19 @@ uint32_t *get_device_type_ids(endpoint_t *endpoint, uint8_t *device_type_count_p
*/
uint8_t *get_device_type_versions(endpoint_t *endpoint, uint8_t *device_type_count_ptr);
/** Set parent endpoint
*
* Set the parent endpoint. This is useful in correctly setting the parts_list attribute for the parent, when the
* parent is a composite endpoint.
*
* @param[in] endpoint Endpoint handle.
* @param[out] parent_endpoint Parent endpoint handle.
*
* @return ESP_OK on success.
* @return error in case of failure.
*/
esp_err_t set_parent_endpoint(endpoint_t *endpoint, endpoint_t *parent_endpoint);
/** Get private data
*
* Get the private data passed while creating the endpoint.
@@ -267,12 +280,11 @@ void *get_priv_data(uint16_t endpoint_id);
* called after all the clusters, attributes and commands have been added to the created endpoint.
*
* @param[in] endpoint Endpoint handle.
* @param[in] parent_endpoint_id Parent Endpoint Id for the endpoint to be enabled, applicable only for bridges.
*
* @return ESP_OK on success.
* @return error in case of failure.
*/
esp_err_t enable(endpoint_t *endpoint, uint16_t parent_endpoint_id);
esp_err_t enable(endpoint_t *endpoint);
} /* endpoint */
@@ -242,6 +242,12 @@ device_t *create_device(node_t *node, uint16_t parent_endpoint_id, uint32_t devi
remove_device(dev);
return NULL;
}
endpoint_t *parent_endpoint = endpoint::get(node, parent_endpoint_id);
if (set_parent_endpoint(dev->endpoint, parent_endpoint) != ESP_OK) {
ESP_LOGE(TAG, "Failed to set parent endpoint for the bridged device");
remove_device(dev);
return NULL;
}
// Store the persistent information
dev->persistent_info.device_endpoint_id = esp_matter::endpoint::get_id(dev->endpoint);
@@ -299,6 +305,12 @@ device_t *resume_device(node_t *node, uint16_t device_endpoint_id)
remove_device(dev);
return NULL;
}
endpoint_t *parent_endpoint = endpoint::get(node, persistent_info.parent_endpoint_id);
if (set_parent_endpoint(dev->endpoint, parent_endpoint) != ESP_OK) {
ESP_LOGE(TAG, "Failed to set parent endpoint for the bridged device");
remove_device(dev);
return NULL;
}
return dev;
}
@@ -144,7 +144,7 @@ app_bridged_device_t *app_bridge_create_bridged_device(node_t *node, uint16_t pa
}
// Enable the created endpoint
esp_matter::endpoint::enable(new_dev->dev->endpoint, new_dev->dev->persistent_info.parent_endpoint_id);
esp_matter::endpoint::enable(new_dev->dev->endpoint);
return new_dev;
}
@@ -188,7 +188,7 @@ esp_err_t app_bridge_initialize(node_t *node)
g_current_bridged_device_count++;
//Enable the resumed endpoint
esp_matter::endpoint::enable(new_dev->dev->endpoint, new_dev->dev->persistent_info.parent_endpoint_id);
esp_matter::endpoint::enable(new_dev->dev->endpoint);
}
}
return ESP_OK;