Skip to content

Commit e3aab6d

Browse files
Add DataModelTest feature to general diagnostics
1 parent e4c4c38 commit e3aab6d

File tree

7 files changed

+376
-54
lines changed

7 files changed

+376
-54
lines changed

examples/all-clusters-app/all-clusters-common/all-clusters-app.zap

+16
Original file line numberDiff line numberDiff line change
@@ -2863,6 +2863,22 @@
28632863
"source": "server",
28642864
"isIncoming": 0,
28652865
"isEnabled": 1
2866+
},
2867+
{
2868+
"name": "PayloadTestRequest",
2869+
"code": 3,
2870+
"mfgCode": null,
2871+
"source": "client",
2872+
"isIncoming": 1,
2873+
"isEnabled": 1
2874+
},
2875+
{
2876+
"name": "PayloadTestResponse",
2877+
"code": 4,
2878+
"mfgCode": null,
2879+
"source": "server",
2880+
"isIncoming": 0,
2881+
"isEnabled": 1
28662882
}
28672883
],
28682884
"attributes": [

examples/all-clusters-minimal-app/all-clusters-common/all-clusters-minimal-app.zap

+16
Original file line numberDiff line numberDiff line change
@@ -2464,6 +2464,22 @@
24642464
"source": "server",
24652465
"isIncoming": 0,
24662466
"isEnabled": 1
2467+
},
2468+
{
2469+
"name": "PayloadTestRequest",
2470+
"code": 3,
2471+
"mfgCode": null,
2472+
"source": "client",
2473+
"isIncoming": 1,
2474+
"isEnabled": 1
2475+
},
2476+
{
2477+
"name": "PayloadTestResponse",
2478+
"code": 4,
2479+
"mfgCode": null,
2480+
"source": "server",
2481+
"isIncoming": 0,
2482+
"isEnabled": 1
24672483
}
24682484
],
24692485
"attributes": [

src/app/clusters/general-diagnostics-server/general-diagnostics-server.cpp

+81-16
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818
#include "general-diagnostics-server.h"
1919

20+
#include <stdint.h>
21+
#include <string.h>
22+
2023
#include <app/util/config.h>
2124

2225
#include "app/server/Server.h"
@@ -28,6 +31,7 @@
2831
#include <app/EventLogging.h>
2932
#include <app/reporting/reporting.h>
3033
#include <app/util/attribute-storage.h>
34+
#include <lib/support/ScopedBuffer.h>
3135
#include <platform/ConnectivityManager.h>
3236
#include <platform/DiagnosticDataProvider.h>
3337

@@ -44,6 +48,8 @@ using chip::Protocols::InteractionModel::Status;
4448

4549
namespace {
4650

51+
constexpr uint8_t kCurrentClusterRevision = 2;
52+
4753
bool IsTestEventTriggerEnabled()
4854
{
4955
auto * triggerDelegate = chip::Server::GetInstance().GetTestEventTriggerDelegate();
@@ -210,9 +216,23 @@ CHIP_ERROR GeneralDiagosticsAttrAccess::Read(const ConcreteReadAttributePath & a
210216
return aEncoder.Encode(isTestEventTriggersEnabled);
211217
}
212218
// Note: Attribute ID 0x0009 was removed (#30002).
213-
default: {
214-
break;
219+
220+
case FeatureMap::Id: {
221+
uint32_t features = 0;
222+
223+
#if CHIP_CONFIG_MAX_PATHS_PER_INVOKE > 1
224+
features |= chip::to_underlying(Clusters::GeneralDiagnostics::Feature::kDataModelTest);
225+
#endif // CHIP_CONFIG_MAX_PATHS_PER_INVOKE > 1
226+
227+
return aEncoder.Encode(features);
215228
}
229+
230+
case ClusterRevision::Id: {
231+
return aEncoder.Encode(kCurrentClusterRevision);
232+
}
233+
234+
default:
235+
break;
216236
}
217237
return CHIP_NO_ERROR;
218238
}
@@ -352,29 +372,37 @@ void GeneralDiagnosticsServer::OnNetworkFaultsDetect(const GeneralFaults<kMaxNet
352372
} // namespace app
353373
} // namespace chip
354374

355-
bool emberAfGeneralDiagnosticsClusterTestEventTriggerCallback(CommandHandler * commandObj, const ConcreteCommandPath & commandPath,
356-
const Commands::TestEventTrigger::DecodableType & commandData)
357-
{
375+
namespace {
358376

359-
if (commandData.enableKey.size() != TestEventTriggerDelegate::kEnableKeyLength)
377+
TestEventTriggerDelegate * GetTriggerDelegateOnMatchingKey(ByteSpan enableKey)
378+
{
379+
if (enableKey.size() != TestEventTriggerDelegate::kEnableKeyLength)
360380
{
361-
commandObj->AddStatus(commandPath, Status::ConstraintError);
362-
return true;
381+
return nullptr;
363382
}
364383

365-
if (IsByteSpanAllZeros(commandData.enableKey))
384+
if (IsByteSpanAllZeros(enableKey))
366385
{
367-
commandObj->AddStatus(commandPath, Status::ConstraintError);
368-
return true;
386+
return nullptr;
369387
}
370388

371389
auto * triggerDelegate = chip::Server::GetInstance().GetTestEventTriggerDelegate();
372390

373-
// Spec says "EnableKeyMismatch" but this never existed prior to 1.0 SVE2 and mismatches
374-
// test plans as well. ConstraintError is specified for most other errors, so
375-
// we keep the behavior as close as possible, except for EnableKeyMismatch which
376-
// is going to be a ConstraintError.
377-
if (triggerDelegate == nullptr || !triggerDelegate->DoesEnableKeyMatch(commandData.enableKey))
391+
if (triggerDelegate == nullptr || !triggerDelegate->DoesEnableKeyMatch(enableKey))
392+
{
393+
return nullptr;
394+
}
395+
396+
return triggerDelegate;
397+
}
398+
399+
} // namespace
400+
401+
bool emberAfGeneralDiagnosticsClusterTestEventTriggerCallback(CommandHandler * commandObj, const ConcreteCommandPath & commandPath,
402+
const Commands::TestEventTrigger::DecodableType & commandData)
403+
{
404+
auto * triggerDelegate = GetTriggerDelegateOnMatchingKey(commandData.enableKey);
405+
if (triggerDelegate == nullptr)
378406
{
379407
commandObj->AddStatus(commandPath, Status::ConstraintError);
380408
return true;
@@ -420,6 +448,43 @@ bool emberAfGeneralDiagnosticsClusterTimeSnapshotCallback(CommandHandler * comma
420448
return true;
421449
}
422450

451+
bool emberAfGeneralDiagnosticsClusterPayloadTestRequestCallback(CommandHandler * commandObj, const ConcreteCommandPath & commandPath,
452+
const Commands::PayloadTestRequest::DecodableType & commandData)
453+
{
454+
// Max allowed is 2048.
455+
if (commandData.count > 2048)
456+
{
457+
commandObj->AddStatus(commandPath, Status::InvalidCommand);
458+
return true;
459+
}
460+
461+
// Ensure Test Event triggers are enabled and key matches.
462+
auto * triggerDelegate = GetTriggerDelegateOnMatchingKey(commandData.enableKey);
463+
if (triggerDelegate == nullptr)
464+
{
465+
commandObj->AddStatus(commandPath, Status::ConstraintError);
466+
return true;
467+
}
468+
469+
Commands::PayloadTestResponse::Type response;
470+
Platform::ScopedMemoryBufferWithSize<uint8_t> payload;
471+
if (!payload.Calloc(commandData.count))
472+
{
473+
commandObj->AddStatus(commandPath, Status::ResourceExhausted);
474+
return true;
475+
}
476+
477+
memset(payload.Get(), commandData.value, payload.AllocatedSize());
478+
response.payload = ByteSpan{payload.Get(), payload.AllocatedSize()};
479+
480+
if (commandObj->AddResponseData(commandPath, response) != CHIP_NO_ERROR)
481+
{
482+
commandObj->AddStatus(commandPath, Status::ResourceExhausted);
483+
}
484+
485+
return true;
486+
}
487+
423488
void MatterGeneralDiagnosticsPluginServerInitCallback()
424489
{
425490
BootReasonEnum bootReason;

src/app/zap-templates/zcl/data-model/chip/general-diagnostics-cluster.xml

+18
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ limitations under the License.
1616
-->
1717
<configurator>
1818
<domain name="CHIP"/>
19+
20+
<bitmap name="Feature" type="bitmap32">
21+
<cluster code="0x0033"/>
22+
<field name="DataModelTest" mask="0x1"/>
23+
</bitmap>
24+
1925
<enum name="HardwareFaultEnum" type="enum8">
2026
<cluster code="0x0033"/>
2127
<item name="Unspecified" value="0x00"/>
@@ -122,6 +128,18 @@ limitations under the License.
122128
<arg name="PosixTimeMs" type="posix_ms" isNullable="true" optional="false"/>
123129
</command>
124130

131+
<command source="client" code="0x03" name="PayloadTestRequest" response="PayloadTestResponse" optional="true" apiMaturity="provisional">
132+
<description>Request a variable length payload response.</description>
133+
<arg name="EnableKey" type="octet_string" length="16"/>
134+
<arg name="Value" type="int8u"/>
135+
<arg name="Count" type="int16u" max="2048"/>
136+
</command>
137+
138+
<command source="server" code="0x04" name="PayloadTestResponse" optional="true" apiMaturity="provisional">
139+
<description>Response for the PayloadTestRequest command.</description>
140+
<arg name="Payload" type="octet_string" max="2048" optional="false"/>
141+
</command>
142+
125143
<event side="server" code="0x00" name="HardwareFaultChange" priority="critical" optional="true">
126144
<description>Indicate a change in the set of hardware faults currently detected by the Node.</description>
127145
<field id="0" name="Current" type="HardwareFaultEnum" array="true"/>

0 commit comments

Comments
 (0)