Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add functions to set Parent Endpoint and Composition Type for an Endpoint #28410

Merged
Merged
20 changes: 19 additions & 1 deletion src/app/clusters/descriptor/descriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ CHIP_ERROR DescriptorAttrAccess::ReadPartsAttribute(EndpointId endpoint, Attribu
return CHIP_NO_ERROR;
});
}
else
else if (IsFlatCompositionForEndpoint(endpoint))
{
err = aEncoder.EncodeList([endpoint](const auto & encoder) -> CHIP_ERROR {
for (uint16_t index = 0; index < emberAfEndpointCount(); index++)
Expand Down Expand Up @@ -104,6 +104,24 @@ CHIP_ERROR DescriptorAttrAccess::ReadPartsAttribute(EndpointId endpoint, Attribu
return CHIP_NO_ERROR;
});
}
else if (IsTreeCompositionForEndpoint(endpoint))
{
err = aEncoder.EncodeList([endpoint](const auto & encoder) -> CHIP_ERROR {
for (uint16_t index = 0; index < emberAfEndpointCount(); index++)
{
if (!emberAfEndpointIndexIsEnabled(index))
continue;

EndpointId parentEndpointId = emberAfParentEndpointFromIndex(index);
if (parentEndpointId == endpoint)
{
ReturnErrorOnFailure(encoder.Encode(emberAfEndpointFromIndex(index)));
}
}

return CHIP_NO_ERROR;
});
}

return err;
}
Expand Down
15 changes: 6 additions & 9 deletions src/app/util/af-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,11 @@ typedef struct
uint16_t endpointSize;
} EmberAfEndpointType;

#ifdef DOXYGEN_SHOULD_SKIP_THIS
enum EmberAfEndpointBitmask;
#else
typedef uint8_t EmberAfEndpointBitmask;
enum
#endif
{ EMBER_AF_ENDPOINT_DISABLED = 0x00,
EMBER_AF_ENDPOINT_ENABLED = 0x01,
enum class EmberAfEndpointOptions : uint8_t
{
isEnabled = 0x1,
isFlatComposition = 0x2,
isTreeComposition = 0x3,
};

/**
Expand All @@ -209,7 +206,7 @@ struct EmberAfDefinedEndpoint
/**
* Meta-data about the endpoint
*/
EmberAfEndpointBitmask bitmask = EMBER_AF_ENDPOINT_DISABLED;
chip::BitMask<EmberAfEndpointOptions> bitmask;
/**
* Endpoint type for this endpoint.
*/
Expand Down
27 changes: 26 additions & 1 deletion src/app/util/af.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ extern EmberAfDefinedEndpoint emAfEndpoints[];
#endif

/**
* @brief Returns root endpoint of a composed bridged device
* @brief Returns parent endpoint for a given endpoint index
*/
chip::EndpointId emberAfParentEndpointFromIndex(uint16_t index);

Expand Down Expand Up @@ -303,5 +303,30 @@ class EnabledEndpointsWithServerCluster
ClusterId mClusterId;
};

/**
* @brief Sets the parent endpoint for a given endpoint
*/
EmberAfStatus SetParentEndpointForEndpoint(EndpointId childEndpoint, EndpointId parentEndpoint);
mhazley marked this conversation as resolved.
Show resolved Hide resolved

/**
* @brief Sets an Endpoint to use Flat Composition
*/
EmberAfStatus SetFlatCompositionForEndpoint(EndpointId endpoint);

/**
* @brief Sets an Endpoint to use Tree Composition
*/
EmberAfStatus SetTreeCompositionForEndpoint(EndpointId endpoint);

/**
* @brief Returns true is an Endpoint has flat composition
*/
bool IsFlatCompositionForEndpoint(EndpointId endpoint);

/**
* @brief Returns true is an Endpoint has tree composition
*/
bool IsTreeCompositionForEndpoint(EndpointId endpoint);

} // namespace app
} // namespace chip
74 changes: 67 additions & 7 deletions src/app/util/attribute-storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,9 @@ void emberAfEndpointConfigure()
emAfEndpoints[ep].deviceTypeList = endpointDeviceTypeList(ep);
emAfEndpoints[ep].endpointType = endpointTypeMacro(ep);
emAfEndpoints[ep].dataVersions = currentDataVersions;
emAfEndpoints[ep].bitmask = EMBER_AF_ENDPOINT_ENABLED;

emAfEndpoints[ep].bitmask.Set(EmberAfEndpointOptions::isEnabled);
emAfEndpoints[ep].bitmask.Set(EmberAfEndpointOptions::isFlatComposition);

