BLE_API

Revision:
1180:e11b058d005e
Parent:
1179:4ab722f8dca0
Child:
1182:b70129080ddf
--- a/ble/Gap.h	Wed Apr 06 19:15:30 2016 +0100
+++ b/ble/Gap.h	Wed Apr 06 19:15:32 2016 +0100
@@ -1295,6 +1295,7 @@
         /* Clear Gap state */
         state.advertising = 0;
         state.connected   = 0;
+        connectionCount   = 0;
 
         /* Clear scanning state */
         scanningActive = false;
@@ -1319,6 +1320,7 @@
         _advPayload(),
         _scanningParams(),
         _scanResponse(),
+        connectionCount(0),
         state(),
         scanningActive(false),
         timeoutCallbackChain(),
@@ -1339,13 +1341,22 @@
                                 BLEProtocol::AddressType_t         ownAddrType,
                                 const BLEProtocol::AddressBytes_t  ownAddr,
                                 const ConnectionParams_t          *connectionParams) {
-        state.connected = 1;
+        /* Update Gap state */
+        state.advertising = 0;
+        state.connected   = 1;
+        ++connectionCount;
+
         ConnectionCallbackParams_t callbackParams(handle, role, peerAddrType, peerAddr, ownAddrType, ownAddr, connectionParams);
         connectionCallChain.call(&callbackParams);
     }
 
     void processDisconnectionEvent(Handle_t handle, DisconnectionReason_t reason) {
-        state.connected = 0;
+        /* Update Gap state */
+        --connectionCount;
+        if (!connectionCount) {
+            state.connected = 0;
+        }
+
         DisconnectionCallbackParams_t callbackParams(handle, reason);
         disconnectionCallChain.call(&callbackParams);
     }
@@ -1382,6 +1393,10 @@
     GapScanningParams                _scanningParams;
     GapAdvertisingData               _scanResponse;
 
+    /**
+     * Total number of open connections.
+     */
+    uint8_t                          connectionCount;
     GapState_t                       state;
     bool                             scanningActive;