diff --git a/examples/common/pigweed/protos/fabric_admin_service.options b/examples/common/pigweed/protos/fabric_admin_service.options index 9a65ae8a2b61d1..c7dbc02f1b5a2a 100644 --- a/examples/common/pigweed/protos/fabric_admin_service.options +++ b/examples/common/pigweed/protos/fabric_admin_service.options @@ -1,2 +1,3 @@ chip.rpc.DeviceCommissioningWindowInfo.verifier max_size:97 // kSpake2p_VerifierSerialized_Length chip.rpc.DeviceCommissioningWindowInfo.salt max_size:32 // kSpake2p_Max_PBKDF_Salt_Length +chip.rpc.DeviceCommissioningInfo.salt max_size:32 // kSpake2p_Max_PBKDF_Salt_Length diff --git a/examples/common/pigweed/protos/fabric_admin_service.proto b/examples/common/pigweed/protos/fabric_admin_service.proto index b2c81d5ee0eaae..3c311493d1c6f3 100644 --- a/examples/common/pigweed/protos/fabric_admin_service.proto +++ b/examples/common/pigweed/protos/fabric_admin_service.proto @@ -14,6 +14,14 @@ message DeviceCommissioningWindowInfo { bytes verifier = 6; } +// Define the message for commissioning a device with necessary fields +message DeviceCommissioningInfo { + uint32 discriminator = 1; + uint32 iterations = 2; + uint32 setup_pin = 3; + bytes salt = 4; +} + message KeepActiveParameters { uint64 node_id = 1; uint32 stay_active_duration_ms = 2; @@ -26,5 +34,6 @@ message OperationStatus { service FabricAdmin { rpc OpenCommissioningWindow(DeviceCommissioningWindowInfo) returns (OperationStatus){} + rpc CommissionNode(DeviceCommissioningInfo) returns (pw.protobuf.Empty){} rpc KeepActive(KeepActiveParameters) returns (pw.protobuf.Empty){} } diff --git a/examples/common/pigweed/rpc_services/FabricAdmin.h b/examples/common/pigweed/rpc_services/FabricAdmin.h index 125d322e3ab8bf..256b06c73e4fd5 100644 --- a/examples/common/pigweed/rpc_services/FabricAdmin.h +++ b/examples/common/pigweed/rpc_services/FabricAdmin.h @@ -40,6 +40,11 @@ class FabricAdmin : public pw_rpc::nanopb::FabricAdmin::Service return pw::Status::Unimplemented(); } + virtual pw::Status CommissionNode(const chip_rpc_DeviceCommissioningInfo & request, pw_protobuf_Empty & response) + { + return pw::Status::Unimplemented(); + } + virtual pw::Status KeepActive(const chip_rpc_KeepActiveParameters & request, pw_protobuf_Empty & response) { return pw::Status::Unimplemented(); diff --git a/examples/fabric-admin/commands/clusters/ClusterCommand.h b/examples/fabric-admin/commands/clusters/ClusterCommand.h index 4865f056e135f4..ab2a535da41cc5 100644 --- a/examples/fabric-admin/commands/clusters/ClusterCommand.h +++ b/examples/fabric-admin/commands/clusters/ClusterCommand.h @@ -84,14 +84,7 @@ class ClusterCommand : public InteractionModelCommands, public ModelCommand, pub if (data != nullptr) { LogErrorOnFailure(RemoteDataModelLogger::LogCommandAsJSON(path, data)); - - error = DataModelLogger::LogCommand(path, data); - if (CHIP_NO_ERROR != error) - { - ChipLogError(NotSpecified, "Response Failure: Can not decode Data"); - mError = error; - return; - } + DeviceMgr().HandleCommandResponse(path, data); } } diff --git a/examples/fabric-admin/device_manager/DeviceManager.cpp b/examples/fabric-admin/device_manager/DeviceManager.cpp index 17adcc2427f9c6..fe0c8aea4da5cb 100644 --- a/examples/fabric-admin/device_manager/DeviceManager.cpp +++ b/examples/fabric-admin/device_manager/DeviceManager.cpp @@ -56,12 +56,12 @@ void DeviceManager::Init() NodeId DeviceManager::GetNextAvailableNodeId() { mLastUsedNodeId++; - VerifyOrDieWithMsg(mLastUsedNodeId < std::numeric_limits::max(), NotSpecified, "No more available NodeIds."); + VerifyOrDieWithMsg(mLastUsedNodeId < std::numeric_limits::max(), NotSpecified, "No more available NodeIds."); return mLastUsedNodeId; } -void DeviceManager::UpdateLastUsedNodeId(chip::NodeId nodeId) +void DeviceManager::UpdateLastUsedNodeId(NodeId nodeId) { if (nodeId > mLastUsedNodeId) { @@ -159,7 +159,7 @@ void DeviceManager::PairRemoteFabricBridge(NodeId nodeId, const char * deviceRem PushCommand(commandBuilder.c_str()); } -void DeviceManager::PairRemoteDevice(chip::NodeId nodeId, const char * payload) +void DeviceManager::PairRemoteDevice(NodeId nodeId, const char * payload) { StringBuilder commandBuilder; @@ -238,7 +238,7 @@ void DeviceManager::ReadSupportedDeviceCategories() PushCommand(commandBuilder.c_str()); } -void DeviceManager::StartReverseCommissioning() +void DeviceManager::RequestCommissioningApproval() { ChipLogProgress(NotSpecified, "Starting reverse commissioning for bridge device: NodeId: " ChipLogFormatX64, ChipLogValueX64(mRemoteBridgeNodeId)); @@ -255,7 +255,36 @@ void DeviceManager::StartReverseCommissioning() PushCommand(commandBuilder.c_str()); } -void DeviceManager::CommissionApprovedRequest(uint64_t requestId, uint16_t responseTimeoutSeconds) +void DeviceManager::HandleCommissioningRequestResult(TLV::TLVReader * data) +{ + ChipLogProgress(NotSpecified, "CommissioningRequestResult event received."); + + CommissionerControl::Events::CommissioningRequestResult::DecodableType value; + CHIP_ERROR error = app::DataModel::Decode(*data, value); + if (error != CHIP_NO_ERROR) + { + ChipLogError(NotSpecified, "Failed to decode event value. Error: %" CHIP_ERROR_FORMAT, error.Format()); + return; + } + + if (value.requestId != mRequestId) + { + ChipLogError(NotSpecified, "The RequestId does not match the RequestId provided to RequestCommissioningApproval"); + return; + } + + if (value.statusCode != static_cast(Protocols::InteractionModel::Status::Success)) + { + ChipLogError(NotSpecified, "The server is not ready to begin commissioning the requested device"); + return; + } + + // The server is ready to begin commissioning the requested device, request the Commissioner Control Server to begin + // commissioning a previously approved request. + SendCommissionNodeRequest(value.requestId, kResponseTimeoutSeconds); +} + +void DeviceManager::SendCommissionNodeRequest(uint64_t requestId, uint16_t responseTimeoutSeconds) { ChipLogProgress(NotSpecified, "Request the Commissioner Control Server to begin commissioning a previously approved request."); @@ -266,6 +295,35 @@ void DeviceManager::CommissionApprovedRequest(uint64_t requestId, uint16_t respo PushCommand(commandBuilder.c_str()); } +void DeviceManager::HandleReverseOpenCommissioningWindow(TLV::TLVReader * data) +{ + CommissionerControl::Commands::ReverseOpenCommissioningWindow::DecodableType value; + CHIP_ERROR error = app::DataModel::Decode(*data, value); + if (error != CHIP_NO_ERROR) + { + ChipLogError(NotSpecified, "Failed to decode command response value. Error: %" CHIP_ERROR_FORMAT, error.Format()); + return; + } + + // Log all fields + ChipLogProgress(NotSpecified, "DecodableType fields:"); + ChipLogProgress(NotSpecified, " commissioningTimeout: %u", value.commissioningTimeout); + ChipLogProgress(NotSpecified, " discriminator: %u", value.discriminator); + ChipLogProgress(NotSpecified, " iterations: %u", value.iterations); + + char verifierHex[Crypto::kSpake2p_VerifierSerialized_Length * 2 + 1]; + Encoding::BytesToHex(value.PAKEPasscodeVerifier.data(), value.PAKEPasscodeVerifier.size(), verifierHex, sizeof(verifierHex), + Encoding::HexFlags::kNullTerminate); + ChipLogProgress(NotSpecified, " PAKEPasscodeVerifier: %s", verifierHex); + + char saltHex[Crypto::kSpake2p_Max_PBKDF_Salt_Length * 2 + 1]; + Encoding::BytesToHex(value.salt.data(), value.salt.size(), saltHex, sizeof(saltHex), Encoding::HexFlags::kNullTerminate); + ChipLogProgress(NotSpecified, " salt: %s", saltHex); + + OpenDeviceCommissioningWindow(mLocalBridgeNodeId, value.commissioningTimeout, value.iterations, value.discriminator, saltHex, + verifierHex); +} + void DeviceManager::HandleAttributeData(const app::ConcreteDataAttributePath & path, TLV::TLVReader * data) { if (path.mClusterId == CommissionerControl::Id && @@ -284,7 +342,7 @@ void DeviceManager::HandleAttributeData(const app::ConcreteDataAttributePath & p if (value.Has(CommissionerControl::SupportedDeviceCategoryBitmap::kFabricSynchronization)) { ChipLogProgress(NotSpecified, "Remote Fabric-Bridge supports Fabric Synchronization, start reverse commissioning."); - StartReverseCommissioning(); + RequestCommissioningApproval(); } return; @@ -399,39 +457,24 @@ void DeviceManager::HandleAttributeData(const app::ConcreteDataAttributePath & p } } -void DeviceManager::HandleEventData(const chip::app::EventHeader & header, chip::TLV::TLVReader * data) +void DeviceManager::HandleEventData(const app::EventHeader & header, TLV::TLVReader * data) { - if (header.mPath.mClusterId != CommissionerControl::Id || - header.mPath.mEventId != CommissionerControl::Events::CommissioningRequestResult::Id) - { - return; - } - - ChipLogProgress(NotSpecified, "CommissioningRequestResult event received."); - - CommissionerControl::Events::CommissioningRequestResult::DecodableType value; - CHIP_ERROR error = app::DataModel::Decode(*data, value); - if (error != CHIP_NO_ERROR) + if (header.mPath.mClusterId == CommissionerControl::Id && + header.mPath.mEventId == CommissionerControl::Events::CommissioningRequestResult::Id) { - ChipLogError(NotSpecified, "Failed to decode event value. Error: %" CHIP_ERROR_FORMAT, error.Format()); - return; + HandleCommissioningRequestResult(data); } +} - if (value.requestId != mRequestId) - { - ChipLogError(NotSpecified, "The RequestId does not match the RequestId provided to RequestCommissioningApproval"); - return; - } +void DeviceManager::HandleCommandResponse(const app::ConcreteCommandPath & path, TLV::TLVReader * data) +{ + ChipLogProgress(NotSpecified, "Command Response received."); - if (value.statusCode != static_cast(Protocols::InteractionModel::Status::Success)) + if (path.mClusterId == CommissionerControl::Id && + path.mCommandId == CommissionerControl::Commands::ReverseOpenCommissioningWindow::Id) { - ChipLogError(NotSpecified, "The server is not ready to begin commissioning the requested device"); - return; + HandleReverseOpenCommissioningWindow(data); } - - // The server is ready to begin commissioning the requested device, request the Commissioner Control Server to begin - // commissioning a previously approved request. - CommissionApprovedRequest(value.requestId, kResponseTimeoutSeconds); } void DeviceManager::OnDeviceRemoved(NodeId deviceId, CHIP_ERROR err) diff --git a/examples/fabric-admin/device_manager/DeviceManager.h b/examples/fabric-admin/device_manager/DeviceManager.h index 454986bd7a40f0..b6c7dc0e657b51 100644 --- a/examples/fabric-admin/device_manager/DeviceManager.h +++ b/examples/fabric-admin/device_manager/DeviceManager.h @@ -148,21 +148,27 @@ class DeviceManager : public PairingDelegate void SubscribeRemoteFabricBridge(); - void StartReverseCommissioning(); - void ReadSupportedDeviceCategories(); - void CommissionApprovedRequest(uint64_t requestId, uint16_t responseTimeoutSeconds); - void HandleAttributeData(const chip::app::ConcreteDataAttributePath & path, chip::TLV::TLVReader * data); void HandleEventData(const chip::app::EventHeader & header, chip::TLV::TLVReader * data); + void HandleCommandResponse(const chip::app::ConcreteCommandPath & path, chip::TLV::TLVReader * data); + void OnDeviceRemoved(chip::NodeId deviceId, CHIP_ERROR err) override; private: friend DeviceManager & DeviceMgr(); + void RequestCommissioningApproval(); + + void HandleCommissioningRequestResult(chip::TLV::TLVReader * data); + + void SendCommissionNodeRequest(uint64_t requestId, uint16_t responseTimeoutSeconds); + + void HandleReverseOpenCommissioningWindow(chip::TLV::TLVReader * data); + static DeviceManager sInstance; chip::NodeId mLastUsedNodeId = 0; diff --git a/examples/fabric-admin/rpc/RpcServer.cpp b/examples/fabric-admin/rpc/RpcServer.cpp index 86d90ad294beb7..f240feda22a2d4 100644 --- a/examples/fabric-admin/rpc/RpcServer.cpp +++ b/examples/fabric-admin/rpc/RpcServer.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #if defined(PW_RPC_FABRIC_ADMIN_SERVICE) && PW_RPC_FABRIC_ADMIN_SERVICE @@ -91,6 +92,45 @@ class FabricAdmin final : public rpc::FabricAdmin, public IcdManager::Delegate return pw::OkStatus(); } + pw::Status CommissionNode(const chip_rpc_DeviceCommissioningInfo & request, pw_protobuf_Empty & response) override + { + char saltHex[Crypto::kSpake2p_Max_PBKDF_Salt_Length * 2 + 1]; + Encoding::BytesToHex(request.salt.bytes, request.salt.size, saltHex, sizeof(saltHex), Encoding::HexFlags::kNullTerminate); + + ChipLogProgress(NotSpecified, "Received CommissionNode request"); + + SetupPayload setupPayload = SetupPayload(); + + setupPayload.setUpPINCode = request.setup_pin; + setupPayload.version = 0; + setupPayload.rendezvousInformation.SetValue(RendezvousInformationFlag::kOnNetwork); + + SetupDiscriminator discriminator{}; + discriminator.SetLongValue(request.discriminator); + setupPayload.discriminator = discriminator; + + char payloadBuffer[kMaxManualCodeLength + 1]; + MutableCharSpan manualCode(payloadBuffer); + + CHIP_ERROR error = ManualSetupPayloadGenerator(setupPayload).payloadDecimalStringRepresentation(manualCode); + if (error == CHIP_NO_ERROR) + { + NodeId nodeId = DeviceMgr().GetNextAvailableNodeId(); + + // After responding with RequestCommissioningApproval to the node where the client initiated the + // RequestCommissioningApproval, you need to wait for it to open a commissioning window on its bridge. + usleep(kCommissionPrepareTimeMs * 1000); + + DeviceMgr().PairRemoteDevice(nodeId, payloadBuffer); + } + else + { + ChipLogError(NotSpecified, "Unable to generate manual code for setup payload: %" CHIP_ERROR_FORMAT, error.Format()); + } + + return pw::OkStatus(); + } + pw::Status KeepActive(const chip_rpc_KeepActiveParameters & request, pw_protobuf_Empty & response) override { ChipLogProgress(NotSpecified, "Received KeepActive request: 0x%lx, %u", request.node_id, request.stay_active_duration_ms); diff --git a/examples/fabric-bridge-app/fabric-bridge-common/BUILD.gn b/examples/fabric-bridge-app/fabric-bridge-common/BUILD.gn index b7b07d3be37bc3..7f2fbcbbfe0556 100644 --- a/examples/fabric-bridge-app/fabric-bridge-common/BUILD.gn +++ b/examples/fabric-bridge-app/fabric-bridge-common/BUILD.gn @@ -45,11 +45,9 @@ source_set("fabric-bridge-lib") { "include/BridgedDeviceBasicInformationImpl.h", "include/BridgedDeviceManager.h", "include/CHIPProjectAppConfig.h", - "include/CommissionerControl.h", "src/BridgedDevice.cpp", "src/BridgedDeviceBasicInformationImpl.cpp", "src/BridgedDeviceManager.cpp", - "src/CommissionerControl.cpp", "src/ZCLCallbacks.cpp", ] diff --git a/examples/fabric-bridge-app/linux/BUILD.gn b/examples/fabric-bridge-app/linux/BUILD.gn index d0f60f30fbb2b9..d0e92a408ee00e 100644 --- a/examples/fabric-bridge-app/linux/BUILD.gn +++ b/examples/fabric-bridge-app/linux/BUILD.gn @@ -33,6 +33,7 @@ if (bridge_enable_pw_rpc) { executable("fabric-bridge-app") { sources = [ "${chip_root}/examples/fabric-bridge-app/fabric-bridge-common/include/CHIPProjectAppConfig.h", + "CommissionerControl.cpp", "main.cpp", ] diff --git a/examples/fabric-bridge-app/fabric-bridge-common/src/CommissionerControl.cpp b/examples/fabric-bridge-app/linux/CommissionerControl.cpp similarity index 70% rename from examples/fabric-bridge-app/fabric-bridge-common/src/CommissionerControl.cpp rename to examples/fabric-bridge-app/linux/CommissionerControl.cpp index 076ced816596d2..9f3180668de42c 100644 --- a/examples/fabric-bridge-app/fabric-bridge-common/src/CommissionerControl.cpp +++ b/examples/fabric-bridge-app/linux/CommissionerControl.cpp @@ -17,17 +17,26 @@ */ #include "CommissionerControl.h" +#include "RpcClient.h" #include #include +#include #include #include +#include using namespace chip; using namespace chip::app; namespace { +// Constants +constexpr uint16_t kDiscriminator = 3840; +constexpr uint16_t kWindowTimeout = 300; +constexpr uint16_t kIteration = 1000; +constexpr uint32_t kSetupPinCode = 20202021; + std::unique_ptr sCommissionerControlDelegate; } // namespace @@ -96,23 +105,43 @@ CHIP_ERROR CommissionerControlDelegate::ValidateCommissionNodeCommand(NodeId cli CHIP_ERROR CommissionerControlDelegate::GetCommissioningWindowParams(CommissioningWindowParams & outParams) { - // TODO: Populate outParams with the required details. - // outParams.commissioningWindowParams.iterations = mIterations; - // outParams.commissioningWindowParams.commissioningTimeout = mCommissioningTimeout; - // outParams.commissioningWindowParams.discriminator = mDiscriminator; - // outParams.commissioningWindowParams.PAKEPasscodeVerifier = mPAKEPasscodeVerifier; - // outParams.commissioningWindowParams.salt = mSalt; + // Populate outParams with the required details. + outParams.iterations = kIteration; + outParams.commissioningTimeout = kWindowTimeout; + outParams.discriminator = kDiscriminator; + + ReturnErrorOnFailure(Crypto::DRBG_get_bytes(mPBKDFSaltBuffer, sizeof(mPBKDFSaltBuffer))); + mPBKDFSalt = ByteSpan(mPBKDFSaltBuffer); + outParams.salt = mPBKDFSalt; - // outParams.ipAddress = mIpAddress; - // outParams.port = mPort; + Crypto::Spake2pVerifier verifier; + uint32_t setupPIN = kSetupPinCode; + ReturnErrorOnFailure(PASESession::GeneratePASEVerifier(verifier, kIteration, mPBKDFSalt, false, setupPIN)); + + MutableByteSpan serializedVerifierSpan(mPAKEPasscodeVerifierBuffer); + ReturnErrorOnFailure(verifier.Serialize(serializedVerifierSpan)); + mPAKEPasscodeVerifier = serializedVerifierSpan; + outParams.PAKEPasscodeVerifier = mPAKEPasscodeVerifier; return CHIP_NO_ERROR; } -CHIP_ERROR CommissionerControlDelegate::ReverseCommissionNode(const CommissioningWindowParams & params, - const Optional & ipAddress, const Optional & port) +CHIP_ERROR CommissionerControlDelegate::HandleCommissionNode(const CommissioningWindowParams & params, + const Optional & ipAddress, const Optional & port) { - return CHIP_NO_ERROR; + ChipLogProgress(NotSpecified, "CommissionerControlDelegate::HandleCommissionNode"); + +#if defined(PW_RPC_FABRIC_BRIDGE_SERVICE) && PW_RPC_FABRIC_BRIDGE_SERVICE + return CommissionNode(Controller::CommissioningWindowPasscodeParams() + .SetSetupPIN(kSetupPinCode) + .SetTimeout(params.commissioningTimeout) + .SetDiscriminator(params.discriminator) + .SetIteration(params.iterations) + .SetSalt(params.salt)); +#else + ChipLogProgress(NotSpecified, "Failed to reverse commission bridge: PW_RPC_FABRIC_BRIDGE_SERVICE not defined"); + return CHIP_ERROR_NOT_IMPLEMENTED; +#endif // defined(PW_RPC_FABRIC_BRIDGE_SERVICE) && PW_RPC_FABRIC_BRIDGE_SERVICE } } // namespace CommissionerControl diff --git a/examples/fabric-bridge-app/linux/RpcClient.cpp b/examples/fabric-bridge-app/linux/RpcClient.cpp index 1260c8744b67f2..b3c82303beb8f5 100644 --- a/examples/fabric-bridge-app/linux/RpcClient.cpp +++ b/examples/fabric-bridge-app/linux/RpcClient.cpp @@ -162,6 +162,31 @@ OpenCommissioningWindow(chip::Controller::CommissioningWindowVerifierParams para return OpenCommissioningWindow(device); } +CHIP_ERROR +CommissionNode(chip::Controller::CommissioningWindowPasscodeParams params) +{ + chip_rpc_DeviceCommissioningInfo device; + device.setup_pin = params.GetSetupPIN(); + device.discriminator = params.GetDiscriminator(); + device.iterations = params.GetIteration(); + + VerifyOrReturnError(params.GetSalt().size() <= sizeof(device.salt.bytes), CHIP_ERROR_BUFFER_TOO_SMALL); + memcpy(device.salt.bytes, params.GetSalt().data(), params.GetSalt().size()); + device.salt.size = static_cast(params.GetSalt().size()); + + // The RPC call is kept alive until it completes. When a response is received, it will be logged by the handler + // function and the call will complete. + auto call = fabricAdminClient.CommissionNode(device, RpcCompletedWithEmptyResponse); + + if (!call.active()) + { + // The RPC call was not sent. This could occur due to, for example, an invalid channel ID. Handle if necessary. + return CHIP_ERROR_INTERNAL; + } + + return WaitForResponse(call); +} + CHIP_ERROR KeepActive(chip::NodeId nodeId, uint32_t stayActiveDurationMs) { chip_rpc_KeepActiveParameters params; diff --git a/examples/fabric-bridge-app/fabric-bridge-common/include/CommissionerControl.h b/examples/fabric-bridge-app/linux/include/CommissionerControl.h similarity index 80% rename from examples/fabric-bridge-app/fabric-bridge-common/include/CommissionerControl.h rename to examples/fabric-bridge-app/linux/include/CommissionerControl.h index b5caa6a2ce1f3d..633be761ba1004 100644 --- a/examples/fabric-bridge-app/fabric-bridge-common/include/CommissionerControl.h +++ b/examples/fabric-bridge-app/linux/include/CommissionerControl.h @@ -32,8 +32,8 @@ class CommissionerControlDelegate : public Delegate CHIP_ERROR HandleCommissioningApprovalRequest(const CommissioningApprovalRequest & request) override; CHIP_ERROR ValidateCommissionNodeCommand(NodeId clientNodeId, uint64_t requestId) override; CHIP_ERROR GetCommissioningWindowParams(CommissioningWindowParams & outParams) override; - CHIP_ERROR ReverseCommissionNode(const CommissioningWindowParams & params, const Optional & ipAddress, - const Optional & port) override; + CHIP_ERROR HandleCommissionNode(const CommissioningWindowParams & params, const Optional & ipAddress, + const Optional & port) override; ~CommissionerControlDelegate() = default; @@ -46,6 +46,12 @@ class CommissionerControlDelegate : public Delegate uint16_t mProductId = 0; char mLabelBuffer[kLabelBufferSize + 1]; Optional mLabel; + + // Parameters needed for non-basic commissioning. + uint8_t mPBKDFSaltBuffer[Crypto::kSpake2p_Max_PBKDF_Salt_Length]; + ByteSpan mPBKDFSalt; + Crypto::Spake2pVerifierSerialized mPAKEPasscodeVerifierBuffer; + ByteSpan mPAKEPasscodeVerifier; }; } // namespace CommissionerControl diff --git a/examples/fabric-bridge-app/linux/include/RpcClient.h b/examples/fabric-bridge-app/linux/include/RpcClient.h index 6913a66d8c24a1..87ccba24f645dc 100644 --- a/examples/fabric-bridge-app/linux/include/RpcClient.h +++ b/examples/fabric-bridge-app/linux/include/RpcClient.h @@ -57,4 +57,15 @@ OpenCommissioningWindow(chip::Controller::CommissioningWindowPasscodeParams para CHIP_ERROR OpenCommissioningWindow(chip::Controller::CommissioningWindowVerifierParams params); +/** + * Commission a node using the specified parameters. + * + * @param params Params for commissioning the device using passcode. + * @return CHIP_ERROR An error code indicating the success or failure of the operation. + * - CHIP_NO_ERROR: The RPC command was successfully sent. + * - CHIP_ERROR_INTERNAL: An internal error occurred. + */ +CHIP_ERROR +CommissionNode(chip::Controller::CommissioningWindowPasscodeParams params); + CHIP_ERROR KeepActive(chip::NodeId nodeId, uint32_t stayActiveDurationMs); diff --git a/examples/fabric-bridge-app/linux/main.cpp b/examples/fabric-bridge-app/linux/main.cpp index 57907db8872b0a..3b6502421045f8 100644 --- a/examples/fabric-bridge-app/linux/main.cpp +++ b/examples/fabric-bridge-app/linux/main.cpp @@ -82,7 +82,7 @@ void BridgePollingThread() #if defined(PW_RPC_FABRIC_BRIDGE_SERVICE) && PW_RPC_FABRIC_BRIDGE_SERVICE else if (ch == 'o') { - CHIP_ERROR err = OpenCommissioningWindow(chip::Controller::CommissioningWindowPasscodeParams() + CHIP_ERROR err = OpenCommissioningWindow(Controller::CommissioningWindowPasscodeParams() .SetNodeId(0x1234) .SetTimeout(300) .SetDiscriminator(3840) @@ -157,7 +157,7 @@ void AdministratorCommissioningCommandHandler::InvokeCommand(HandlerContext & ha // TODO: issues:#33784, need to make OpenCommissioningWindow synchronous if (device != nullptr && - OpenCommissioningWindow(chip::Controller::CommissioningWindowVerifierParams() + OpenCommissioningWindow(Controller::CommissioningWindowVerifierParams() .SetNodeId(device->GetNodeId()) .SetTimeout(commandData.commissioningTimeout) .SetDiscriminator(commandData.discriminator) diff --git a/src/app/clusters/commissioner-control-server/commissioner-control-server.cpp b/src/app/clusters/commissioner-control-server/commissioner-control-server.cpp index d8a655f6afb241..4df397326894ed 100644 --- a/src/app/clusters/commissioner-control-server/commissioner-control-server.cpp +++ b/src/app/clusters/commissioner-control-server/commissioner-control-server.cpp @@ -71,15 +71,15 @@ void RunDeferredCommissionNode(intptr_t commandArg) if (delegate != nullptr) { - CHIP_ERROR err = delegate->ReverseCommissionNode(info->params, info->ipAddress.GetIPAddress(), info->port); + CHIP_ERROR err = delegate->HandleCommissionNode(info->params, info->ipAddress.GetIPAddress(), info->port); if (err != CHIP_NO_ERROR) { - ChipLogError(Zcl, "ReverseCommissionNode error: %" CHIP_ERROR_FORMAT, err.Format()); + ChipLogError(Zcl, "HandleCommissionNode error: %" CHIP_ERROR_FORMAT, err.Format()); } } else { - ChipLogError(Zcl, "No delegate available for ReverseCommissionNode"); + ChipLogError(Zcl, "No delegate available for HandleCommissionNode"); } delete info; diff --git a/src/app/clusters/commissioner-control-server/commissioner-control-server.h b/src/app/clusters/commissioner-control-server/commissioner-control-server.h index 5e2422f5ebe018..60a4e81a93c3af 100644 --- a/src/app/clusters/commissioner-control-server/commissioner-control-server.h +++ b/src/app/clusters/commissioner-control-server/commissioner-control-server.h @@ -101,9 +101,6 @@ class Delegate /** * @brief Validate a commission node command. * - * This command is sent by a client to request that the server begins commissioning a previously - * approved request. - * * The server SHALL return FAILURE if the CommissionNode command is not sent from the same * NodeId as the RequestCommissioningApproval or if the provided RequestId to CommissionNode * does not match the value provided to RequestCommissioningApproval. @@ -128,19 +125,17 @@ class Delegate virtual CHIP_ERROR GetCommissioningWindowParams(CommissioningWindowParams & outParams) = 0; /** - * @brief Reverse the commission node process. + * @brief Handle a commission node request. * - * When received within the timeout specified by CommissionNode, the client SHALL open a - * commissioning window on the node which the client called RequestCommissioningApproval to - * have commissioned. + * Commission a node specified by the previously approved request. * * @param params The parameters for the commissioning window. * @param ipAddress Optional IP address for the commissioning window. * @param port Optional port for the commissioning window. * @return CHIP_ERROR indicating the success or failure of the operation. */ - virtual CHIP_ERROR ReverseCommissionNode(const CommissioningWindowParams & params, const Optional & ipAddress, - const Optional & port) = 0; + virtual CHIP_ERROR HandleCommissionNode(const CommissioningWindowParams & params, const Optional & ipAddress, + const Optional & port) = 0; virtual ~Delegate() = default; };