Skip to content

Commit

Permalink
Do not start the PASE Session establishement before device scan succe…
Browse files Browse the repository at this point in the history
…eds (#23638)
  • Loading branch information
vivien-apple authored and pull[bot] committed Nov 6, 2023
1 parent 37308fe commit b2a2516
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
40 changes: 39 additions & 1 deletion src/controller/CHIPDeviceController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -703,9 +703,15 @@ CHIP_ERROR DeviceCommissioner::EstablishPASEConnection(NodeId remoteDeviceId, Re
}
else if (params.HasDiscriminator())
{
// The RendezvousParameters argument needs to be recovered if the search succeed, so save them
// for later.
mRendezvousParametersForDeviceDiscoveredOverBle = params;

SetupDiscriminator discriminator;
discriminator.SetLongValue(params.GetDiscriminator());
SuccessOrExit(err = mSystemState->BleLayer()->NewBleConnectionByDiscriminator(discriminator));
SuccessOrExit(err = mSystemState->BleLayer()->NewBleConnectionByDiscriminator(
discriminator, this, OnDiscoveredDeviceOverBleSuccess, OnDiscoveredDeviceOverBleError));
ExitNow(CHIP_NO_ERROR);
}
else
{
Expand Down Expand Up @@ -740,6 +746,38 @@ CHIP_ERROR DeviceCommissioner::EstablishPASEConnection(NodeId remoteDeviceId, Re
return err;
}

#if CONFIG_NETWORK_LAYER_BLE
void DeviceCommissioner::OnDiscoveredDeviceOverBleSuccess(void * appState, BLE_CONNECTION_OBJECT connObj)
{
auto self = static_cast<DeviceCommissioner *>(appState);
auto device = self->mDeviceInPASEEstablishment;

if (nullptr != device && device->GetDeviceTransportType() == Transport::Type::kBle)
{
auto remoteId = device->GetDeviceId();

auto params = self->mRendezvousParametersForDeviceDiscoveredOverBle;
params.SetConnectionObject(connObj);
self->mRendezvousParametersForDeviceDiscoveredOverBle = RendezvousParameters();

self->ReleaseCommissioneeDevice(device);
LogErrorOnFailure(self->EstablishPASEConnection(remoteId, params));
}
}

void DeviceCommissioner::OnDiscoveredDeviceOverBleError(void * appState, CHIP_ERROR err)
{
auto self = static_cast<DeviceCommissioner *>(appState);
auto device = self->mDeviceInPASEEstablishment;

if (nullptr != device && device->GetDeviceTransportType() == Transport::Type::kBle)
{
self->ReleaseCommissioneeDevice(device);
self->mRendezvousParametersForDeviceDiscoveredOverBle = RendezvousParameters();
}
}
#endif // CONFIG_NETWORK_LAYER_BLE

CHIP_ERROR DeviceCommissioner::Commission(NodeId remoteDeviceId, CommissioningParameters & params)
{
if (mDefaultCommissioner == nullptr)
Expand Down
6 changes: 6 additions & 0 deletions src/controller/CHIPDeviceController.h
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,12 @@ class DLL_EXPORT DeviceCommissioner : public DeviceController,
uint16_t mUdcListenPort = CHIP_UDC_PORT;
#endif // CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY

#if CONFIG_NETWORK_LAYER_BLE
static void OnDiscoveredDeviceOverBleSuccess(void * appState, BLE_CONNECTION_OBJECT connObj);
static void OnDiscoveredDeviceOverBleError(void * appState, CHIP_ERROR err);
RendezvousParameters mRendezvousParametersForDeviceDiscoveredOverBle;
#endif

CHIP_ERROR LoadKeyId(PersistentStorageDelegate * delegate, uint16_t & out);

/* This function sends a Device Attestation Certificate chain request to the device.
Expand Down

0 comments on commit b2a2516

Please sign in to comment.