@@ -22,23 +22,49 @@ namespace scenes {
22
22
23
23
namespace {
24
24
25
- // / ValideAttribute
25
+ using ConcreteAttributePath = app::ConcreteAttributePath;
26
+ using AttributeValuePairType = app::Clusters::ScenesManagement::Structs::AttributeValuePair::Type;
27
+
28
+ // / CapAttributeID
29
+ // / Cap the attribute value based on the attribute type size
30
+ // / @param[in] aVPair AttributeValuePairType
31
+ // / @param[in] metadata EmberAfAttributeMetadata
32
+ // /
33
+ void CapAttributeID (AttributeValuePairType & aVPair, const EmberAfAttributeMetadata * metadata)
34
+ {
35
+ // Calculate the maximum value that can be represented with the given number of bytes
36
+ uint64_t maxValue = (1ULL << (metadata->size * 8 )) - 1 ;
37
+
38
+ // If the attribute ID is greater than the maximum value, cap it
39
+ if (aVPair.attributeValue > maxValue)
40
+ {
41
+ aVPair.attributeValue = maxValue;
42
+ }
43
+ }
44
+
26
45
// / @brief Validate the attribute exists for a given cluster
46
+ // / @param[in] endpoint Endpoint ID
27
47
// / @param[in] clusterID Cluster ID
28
- // / @param[in] attID Attribute ID
48
+ // / @param[in] aVPair AttributeValuePairType, will be mutated to cap the value if it is out of range
29
49
// / @return CHIP_ERROR_UNSUPPORTED_ATTRIBUTE if the attribute does not exist for a given cluster or is not scenable
30
50
// / @note This will allways fail for global list attributes. If we do want to make them scenable someday, we will need to
31
51
// / use a different validation method.
32
- // TODO: Assess if we also want to throw an error if the attribute value is out of range
52
+ // TODO: Assess if (and how) we also want to throw an error if the attribute value is out of range
33
53
// TODO: Add check for "S" quality to determine if the attribute is scenable once suported :
34
54
// https://github.com/project-chip/connectedhomeip/issues/24177
35
- CHIP_ERROR ValidateAttributePath (EndpointId endpoint, ClusterId cluster, AttributeId attributeId )
55
+ CHIP_ERROR ValidateAttributePath (EndpointId endpoint, ClusterId cluster, AttributeValuePairType & aVPair )
36
56
{
37
- bool attIndex = emberAfContainsAttribute (endpoint, cluster, attributeId );
57
+ bool attIndex = emberAfContainsAttribute (endpoint, cluster, aVPair. attributeID );
38
58
if (!attIndex)
39
59
{
40
60
return CHIP_ERROR_UNSUPPORTED_ATTRIBUTE;
41
61
}
62
+
63
+ EmberAfAttributeMetadata metadata = *emberAfLocateAttributeMetadata (endpoint, cluster, aVPair.attributeID );
64
+
65
+ // Cap value based on the attribute type size
66
+ CapAttributeID (aVPair, &metadata);
67
+
42
68
return CHIP_NO_ERROR;
43
69
}
44
70
} // namespace
@@ -81,8 +107,9 @@ DefaultSceneHandlerImpl::SerializeAdd(EndpointId endpoint, const ExtensionFieldS
81
107
auto pair_iterator = extensionFieldSet.attributeValueList .begin ();
82
108
while (pair_iterator.Next ())
83
109
{
84
- ReturnErrorOnFailure (ValidateAttributePath (endpoint, extensionFieldSet.clusterID , pair_iterator.GetValue ().attributeID ));
85
- aVPairs[pairCount] = pair_iterator.GetValue ();
110
+ AttributeValuePairType currentPair = pair_iterator.GetValue ();
111
+ ReturnErrorOnFailure (ValidateAttributePath (endpoint, extensionFieldSet.clusterID , currentPair));
112
+ aVPairs[pairCount] = currentPair;
86
113
pairCount++;
87
114
}
88
115
ReturnErrorOnFailure (pair_iterator.GetStatus ());
0 commit comments