From 14027629466171de9f13cebabd204022eeb8e434 Mon Sep 17 00:00:00 2001 From: chrisdecenzo Date: Thu, 24 Feb 2022 17:23:48 -0800 Subject: [PATCH] make sure BLE transport is setup for commissioning --- src/controller/CHIPDeviceController.cpp | 14 ++++++++++++++ src/controller/CHIPDeviceController.h | 9 +++++++++ src/controller/SetUpCodePairer.cpp | 4 ++++ 3 files changed, 27 insertions(+) diff --git a/src/controller/CHIPDeviceController.cpp b/src/controller/CHIPDeviceController.cpp index c7db1e3a4cd035..bc6409c8884e81 100644 --- a/src/controller/CHIPDeviceController.cpp +++ b/src/controller/CHIPDeviceController.cpp @@ -773,6 +773,9 @@ CHIP_ERROR DeviceCommissioner::EstablishPASEConnection(NodeId remoteDeviceId, Re params.GetPeerAddress().GetTransportType() == Transport::Type::kUndefined) { #if CONFIG_NETWORK_LAYER_BLE +#if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE + PrepareBleTransport(); +#endif // CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE if (!params.HasBleLayer()) { params.SetPeerAddress(Transport::PeerAddress::BLE()); @@ -1327,6 +1330,17 @@ CHIP_ERROR DeviceCommissioner::OnOperationalCredentialsProvisioningCompletion(Co } #if CONFIG_NETWORK_LAYER_BLE +#if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE +void DeviceCommissioner::PrepareBleTransport() +{ + Transport::BLEBase transport = mSystemState->TransportMgr()->GetTransport().template GetImplAtIndex<2>(); + if (!transport.IsBleLayerTransportSetToSelf()) + { + transport.SetBleLayerTransportToSelf(); + } +} +#endif // CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE + CHIP_ERROR DeviceCommissioner::CloseBleConnection() { // It is fine since we can only commission one device at the same time. diff --git a/src/controller/CHIPDeviceController.h b/src/controller/CHIPDeviceController.h index 63a04bf9635348..35fdde9d07af5d 100644 --- a/src/controller/CHIPDeviceController.h +++ b/src/controller/CHIPDeviceController.h @@ -596,6 +596,15 @@ class DLL_EXPORT DeviceCommissioner : public DeviceController, CommissioningDelegate::CommissioningReport report = CommissioningDelegate::CommissioningReport()); #if CONFIG_NETWORK_LAYER_BLE +#if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE + /** + * @brief + * Prior to commissioning, the Controller should make sure the BleLayer transport + * is set to the Commissioner transport and not the Server transport. + */ + void PrepareBleTransport(); +#endif // CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE + /** * @brief * Once we have finished all commissioning work, the Controller should close the BLE diff --git a/src/controller/SetUpCodePairer.cpp b/src/controller/SetUpCodePairer.cpp index 6817d2181bf801..05f13b9dcec89c 100644 --- a/src/controller/SetUpCodePairer.cpp +++ b/src/controller/SetUpCodePairer.cpp @@ -85,6 +85,10 @@ CHIP_ERROR SetUpCodePairer::Connect(SetupPayload & payload) CHIP_ERROR SetUpCodePairer::StartDiscoverOverBle(SetupPayload & payload) { #if CONFIG_NETWORK_LAYER_BLE +#if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE + VerifyOrReturnError(mCommissioner != nullptr, CHIP_ERROR_INCORRECT_STATE); + mCommissioner->PrepareBleTransport(); +#endif // CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE VerifyOrReturnError(mBleLayer != nullptr, CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE); return mBleLayer->NewBleConnectionByDiscriminator(payload.discriminator, this, OnDiscoveredDeviceOverBleSuccess, OnDiscoveredDeviceOverBleError);