Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use TestEventTriggerDelegate in General Diagnostics Cluster #18852

Merged
Merged
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
}
],
tehampson marked this conversation as resolved.
Show resolved Hide resolved
"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 @@ -2029,6 +2029,7 @@ server cluster OperationalCredentials = 62 {
kInvalidNOC = 3;
kMissingCsr = 4;
kTableFull = 5;
kInvalidAdminSubject = 6;
kInsufficientPrivilege = 8;
kFabricConflict = 9;
kLabelConflict = 10;
Expand Down Expand Up @@ -2075,7 +2076,7 @@ server cluster OperationalCredentials = 62 {
OCTET_STRING NOCValue = 0;
optional OCTET_STRING ICACValue = 1;
OCTET_STRING IPKValue = 2;
NODE_ID caseAdminNode = 3;
Int64u caseAdminSubject = 3;
VENDOR_ID adminVendorId = 4;
}

Expand Down Expand Up @@ -3001,14 +3002,14 @@ server cluster ThreadNetworkDiagnostics = 53 {
readonly attribute nullable octet_string<17> meshLocalPrefix = 5;
readonly attribute NeighborTable neighborTableList[] = 7;
readonly attribute RouteTable routeTableList[] = 8;
readonly attribute int32u partitionId = 9;
readonly attribute int8u weighting = 10;
readonly attribute int8u dataVersion = 11;
readonly attribute int8u stableDataVersion = 12;
readonly attribute int8u leaderRouterId = 13;
readonly attribute SecurityPolicy securityPolicy[] = 59;
readonly attribute octet_string<4> channelMask = 60;
readonly attribute OperationalDatasetComponents operationalDatasetComponents[] = 61;
readonly attribute nullable int32u partitionId = 9;
readonly attribute nullable int8u weighting = 10;
readonly attribute nullable int8u dataVersion = 11;
tehampson marked this conversation as resolved.
Show resolved Hide resolved
readonly attribute nullable int8u stableDataVersion = 12;
readonly attribute nullable int8u leaderRouterId = 13;
readonly attribute nullable SecurityPolicy securityPolicy[] = 59;
readonly attribute nullable octet_string<4> channelMask = 60;
readonly attribute nullable OperationalDatasetComponents operationalDatasetComponents[] = 61;
readonly attribute NetworkFault activeNetworkFaultsList[] = 62;
readonly attribute bitmap32 featureMap = 65532;
readonly attribute int16u clusterRevision = 65533;
Expand Down Expand Up @@ -3370,21 +3371,21 @@ endpoint 0 {
}

server cluster ThreadNetworkDiagnostics {
ram attribute channel;
ram attribute routingRole;
ram attribute networkName;
ram attribute panId;
ram attribute extendedPanId;
ram attribute meshLocalPrefix;
callback attribute channel;
callback attribute routingRole;
callback attribute networkName;
callback attribute panId;
callback attribute extendedPanId;
callback attribute meshLocalPrefix;
callback attribute neighborTableList;
callback attribute routeTableList;
ram attribute partitionId;
ram attribute weighting;
ram attribute dataVersion;
ram attribute stableDataVersion;
ram attribute leaderRouterId;
callback attribute partitionId;
callback attribute weighting;
callback attribute dataVersion;
callback attribute stableDataVersion;
callback attribute leaderRouterId;
callback attribute securityPolicy;
ram attribute channelMask;
callback attribute channelMask;
callback attribute operationalDatasetComponents;
callback attribute activeNetworkFaultsList;
ram attribute featureMap;
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