diff --git a/src/controller/CHIPDeviceController.cpp b/src/controller/CHIPDeviceController.cpp index 9f0548a468814a..77ed99b600f00a 100644 --- a/src/controller/CHIPDeviceController.cpp +++ b/src/controller/CHIPDeviceController.cpp @@ -1588,14 +1588,6 @@ void BasicFailure(void * context, uint8_t status) #if CHIP_DEVICE_CONFIG_ENABLE_MDNS void DeviceCommissioner::OnNodeIdResolved(const chip::Mdns::ResolvedNodeData & nodeData) { - if (mDeviceBeingPaired < kNumMaxActiveDevices) - { - Device * device = &mActiveDevices[mDeviceBeingPaired]; - if (device->GetDeviceId() == nodeData.mPeerId.GetNodeId() && mCommissioningStage == CommissioningStage::kFindOperational) - { - AdvanceCommissioningStage(CHIP_NO_ERROR); - } - } DeviceController::OnNodeIdResolved(nodeData); OperationalDiscoveryComplete(nodeData.mPeerId.GetNodeId()); } @@ -1619,6 +1611,16 @@ void DeviceCommissioner::OnDeviceConnectedFn(void * context, Device * device) { DeviceCommissioner * commissioner = reinterpret_cast(context); VerifyOrReturn(commissioner != nullptr, ChipLogProgress(Controller, "Device connected callback with null context. Ignoring")); + + if (commissioner->mDeviceBeingPaired < kNumMaxActiveDevices) + { + Device * deviceBeingPaired = &commissioner->mActiveDevices[commissioner->mDeviceBeingPaired]; + if (device == deviceBeingPaired && commissioner->mCommissioningStage == CommissioningStage::kFindOperational) + { + commissioner->AdvanceCommissioningStage(CHIP_NO_ERROR); + } + } + VerifyOrReturn(commissioner->mPairingDelegate != nullptr, ChipLogProgress(Controller, "Device connected callback with null pairing delegate. Ignoring")); commissioner->mPairingDelegate->OnCommissioningComplete(device->GetDeviceId(), CHIP_NO_ERROR);