// Increment currentDataVersions by 1 (slot) for every server cluster
// this endpoint has.
Expand Down Expand Up @@ -271,7 +273,7 @@ EmberAfStatus emberAfSetDynamicEndpoint(uint16_t index, EndpointId id, const Emb
emAfEndpoints[index].endpointType = ep;
emAfEndpoints[index].dataVersions = dataVersionStorage.data();
// Start the endpoint off as disabled.
emAfEndpoints[index].bitmask = EMBER_AF_ENDPOINT_DISABLED;
emAfEndpoints[index].bitmask.Clear(EmberAfEndpointOptions::isEnabled);
emAfEndpoints[index].parentEndpointId = parentEndpointId;

emberAfSetDynamicEndpointCount(MAX_ENDPOINT_COUNT - FIXED_ENDPOINT_COUNT);
Expand Down Expand Up @@ -322,7 +324,7 @@ uint16_t emberAfEndpointCount()

bool emberAfEndpointIndexIsEnabled(uint16_t index)
{
return (emAfEndpoints[index].bitmask & EMBER_AF_ENDPOINT_ENABLED);
return (emAfEndpoints[index].bitmask.Has(EmberAfEndpointOptions::isEnabled));
}

bool emberAfIsStringAttributeType(EmberAfAttributeType attributeType)
Expand Down Expand Up @@ -838,7 +840,7 @@ static uint16_t findIndexFromEndpoint(EndpointId endpoint, bool ignoreDisabledEn
for (epi = 0; epi < emberAfEndpointCount(); epi++)
{
if (emAfEndpoints[epi].endpoint == endpoint &&
(!ignoreDisabledEndpoints || emAfEndpoints[epi].bitmask & EMBER_AF_ENDPOINT_ENABLED))
(!ignoreDisabledEndpoints || emAfEndpoints[epi].bitmask.Has(EmberAfEndpointOptions::isEnabled)))
{
return epi;
}
Expand Down Expand Up @@ -919,11 +921,11 @@ bool emberAfEndpointEnableDisable(EndpointId endpoint, bool enable)
return false;
}

currentlyEnabled = emAfEndpoints[index].bitmask & EMBER_AF_ENDPOINT_ENABLED;
currentlyEnabled = emAfEndpoints[index].bitmask.Has(EmberAfEndpointOptions::isEnabled);

if (enable)
{
emAfEndpoints[index].bitmask |= EMBER_AF_ENDPOINT_ENABLED;
emAfEndpoints[index].bitmask.Set(EmberAfEndpointOptions::isEnabled);
}

#if defined(EZSP_HOST)
Expand Down Expand Up @@ -962,7 +964,7 @@ bool emberAfEndpointEnableDisable(EndpointId endpoint, bool enable)

if (!enable)
{
emAfEndpoints[index].bitmask &= EMBER_AF_ENDPOINT_DISABLED;
emAfEndpoints[index].bitmask.Clear(EmberAfEndpointOptions::isEnabled);
}

return true;
Expand Down Expand Up @@ -1421,6 +1423,64 @@ app::AttributeAccessInterface * GetAttributeAccessOverride(EndpointId endpointId

return nullptr;
}

EmberAfStatus SetParentEndpointForEndpoint(EndpointId childEndpoint, EndpointId parentEndpoint)
{
uint16_t childIndex = emberAfIndexFromEndpoint(childEndpoint);
uint16_t parentIndex = emberAfIndexFromEndpoint(parentEndpoint);

if (childIndex == kEmberInvalidEndpointIndex || parentIndex == kEmberInvalidEndpointIndex)
{
return EMBER_ZCL_STATUS_UNSUPPORTED_ENDPOINT;
}
emAfEndpoints[childIndex].parentEndpointId = parentEndpoint;
return EMBER_ZCL_STATUS_SUCCESS;
}

EmberAfStatus SetFlatCompositionForEndpoint(EndpointId endpoint)
{
uint16_t index = emberAfIndexFromEndpoint(endpoint);
if (index == kEmberInvalidEndpointIndex)
{
return EMBER_ZCL_STATUS_UNSUPPORTED_ENDPOINT;
}
emAfEndpoints[index].bitmask.Clear(EmberAfEndpointOptions::isTreeComposition);
emAfEndpoints[index].bitmask.Set(EmberAfEndpointOptions::isFlatComposition);
return EMBER_ZCL_STATUS_SUCCESS;
}

EmberAfStatus SetTreeCompositionForEndpoint(EndpointId endpoint)
{
uint16_t index = emberAfIndexFromEndpoint(endpoint);
if (index == kEmberInvalidEndpointIndex)
{
return EMBER_ZCL_STATUS_UNSUPPORTED_ENDPOINT;
}
emAfEndpoints[index].bitmask.Clear(EmberAfEndpointOptions::isFlatComposition);
emAfEndpoints[index].bitmask.Set(EmberAfEndpointOptions::isTreeComposition);
mhazley marked this conversation as resolved.
Show resolved Hide resolved
return EMBER_ZCL_STATUS_SUCCESS;
}

bool IsFlatCompositionForEndpoint(EndpointId endpoint)
{
uint16_t index = emberAfIndexFromEndpoint(endpoint);
if (index == kEmberInvalidEndpointIndex)
{
return false;
}
return emAfEndpoints[index].bitmask.Has(EmberAfEndpointOptions::isFlatComposition);
}

bool IsTreeCompositionForEndpoint(EndpointId endpoint)
{
uint16_t index = emberAfIndexFromEndpoint(endpoint);
if (index == kEmberInvalidEndpointIndex)
{
return false;
}
return emAfEndpoints[index].bitmask.Has(EmberAfEndpointOptions::isTreeComposition);
}

} // namespace app
} // namespace chip

Expand Down