Skip to content

Commit

Permalink
Expose commissionerNodeId as a variable for yaml (#24197)
Browse files Browse the repository at this point in the history
* Expose commissionerNodeId as a variable for yaml

yaml can now use commissionerNodeId directly in an argument or
response and the generated code will fill in the commissionerNodeId
of the current commissioner.

* Two more zap files.

* Restyled by clang-format

* Make node id useable for different identities

- useable on response and argument
- usable for different identities
- added test

* re-compile zap

* Add comment

* Restyled by prettier-yaml

* Add commissioner node id to placeholder

* Update src/app/tests/suites/TestCommissionerNodeId.yaml

* Update zap

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Nov 17, 2023
1 parent 426ed7d commit 1388702
Show file tree
Hide file tree
Showing 11 changed files with 14,083 additions and 340 deletions.
7 changes: 7 additions & 0 deletions examples/chip-tool/commands/tests/TestCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ class TestCommand : public TestRunner,

chip::Controller::DeviceCommissioner & GetCommissioner(const char * identity) override
{
// Best effort to get NodeId - if this fails, GetCommissioner will also fail
chip::NodeId id;
if (GetCommissionerNodeId(identity, &id) == CHIP_NO_ERROR)
{
mCommissionerNodeId.SetValue(id);
}
return CHIPCommand::GetCommissioner(identity);
};

Expand All @@ -95,6 +101,7 @@ class TestCommand : public TestRunner,

chip::Optional<char *> mPICSFilePath;
chip::Optional<uint16_t> mTimeout;
chip::Optional<chip::NodeId> mCommissionerNodeId;
std::map<std::string, std::unique_ptr<chip::OperationalDeviceProxy>> mDevices;

// When set to false, prevents interaction model events from affecting the current test status.
Expand Down
14 changes: 14 additions & 0 deletions examples/chip-tool/templates/tests/partials/test_cluster.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ private:

void OnResponse(const chip::app::StatusIB & status, chip::TLV::TLVReader * data) override
{

// Allow yaml to access the current commissioner node id.
// Default to 0 (undefined node id) so we know if this isn't
// set correctly.
// Reset on every step in case it changed.
chip::NodeId commissionerNodeId = mCommissionerNodeId.ValueOr(0);
(void) commissionerNodeId;

bool shouldContinue = false;

switch (mTestIndex - 1)
Expand All @@ -72,6 +80,12 @@ private:
CHIP_ERROR DoTestStep(uint16_t testIndex) override
{
using namespace chip::app::Clusters;
// Allow yaml to access the current commissioner node id.
// Default to 0 (undefined node id) so we know if this isn't
// set correctly.
// Reset on every step in case it changed.
chip::NodeId commissionerNodeId = mCommissionerNodeId.ValueOr(0);
(void) commissionerNodeId;
switch (testIndex)
{
{{#chip_tests_items}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ class TestCommandBridge : public CHIPCommandBridge,
VerifyOrReturnError(controller != nil, CHIP_ERROR_INCORRECT_STATE);

SetIdentity(identity);
if (controller.controllerNodeId != nil) {
mCommissionerNodeId.SetValue([controller.controllerNodeId unsignedLongLongValue]);
}

// Invalidate our existing CASE session; otherwise trying to work with
// our device will just reuse it without establishing a new CASE
Expand Down Expand Up @@ -181,6 +184,9 @@ class TestCommandBridge : public CHIPCommandBridge,
VerifyOrReturnError(controller != nil, CHIP_ERROR_INCORRECT_STATE);

SetIdentity(identity);
if (controller.controllerNodeId != nil) {
mCommissionerNodeId.SetValue([controller.controllerNodeId unsignedLongLongValue]);
}

[controller setDeviceControllerDelegate:mDeviceControllerDelegate queue:mCallbackQueue];
[mDeviceControllerDelegate setDeviceId:value.nodeId];
Expand Down Expand Up @@ -215,7 +221,16 @@ class TestCommandBridge : public CHIPCommandBridge,
return CHIP_NO_ERROR;
}

MTRBaseDevice * _Nullable GetDevice(const char * _Nullable identity) { return mConnectedDevices[identity]; }
MTRBaseDevice * _Nullable GetDevice(const char * _Nullable identity)
{
MTRDeviceController * controller = GetCommissioner(identity);

SetIdentity(identity);
if (controller != nil && controller.controllerNodeId != nil) {
mCommissionerNodeId.SetValue([controller.controllerNodeId unsignedLongLongValue]);
}
return mConnectedDevices[identity];
}

// PairingDeleted and PairingComplete need to be public so our pairing
// delegate can call them.
Expand Down Expand Up @@ -255,6 +270,7 @@ class TestCommandBridge : public CHIPCommandBridge,
chip::Optional<char *> mPICSFilePath;
chip::Optional<chip::EndpointId> mEndpointId;
chip::Optional<uint16_t> mTimeout;
chip::Optional<chip::NodeId> mCommissionerNodeId;

bool CheckConstraintStartsWith(
const char * _Nonnull itemName, const NSString * _Nonnull current, const char * _Nonnull expected)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,17 @@ class {{filename}}: public TestCommandBridge
{
}

// Allow yaml to access the current commissioner node id.
// Default to 0 (undefined node id) so we know if this isn't
// set correctly.
// Reset on every step in case it changed.
chip::NodeId commissionerNodeId = mCommissionerNodeId.ValueOr(0);

/////////// TestCommand Interface /////////
void NextTest() override
{
CHIP_ERROR err = CHIP_NO_ERROR;
commissionerNodeId = mCommissionerNodeId.ValueOr(0);

if (0 == mTestIndex)
{
Expand Down Expand Up @@ -136,6 +143,7 @@ class {{filename}}: public TestCommandBridge
return {{command}}("{{identity}}", value);
{{else}}
MTRBaseDevice * device = GetDevice("{{identity}}");
commissionerNodeId = mCommissionerNodeId.ValueOr(0);
__auto_type * cluster = [[MTRBaseCluster{{>cluster}} alloc] initWithDevice:device endpointID:@({{endpoint}}) queue:mCallbackQueue];
VerifyOrReturnError(cluster != nil, CHIP_ERROR_INCORRECT_STATE);

Expand Down
1 change: 1 addition & 0 deletions examples/placeholder/linux/include/TestCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ class TestCommand : public TestRunner,
protected:
chip::app::ConcreteCommandPath mCommandPath;
chip::app::ConcreteAttributePath mAttributePath;
chip::Optional<chip::NodeId> mCommissionerNodeId;
chip::Optional<chip::EndpointId> mEndpointId;
void SetIdentity(const char * name){};

Expand Down
235 changes: 235 additions & 0 deletions src/app/tests/suites/TestCommissionerNodeId.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
# Copyright (c) 2022 Project CHIP Authors
#
# 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.

name: Test Commissioner Node ID

config:
nodeId: 0x12344321
endpoint: 0
cluster: "Access Control"
payload:
type: char_string
defaultValue: "MT:-24J0AFN00KA0648G00" # This value needs to be generated automatically

tests:
- label: "Wait for the commissioned device to be retrieved for alpha"
cluster: "DelayCommands"
command: "WaitForCommissionee"
arguments:
values:
- name: "nodeId"
value: nodeId

- label: "Open Commissioning Window from alpha"
cluster: "AdministratorCommissioning"
command: "OpenBasicCommissioningWindow"
timedInteractionTimeoutMs: 10000
arguments:
values:
- name: "CommissioningTimeout"
value: 180

- label: "Commission from beta"
identity: "beta"
cluster: "CommissionerCommands"
command: "PairWithCode"
arguments:
values:
- name: "nodeId"
value: nodeId
- name: "payload"
value: payload

- label: "Wait for the commissioned device to be retrieved for beta"
identity: "beta"
cluster: "DelayCommands"
command: "WaitForCommissionee"
arguments:
values:
- name: "nodeId"
value: nodeId

- label: "Open Commissioning Window from alpha"
cluster: "AdministratorCommissioning"
command: "OpenBasicCommissioningWindow"
timedInteractionTimeoutMs: 10000
arguments:
values:
- name: "CommissioningTimeout"
value: 180

- label: "Commission from gamma"
identity: "gamma"
cluster: "CommissionerCommands"
command: "PairWithCode"
arguments:
values:
- name: "nodeId"
value: nodeId
- name: "payload"
value: payload

- label: "Wait for the commissioned device to be retrieved for gamma"
identity: "gamma"
cluster: "DelayCommands"
command: "WaitForCommissionee"
arguments:
values:
- name: "nodeId"
value: nodeId

- label: "Read the fabric ID from the alpha fabric"
identity: "alpha"
cluster: "Operational Credentials"
command: "readAttribute"
attribute: "CurrentFabricIndex"
response:
saveAs: alphaIndex

- label: "Read the fabric ID from the beta fabric"
identity: "beta"
cluster: "Operational Credentials"
command: "readAttribute"
attribute: "CurrentFabricIndex"
response:
saveAs: betaIndex

- label: "Read the fabric ID from the gamma fabric"
identity: "gamma"
cluster: "Operational Credentials"
command: "readAttribute"
attribute: "CurrentFabricIndex"
response:
saveAs: gammaIndex

- label: "Read the ACL from alpha and check commissioner node id"
identity: "alpha"
command: "readAttribute"
attribute: "ACL"
response:
value: [
{
FabricIndex: alphaIndex,
Privilege: 5, # administer
AuthMode: 2, # case
Subjects: [commissionerNodeId],
Targets: null,
},
]

- label: "Read the ACL from beta and check commissioner node id"
identity: "beta"
command: "readAttribute"
attribute: "ACL"
response:
value: [
{
FabricIndex: betaIndex,
Privilege: 5, # administer
AuthMode: 2, # case
Subjects: [commissionerNodeId],
Targets: null,
},
]

- label: "Read the ACL from gamma and check commissioner node id"
identity: "gamma"
command: "readAttribute"
attribute: "ACL"
response:
value: [
{
FabricIndex: gammaIndex,
Privilege: 5, # administer
AuthMode: 2, # case
Subjects: [commissionerNodeId],
Targets: null,
},
]

- label: "Write the ACL using the commissioner node id value"
identity: "beta"
command: "writeAttribute"
attribute: "ACL"
arguments:
value: [
{
FabricIndex: betaIndex,
Privilege: 5, # administer
AuthMode: 2, # case
Subjects: [commissionerNodeId],
Targets: null,
},
]

- label: "Write the ACL using the commissioner node id value"
identity: "gamma"
command: "writeAttribute"
attribute: "ACL"
arguments:
value: [
{
FabricIndex: gammaIndex,
Privilege: 5, # administer
AuthMode: 2, # case
Subjects: [commissionerNodeId],
Targets: null,
},
]

- label: "Read the ACL from beta and check commissioner node id"
identity: "beta"
command: "readAttribute"
attribute: "ACL"
response:
value: [
{
FabricIndex: betaIndex,
Privilege: 5, # administer
AuthMode: 2, # case
Subjects: [commissionerNodeId],
Targets: null,
},
]

- label: "Read the ACL from gamma and check commissioner node id"
identity: "gamma"
command: "readAttribute"
attribute: "ACL"
response:
value: [
{
FabricIndex: gammaIndex,
Privilege: 5, # administer
AuthMode: 2, # case
Subjects: [commissionerNodeId],
Targets: null,
},
]

- label: "Remove beta fabric"
cluster: "Operational Credentials"
command: "RemoveFabric"
arguments:
values:
- name: "FabricIndex"
value: betaIndex

- label: "Remove gamma fabric"
cluster: "Operational Credentials"
command: "RemoveFabric"
arguments:
values:
- name: "FabricIndex"
value: gammaIndex
1 change: 1 addition & 0 deletions src/app/tests/suites/ciTests.json
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@
"TestAccessControlConstraints",
"TestLevelControlWithOnOffDependency",
"TestCommissioningWindow",
"TestCommissionerNodeId",
"TestClientMonitoringCluster"
],
"MultiAdmin": ["TestMultiAdmin"],
Expand Down
Loading

0 comments on commit 1388702

Please sign in to comment.