From cdce7fa7aa60a9f685d42e5d8df8c44b8c14da3d Mon Sep 17 00:00:00 2001 From: Song Guo Date: Tue, 4 Jun 2024 03:43:12 +0000 Subject: [PATCH] Use ScopedNodeId in ICD commissioning callbacks --- .../commands/pairing/PairingCommand.cpp | 14 +++++++------- .../chip-tool/commands/pairing/PairingCommand.h | 4 ++-- .../commands/pairing/PairingCommand.cpp | 16 ++++++++-------- .../commands/pairing/PairingCommand.h | 4 ++-- src/controller/CHIPDeviceController.cpp | 10 ++++++---- src/controller/DevicePairingDelegate.h | 4 ++-- .../java/AndroidDeviceControllerWrapper.cpp | 10 +++++----- .../java/AndroidDeviceControllerWrapper.h | 2 +- ...iceController-ScriptDevicePairingDelegate.cpp | 16 ++++++++-------- ...eviceController-ScriptDevicePairingDelegate.h | 4 ++-- 10 files changed, 43 insertions(+), 41 deletions(-) diff --git a/examples/chip-tool/commands/pairing/PairingCommand.cpp b/examples/chip-tool/commands/pairing/PairingCommand.cpp index 5f6c179779f3c2..76c8ac8a58cc19 100644 --- a/examples/chip-tool/commands/pairing/PairingCommand.cpp +++ b/examples/chip-tool/commands/pairing/PairingCommand.cpp @@ -436,7 +436,7 @@ void PairingCommand::OnReadCommissioningInfo(const Controller::ReadCommissioning info.icd.idleModeDuration, info.icd.activeModeDuration, info.icd.activeModeThreshold); } -void PairingCommand::OnICDRegistrationComplete(NodeId nodeId, uint32_t icdCounter) +void PairingCommand::OnICDRegistrationComplete(ScopedNodeId nodeId, uint32_t icdCounter) { char icdSymmetricKeyHex[chip::Crypto::kAES_CCM128_Key_Length * 2 + 1]; @@ -444,7 +444,7 @@ void PairingCommand::OnICDRegistrationComplete(NodeId nodeId, uint32_t icdCounte sizeof(icdSymmetricKeyHex), chip::Encoding::HexFlags::kNullTerminate); app::ICDClientInfo clientInfo; - clientInfo.peer_node = ScopedNodeId(nodeId, CurrentCommissioner().GetFabricIndex()); + clientInfo.peer_node = nodeId; clientInfo.monitored_subject = mICDMonitoredSubject.Value(); clientInfo.start_icd_counter = icdCounter; @@ -457,7 +457,7 @@ void PairingCommand::OnICDRegistrationComplete(NodeId nodeId, uint32_t icdCounte if (err != CHIP_NO_ERROR) { CHIPCommand::sICDClientStorage.RemoveKey(clientInfo); - ChipLogError(chipTool, "Failed to persist symmetric key for " ChipLogFormatX64 ": %s", ChipLogValueX64(nodeId), + ChipLogError(chipTool, "Failed to persist symmetric key for " ChipLogFormatX64 ": %s", ChipLogValueX64(nodeId.GetNodeId()), err.AsString()); SetCommandExitStatus(err); return; @@ -465,18 +465,18 @@ void PairingCommand::OnICDRegistrationComplete(NodeId nodeId, uint32_t icdCounte mDeviceIsICD = true; - ChipLogProgress(chipTool, "Saved ICD Symmetric key for " ChipLogFormatX64, ChipLogValueX64(nodeId)); + ChipLogProgress(chipTool, "Saved ICD Symmetric key for " ChipLogFormatX64, ChipLogValueX64(nodeId.GetNodeId())); ChipLogProgress(chipTool, "ICD Registration Complete for device " ChipLogFormatX64 " / Check-In NodeID: " ChipLogFormatX64 " / Monitored Subject: " ChipLogFormatX64 " / Symmetric Key: %s / ICDCounter %u", - ChipLogValueX64(nodeId), ChipLogValueX64(mICDCheckInNodeId.Value()), + ChipLogValueX64(nodeId.GetNodeId()), ChipLogValueX64(mICDCheckInNodeId.Value()), ChipLogValueX64(mICDMonitoredSubject.Value()), icdSymmetricKeyHex, icdCounter); } -void PairingCommand::OnICDStayActiveComplete(NodeId deviceId, uint32_t promisedActiveDuration) +void PairingCommand::OnICDStayActiveComplete(ScopedNodeId deviceId, uint32_t promisedActiveDuration) { ChipLogProgress(chipTool, "ICD Stay Active Complete for device " ChipLogFormatX64 " / promisedActiveDuration: %u", - ChipLogValueX64(deviceId), promisedActiveDuration); + ChipLogValueX64(deviceId.GetNodeId()), promisedActiveDuration); } void PairingCommand::OnDiscoveredDevice(const chip::Dnssd::CommissionNodeData & nodeData) diff --git a/examples/chip-tool/commands/pairing/PairingCommand.h b/examples/chip-tool/commands/pairing/PairingCommand.h index 99b0fd0c91882e..aaa8dc714e1017 100644 --- a/examples/chip-tool/commands/pairing/PairingCommand.h +++ b/examples/chip-tool/commands/pairing/PairingCommand.h @@ -197,8 +197,8 @@ class PairingCommand : public CHIPCommand, void OnPairingDeleted(CHIP_ERROR error) override; void OnReadCommissioningInfo(const chip::Controller::ReadCommissioningInfo & info) override; void OnCommissioningComplete(NodeId deviceId, CHIP_ERROR error) override; - void OnICDRegistrationComplete(NodeId deviceId, uint32_t icdCounter) override; - void OnICDStayActiveComplete(NodeId deviceId, uint32_t promisedActiveDuration) override; + void OnICDRegistrationComplete(chip::ScopedNodeId deviceId, uint32_t icdCounter) override; + void OnICDStayActiveComplete(chip::ScopedNodeId deviceId, uint32_t promisedActiveDuration) override; /////////// DeviceDiscoveryDelegate Interface ///////// void OnDiscoveredDevice(const chip::Dnssd::CommissionNodeData & nodeData) override; diff --git a/examples/fabric-admin/commands/pairing/PairingCommand.cpp b/examples/fabric-admin/commands/pairing/PairingCommand.cpp index 379b56431379e4..92754c2adaa69a 100644 --- a/examples/fabric-admin/commands/pairing/PairingCommand.cpp +++ b/examples/fabric-admin/commands/pairing/PairingCommand.cpp @@ -436,7 +436,7 @@ void PairingCommand::OnReadCommissioningInfo(const Controller::ReadCommissioning info.icd.idleModeDuration, info.icd.activeModeDuration, info.icd.activeModeThreshold); } -void PairingCommand::OnICDRegistrationComplete(NodeId nodeId, uint32_t icdCounter) +void PairingCommand::OnICDRegistrationComplete(ScopedNodeId nodeId, uint32_t icdCounter) { char icdSymmetricKeyHex[chip::Crypto::kAES_CCM128_Key_Length * 2 + 1]; @@ -444,7 +444,7 @@ void PairingCommand::OnICDRegistrationComplete(NodeId nodeId, uint32_t icdCounte sizeof(icdSymmetricKeyHex), chip::Encoding::HexFlags::kNullTerminate); app::ICDClientInfo clientInfo; - clientInfo.peer_node = ScopedNodeId(nodeId, CurrentCommissioner().GetFabricIndex()); + clientInfo.peer_node = nodeId; clientInfo.monitored_subject = mICDMonitoredSubject.Value(); clientInfo.start_icd_counter = icdCounter; @@ -457,26 +457,26 @@ void PairingCommand::OnICDRegistrationComplete(NodeId nodeId, uint32_t icdCounte if (err != CHIP_NO_ERROR) { CHIPCommand::sICDClientStorage.RemoveKey(clientInfo); - ChipLogError(NotSpecified, "Failed to persist symmetric key for " ChipLogFormatX64 ": %s", ChipLogValueX64(nodeId), - err.AsString()); + ChipLogError(NotSpecified, "Failed to persist symmetric key for " ChipLogFormatX64 ": %s", + ChipLogValueX64(nodeId.GetNodeId()), err.AsString()); SetCommandExitStatus(err); return; } mDeviceIsICD = true; - ChipLogProgress(NotSpecified, "Saved ICD Symmetric key for " ChipLogFormatX64, ChipLogValueX64(nodeId)); + ChipLogProgress(NotSpecified, "Saved ICD Symmetric key for " ChipLogFormatX64, ChipLogValueX64(nodeId.GetNodeId())); ChipLogProgress(NotSpecified, "ICD Registration Complete for device " ChipLogFormatX64 " / Check-In NodeID: " ChipLogFormatX64 " / Monitored Subject: " ChipLogFormatX64 " / Symmetric Key: %s / ICDCounter %u", - ChipLogValueX64(nodeId), ChipLogValueX64(mICDCheckInNodeId.Value()), + ChipLogValueX64(nodeId.GetNodeId()), ChipLogValueX64(mICDCheckInNodeId.Value()), ChipLogValueX64(mICDMonitoredSubject.Value()), icdSymmetricKeyHex, icdCounter); } -void PairingCommand::OnICDStayActiveComplete(NodeId deviceId, uint32_t promisedActiveDuration) +void PairingCommand::OnICDStayActiveComplete(ScopedNodeId deviceId, uint32_t promisedActiveDuration) { ChipLogProgress(NotSpecified, "ICD Stay Active Complete for device " ChipLogFormatX64 " / promisedActiveDuration: %u", - ChipLogValueX64(deviceId), promisedActiveDuration); + ChipLogValueX64(deviceId.GetNodeId()), promisedActiveDuration); } void PairingCommand::OnDiscoveredDevice(const chip::Dnssd::CommissionNodeData & nodeData) diff --git a/examples/fabric-admin/commands/pairing/PairingCommand.h b/examples/fabric-admin/commands/pairing/PairingCommand.h index 8de34a0ba989ed..331d177448aed5 100644 --- a/examples/fabric-admin/commands/pairing/PairingCommand.h +++ b/examples/fabric-admin/commands/pairing/PairingCommand.h @@ -196,8 +196,8 @@ class PairingCommand : public CHIPCommand, void OnPairingDeleted(CHIP_ERROR error) override; void OnReadCommissioningInfo(const chip::Controller::ReadCommissioningInfo & info) override; void OnCommissioningComplete(NodeId deviceId, CHIP_ERROR error) override; - void OnICDRegistrationComplete(NodeId deviceId, uint32_t icdCounter) override; - void OnICDStayActiveComplete(NodeId deviceId, uint32_t promisedActiveDuration) override; + void OnICDRegistrationComplete(chip::ScopedNodeId deviceId, uint32_t icdCounter) override; + void OnICDStayActiveComplete(chip::ScopedNodeId deviceId, uint32_t promisedActiveDuration) override; /////////// DeviceDiscoveryDelegate Interface ///////// void OnDiscoveredDevice(const chip::Dnssd::CommissionNodeData & nodeData) override; diff --git a/src/controller/CHIPDeviceController.cpp b/src/controller/CHIPDeviceController.cpp index 1381ed3381a649..75c95ee20abc06 100644 --- a/src/controller/CHIPDeviceController.cpp +++ b/src/controller/CHIPDeviceController.cpp @@ -1326,8 +1326,8 @@ void DeviceCommissioner::OnICDManagementRegisterClientResponse( if (commissioner->mPairingDelegate != nullptr) { - commissioner->mPairingDelegate->OnICDRegistrationComplete(commissioner->mDeviceBeingCommissioned->GetDeviceId(), - data.ICDCounter); + commissioner->mPairingDelegate->OnICDRegistrationComplete( + ScopedNodeId(commissioner->mDeviceBeingCommissioned->GetDeviceId(), commissioner->GetFabricIndex()), data.ICDCounter); } exit: @@ -1346,8 +1346,10 @@ void DeviceCommissioner::OnICDManagementStayActiveResponse( if (commissioner->mPairingDelegate != nullptr) { - commissioner->mPairingDelegate->OnICDStayActiveComplete(commissioner->mDeviceBeingCommissioned->GetDeviceId(), - data.promisedActiveDuration); + commissioner->mPairingDelegate->OnICDStayActiveComplete( + + ScopedNodeId(commissioner->mDeviceBeingCommissioned->GetDeviceId(), commissioner->GetFabricIndex()), + data.promisedActiveDuration); } exit: diff --git a/src/controller/DevicePairingDelegate.h b/src/controller/DevicePairingDelegate.h index 558a6c16a6bc2e..849df45436d9e8 100644 --- a/src/controller/DevicePairingDelegate.h +++ b/src/controller/DevicePairingDelegate.h @@ -136,7 +136,7 @@ class DLL_EXPORT DevicePairingDelegate * @param[in] icdNodeId The node id of the ICD. * @param[in] icdCounter The ICD Counter received from the device. */ - virtual void OnICDRegistrationComplete(NodeId icdNodeId, uint32_t icdCounter) {} + virtual void OnICDRegistrationComplete(ScopedNodeId icdNodeId, uint32_t icdCounter) {} /** * @brief @@ -147,7 +147,7 @@ class DLL_EXPORT DevicePairingDelegate * @param[in] promisedActiveDurationMsec The actual duration that the ICD server can stay active * from the time it receives the StayActiveRequest command. */ - virtual void OnICDStayActiveComplete(NodeId icdNodeId, uint32_t promisedActiveDurationMsec) {} + virtual void OnICDStayActiveComplete(ScopedNodeId icdNodeId, uint32_t promisedActiveDurationMsec) {} }; } // namespace Controller diff --git a/src/controller/java/AndroidDeviceControllerWrapper.cpp b/src/controller/java/AndroidDeviceControllerWrapper.cpp index 526f6830844f13..bd58be59afebd7 100644 --- a/src/controller/java/AndroidDeviceControllerWrapper.cpp +++ b/src/controller/java/AndroidDeviceControllerWrapper.cpp @@ -994,13 +994,13 @@ void AndroidDeviceControllerWrapper::OnICDRegistrationInfoRequired() env->CallVoidMethod(mJavaObjectRef.ObjectRef(), onICDRegistrationInfoRequiredMethod); } -void AndroidDeviceControllerWrapper::OnICDRegistrationComplete(chip::NodeId icdNodeId, uint32_t icdCounter) +void AndroidDeviceControllerWrapper::OnICDRegistrationComplete(chip::ScopedNodeId icdNodeId, uint32_t icdCounter) { chip::DeviceLayer::StackUnlock unlock; CHIP_ERROR err = CHIP_NO_ERROR; chip::app::ICDClientInfo clientInfo; - clientInfo.peer_node = ScopedNodeId(icdNodeId, Controller()->GetFabricIndex()); + clientInfo.peer_node = icdNodeId; clientInfo.monitored_subject = mAutoCommissioner.GetCommissioningParameters().GetICDMonitoredSubject().Value(); clientInfo.start_icd_counter = icdCounter; @@ -1014,13 +1014,13 @@ void AndroidDeviceControllerWrapper::OnICDRegistrationComplete(chip::NodeId icdN if (err == CHIP_NO_ERROR) { - ChipLogProgress(Controller, "Saved ICD Symmetric key for " ChipLogFormatX64, ChipLogValueX64(icdNodeId)); + ChipLogProgress(Controller, "Saved ICD Symmetric key for " ChipLogFormatX64, ChipLogValueX64(icdNodeId.GetNodeId())); } else { getICDClientStorage()->RemoveKey(clientInfo); - ChipLogError(Controller, "Failed to persist symmetric key for " ChipLogFormatX64 ": %s", ChipLogValueX64(icdNodeId), - err.AsString()); + ChipLogError(Controller, "Failed to persist symmetric key for " ChipLogFormatX64 ": %s", + ChipLogValueX64(icdNodeId.GetNodeId()), err.AsString()); } mDeviceIsICD = true; diff --git a/src/controller/java/AndroidDeviceControllerWrapper.h b/src/controller/java/AndroidDeviceControllerWrapper.h index 1d26d31d112774..02d50499bbbcda 100644 --- a/src/controller/java/AndroidDeviceControllerWrapper.h +++ b/src/controller/java/AndroidDeviceControllerWrapper.h @@ -118,7 +118,7 @@ class AndroidDeviceControllerWrapper : public chip::Controller::DevicePairingDel const chip::app::Clusters::NetworkCommissioning::Commands::ScanNetworksResponse::DecodableType & dataResponse) override; void OnScanNetworksFailure(CHIP_ERROR error) override; void OnICDRegistrationInfoRequired() override; - void OnICDRegistrationComplete(chip::NodeId icdNodeId, uint32_t icdCounter) override; + void OnICDRegistrationComplete(chip::ScopedNodeId icdNodeId, uint32_t icdCounter) override; // PersistentStorageDelegate implementation CHIP_ERROR SyncSetKeyValue(const char * key, const void * value, uint16_t size) override; diff --git a/src/controller/python/ChipDeviceController-ScriptDevicePairingDelegate.cpp b/src/controller/python/ChipDeviceController-ScriptDevicePairingDelegate.cpp index 850490da01aba0..c979e0d9cd77a3 100644 --- a/src/controller/python/ChipDeviceController-ScriptDevicePairingDelegate.cpp +++ b/src/controller/python/ChipDeviceController-ScriptDevicePairingDelegate.cpp @@ -185,10 +185,10 @@ ScriptDevicePairingDelegate::GetOpenWindowCallback(Controller::CommissioningWind return &mOpenWindowCallback; } -void ScriptDevicePairingDelegate::OnICDRegistrationComplete(NodeId nodeId, uint32_t icdCounter) +void ScriptDevicePairingDelegate::OnICDRegistrationComplete(ScopedNodeId nodeId, uint32_t icdCounter) { app::ICDClientInfo clientInfo; - clientInfo.peer_node = ScopedNodeId(nodeId, mFabricIndex); + clientInfo.peer_node = nodeId; clientInfo.monitored_subject = sCommissioningParameters.GetICDMonitoredSubject().Value(); clientInfo.start_icd_counter = icdCounter; @@ -201,23 +201,23 @@ void ScriptDevicePairingDelegate::OnICDRegistrationComplete(NodeId nodeId, uint3 if (err != CHIP_NO_ERROR) { sICDClientStorage.RemoveKey(clientInfo); - ChipLogError(Controller, "Failed to persist symmetric key for " ChipLogFormatX64 ": %s", ChipLogValueX64(nodeId), - err.AsString()); + ChipLogError(Controller, "Failed to persist symmetric key for " ChipLogFormatX64 ": %s", + ChipLogValueX64(nodeId.GetNodeId()), err.AsString()); return; } - ChipLogProgress(Controller, "Saved ICD Symmetric key for " ChipLogFormatX64, ChipLogValueX64(nodeId)); + ChipLogProgress(Controller, "Saved ICD Symmetric key for " ChipLogFormatX64, ChipLogValueX64(nodeId.GetNodeId())); ChipLogProgress(Controller, "ICD Registration Complete for device " ChipLogFormatX64 " / Check-In NodeID: " ChipLogFormatX64 " / Monitored Subject: " ChipLogFormatX64 " / ICDCounter %u", - ChipLogValueX64(nodeId), ChipLogValueX64(sCommissioningParameters.GetICDCheckInNodeId().Value()), + ChipLogValueX64(nodeId.GetNodeId()), ChipLogValueX64(sCommissioningParameters.GetICDCheckInNodeId().Value()), ChipLogValueX64(clientInfo.monitored_subject), icdCounter); } -void ScriptDevicePairingDelegate::OnICDStayActiveComplete(NodeId deviceId, uint32_t promisedActiveDuration) +void ScriptDevicePairingDelegate::OnICDStayActiveComplete(ScopedNodeId deviceId, uint32_t promisedActiveDuration) { ChipLogProgress(Controller, "ICD Stay Active Complete for device " ChipLogFormatX64 " / promisedActiveDuration: %u", - ChipLogValueX64(deviceId), promisedActiveDuration); + ChipLogValueX64(deviceId.GetNodeId()), promisedActiveDuration); } } // namespace Controller diff --git a/src/controller/python/ChipDeviceController-ScriptDevicePairingDelegate.h b/src/controller/python/ChipDeviceController-ScriptDevicePairingDelegate.h index 2617f3fea85852..d6665f8fb2baba 100644 --- a/src/controller/python/ChipDeviceController-ScriptDevicePairingDelegate.h +++ b/src/controller/python/ChipDeviceController-ScriptDevicePairingDelegate.h @@ -69,8 +69,8 @@ class ScriptDevicePairingDelegate final : public Controller::DevicePairingDelega void OnCommissioningFailure(PeerId peerId, CHIP_ERROR error, CommissioningStage stageFailed, Optional additionalErrorInfo) override; void OnCommissioningStatusUpdate(PeerId peerId, CommissioningStage stageCompleted, CHIP_ERROR error) override; - void OnICDRegistrationComplete(NodeId deviceId, uint32_t icdCounter) override; - void OnICDStayActiveComplete(NodeId deviceId, uint32_t promisedActiveDuration) override; + void OnICDRegistrationComplete(ScopedNodeId deviceId, uint32_t icdCounter) override; + void OnICDStayActiveComplete(ScopedNodeId deviceId, uint32_t promisedActiveDuration) override; void OnFabricCheck(NodeId matchingNodeId) override; Callback::Callback * GetOpenWindowCallback(Controller::CommissioningWindowOpener * context);