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

Merged
merged 32 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from 4 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
20 changes: 11 additions & 9 deletions src/app/WriteHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include <app/AppConfig.h>
#include <app/AttributeAccessInterfaceRegistry.h>
#include <app/AttributeValueDecoder.h>
#include <app/ConcreteAttributePath.h>
#include <app/GlobalAttributes.h>
#include <app/InteractionModelEngine.h>
#include <app/MessageDef/EventPathIB.h>
#include <app/MessageDef/StatusIB.h>
Expand Down Expand Up @@ -759,8 +761,9 @@ void WriteHandler::MoveToState(const State aTargetState)
}

DataModel::ActionReturnStatus WriteHandler::CheckWriteAllowed(const Access::SubjectDescriptor & aSubject,
const ConcreteDataAttributePath & aPath)
const ConcreteAttributePath & aPath)
{

// TODO: ordering is to check writability/existence BEFORE ACL and this seems wrong, however
// existing unit tests (TC_AcessChecker.py) validate that we get UnsupportedWrite instead of UnsupportedAccess
//
Expand All @@ -769,6 +772,10 @@ DataModel::ActionReturnStatus WriteHandler::CheckWriteAllowed(const Access::Subj
// and tests and implementation
//
// Open issue that needs fixing: https://github.com/project-chip/connectedhomeip/issues/33735

// First check things that are not even in metadata. These are read.only.
andy31415 marked this conversation as resolved.
Show resolved Hide resolved
VerifyOrReturnValue(!IsSupportedGlobalAttributeNotInMetadata(aPath.mAttributeId), Status::UnsupportedWrite);
andy31415 marked this conversation as resolved.
Show resolved Hide resolved

std::optional<DataModel::AttributeEntry> attributeEntry;
DataModel::AttributeFinder finder(mDataModelProvider);

Expand All @@ -786,15 +793,10 @@ DataModel::ActionReturnStatus WriteHandler::CheckWriteAllowed(const Access::Subj
bool checkAcl = true;
if (mLastSuccessfullyWrittenPath.has_value())
{
// NOTE: explicit cast/check only for attribute path and nothing else.
//
// Specifically we DO NOT use `operator==` because `aPath` is a
// DATA path (contains a list index) and we do not want
// mLastSuccessfullyWrittenPath to be auto-cast to a
// data path with a empty list and fail the compare.
// only validate ACL if path has changed
//
// This inline endpoint/cluster/attribute compare results in
// smaller code as well.
// Note that this is NOT operator==: we could do `checkAcl == (aPath != *mLastSuccessfullyWrittenPath)`
// however that seems to use more flash.
if ((aPath.mEndpointId == mLastSuccessfullyWrittenPath->mEndpointId) &&
(aPath.mClusterId == mLastSuccessfullyWrittenPath->mClusterId) &&
(aPath.mAttributeId == mLastSuccessfullyWrittenPath->mAttributeId))
Expand Down
2 changes: 1 addition & 1 deletion src/app/WriteHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class WriteHandler : public Messaging::ExchangeDelegate
///
/// Returns a success status if all is ok, failure otherwise.
DataModel::ActionReturnStatus CheckWriteAllowed(const Access::SubjectDescriptor & aSubject,
const ConcreteDataAttributePath & aPath);
const ConcreteAttributePath & aPath);

// Write the given data to the given path
CHIP_ERROR WriteClusterData(const Access::SubjectDescriptor & aSubject, const ConcreteDataAttributePath & aPath,
Expand Down
Loading