Skip to content

Commit

Permalink
Initial version of Joint Fabric implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
vijs committed Jul 30, 2024
1 parent 37fc757 commit feef2f1
Show file tree
Hide file tree
Showing 664 changed files with 295,848 additions and 240,483 deletions.
1 change: 1 addition & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ jobs:
src/app/zap-templates/zcl/data-model/chip/group-key-mgmt-cluster.xml \
src/app/zap-templates/zcl/data-model/chip/identify-cluster.xml \
src/app/zap-templates/zcl/data-model/chip/illuminance-measurement-cluster.xml \
src/app/zap-templates/zcl/data-model/chip/joint-fabric-pki-cluster.xml \
src/app/zap-templates/zcl/data-model/chip/keypad-input-cluster.xml \
src/app/zap-templates/zcl/data-model/chip/laundry-washer-mode-cluster.xml \
src/app/zap-templates/zcl/data-model/chip/laundry-dryer-controls-cluster.xml \
Expand Down
1 change: 1 addition & 0 deletions docs/zap_clusters.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Generally regenerate using one of:
| 57 | 0x39 | BridgedDeviceBasicInformation |
| 59 | 0x3B | Switch |
| 60 | 0x3C | AdministratorCommissioning |
| 61 | 0x3D | JointFabricPki |
| 62 | 0x3E | OperationalCredentials |
| 63 | 0x3F | GroupKeyManagement |
| 64 | 0x40 | FixedLabel |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2368,6 +2368,68 @@ cluster AdministratorCommissioning = 60 {
timed command access(invoke: administer) RevokeCommissioning(): DefaultSuccess = 2;
}

/** Joint Fabric Pki Cluster. */
cluster JointFabricPki = 61 {
revision 1; // NOTE: Default/not specifically set

enum JointFabricStatusEnum : enum8 {
kOK = 0;
kInvalidPublicKey = 1;
kInvalidNodeOpId = 2;
kInvalidNOC = 3;
kMissingCsr = 4;
kTableFull = 5;
kInvalidAdminSubject = 6;
kFabricConflict = 9;
kLabelConflict = 10;
kInvalidFabricIndex = 11;
}

enum SignNOCIssuerRequestStatusEnum : enum8 {
kOK = 0;
kFailSafeRequired = 1;
kInvalidNOCIssuerCSR = 2;
kChainValidationFailed = 3;
kTrustQuotientThreshold = 4;
kSignNOCIssuerFailed = 5;
}

readonly attribute command_id generatedCommandList[] = 65528;
readonly attribute command_id acceptedCommandList[] = 65529;
readonly attribute event_id eventList[] = 65530;
readonly attribute attrib_id attributeList[] = 65531;
readonly attribute bitmap32 featureMap = 65532;
readonly attribute int16u clusterRevision = 65533;

request struct JointFabricRequestRequest {
int64u fabricIndex = 0;
}

response struct SignNOCIssuerRequest = 1 {
octet_string<400> NOCIssuerCSR = 0;
}

request struct SignNOCIssuerResponseRequest {
SignNOCIssuerRequestStatusEnum statusCode = 0;
octet_string<400> NOCIssuerCert = 1;
node_id nodeId = 2;
fabric_id fabricId = 3;
vendor_id adminVendorId = 4;
int64u caseAdminSubject = 5;
}

response struct JointFabricResponse = 3 {
JointFabricStatusEnum statusCode = 0;
optional fabric_idx fabricIndex = 1;
optional char_string<128> debugText = 2;
}

/** Client requests Server's ICA CSR and CA Chain. */
command access(invoke: administer) JointFabricRequest(JointFabricRequestRequest): SignNOCIssuerRequest = 0;
/** Joint Fabric ICA generated. */
command access(invoke: administer) SignNOCIssuerResponse(SignNOCIssuerResponseRequest): JointFabricResponse = 2;
}

