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

[Fabric-Sync] Fix failing to pair sync device #36510

Merged
merged 3 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 3 additions & 2 deletions examples/fabric-admin/device_manager/DeviceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,13 +381,14 @@ void DeviceManager::HandleAttributePartsListUpdate(TLV::TLVReader & data)
for (const auto & endpoint : addedEndpoints)
{
// print to console
fprintf(stderr, "A new device is added on Endpoint: %u\n", endpoint);
fprintf(stderr, "A new endpoint %u is added on the remote bridge\n", endpoint);
}

// Process removed endpoints
for (const auto & endpoint : removedEndpoints)
{
ChipLogProgress(NotSpecified, "Endpoint removed: %u", endpoint);
// print to console
fprintf(stderr, "Endpoint %u removed from the remote bridge\n", endpoint);

Device * device = FindDeviceByEndpoint(endpoint);

Expand Down
5 changes: 3 additions & 2 deletions examples/fabric-sync/admin/DeviceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,13 +450,14 @@ void DeviceManager::HandleAttributePartsListUpdate(TLV::TLVReader & data)
for (const auto & endpoint : addedEndpoints)
{
// print to console
fprintf(stderr, "A new device is added on Endpoint: %u\n", endpoint);
fprintf(stderr, "A new endpoint %u is added on the remote bridge\n", endpoint);
}

// Process removed endpoints
for (const auto & endpoint : removedEndpoints)
{
ChipLogProgress(NotSpecified, "Endpoint removed: %u", endpoint);
// print to console
fprintf(stderr, "Endpoint %u removed from the remote bridge\n", endpoint);

SyncedDevice * device = FindDeviceByEndpoint(endpoint);

Expand Down
5 changes: 5 additions & 0 deletions examples/fabric-sync/admin/PairingManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,11 @@ void PairingManager::OnCurrentFabricRemove(void * context, NodeId nodeId, CHIP_E
self->mPairingDelegate->OnDeviceRemoved(nodeId, err);
self->SetPairingDelegate(nullptr);
}

FabricIndex fabricIndex = self->CurrentCommissioner().GetFabricIndex();
app::InteractionModelEngine::GetInstance()->ShutdownSubscriptions(fabricIndex, nodeId);
ScopedNodeId scopedNodeId(nodeId, fabricIndex);
DeviceManager::Instance().RemoveSyncedDevice(scopedNodeId);
}
else
{
Expand Down
77 changes: 77 additions & 0 deletions examples/fabric-sync/bridge/src/Bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,83 @@ namespace bridge {

namespace {

class AdministratorCommissioningCommandHandler : public CommandHandlerInterface
yufengwangca marked this conversation as resolved.
Show resolved Hide resolved
{
public:
// Register for the AdministratorCommissioning cluster on all endpoints.
AdministratorCommissioningCommandHandler() :
CommandHandlerInterface(Optional<EndpointId>::Missing(), AdministratorCommissioning::Id)
{}

void InvokeCommand(HandlerContext & handlerContext) override;
};

void AdministratorCommissioningCommandHandler::InvokeCommand(HandlerContext & handlerContext)
{
using Protocols::InteractionModel::Status;

EndpointId endpointId = handlerContext.mRequestPath.mEndpointId;

if (handlerContext.mRequestPath.mCommandId != AdministratorCommissioning::Commands::OpenCommissioningWindow::Id ||
endpointId == kRootEndpointId)
{
// Proceed with default handling in Administrator Commissioning Server
return;
}

ChipLogProgress(NotSpecified, "Received command to open commissioning window on Endpoint: %d", endpointId);

handlerContext.SetCommandHandled();

AdministratorCommissioning::Commands::OpenCommissioningWindow::DecodableType commandData;
if (DataModel::Decode(handlerContext.mPayload, commandData) != CHIP_NO_ERROR)
{
handlerContext.mCommandHandler.AddStatus(handlerContext.mRequestPath, Status::InvalidCommand);
return;
}

Status status = Status::Failure;
BridgedDevice * device = BridgedDeviceManager::Instance().GetDevice(endpointId);
FabricAdminDelegate * adminDelegate = FabricBridge::Instance().GetDelegate();

if (!device)
{
ChipLogError(NotSpecified, "Commissioning window failed to open: device is null");
return;
}

if (!adminDelegate)
{
ChipLogError(NotSpecified, "Commissioning window failed to open: adminDelegate is null");
return;
}

auto nodeId = device->GetScopedNodeId().GetNodeId();
auto fabricIndex = device->GetScopedNodeId().GetFabricIndex();

Controller::CommissioningWindowVerifierParams params;
params.SetNodeId(nodeId)
.SetTimeout(commandData.commissioningTimeout)
.SetDiscriminator(commandData.discriminator)
.SetIteration(commandData.iterations)
.SetSalt(commandData.salt)
.SetVerifier(commandData.PAKEPasscodeVerifier);

CHIP_ERROR err = adminDelegate->OpenCommissioningWindow(params, fabricIndex);

if (err == CHIP_NO_ERROR)
{
ChipLogProgress(NotSpecified, "Commissioning window is now open");
status = Status::Success;
}
else
{
ChipLogError(NotSpecified, "Failed to open commissioning window. Error: %" CHIP_ERROR_FORMAT, err.Format());
}

handlerContext.mCommandHandler.AddStatus(handlerContext.mRequestPath, status);
}

class BridgedDeviceInformationCommandHandler : public CommandHandlerInterface
{
public:
Expand Down
Loading