Skip to content

Commit aaeafb0

Browse files
committed
Merge branch 'imdm/3-ember-read-attribute' of github.com:andy31415/connectedhomeip into imdm/3-ember-read-attribute
2 parents 9394cd6 + adbb76b commit aaeafb0

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

src/app/codegen-data-model/CodegenDataModel_Read.cpp

+10-6
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,19 @@ FindAttributeMetadata(const ConcreteAttributePath & aPath)
6161
{
6262
for (auto & attr : GlobalAttributesNotInMetadata)
6363
{
64+
6465
if (attr == aPath.mAttributeId)
6566
{
6667
const EmberAfCluster * cluster = emberAfFindServerCluster(aPath.mEndpointId, aPath.mClusterId);
67-
ReturnErrorCodeIf(cluster == nullptr, CHIP_IM_GLOBAL_STATUS(UnsupportedAttribute));
68+
if (cluster == nullptr)
69+
{
70+
return (emberAfFindEndpointType(aPath.mEndpointId) == nullptr) ? CHIP_IM_GLOBAL_STATUS(UnsupportedEndpoint)
71+
: CHIP_IM_GLOBAL_STATUS(UnsupportedCluster);
72+
}
73+
6874
return cluster;
6975
}
7076
}
71-
7277
const EmberAfAttributeMetadata * metadata =
7378
emberAfLocateAttributeMetadata(aPath.mEndpointId, aPath.mClusterId, aPath.mAttributeId);
7479

@@ -123,7 +128,7 @@ std::optional<CHIP_ERROR> TryReadViaAccessInterface(const ConcreteAttributePath
123128
}
124129

125130
// If the encoder tried to encode, then a value should have been written.
126-
// - if encode, assueme DONE (i.e. FINAL CHIP_NO_ERROR)
131+
// - if encode, assume DONE (i.e. FINAL CHIP_NO_ERROR)
127132
// - if no encode, say that processing must continue
128133
return encoder.TriedEncode() ? std::make_optional(CHIP_NO_ERROR) : std::nullopt;
129134
}
@@ -290,7 +295,7 @@ CHIP_ERROR EncodeEmberValue(ByteSpan data, const EmberAfAttributeMetadata * meta
290295
CHIP_ERROR CodegenDataModel::ReadAttribute(const InteractionModel::ReadAttributeRequest & request, AttributeValueEncoder & encoder)
291296
{
292297
ChipLogDetail(DataManagement,
293-
"Reading attribute: Cluster=" ChipLogFormatMEI " Endpoint=%x AttributeId=" ChipLogFormatMEI " (expanded=%d)",
298+
"Reading attribute: Cluster=" ChipLogFormatMEI " Endpoint=0x%x AttributeId=" ChipLogFormatMEI " (expanded=%d)",
294299
ChipLogValueMEI(request.path.mClusterId), request.path.mEndpointId, ChipLogValueMEI(request.path.mAttributeId),
295300
request.path.mExpanded);
296301

@@ -340,8 +345,7 @@ CHIP_ERROR CodegenDataModel::ReadAttribute(const InteractionModel::ReadAttribute
340345
{
341346
// if we only got a cluster, this was for a global attribute. We cannot read ember attributes
342347
// at this point, so give up (although GlobalAttributeReader should have returned something here).
343-
// Return a permanent failure...
344-
return CHIP_IM_GLOBAL_STATUS(UnsupportedAttribute);
348+
chipDie();
345349
}
346350
const EmberAfAttributeMetadata * attributeMetadata = std::get<const EmberAfAttributeMetadata *>(metadata);
347351

src/app/codegen-data-model/tests/TestAttributeReportIBsEncoding.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ CHIP_ERROR DecodeAttributeReportIBs(ByteSpan data, std::vector<DecodedAttributeD
4343
// 0x01 => Array (i.e. report data ib)
4444
// ReportIB*
4545
//
46-
// Overally this is VERY hard to process ...
46+
// Generally this is VERY hard to process ...
4747
//
4848
TLV::TLVReader reportIBsReader;
4949
reportIBsReader.Init(data);

src/app/codegen-data-model/tests/TestCodegenModelViaMocks.cpp

+21
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,27 @@ TEST(TestCodegenModelViaMocks, EmberAttributeReadAclDeny)
976976
ASSERT_EQ(model.ReadAttribute(testRequest.request, *encoder), CHIP_ERROR_ACCESS_DENIED);
977977
}
978978

979+
TEST(TestCodegenModelViaMocks, ReadForInvalidGlobalAttributePath)
980+
{
981+
UseMockNodeConfig config(gTestNodeConfig);
982+
chip::app::CodegenDataModel model;
983+
ScopedMockAccessControl accessControl;
984+
985+
{
986+
TestReadRequest testRequest(kAdminSubjectDescriptor,
987+
ConcreteAttributePath(kEndpointIdThatIsMissing, MockClusterId(1), AttributeList::Id));
988+
std::unique_ptr<AttributeValueEncoder> encoder = testRequest.StartEncoding(&model);
989+
ASSERT_EQ(model.ReadAttribute(testRequest.request, *encoder), CHIP_IM_GLOBAL_STATUS(UnsupportedEndpoint));
990+
}
991+
992+
{
993+
TestReadRequest testRequest(kAdminSubjectDescriptor,
994+
ConcreteAttributePath(kMockEndpoint1, kInvalidClusterId, AttributeList::Id));
995+
std::unique_ptr<AttributeValueEncoder> encoder = testRequest.StartEncoding(&model);
996+
ASSERT_EQ(model.ReadAttribute(testRequest.request, *encoder), CHIP_IM_GLOBAL_STATUS(UnsupportedCluster));
997+
}
998+
}
999+
9791000
TEST(TestCodegenModelViaMocks, EmberAttributeInvalidRead)
9801001
{
9811002
UseMockNodeConfig config(gTestNodeConfig);

0 commit comments

Comments
 (0)