17
17
18
18
#include " general-diagnostics-server.h"
19
19
20
+ #include < stdint.h>
21
+ #include < string.h>
22
+
20
23
#include < app/util/config.h>
21
24
22
25
#include " app/server/Server.h"
28
31
#include < app/EventLogging.h>
29
32
#include < app/reporting/reporting.h>
30
33
#include < app/util/attribute-storage.h>
34
+ #include < lib/support/ScopedBuffer.h>
31
35
#include < platform/ConnectivityManager.h>
32
36
#include < platform/DiagnosticDataProvider.h>
33
37
@@ -44,6 +48,8 @@ using chip::Protocols::InteractionModel::Status;
44
48
45
49
namespace {
46
50
51
+ constexpr uint8_t kCurrentClusterRevision = 2 ;
52
+
47
53
bool IsTestEventTriggerEnabled ()
48
54
{
49
55
auto * triggerDelegate = chip::Server::GetInstance ().GetTestEventTriggerDelegate ();
@@ -210,9 +216,23 @@ CHIP_ERROR GeneralDiagosticsAttrAccess::Read(const ConcreteReadAttributePath & a
210
216
return aEncoder.Encode (isTestEventTriggersEnabled);
211
217
}
212
218
// 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);
215
228
}
229
+
230
+ case ClusterRevision::Id: {
231
+ return aEncoder.Encode (kCurrentClusterRevision );
232
+ }
233
+
234
+ default :
235
+ break ;
216
236
}
217
237
return CHIP_NO_ERROR;
218
238
}
@@ -352,29 +372,37 @@ void GeneralDiagnosticsServer::OnNetworkFaultsDetect(const GeneralFaults<kMaxNet
352
372
} // namespace app
353
373
} // namespace chip
354
374
355
- bool emberAfGeneralDiagnosticsClusterTestEventTriggerCallback (CommandHandler * commandObj, const ConcreteCommandPath & commandPath,
356
- const Commands::TestEventTrigger::DecodableType & commandData)
357
- {
375
+ namespace {
358
376
359
- if (commandData.enableKey .size () != TestEventTriggerDelegate::kEnableKeyLength )
377
+ TestEventTriggerDelegate * GetTriggerDelegateOnMatchingKey (ByteSpan enableKey)
378
+ {
379
+ if (enableKey.size () != TestEventTriggerDelegate::kEnableKeyLength )
360
380
{
361
- commandObj->AddStatus (commandPath, Status::ConstraintError);
362
- return true ;
381
+ return nullptr ;
363
382
}
364
383
365
- if (IsByteSpanAllZeros (commandData. enableKey ))
384
+ if (IsByteSpanAllZeros (enableKey))
366
385
{
367
- commandObj->AddStatus (commandPath, Status::ConstraintError);
368
- return true ;
386
+ return nullptr ;
369
387
}
370
388
371
389
auto * triggerDelegate = chip::Server::GetInstance ().GetTestEventTriggerDelegate ();
372
390
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 )
378
406
{
379
407
commandObj->AddStatus (commandPath, Status::ConstraintError);
380
408
return true ;
@@ -420,6 +448,43 @@ bool emberAfGeneralDiagnosticsClusterTimeSnapshotCallback(CommandHandler * comma
420
448
return true ;
421
449
}
422
450
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
+
423
488
void MatterGeneralDiagnosticsPluginServerInitCallback ()
424
489
{
425
490
BootReasonEnum bootReason;
0 commit comments