Skip to content

Commit

Permalink
Add BLE ManagerImpl ShutDown Function
Browse files Browse the repository at this point in the history
  • Loading branch information
shchen-Lab committed Aug 8, 2023
1 parent fbd89cc commit 104d93a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
8 changes: 5 additions & 3 deletions src/platform/bouffalolab/common/BLEManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ CHIP_ERROR BLEManagerImpl::_Init()
return CHIP_NO_ERROR;
}

void BLEManagerImpl::_Shutdown()
{
bt_disable();
}
void BLEManagerImpl::DriveBLEState(intptr_t arg)
{
BLEMgrImpl().DriveBLEState();
Expand Down Expand Up @@ -435,7 +439,7 @@ CHIP_ERROR BLEManagerImpl::HandleGAPDisconnect(const ChipDeviceEvent * event)
{
case BT_HCI_ERR_REMOTE_USER_TERM_CONN:
// Do not treat proper connection termination as an error and exit.
VerifyOrExit(!ConfigurationMgr().IsFullyProvisioned(), );
VerifyOrExit(!ConfigurationMgr().IsFullyProvisioned(),BLEMgrImpl()._Shutdown());
disconReason = BLE_ERROR_REMOTE_DEVICE_DISCONNECTED;
break;
case BT_HCI_ERR_LOCALHOST_TERM_CONN:
Expand All @@ -457,7 +461,6 @@ CHIP_ERROR BLEManagerImpl::HandleGAPDisconnect(const ChipDeviceEvent * event)
ChipDeviceEvent disconnectEvent;
disconnectEvent.Type = DeviceEventType::kCHIPoBLEConnectionClosed;
ReturnErrorOnFailure(PlatformMgr().PostEvent(&disconnectEvent));

// Force a reconfiguration of advertising in case we switched to non-connectable mode when
// the BLE connection was established.
mFlags.Set(Flags::kAdvertisingRefreshNeeded);
Expand Down Expand Up @@ -592,7 +595,6 @@ void BLEManagerImpl::_OnPlatformEvent(const ChipDeviceEvent * event)
case DeviceEventType::kPlatformZephyrBleC2IndDoneEvent:
err = HandleTXCharComplete(event);
break;

default:
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/platform/bouffalolab/common/BLEManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla
std::conditional_t<std::is_same<bt_gatt_indicate_func_t, void (*)(bt_conn *, bt_gatt_indicate_params *, uint8_t)>::value,
bt_gatt_indicate_params *, const bt_gatt_attr *>;
CHIP_ERROR _Init(void);
void _Shutdown() {}
void _Shutdown();
bool _IsAdvertisingEnabled(void);
CHIP_ERROR _SetAdvertisingEnabled(bool val);
bool _IsAdvertising(void);
Expand Down
13 changes: 11 additions & 2 deletions src/platform/bouffalolab/common/ConfigurationManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,17 @@ ConfigurationManagerImpl & ConfigurationManagerImpl::GetDefaultInstance()
static ConfigurationManagerImpl sInstance;
return sInstance;
}

bool ConfigurationManagerImpl::IsFullyProvisioned()
{
return
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION
ConnectivityMgr().IsWiFiStationProvisioned() &&
#endif
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
ConnectivityMgr().IsThreadProvisioned() &&
#endif
true;
}
CHIP_ERROR ConfigurationManagerImpl::Init()
{
CHIP_ERROR err;
Expand Down Expand Up @@ -198,7 +208,6 @@ void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg)

hal_reboot();
}

ConfigurationManager & ConfigurationMgrImpl()
{
return ConfigurationManagerImpl::GetDefaultInstance();
Expand Down
2 changes: 1 addition & 1 deletion src/platform/bouffalolab/common/ConfigurationManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImp
CHIP_ERROR StoreRebootCount(uint32_t rebootCount);
CHIP_ERROR GetTotalOperationalHours(uint32_t & totalOperationalHours);
CHIP_ERROR StoreTotalOperationalHours(uint32_t totalOperationalHours);

bool IsFullyProvisioned();
private:
// ===== Members that implement the ConfigurationManager private interface.

Expand Down

0 comments on commit 104d93a

Please sign in to comment.