diff --git a/src/controller/CHIPDeviceController.cpp b/src/controller/CHIPDeviceController.cpp index 06d33134130ba9..5268b6f6426a0d 100644 --- a/src/controller/CHIPDeviceController.cpp +++ b/src/controller/CHIPDeviceController.cpp @@ -1510,32 +1510,25 @@ void DeviceCommissioner::OnDeviceConnectedFn(void * context, OperationalDevicePr DeviceCommissioner * commissioner = static_cast(context); VerifyOrReturn(commissioner != nullptr, ChipLogProgress(Controller, "Device connected callback with null context. Ignoring")); - if (commissioner->mCommissioningStage == CommissioningStage::kFindOperational) + if (commissioner->mCommissioningStage != CommissioningStage::kFindOperational) { - if (commissioner->mDeviceBeingCommissioned != nullptr && - commissioner->mDeviceBeingCommissioned->GetDeviceId() == device->GetDeviceId() && - commissioner->mCommissioningDelegate != nullptr) - { - CommissioningDelegate::CommissioningReport report; - report.Set(OperationalNodeFoundData(device)); - commissioner->CommissioningStageComplete(CHIP_NO_ERROR, report); - } + // This call is definitely not us finding our commissionee device. + // This is presumably us trying to re-establish CASE on MRP failure. + return; } - else + + if (commissioner->mDeviceBeingCommissioned == nullptr || + commissioner->mDeviceBeingCommissioned->GetDeviceId() != device->GetDeviceId()) { - if (commissioner->mPairingDelegate != nullptr) - { - commissioner->mPairingDelegate->OnPairingComplete(CHIP_NO_ERROR); - } - // Only release the PASE session if we're not commissioning. If we're commissioning, we're going to hold onto that PASE - // session until we send the commissioning complete command just in case it fails and we need to go back to the PASE - // connection to re-setup the network. This is unlikely, given that we just connected over the operational network, but is - // required by the spec. - CommissioneeDeviceProxy * commissionee = commissioner->FindCommissioneeDevice(device->GetDeviceId()); - if (commissionee != nullptr) - { - commissioner->ReleaseCommissioneeDevice(commissionee); - } + // Not the device we are trying to commission. + return; + } + + if (commissioner->mCommissioningDelegate != nullptr) + { + CommissioningDelegate::CommissioningReport report; + report.Set(OperationalNodeFoundData(device)); + commissioner->CommissioningStageComplete(CHIP_NO_ERROR, report); } } @@ -1562,10 +1555,6 @@ void DeviceCommissioner::OnDeviceConnectionFailureFn(void * context, PeerId peer { commissioner->CommissioningStageComplete(error); } - else - { - commissioner->mPairingDelegate->OnPairingComplete(error); - } commissioner->mSystemState->CASESessionMgr()->ReleaseSession(peerId); }