diff --git a/docs/guides/fabric_synchronization_guide.md b/docs/guides/fabric_synchronization_guide.md index 22d616211fbd01..e5d47dda8f9563 100644 --- a/docs/guides/fabric_synchronization_guide.md +++ b/docs/guides/fabric_synchronization_guide.md @@ -107,7 +107,7 @@ fabricsync add-local-bridge 1 Pair the Ecosystem 2 bridge to Ecosystem 1 with node ID 2: ``` -fabricsync add-bridge 2 +fabricsync add-bridge 2 ``` This command will initiate the reverse commissioning process. After a few diff --git a/examples/fabric-admin/commands/fabric-sync/FabricSyncCommand.cpp b/examples/fabric-admin/commands/fabric-sync/FabricSyncCommand.cpp index 6a7b5be05bb3bd..3c389c468f9485 100644 --- a/examples/fabric-admin/commands/fabric-sync/FabricSyncCommand.cpp +++ b/examples/fabric-admin/commands/fabric-sync/FabricSyncCommand.cpp @@ -104,7 +104,7 @@ CHIP_ERROR FabricSyncAddBridgeCommand::RunCommand(NodeId remoteId) pairingCommand->RegisterCommissioningDelegate(this); mBridgeNodeId = remoteId; - DeviceMgr().PairRemoteFabricBridge(remoteId, reinterpret_cast(mRemoteAddr.data())); + DeviceMgr().PairRemoteFabricBridge(remoteId, mSetupPINCode, reinterpret_cast(mRemoteAddr.data()), mRemotePort); return CHIP_NO_ERROR; } @@ -207,6 +207,15 @@ CHIP_ERROR FabricSyncAddLocalBridgeCommand::RunCommand(NodeId deviceId) pairingCommand->RegisterCommissioningDelegate(this); mLocalBridgeNodeId = deviceId; + if (mSetupPINCode.HasValue()) + { + DeviceMgr().SetLocalBridgeSetupPinCode(mSetupPINCode.Value()); + } + if (mLocalPort.HasValue()) + { + DeviceMgr().SetLocalBridgePort(mLocalPort.Value()); + } + DeviceMgr().PairLocalFabricBridge(deviceId); return CHIP_NO_ERROR; diff --git a/examples/fabric-admin/commands/fabric-sync/FabricSyncCommand.h b/examples/fabric-admin/commands/fabric-sync/FabricSyncCommand.h index 1bbd22d293f39d..669edd75d653e6 100644 --- a/examples/fabric-admin/commands/fabric-sync/FabricSyncCommand.h +++ b/examples/fabric-admin/commands/fabric-sync/FabricSyncCommand.h @@ -31,8 +31,10 @@ class FabricSyncAddBridgeCommand : public CHIPCommand, public CommissioningDeleg public: FabricSyncAddBridgeCommand(CredentialIssuerCommands * credIssuerCommands) : CHIPCommand("add-bridge", credIssuerCommands) { - AddArgument("nodeid", 0, UINT64_MAX, &mNodeId); - AddArgument("device-remote-ip", &mRemoteAddr); + AddArgument("node-id", 0, UINT64_MAX, &mNodeId); + AddArgument("setup-pin-code", 0, 0x7FFFFFF, &mSetupPINCode, "Setup PIN code for the remote bridge device."); + AddArgument("device-remote-ip", &mRemoteAddr, "The IP address of the remote bridge device."); + AddArgument("device-remote-port", 0, UINT16_MAX, &mRemotePort, "The secured device port of the remote bridge device."); } void OnCommissioningComplete(chip::NodeId deviceId, CHIP_ERROR err) override; @@ -45,7 +47,9 @@ class FabricSyncAddBridgeCommand : public CHIPCommand, public CommissioningDeleg private: chip::NodeId mNodeId; chip::NodeId mBridgeNodeId; + uint32_t mSetupPINCode; chip::ByteSpan mRemoteAddr; + uint16_t mRemotePort; CHIP_ERROR RunCommand(NodeId remoteId); }; @@ -73,7 +77,9 @@ class FabricSyncAddLocalBridgeCommand : public CHIPCommand, public Commissioning FabricSyncAddLocalBridgeCommand(CredentialIssuerCommands * credIssuerCommands) : CHIPCommand("add-local-bridge", credIssuerCommands) { - AddArgument("nodeid", 0, UINT64_MAX, &mNodeId); + AddArgument("node-id", 0, UINT64_MAX, &mNodeId); + AddArgument("setup-pin-code", 0, 0x7FFFFFF, &mSetupPINCode, "Setup PIN code for the local bridge device."); + AddArgument("local-port", 0, UINT16_MAX, &mLocalPort, "The secured device port of the local bridge device."); } void OnCommissioningComplete(NodeId deviceId, CHIP_ERROR err) override; @@ -85,6 +91,8 @@ class FabricSyncAddLocalBridgeCommand : public CHIPCommand, public Commissioning private: chip::NodeId mNodeId; + chip::Optional mSetupPINCode; + chip::Optional mLocalPort; chip::NodeId mLocalBridgeNodeId; CHIP_ERROR RunCommand(chip::NodeId deviceId); diff --git a/examples/fabric-admin/device_manager/DeviceManager.cpp b/examples/fabric-admin/device_manager/DeviceManager.cpp index ad8def646a0594..54c4bd8d45debf 100644 --- a/examples/fabric-admin/device_manager/DeviceManager.cpp +++ b/examples/fabric-admin/device_manager/DeviceManager.cpp @@ -30,10 +30,6 @@ using namespace chip::app::Clusters; namespace { -// Constants -constexpr uint32_t kSetupPinCode = 20202021; -constexpr uint16_t kRemoteBridgePort = 5540; -constexpr uint16_t kLocalBridgePort = 5540; constexpr uint16_t kWindowTimeout = 300; constexpr uint16_t kIteration = 1000; constexpr uint16_t kSubscribeMinInterval = 0; @@ -137,7 +133,7 @@ void DeviceManager::OpenRemoteDeviceCommissioningWindow(EndpointId remoteEndpoin // that is part of a different fabric, accessed through a fabric bridge. StringBuilder commandBuilder; - // Use random discriminator to have less chance of collission. + // Use random discriminator to have less chance of collision. uint16_t discriminator = Crypto::GetRandU16() % (kMaxDiscriminatorLength + 1); // Include the upper limit kMaxDiscriminatorLength @@ -148,12 +144,13 @@ void DeviceManager::OpenRemoteDeviceCommissioningWindow(EndpointId remoteEndpoin PushCommand(commandBuilder.c_str()); } -void DeviceManager::PairRemoteFabricBridge(NodeId nodeId, const char * deviceRemoteIp) +void DeviceManager::PairRemoteFabricBridge(chip::NodeId nodeId, uint32_t setupPINCode, const char * deviceRemoteIp, + uint16_t deviceRemotePort) { StringBuilder commandBuilder; commandBuilder.Add("pairing already-discovered "); - commandBuilder.AddFormat("%lu %d %s %d", nodeId, kSetupPinCode, deviceRemoteIp, kRemoteBridgePort); + commandBuilder.AddFormat("%lu %d %s %d", nodeId, setupPINCode, deviceRemoteIp, deviceRemotePort); PushCommand(commandBuilder.c_str()); } @@ -173,7 +170,7 @@ void DeviceManager::PairLocalFabricBridge(NodeId nodeId) StringBuilder commandBuilder; commandBuilder.Add("pairing already-discovered "); - commandBuilder.AddFormat("%lu %d ::1 %d", nodeId, kSetupPinCode, kLocalBridgePort); + commandBuilder.AddFormat("%lu %d ::1 %d", nodeId, mLocalBridgeSetupPinCode, mLocalBridgePort); PushCommand(commandBuilder.c_str()); } diff --git a/examples/fabric-admin/device_manager/DeviceManager.h b/examples/fabric-admin/device_manager/DeviceManager.h index fa94f3d09d18cf..22a3004aa1642b 100644 --- a/examples/fabric-admin/device_manager/DeviceManager.h +++ b/examples/fabric-admin/device_manager/DeviceManager.h @@ -24,6 +24,8 @@ #include +constexpr uint32_t kDefaultSetupPinCode = 20202021; +constexpr uint16_t kDefaultLocalBridgePort = 5540; constexpr uint16_t kResponseTimeoutSeconds = 30; class Device @@ -61,6 +63,8 @@ class DeviceManager : public PairingDelegate void SetRemoteBridgeNodeId(chip::NodeId nodeId) { mRemoteBridgeNodeId = nodeId; } + void SetLocalBridgePort(uint16_t port) { mLocalBridgePort = port; } + void SetLocalBridgeSetupPinCode(uint32_t pinCode) { mLocalBridgeSetupPinCode = pinCode; } void SetLocalBridgeNodeId(chip::NodeId nodeId) { mLocalBridgeNodeId = nodeId; } bool IsAutoSyncEnabled() const { return mAutoSyncEnabled; } @@ -125,9 +129,11 @@ class DeviceManager : public PairingDelegate * @param nodeId The user-defined ID for the node being commissioned. It doesn’t need to be the same ID, * as for the first fabric. + * @param setupPINCode The setup PIN code used to authenticate the pairing process. * @param deviceRemoteIp The IP address of the remote device that is being paired as part of the fabric bridge. + * @param deviceRemotePort The secured device port of the remote device that is being paired as part of the fabric bridge. */ - void PairRemoteFabricBridge(chip::NodeId nodeId, const char * deviceRemoteIp); + void PairRemoteFabricBridge(chip::NodeId nodeId, uint32_t setupPINCode, const char * deviceRemoteIp, uint16_t deviceRemotePort); /** * @brief Pair a remote Matter device to the current fabric. @@ -190,6 +196,8 @@ class DeviceManager : public PairingDelegate // This represents the bridge on the other ecosystem. chip::NodeId mRemoteBridgeNodeId = chip::kUndefinedNodeId; + uint16_t mLocalBridgePort = kDefaultLocalBridgePort; + uint32_t mLocalBridgeSetupPinCode = kDefaultSetupPinCode; // The Node ID of the local bridge used for Fabric-Sync // This represents the bridge within its own ecosystem. chip::NodeId mLocalBridgeNodeId = chip::kUndefinedNodeId;