Skip to content

Commit

Permalink
Don't reuse a commissionee device if it has the wrong device id. (#19141
Browse files Browse the repository at this point in the history
)

Found during investigation of
#15409 but there
may be more problems left in that issue.

If we get into EstablishPASEConnection and find an existing
commissionee for the peer address (which is easy for BLE, where the
peer address is basically a singleton), but the device id does not
match the passed-in one, we should not reuse that device.  If we try
to, Commission will fail to find the commissionee device by device id
and fail out.
  • Loading branch information
bzbarsky-apple authored Jun 6, 2022
1 parent 2e9a1cd commit 2d1f8a1
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions src/controller/CHIPDeviceController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,24 +556,31 @@ CHIP_ERROR DeviceCommissioner::EstablishPASEConnection(NodeId remoteDeviceId, Re
current = FindCommissioneeDevice(peerAddress);
if (current != nullptr)
{

if (current->IsSecureConnected())
if (current->GetDeviceId() == remoteDeviceId)
{
if (mPairingDelegate)
// We might be able to just reuse its connection if it has one or is
// working on one.
if (current->IsSecureConnected())
{
// We already have an open secure session to this device, call the callback immediately and early return.
mPairingDelegate->OnPairingComplete(CHIP_NO_ERROR);
if (mPairingDelegate)
{
// We already have an open secure session to this device, call the callback immediately and early return.
mPairingDelegate->OnPairingComplete(CHIP_NO_ERROR);
}
return CHIP_NO_ERROR;
}
if (current->IsSessionSetupInProgress())
{
// We're not connected yet, but we're in the process of connecting. Pairing delegate will get a callback when
// connection completes
return CHIP_NO_ERROR;
}
return CHIP_NO_ERROR;
}
if (current->IsSessionSetupInProgress())
{
// We're not connected yet, but we're in the process of connecting. Pairing delegate will get a callback when
// connection completes
return CHIP_NO_ERROR;
}

// Something has gone strange. Delete the old device, try again.
// Either the consumer wants to assign a different device id to this
// peer address now (so we can't reuse the commissionee device we have
// already) or something has gone strange. Delete the old device, try
// again.
ChipLogError(Controller, "Found unconnected device, removing");
ReleaseCommissioneeDevice(current);
}
Expand Down

0 comments on commit 2d1f8a1

Please sign in to comment.