From b64fe67cb05b639f9ced35b61bf1480775e1ccd1 Mon Sep 17 00:00:00 2001 From: Chirag Atal Date: Fri, 21 Jan 2022 16:42:41 +0530 Subject: [PATCH] Setting the endpoint_id of all the uninitialized endpoints to invalid instead of 0 --- src/app/util/attribute-storage.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/app/util/attribute-storage.cpp b/src/app/util/attribute-storage.cpp index e621c011ee6922..84e77ade1ef05e 100644 --- a/src/app/util/attribute-storage.cpp +++ b/src/app/util/attribute-storage.cpp @@ -149,6 +149,10 @@ void emberAfEndpointConfigure(void) static_assert(EMBER_AF_ENDPOINT_DISABLED == 0, "We are creating enabled dynamic endpoints!"); memset(&emAfEndpoints[FIXED_ENDPOINT_COUNT], 0, sizeof(EmberAfDefinedEndpoint) * (MAX_ENDPOINT_COUNT - FIXED_ENDPOINT_COUNT)); + for (ep = FIXED_ENDPOINT_COUNT; ep < MAX_ENDPOINT_COUNT; ep++) + { + emAfEndpoints[ep].endpoint = kInvalidEndpointId; + } } #endif } @@ -180,11 +184,15 @@ EmberAfStatus emberAfSetDynamicEndpoint(uint16_t index, EndpointId id, EmberAfEn { return EMBER_ZCL_STATUS_INSUFFICIENT_SPACE; } + if (id == kInvalidEndpointId) + { + return EMBER_ZCL_STATUS_CONSTRAINT_ERROR; + } index = static_cast(realIndex); for (uint16_t i = FIXED_ENDPOINT_COUNT; i < MAX_ENDPOINT_COUNT; i++) { - if (emAfEndpoints[i].endpoint == id && emAfEndpoints[i].endpointType != NULL) + if (emAfEndpoints[i].endpoint == id) { return EMBER_ZCL_STATUS_DUPLICATE_EXISTS; } @@ -213,15 +221,13 @@ EndpointId emberAfClearDynamicEndpoint(uint16_t index) index = static_cast(index + FIXED_ENDPOINT_COUNT); - if ((index < MAX_ENDPOINT_COUNT) && (emAfEndpoints[index].endpoint != 0) && (emberAfEndpointIndexIsEnabled(index))) + if ((index < MAX_ENDPOINT_COUNT) && (emAfEndpoints[index].endpoint != kInvalidEndpointId) && + (emberAfEndpointIndexIsEnabled(index))) { ep = emAfEndpoints[index].endpoint; - if (ep) - { - emberAfSetDeviceEnabled(ep, false); - emberAfEndpointEnableDisable(ep, false); - emAfEndpoints[index].endpoint = 0; - } + emberAfSetDeviceEnabled(ep, false); + emberAfEndpointEnableDisable(ep, false); + emAfEndpoints[index].endpoint = kInvalidEndpointId; } return ep;