Skip to content

[E2E][JF] Implemented JCM mDNS advertisement and OJCW #38994

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions docs/guides/joint_fabric_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

- [Joint Fabric Guide](#joint-fabric-guide)
- [Joint Fabric Example Applications](#joint-fabric-example-applications)
- [Bootstrap Joint Fabric Demo on Linux](#bootstrap-joint-fabric-demo-on-linux)
- [Run Joint Fabric Demo](#run-joint-fabric-demo)
- [Building the Example Application](#building-the-example-application)
- [Bootstrap Joint Fabric Demo on Linux](#bootstrap-joint-fabric-demo-on-linux)
- [Initialize Ecosystem A (Vendor ID = 0xFFF1)](#initialize-ecosystem-a-vendor-id--0xfff1)
- [Initialize Ecosystem B (Vendor ID = 0xFFF2)](#initialize-ecosystem-b-vendor-id--0xfff2)
- [Run Joint Fabric Demo](#run-joint-fabric-demo)

## Joint Fabric Example Applications

Expand Down Expand Up @@ -60,7 +63,7 @@ $ rm -rf /tmp/chip_*
```
$ cd ~/connectedhomeip/examples/jf-admin-app/linux/out/debug
$ rm -rf jfa_a_kvs && touch jfa_a_kvs
$ ./jfa-app --capabilities 0x4 --passcode 110220033 --secured-device-port 5533 --rpc-server-port 33033 --KVS jfa_a_kvs
$ ./jfa-app --capabilities 0x4 --passcode 110220033 --secured-device-port 5533 --rpc-server-port 33033 --KVS jfa_a_kvs --vendor-id 0xFFF1
```

- Start jf-control-app
Expand Down Expand Up @@ -126,7 +129,7 @@ Subject: 1.3.6.1.4.1.37244.1.3 = 0000000000000003, OU = jf-anchor-icac
```
$ cd ~/connectedhomeip/examples/lighting-app/linux/out/debug
$ rm -rf light_a_kvs && touch light_a_kvs
$ ./chip-lighting-app --capabilities 0x4 --passcode 110220044 --KVS light_a_kvs
$ ./chip-lighting-app --capabilities 0x4 --passcode 110220044 --KVS light_a_kvs --vendor-id 0xFFF1
```

- Commission lighting-app
Expand Down Expand Up @@ -158,7 +161,7 @@ should be found.
```
$ cd ~/connectedhomeip/examples/jf-admin-app/linux/out/debug
$ rm -rf jfa_b_kvs && touch jfa_b_kvs
$ ./jfa-app --capabilities 0x4 --passcode 110220055 --secured-device-port 5555 --rpc-server-port 33055 --KVS jfa_b_kvs
$ ./jfa-app --capabilities 0x4 --passcode 110220055 --secured-device-port 5555 --rpc-server-port 33055 --KVS jfa_b_kvs --vendor-id 0xFFF2
```

- Start jf-control-app
Expand Down Expand Up @@ -225,7 +228,7 @@ Subject: 1.3.6.1.4.1.37244.1.3 = 0000000000000003, OU = jf-anchor-icac
```
$ cd ~/connectedhomeip/examples/lighting-app/linux/out/debug
$ rm -rf light_b_kvs && touch light_b_kvs
$ ./chip-lighting-app --capabilities 0x4 --passcode 110220066 --KVS light_b_kvs
$ ./chip-lighting-app --capabilities 0x4 --passcode 110220066 --KVS light_b_kvs --vendor-id 0xFFF2
```

- Commission lighting-app
Expand All @@ -251,3 +254,15 @@ A `Subjects` field equal to `18446744065119551489` (`FFFFFFFDFFFF0001` in hex)
should be found.

## Run Joint Fabric Demo

- Open Joint Commissioning Window on JF Admin App of Ecosystem B

```
>>> jcm open-joint-commissioning-window 11 1 400 1000 1261
```

Check for the following logs on the jf-admin-app side:

```
>>> [DIS] Advertise commission parameter vendorID=65522 productID=32769 discriminator=1261/04 cm=2 cp=0 jf=14
```
54 changes: 54 additions & 0 deletions examples/jf-admin-app/linux/JFAManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ using namespace chip::app;
using namespace chip::app::Clusters;
using namespace chip::Controller;

constexpr uint8_t kJFAvailableShift = 0;
constexpr uint8_t kJFAdminShift = 1;
constexpr uint8_t kJFAnchorShift = 2;
constexpr uint8_t kJFDatastoreShift = 3;

JFAManager JFAManager::sJFA;

CHIP_ERROR JFAManager::Init(Server & server)
Expand All @@ -41,6 +46,15 @@ CHIP_ERROR JFAManager::Init(Server & server)
return CHIP_NO_ERROR;
}

CHIP_ERROR JFAManager::GetJointFabricMode(uint8_t & jointFabricMode)
{
jointFabricMode = ((IsDeviceCommissioned() ? 0 : 1) << kJFAvailableShift) |
(IsDeviceCommissioned() ? (IsDeviceJFAdmin() ? (1 << kJFAdminShift) : 0) : 0) |
(IsDeviceCommissioned() ? (IsDeviceJFAnchor() ? (1 << kJFAnchorShift) : 0) : 0) |
(IsDeviceCommissioned() ? (1 << kJFDatastoreShift) : 0);
return CHIP_NO_ERROR;
}

CHIP_ERROR JFAManager::FinalizeCommissioning(NodeId nodeId)
{
if (jfFabricIndex == kUndefinedFabricId)
Expand Down Expand Up @@ -75,6 +89,46 @@ void JFAManager::HandleCommissioningCompleteEvent()
}
}

bool JFAManager::IsDeviceJFAdmin()
{
if (jfFabricIndex == kUndefinedFabricId)
{
return false;
}

CATValues cats;

if (mServer->GetFabricTable().FetchCATs(jfFabricIndex, cats) == CHIP_NO_ERROR)
{
if (cats.ContainsIdentifier(kAdminCATIdentifier))
{
return true;
}
}

return false;
}

bool JFAManager::IsDeviceJFAnchor()
{
if (jfFabricIndex == kUndefinedFabricId)
{
return false;
}

CATValues cats;

if (mServer->GetFabricTable().FetchCATs(jfFabricIndex, cats) == CHIP_NO_ERROR)
{
if (cats.ContainsIdentifier(kAnchorCATIdentifier))
{
return true;
}
}

return false;
}

void JFAManager::ReleaseSession()
{
auto optionalSessionHandle = mSessionHolder.Get();
Expand Down
2 changes: 2 additions & 0 deletions examples/jf-admin-app/linux/args.gni
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ chip_enable_additional_data_advertising = true
chip_enable_rotating_device_id = true

chip_enable_read_client = false

chip_device_config_enable_joint_fabric = true
6 changes: 6 additions & 0 deletions examples/jf-admin-app/linux/include/JFAManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ class JFAManager
void HandleCommissioningCompleteEvent();
CHIP_ERROR FinalizeCommissioning(NodeId nodeId);

CHIP_ERROR GetJointFabricMode(uint8_t & jointFabricMode);

bool IsDeviceCommissioned() { return jfFabricIndex != kUndefinedFabricId; }
bool IsDeviceJFAdmin();
bool IsDeviceJFAnchor();

private:
// Various actions to take when OnConnected callback is called
enum OnConnectedAction
Expand Down
56 changes: 53 additions & 3 deletions examples/jf-admin-app/linux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,81 @@
#include <app/ConcreteAttributePath.h>
#include <app/server/Server.h>
#include <lib/support/logging/CHIPLogging.h>
#include <platform/DeviceInstanceInfoProvider.h>

#include <string>

using namespace chip;
using namespace chip::app;
using namespace chip::app::Clusters;
using namespace chip::DeviceLayer;

namespace {

class ExampleDeviceInstanceInfoProvider : public DeviceInstanceInfoProvider
{
public:
void Init(DeviceInstanceInfoProvider * defaultProvider) { mDefaultProvider = defaultProvider; }

CHIP_ERROR GetVendorName(char * buf, size_t bufSize) override { return mDefaultProvider->GetVendorName(buf, bufSize); }
CHIP_ERROR GetVendorId(uint16_t & vendorId) override { return mDefaultProvider->GetVendorId(vendorId); }
CHIP_ERROR GetProductName(char * buf, size_t bufSize) override { return mDefaultProvider->GetProductName(buf, bufSize); }
CHIP_ERROR GetProductId(uint16_t & productId) override { return mDefaultProvider->GetProductId(productId); }
CHIP_ERROR GetPartNumber(char * buf, size_t bufSize) override { return mDefaultProvider->GetPartNumber(buf, bufSize); }
CHIP_ERROR GetProductURL(char * buf, size_t bufSize) override { return mDefaultProvider->GetPartNumber(buf, bufSize); }
CHIP_ERROR GetProductLabel(char * buf, size_t bufSize) override { return mDefaultProvider->GetProductLabel(buf, bufSize); }
CHIP_ERROR GetSerialNumber(char * buf, size_t bufSize) override { return mDefaultProvider->GetSerialNumber(buf, bufSize); }
CHIP_ERROR GetManufacturingDate(uint16_t & year, uint8_t & month, uint8_t & day) override
{
return mDefaultProvider->GetManufacturingDate(year, month, day);
}
CHIP_ERROR GetHardwareVersion(uint16_t & hardwareVersion) override
{
return mDefaultProvider->GetHardwareVersion(hardwareVersion);
}
CHIP_ERROR GetHardwareVersionString(char * buf, size_t bufSize) override
{
return mDefaultProvider->GetHardwareVersionString(buf, bufSize);
}
CHIP_ERROR GetRotatingDeviceIdUniqueId(MutableByteSpan & uniqueIdSpan) override
{
return mDefaultProvider->GetRotatingDeviceIdUniqueId(uniqueIdSpan);
}
CHIP_ERROR GetJointFabricMode(uint8_t & jointFabricMode) override { return JFAMgr().GetJointFabricMode(jointFabricMode); }

private:
DeviceInstanceInfoProvider * mDefaultProvider;
};

ExampleDeviceInstanceInfoProvider gExampleDeviceInstanceInfoProvider;

} // namespace

void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath & attributePath, uint8_t type, uint16_t size,
uint8_t * value)
{}

void EventHandler(const DeviceLayer::ChipDeviceEvent * event, intptr_t arg)
void EventHandler(const ChipDeviceEvent * event, intptr_t arg)
{
(void) arg;

if (event->Type == DeviceLayer::DeviceEventType::kCommissioningComplete)
if (event->Type == DeviceEventType::kCommissioningComplete)
{
JFAMgr().HandleCommissioningCompleteEvent();
}
}

void ApplicationInit()
{
auto * defaultProvider = GetDeviceInstanceInfoProvider();
if (defaultProvider != &gExampleDeviceInstanceInfoProvider)
{
gExampleDeviceInstanceInfoProvider.Init(defaultProvider);
SetDeviceInstanceInfoProvider(&gExampleDeviceInstanceInfoProvider);
}

JFAMgr().Init(Server::GetInstance());
DeviceLayer::PlatformMgrImpl().AddEventHandler(EventHandler, 0);
PlatformMgrImpl().AddEventHandler(EventHandler, 0);
}

void ApplicationShutdown() {}
Expand Down
4 changes: 3 additions & 1 deletion examples/jf-control-app/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ config("config") {

static_library("jfc-utils") {
sources = [
"${chip_root}/examples/chip-tool/CHIPCommand.h",
"${chip_root}/examples/chip-tool/commands/clusters/ModelCommand.cpp",
"${chip_root}/examples/chip-tool/commands/clusters/ModelCommand.h",
"${chip_root}/examples/chip-tool/commands/common/BDXDiagnosticLogsServerDelegate.cpp",
"${chip_root}/examples/chip-tool/commands/common/CHIPCommand.h",
"${chip_root}/examples/chip-tool/commands/common/Command.cpp",
"${chip_root}/examples/chip-tool/commands/common/Command.h",
"${chip_root}/examples/chip-tool/commands/common/Commands.cpp",
Expand All @@ -93,6 +93,8 @@ static_library("jfc-utils") {
"commands/common/CHIPCommand.cpp",
"commands/example/ExampleOperationalCredentialsIssuer.cpp",
"commands/example/ExampleOperationalCredentialsIssuer.h",
"commands/pairing/OpenJointCommissioningWindowCommand.cpp",
"commands/pairing/OpenJointCommissioningWindowCommand.h",
"commands/pairing/PairingCommand.cpp",
"commands/pairing/PairingCommand.h",
]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (c) 2025 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

#include "OpenJointCommissioningWindowCommand.h"

#include <system/SystemClock.h>

using namespace ::chip;

CHIP_ERROR OpenJointCommissioningWindowCommand::RunCommand()
{
mWindowOpener = Platform::MakeUnique<Controller::CommissioningWindowOpener>(&CurrentCommissioner());

SetupPayload ignored;
return mWindowOpener->OpenCommissioningWindow(Controller::CommissioningWindowPasscodeParams()
.SetNodeId(mNodeId)
.SetTimeout(mCommissioningWindowTimeout)
.SetIteration(mIteration)
.SetDiscriminator(mDiscriminator)
.SetReadVIDPIDAttributes(true)
.SetCallback(&mOnOpenCommissioningWindowCallback)
.SetEndpointId(mEndpointId),
ignored, true);
}

void OpenJointCommissioningWindowCommand::OnOpenCommissioningWindowResponse(void * context, NodeId remoteId, CHIP_ERROR err,
SetupPayload payload)
{
LogErrorOnFailure(err);

OpenJointCommissioningWindowCommand * command = reinterpret_cast<OpenJointCommissioningWindowCommand *>(context);
VerifyOrReturn(command != nullptr, ChipLogError(chipTool, "OnOpenJointCommissioningWindowCommand: context is null"));
command->SetCommandExitStatus(err);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright (c) 2025 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

#pragma once

#include "../common/CHIPCommand.h"

#include <controller/CommissioningWindowOpener.h>
#include <lib/support/CHIPMem.h>

class OpenJointCommissioningWindowCommand : public CHIPCommand
{
public:
OpenJointCommissioningWindowCommand(CredentialIssuerCommands * credIssuerCommands) :
CHIPCommand("open-joint-commissioning-window", credIssuerCommands),
mOnOpenCommissioningWindowCallback(OnOpenCommissioningWindowResponse, this)
{
AddArgument("node-id", 0, UINT64_MAX, &mNodeId, "Node to send command to.");
AddArgument("endpoint-id", 0, UINT16_MAX, &mEndpointId, "Endpoint the command is targeted at.");
AddArgument("window-timeout", 0, UINT16_MAX, &mCommissioningWindowTimeout,
"Time, in seconds, before the commissioning window closes.");
AddArgument("iteration", chip::Crypto::kSpake2p_Min_PBKDF_Iterations, chip::Crypto::kSpake2p_Max_PBKDF_Iterations,
&mIteration, "Number of PBKDF iterations to use to derive the verifier. Ignored if 'option' is 0.");
AddArgument("discriminator", 0, 4095, &mDiscriminator, "Discriminator to use for advertising. Ignored if 'option' is 0.");
AddArgument("timeout", 0, UINT16_MAX, &mTimeout, "Time, in seconds, before this command is considered to have timed out.");
}

/////////// CHIPCommand Interface /////////
CHIP_ERROR RunCommand() override;
// We issue multiple data model operations for this command, and the default
// timeout for those is 10 seconds, so default to 20 seconds.
chip::System::Clock::Timeout GetWaitDuration() const override { return chip::System::Clock::Seconds16(mTimeout.ValueOr(20)); }

private:
NodeId mNodeId;
uint16_t mCommissioningWindowTimeout;
uint32_t mIteration;
uint16_t mDiscriminator;

chip::Optional<uint16_t> mTimeout;

chip::EndpointId mEndpointId;

chip::Platform::UniquePtr<chip::Controller::CommissioningWindowOpener> mWindowOpener;

static void OnOpenCommissioningWindowResponse(void * context, NodeId deviceId, CHIP_ERROR status, chip::SetupPayload payload);

chip::Callback::Callback<chip::Controller::OnOpenCommissioningWindow> mOnOpenCommissioningWindowCallback;
};
Loading
Loading