@@ -139,13 +139,13 @@ CHIP_ERROR BLEManagerCommon::_Init()
139
139
{
140
140
CHIP_ERROR err = CHIP_NO_ERROR;
141
141
EventBits_t eventBits;
142
- mWriteNotificationHandle [ mWriteHandleSize ++ ] = (uint16_t ) value_chipoble_rx;
142
+ uint16_t attChipRxHandle[ 1 ] = { (uint16_t ) value_chipoble_rx } ;
143
143
144
144
#if CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING
145
- mReadNotificationHandle [ mReadHandleSize ++ ] = (uint16_t ) value_chipoble_c3;
145
+ uint16_t attChipC3Handle[ 1 ] = { (uint16_t ) value_chipoble_c3 } ;
146
146
#endif
147
147
148
- mServiceMode = kCHIPoBLE_Enabled ;
148
+ mServiceMode = ConnectivityManager:: kCHIPoBLEServiceMode_Enabled ;
149
149
150
150
// Check if BLE stack is initialized
151
151
VerifyOrExit (!mFlags .Has (Flags::kK32WBLEStackInitialized ), err = CHIP_ERROR_INCORRECT_STATE);
@@ -196,9 +196,9 @@ CHIP_ERROR BLEManagerCommon::_Init()
196
196
PWR_ChangeDeepSleepMode (cPWR_PowerDown_RamRet);
197
197
#endif
198
198
199
- GattServer_RegisterHandlesForWriteNotifications (mWriteHandleSize , mWriteNotificationHandle );
199
+ GattServer_RegisterHandlesForWriteNotifications (1 , attChipRxHandle );
200
200
#if CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING
201
- VerifyOrExit (GattServer_RegisterHandlesForReadNotifications (mReadHandleSize , mReadNotificationHandle ) == gBleSuccess_c ,
201
+ VerifyOrExit (GattServer_RegisterHandlesForReadNotifications (1 , attChipC3Handle ) == gBleSuccess_c ,
202
202
err = CHIP_ERROR_INCORRECT_STATE);
203
203
#endif
204
204
@@ -221,7 +221,7 @@ CHIP_ERROR BLEManagerCommon::_Init()
221
221
222
222
uint16_t BLEManagerCommon::_NumConnections (void )
223
223
{
224
- return mDeviceIds . size ( );
224
+ return static_cast < uint16_t >( mDeviceConnected == true );
225
225
}
226
226
227
227
bool BLEManagerCommon::_IsAdvertisingEnabled (void )
@@ -238,8 +238,7 @@ CHIP_ERROR BLEManagerCommon::_SetAdvertisingEnabled(bool val)
238
238
{
239
239
CHIP_ERROR err = CHIP_NO_ERROR;
240
240
241
- VerifyOrExit ((mServiceMode == kCHIPoBLE_Enabled ) || (mServiceMode == kMultipleBLE_Enabled ),
242
- err = CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE);
241
+ VerifyOrExit (mServiceMode != ConnectivityManager::kCHIPoBLEServiceMode_NotSupported , err = CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE);
243
242
244
243
if (mFlags .Has (Flags::kAdvertisingEnabled ) != val)
245
244
{
@@ -285,6 +284,10 @@ CHIP_ERROR BLEManagerCommon::_GetDeviceName(char * buf, size_t bufSize)
285
284
286
285
CHIP_ERROR BLEManagerCommon::_SetDeviceName (const char * deviceName)
287
286
{
287
+ if (mServiceMode == ConnectivityManager::kCHIPoBLEServiceMode_NotSupported )
288
+ {
289
+ return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
290
+ }
288
291
if (deviceName != NULL && deviceName[0 ] != 0 )
289
292
{
290
293
if (strlen (deviceName) >= kMaxDeviceNameLength )
@@ -764,7 +767,7 @@ CHIP_ERROR BLEManagerCommon::StopAdvertising(void)
764
767
mFlags .Clear (Flags::kAdvertising );
765
768
mFlags .Clear (Flags::kRestartAdvertising );
766
769
767
- if (mDeviceIds . size () )
770
+ if (! mDeviceConnected )
768
771
{
769
772
ble_err_t err = blekw_stop_advertising ();
770
773
VerifyOrReturnError (err == BLE_OK, CHIP_ERROR_INCORRECT_STATE);
@@ -791,7 +794,7 @@ void BLEManagerCommon::DriveBLEState(void)
791
794
VerifyOrExit (mFlags .Has (Flags::kK32WBLEStackInitialized ), err = CHIP_ERROR_INCORRECT_STATE);
792
795
793
796
// Start advertising if needed...
794
- if ((( mServiceMode == kCHIPoBLE_Enabled ) || ( mServiceMode == kMultipleBLE_Enabled )) && mFlags .Has (Flags::kAdvertisingEnabled ))
797
+ if (mServiceMode == ConnectivityManager:: kCHIPoBLEServiceMode_Enabled && mFlags .Has (Flags::kAdvertisingEnabled ))
795
798
{
796
799
// Start/re-start advertising if not already started, or if there is a pending change
797
800
// to the advertising configuration.
@@ -814,7 +817,7 @@ void BLEManagerCommon::DriveBLEState(void)
814
817
if (err != CHIP_NO_ERROR)
815
818
{
816
819
ChipLogError (DeviceLayer, " Disabling CHIPoBLE service due to error: %s" , ErrorStr (err));
817
- mServiceMode = kCHIPoBLE_Disabled ;
820
+ mServiceMode = ConnectivityManager:: kCHIPoBLEServiceMode_Disabled ;
818
821
}
819
822
}
820
823
@@ -860,9 +863,7 @@ void BLEManagerCommon::DoBleProcessing(void)
860
863
}
861
864
else if (msg->type == BLE_KW_MSG_MTU_CHANGED)
862
865
{
863
- if (mServiceMode == kCHIPoBLE_Enabled )
864
- blekw_start_connection_timeout ();
865
-
866
+ blekw_start_connection_timeout ();
866
867
ChipLogProgress (DeviceLayer, " BLE MTU size has been changed to %d." , msg->data .u16 );
867
868
}
868
869
else if (msg->type == BLE_KW_MSG_ATT_WRITTEN || msg->type == BLE_KW_MSG_ATT_LONG_WRITTEN ||
@@ -896,32 +897,6 @@ void BLEManagerCommon::RegisterAppCallbacks(BLECallbackDelegate::GapGenericCallb
896
897
callbackDelegate.gattCallback = gattCallback;
897
898
}
898
899
899
- CHIP_ERROR BLEManagerCommon::AddWriteNotificationHandle (uint16_t name)
900
- {
901
- CHIP_ERROR err = CHIP_NO_ERROR;
902
-
903
- // This function should be called before calling BLEManagerCommon::_Init
904
- VerifyOrExit (!mFlags .Has (Flags::kK32WBLEStackInitialized ), err = CHIP_ERROR_INCORRECT_STATE);
905
-
906
- mWriteNotificationHandle [mWriteHandleSize ++] = name;
907
-
908
- exit :
909
- return err;
910
- }
911
-
912
- CHIP_ERROR BLEManagerCommon::AddReadNotificationHandle (uint16_t name)
913
- {
914
- CHIP_ERROR err = CHIP_NO_ERROR;
915
-
916
- // This function should be called before calling BLEManagerCommon::_Init
917
- VerifyOrExit (!mFlags .Has (Flags::kK32WBLEStackInitialized ), err = CHIP_ERROR_INCORRECT_STATE);
918
-
919
- mReadNotificationHandle [mReadHandleSize ++] = name;
920
-
921
- exit :
922
- return err;
923
- }
924
-
925
900
void BLEManagerCommon::HandleConnectEvent (blekw_msg_t * msg)
926
901
{
927
902
uint8_t deviceId = msg->data .u8 ;
@@ -931,17 +906,10 @@ void BLEManagerCommon::HandleConnectEvent(blekw_msg_t * msg)
931
906
PWR_DisallowDeviceToSleep ();
932
907
#endif
933
908
934
- mDeviceIds .insert (deviceId);
935
-
936
- if (mServiceMode == kCHIPoBLE_Enabled )
937
- blekw_start_connection_timeout ();
938
-
939
- if (mServiceMode == kMultipleBLE_Enabled )
940
- {
941
- _SetAdvertisingEnabled (false );
942
- mServiceMode = kMultipleBLE_Disabled ;
943
- }
909
+ mDeviceId = deviceId;
910
+ mDeviceConnected = true ;
944
911
912
+ blekw_start_connection_timeout ();
945
913
PlatformMgr ().ScheduleWork (DriveBLEState, 0 );
946
914
}
947
915
@@ -954,7 +922,7 @@ void BLEManagerCommon::HandleConnectionCloseEvent(blekw_msg_t * msg)
954
922
PWR_AllowDeviceToSleep ();
955
923
#endif
956
924
957
- mDeviceIds . erase (deviceId) ;
925
+ mDeviceConnected = false ;
958
926
959
927
ChipDeviceEvent event;
960
928
event.Type = DeviceEventType::kCHIPoBLEConnectionClosed ;
@@ -978,8 +946,7 @@ void BLEManagerCommon::HandleWriteEvent(blekw_msg_t * msg)
978
946
ChipLogProgress (DeviceLayer, " Attribute write request(device: %d,handle: %d)." , att_wr_data->device_id , att_wr_data->handle );
979
947
#endif
980
948
981
- if (mServiceMode == kCHIPoBLE_Enabled )
982
- blekw_start_connection_timeout ();
949
+ blekw_start_connection_timeout ();
983
950
984
951
if (value_chipoble_rx == att_wr_data->handle )
985
952
{
@@ -1080,12 +1047,9 @@ void BLEManagerCommon::HandleForceDisconnect()
1080
1047
ChipLogProgress (DeviceLayer, " BLE connection timeout: Forcing disconnection." );
1081
1048
1082
1049
/* Set the advertising parameters */
1083
- for ( auto & id : mDeviceIds )
1050
+ if ( Gap_Disconnect ( mDeviceId ) != gBleSuccess_c )
1084
1051
{
1085
- if (Gap_Disconnect (id) != gBleSuccess_c )
1086
- {
1087
- ChipLogProgress (DeviceLayer, " Gap_Disconnect() failed." );
1088
- }
1052
+ ChipLogProgress (DeviceLayer, " Gap_Disconnect() failed." );
1089
1053
}
1090
1054
1091
1055
#if defined(chip_with_low_power) && (chip_with_low_power == 1)
0 commit comments