@@ -167,7 +167,8 @@ CHIP_ERROR BLEManagerImpl::_Init()
167
167
mServiceMode = ConnectivityManager::kCHIPoBLEServiceMode_Enabled ;
168
168
mFlags .ClearAll ().Set (Flags::kAdvertisingEnabled , CHIP_DEVICE_CONFIG_CHIPOBLE_ENABLE_ADVERTISING_AUTOSTART);
169
169
mFlags .Set (Flags::kFastAdvertisingEnabled , true );
170
- mGAPConns = 0 ;
170
+ mMatterConnNum = 0 ;
171
+ mTotalConnNum = 0 ;
171
172
172
173
memset (mSubscribedConns , 0 , sizeof (mSubscribedConns ));
173
174
@@ -493,15 +494,13 @@ CHIP_ERROR BLEManagerImpl::HandleGAPConnect(const ChipDeviceEvent * event)
493
494
if (connEvent->HciResult == BT_HCI_ERR_SUCCESS)
494
495
{
495
496
ChipLogProgress (DeviceLayer, " BLE connection established (ConnId: 0x%02x)" , bt_conn_index (connEvent->BtConn ));
496
- mGAPConns ++;
497
+ mMatterConnNum ++;
497
498
}
498
499
else
499
500
{
500
501
ChipLogError (DeviceLayer, " BLE connection failed (reason: 0x%02x)" , connEvent->HciResult );
501
502
}
502
503
503
- ChipLogProgress (DeviceLayer, " Current number of connections: %u/%u" , NumConnections (), CONFIG_BT_MAX_CONN);
504
-
505
504
mFlags .Set (Flags::kAdvertisingRefreshNeeded );
506
505
PlatformMgr ().ScheduleWork (DriveBLEState, 0 );
507
506
@@ -516,7 +515,7 @@ CHIP_ERROR BLEManagerImpl::HandleGAPDisconnect(const ChipDeviceEvent * event)
516
515
517
516
ChipLogProgress (DeviceLayer, " BLE GAP connection terminated (reason 0x%02x)" , connEvent->HciResult );
518
517
519
- mGAPConns --;
518
+ mMatterConnNum --;
520
519
521
520
// If indications were enabled for this connection, record that they are now disabled and
522
521
// notify the BLE Layer of a disconnect.
@@ -544,8 +543,6 @@ CHIP_ERROR BLEManagerImpl::HandleGAPDisconnect(const ChipDeviceEvent * event)
544
543
// Unref bt_conn before scheduling DriveBLEState.
545
544
bt_conn_unref (connEvent->BtConn );
546
545
547
- ChipLogProgress (DeviceLayer, " Current number of connections: %u/%u" , NumConnections (), CONFIG_BT_MAX_CONN);
548
-
549
546
ChipDeviceEvent disconnectEvent;
550
547
disconnectEvent.Type = DeviceEventType::kCHIPoBLEConnectionClosed ;
551
548
ReturnErrorOnFailure (PlatformMgr ().PostEvent (&disconnectEvent));
@@ -705,7 +702,7 @@ void BLEManagerImpl::_OnPlatformEvent(const ChipDeviceEvent * event)
705
702
706
703
uint16_t BLEManagerImpl::_NumConnections (void )
707
704
{
708
- return mGAPConns ;
705
+ return mMatterConnNum ;
709
706
}
710
707
711
708
bool BLEManagerImpl::CloseConnection (BLE_CONNECTION_OBJECT conId)
@@ -880,9 +877,16 @@ void BLEManagerImpl::HandleTXIndicated(struct bt_conn * conId, bt_gatt_indicate_
880
877
void BLEManagerImpl::HandleConnect (struct bt_conn * conId, uint8_t err)
881
878
{
882
879
ChipDeviceEvent event;
880
+ bt_conn_info bt_info;
883
881
884
882
PlatformMgr ().LockChipStack ();
885
883
884
+ sInstance .mTotalConnNum ++;
885
+ ChipLogProgress (DeviceLayer, " Current number of connections: %u/%u" , sInstance .mTotalConnNum , CONFIG_BT_MAX_CONN);
886
+
887
+ VerifyOrExit (bt_conn_get_info (conId, &bt_info) == 0 , );
888
+ // Drop all callbacks incoming for the role other than peripheral, required by the Matter accessory
889
+ VerifyOrExit (bt_info.role == BT_CONN_ROLE_PERIPHERAL, );
886
890
// Don't handle BLE connecting events when it is not related to CHIPoBLE
887
891
VerifyOrExit (sInstance .mFlags .Has (Flags::kChipoBleGattServiceRegister ), );
888
892
@@ -899,9 +903,16 @@ void BLEManagerImpl::HandleConnect(struct bt_conn * conId, uint8_t err)
899
903
void BLEManagerImpl::HandleDisconnect (struct bt_conn * conId, uint8_t reason)
900
904
{
901
905
ChipDeviceEvent event;
906
+ bt_conn_info bt_info;
902
907
903
908
PlatformMgr ().LockChipStack ();
904
909
910
+ sInstance .mTotalConnNum --;
911
+ ChipLogProgress (DeviceLayer, " Current number of connections: %u/%u" , sInstance .mTotalConnNum , CONFIG_BT_MAX_CONN);
912
+
913
+ VerifyOrExit (bt_conn_get_info (conId, &bt_info) == 0 , );
914
+ // Drop all callbacks incoming for the role other than peripheral, required by the Matter accessory
915
+ VerifyOrExit (bt_info.role == BT_CONN_ROLE_PERIPHERAL, );
905
916
// Don't handle BLE disconnecting events when it is not related to CHIPoBLE
906
917
VerifyOrExit (sInstance .mFlags .Has (Flags::kChipoBleGattServiceRegister ), );
907
918
0 commit comments