Skip to content

Commit 2523144

Browse files
shchen-Labrestyled-commits
authored andcommitted
[BouffaloLab][BLE]Add BLE ManagerImpl ShutDown Function (#28600)
* Add BLE ManagerImpl ShutDown Function * Restyled by whitespace * Restyled by clang-format --------- Co-authored-by: Restyled.io <commits@restyled.io>
1 parent effa429 commit 2523144

File tree

4 files changed

+34
-4
lines changed

4 files changed

+34
-4
lines changed

src/platform/bouffalolab/common/BLEManagerImpl.cpp

+20-2
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,12 @@ CHIP_ERROR BLEManagerImpl::_Init()
146146
return CHIP_NO_ERROR;
147147
}
148148

149+
void BLEManagerImpl::_Shutdown()
150+
{
151+
// Release BLE Stack resources
152+
mFlags.Set(Flags::kChipoBleShutDown);
153+
}
154+
149155
void BLEManagerImpl::DriveBLEState(intptr_t arg)
150156
{
151157
BLEMgrImpl().DriveBLEState();
@@ -435,7 +441,7 @@ CHIP_ERROR BLEManagerImpl::HandleGAPDisconnect(const ChipDeviceEvent * event)
435441
{
436442
case BT_HCI_ERR_REMOTE_USER_TERM_CONN:
437443
// Do not treat proper connection termination as an error and exit.
438-
VerifyOrExit(!ConfigurationMgr().IsFullyProvisioned(), );
444+
VerifyOrExit(!ConfigurationMgr().IsFullyProvisioned(), BLEMgrImpl()._Shutdown());
439445
disconReason = BLE_ERROR_REMOTE_DEVICE_DISCONNECTED;
440446
break;
441447
case BT_HCI_ERR_LOCALHOST_TERM_CONN:
@@ -457,7 +463,19 @@ CHIP_ERROR BLEManagerImpl::HandleGAPDisconnect(const ChipDeviceEvent * event)
457463
ChipDeviceEvent disconnectEvent;
458464
disconnectEvent.Type = DeviceEventType::kCHIPoBLEConnectionClosed;
459465
ReturnErrorOnFailure(PlatformMgr().PostEvent(&disconnectEvent));
460-
466+
if (mFlags.Has(Flags::kChipoBleShutDown))
467+
{
468+
int ret = bt_disable();
469+
if (ret)
470+
{
471+
ChipLogError(DeviceLayer, "CHIPoBLE Shutdown faild =%d", ret);
472+
}
473+
else
474+
{
475+
mFlags.Clear(Flags::kChipoBleShutDown);
476+
}
477+
return CHIP_NO_ERROR;
478+
}
461479
// Force a reconfiguration of advertising in case we switched to non-connectable mode when
462480
// the BLE connection was established.
463481
mFlags.Set(Flags::kAdvertisingRefreshNeeded);

src/platform/bouffalolab/common/BLEManagerImpl.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla
4444
std::conditional_t<std::is_same<bt_gatt_indicate_func_t, void (*)(bt_conn *, bt_gatt_indicate_params *, uint8_t)>::value,
4545
bt_gatt_indicate_params *, const bt_gatt_attr *>;
4646
CHIP_ERROR _Init(void);
47-
void _Shutdown() {}
47+
void _Shutdown();
4848
bool _IsAdvertisingEnabled(void);
4949
CHIP_ERROR _SetAdvertisingEnabled(bool val);
5050
bool _IsAdvertising(void);
@@ -85,6 +85,7 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla
8585
kAdvertisingRefreshNeeded =
8686
0x0010, /**< The advertising state/configuration has changed, but the SoftDevice has yet to be updated. */
8787
kChipoBleGattServiceRegister = 0x0020, /**< The system has currently CHIPoBLE GATT service registered. */
88+
kChipoBleShutDown = 0x0040, /**< The system has disable ble stack. */
8889
};
8990

9091
struct ServiceData;

src/platform/bouffalolab/common/ConfigurationManagerImpl.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,17 @@ ConfigurationManagerImpl & ConfigurationManagerImpl::GetDefaultInstance()
3434
static ConfigurationManagerImpl sInstance;
3535
return sInstance;
3636
}
37-
37+
bool ConfigurationManagerImpl::IsFullyProvisioned()
38+
{
39+
return
40+
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION
41+
ConnectivityMgr().IsWiFiStationProvisioned() &&
42+
#endif
43+
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
44+
ConnectivityMgr().IsThreadProvisioned() &&
45+
#endif
46+
true;
47+
}
3848
CHIP_ERROR ConfigurationManagerImpl::Init()
3949
{
4050
CHIP_ERROR err;

src/platform/bouffalolab/common/ConfigurationManagerImpl.h

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImp
3636
CHIP_ERROR StoreRebootCount(uint32_t rebootCount);
3737
CHIP_ERROR GetTotalOperationalHours(uint32_t & totalOperationalHours);
3838
CHIP_ERROR StoreTotalOperationalHours(uint32_t totalOperationalHours);
39+
bool IsFullyProvisioned();
3940

4041
private:
4142
// ===== Members that implement the ConfigurationManager private interface.

0 commit comments

Comments
 (0)