Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SetUpCodePairer] Only search on network if no credentials are provid… #22104

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

@bzbarsky-apple bzbarsky-apple Aug 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/is/are/ and s/as/has/

// 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