/** This cluster is used to add or remove Operational Credentials on a Commissionee or Node, as well as manage the associated Fabrics. */
cluster OperationalCredentials = 62 {
revision 1; // NOTE: Default/not specifically set
Expand Down Expand Up @@ -7740,6 +7802,15 @@ endpoint 0 {
handle command RevokeCommissioning;
}

server cluster JointFabricPki {
ram attribute clusterRevision default = 1;

handle command JointFabricRequest;
handle command SignNOCIssuerRequest;
handle command SignNOCIssuerResponse;
handle command JointFabricResponse;
}

server cluster OperationalCredentials {
callback attribute NOCs;
callback attribute fabrics;
Expand Down
60 changes: 60 additions & 0 deletions examples/all-clusters-app/all-clusters-common/all-clusters-app.zap
Original file line number Diff line number Diff line change
Expand Up @@ -5368,6 +5368,66 @@
}
]
},
{
"name": "Joint Fabric Pki",
"code": 61,
"mfgCode": null,
"define": "JOINT_FABRIC_PKI_CLUSTER",
"side": "server",
"enabled": 1,
"commands": [
{
"name": "JointFabricRequest",
"code": 0,
"mfgCode": null,
"source": "client",
"isIncoming": 1,
"isEnabled": 1
},
{
"name": "SignNOCIssuerRequest",
"code": 1,
"mfgCode": null,
"source": "server",
"isIncoming": 0,
"isEnabled": 1
},
{
"name": "SignNOCIssuerResponse",
"code": 2,
"mfgCode": null,
"source": "client",
"isIncoming": 1,
"isEnabled": 1
},
{
"name": "JointFabricResponse",
"code": 3,
"mfgCode": null,
"source": "server",
"isIncoming": 0,
"isEnabled": 1
}
],
"attributes": [
{
"name": "ClusterRevision",
"code": 65533,
"mfgCode": null,
"side": "server",
"type": "int16u",
"included": 1,
"storageOption": "RAM",
"singleton": 0,
"bounded": 0,
"defaultValue": "1",
"reportable": 1,
"minInterval": 0,
"maxInterval": 65344,
"reportableChange": 0
}
]
},
{
"name": "Operational Credentials",
"code": 62,
Expand Down
1 change: 1 addition & 0 deletions examples/chip-tool/commands/pairing/PairingCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ CommissioningParameters PairingCommand::GetCommissioningParameters()
{
auto params = CommissioningParameters();
params.SetSkipCommissioningComplete(mSkipCommissioningComplete.ValueOr(false));
params.SetJointFabric(mJointFabric.ValueOr(false));
if (mBypassAttestationVerifier.ValueOr(false))
{
params.SetDeviceAttestationDelegate(this);
Expand Down
2 changes: 2 additions & 0 deletions examples/chip-tool/commands/pairing/PairingCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class PairingCommand : public CHIPCommand,
AddArgument("icd-symmetric-key", &mICDSymmetricKey, "The 16 bytes ICD symmetric key, default: randomly generated.");
AddArgument("icd-stay-active-duration", 0, UINT32_MAX, &mICDStayActiveDurationMsec,
"If set, a LIT ICD that is commissioned will be requested to stay active for this many milliseconds");
AddArgument("joint-fabric", 0, 1, &mJointFabric, "Enable Joint Fabric commissioning mode.");
switch (networkType)
{
case PairingNetworkType::None:
Expand Down Expand Up @@ -255,6 +256,7 @@ class PairingCommand : public CHIPCommand,
chip::app::DataModel::List<chip::app::Clusters::TimeSynchronization::Structs::DSTOffsetStruct::Type> mDSTOffsetList;
TypedComplexArgument<chip::app::DataModel::List<chip::app::Clusters::TimeSynchronization::Structs::DSTOffsetStruct::Type>>
mComplex_DSTOffsets;
chip::Optional<bool> mJointFabric;

uint16_t mRemotePort;
// mDiscriminator is only used for some situations, but in those situations
Expand Down
22 changes: 22 additions & 0 deletions examples/platform/linux/AppMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <platform/PlatformManager.h>

#include <app/InteractionModelEngine.h>
#include <app/clusters/joint-fabric-pki-server/joint-fabric-pki-server.h>
#include <app/clusters/network-commissioning/network-commissioning.h>
#include <app/server/Dnssd.h>
#include <app/server/OnboardingCodesUtil.h>
Expand Down Expand Up @@ -114,8 +115,12 @@
#include <platform/Linux/NetworkCommissioningDriver.h>
#endif // CHIP_DEVICE_LAYER_TARGET_LINUX

#include <controller/ExampleOperationalCredentialsIssuer.h>
#include <controller/ExamplePersistentStorage.h>

using namespace chip;
using namespace chip::ArgParser;
using namespace chip::Controller;
using namespace chip::Credentials;
using namespace chip::DeviceLayer;
using namespace chip::Inet;
Expand Down Expand Up @@ -492,6 +497,21 @@ int ChipLinuxAppInit(int argc, char * const argv[], OptionSet * customOptions,
return 0;
}

namespace {
static constexpr size_t kFabricId = 1;

ExampleOperationalCredentialsIssuer gOpCredsIssuer(kFabricId);
PersistentStorage gStorage;

CHIP_ERROR PrepareJointFabricCluster()
{
SetPersistentStorageDelegate(&gStorage);
SetOperationalCredentialsIssuer(&gOpCredsIssuer);
SetChipToolKvs(LinuxDeviceOptions::GetInstance().chipToolKvs);
return CHIP_NO_ERROR;
}
} // namespace

void ChipLinuxAppMainLoop(AppMainLoopImplementation * impl)
{
gMainLoopImplementation = impl;
Expand Down Expand Up @@ -579,6 +599,8 @@ void ChipLinuxAppMainLoop(AppMainLoopImplementation * impl)
// Init ZCL Data Model and CHIP App Server
Server::GetInstance().Init(initParams);

VerifyOrDie(PrepareJointFabricCluster() == CHIP_NO_ERROR);

#if CONFIG_BUILD_FOR_HOST_UNIT_TEST
// Set ReadHandler Capacity for Subscriptions
chip::app::InteractionModelEngine::GetInstance()->SetHandlerCapacityForSubscriptions(
Expand Down
7 changes: 7 additions & 0 deletions examples/platform/linux/Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ enum
#if CHIP_WITH_NLFAULTINJECTION
kDeviceOption_FaultInjection,
#endif
kDeviceOption_ChipToolKvs = 0x1028,
};

constexpr unsigned kAppUsageLength = 64;
Expand Down Expand Up @@ -171,6 +172,7 @@ OptionDef sDeviceOptionDefs[] = {
#if CHIP_WITH_NLFAULTINJECTION
{ "faults", kArgumentRequired, kDeviceOption_FaultInjection },
#endif
{ "chip-tool-kvs", kArgumentRequired, kDeviceOption_ChipToolKvs },
{}
};

Expand Down Expand Up @@ -306,6 +308,8 @@ const char * sDeviceOptionHelp =
" --faults <fault-string,...>\n"
" Inject specified fault(s) at runtime.\n"
#endif
" --chip-tool-kvs <filepath>\n"
" A file to sync Key Value Store items with chip-tool.\n"
"\n";

bool Base64ArgToVector(const char * arg, size_t maxSize, std::vector<uint8_t> & outVector)
Expand Down Expand Up @@ -589,6 +593,9 @@ bool HandleOption(const char * aProgram, OptionSet * aOptions, int aIdentifier,
break;
}
#endif
case kDeviceOption_ChipToolKvs:
LinuxDeviceOptions::GetInstance().chipToolKvs = aValue;
break;
default:
PrintArgError("%s: INTERNAL ERROR: Unhandled option: %s\n", aProgram, aName);
retval = false;
Expand Down
1 change: 1 addition & 0 deletions examples/platform/linux/Options.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ struct LinuxDeviceOptions
int32_t subscriptionCapacity = CHIP_IM_MAX_NUM_SUBSCRIPTIONS;
int32_t subscriptionResumptionRetryIntervalSec = -1;
#endif
const char * chipToolKvs = nullptr;
static LinuxDeviceOptions & GetInstance();
};

Expand Down
2 changes: 2 additions & 0 deletions scripts/rules.matterlint
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ load "../src/app/zap-templates/zcl/data-model/chip/groups-cluster.xml";
load "../src/app/zap-templates/zcl/data-model/chip/group-key-mgmt-cluster.xml";
load "../src/app/zap-templates/zcl/data-model/chip/identify-cluster.xml";
load "../src/app/zap-templates/zcl/data-model/chip/illuminance-measurement-cluster.xml";
load "../src/app/zap-templates/zcl/data-model/chip/joint-fabric-pki-cluster.xml";
load "../src/app/zap-templates/zcl/data-model/chip/keypad-input-cluster.xml";
load "../src/app/zap-templates/zcl/data-model/chip/laundry-washer-mode-cluster.xml";
load "../src/app/zap-templates/zcl/data-model/chip/laundry-dryer-controls-cluster.xml";
Expand Down Expand Up @@ -152,6 +153,7 @@ endpoint 0 {
require server cluster GeneralCommissioning;
require server cluster AdministratorCommissioning;
require server cluster OperationalCredentials;
require server cluster JointFabricPki
require server cluster GeneralDiagnostics;

// Example rejection of clusters:
Expand Down
2 changes: 2 additions & 0 deletions src/app/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ static_library("app") {
output_name = "libCHIPDataModel"

sources = [
"${chip_root}/src/controller/ExamplePersistentStorage.cpp",
"AttributePathExpandIterator.h",
"AttributePersistenceProvider.h",
"ChunkedWriteCallback.cpp",
Expand Down Expand Up @@ -473,6 +474,7 @@ static_library("app") {
"${chip_root}/src/messaging",
"${chip_root}/src/protocols/interaction_model",
"${chip_root}/src/system",
"${chip_root}/third_party/inipp",
]

if (chip_use_data_model_interface == "disabled") {
Expand Down
Loading

0 comments on commit feef2f1

Please sign in to comment.