diff --git a/src/app/server/CommissioningWindowManager.cpp b/src/app/server/CommissioningWindowManager.cpp index 45e333e4a9d7dc..4be5a53112403d 100644 --- a/src/app/server/CommissioningWindowManager.cpp +++ b/src/app/server/CommissioningWindowManager.cpp @@ -95,6 +95,9 @@ void CommissioningWindowManager::OnSessionEstablishmentError(CHIP_ERROR err) mFailedCommissioningAttempts++; ChipLogError(AppServer, "Commissioning failed (attempt %d): %s", mFailedCommissioningAttempts, ErrorStr(err)); +#if CONFIG_NETWORK_LAYER_BLE + mServer->getBleLayerObject()->mBleEndPoint->ReleaseBleConnection(); +#endif if (mFailedCommissioningAttempts < kMaxFailedCommissioningAttempts) { // If the number of commissioning attempts have not exceeded maximum retries, let's reopen diff --git a/src/app/server/Server.cpp b/src/app/server/Server.cpp index 0d41fcba173b04..503cbd317193db 100644 --- a/src/app/server/Server.cpp +++ b/src/app/server/Server.cpp @@ -112,6 +112,9 @@ CHIP_ERROR Server::Init(AppDelegate * delegate, uint16_t secureServicePort, uint #endif ); +#if CONFIG_NETWORK_LAYER_BLE + mBleLayer = DeviceLayer::ConnectivityMgr().GetBleLayer(); +#endif SuccessOrExit(err); err = mSessions.Init(&DeviceLayer::SystemLayer(), &mTransports, &mFabrics, &mMessageCounterManager); diff --git a/src/app/server/Server.h b/src/app/server/Server.h index 752fa471cbff18..e305996179f0a3 100644 --- a/src/app/server/Server.h +++ b/src/app/server/Server.h @@ -71,6 +71,10 @@ class Server : public Messaging::ExchangeDelegate TransportMgrBase & GetTransportManager() { return mTransports; } +#if CONFIG_NETWORK_LAYER_BLE + Ble::BleLayer * getBleLayerObject() { return mBleLayer; } +#endif + CommissioningWindowManager & GetCommissioningWindowManager() { return mCommissioningWindowManager; } void Shutdown(); @@ -113,6 +117,10 @@ class Server : public Messaging::ExchangeDelegate AppDelegate * mAppDelegate = nullptr; +#if CONFIG_NETWORK_LAYER_BLE + Ble::BleLayer * mBleLayer = nullptr; +#endif + ServerTransportMgr mTransports; SessionManager mSessions; CASEServer mCASEServer; diff --git a/src/ble/BLEEndPoint.h b/src/ble/BLEEndPoint.h index 85eb827b2e243a..b36748d3601abf 100644 --- a/src/ble/BLEEndPoint.h +++ b/src/ble/BLEEndPoint.h @@ -107,6 +107,7 @@ class DLL_EXPORT BLEEndPoint bool ConnectionObjectIs(BLE_CONNECTION_OBJECT connObj) { return connObj == mConnObj; } void Close(); void Abort(); + void ReleaseBleConnection(); private: BleLayer * mBle; ///< [READ-ONLY] Pointer to the BleLayer object that owns this object. @@ -223,7 +224,6 @@ class DLL_EXPORT BLEEndPoint // Close functions: void DoCloseCallback(uint8_t state, uint8_t flags, CHIP_ERROR err); void FinalizeClose(uint8_t state, uint8_t flags, CHIP_ERROR err); - void ReleaseBleConnection(); void Free(); void FreeBtpEngine(); diff --git a/src/ble/BleLayer.cpp b/src/ble/BleLayer.cpp index 738f11dd2b077a..2ae6d7fb7dc6e8 100644 --- a/src/ble/BleLayer.cpp +++ b/src/ble/BleLayer.cpp @@ -288,6 +288,7 @@ CHIP_ERROR BleLayer::Init(BlePlatformDelegate * platformDelegate, BleConnectionD #if CHIP_ENABLE_CHIPOBLE_TEST mTestBleEndPoint = NULL; #endif + mBleEndPoint = NULL; return CHIP_NO_ERROR; } @@ -425,6 +426,7 @@ CHIP_ERROR BleLayer::NewBleEndPoint(BLEEndPoint ** retEndPoint, BLE_CONNECTION_O #if CHIP_ENABLE_CHIPOBLE_TEST mTestBleEndPoint = *retEndPoint; #endif + mBleEndPoint = *retEndPoint; return CHIP_NO_ERROR; } diff --git a/src/ble/BleLayer.h b/src/ble/BleLayer.h index 12ef0445c3dce6..26e0507096c9d1 100644 --- a/src/ble/BleLayer.h +++ b/src/ble/BleLayer.h @@ -320,6 +320,8 @@ class DLL_EXPORT BleLayer BLEEndPoint * mTestBleEndPoint; #endif + BLEEndPoint * mBleEndPoint; + private: // Private data members: diff --git a/src/transport/raw/BLE.h b/src/transport/raw/BLE.h index d54ecc2454d586..070b3bf67a72fe 100644 --- a/src/transport/raw/BLE.h +++ b/src/transport/raw/BLE.h @@ -91,6 +91,8 @@ class DLL_EXPORT BLEBase : public Base, public Ble::BleLayerDelegate CHIP_ERROR SetEndPoint(Ble::BLEEndPoint * endPoint) override; + Ble::BLEEndPoint * GetEndPoint() { return mBleEndPoint; } + private: void ClearState();