Skip to content

Commit

Permalink
[SetUpCodePairer] Only search on network if no credentials are provid…
Browse files Browse the repository at this point in the history
…ed to chip-tool pairing code commands
  • Loading branch information
vivien-apple committed Aug 23, 2022
1 parent 48f87f3 commit a49de67
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
11 changes: 10 additions & 1 deletion src/controller/CHIPDeviceController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,16 @@ CHIP_ERROR DeviceCommissioner::PairDevice(NodeId remoteDeviceId, const char * se
return CHIP_ERROR_INCORRECT_STATE;
}
ReturnErrorOnFailure(mDefaultCommissioner->SetCommissioningParameters(params));
return mSetUpCodePairer.PairDevice(remoteDeviceId, setUpCode, SetupCodePairerBehaviour::kCommission);

auto threadCredentials = params.GetThreadOperationalDataset();
auto wiFiCredentials = params.GetWiFiCredentials();
bool hasCredentials = threadCredentials.HasValue() || wiFiCredentials.HasValue();

// If there is no network credentials, we assume that the pairing command as been issued to pair with a
// device that is already on the network.
auto pairerBehaviour = hasCredentials ? SetupCodePairerBehaviour::kCommission : SetupCodePairerBehaviour::kCommissionOnNetwork;

return mSetUpCodePairer.PairDevice(remoteDeviceId, setUpCode, pairerBehaviour);
}

CHIP_ERROR DeviceCommissioner::PairDevice(NodeId remoteDeviceId, const char * setUpCode)
Expand Down
27 changes: 16 additions & 11 deletions src/controller/SetUpCodePairer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,26 @@ CHIP_ERROR SetUpCodePairer::Connect(SetupPayload & payload)
bool isRunning = false;

bool searchOverAll = !payload.rendezvousInformation.HasValue();
if (searchOverAll || payload.rendezvousInformation.Value().Has(RendezvousInformationFlag::kBLE))

if (mConnectionType != SetupCodePairerBehaviour::kCommissionOnNetwork)
{
if (CHIP_NO_ERROR == (err = StartDiscoverOverBle(payload)))
if (searchOverAll || payload.rendezvousInformation.Value().Has(RendezvousInformationFlag::kBLE))
{
isRunning = true;
if (CHIP_NO_ERROR == (err = StartDiscoverOverBle(payload)))
{
isRunning = true;
}
VerifyOrReturnError(searchOverAll || CHIP_NO_ERROR == err || CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE == err, err);
}
VerifyOrReturnError(searchOverAll || CHIP_NO_ERROR == err || CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE == err, err);
}

if (searchOverAll || payload.rendezvousInformation.Value().Has(RendezvousInformationFlag::kSoftAP))
{
if (CHIP_NO_ERROR == (err = StartDiscoverOverSoftAP(payload)))
if (searchOverAll || payload.rendezvousInformation.Value().Has(RendezvousInformationFlag::kSoftAP))
{
isRunning = true;
if (CHIP_NO_ERROR == (err = StartDiscoverOverSoftAP(payload)))
{
isRunning = true;
}
VerifyOrReturnError(searchOverAll || CHIP_NO_ERROR == err || CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE == err, err);
}
VerifyOrReturnError(searchOverAll || CHIP_NO_ERROR == err || CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE == err, err);
}

// We always want to search on network because any node that has already been commissioned will use on-network regardless of the
Expand Down Expand Up @@ -225,7 +229,8 @@ bool SetUpCodePairer::ConnectToDiscoveredDevice()
ExpectPASEEstablishment();

CHIP_ERROR err;
if (mConnectionType == SetupCodePairerBehaviour::kCommission)
if (mConnectionType == SetupCodePairerBehaviour::kCommission ||
mConnectionType == SetupCodePairerBehaviour::kCommissionOnNetwork)
{
err = mCommissioner->PairDevice(mRemoteId, params);
}
Expand Down
1 change: 1 addition & 0 deletions src/controller/SetUpCodePairer.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class DeviceCommissioner;
enum class SetupCodePairerBehaviour : uint8_t
{
kCommission,
kCommissionOnNetwork,
kPaseOnly,
};

Expand Down

0 comments on commit a49de67

Please sign in to comment.