Skip to content

Commit

Permalink
ESP32: Close active ble connection on PASE session failure. (#9845)
Browse files Browse the repository at this point in the history
  • Loading branch information
sweetymhaiske authored and pull[bot] committed Oct 20, 2021
1 parent e3333c5 commit 6781f3e
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/app/server/CommissioningWindowManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/app/server/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions src/app/server/Server.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/ble/BLEEndPoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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();

Expand Down
2 changes: 2 additions & 0 deletions src/ble/BleLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions src/ble/BleLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,8 @@ class DLL_EXPORT BleLayer
BLEEndPoint * mTestBleEndPoint;
#endif

BLEEndPoint * mBleEndPoint;

private:
// Private data members:

Expand Down
2 changes: 2 additions & 0 deletions src/transport/raw/BLE.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 6781f3e

Please sign in to comment.