-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Add plumbing that allows fabric-bridge endpoints to report CADMIN attr #35076
Merged
tehampson
merged 14 commits into
project-chip:master
from
tehampson:fabric-bridge-override-of-cadmin-aai
Aug 20, 2024
Merged
Changes from 9 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
c0c56e3
Add plumbing that allows fabric-bridge endpoints to report CADMIN attr
tehampson 539bd5c
Restyled by whitespace
restyled-commits dee3ec5
Restyled by clang-format
restyled-commits 0155602
Merge branch 'master' into fabric-bridge-override-of-cadmin-aai
tehampson c4e6d57
Self review
tehampson a62f710
Restyled by whitespace
restyled-commits 89a8005
Add TODO with github issue for follow up PR
tehampson 4239652
Fix CI
tehampson 6aa91f7
Address PR comments
tehampson e9013ae
Restyled by clang-format
restyled-commits 8777f81
Address PR comment
tehampson 621766e
Restyled by clang-format
restyled-commits aed335e
Update MCORE_FS_1_2 to latest testplan
tehampson 7e913a1
Revert "Update MCORE_FS_1_2 to latest testplan"
tehampson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
examples/fabric-bridge-app/fabric-bridge-common/include/BridgedAdministratorCommissioning.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright (c) 2024 Project CHIP Authors | ||
* All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <app-common/zap-generated/cluster-objects.h> | ||
#include <app/AttributeAccessInterfaceRegistry.h> | ||
|
||
/** | ||
* @brief CADMIN cluster implementation for handling attribute interactions of bridged device endpoints. | ||
* | ||
* The current Administrator Commissioning Cluster server's zap generated code will automatically | ||
* register an Attribute Access Interface for the root node endpoint implementation. In order to | ||
* properly respond to a read attribute for bridged devices we are representing, we override the | ||
* currently registered Attribute Interface such that we are first to receive any read attribute | ||
* request on Administrator Commissioning Cluster, and if it is not an endpoint for a device we | ||
* are a bridge for we redirect to the default cluster server implementation of Administrator | ||
* Commissioning Cluster. | ||
*/ | ||
class BridgedAdministratorCommissioning : public chip::app::AttributeAccessInterface | ||
{ | ||
public: | ||
// Register for the AdministratorCommissioning cluster on all endpoints. | ||
BridgedAdministratorCommissioning() : | ||
AttributeAccessInterface(chip::NullOptional, chip::app::Clusters::AdministratorCommissioning::Id) | ||
{} | ||
|
||
CHIP_ERROR Init(); | ||
|
||
CHIP_ERROR Read(const chip::app::ConcreteReadAttributePath & aPath, chip::app::AttributeValueEncoder & aEncoder) override; | ||
|
||
// We do not allow writing to CADMIN attributes of a bridged device endpoint. We simply redirect | ||
// write requests to the original attribute interface. | ||
CHIP_ERROR Write(const chip::app::ConcreteDataAttributePath & aPath, chip::app::AttributeValueDecoder & aDecoder) override | ||
{ | ||
VerifyOrDie(mOriginalAttributeInterface); | ||
return mOriginalAttributeInterface->Write(aPath, aDecoder); | ||
} | ||
|
||
private: | ||
// If mOriginalAttributeInterface is removed from here, the class description needs to be updated | ||
// to reflect this change. | ||
chip::app::AttributeAccessInterface * mOriginalAttributeInterface = nullptr; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
examples/fabric-bridge-app/fabric-bridge-common/src/BridgedAdministratorCommissioning.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Copyright (c) 2024 Project CHIP Authors | ||
* All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include "BridgedAdministratorCommissioning.h" | ||
|
||
#include "BridgedDevice.h" | ||
#include "BridgedDeviceManager.h" | ||
#include <app/AttributeAccessInterfaceRegistry.h> | ||
|
||
using namespace chip; | ||
using namespace chip::app; | ||
using namespace chip::app::Clusters; | ||
using namespace chip::app::Clusters::AdministratorCommissioning; | ||
|
||
CHIP_ERROR BridgedAdministratorCommissioning::Init() | ||
{ | ||
// We expect initialization after all embr plugin clusters initialization. This allows us to unregister | ||
// the existing AccessAttributeInterface for AdministratorCommissioning and register ourselves, ensuring | ||
// we get the callback for reading attribute. If the read is not intended for a bridged device we will | ||
// forward it to the original attribute interface that we are unregistering. | ||
mOriginalAttributeInterface = AttributeAccessInterfaceRegistry::Instance().Get(chip::kRootEndpointId, AdministratorCommissioning::Id); | ||
tehampson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
VerifyOrReturnError(mOriginalAttributeInterface, CHIP_ERROR_INTERNAL); | ||
AttributeAccessInterfaceRegistry::Instance().Unregister(mOriginalAttributeInterface); | ||
VerifyOrDie(AttributeAccessInterfaceRegistry::Instance().Register(this)); | ||
return CHIP_NO_ERROR; | ||
} | ||
|
||
CHIP_ERROR BridgedAdministratorCommissioning::Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) | ||
{ | ||
VerifyOrDie(aPath.mClusterId == Clusters::AdministratorCommissioning::Id); | ||
EndpointId endpointId = aPath.mEndpointId; | ||
BridgedDevice * device = BridgeDeviceMgr().GetDevice(endpointId); | ||
|
||
if (!device) | ||
{ | ||
tehampson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
VerifyOrDie(mOriginalAttributeInterface); | ||
return mOriginalAttributeInterface->Read(aPath, aEncoder); | ||
} | ||
auto attr = device->GetAdminCommissioningAttributes(); | ||
|
||
switch (aPath.mAttributeId) | ||
{ | ||
case Attributes::WindowStatus::Id: { | ||
return aEncoder.Encode(attr.commissioningWindowStatus); | ||
} | ||
case Attributes::AdminFabricIndex::Id: { | ||
DataModel::Nullable<FabricIndex> encodeableFabricIndex = DataModel::NullNullable; | ||
if (attr.openerFabricIndex.has_value()) | ||
{ | ||
encodeableFabricIndex.SetNonNull(attr.openerFabricIndex.value()); | ||
} | ||
return aEncoder.Encode(encodeableFabricIndex); | ||
} | ||
case Attributes::AdminVendorId::Id: { | ||
DataModel::Nullable<VendorId> encodeableVendorId = DataModel::NullNullable; | ||
if (attr.openerVendorId.has_value()) | ||
{ | ||
encodeableVendorId.SetNonNull(attr.openerVendorId.value()); | ||
} | ||
return aEncoder.Encode(encodeableVendorId); | ||
} | ||
default: | ||
break; | ||
} | ||
|
||
return CHIP_NO_ERROR; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tehampson what is "embr"?