Skip to content

Commit

Permalink
Handle StopPairing more cleanly in DeviceController (#28939)
Browse files Browse the repository at this point in the history
* 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".

* Comment typo

Co-authored-by: Boris Zbarsky <bzbarsky@apple.com>

---------

Co-authored-by: Boris Zbarsky <bzbarsky@apple.com>
  • Loading branch information
ksperling-apple and bzbarsky-apple authored Aug 30, 2023
1 parent 02910be commit 42681a2
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/controller/CHIPDeviceController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 42681a2

Please sign in to comment.