From a44237cdffa7ce23fab694b08d6ccbe610781f26 Mon Sep 17 00:00:00 2001 From: Karsten Sperling Date: Tue, 29 Aug 2023 16:04:06 +1200 Subject: [PATCH 1/2] Handle StopPairing more cleanly in DeviceController This ensures the controller is not left in a state where further commissioning operations after a StopPairing call are rejected because pairing is already "in progress". --- src/controller/CHIPDeviceController.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/controller/CHIPDeviceController.cpp b/src/controller/CHIPDeviceController.cpp index ee2c36d8bd761e..dd1e2d0d2dab0a 100644 --- a/src/controller/CHIPDeviceController.cpp +++ b/src/controller/CHIPDeviceController.cpp @@ -918,16 +918,27 @@ CHIP_ERROR DeviceCommissioner::StopPairing(NodeId remoteDeviceId) VerifyOrReturnError(mState == State::Initialized, CHIP_ERROR_INCORRECT_STATE); VerifyOrReturnError(remoteDeviceId != kUndefinedNodeId, CHIP_ERROR_INVALID_ARGUMENT); - bool stopped = mSetUpCodePairer.StopPairing(remoteDeviceId); + ChipLogProgress(Controller, "StopPairing called for node ID 0x" ChipLogFormatX64, ChipLogValueX64(remoteDeviceId)); + // If we're still in the process of discovering the device, just stop the SetupCodePairer + if (mSetUpCodePairer.StopPairing(remoteDeviceId)) + { + return CHIP_NO_ERROR; + } + + // Otherwise we might be pairing and / or commissioning it. CommissioneeDeviceProxy * device = FindCommissioneeDevice(remoteDeviceId); - if (device != nullptr) + VerifyOrReturnError(device != nullptr, CHIP_ERROR_INVALID_DEVICE_DESCRIPTOR); + + if (mDeviceBeingCommissioned == device) + { + CommissioningStageComplete(CHIP_ERROR_CANCELLED); + } + else { ReleaseCommissioneeDevice(device); - stopped = true; } - - return (stopped) ? CHIP_NO_ERROR : CHIP_ERROR_INVALID_DEVICE_DESCRIPTOR; + return CHIP_NO_ERROR; } CHIP_ERROR DeviceCommissioner::UnpairDevice(NodeId remoteDeviceId) From 967a758325fb6d926b13e0da1b943936276b6fe1 Mon Sep 17 00:00:00 2001 From: Karsten Sperling <113487422+ksperling-apple@users.noreply.github.com> Date: Thu, 31 Aug 2023 06:38:45 +1200 Subject: [PATCH 2/2] Comment typo Co-authored-by: Boris Zbarsky --- src/controller/CHIPDeviceController.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controller/CHIPDeviceController.cpp b/src/controller/CHIPDeviceController.cpp index dd1e2d0d2dab0a..3333a6554f3c59 100644 --- a/src/controller/CHIPDeviceController.cpp +++ b/src/controller/CHIPDeviceController.cpp @@ -920,7 +920,7 @@ CHIP_ERROR DeviceCommissioner::StopPairing(NodeId remoteDeviceId) ChipLogProgress(Controller, "StopPairing called for node ID 0x" ChipLogFormatX64, ChipLogValueX64(remoteDeviceId)); - // If we're still in the process of discovering the device, just stop the SetupCodePairer + // If we're still in the process of discovering the device, just stop the SetUpCodePairer if (mSetUpCodePairer.StopPairing(remoteDeviceId)) { return CHIP_NO_ERROR;