Skip to content

Commit

Permalink
Update src/controller/SetUpCodePairer to timeout after a certain amou…
Browse files Browse the repository at this point in the history
…nt of time
  • Loading branch information
vivien-apple committed Mar 30, 2022
1 parent 7712743 commit 6358be1
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
13 changes: 13 additions & 0 deletions src/app/tests/suites/TestMultiAdmin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,19 @@ tests:
- name: "nodeId"
value: nodeId

- label: "Commission from alpha when the commissioning window is not opened"
identity: "alpha"
cluster: "CommissionerCommands"
command: "PairWithQRCode"
arguments:
values:
- name: "nodeId"
value: nodeIdForDuplicateCommissioning
- name: "payload"
value: payload
response:
error: FAILURE

- label: "Open Commissioning Window from alpha"
cluster: "AdministratorCommissioning"
command: "OpenBasicCommissioningWindow"
Expand Down
7 changes: 5 additions & 2 deletions src/controller/CHIPDeviceController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,13 +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);
return PairDevice(remoteDeviceId, setUpCode);
}

CHIP_ERROR DeviceCommissioner::PairDevice(NodeId remoteDeviceId, const char * setUpCode)
{
MATTER_TRACE_EVENT_SCOPE("PairDevice", "DeviceCommissioner");
return mSetUpCodePairer.PairDevice(remoteDeviceId, setUpCode, SetupCodePairerBehaviour::kCommission);
ReturnErrorOnFailure(mSetUpCodePairer.PairDevice(remoteDeviceId, setUpCode, SetupCodePairerBehaviour::kCommission));

return mSystemState->SystemLayer()->StartTimer(chip::System::Clock::Milliseconds32(kSessionEstablishmentTimeout),
mSetUpCodePairer.OnSessionEstablishmentTimeoutCallback, &mSetUpCodePairer);
}

CHIP_ERROR DeviceCommissioner::PairDevice(NodeId remoteDeviceId, RendezvousParameters & params)
Expand Down
9 changes: 9 additions & 0 deletions src/controller/SetUpCodePairer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,5 +202,14 @@ void SetUpCodePairer::NotifyCommissionableDeviceDiscovered(const Dnssd::Discover
OnDeviceDiscovered(params);
}

void SetUpCodePairer::OnSessionEstablishmentTimeoutCallback(System::Layer * layer, void * context)
{
SetUpCodePairer * pairer = static_cast<SetUpCodePairer *>(context);
LogErrorOnFailure(pairer->StopConnectOverBle());
LogErrorOnFailure(pairer->StopConnectOverIP());
LogErrorOnFailure(pairer->StopConnectOverSoftAP());
pairer->mCommissioner->OnSessionEstablishmentError(CHIP_ERROR_TIMEOUT);
}

} // namespace Controller
} // namespace chip
2 changes: 2 additions & 0 deletions src/controller/SetUpCodePairer.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ class DLL_EXPORT SetUpCodePairer
void SetBleLayer(Ble::BleLayer * bleLayer) { mBleLayer = bleLayer; };
#endif // CONFIG_NETWORK_LAYER_BLE

static void OnSessionEstablishmentTimeoutCallback(System::Layer * layer, void * context);

private:
CHIP_ERROR Connect(SetupPayload & paload);
CHIP_ERROR StartDiscoverOverBle(SetupPayload & payload);
Expand Down

0 comments on commit 6358be1

Please sign in to comment.