@@ -542,61 +542,66 @@ CHIP_ERROR prepareWriteData(const EmberAfAttributeMetadata * metadata, TLV::TLVR
542
542
}
543
543
} // namespace
544
544
545
- static Protocols::InteractionModel::Status WriteSingleClusterDataInternal (ClusterInfo & aClusterInfo, TLV::TLVReader & aReader,
546
- WriteHandler * apWriteHandler)
545
+ static Protocols::InteractionModel::Status WriteSingleClusterDataInternal (const ConcreteAttributePath aPath,
546
+ const EmberAfAttributeMetadata * aMetadata,
547
+ TLV::TLVReader & aReader, WriteHandler * apWriteHandler)
547
548
{
548
- // Passing nullptr as buf to emberAfReadAttribute means we only need attribute type here, and ember will not do data read &
549
- // copy in this case.
550
- const EmberAfAttributeMetadata * attributeMetadata = emberAfLocateAttributeMetadata (
551
- aClusterInfo.mEndpointId , aClusterInfo.mClusterId , aClusterInfo.mAttributeId , CLUSTER_MASK_SERVER, 0 );
552
-
553
- if (attributeMetadata == nullptr )
554
- {
555
- return Protocols::InteractionModel::Status::UnsupportedAttribute;
556
- }
557
-
558
549
CHIP_ERROR preparationError = CHIP_NO_ERROR;
559
550
uint16_t dataLen = 0 ;
560
- if ((preparationError = prepareWriteData (attributeMetadata , aReader, dataLen)) != CHIP_NO_ERROR)
551
+ if ((preparationError = prepareWriteData (aMetadata , aReader, dataLen)) != CHIP_NO_ERROR)
561
552
{
562
553
ChipLogDetail (Zcl, " Failed to prepare data to write: %s" , ErrorStr (preparationError));
563
554
return Protocols::InteractionModel::Status::InvalidValue;
564
555
}
565
556
566
- if (dataLen > attributeMetadata ->size )
557
+ if (dataLen > aMetadata ->size )
567
558
{
568
559
ChipLogDetail (Zcl, " Data to write exceedes the attribute size claimed." );
569
560
return Protocols::InteractionModel::Status::InvalidValue;
570
561
}
571
562
572
- return ToInteractionModelStatus (emberAfWriteAttributeExternal (aClusterInfo.mEndpointId , aClusterInfo.mClusterId ,
573
- aClusterInfo.mAttributeId , CLUSTER_MASK_SERVER, 0 , attributeData,
574
- attributeMetadata->attributeType ));
563
+ return ToInteractionModelStatus (emberAfWriteAttributeExternal (aPath.mEndpointId , aPath.mClusterId , aPath.mAttributeId ,
564
+ CLUSTER_MASK_SERVER, 0 , attributeData, aMetadata->attributeType ));
575
565
}
576
566
577
567
CHIP_ERROR WriteSingleClusterData (ClusterInfo & aClusterInfo, TLV::TLVReader & aReader, WriteHandler * apWriteHandler)
578
568
{
569
+ // TODO: Refactor WriteSingleClusterData and all dependent functions to take ConcreteAttributePath instead of ClusterInfo
570
+ // as the input argument.
579
571
AttributePathParams attributePathParams;
580
572
attributePathParams.mEndpointId = aClusterInfo.mEndpointId ;
581
573
attributePathParams.mClusterId = aClusterInfo.mClusterId ;
582
574
attributePathParams.mAttributeId = aClusterInfo.mAttributeId ;
583
575
584
- // TODO: Refactor WriteSingleClusterData and all dependent functions to take ConcreteAttributePath instead of ClusterInfo
585
- // as the input argument.
576
+ // Named aPath for now to reduce the amount of code change that needs to
577
+ // happen when the above TODO is resolved.
578
+ ConcreteAttributePath aPath (aClusterInfo.mEndpointId , aClusterInfo.mClusterId , aClusterInfo.mAttributeId );
579
+ const EmberAfAttributeMetadata * attributeMetadata =
580
+ emberAfLocateAttributeMetadata (aPath.mEndpointId , aPath.mClusterId , aPath.mAttributeId , CLUSTER_MASK_SERVER, 0 );
581
+
582
+ if (attributeMetadata == nullptr )
583
+ {
584
+ return apWriteHandler->AddStatus (attributePathParams, Protocols::InteractionModel::Status::UnsupportedAttribute);
585
+ }
586
+
587
+ if (attributeMetadata->IsReadOnly ())
588
+ {
589
+ return apWriteHandler->AddStatus (attributePathParams, Protocols::InteractionModel::Status::UnsupportedWrite);
590
+ }
591
+
586
592
AttributeAccessInterface * attrOverride = findAttributeAccessOverride (aClusterInfo.mEndpointId , aClusterInfo.mClusterId );
587
593
if (attrOverride != nullptr )
588
594
{
589
- ConcreteAttributePath path (aClusterInfo.mEndpointId , aClusterInfo.mClusterId , aClusterInfo.mAttributeId );
590
595
AttributeValueDecoder valueDecoder (aReader);
591
- ReturnErrorOnFailure (attrOverride->Write (path , valueDecoder));
596
+ ReturnErrorOnFailure (attrOverride->Write (aPath , valueDecoder));
592
597
593
598
if (valueDecoder.TriedDecode ())
594
599
{
595
600
return apWriteHandler->AddStatus (attributePathParams, Protocols::InteractionModel::Status::Success);
596
601
}
597
602
}
598
603
599
- auto imCode = WriteSingleClusterDataInternal (aClusterInfo , aReader, apWriteHandler);
604
+ auto imCode = WriteSingleClusterDataInternal (aPath, attributeMetadata , aReader, apWriteHandler);
600
605
return apWriteHandler->AddStatus (attributePathParams, imCode);
601
606
}
602
607
0 commit comments