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

Implement ACL attribute read/write #12305

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
d5eb767
Add access control server skeleton
mlepage-google Nov 25, 2021
2748396
Regen code.
mlepage-google Nov 26, 2021
dd3d079
Restyle code
mlepage-google Nov 26, 2021
2e5b927
Update from upstream changes
mlepage-google Nov 27, 2021
e4af168
Merge branch 'master' into access-control-server-skeleton
mlepage-google Nov 29, 2021
dcc1381
Restyle
mlepage-google Nov 29, 2021
c593e2a
Merge branch 'master' into access-control-server-skeleton
mlepage-google Nov 29, 2021
d3df60c
Add access-control-server to CMakeLists.txt
mlepage-google Nov 29, 2021
bf1709f
Remove nullable from list attribute
mlepage-google Nov 29, 2021
b8bc6ec
Merge branch 'master' into access-control-server-skeleton
mlepage-google Nov 29, 2021
2fb788a
Merge branch 'master' into access-control-server-skeleton
mlepage-google Nov 30, 2021
89a5974
Regen and restyle
mlepage-google Nov 30, 2021
71b5fa7
Merge branch 'master' into access-control-server-skeleton
mlepage-google Nov 30, 2021
c68c025
Regen and restyle
mlepage-google Nov 30, 2021
21466e7
Merge branch 'master' into access-control-server-skeleton
mlepage-google Dec 1, 2021
80dc54b
Fix test
mlepage-google Dec 2, 2021
53baaf3
Regen and restyle
mlepage-google Dec 2, 2021
63a0ce0
Regen and restyle
mlepage-google Dec 2, 2021
08c41e9
Merge branch 'master' into access-control-server-skeleton
mlepage-google Dec 2, 2021
466a548
Merge branch 'master' into access-control-server-skeleton
mlepage-google Dec 2, 2021
6a5b6f8
Regen and restyle
mlepage-google Dec 2, 2021
a2208c6
Merge branch 'master' into access-control-server-skeleton
mlepage-google Dec 2, 2021
1655019
Regen and restyle
mlepage-google Dec 2, 2021
c710106
Merge branch 'master' into access-control-server-skeleton
mlepage-google Dec 2, 2021
49cbd62
Regen and restyle
mlepage-google Dec 2, 2021
5ac7f6a
Regen and restyle
mlepage-google Dec 2, 2021
ea2d4df
Add AccessControl cluster to Darwin test helper
mlepage-google Dec 3, 2021
c8a905a
Remove AccessControl cluster from some tests
mlepage-google Dec 3, 2021
6eec4e3
Fix unless in test file
mlepage-google Dec 3, 2021
4334838
Merge branch 'master' into access-control-server-skeleton
mlepage-google Dec 3, 2021
fb1e25f
Restyle and regen
mlepage-google Dec 3, 2021
e9a2499
Implement ACL attribute
mlepage-google Dec 3, 2021
04d074d
Merge branch 'master' into access-control-server-skeleton
mlepage-google Dec 3, 2021
ccad3d2
Regen and restyle
mlepage-google Dec 3, 2021
cd3a461
Merge branch 'access-control-server-skeleton' into access-control-ser…
mlepage-google Dec 3, 2021
ff1b272
Merge branch 'master' into access-control-server-implementation
mlepage-google Dec 4, 2021
406a6f9
Regen and restyle
mlepage-google Dec 4, 2021
9fa4b97
Change extension attribute storage to RAM
mlepage-google Dec 4, 2021
8435fdd
Re-enable access control cluster tests
mlepage-google Dec 4, 2021
884341b
Fix extension attribute
mlepage-google Dec 4, 2021
31853e4
Merge branch 'master' into access-control-server-implementation
mlepage-google Dec 6, 2021
53926dd
Restyle and regen
mlepage-google Dec 6, 2021
12b0651
Change lambda arg to auto in access control server
mlepage-google Dec 6, 2021
e19c1ad
Add missing variable definitions
mlepage-google Dec 7, 2021
0a62238
Merge branch 'master' into access-control-server-implementation
mlepage-google Dec 7, 2021
b7e997e
Regen and restyle
mlepage-google Dec 7, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,7 @@
"bounded": 0,
"defaultValue": "",
"reportable": 1,
"minInterval": 1,
"minInterval": 0,
"maxInterval": 65534,
"reportableChange": 0
},
Expand All @@ -979,12 +979,12 @@
"mfgCode": null,
"side": "server",
"included": 1,
"storageOption": "External",
"storageOption": "RAM",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? This is going to take up space in the attr store that is completely unused...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the easiest way to get the tests running for now, because the attribute exists. Otherwise I have to go through and ensure all the "not yet implemented" parts have "some kind of implementation" sufficient to keep the tests happy. I made the length 4 just in case any test tried to write more than one, but I could change the length to 1 for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see PR #12690

