Skip to content

Commit bc54f3c

Browse files
Revert "[nxp noup][platform][common][ble] Add BLEManagerCommon multiple connections changes"
This reverts commit 5c8bf87.
1 parent 7607450 commit bc54f3c

File tree

2 files changed

+31
-87
lines changed

2 files changed

+31
-87
lines changed

src/platform/nxp/common/ble/BLEManagerCommon.cpp

+22-58
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,13 @@ CHIP_ERROR BLEManagerCommon::_Init()
139139
{
140140
CHIP_ERROR err = CHIP_NO_ERROR;
141141
EventBits_t eventBits;
142-
mWriteNotificationHandle[mWriteHandleSize++] = (uint16_t) value_chipoble_rx;
142+
uint16_t attChipRxHandle[1] = { (uint16_t) value_chipoble_rx };
143143

144144
#if CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING
145-
mReadNotificationHandle[mReadHandleSize++] = (uint16_t) value_chipoble_c3;
145+
uint16_t attChipC3Handle[1] = { (uint16_t) value_chipoble_c3 };
146146
#endif
147147

148-
mServiceMode = kCHIPoBLE_Enabled;
148+
mServiceMode = ConnectivityManager::kCHIPoBLEServiceMode_Enabled;
149149

150150
// Check if BLE stack is initialized
151151
VerifyOrExit(!mFlags.Has(Flags::kK32WBLEStackInitialized), err = CHIP_ERROR_INCORRECT_STATE);
@@ -196,9 +196,9 @@ CHIP_ERROR BLEManagerCommon::_Init()
196196
PWR_ChangeDeepSleepMode(cPWR_PowerDown_RamRet);
197197
#endif
198198

199-
GattServer_RegisterHandlesForWriteNotifications(mWriteHandleSize, mWriteNotificationHandle);
199+
GattServer_RegisterHandlesForWriteNotifications(1, attChipRxHandle);
200200
#if CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING
201-
VerifyOrExit(GattServer_RegisterHandlesForReadNotifications(mReadHandleSize, mReadNotificationHandle) == gBleSuccess_c,
201+
VerifyOrExit(GattServer_RegisterHandlesForReadNotifications(1, attChipC3Handle) == gBleSuccess_c,
202202
err = CHIP_ERROR_INCORRECT_STATE);
203203
#endif
204204

@@ -221,7 +221,7 @@ CHIP_ERROR BLEManagerCommon::_Init()
221221

222222
uint16_t BLEManagerCommon::_NumConnections(void)
223223
{
224-
return mDeviceIds.size();
224+
return static_cast<uint16_t>(mDeviceConnected == true);
225225
}
226226

227227
bool BLEManagerCommon::_IsAdvertisingEnabled(void)
@@ -238,8 +238,7 @@ CHIP_ERROR BLEManagerCommon::_SetAdvertisingEnabled(bool val)
238238
{
239239
CHIP_ERROR err = CHIP_NO_ERROR;
240240

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);
243242

244243
if (mFlags.Has(Flags::kAdvertisingEnabled) != val)
245244
{
@@ -285,6 +284,10 @@ CHIP_ERROR BLEManagerCommon::_GetDeviceName(char * buf, size_t bufSize)
285284

286285
CHIP_ERROR BLEManagerCommon::_SetDeviceName(const char * deviceName)
287286
{
287+
if (mServiceMode == ConnectivityManager::kCHIPoBLEServiceMode_NotSupported)
288+
{
289+
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
290+
}
288291
if (deviceName != NULL && deviceName[0] != 0)
289292
{
290293
if (strlen(deviceName) >= kMaxDeviceNameLength)
@@ -764,7 +767,7 @@ CHIP_ERROR BLEManagerCommon::StopAdvertising(void)
764767
mFlags.Clear(Flags::kAdvertising);
765768
mFlags.Clear(Flags::kRestartAdvertising);
766769

767-
if (mDeviceIds.size())
770+
if (!mDeviceConnected)
768771
{
769772
ble_err_t err = blekw_stop_advertising();
770773
VerifyOrReturnError(err == BLE_OK, CHIP_ERROR_INCORRECT_STATE);
@@ -791,7 +794,7 @@ void BLEManagerCommon::DriveBLEState(void)
791794
VerifyOrExit(mFlags.Has(Flags::kK32WBLEStackInitialized), err = CHIP_ERROR_INCORRECT_STATE);
792795

793796
// 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))
795798
{
796799
// Start/re-start advertising if not already started, or if there is a pending change
797800
// to the advertising configuration.
@@ -814,7 +817,7 @@ void BLEManagerCommon::DriveBLEState(void)
814817
if (err != CHIP_NO_ERROR)
815818
{
816819
ChipLogError(DeviceLayer, "Disabling CHIPoBLE service due to error: %s", ErrorStr(err));
817-
mServiceMode = kCHIPoBLE_Disabled;
820+
mServiceMode = ConnectivityManager::kCHIPoBLEServiceMode_Disabled;
818821
}
819822
}
820823

@@ -860,9 +863,7 @@ void BLEManagerCommon::DoBleProcessing(void)
860863
}
861864
else if (msg->type == BLE_KW_MSG_MTU_CHANGED)
862865
{
863-
if (mServiceMode == kCHIPoBLE_Enabled)
864-
blekw_start_connection_timeout();
865-
866+
blekw_start_connection_timeout();
866867
ChipLogProgress(DeviceLayer, "BLE MTU size has been changed to %d.", msg->data.u16);
867868
}
868869
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
896897
callbackDelegate.gattCallback = gattCallback;
897898
}
898899

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-
925900
void BLEManagerCommon::HandleConnectEvent(blekw_msg_t * msg)
926901
{
927902
uint8_t deviceId = msg->data.u8;
@@ -931,17 +906,10 @@ void BLEManagerCommon::HandleConnectEvent(blekw_msg_t * msg)
931906
PWR_DisallowDeviceToSleep();
932907
#endif
933908

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;
944911

912+
blekw_start_connection_timeout();
945913
PlatformMgr().ScheduleWork(DriveBLEState, 0);
946914
}
947915

@@ -954,7 +922,7 @@ void BLEManagerCommon::HandleConnectionCloseEvent(blekw_msg_t * msg)
954922
PWR_AllowDeviceToSleep();
955923
#endif
956924

957-
mDeviceIds.erase(deviceId);
925+
mDeviceConnected = false;
958926

959927
ChipDeviceEvent event;
960928
event.Type = DeviceEventType::kCHIPoBLEConnectionClosed;
@@ -978,8 +946,7 @@ void BLEManagerCommon::HandleWriteEvent(blekw_msg_t * msg)
978946
ChipLogProgress(DeviceLayer, "Attribute write request(device: %d,handle: %d).", att_wr_data->device_id, att_wr_data->handle);
979947
#endif
980948

981-
if (mServiceMode == kCHIPoBLE_Enabled)
982-
blekw_start_connection_timeout();
949+
blekw_start_connection_timeout();
983950

984951
if (value_chipoble_rx == att_wr_data->handle)
985952
{
@@ -1080,12 +1047,9 @@ void BLEManagerCommon::HandleForceDisconnect()
10801047
ChipLogProgress(DeviceLayer, "BLE connection timeout: Forcing disconnection.");
10811048

10821049
/* Set the advertising parameters */
1083-
for (auto & id : mDeviceIds)
1050+
if (Gap_Disconnect(mDeviceId) != gBleSuccess_c)
10841051
{
1085-
if (Gap_Disconnect(id) != gBleSuccess_c)
1086-
{
1087-
ChipLogProgress(DeviceLayer, "Gap_Disconnect() failed.");
1088-
}
1052+
ChipLogProgress(DeviceLayer, "Gap_Disconnect() failed.");
10891053
}
10901054

10911055
#if defined(chip_with_low_power) && (chip_with_low_power == 1)

src/platform/nxp/common/ble/BLEManagerCommon.h

+9-29
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727

2828
#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
2929

30-
#include <set>
31-
3230
#include "fsl_os_abstraction.h"
3331

3432
#include "ble_conn_manager.h"
@@ -61,15 +59,6 @@ struct BLECallbackDelegate
6159
GattServerCallback gattCallback = nullptr;
6260
};
6361

64-
typedef enum service_mode_t
65-
{
66-
kCHIPoBLE_NotSupported = 0,
67-
kCHIPoBLE_Enabled,
68-
kCHIPoBLE_Disabled,
69-
kMultipleBLE_Enabled,
70-
kMultipleBLE_Disabled,
71-
} service_mode_t;
72-
7362
/**
7463
* Base class for different platform implementations (K32W0 and K32W1 for now).
7564
*/
@@ -80,6 +69,7 @@ class BLEManagerCommon : public BLEManager, protected BleLayer, private BlePlatf
8069

8170
CHIP_ERROR _Init(void);
8271
CHIP_ERROR _Shutdown() { return CHIP_NO_ERROR; }
72+
CHIPoBLEServiceMode _GetCHIPoBLEServiceMode(void);
8373
CHIP_ERROR _SetCHIPoBLEServiceMode(CHIPoBLEServiceMode val);
8474
bool _IsAdvertisingEnabled(void);
8575
CHIP_ERROR _SetAdvertisingEnabled(bool val);
@@ -126,11 +116,6 @@ class BLEManagerCommon : public BLEManager, protected BleLayer, private BlePlatf
126116
kUnusedIndex = 0xFF,
127117
};
128118

129-
enum
130-
{
131-
kMaxHandles = 5,
132-
};
133-
134119
typedef enum
135120
{
136121
BLE_KW_MSG_ERROR = 0x01,
@@ -190,18 +175,14 @@ class BLEManagerCommon : public BLEManager, protected BleLayer, private BlePlatf
190175
uint16_t handle;
191176
} blekw_att_read_data_t;
192177

193-
service_mode_t mServiceMode;
178+
CHIPoBLEServiceMode mServiceMode;
194179
char mDeviceName[kMaxDeviceNameLength + 1];
195180
#if CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING
196181
chip::System::PacketBufferHandle c3AdditionalDataBufferHandle;
197182
#endif
198-
std::set<uint8_t> mDeviceIds;
183+
uint8_t mDeviceId;
199184
bool mDeviceSubscribed = false;
200-
201-
uint8_t mReadHandleSize = 0;
202-
uint8_t mWriteHandleSize = 0;
203-
uint16_t mReadNotificationHandle[kMaxHandles];
204-
uint16_t mWriteNotificationHandle[kMaxHandles];
185+
bool mDeviceConnected = false;
205186

206187
void DriveBLEState(void);
207188
CHIP_ERROR ConfigureAdvertising(void);
@@ -254,14 +235,13 @@ class BLEManagerCommon : public BLEManager, protected BleLayer, private BlePlatf
254235
BLECallbackDelegate callbackDelegate;
255236
void RegisterAppCallbacks(BLECallbackDelegate::GapGenericCallback gapCallback,
256237
BLECallbackDelegate::GattServerCallback gattCallback);
257-
258-
CHIP_ERROR AddWriteNotificationHandle(uint16_t name);
259-
CHIP_ERROR AddReadNotificationHandle(uint16_t name);
260-
261-
service_mode_t GetBLEServiceMode(void) { return mServiceMode; }
262-
void SetBLEServiceMode(service_mode_t mode) { mServiceMode = mode; };
263238
};
264239

240+
inline BLEManager::CHIPoBLEServiceMode BLEManagerCommon::_GetCHIPoBLEServiceMode(void)
241+
{
242+
return mServiceMode;
243+
}
244+
265245
} // namespace Internal
266246
} // namespace DeviceLayer
267247
} // namespace chip

0 commit comments

Comments
 (0)