Skip to content

Commit 1d1319b

Browse files
THNETDIR and WIFINM: Align with latest spec and other small fixes (project-chip#35191)
* YAML runner: Add support for EstablishPASESession command * Enable python constraints in TC_THNETDIR_* * THNETDIR: Align with latest spec - Implement ActiveTimestamp check for updates - Implement CASE session requirement for GetOperationalDataset - Update / add certification YAML tests accordingly * WIFINM: Implement CASE session requirement for NetworkPassphraseRequest - Implement CASE session requirement for NetworkPassphraseRequest - Add a corresponding YAML test * Apply test script suggestions from code review Co-authored-by: marchemi <56955785+marchemi@users.noreply.github.com> * Enable negative timed-invoke tests in TC_THNETDIR_2_2 Instead, disable the test in CI for darwin-framework-tool. Fixes matter-test-scripts#359 --------- Co-authored-by: marchemi <56955785+marchemi@users.noreply.github.com>
1 parent c3a4675 commit 1d1319b

File tree

10 files changed

+335
-45
lines changed

10 files changed

+335
-45
lines changed

examples/chip-tool/py_matter_chip_tool_adapter/matter_chip_tool_adapter/encoder.py

+8
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,14 @@
130130
'has_destination': False,
131131
'has_endpoint': False,
132132
},
133+
'EstablishPASESession': {
134+
'alias': 'code-paseonly',
135+
'arguments': {
136+
'nodeId': 'node-id'
137+
},
138+
'has_destination': False,
139+
'has_endpoint': False,
140+
},
133141
'GetCommissionerNodeId': {
134142
'has_destination': False,
135143
'has_endpoint': False,

scripts/py_matter_yamltests/matter_yamltests/pseudo_clusters/clusters/commissioner_commands.py

+5
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@
5757
<arg name="IPK" type="octet_string"/>
5858
</command>
5959
60+
<command source="client" code="5" name="EstablishPASESession">
61+
<arg name="nodeId" type="node_id"/>
62+
<arg name="payload" type="char_string"/>
63+
</command>
64+
6065
</cluster>
6166
</configurator>
6267
'''

scripts/tests/chiptest/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ def _GetDarwinFrameworkToolUnsupportedTests() -> Set[str]:
220220
"Test_TC_SC_4_1", # darwin-framework-tool does not support dns-sd commands.
221221
"Test_TC_SC_5_2", # darwin-framework-tool does not support group commands.
222222
"Test_TC_S_2_3", # darwin-framework-tool does not support group commands.
223+
"Test_TC_THNETDIR_2_2", # darwin-framework-tool does not support negative timed-invoke tests
223224
}
224225

225226

src/app/clusters/thread-network-directory-server/thread-network-directory-server.cpp

+29-2
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,9 @@ void ThreadNetworkDirectoryServer::HandleAddNetworkRequest(HandlerContext & ctx,
182182
{
183183
OperationalDataset dataset;
184184
ByteSpan extendedPanIdSpan;
185+
uint64_t activeTimestamp;
185186
union
186187
{
187-
uint64_t activeTimestamp;
188188
uint16_t channel;
189189
uint8_t masterKey[kSizeMasterKey];
190190
uint8_t meshLocalPrefix[kSizeMeshLocalPrefix];
@@ -203,7 +203,7 @@ void ThreadNetworkDirectoryServer::HandleAddNetworkRequest(HandlerContext & ctx,
203203
// TODO: An immutable OperationalDatasetView on top of a ByteSpan (without copying) would be useful here.
204204
SuccessOrExitAction(err = dataset.Init(req.operationalDataset), context = "OperationalDataset");
205205
SuccessOrExitAction(err = dataset.GetExtendedPanIdAsByteSpan(extendedPanIdSpan), context = "ExtendedPanID");
206-
SuccessOrExitAction(err = dataset.GetActiveTimestamp(unused.activeTimestamp), context = "ActiveTimestamp");
206+
SuccessOrExitAction(err = dataset.GetActiveTimestamp(activeTimestamp), context = "ActiveTimestamp");
207207
SuccessOrExitAction(err = dataset.GetChannel(unused.channel), context = "Channel");
208208
SuccessOrExitAction(err = dataset.GetChannelMask(unusedSpan), context = "ChannelMask");
209209
SuccessOrExitAction(err = dataset.GetMasterKey(unused.masterKey), context = "NetworkKey");
@@ -214,6 +214,27 @@ void ThreadNetworkDirectoryServer::HandleAddNetworkRequest(HandlerContext & ctx,
214214
SuccessOrExitAction(err = dataset.GetSecurityPolicy(unused.securityPolicy), context = "SecurityContext");
215215

216216
status = IMStatus::Failure;
217+
218+
// "If the received dataset has an Active Timestamp that is less than or equal to that of the existing entry,
219+
// then the update SHALL be rejected with a status of INVALID_IN_STATE."
220+
{
221+
uint8_t datasetBuffer[kSizeOperationalDataset];
222+
MutableByteSpan datasetSpan(datasetBuffer);
223+
err = mStorage.GetNetworkDataset(ExtendedPanId(extendedPanIdSpan), datasetSpan);
224+
if (err != CHIP_ERROR_NOT_FOUND)
225+
{
226+
SuccessOrExit(err);
227+
SuccessOrExit(err = dataset.Init(datasetSpan));
228+
uint64_t existingActiveTimestamp;
229+
SuccessOrExit(err = dataset.GetActiveTimestamp(existingActiveTimestamp));
230+
if (activeTimestamp <= existingActiveTimestamp)
231+
{
232+
ctx.mCommandHandler.AddStatus(ctx.mRequestPath, IMStatus::InvalidInState, "ActiveTimestamp");
233+
return;
234+
}
235+
}
236+
}
237+
217238
SuccessOrExit(err = mStorage.AddOrUpdateNetwork(ExtendedPanId(extendedPanIdSpan), req.operationalDataset));
218239

219240
ctx.mCommandHandler.AddStatus(ctx.mRequestPath, IMStatus::Success);
@@ -266,6 +287,12 @@ void ThreadNetworkDirectoryServer::HandleOperationalDatasetRequest(
266287
{
267288
CHIP_ERROR err;
268289

290+
if (ctx.mCommandHandler.GetSubjectDescriptor().authMode != Access::AuthMode::kCase)
291+
{
292+
ctx.mCommandHandler.AddStatus(ctx.mRequestPath, IMStatus::UnsupportedAccess);
293+
return;
294+
}
295+
269296
if (req.extendedPanID.size() != ExtendedPanId::size())
270297
{
271298
ctx.mCommandHandler.AddStatus(ctx.mRequestPath, IMStatus::ConstraintError);

src/app/clusters/wifi-network-management-server/wifi-network-management-server.cpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ using namespace chip::app;
3232
using namespace chip::app::Clusters;
3333
using namespace chip::app::Clusters::WiFiNetworkManagement::Attributes;
3434
using namespace chip::app::Clusters::WiFiNetworkManagement::Commands;
35-
using namespace std::placeholders;
35+
using IMStatus = chip::Protocols::InteractionModel::Status;
3636

3737
namespace chip {
3838
namespace app {
@@ -143,6 +143,12 @@ void WiFiNetworkManagementServer::InvokeCommand(HandlerContext & ctx)
143143
void WiFiNetworkManagementServer::HandleNetworkPassphraseRequest(HandlerContext & ctx,
144144
const NetworkPassphraseRequest::DecodableType & req)
145145
{
146+
if (ctx.mCommandHandler.GetSubjectDescriptor().authMode != Access::AuthMode::kCase)
147+
{
148+
ctx.mCommandHandler.AddStatus(ctx.mRequestPath, IMStatus::UnsupportedAccess);
149+
return;
150+
}
151+
146152
if (HaveNetworkCredentials())
147153
{
148154
NetworkPassphraseResponse::Type response;
@@ -151,8 +157,7 @@ void WiFiNetworkManagementServer::HandleNetworkPassphraseRequest(HandlerContext
151157
}
152158
else
153159
{
154-
// TODO: Status code TBC: https://github.com/CHIP-Specifications/connectedhomeip-spec/issues/9234
155-
ctx.mCommandHandler.AddStatus(ctx.mRequestPath, Protocols::InteractionModel::Status::InvalidInState);
160+
ctx.mCommandHandler.AddStatus(ctx.mRequestPath, IMStatus::InvalidInState);
156161
}
157162
}
158163

src/app/tests/suites/certification/Test_TC_THNETDIR_2_1.yaml

+1-2
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,4 @@ tests:
4747
response:
4848
constraints:
4949
type: int8u
50-
minValue: 10 # assume 5 supported fabrics
51-
# python: value >= 2 * supportedFabrics
50+
python: value >= 2 * supportedFabrics

src/app/tests/suites/certification/Test_TC_THNETDIR_2_2.yaml

+111-36
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,16 @@ config:
2525
# Note: TestNetwork* values need to match what's encoded in TestNetworkDataset
2626
TestNetworkDataset:
2727
type: octet_string
28-
defaultValue: "hex:0e080000000000000001000300000f350407fff800020839758ec8144b07fb0708fdf1f1add0797dc00510f366cec7a446bab978d90d27abe38f23030f4f70656e5468726561642d353933380102593804103ca67c969efb0d0c74a4d8ee923b576c0c0402a0f7f8"
28+
defaultValue: "hex:0e0800000000000c0001000300000f350407fff800020839758ec8144b07fb0708fdf1f1add0797dc00510f366cec7a446bab978d90d27abe38f23030f4f70656e5468726561642d353933380102593804103ca67c969efb0d0c74a4d8ee923b576c0c0402a0f7f8"
2929
TestNetworkExtendedPanId:
3030
type: octet_string
3131
defaultValue: "hex:39758ec8144b07fb"
3232
TestNetworkName: "OpenThread-5938"
3333
TestNetworkChannel: 15
34-
TestNetworkActiveTimestamp: 1
34+
TestNetworkActiveTimestamp: 0xc0001
35+
TestNetworkUpdatedDataset:
36+
type: octet_string
37+
defaultValue: "hex:0e0800000000000d0001000300000f350407fff800020839758ec8144b07fb0708fdf1f1add0797dc00510f366cec7a446bab978d90d27abe38f23030f4f70656e5468726561642d353933380102593804103ca67c969efb0d0c74a4d8ee923b576c0c0402a0f7f8"
3538

3639
tests:
3740
- label: "Wait for the commissioned device to be retrieved"
@@ -90,15 +93,15 @@ tests:
9093
response:
9194
error: NOT_FOUND
9295

93-
# TODO: Currently fails with darwin-framework-tool because it automatically performs a timed invoke
94-
# - label: "TH sends AddNetwork command to DUT without a timed interaction"
95-
# command: AddNetwork
96-
# arguments:
97-
# values:
98-
# - name: OperationalDataset
99-
# value: TestNetworkDataset
100-
# response:
101-
# error: NEEDS_TIMED_INTERACTION
96+
# Note: Unsupported with darwin-framework-tool because it automatically performs a timed invoke
97+
- label: "TH sends AddNetwork command to DUT without a timed interaction"
98+
command: AddNetwork
99+
arguments:
100+
values:
101+
- name: OperationalDataset
102+
value: TestNetworkDataset
103+
response:
104+
error: NEEDS_TIMED_INTERACTION
102105

103106
- label: "TH sends AddNetwork command to DUT with TestNetwork dataset"
104107
command: AddNetwork
@@ -116,18 +119,43 @@ tests:
116119
response:
117120
constraints:
118121
type: list
119-
# python: |
120-
# # Split the list into test (our TestNetwork) and rest (everything else)
121-
# test = next((n for n in value if n['ExtendedPanID'] == TestNetworkExtendedPanId), None)
122-
# rest = [n for n in value if n != test]
123-
# # Check test has the expected values and rest == initialNetworks (ignoring order)
124-
# return (test is not None and
125-
# test['NetworkName'] == TestNetworkName and
126-
# test['Channel'] == TestNetworkChannel and
127-
# test['ActiveTimestamp'] == TestNetworkActiveTimestamp and
128-
# len(value) == len(initialNetworks) + 1 and
129-
# len(rest) == len(initialNetworks) and
130-
# all(n in initialNetworks for n in rest))
122+
python: |
123+
# Split the list into test (our TestNetwork) and rest (everything else)
124+
test = next((n for n in value if n['ExtendedPanID'] == TestNetworkExtendedPanId), None)
125+
rest = [n for n in value if n != test]
126+
# Check test has the expected values and rest == initialNetworks (ignoring order)
127+
return (test is not None and
128+
test['NetworkName'] == TestNetworkName and
129+
test['Channel'] == TestNetworkChannel and
130+
test['ActiveTimestamp'] == TestNetworkActiveTimestamp and
131+
len(value) == len(initialNetworks) + 1 and
132+
len(rest) == len(initialNetworks) and
133+
all(n in initialNetworks for n in rest))
134+
135+
- label:
136+
"TH sends GetOperationalDataset command to DUT with ExtendedPanID from
137+
TestNetwork"
138+
command: GetOperationalDataset
139+
arguments:
140+
values:
141+
- name: ExtendedPanID
142+
value: TestNetworkExtendedPanId
143+
response:
144+
values:
145+
- name: OperationalDataset
146+
value: TestNetworkDataset
147+
148+
- label:
149+
"TH sends AddNetwork command to DUT with TestNetwork dataset matching
150+
existing Active Timestamp"
151+
command: AddNetwork
152+
timedInteractionTimeoutMs: 2000
153+
arguments:
154+
values:
155+
- name: OperationalDataset
156+
value: TestNetworkDataset
157+
response:
158+
error: INVALID_IN_STATE
131159

132160
- label:
133161
"TH sends GetOperationalDataset command to DUT with ExtendedPanID from
@@ -142,6 +170,53 @@ tests:
142170
- name: OperationalDataset
143171
value: TestNetworkDataset
144172

173+
- label:
174+
"TH sends AddNetwork command to DUT with updated TestNetwork dataset
175+
with larger Active Timestamp"
176+
command: AddNetwork
177+
timedInteractionTimeoutMs: 2000
178+
arguments:
179+
values:
180+
- name: OperationalDataset
181+
value: TestNetworkUpdatedDataset
182+
183+
- label:
184+
"TH sends GetOperationalDataset command to DUT with ExtendedPanID from
185+
TestNetwork"
186+
command: GetOperationalDataset
187+
arguments:
188+
values:
189+
- name: ExtendedPanID
190+
value: TestNetworkExtendedPanId
191+
response:
192+
values:
193+
- name: OperationalDataset
194+
value: TestNetworkUpdatedDataset
195+
196+
- label:
197+
"TH sends AddNetwork command to DUT with original TestNetwork dataset"
198+
command: AddNetwork
199+
timedInteractionTimeoutMs: 2000
200+
arguments:
201+
values:
202+
- name: OperationalDataset
203+
value: TestNetworkDataset
204+
response:
205+
error: INVALID_IN_STATE
206+
207+
- label:
208+
"TH sends GetOperationalDataset command to DUT with ExtendedPanID from
209+
TestNetwork"
210+
command: GetOperationalDataset
211+
arguments:
212+
values:
213+
- name: ExtendedPanID
214+
value: TestNetworkExtendedPanId
215+
response:
216+
values:
217+
- name: OperationalDataset
218+
value: TestNetworkUpdatedDataset
219+
145220
- label:
146221
"TH writes ExtendedPanID from TestNetwork to PreferredExtendedPanID on
147222
DUT"
@@ -158,15 +233,15 @@ tests:
158233
response:
159234
value: TestNetworkExtendedPanId
160235

161-
# TODO: Currently fails with darwin-framework-tool because it automatically performs a timed invoke
162-
# - label: "TH sends RemoveNetwork command to DUT without a timed interaction"
163-
# command: RemoveNetwork
164-
# arguments:
165-
# values:
166-
# - name: ExtendedPanID
167-
# value: TestNetworkExtendedPanId
168-
# response:
169-
# error: NEEDS_TIMED_INTERACTION
236+
# Note: Unsupported with darwin-framework-tool because it automatically performs a timed invoke
237+
- label: "TH sends RemoveNetwork command to DUT without a timed interaction"
238+
command: RemoveNetwork
239+
arguments:
240+
values:
241+
- name: ExtendedPanID
242+
value: TestNetworkExtendedPanId
243+
response:
244+
error: NEEDS_TIMED_INTERACTION
170245

171246
- label:
172247
"TH sends RemoveNetwork command to DUT with ExtendedPanID of
@@ -212,10 +287,10 @@ tests:
212287
response:
213288
constraints:
214289
type: list
215-
# python: |
216-
# # value == initialNetworks (ignoring order)
217-
# return (len(value) == len(initialNetworks) and
218-
# all(n in initialNetworks for n in value))
290+
python: |
291+
# value == initialNetworks (ignoring order)
292+
return (len(value) == len(initialNetworks) and
293+
all(n in initialNetworks for n in value))
219294
220295
- label:
221296
"TH writes PreferredExtendedPanID to DUT, restoring the initial value"

0 commit comments

Comments
 (0)