"singleton": 0,
"bounded": 0,
"defaultValue": "",
"reportable": 1,
"minInterval": 1,
"minInterval": 0,
"maxInterval": 65534,
"reportableChange": 0
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class BridgedActionsAttrAccess : public AttributeAccessInterface
CHIP_ERROR ReadClusterRevision(EndpointId endpoint, AttributeValueEncoder & aEncoder);
};

constexpr uint16_t BridgedActionsAttrAccess::ClusterRevision;

CHIP_ERROR BridgedActionsAttrAccess::ReadActionListAttribute(EndpointId endpoint, AttributeValueEncoder & aEncoder)
{
// Just return an empty list
Expand Down
25 changes: 22 additions & 3 deletions src/access/AccessControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class AccessControl
static constexpr Flags kCluster = 1 << 0;
static constexpr Flags kEndpoint = 1 << 1;
static constexpr Flags kDeviceType = 1 << 2;
Flags flags;
Flags flags = 0;
ClusterId cluster;
EndpointId endpoint;
DeviceTypeId deviceType;
Expand Down Expand Up @@ -89,6 +89,19 @@ class AccessControl

Entry() = default;

Entry(Entry && other) : mDelegate(other.mDelegate) { other.mDelegate = &mDefaultDelegate; }

Entry & operator=(Entry && other)
{
if (this != &other)
{
mDelegate->Release();
mDelegate = other.mDelegate;
other.mDelegate = &mDefaultDelegate;
}
return *this;
}

Entry(const Entry &) = delete;
Entry & operator=(const Entry &) = delete;

Expand Down Expand Up @@ -292,9 +305,12 @@ class AccessControl
virtual CHIP_ERROR Finish() { return CHIP_ERROR_NOT_IMPLEMENTED; }

// Capabilities
virtual CHIP_ERROR GetMaxEntries(int & value) const { return CHIP_ERROR_NOT_IMPLEMENTED; }
virtual CHIP_ERROR GetMaxEntryCount(size_t & value) const { return CHIP_ERROR_NOT_IMPLEMENTED; }
// TODO: more capabilities

// Actualities
virtual CHIP_ERROR GetEntryCount(size_t & value) const { return CHIP_ERROR_NOT_IMPLEMENTED; }

// Preparation
virtual CHIP_ERROR PrepareEntry(Entry & entry) { return CHIP_ERROR_NOT_IMPLEMENTED; }

Expand Down Expand Up @@ -352,7 +368,10 @@ class AccessControl
CHIP_ERROR Finish();

// Capabilities
CHIP_ERROR GetMaxEntries(int & value) const { return mDelegate.GetMaxEntries(value); }
CHIP_ERROR GetMaxEntryCount(size_t & value) const { return mDelegate.GetMaxEntryCount(value); }

// Actualities
CHIP_ERROR GetEntryCount(size_t & value) const { return mDelegate.GetEntryCount(value); }

/**
* Prepares an entry.
Expand Down
16 changes: 15 additions & 1 deletion src/access/examples/ExampleAccessControlDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -968,12 +968,26 @@ class AccessControlDelegate : public AccessControl::Delegate
return SaveToFlash();
}

CHIP_ERROR GetMaxEntries(int & value) const override
CHIP_ERROR GetMaxEntryCount(size_t & value) const override
{
value = ArraySize(EntryStorage::acl);
return CHIP_NO_ERROR;
}

CHIP_ERROR GetEntryCount(size_t & value) const override
{
value = 0;
for (const auto & storage : EntryStorage::acl)
{
if (!storage.InUse())
{
break;
}
value++;
}
return CHIP_NO_ERROR;
}

CHIP_ERROR PrepareEntry(Entry & entry) override
{
if (auto * delegate = EntryDelegate::Find(entry.GetDelegate()))
Expand Down
2 changes: 1 addition & 1 deletion src/access/tests/TestAccessControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ struct EntryData
NodeId subjects[kMaxSubjects] = { 0 };
Target targets[kMaxTargets] = { { 0 } };

void Clear() { memset(this, 0, sizeof(*this)); }
void Clear() { *this = EntryData(); }

bool IsEmpty() const { return authMode == AuthMode::kNone; }

Expand Down
10 changes: 5 additions & 5 deletions src/app/AttributeAccessInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class AttributeReportBuilder
* EncodeValue encodes the value field of the report, it should be called exactly once.
*/
template <typename... Ts>
CHIP_ERROR EncodeValue(AttributeReportIBs::Builder & aAttributeReportIBs, Ts... aArgs)
CHIP_ERROR EncodeValue(AttributeReportIBs::Builder & aAttributeReportIBs, Ts &&... aArgs)
{
return DataModel::Encode(*(aAttributeReportIBs.GetAttributeReport().GetAttributeData().GetWriter()),
TLV::ContextTag(to_underlying(AttributeDataIB::Tag::kData)), std::forward<Ts>(aArgs)...);
Expand All @@ -98,7 +98,7 @@ class AttributeValueEncoder
ListEncodeHelper(AttributeValueEncoder & encoder) : mAttributeValueEncoder(encoder) {}

template <typename... Ts>
CHIP_ERROR Encode(Ts... aArgs) const
CHIP_ERROR Encode(Ts &&... aArgs) const
{
return mAttributeValueEncoder.EncodeListItem(std::forward<Ts>(aArgs)...);
}
Expand Down Expand Up @@ -152,7 +152,7 @@ class AttributeValueEncoder
* operation.
*/
template <typename... Ts>
CHIP_ERROR Encode(Ts... aArgs)
CHIP_ERROR Encode(Ts &&... aArgs)
{
mTriedEncode = true;
return EncodeAttributeReportIB(std::forward<Ts>(aArgs)...);
Expand Down Expand Up @@ -209,7 +209,7 @@ class AttributeValueEncoder
friend class ListEncodeHelper;

template <typename... Ts>
CHIP_ERROR EncodeListItem(Ts... aArgs)
CHIP_ERROR EncodeListItem(Ts &&... aArgs)
{
// EncodeListItem must be called after EncodeEmptyList(), thus mCurrentEncodingListIndex and
// mEncodeState.mCurrentEncodingListIndex are not invalid values.
Expand Down Expand Up @@ -242,7 +242,7 @@ class AttributeValueEncoder
* Actual logic for encoding a single AttributeReportIB in AttributeReportIBs.
*/
template <typename... Ts>
CHIP_ERROR EncodeAttributeReportIB(Ts... aArgs)
CHIP_ERROR EncodeAttributeReportIB(Ts &&... aArgs)
{
mTriedEncode = true;
AttributeReportBuilder builder;
Expand Down
1 change: 1 addition & 0 deletions src/app/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ static_library("app") {

public_deps = [
":app_buildconfig",
"${chip_root}/src/access",
"${chip_root}/src/app/util:device_callbacks_manager",
"${chip_root}/src/lib/support",
"${chip_root}/src/messaging",
Expand Down
Loading