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

Move ::WriteAttribute validation inside Interaction Model Write Handling #37322

Open
wants to merge 32 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
39dece4
Move write validity inside the write handler rather than requesting t…
andreilitvin Jan 30, 2025
0b37533
Restyle
andreilitvin Jan 30, 2025
345fffe
A bit of code cleanup and reuse, to minimize flash impact
andreilitvin Jan 30, 2025
963a235
Restyle
andreilitvin Jan 30, 2025
9f0ba20
Drop the mPreviousSuccessPath, making objects smaller and saving yet …
andreilitvin Jan 30, 2025
d00c1ba
Cleanup some includes
andreilitvin Jan 30, 2025
a5fc51a
Restyle
andreilitvin Jan 30, 2025
cc77d33
Remove obsolete tests from codgen, as we do not do more validation now
andreilitvin Jan 30, 2025
30670c8
Test write interaction passes
andreilitvin Jan 30, 2025
556d06b
Test write passes
andreilitvin Jan 30, 2025
299e75a
Slight clarity of code update
andreilitvin Jan 30, 2025
d6cb071
Fix comment
andreilitvin Jan 30, 2025
9d38910
Manual check for last written saves 16 bytes of flash on QPG.
andreilitvin Jan 30, 2025
77ba731
Status success is 2 bytes smaller in code generation than CHIP_NO_ERROR
andreilitvin Jan 30, 2025
abb61d3
Not using endpoint finder saves flash
andreilitvin Jan 30, 2025
f51eb31
Clean up code. We now save flash
andreilitvin Jan 30, 2025
714e7bf
More flash savings by reusing the server cluster finder
andreilitvin Jan 30, 2025
8346610
Update src/app/data-model-provider/MetadataLookup.cpp
andy31415 Jan 30, 2025
bc00cfd
Update src/app/data-model-provider/MetadataLookup.h
andy31415 Jan 30, 2025
266c8b9
Update src/app/data-model-provider/Provider.h
andy31415 Jan 30, 2025
ca7e6cf
Update src/app/data-model-provider/MetadataLookup.h
andy31415 Jan 30, 2025
3090732
Updated comment
andreilitvin Jan 30, 2025
d36e731
Hoist "writing" log up in processing, to preserve similar functionality
andreilitvin Jan 30, 2025
61d7ac7
Code clarity updates
andreilitvin Jan 31, 2025
b5d9035
Fix includes and update the code AGAIN because it does seem we use mo…
andreilitvin Jan 31, 2025
70ca917
Fix unsupported write on global attributes
andreilitvin Jan 31, 2025
ea2daaf
Fix includes
andreilitvin Jan 31, 2025
1d34e06
Update src/app/WriteHandler.cpp
andy31415 Feb 1, 2025
5509caf
Merge branch 'master' into write_handler_validation
andreilitvin Feb 6, 2025
3e224f4
Post merge cleanup
andreilitvin Feb 6, 2025
b0111d9
Fix merge error
andreilitvin Feb 6, 2025
17dbfe0
Merge branch 'master' into write_handler_validation
andreilitvin Feb 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/app/WriteHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -788,9 +788,13 @@ DataModel::ActionReturnStatus WriteHandler::CheckWriteAllowed(const Access::Subj
{
// NOTE: explicit cast/check only for attribute path and nothing else.
//
// In particular `request.path` is a DATA path (contains a list index)
// and we do not want mLastSuccessfullyWrittenPath to be auto-cast to a
// Specifically we DO NOT use `operator==` because `aPath` is a
// DATA path (contains a list index) and we do not want
andy31415 marked this conversation as resolved.
Show resolved Hide resolved
// mLastSuccessfullyWrittenPath to be auto-cast to a
// data path with a empty list and fail the compare.
//
// This inline endpoint/cluster/attribute compare results in
// smaller code as well.
if ((aPath.mEndpointId == mLastSuccessfullyWrittenPath->mEndpointId) &&
(aPath.mClusterId == mLastSuccessfullyWrittenPath->mClusterId) &&
(aPath.mAttributeId == mLastSuccessfullyWrittenPath->mAttributeId))
Expand Down Expand Up @@ -830,6 +834,9 @@ CHIP_ERROR WriteHandler::WriteClusterData(const Access::SubjectDescriptor & aSub
// the write is done via the DataModel interface
VerifyOrReturnError(mDataModelProvider != nullptr, CHIP_ERROR_INCORRECT_STATE);

ChipLogDetail(DataManagement, "Writing attribute: Cluster=" ChipLogFormatMEI " Endpoint=0x%x AttributeId=" ChipLogFormatMEI,
ChipLogValueMEI(aPath.mClusterId), aPath.mEndpointId, ChipLogValueMEI(aPath.mAttributeId));

DataModel::ActionReturnStatus status = CheckWriteAllowed(aSubject, aPath);
andy31415 marked this conversation as resolved.
Show resolved Hide resolved
if (status.IsSuccess())
{
Expand Down
2 changes: 1 addition & 1 deletion src/app/data-model-provider/MetadataLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Protocols::InteractionModel::Status ValidateClusterPath(ProviderMetadataTree * p
return successStatus;
}

// if we get here, the path is invalid.
// If we get here, the cluster identified by the path does not exist.
auto endpoints = provider->EndpointsIgnoreError();
for (auto & endpointEntry : endpoints)
{
Expand Down
6 changes: 3 additions & 3 deletions src/app/data-model-provider/MetadataLookup.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ class AttributeFinder
ReadOnlyBuffer<AttributeEntry> mAttributes;
};

/// Validates that `path` exists within the given provider
/// Validates that the cluster identified by `path` exists within the given provider.
///
/// If `endpointID` is not valid, will return Status::UnsupportedEndpoint
/// If `clusterId` is not valid, will return Status::UnsupportedCluster
/// If the endpoint identified by the path does not exist, will return Status::UnsupportedEndpoint.
/// If the endpoint exists but does not have the cluster identified by the path, will return Status::UnsupportedCluster.
///
/// otherwise, it will return successStatus.
Protocols::InteractionModel::Status ValidateClusterPath(ProviderMetadataTree * provider, const ConcreteClusterPath & path,
Expand Down
2 changes: 1 addition & 1 deletion src/app/data-model-provider/Provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class Provider : public ProviderMetadataTree
///
/// When this is invoked, caller is expected to have already done some validations:
/// - cluster `data version` has been checked for the incoming request if applicable
/// - validation of ACL/timed interaction flags/writability
/// - validation of ACL/timed interaction flags/writability, if those checks are desired.
virtual ActionReturnStatus WriteAttribute(const WriteAttributeRequest & request, AttributeValueDecoder & decoder) = 0;

/// `handler` is used to send back the reply.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,6 @@ std::optional<CHIP_ERROR> TryWriteViaAccessInterface(const ConcreteDataAttribute
DataModel::ActionReturnStatus CodegenDataModelProvider::WriteAttribute(const DataModel::WriteAttributeRequest & request,
AttributeValueDecoder & decoder)
{
ChipLogDetail(DataManagement, "Writing attribute: Cluster=" ChipLogFormatMEI " Endpoint=0x%x AttributeId=" ChipLogFormatMEI,
ChipLogValueMEI(request.path.mClusterId), request.path.mEndpointId, ChipLogValueMEI(request.path.mAttributeId));

auto metadata = Ember::FindAttributeMetadata(request.path);

// Explicit failure in finding a suitable metadata
andy31415 marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Loading