Skip to content

Commit

Permalink
[Fabric Bridge] Overwrite the default implementation of Administrator…
Browse files Browse the repository at this point in the history
… Commissioning C… (#33909)

* Overwrite the default implementation of Administrator Commissioning Cluster

* Address review comments
  • Loading branch information
yufengwangca authored Jun 18, 2024
1 parent b6e1a48 commit dacf560
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions examples/fabric-bridge-app/linux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@

using namespace chip;

using namespace chip::app;
using namespace chip::app::Clusters;
using namespace chip::app::Clusters::AdministratorCommissioning;

#define ZCL_DESCRIPTOR_CLUSTER_REVISION (1u)
#define ZCL_BRIDGED_DEVICE_BASIC_INFORMATION_CLUSTER_REVISION (2u)
#define ZCL_BRIDGED_DEVICE_BASIC_INFORMATION_FEATURE_MAP (0u)
Expand Down Expand Up @@ -97,10 +101,62 @@ void AttemptRpcClientConnect(System::Layer * systemLayer, void * appState)
}
#endif // defined(PW_RPC_FABRIC_BRIDGE_SERVICE) && PW_RPC_FABRIC_BRIDGE_SERVICE

class AdministratorCommissioningCommandHandler : public CommandHandlerInterface
{
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;
ChipLogProgress(NotSpecified, "Received command to open commissioning window on Endpoind: %d", endpointId);

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

handlerContext.SetCommandHandled();
Status status = Status::Success;

#if defined(PW_RPC_FABRIC_BRIDGE_SERVICE) && PW_RPC_FABRIC_BRIDGE_SERVICE
Device * device = DeviceMgr().GetDevice(endpointId);

// TODO: issues:#33784, need to make OpenCommissioningWindow synchronous
if (device != nullptr && OpenCommissioningWindow(device->GetNodeId()) == CHIP_NO_ERROR)
{
ChipLogProgress(NotSpecified, "Commissioning window is now open");
}
else
{
status = Status::Failure;
ChipLogProgress(NotSpecified, "Commissioning window is failed to open");
}
#else
status = Status::Failure;
ChipLogProgress(NotSpecified, "Commissioning window failed to open: PW_RPC_FABRIC_BRIDGE_SERVICE not defined");
#endif // defined(PW_RPC_FABRIC_BRIDGE_SERVICE) && PW_RPC_FABRIC_BRIDGE_SERVICE

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

AdministratorCommissioningCommandHandler gAdministratorCommissioningCommandHandler;

} // namespace

void ApplicationInit()
{
InteractionModelEngine::GetInstance()->RegisterCommandHandler(&gAdministratorCommissioningCommandHandler);

#if defined(PW_RPC_FABRIC_BRIDGE_SERVICE) && PW_RPC_FABRIC_BRIDGE_SERVICE
InitRpcServer(kFabricBridgeServerPort);
AttemptRpcClientConnect(&DeviceLayer::SystemLayer(), nullptr);
Expand Down

0 comments on commit dacf560

Please sign in to comment.