Skip to content

Commit

Permalink
Merge branch 'master' into feature/add-chef-air-conditioner
Browse files Browse the repository at this point in the history
  • Loading branch information
mideayanghui committed Aug 3, 2023
2 parents 53d8857 + 59a0b2f commit 87a9a2c
Show file tree
Hide file tree
Showing 16 changed files with 344 additions and 104 deletions.
5 changes: 5 additions & 0 deletions src/app/AttributePathExpandIterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ void AttributePathExpandIterator::PrepareAttributeIndexRange(const AttributePath
}
mGlobalAttributeEndIndex = static_cast<uint8_t>(mGlobalAttributeIndex + 1);
}
else
{
mGlobalAttributeIndex = UINT8_MAX;
mGlobalAttributeEndIndex = 0;
}
}
}

Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -654,9 +654,10 @@ bool emberAfOperationalCredentialsClusterAddNOCCallback(app::CommandHandler * co

// Set the Identity Protection Key (IPK)
// The IPK SHALL be the operational group key under GroupKeySetID of 0
keyset.keyset_id = Credentials::GroupDataProvider::kIdentityProtectionKeySetId;
keyset.policy = GroupKeyManagement::GroupKeySecurityPolicyEnum::kTrustFirst;
keyset.num_keys_used = 1;
keyset.keyset_id = Credentials::GroupDataProvider::kIdentityProtectionKeySetId;
keyset.policy = GroupKeyManagement::GroupKeySecurityPolicyEnum::kTrustFirst;
keyset.num_keys_used = 1;
keyset.epoch_keys[0].start_time = 0;
memcpy(keyset.epoch_keys[0].key, ipkValue.data(), Crypto::CHIP_CRYPTO_SYMMETRIC_KEY_LENGTH_BYTES);

err = newFabricInfo->GetCompressedFabricIdBytes(compressed_fabric_id);
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
*/
CHIP_ERROR SetParentEndpointForEndpoint(EndpointId childEndpoint, EndpointId parentEndpoint);

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

/**
* @brief Sets an Endpoint to use Tree Composition
*/
CHIP_ERROR 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;
}

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

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

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

CHIP_ERROR SetTreeCompositionForEndpoint(EndpointId endpoint)
{
uint16_t index = emberAfIndexFromEndpoint(endpoint);
if (index == kEmberInvalidEndpointIndex)
{
return CHIP_ERROR_INVALID_ARGUMENT;
}
emAfEndpoints[index].bitmask.Clear(EmberAfEndpointOptions::isFlatComposition);
emAfEndpoints[index].bitmask.Set(EmberAfEndpointOptions::isTreeComposition);
return CHIP_NO_ERROR;
}

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
2 changes: 1 addition & 1 deletion src/crypto/CHIPCryptoPAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ CHIP_ERROR Hash_SHA1(const uint8_t * data, size_t data_length, uint8_t * out_buf
* All implementations must check for std::is_trivially_copyable.
**/

struct alignas(size_t) HashSHA256OpaqueContext
struct alignas(CHIP_CONFIG_SHA256_CONTEXT_ALIGN) HashSHA256OpaqueContext
{
uint8_t mOpaque[kMAX_Hash_SHA256_Context_Size];
};
Expand Down
Loading

0 comments on commit 87a9a2c

Please sign in to comment.