Skip to content

Commit

Permalink
Use TestEventTriggerDelegate in General Diagnostics Cluster (#18852)
Browse files Browse the repository at this point in the history
* Enable TestEventTriggersEnabled attribute in general diagnostics cluster
* Enable TestEventTrigger command in general diagnostics cluster
  • Loading branch information
tehampson authored and pull[bot] committed Dec 5, 2023
1 parent 5f2c994 commit c6673f3
Show file tree
Hide file tree
Showing 43 changed files with 1,261 additions and 310 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1600,11 +1600,19 @@ server cluster GeneralDiagnostics = 51 {
readonly attribute ENUM8 activeHardwareFaults[] = 5;
readonly attribute ENUM8 activeRadioFaults[] = 6;
readonly attribute ENUM8 activeNetworkFaults[] = 7;
readonly attribute boolean testEventTriggersEnabled = 8;
readonly attribute command_id generatedCommandList[] = 65528;
readonly attribute command_id acceptedCommandList[] = 65529;
readonly attribute attrib_id attributeList[] = 65531;
readonly attribute bitmap32 featureMap = 65532;
readonly attribute int16u clusterRevision = 65533;

request struct TestEventTriggerRequest {
OCTET_STRING enableKey = 0;
INT64U eventTrigger = 1;
}

command TestEventTrigger(TestEventTriggerRequest): DefaultSuccess = 0;
}

server cluster GroupKeyManagement = 63 {
Expand Down Expand Up @@ -3990,6 +3998,7 @@ endpoint 0 {
callback attribute activeHardwareFaults;
callback attribute activeRadioFaults;
callback attribute activeNetworkFaults;
callback attribute testEventTriggersEnabled;
callback attribute generatedCommandList;
callback attribute acceptedCommandList;
callback attribute attributeList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3339,7 +3339,16 @@
"define": "GENERAL_DIAGNOSTICS_CLUSTER",
"side": "client",
"enabled": 0,
"commands": [],
"commands": [
{
"name": "TestEventTrigger",
"code": 0,
"mfgCode": null,
"source": "client",
"incoming": 1,
"outgoing": 0
}
],
"attributes": [
{
"name": "ClusterRevision",
Expand Down Expand Up @@ -3496,6 +3505,22 @@
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "TestEventTriggersEnabled",
"code": 8,
"mfgCode": null,
"side": "server",
"type": "boolean",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "GeneratedCommandList",
"code": 65528,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1223,11 +1223,19 @@ server cluster GeneralDiagnostics = 51 {

readonly attribute NetworkInterfaceType networkInterfaces[] = 0;
readonly attribute int16u rebootCount = 1;
readonly attribute boolean testEventTriggersEnabled = 8;
readonly attribute command_id generatedCommandList[] = 65528;
readonly attribute command_id acceptedCommandList[] = 65529;
readonly attribute attrib_id attributeList[] = 65531;
readonly attribute bitmap32 featureMap = 65532;
readonly attribute int16u clusterRevision = 65533;

request struct TestEventTriggerRequest {
OCTET_STRING enableKey = 0;
INT64U eventTrigger = 1;
}

command TestEventTrigger(TestEventTriggerRequest): DefaultSuccess = 0;
}

server cluster GroupKeyManagement = 63 {
Expand Down Expand Up @@ -3358,6 +3366,7 @@ endpoint 0 {
server cluster GeneralDiagnostics {
callback attribute networkInterfaces;
callback attribute rebootCount;
callback attribute testEventTriggersEnabled;
callback attribute generatedCommandList;
callback attribute acceptedCommandList;
callback attribute attributeList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3339,7 +3339,16 @@
"define": "GENERAL_DIAGNOSTICS_CLUSTER",
"side": "client",
"enabled": 0,
"commands": [],
"commands": [
{
"name": "TestEventTrigger",
"code": 0,
"mfgCode": null,
"source": "client",
"incoming": 1,
"outgoing": 0
}
],
"attributes": [
{
"name": "ClusterRevision",
Expand Down Expand Up @@ -3496,6 +3505,22 @@
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "TestEventTriggersEnabled",
"code": 8,
"mfgCode": null,
"side": "server",
"type": "boolean",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "GeneratedCommandList",
"code": 65528,
Expand Down
4 changes: 4 additions & 0 deletions src/app/TestEventTriggerDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ namespace chip {
class TestEventTriggerDelegate
{
public:
/* Expected byte size of the EnableKey */
static constexpr size_t kEnableKeyLength = 16;

virtual ~TestEventTriggerDelegate() {}
/**
* Checks to see if `enableKey` provided matches value chosen by the manufacturer.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* limitations under the License.
*/

#include "app/server/Server.h"
#include <app-common/zap-generated/attributes/Accessors.h>
#include <app-common/zap-generated/cluster-objects.h>
#include <app-common/zap-generated/ids/Attributes.h>
Expand All @@ -35,9 +36,37 @@ using namespace chip::DeviceLayer;
using chip::DeviceLayer::ConnectivityMgr;
using chip::DeviceLayer::DiagnosticDataProvider;
using chip::DeviceLayer::GetDiagnosticDataProvider;
using chip::Protocols::InteractionModel::Status;

namespace {

bool IsTestEventTriggerEnabled()
{
auto * triggerDelegate = Server::GetInstance().GetTestEventTriggerDelegate();
if (triggerDelegate == nullptr)
{
return false;
}
uint8_t zeroByteSpanData[TestEventTriggerDelegate::kEnableKeyLength] = { 0 };
if (triggerDelegate->DoesEnableKeyMatch(ByteSpan(zeroByteSpanData)))
{
return false;
}
return true;
}

bool IsByteSpanAllZeros(const ByteSpan & byteSpan)
{
for (auto * it = byteSpan.begin(); it != byteSpan.end(); ++it)
{
if (*it != 0)
{
return false;
}
}
return true;
}

class GeneralDiagosticsAttrAccess : public AttributeAccessInterface
{
public:
Expand Down Expand Up @@ -162,6 +191,10 @@ CHIP_ERROR GeneralDiagosticsAttrAccess::Read(const ConcreteReadAttributePath & a
case BootReasons::Id: {
return ReadIfSupported(&DiagnosticDataProvider::GetBootReason, aEncoder);
}
case TestEventTriggersEnabled::Id: {
bool isTestEventTriggersEnabled = IsTestEventTriggerEnabled();
return aEncoder.Encode(isTestEventTriggersEnabled);
}
default: {
break;
}
Expand Down Expand Up @@ -290,6 +323,44 @@ GeneralDiagnosticsDelegate gDiagnosticDelegate;

} // anonymous namespace

bool emberAfGeneralDiagnosticsClusterTestEventTriggerCallback(CommandHandler * commandObj, const ConcreteCommandPath & commandPath,
const Commands::TestEventTrigger::DecodableType & commandData)
{

if (commandData.enableKey.size() != TestEventTriggerDelegate::kEnableKeyLength)
{
commandObj->AddStatus(commandPath, Status::ConstraintError);
return true;
}

if (IsByteSpanAllZeros(commandData.enableKey))
{
commandObj->AddStatus(commandPath, Status::ConstraintError);
return true;
}

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

if (triggerDelegate == nullptr || !triggerDelegate->DoesEnableKeyMatch(commandData.enableKey))
{
commandObj->AddStatus(commandPath, Status::UnsupportedAccess);
return true;
}

CHIP_ERROR handleEventTriggerResult = triggerDelegate->HandleEventTrigger(commandData.eventTrigger);
Status returnStatus = StatusIB(handleEventTriggerResult).mStatus;

// When HandleEventTrigger returns INVALID_ARGUMENT we convert that into InvalidCommand to be spec
// compliant.
if (handleEventTriggerResult == CHIP_ERROR_INVALID_ARGUMENT)
{
returnStatus = Status::InvalidCommand;
}

commandObj->AddStatus(commandPath, returnStatus);
return true;
}

void MatterGeneralDiagnosticsPluginServerInitCallback()
{
registerAttributeAccessOverride(&gAttrAccess);
Expand Down
2 changes: 2 additions & 0 deletions src/app/server/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ CHIP_ERROR Server::Init(const ServerInitParams & initParams)
mGroupsProvider = initParams.groupDataProvider;
SetGroupDataProvider(mGroupsProvider);

mTestEventTriggerDelegate = initParams.testEventTriggerDelegate;

deviceInfoprovider = DeviceLayer::GetDeviceInfoProvider();
if (deviceInfoprovider)
{
Expand Down
8 changes: 8 additions & 0 deletions src/app/server/Server.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <app/CASESessionManager.h>
#include <app/DefaultAttributePersistenceProvider.h>
#include <app/OperationalDeviceProxyPool.h>
#include <app/TestEventTriggerDelegate.h>
#include <app/server/AclStorage.h>
#include <app/server/AppDelegate.h>
#include <app/server/CommissioningWindowManager.h>
Expand Down Expand Up @@ -105,6 +106,9 @@ struct ServerInitParams
// Network native params can be injected depending on the
// selected Endpoint implementation
void * endpointNativeParams = nullptr;
// Optional. Support test event triggers when provided. Must be initialized before being
// provided.
TestEventTriggerDelegate * testEventTriggerDelegate = nullptr;
};

/**
Expand Down Expand Up @@ -242,6 +246,8 @@ class Server

PersistentStorageDelegate & GetPersistentStorage() { return *mDeviceStorage; }

TestEventTriggerDelegate * GetTestEventTriggerDelegate() { return mTestEventTriggerDelegate; }

/**
* This function send the ShutDown event before stopping
* the event loop.
Expand Down Expand Up @@ -381,6 +387,8 @@ class Server
Access::AccessControl mAccessControl;
app::AclStorage * mAclStorage;

TestEventTriggerDelegate * mTestEventTriggerDelegate;

uint16_t mOperationalServicePort;
uint16_t mUserDirectedCommissioningPort;
Inet::InterfaceId mInterfaceId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ limitations under the License.
<attribute side="server" code="0x05" define="ACTIVE_HARDWARE_FAULTS" type="ARRAY" entryType="ENUM8" writable="false" optional="true">ActiveHardwareFaults</attribute>
<attribute side="server" code="0x06" define="ACTIVE_RADIO_FAULTS" type="ARRAY" entryType="ENUM8" writable="false" optional="true">ActiveRadioFaults</attribute>
<attribute side="server" code="0x07" define="ACTIVE_NETWORK_FAULTS" type="ARRAY" entryType="ENUM8" writable="false" optional="true">ActiveNetworkFaults</attribute>
<attribute side="server" code="0x08" define="TEST_EVENT_TRIGGERS_ENABLED" type="BOOLEAN" writable="false" optional="false">TestEventTriggersEnabled</attribute>

<command source="client" code="0x00" name="TestEventTrigger" optional="false">
<description>Provide a means for certification tests to trigger some test-plan-specific events</description>
<arg name="EnableKey" type="OCTET_STRING" length="16"/>
<arg name="EventTrigger" type="INT64U"/>
</command>

<event side="server" code="0x00" name="HardwareFaultChange" priority="critical" optional="true">
<description>Indicate a change in the set of hardware faults currently detected by the Node.</description>
<field id="0" name="Current" type="HardwareFaultType" array="true"/>
Expand Down
8 changes: 8 additions & 0 deletions src/controller/data_model/controller-clusters.matter
Original file line number Diff line number Diff line change
Expand Up @@ -1958,11 +1958,19 @@ client cluster GeneralDiagnostics = 51 {
readonly attribute ENUM8 activeHardwareFaults[] = 5;
readonly attribute ENUM8 activeRadioFaults[] = 6;
readonly attribute ENUM8 activeNetworkFaults[] = 7;
readonly attribute boolean testEventTriggersEnabled = 8;
readonly attribute command_id generatedCommandList[] = 65528;
readonly attribute command_id acceptedCommandList[] = 65529;
readonly attribute attrib_id attributeList[] = 65531;
readonly attribute bitmap32 featureMap = 65532;
readonly attribute int16u clusterRevision = 65533;

request struct TestEventTriggerRequest {
OCTET_STRING enableKey = 0;
INT64U eventTrigger = 1;
}

command TestEventTrigger(TestEventTriggerRequest): DefaultSuccess = 0;
}

client cluster GroupKeyManagement = 63 {
Expand Down
27 changes: 26 additions & 1 deletion src/controller/data_model/controller-clusters.zap
Original file line number Diff line number Diff line change
Expand Up @@ -5212,7 +5212,16 @@
"define": "GENERAL_DIAGNOSTICS_CLUSTER",
"side": "client",
"enabled": 1,
"commands": [],
"commands": [
{
"name": "TestEventTrigger",
"code": 0,
"mfgCode": null,
"source": "client",
"incoming": 0,
"outgoing": 1
}
],
"attributes": [
{
"name": "ClusterRevision",
Expand Down Expand Up @@ -5369,6 +5378,22 @@
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "TestEventTriggersEnabled",
"code": 8,
"mfgCode": null,
"side": "server",
"type": "boolean",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "GeneratedCommandList",
"code": 65528,
Expand Down
15 changes: 15 additions & 0 deletions src/controller/java/zap-generated/CHIPAttributeTLVValueDecoder.cpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c6673f3

Please sign in to comment.