Skip to content

Commit

Permalink
Setting the endpoint_id of all the uninitialized endpoints to invalid…
Browse files Browse the repository at this point in the history
… instead of 0
  • Loading branch information
chiragatal committed Jan 25, 2022
1 parent f0f5de0 commit cfa5121
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/app/util/attribute-storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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<uint16_t>(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;
}
Expand Down Expand Up @@ -213,15 +221,13 @@ EndpointId emberAfClearDynamicEndpoint(uint16_t index)

index = static_cast<uint8_t>(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;
Expand Down

0 comments on commit cfa5121

Please sign in to comment.