From 22202901f34884000490f06c82ddf95256b199cf Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Fri, 5 Nov 2021 02:16:47 -0400 Subject: [PATCH] Add BLE shutdown, make linux free up scanning upon shutdown (#11437) * Add BLE shutdown, make linux free up scanning upon shutdown * Add shutdown method for ameba as well * Revert change to copyright date in gn.py --- src/include/platform/internal/BLEManager.h | 7 +++++++ .../platform/internal/GenericPlatformManagerImpl.cpp | 4 ++-- src/platform/Ameba/BLEManagerImpl.h | 1 + src/platform/Darwin/BLEManagerImpl.h | 1 + src/platform/EFR32/BLEManagerImpl.h | 1 + src/platform/ESP32/BLEManagerImpl.h | 1 + src/platform/Linux/BLEManagerImpl.cpp | 8 ++++++++ src/platform/Linux/BLEManagerImpl.h | 1 + src/platform/P6/BLEManagerImpl.h | 1 + src/platform/Tizen/BLEManagerImpl.h | 1 + src/platform/Zephyr/BLEManagerImpl.h | 1 + src/platform/android/BLEManagerImpl.h | 1 + src/platform/cc13x2_26x2/BLEManagerImpl.h | 1 + src/platform/mbed/BLEManagerImpl.h | 1 + src/platform/nxp/k32w/k32w0/BLEManagerImpl.h | 1 + src/platform/qpg/BLEManagerImpl.h | 1 + 16 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/include/platform/internal/BLEManager.h b/src/include/platform/internal/BLEManager.h index 17c69b9e465ff0..3910822f1952ae 100644 --- a/src/include/platform/internal/BLEManager.h +++ b/src/include/platform/internal/BLEManager.h @@ -54,6 +54,7 @@ class BLEManager using BLEAdvertisingMode = ConnectivityManager::BLEAdvertisingMode; CHIP_ERROR Init(); + CHIP_ERROR Shutdown(); CHIPoBLEServiceMode GetCHIPoBLEServiceMode(); CHIP_ERROR SetCHIPoBLEServiceMode(CHIPoBLEServiceMode val); bool IsAdvertisingEnabled(); @@ -116,6 +117,12 @@ inline CHIP_ERROR BLEManager::Init() return static_cast(this)->_Init(); } +inline CHIP_ERROR BLEManager::Shutdown() +{ + ReturnErrorOnFailure(GetBleLayer()->Shutdown()); + return static_cast(this)->_Shutdown(); +} + inline BLEManager::CHIPoBLEServiceMode BLEManager::GetCHIPoBLEServiceMode() { return static_cast(this)->_GetCHIPoBLEServiceMode(); diff --git a/src/include/platform/internal/GenericPlatformManagerImpl.cpp b/src/include/platform/internal/GenericPlatformManagerImpl.cpp index ac80fa8a4617ee..041999fa4eb45e 100644 --- a/src/include/platform/internal/GenericPlatformManagerImpl.cpp +++ b/src/include/platform/internal/GenericPlatformManagerImpl.cpp @@ -134,8 +134,8 @@ CHIP_ERROR GenericPlatformManagerImpl::_Shutdown() err = InetLayer().Shutdown(); #if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE - ChipLogError(DeviceLayer, "BLE layer shutdown"); - err = BLEMgr().GetBleLayer()->Shutdown(); + ChipLogError(DeviceLayer, "BLE shutdown"); + err = BLEMgr().Shutdown(); #endif ChipLogError(DeviceLayer, "System Layer shutdown"); diff --git a/src/platform/Ameba/BLEManagerImpl.h b/src/platform/Ameba/BLEManagerImpl.h index bfb2ed1df37cef..8218f8e027a81e 100755 --- a/src/platform/Ameba/BLEManagerImpl.h +++ b/src/platform/Ameba/BLEManagerImpl.h @@ -46,6 +46,7 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla // ===== Members that implement the BLEManager internal interface. CHIP_ERROR _Init(void); + CHIP_ERROR _Shutdown() { return CHIP_NO_ERROR; } CHIPoBLEServiceMode _GetCHIPoBLEServiceMode(void); CHIP_ERROR _SetCHIPoBLEServiceMode(CHIPoBLEServiceMode val); bool _IsAdvertisingEnabled(void); diff --git a/src/platform/Darwin/BLEManagerImpl.h b/src/platform/Darwin/BLEManagerImpl.h index d3920051442bc0..a449a645df0c8c 100644 --- a/src/platform/Darwin/BLEManagerImpl.h +++ b/src/platform/Darwin/BLEManagerImpl.h @@ -47,6 +47,7 @@ class BLEManagerImpl final : public BLEManager, private BleLayer // ===== Members that implement the BLEManager internal interface. CHIP_ERROR _Init(void); + CHIP_ERROR _Shutdown() { return CHIP_NO_ERROR; } CHIPoBLEServiceMode _GetCHIPoBLEServiceMode(void); CHIP_ERROR _SetCHIPoBLEServiceMode(CHIPoBLEServiceMode val); bool _IsAdvertisingEnabled(void); diff --git a/src/platform/EFR32/BLEManagerImpl.h b/src/platform/EFR32/BLEManagerImpl.h index b1b40dd977a7ec..131a833736d25f 100644 --- a/src/platform/EFR32/BLEManagerImpl.h +++ b/src/platform/EFR32/BLEManagerImpl.h @@ -49,6 +49,7 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla // ===== Members that implement the BLEManager internal interface. CHIP_ERROR _Init(void); + CHIP_ERROR _Shutdown() { return CHIP_NO_ERROR; } CHIPoBLEServiceMode _GetCHIPoBLEServiceMode(void); CHIP_ERROR _SetCHIPoBLEServiceMode(CHIPoBLEServiceMode val); bool _IsAdvertisingEnabled(void); diff --git a/src/platform/ESP32/BLEManagerImpl.h b/src/platform/ESP32/BLEManagerImpl.h index 92d291b6d0d89e..624da05ea2d4ce 100644 --- a/src/platform/ESP32/BLEManagerImpl.h +++ b/src/platform/ESP32/BLEManagerImpl.h @@ -81,6 +81,7 @@ class BLEManagerImpl final : public BLEManager, // ===== Members that implement the BLEManager internal interface. CHIP_ERROR _Init(void); + CHIP_ERROR _Shutdown() { return CHIP_NO_ERROR; } CHIPoBLEServiceMode _GetCHIPoBLEServiceMode(void); CHIP_ERROR _SetCHIPoBLEServiceMode(CHIPoBLEServiceMode val); bool _IsAdvertisingEnabled(void); diff --git a/src/platform/Linux/BLEManagerImpl.cpp b/src/platform/Linux/BLEManagerImpl.cpp index e22716259bfe6a..020783698b18d4 100644 --- a/src/platform/Linux/BLEManagerImpl.cpp +++ b/src/platform/Linux/BLEManagerImpl.cpp @@ -92,6 +92,14 @@ CHIP_ERROR BLEManagerImpl::_Init() return err; } +CHIP_ERROR BLEManagerImpl::_Shutdown() +{ + // ensure scan resources are cleared (e.g. timeout timers) + mDeviceScanner.reset(); + + return CHIP_NO_ERROR; +} + CHIP_ERROR BLEManagerImpl::_SetCHIPoBLEServiceMode(CHIPoBLEServiceMode val) { CHIP_ERROR err = CHIP_NO_ERROR; diff --git a/src/platform/Linux/BLEManagerImpl.h b/src/platform/Linux/BLEManagerImpl.h index c8b0072d088fd5..87a8f83f8f3ea1 100644 --- a/src/platform/Linux/BLEManagerImpl.h +++ b/src/platform/Linux/BLEManagerImpl.h @@ -112,6 +112,7 @@ class BLEManagerImpl final : public BLEManager, // ===== Members that implement the BLEManager internal interface. CHIP_ERROR _Init(); + CHIP_ERROR _Shutdown(); CHIPoBLEServiceMode _GetCHIPoBLEServiceMode(); CHIP_ERROR _SetCHIPoBLEServiceMode(CHIPoBLEServiceMode val); bool _IsAdvertisingEnabled(); diff --git a/src/platform/P6/BLEManagerImpl.h b/src/platform/P6/BLEManagerImpl.h index 98fb4f665c828c..545dc440e58ce5 100644 --- a/src/platform/P6/BLEManagerImpl.h +++ b/src/platform/P6/BLEManagerImpl.h @@ -51,6 +51,7 @@ class BLEManagerImpl final : public BLEManager, // ===== Members that implement the BLEManager internal interface. CHIP_ERROR _Init(void); + CHIP_ERROR _Shutdown() { return CHIP_NO_ERROR; } CHIPoBLEServiceMode _GetCHIPoBLEServiceMode(void); CHIP_ERROR _SetCHIPoBLEServiceMode(CHIPoBLEServiceMode val); bool _IsAdvertisingEnabled(void); diff --git a/src/platform/Tizen/BLEManagerImpl.h b/src/platform/Tizen/BLEManagerImpl.h index 3d5ea4f03e43e7..16e5c1512e506f 100644 --- a/src/platform/Tizen/BLEManagerImpl.h +++ b/src/platform/Tizen/BLEManagerImpl.h @@ -55,6 +55,7 @@ class BLEManagerImpl final : public BLEManager, // ===== Members that implement the BLEManager internal interface. CHIP_ERROR _Init(void); + CHIP_ERROR _Shutdown() { return CHIP_NO_ERROR; } CHIPoBLEServiceMode _GetCHIPoBLEServiceMode(void); CHIP_ERROR _SetCHIPoBLEServiceMode(CHIPoBLEServiceMode val); bool _IsAdvertisingEnabled(void); diff --git a/src/platform/Zephyr/BLEManagerImpl.h b/src/platform/Zephyr/BLEManagerImpl.h index 9f8be0aeb2c01a..f564b305f8a8aa 100644 --- a/src/platform/Zephyr/BLEManagerImpl.h +++ b/src/platform/Zephyr/BLEManagerImpl.h @@ -50,6 +50,7 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla // ===== Members that implement the BLEManager internal interface. CHIP_ERROR _Init(void); + CHIP_ERROR _Shutdown() { return CHIP_NO_ERROR; } CHIPoBLEServiceMode _GetCHIPoBLEServiceMode(void); CHIP_ERROR _SetCHIPoBLEServiceMode(CHIPoBLEServiceMode val); bool _IsAdvertisingEnabled(void); diff --git a/src/platform/android/BLEManagerImpl.h b/src/platform/android/BLEManagerImpl.h index 43e44819a56db2..1b2b062e93e092 100644 --- a/src/platform/android/BLEManagerImpl.h +++ b/src/platform/android/BLEManagerImpl.h @@ -56,6 +56,7 @@ class BLEManagerImpl final : public BLEManager, // ===== Members that implement the BLEManager internal interface. CHIP_ERROR _Init(); + CHIP_ERROR _Shutdown() { return CHIP_NO_ERROR; } CHIPoBLEServiceMode _GetCHIPoBLEServiceMode(); CHIP_ERROR _SetCHIPoBLEServiceMode(CHIPoBLEServiceMode val); bool _IsAdvertisingEnabled(); diff --git a/src/platform/cc13x2_26x2/BLEManagerImpl.h b/src/platform/cc13x2_26x2/BLEManagerImpl.h index 76f66bbcfed9a5..1bb256bb79f9bc 100644 --- a/src/platform/cc13x2_26x2/BLEManagerImpl.h +++ b/src/platform/cc13x2_26x2/BLEManagerImpl.h @@ -205,6 +205,7 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla // ===== Members that implement the BLEManager internal interface. CHIP_ERROR _Init(void); + CHIP_ERROR _Shutdown() { return CHIP_NO_ERROR; } CHIPoBLEServiceMode _GetCHIPoBLEServiceMode(void); CHIP_ERROR _SetCHIPoBLEServiceMode(CHIPoBLEServiceMode val); bool _IsAdvertisingEnabled(void); diff --git a/src/platform/mbed/BLEManagerImpl.h b/src/platform/mbed/BLEManagerImpl.h index ab98a8a51734da..fc96bc4a4c823d 100644 --- a/src/platform/mbed/BLEManagerImpl.h +++ b/src/platform/mbed/BLEManagerImpl.h @@ -46,6 +46,7 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla // ===== Members that implement the BLEManager internal interface. CHIP_ERROR _Init(void); + CHIP_ERROR _Shutdown() { return CHIP_NO_ERROR; } CHIPoBLEServiceMode _GetCHIPoBLEServiceMode(void); CHIP_ERROR _SetCHIPoBLEServiceMode(CHIPoBLEServiceMode val); bool _IsAdvertisingEnabled(void); diff --git a/src/platform/nxp/k32w/k32w0/BLEManagerImpl.h b/src/platform/nxp/k32w/k32w0/BLEManagerImpl.h index e924fd8bafc8f7..410dca8d452de1 100644 --- a/src/platform/nxp/k32w/k32w0/BLEManagerImpl.h +++ b/src/platform/nxp/k32w/k32w0/BLEManagerImpl.h @@ -64,6 +64,7 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla // ===== Members that implement the BLEManager internal interface. CHIP_ERROR _Init(void); + CHIP_ERROR _Shutdown() { return CHIP_NO_ERROR; } CHIPoBLEServiceMode _GetCHIPoBLEServiceMode(void); CHIP_ERROR _SetCHIPoBLEServiceMode(CHIPoBLEServiceMode val); bool _IsAdvertisingEnabled(void); diff --git a/src/platform/qpg/BLEManagerImpl.h b/src/platform/qpg/BLEManagerImpl.h index 595267a100b0f0..59998d5727b870 100644 --- a/src/platform/qpg/BLEManagerImpl.h +++ b/src/platform/qpg/BLEManagerImpl.h @@ -48,6 +48,7 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla // ===== Members that implement the BLEManager internal interface. CHIP_ERROR _Init(void); + CHIP_ERROR _Shutdown() { return CHIP_NO_ERROR; } CHIPoBLEServiceMode _GetCHIPoBLEServiceMode(void); CHIP_ERROR _SetCHIPoBLEServiceMode(CHIPoBLEServiceMode val); bool _IsAdvertisingEnabled(void);