From 102e0c33c8f006f42a8d98f542c14274297c9125 Mon Sep 17 00:00:00 2001 From: Kamil Kasperczyk Date: Wed, 13 Apr 2022 14:52:10 +0200 Subject: [PATCH 1/3] Added support for Thread Synchronized Sleepy End Devices Thread 1.2 allows to use Synchronized Sleepy End Devices that doesn't need to poll parent for data like traditional SED, but wakes up in scheduled time slots to listen for messages without transmitting requests to parent. * Refactored naming for sleepy end devices, as everywhere the polling mechanism is assumed. Basically renamed polling intervals to intervals and fast/slow polling mode to active/idle mode. * Added CHIP_DEVICE_CONFIG_THREAD_SSED that allows to enable Thread SSED support. * Added new Thread kThreadDeviceType_SynchronizedSleepyEndDevice device type * Added calculating communication intervals for Thread SSED based on CSL period instead of poll period. --- .../Kconfig.multiprotocol_rpmsg.defaults | 4 + config/zephyr/Kconfig | 23 +++-- .../main/include/CHIPProjectConfig.h | 2 +- .../main/include/CHIPProjectConfig.h | 2 +- .../main/include/CHIPProjectConfig.h | 2 +- .../k32w/k32w0/include/CHIPProjectConfig.h | 4 +- src/app/server/CommissioningWindowManager.cpp | 4 +- src/app/server/Dnssd.cpp | 2 +- src/include/platform/CHIPDeviceConfig.h | 26 ++++-- src/include/platform/CHIPDeviceEvent.h | 6 +- src/include/platform/ConnectivityManager.h | 61 +++++++------ src/include/platform/ThreadStackManager.h | 30 +++--- .../GenericConnectivityManagerImpl_NoThread.h | 16 ++-- .../GenericConnectivityManagerImpl_Thread.h | 20 ++-- src/messaging/ExchangeContext.cpp | 22 ++--- src/messaging/ExchangeContext.h | 16 ++-- src/messaging/ReliableMessageContext.h | 20 ++-- .../ReliableMessageProtocolConfig.cpp | 10 +- src/platform/Linux/ThreadStackManagerImpl.cpp | 16 ++-- src/platform/Linux/ThreadStackManagerImpl.h | 6 +- ...nericThreadStackManagerImpl_OpenThread.cpp | 91 ++++++++++++------- ...GenericThreadStackManagerImpl_OpenThread.h | 14 +-- .../nrfconnect/CHIPDevicePlatformConfig.h | 1 + 23 files changed, 221 insertions(+), 177 deletions(-) diff --git a/config/nrfconnect/chip-module/Kconfig.multiprotocol_rpmsg.defaults b/config/nrfconnect/chip-module/Kconfig.multiprotocol_rpmsg.defaults index ae993ca7ef63fc..18d3e7889ae1a2 100644 --- a/config/nrfconnect/chip-module/Kconfig.multiprotocol_rpmsg.defaults +++ b/config/nrfconnect/chip-module/Kconfig.multiprotocol_rpmsg.defaults @@ -97,3 +97,7 @@ config NRF_802154_SER_RADIO config NRF_RTC_TIMER_USER_CHAN_COUNT int default 2 + +config NRF_802154_ENCRYPTION + bool + default y diff --git a/config/zephyr/Kconfig b/config/zephyr/Kconfig index 748047ca5a85d7..8bfa06ad923d70 100644 --- a/config/zephyr/Kconfig +++ b/config/zephyr/Kconfig @@ -1,17 +1,17 @@ # # Copyright (c) 2021 Project CHIP Authors # -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0(the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http: // www.apache.org/licenses/LICENSE-2.0 # -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. # menuconfig CHIP @@ -139,6 +139,11 @@ config CHIP_ENABLE_SLEEPY_END_DEVICE_SUPPORT help Enables Thread Sleepy End Device support in Matter. +config CHIP_THREAD_SSED + bool "Enable Thread Synchronized Sleepy End Device support" + help + Enables Thread Synchronized Sleepy End Device support in Matter. + config CHIP_OTA_REQUESTOR bool "Enable OTA requestor" help diff --git a/examples/all-clusters-app/nrfconnect/main/include/CHIPProjectConfig.h b/examples/all-clusters-app/nrfconnect/main/include/CHIPProjectConfig.h index 49000724fc6c47..7a2941f28621df 100644 --- a/examples/all-clusters-app/nrfconnect/main/include/CHIPProjectConfig.h +++ b/examples/all-clusters-app/nrfconnect/main/include/CHIPProjectConfig.h @@ -30,4 +30,4 @@ #define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 20202021 #define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR 0xF00 -#define CHIP_DEVICE_CONFIG_SED_SLOW_POLLING_INTERVAL 2000_ms32 +#define CHIP_DEVICE_CONFIG_SED_IDLE_INTERVAL 2000_ms32 diff --git a/examples/light-switch-app/nrfconnect/main/include/CHIPProjectConfig.h b/examples/light-switch-app/nrfconnect/main/include/CHIPProjectConfig.h index b5a27150a26404..5361319e42ecfe 100644 --- a/examples/light-switch-app/nrfconnect/main/include/CHIPProjectConfig.h +++ b/examples/light-switch-app/nrfconnect/main/include/CHIPProjectConfig.h @@ -30,4 +30,4 @@ /* Use a default pairing code if one hasn't been provisioned in flash. */ #define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 20202021 #define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR 0xF00 -#define CHIP_DEVICE_CONFIG_SED_SLOW_POLLING_INTERVAL 2000_ms32 +#define CHIP_DEVICE_CONFIG_SED_IDLE_INTERVAL 2000_ms32 diff --git a/examples/lock-app/nrfconnect/main/include/CHIPProjectConfig.h b/examples/lock-app/nrfconnect/main/include/CHIPProjectConfig.h index d6afc4def5622a..3a6d7ab9f27f28 100644 --- a/examples/lock-app/nrfconnect/main/include/CHIPProjectConfig.h +++ b/examples/lock-app/nrfconnect/main/include/CHIPProjectConfig.h @@ -31,4 +31,4 @@ #define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 20202021 #define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR 0xF00 -#define CHIP_DEVICE_CONFIG_SED_SLOW_POLLING_INTERVAL 2000_ms32 +#define CHIP_DEVICE_CONFIG_SED_IDLE_INTERVAL 2000_ms32 diff --git a/examples/lock-app/nxp/k32w/k32w0/include/CHIPProjectConfig.h b/examples/lock-app/nxp/k32w/k32w0/include/CHIPProjectConfig.h index 688a563932b9d6..8f8afba2cc8751 100644 --- a/examples/lock-app/nxp/k32w/k32w0/include/CHIPProjectConfig.h +++ b/examples/lock-app/nxp/k32w/k32w0/include/CHIPProjectConfig.h @@ -147,8 +147,8 @@ #define CHIP_CONFIG_MAX_FABRICS 4 // 3 fabrics + 1 for rotation slack #define CHIP_DEVICE_CONFIG_ENABLE_SED 1 -#define CHIP_DEVICE_CONFIG_SED_SLOW_POLLING_INTERVAL 1000_ms32 -#define CHIP_DEVICE_CONFIG_SED_FAST_POLLING_INTERVAL 100_ms32 +#define CHIP_DEVICE_CONFIG_SED_IDLE_INTERVAL 1000_ms32 +#define CHIP_DEVICE_CONFIG_SED_ACTIVE_INTERVAL 100_ms32 /** * CHIP_CONFIG_EVENT_LOGGING_DEFAULT_IMPORTANCE diff --git a/src/app/server/CommissioningWindowManager.cpp b/src/app/server/CommissioningWindowManager.cpp index 339935c94f228e..ad656a6278c67f 100644 --- a/src/app/server/CommissioningWindowManager.cpp +++ b/src/app/server/CommissioningWindowManager.cpp @@ -344,7 +344,7 @@ CHIP_ERROR CommissioningWindowManager::StartAdvertisement() #if CHIP_DEVICE_CONFIG_ENABLE_SED if (!mIsBLE && mWindowStatus == AdministratorCommissioning::CommissioningWindowStatus::kWindowNotOpen) { - DeviceLayer::ConnectivityMgr().RequestSEDFastPollingMode(true); + DeviceLayer::ConnectivityMgr().RequestSEDActiveMode(true); } #endif @@ -386,7 +386,7 @@ CHIP_ERROR CommissioningWindowManager::StopAdvertisement(bool aShuttingDown) #if CHIP_DEVICE_CONFIG_ENABLE_SED if (!mIsBLE && mWindowStatus != AdministratorCommissioning::CommissioningWindowStatus::kWindowNotOpen) { - DeviceLayer::ConnectivityMgr().RequestSEDFastPollingMode(false); + DeviceLayer::ConnectivityMgr().RequestSEDActiveMode(false); } #endif diff --git a/src/app/server/Dnssd.cpp b/src/app/server/Dnssd.cpp index e49255050ce448..962b02c5fa4e01 100644 --- a/src/app/server/Dnssd.cpp +++ b/src/app/server/Dnssd.cpp @@ -48,7 +48,7 @@ void OnPlatformEvent(const DeviceLayer::ChipDeviceEvent * event) { if (event->Type == DeviceLayer::DeviceEventType::kDnssdPlatformInitialized #if CHIP_DEVICE_CONFIG_ENABLE_SED - || event->Type == DeviceLayer::DeviceEventType::kSEDPollingIntervalChange + || event->Type == DeviceLayer::DeviceEventType::kSEDIntervalChange #endif ) { diff --git a/src/include/platform/CHIPDeviceConfig.h b/src/include/platform/CHIPDeviceConfig.h index 5c9406d6595772..1a8d3b8bbf9227 100644 --- a/src/include/platform/CHIPDeviceConfig.h +++ b/src/include/platform/CHIPDeviceConfig.h @@ -126,23 +126,23 @@ #endif /** - * CHIP_DEVICE_CONFIG_SED_SLOW_POLLING_INTERVAL + * CHIP_DEVICE_CONFIG_SED_IDLE_INTERVAL * - * The default amount of time in milliseconds that the sleepy end device will use as a slow-polling interval. + * The default amount of time in milliseconds that the sleepy end device will use as an idle interval. * This interval is used by the device to periodically wake up and poll the data in the idle mode. */ -#ifndef CHIP_DEVICE_CONFIG_SED_SLOW_POLLING_INTERVAL -#define CHIP_DEVICE_CONFIG_SED_SLOW_POLLING_INTERVAL 5000_ms32 +#ifndef CHIP_DEVICE_CONFIG_SED_IDLE_INTERVAL +#define CHIP_DEVICE_CONFIG_SED_IDLE_INTERVAL 5000_ms32 #endif /** - * CHIP_DEVICE_CONFIG_SED_FAST_POLLING_INTERVAL + * CHIP_DEVICE_CONFIG_SED_ACTIVE_INTERVAL * - * The default amount of time in milliseconds that the sleepy end device will use as a fast-polling interval. + * The default amount of time in milliseconds that the sleepy end device will use as an active interval. * This interval is used by the device to periodically wake up and poll the data in the active mode. */ -#ifndef CHIP_DEVICE_CONFIG_SED_FAST_POLLING_INTERVAL -#define CHIP_DEVICE_CONFIG_SED_FAST_POLLING_INTERVAL 200_ms32 +#ifndef CHIP_DEVICE_CONFIG_SED_ACTIVE_INTERVAL +#define CHIP_DEVICE_CONFIG_SED_ACTIVE_INTERVAL 200_ms32 #endif // -------------------- Device Identification Configuration -------------------- @@ -691,6 +691,16 @@ #define CHIP_DEVICE_CONFIG_THREAD_FTD 1 #endif +/** + * CHIP_DEVICE_CONFIG_THREAD_SSED + * + * Enable support for Thread Synchronized Sleepy End Device behavior. + * + */ +#ifndef CHIP_DEVICE_CONFIG_THREAD_SSED +#define CHIP_DEVICE_CONFIG_THREAD_SSED 0 +#endif + /** * CHIP_DEVICE_CONFIG_THREAD_TASK_NAME * diff --git a/src/include/platform/CHIPDeviceEvent.h b/src/include/platform/CHIPDeviceEvent.h index f5988a7a4ffc4d..2ff9526b58ce28 100644 --- a/src/include/platform/CHIPDeviceEvent.h +++ b/src/include/platform/CHIPDeviceEvent.h @@ -161,11 +161,11 @@ enum PublicEventTypes kTimeSyncChange, /** - * SED Polling Interval Change + * SED Interval Change * - * Signals a change to the sleepy end device polling interval. + * Signals a change to the sleepy end device interval. */ - kSEDPollingIntervalChange, + kSEDIntervalChange, /** * Security Session Established diff --git a/src/include/platform/ConnectivityManager.h b/src/include/platform/ConnectivityManager.h index 32824e2fd6462e..105f70a74ee506 100644 --- a/src/include/platform/ConnectivityManager.h +++ b/src/include/platform/ConnectivityManager.h @@ -133,11 +133,12 @@ class ConnectivityManager enum ThreadDeviceType { - kThreadDeviceType_NotSupported = 0, - kThreadDeviceType_Router = 1, - kThreadDeviceType_FullEndDevice = 2, - kThreadDeviceType_MinimalEndDevice = 3, - kThreadDeviceType_SleepyEndDevice = 4, + kThreadDeviceType_NotSupported = 0, + kThreadDeviceType_Router = 1, + kThreadDeviceType_FullEndDevice = 2, + kThreadDeviceType_MinimalEndDevice = 3, + kThreadDeviceType_SleepyEndDevice = 4, + kThreadDeviceType_SynchronizedSleepyEndDevice = 5, }; enum BLEAdvertisingMode @@ -146,13 +147,13 @@ class ConnectivityManager kSlowAdvertising = 1, }; - enum class SEDPollingMode + enum class SEDIntervalMode { Idle = 0, Active = 1, }; - struct SEDPollingConfig; + struct SEDIntervalsConfig; void SetDelegate(ConnectivityManagerDelegate * delegate) { mDelegate = delegate; } ConnectivityManagerDelegate * GetDelegate() const { return mDelegate; } @@ -195,24 +196,24 @@ class ConnectivityManager // Sleepy end device methods #if CHIP_DEVICE_CONFIG_ENABLE_SED - CHIP_ERROR GetSEDPollingConfig(SEDPollingConfig & pollingConfig); + CHIP_ERROR GetSEDIntervalsConfig(SEDIntervalsConfig & intervalsConfig); /** - * Sets Sleepy End Device polling configuration and posts kSEDPollingIntervalChange event to inform other software + * Sets Sleepy End Device intervals configuration and posts kSEDIntervalChange event to inform other software * modules about the change. * - * @param[in] pollingConfig polling intervals configuration to be set + * @param[in] intervalsConfig intervals configuration to be set */ - CHIP_ERROR SetSEDPollingConfig(const SEDPollingConfig & pollingConfig); + CHIP_ERROR SetSEDIntervalsConfig(const SEDIntervalsConfig & intervalsConfig); /** - * Requests setting Sleepy End Device fast polling interval on or off. - * Every method call with onOff parameter set to true or false results in incrementing or decrementing the fast polling - * consumers counter. Fast polling mode is set if the consumers counter is bigger than 0. + * Requests setting Sleepy End Device active interval on or off. + * Every method call with onOff parameter set to true or false results in incrementing or decrementing the active mode + * consumers counter. Active mode is set if the consumers counter is bigger than 0. * - * @param[in] onOff true if fast polling should be enabled and false otherwise. + * @param[in] onOff true if active mode should be enabled and false otherwise. */ - CHIP_ERROR RequestSEDFastPollingMode(bool onOff); + CHIP_ERROR RequestSEDActiveMode(bool onOff); #endif // CHIPoBLE service methods @@ -271,17 +272,17 @@ class ConnectivityManager }; /** - * Information describing the desired polling behavior of a sleepy end device (SED). + * Information describing the desired intervals for a sleepy end device (SED). */ -struct ConnectivityManager::SEDPollingConfig +struct ConnectivityManager::SEDIntervalsConfig { - /** Interval at which the device polls its parent when there are active chip exchanges in progress. Only meaningful when the - * device is acting as a sleepy end node. */ - System::Clock::Milliseconds32 FastPollingIntervalMS; + /** Interval at which the device is able to communicate with its parent when there are active chip exchanges in progress. Only + * meaningful when the device is acting as a sleepy end node. */ + System::Clock::Milliseconds32 ActiveIntervalMS; - /** Interval at which the device polls its parent when there are NO active chip exchanges in progress. Only meaningful when the - * device is acting as a sleepy end node. */ - System::Clock::Milliseconds32 SlowPollingIntervalMS; + /** Interval at which the device is able to communicate with its parent when there are NO active chip exchanges in progress. + * Only meaningful when the device is acting as a sleepy end node. */ + System::Clock::Milliseconds32 IdleIntervalMS; }; /** @@ -442,19 +443,19 @@ inline CHIP_ERROR ConnectivityManager::SetThreadDeviceType(ThreadDeviceType devi } #if CHIP_DEVICE_CONFIG_ENABLE_SED -inline CHIP_ERROR ConnectivityManager::GetSEDPollingConfig(SEDPollingConfig & pollingConfig) +inline CHIP_ERROR ConnectivityManager::GetSEDIntervalsConfig(SEDIntervalsConfig & intervalsConfig) { - return static_cast(this)->_GetSEDPollingConfig(pollingConfig); + return static_cast(this)->_GetSEDIntervalsConfig(intervalsConfig); } -inline CHIP_ERROR ConnectivityManager::SetSEDPollingConfig(const SEDPollingConfig & pollingConfig) +inline CHIP_ERROR ConnectivityManager::SetSEDIntervalsConfig(const SEDIntervalsConfig & intervalsConfig) { - return static_cast(this)->_SetSEDPollingConfig(pollingConfig); + return static_cast(this)->_SetSEDIntervalsConfig(intervalsConfig); } -inline CHIP_ERROR ConnectivityManager::RequestSEDFastPollingMode(bool onOff) +inline CHIP_ERROR ConnectivityManager::RequestSEDActiveMode(bool onOff) { - return static_cast(this)->_RequestSEDFastPollingMode(onOff); + return static_cast(this)->_RequestSEDActiveMode(onOff); } #endif diff --git a/src/include/platform/ThreadStackManager.h b/src/include/platform/ThreadStackManager.h index f236835f832d1e..5ce7ec1dd09ea6 100644 --- a/src/include/platform/ThreadStackManager.h +++ b/src/include/platform/ThreadStackManager.h @@ -163,24 +163,24 @@ class ThreadStackManager CHIP_ERROR SetThreadDeviceType(ConnectivityManager::ThreadDeviceType threadRole); #if CHIP_DEVICE_CONFIG_ENABLE_SED - CHIP_ERROR GetSEDPollingConfig(ConnectivityManager::SEDPollingConfig & pollingConfig); + CHIP_ERROR GetSEDIntervalsConfig(ConnectivityManager::SEDIntervalsConfig & intervalsConfig); /** - * Sets Sleepy End Device polling configuration and posts kSEDPollingIntervalChange event to inform other software + * Sets Sleepy End Device intervals configuration and posts kSEDIntervalChange event to inform other software * modules about the change. * - * @param[in] pollingConfig polling intervals configuration to be set + * @param[in] intervalsConfig intervals configuration to be set */ - CHIP_ERROR SetSEDPollingConfig(const ConnectivityManager::SEDPollingConfig & pollingConfig); + CHIP_ERROR SetSEDIntervalsConfig(const ConnectivityManager::SEDIntervalsConfig & intervalsConfig); /** - * Requests setting Sleepy End Device fast polling interval on or off. - * Every method call with onOff parameter set to true or false results in incrementing or decrementing the fast polling - * consumers counter. Fast polling mode is set if the consumers counter is bigger than 0. + * Requests setting Sleepy End Device active interval on or off. + * Every method call with onOff parameter set to true or false results in incrementing or decrementing the active mode + * consumers counter. Active mode is set if the consumers counter is bigger than 0. * - * @param[in] onOff true if fast polling should be enabled and false otherwise. + * @param[in] onOff true if active mode should be enabled and false otherwise. */ - CHIP_ERROR RequestSEDFastPollingMode(bool onOff); + CHIP_ERROR RequestSEDActiveMode(bool onOff); #endif bool HaveMeshConnectivity(); @@ -390,19 +390,19 @@ inline CHIP_ERROR ThreadStackManager::SetThreadDeviceType(ConnectivityManager::T } #if CHIP_DEVICE_CONFIG_ENABLE_SED -inline CHIP_ERROR ThreadStackManager::GetSEDPollingConfig(ConnectivityManager::SEDPollingConfig & pollingConfig) +inline CHIP_ERROR ThreadStackManager::GetSEDIntervalsConfig(ConnectivityManager::SEDIntervalsConfig & intervalsConfig) { - return static_cast(this)->_GetSEDPollingConfig(pollingConfig); + return static_cast(this)->_GetSEDIntervalsConfig(intervalsConfig); } -inline CHIP_ERROR ThreadStackManager::SetSEDPollingConfig(const ConnectivityManager::SEDPollingConfig & pollingConfig) +inline CHIP_ERROR ThreadStackManager::SetSEDIntervalsConfig(const ConnectivityManager::SEDIntervalsConfig & intervalsConfig) { - return static_cast(this)->_SetSEDPollingConfig(pollingConfig); + return static_cast(this)->_SetSEDIntervalsConfig(intervalsConfig); } -inline CHIP_ERROR ThreadStackManager::RequestSEDFastPollingMode(bool onOff) +inline CHIP_ERROR ThreadStackManager::RequestSEDActiveMode(bool onOff) { - return static_cast(this)->_RequestSEDFastPollingMode(onOff); + return static_cast(this)->_RequestSEDActiveMode(onOff); } #endif diff --git a/src/include/platform/internal/GenericConnectivityManagerImpl_NoThread.h b/src/include/platform/internal/GenericConnectivityManagerImpl_NoThread.h index e25dcb4ff8aea4..e4bb6cf9f31e80 100644 --- a/src/include/platform/internal/GenericConnectivityManagerImpl_NoThread.h +++ b/src/include/platform/internal/GenericConnectivityManagerImpl_NoThread.h @@ -50,9 +50,9 @@ class GenericConnectivityManagerImpl_NoThread bool _IsThreadApplicationControlled(void); ConnectivityManager::ThreadDeviceType _GetThreadDeviceType(void); CHIP_ERROR _SetThreadDeviceType(ConnectivityManager::ThreadDeviceType deviceType); - CHIP_ERROR _GetSEDPollingConfig(ConnectivityManager::SEDPollingConfig & pollingConfig); - CHIP_ERROR _SetSEDPollingConfig(const ConnectivityManager::SEDPollingConfig & pollingConfig); - CHIP_ERROR _RequestSEDFastPollingMode(bool onOff); + CHIP_ERROR _GetSEDIntervalsConfig(ConnectivityManager::SEDIntervalsConfig & intervalsConfig); + CHIP_ERROR _SetSEDIntervalsConfig(const ConnectivityManager::SEDIntervalsConfig & intervalsConfig); + CHIP_ERROR _RequestSEDActiveMode(bool onOff); bool _IsThreadAttached(void); bool _IsThreadProvisioned(void); void _ErasePersistentInfo(void); @@ -116,21 +116,21 @@ GenericConnectivityManagerImpl_NoThread::_SetThreadDeviceType(Connect } template -inline CHIP_ERROR -GenericConnectivityManagerImpl_NoThread::_GetSEDPollingConfig(ConnectivityManager::SEDPollingConfig & pollingConfig) +inline CHIP_ERROR GenericConnectivityManagerImpl_NoThread::_GetSEDIntervalsConfig( + ConnectivityManager::SEDIntervalsConfig & intervalsConfig) { return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; } template -inline CHIP_ERROR GenericConnectivityManagerImpl_NoThread::_SetSEDPollingConfig( - const ConnectivityManager::SEDPollingConfig & pollingConfig) +inline CHIP_ERROR GenericConnectivityManagerImpl_NoThread::_SetSEDIntervalsConfig( + const ConnectivityManager::SEDIntervalsConfig & intervalsConfig) { return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; } template -inline CHIP_ERROR GenericConnectivityManagerImpl_NoThread::_RequestSEDFastPollingMode(bool onOff) +inline CHIP_ERROR GenericConnectivityManagerImpl_NoThread::_RequestSEDActiveMode(bool onOff) { return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; } diff --git a/src/include/platform/internal/GenericConnectivityManagerImpl_Thread.h b/src/include/platform/internal/GenericConnectivityManagerImpl_Thread.h index 2c34aa81b921f8..84cf4f04da31aa 100644 --- a/src/include/platform/internal/GenericConnectivityManagerImpl_Thread.h +++ b/src/include/platform/internal/GenericConnectivityManagerImpl_Thread.h @@ -64,9 +64,9 @@ class GenericConnectivityManagerImpl_Thread ConnectivityManager::ThreadDeviceType _GetThreadDeviceType(); CHIP_ERROR _SetThreadDeviceType(ConnectivityManager::ThreadDeviceType deviceType); #if CHIP_DEVICE_CONFIG_ENABLE_SED - CHIP_ERROR _GetSEDPollingConfig(ConnectivityManager::SEDPollingConfig & pollingConfig); - CHIP_ERROR _SetSEDPollingConfig(const ConnectivityManager::SEDPollingConfig & pollingConfig); - CHIP_ERROR _RequestSEDFastPollingMode(bool onOff); + CHIP_ERROR _GetSEDIntervalsConfig(ConnectivityManager::SEDIntervalsConfig & intervalsConfig); + CHIP_ERROR _SetSEDIntervalsConfig(const ConnectivityManager::SEDIntervalsConfig & intervalsConfig); + CHIP_ERROR _RequestSEDActiveMode(bool onOff); #endif bool _IsThreadAttached(); bool _IsThreadProvisioned(); @@ -144,22 +144,22 @@ GenericConnectivityManagerImpl_Thread::_SetThreadDeviceType(Connectiv #if CHIP_DEVICE_CONFIG_ENABLE_SED template inline CHIP_ERROR -GenericConnectivityManagerImpl_Thread::_GetSEDPollingConfig(ConnectivityManager::SEDPollingConfig & pollingConfig) +GenericConnectivityManagerImpl_Thread::_GetSEDIntervalsConfig(ConnectivityManager::SEDIntervalsConfig & intervalsConfig) { - return ThreadStackMgrImpl().GetSEDPollingConfig(pollingConfig); + return ThreadStackMgrImpl().GetSEDIntervalsConfig(intervalsConfig); } template -inline CHIP_ERROR -GenericConnectivityManagerImpl_Thread::_SetSEDPollingConfig(const ConnectivityManager::SEDPollingConfig & pollingConfig) +inline CHIP_ERROR GenericConnectivityManagerImpl_Thread::_SetSEDIntervalsConfig( + const ConnectivityManager::SEDIntervalsConfig & intervalsConfig) { - return ThreadStackMgrImpl().SetSEDPollingConfig(pollingConfig); + return ThreadStackMgrImpl().SetSEDIntervalsConfig(intervalsConfig); } template -inline CHIP_ERROR GenericConnectivityManagerImpl_Thread::_RequestSEDFastPollingMode(bool onOff) +inline CHIP_ERROR GenericConnectivityManagerImpl_Thread::_RequestSEDActiveMode(bool onOff) { - return ThreadStackMgrImpl().RequestSEDFastPollingMode(onOff); + return ThreadStackMgrImpl().RequestSEDActiveMode(onOff); } #endif diff --git a/src/messaging/ExchangeContext.cpp b/src/messaging/ExchangeContext.cpp index a89bf15ed2bc2c..d9dc3d86ade96a 100644 --- a/src/messaging/ExchangeContext.cpp +++ b/src/messaging/ExchangeContext.cpp @@ -85,13 +85,13 @@ void ExchangeContext::SetResponseTimeout(Timeout timeout) } #if CONFIG_DEVICE_LAYER && CHIP_DEVICE_CONFIG_ENABLE_SED -void ExchangeContext::UpdateSEDPollingMode() +void ExchangeContext::UpdateSEDIntervalMode() { if (!HasSessionHandle()) { // After the session has been deleted, no further communication can occur on the exchange, - // so withdraw a SED fast-polling mode request. - UpdateSEDPollingMode(false); + // so withdraw a SED active mode request. + UpdateSEDIntervalMode(false); return; } @@ -110,15 +110,15 @@ void ExchangeContext::UpdateSEDPollingMode() } VerifyOrReturn(address.GetTransportType() != Transport::Type::kBle); - UpdateSEDPollingMode(IsResponseExpected() || IsSendExpected() || IsMessageNotAcked()); + UpdateSEDIntervalMode(IsResponseExpected() || IsSendExpected() || IsMessageNotAcked()); } -void ExchangeContext::UpdateSEDPollingMode(bool fastPollingMode) +void ExchangeContext::UpdateSEDIntervalMode(bool activeMode) { - if (fastPollingMode != IsRequestingFastPollingMode()) + if (activeMode != IsRequestingActiveMode()) { - SetRequestingFastPollingMode(fastPollingMode); - DeviceLayer::ConnectivityMgr().RequestSEDFastPollingMode(fastPollingMode); + SetRequestingActiveMode(activeMode); + DeviceLayer::ConnectivityMgr().RequestSEDActiveMode(activeMode); } } #endif @@ -302,8 +302,8 @@ ExchangeContext::~ExchangeContext() VerifyOrDie(!IsAckPending()); #if CONFIG_DEVICE_LAYER && CHIP_DEVICE_CONFIG_ENABLE_SED - // Make sure that the exchange withdraws the request for Sleepy End Device fast-polling mode. - UpdateSEDPollingMode(false); + // Make sure that the exchange withdraws the request for Sleepy End Device active mode. + UpdateSEDIntervalMode(false); #endif // Ideally, in this scenario, the retransmit table should @@ -500,7 +500,7 @@ CHIP_ERROR ExchangeContext::HandleMessage(uint32_t messageCounter, const Payload void ExchangeContext::MessageHandled() { #if CONFIG_DEVICE_LAYER && CHIP_DEVICE_CONFIG_ENABLE_SED - UpdateSEDPollingMode(); + UpdateSEDIntervalMode(); #endif if (mFlags.Has(Flags::kFlagClosed) || IsResponseExpected() || IsSendExpected()) diff --git a/src/messaging/ExchangeContext.h b/src/messaging/ExchangeContext.h index 4e616194584037..9369c86c2c511a 100644 --- a/src/messaging/ExchangeContext.h +++ b/src/messaging/ExchangeContext.h @@ -242,23 +242,23 @@ class DLL_EXPORT ExchangeContext : public ReliableMessageContext, void MessageHandled(); /** - * Updates Sleepy End Device polling mode in the following way: + * Updates Sleepy End Device intervals mode in the following way: * - does nothing for exchanges over Bluetooth LE - * - requests fast-polling (active) mode if there are more messages, + * - requests active mode if there are more messages, * including MRP acknowledgements, expected to be sent or received on * this exchange. - * - withdraws the request for fast-polling (active) mode, otherwise. + * - withdraws the request for active mode, otherwise. */ - void UpdateSEDPollingMode(); + void UpdateSEDIntervalMode(); /** - * Requests or withdraws the request for Sleepy End Device fast-polling mode + * Requests or withdraws the request for Sleepy End Device active mode * based on the argument value. * - * Note that the device switches to the slow-polling (idle) mode if no - * exchange nor other component requests the fast-polling mode. + * Note that the device switches to the idle mode if no + * exchange nor other component requests the active mode. */ - void UpdateSEDPollingMode(bool fastPollingMode); + void UpdateSEDIntervalMode(bool activeMode); }; } // namespace Messaging diff --git a/src/messaging/ReliableMessageContext.h b/src/messaging/ReliableMessageContext.h index 19bfeca4e993c3..1a75c0c4cd2945 100644 --- a/src/messaging/ReliableMessageContext.h +++ b/src/messaging/ReliableMessageContext.h @@ -153,11 +153,11 @@ class ReliableMessageContext /// Set whether there is a message hasn't been acknowledged. void SetMessageNotAcked(bool messageNotAcked); - /// Set if this exchange is requesting Sleepy End Device fast-polling mode - void SetRequestingFastPollingMode(bool fastPollingMode); + /// Set if this exchange is requesting Sleepy End Device active mode + void SetRequestingActiveMode(bool activeMode); - /// Determine whether this exchange is requesting Sleepy End Device fast-polling mode - bool IsRequestingFastPollingMode() const; + /// Determine whether this exchange is requesting Sleepy End Device active mode + bool IsRequestingActiveMode() const; /** * Get the reliable message manager that corresponds to this reliable @@ -204,8 +204,8 @@ class ReliableMessageContext /// When set, we have had Close() or Abort() called on us already. kFlagClosed = (1u << 10), - /// When set, signifies that the exchange is requesting Sleepy End Device fast-polling mode. - kFlagFastPollingMode = (1u << 11), + /// When set, signifies that the exchange is requesting Sleepy End Device active mode. + kFlagActiveMode = (1u << 11), }; BitFlags mFlags; // Internal state flags @@ -267,9 +267,9 @@ inline bool ReliableMessageContext::HasPiggybackAckPending() const return mFlags.Has(Flags::kFlagAckMessageCounterIsValid); } -inline bool ReliableMessageContext::IsRequestingFastPollingMode() const +inline bool ReliableMessageContext::IsRequestingActiveMode() const { - return mFlags.Has(Flags::kFlagFastPollingMode); + return mFlags.Has(Flags::kFlagActiveMode); } inline void ReliableMessageContext::SetAutoRequestAck(bool autoReqAck) @@ -297,9 +297,9 @@ inline void ReliableMessageContext::SetMessageNotAcked(bool messageNotAcked) mFlags.Set(Flags::kFlagMessageNotAcked, messageNotAcked); } -inline void ReliableMessageContext::SetRequestingFastPollingMode(bool fastPollingMode) +inline void ReliableMessageContext::SetRequestingActiveMode(bool activeMode) { - mFlags.Set(Flags::kFlagFastPollingMode, fastPollingMode); + mFlags.Set(Flags::kFlagActiveMode, activeMode); } } // namespace Messaging diff --git a/src/messaging/ReliableMessageProtocolConfig.cpp b/src/messaging/ReliableMessageProtocolConfig.cpp index 3404ad97623957..6132a240cbaed3 100644 --- a/src/messaging/ReliableMessageProtocolConfig.cpp +++ b/src/messaging/ReliableMessageProtocolConfig.cpp @@ -37,14 +37,14 @@ ReliableMessageProtocolConfig GetLocalMRPConfig() CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL); #if CHIP_DEVICE_CONFIG_ENABLE_SED - DeviceLayer::ConnectivityManager::SEDPollingConfig sedPollingConfig; + DeviceLayer::ConnectivityManager::SEDIntervalsConfig sedIntervalsConfig; - if (DeviceLayer::ConnectivityMgr().GetSEDPollingConfig(sedPollingConfig) == CHIP_NO_ERROR) + if (DeviceLayer::ConnectivityMgr().GetSEDIntervalsConfig(sedIntervalsConfig) == CHIP_NO_ERROR) { - // Increase default MRP retry intervals by SED polling intervals. That is, intervals for + // Increase default MRP retry intervals by SED intervals. That is, intervals for // which the device can be at sleep and not be able to receive any messages). - config.mIdleRetransTimeout += sedPollingConfig.SlowPollingIntervalMS; - config.mActiveRetransTimeout += sedPollingConfig.FastPollingIntervalMS; + config.mIdleRetransTimeout += sedIntervalsConfig.IdleIntervalMS; + config.mActiveRetransTimeout += sedIntervalsConfig.ActiveIntervalMS; } #endif diff --git a/src/platform/Linux/ThreadStackManagerImpl.cpp b/src/platform/Linux/ThreadStackManagerImpl.cpp index acc7dbe7830516..da9705b5b60794 100644 --- a/src/platform/Linux/ThreadStackManagerImpl.cpp +++ b/src/platform/Linux/ThreadStackManagerImpl.cpp @@ -480,27 +480,27 @@ CHIP_ERROR ThreadStackManagerImpl::_SetThreadDeviceType(ConnectivityManager::Thr } #if CHIP_DEVICE_CONFIG_ENABLE_SED -CHIP_ERROR ThreadStackManagerImpl::_GetSEDPollingConfig(ConnectivityManager::SEDPollingConfig & pollingConfig) +CHIP_ERROR ThreadStackManagerImpl::_GetSEDIntervalsConfig(ConnectivityManager::SEDIntervalsConfig & intervalsConfig) { - (void) pollingConfig; + (void) intervalsConfig; - ChipLogError(DeviceLayer, "Polling config is not supported on linux"); + ChipLogError(DeviceLayer, "SED intervals config is not supported on linux"); return CHIP_ERROR_NOT_IMPLEMENTED; } -CHIP_ERROR ThreadStackManagerImpl::_SetSEDPollingConfig(const ConnectivityManager::SEDPollingConfig & pollingConfig) +CHIP_ERROR ThreadStackManagerImpl::_SetSEDIntervalsConfig(const ConnectivityManager::SEDIntervalsConfig & intervalsConfig) { - (void) pollingConfig; + (void) intervalsConfig; - ChipLogError(DeviceLayer, "Polling config is not supported on linux"); + ChipLogError(DeviceLayer, "SED intervals config is not supported on linux"); return CHIP_ERROR_NOT_IMPLEMENTED; } -CHIP_ERROR ThreadStackManagerImpl::_RequestSEDFastPollingMode(bool onOff) +CHIP_ERROR ThreadStackManagerImpl::_RequestSEDActiveMode(bool onOff) { (void) onOff; - ChipLogError(DeviceLayer, "Polling config is not supported on linux"); + ChipLogError(DeviceLayer, "SED intervals config is not supported on linux"); return CHIP_ERROR_NOT_IMPLEMENTED; } #endif diff --git a/src/platform/Linux/ThreadStackManagerImpl.h b/src/platform/Linux/ThreadStackManagerImpl.h index f112c065a65de5..cb86c1e9e695c8 100644 --- a/src/platform/Linux/ThreadStackManagerImpl.h +++ b/src/platform/Linux/ThreadStackManagerImpl.h @@ -87,9 +87,9 @@ class ThreadStackManagerImpl : public ThreadStackManager CHIP_ERROR _SetThreadDeviceType(ConnectivityManager::ThreadDeviceType deviceType); #if CHIP_DEVICE_CONFIG_ENABLE_SED - CHIP_ERROR _GetSEDPollingConfig(ConnectivityManager::SEDPollingConfig & pollingConfig); - CHIP_ERROR _SetSEDPollingConfig(const ConnectivityManager::SEDPollingConfig & pollingConfig); - CHIP_ERROR _RequestSEDFastPollingMode(bool onOff); + CHIP_ERROR _GetSEDIntervalsConfig(ConnectivityManager::SEDIntervalsConfig & intervalsConfig); + CHIP_ERROR _SetSEDIntervalsConfig(const ConnectivityManager::SEDIntervalsConfig & intervalsConfig); + CHIP_ERROR _RequestSEDActiveMode(bool onOff); #endif bool _HaveMeshConnectivity(); diff --git a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.cpp b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.cpp index 97be1912c22f0e..d066b9d5bf0514 100644 --- a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.cpp +++ b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.cpp @@ -469,6 +469,9 @@ ConnectivityManager::ThreadDeviceType GenericThreadStackManagerImpl_OpenThread::_SetThreadDeviceType(Connec #endif case ConnectivityManager::kThreadDeviceType_MinimalEndDevice: case ConnectivityManager::kThreadDeviceType_SleepyEndDevice: + case ConnectivityManager::kThreadDeviceType_SynchronizedSleepyEndDevice: break; default: ExitNow(err = CHIP_ERROR_INVALID_ARGUMENT); @@ -514,6 +518,9 @@ GenericThreadStackManagerImpl_OpenThread::_SetThreadDeviceType(Connec case ConnectivityManager::kThreadDeviceType_SleepyEndDevice: deviceTypeStr = "SLEEPY END DEVICE"; break; + case ConnectivityManager::kThreadDeviceType_SynchronizedSleepyEndDevice: + deviceTypeStr = "SYNCHRONIZED SLEEPY END DEVICE"; + break; default: deviceTypeStr = "(unknown)"; break; @@ -542,6 +549,7 @@ GenericThreadStackManagerImpl_OpenThread::_SetThreadDeviceType(Connec linkMode.mRxOnWhenIdle = true; break; case ConnectivityManager::kThreadDeviceType_SleepyEndDevice: + case ConnectivityManager::kThreadDeviceType_SynchronizedSleepyEndDevice: linkMode.mDeviceType = false; linkMode.mRxOnWhenIdle = false; break; @@ -1636,14 +1644,14 @@ CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::DoInit(otInstanc mOTInst = otInst; #if CHIP_DEVICE_CONFIG_ENABLE_SED - ConnectivityManager::SEDPollingConfig sedPollingConfig; + ConnectivityManager::SEDIntervalsConfig sedIntervalsConfig; using namespace System::Clock::Literals; - sedPollingConfig.FastPollingIntervalMS = CHIP_DEVICE_CONFIG_SED_FAST_POLLING_INTERVAL; - sedPollingConfig.SlowPollingIntervalMS = CHIP_DEVICE_CONFIG_SED_SLOW_POLLING_INTERVAL; - err = _SetSEDPollingConfig(sedPollingConfig); + sedIntervalsConfig.ActiveIntervalMS = CHIP_DEVICE_CONFIG_SED_ACTIVE_INTERVAL; + sedIntervalsConfig.IdleIntervalMS = CHIP_DEVICE_CONFIG_SED_IDLE_INTERVAL; + err = _SetSEDIntervalsConfig(sedIntervalsConfig); if (err != CHIP_NO_ERROR) { - ChipLogError(DeviceLayer, "Sleepy end device polling config set failed: %s", ErrorStr(err)); + ChipLogError(DeviceLayer, "Sleepy end device intervals config set failed: %s", ErrorStr(err)); } SuccessOrExit(err); #endif @@ -1682,6 +1690,7 @@ CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::DoInit(otInstanc initNetworkCommissioningThreadDriver(); exit: + ChipLogProgress(DeviceLayer, "OpenThread started: %s", otThreadErrorToString(otErr)); return err; } @@ -1701,31 +1710,31 @@ bool GenericThreadStackManagerImpl_OpenThread::IsThreadInterfaceUpNoL #if CHIP_DEVICE_CONFIG_ENABLE_SED template -CHIP_ERROR -GenericThreadStackManagerImpl_OpenThread::_GetSEDPollingConfig(ConnectivityManager::SEDPollingConfig & pollingConfig) +CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::_GetSEDIntervalsConfig( + ConnectivityManager::SEDIntervalsConfig & intervalsConfig) { - pollingConfig = mPollingConfig; + intervalsConfig = mIntervalsConfig; return CHIP_NO_ERROR; } template -CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::_SetSEDPollingConfig( - const ConnectivityManager::SEDPollingConfig & pollingConfig) +CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::_SetSEDIntervalsConfig( + const ConnectivityManager::SEDIntervalsConfig & intervalsConfig) { using namespace System::Clock::Literals; - if ((pollingConfig.SlowPollingIntervalMS < pollingConfig.FastPollingIntervalMS) || - (pollingConfig.SlowPollingIntervalMS == 0_ms32) || (pollingConfig.FastPollingIntervalMS == 0_ms32)) + if ((intervalsConfig.IdleIntervalMS < intervalsConfig.ActiveIntervalMS) || (intervalsConfig.IdleIntervalMS == 0_ms32) || + (intervalsConfig.ActiveIntervalMS == 0_ms32)) { return CHIP_ERROR_INVALID_ARGUMENT; } - mPollingConfig = pollingConfig; + mIntervalsConfig = intervalsConfig; - CHIP_ERROR err = SetSEDPollingMode(mPollingMode); + CHIP_ERROR err = SetSEDIntervalMode(mIntervalsMode); if (err == CHIP_NO_ERROR) { ChipDeviceEvent event; - event.Type = DeviceEventType::kSEDPollingIntervalChange; + event.Type = DeviceEventType::kSEDIntervalChange; err = chip::DeviceLayer::PlatformMgr().PostEvent(&event); } @@ -1733,65 +1742,79 @@ CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::_SetSEDPollingCo } template -CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::SetSEDPollingMode(ConnectivityManager::SEDPollingMode pollingType) +CHIP_ERROR +GenericThreadStackManagerImpl_OpenThread::SetSEDIntervalMode(ConnectivityManager::SEDIntervalMode intervalType) { CHIP_ERROR err = CHIP_NO_ERROR; System::Clock::Milliseconds32 interval; - if (pollingType == ConnectivityManager::SEDPollingMode::Idle) + if (intervalType == ConnectivityManager::SEDIntervalMode::Idle) { - interval = mPollingConfig.SlowPollingIntervalMS; + interval = mIntervalsConfig.IdleIntervalMS; } - else if (pollingType == ConnectivityManager::SEDPollingMode::Active) + else if (intervalType == ConnectivityManager::SEDIntervalMode::Active) { - interval = mPollingConfig.FastPollingIntervalMS; + interval = mIntervalsConfig.ActiveIntervalMS; } else { return CHIP_ERROR_INVALID_ARGUMENT; } - mPollingMode = pollingType; + mIntervalsMode = intervalType; Impl()->LockThreadStack(); - uint32_t curPollingIntervalMS = otLinkGetPollPeriod(mOTInst); +// For Thread devices, the intervals are defined as: +// * poll period for SED devices that polls for data to the parent +// * CSL period for SSED devices that listen for messages in scheduled time slots. +#if CHIP_DEVICE_CONFIG_THREAD_SSED + // Get CSL period in units of 10 symbols, convert it to microseconds and divide by 1000 to get milliseconds. + uint32_t curIntervalMS = otLinkCslGetPeriod(mOTInst) * OT_US_PER_TEN_SYMBOLS / 1000; +#else + uint32_t curIntervalMS = otLinkGetPollPeriod(mOTInst); +#endif - if (interval.count() != curPollingIntervalMS) + if (interval.count() != curIntervalMS) { +#if CHIP_DEVICE_CONFIG_THREAD_SSED + // Set CSL period in units of 10 symbols, convert it to microseconds and divide by 1000 to get milliseconds. + otError otErr = otLinkCslSetPeriod(mOTInst, interval.count() * 1000 / OT_US_PER_TEN_SYMBOLS); +#else otError otErr = otLinkSetPollPeriod(mOTInst, interval.count()); - err = MapOpenThreadError(otErr); +#endif + err = MapOpenThreadError(otErr); } Impl()->UnlockThreadStack(); - if (interval.count() != curPollingIntervalMS) + if (interval.count() != curIntervalMS) { - ChipLogProgress(DeviceLayer, "OpenThread polling interval set to %" PRId32 "ms", interval.count()); + ChipLogProgress(DeviceLayer, "OpenThread SED interval set to %" PRId32 "ms", interval.count()); } return err; } template -CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::_RequestSEDFastPollingMode(bool onOff) +CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::_RequestSEDActiveMode(bool onOff) { CHIP_ERROR err = CHIP_NO_ERROR; - ConnectivityManager::SEDPollingMode mode; + ConnectivityManager::SEDIntervalMode mode; if (onOff) { - mFastPollingConsumers++; + mActiveModeConsumers++; } else { - if (mFastPollingConsumers > 0) - mFastPollingConsumers--; + if (mActiveModeConsumers > 0) + mActiveModeConsumers--; } - mode = mFastPollingConsumers > 0 ? ConnectivityManager::SEDPollingMode::Active : ConnectivityManager::SEDPollingMode::Idle; + mode = mActiveModeConsumers > 0 ? ConnectivityManager::SEDIntervalMode::Active : ConnectivityManager::SEDIntervalMode::Idle; - if (mPollingMode != mode) - err = SetSEDPollingMode(mode); + if (mIntervalsMode != mode) + err = SetSEDIntervalMode(mode); return err; } diff --git a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.h b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.h index e3395ec147145c..397658b146ee5f 100644 --- a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.h +++ b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.h @@ -101,9 +101,9 @@ class GenericThreadStackManagerImpl_OpenThread void _UpdateNetworkStatus(); #if CHIP_DEVICE_CONFIG_ENABLE_SED - CHIP_ERROR _GetSEDPollingConfig(ConnectivityManager::SEDPollingConfig & pollingConfig); - CHIP_ERROR _SetSEDPollingConfig(const ConnectivityManager::SEDPollingConfig & pollingConfig); - CHIP_ERROR _RequestSEDFastPollingMode(bool onOff); + CHIP_ERROR _GetSEDIntervalsConfig(ConnectivityManager::SEDIntervalsConfig & intervalsConfig); + CHIP_ERROR _SetSEDIntervalsConfig(const ConnectivityManager::SEDIntervalsConfig & intervalsConfig); + CHIP_ERROR _RequestSEDActiveMode(bool onOff); #endif bool _HaveMeshConnectivity(void); @@ -157,9 +157,9 @@ class GenericThreadStackManagerImpl_OpenThread NetworkCommissioning::Internal::BaseDriver::NetworkStatusChangeCallback * mpStatusChangeCallback = nullptr; #if CHIP_DEVICE_CONFIG_ENABLE_SED - ConnectivityManager::SEDPollingConfig mPollingConfig; - ConnectivityManager::SEDPollingMode mPollingMode = ConnectivityManager::SEDPollingMode::Idle; - uint32_t mFastPollingConsumers = 0; + ConnectivityManager::SEDIntervalsConfig mIntervalsConfig; + ConnectivityManager::SEDIntervalMode mIntervalsMode = ConnectivityManager::SEDIntervalMode::Idle; + uint32_t mActiveModeConsumers = 0; #endif #if CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT @@ -271,7 +271,7 @@ class GenericThreadStackManagerImpl_OpenThread void OnJoinerComplete(otError aError); #if CHIP_DEVICE_CONFIG_ENABLE_SED - CHIP_ERROR SetSEDPollingMode(ConnectivityManager::SEDPollingMode pollingType); + CHIP_ERROR SetSEDIntervalMode(ConnectivityManager::SEDIntervalMode intervalType); #endif inline ImplClass * Impl() { return static_cast(this); } diff --git a/src/platform/nrfconnect/CHIPDevicePlatformConfig.h b/src/platform/nrfconnect/CHIPDevicePlatformConfig.h index c3d87d1c0de72b..7d40dd01c15b41 100644 --- a/src/platform/nrfconnect/CHIPDevicePlatformConfig.h +++ b/src/platform/nrfconnect/CHIPDevicePlatformConfig.h @@ -117,6 +117,7 @@ #ifdef CONFIG_CHIP_ENABLE_SLEEPY_END_DEVICE_SUPPORT #define CHIP_DEVICE_CONFIG_ENABLE_SED 1 +#define CHIP_DEVICE_CONFIG_THREAD_SSED CONFIG_CHIP_THREAD_SSED #endif // CONFIG_CHIP_ENABLE_SLEEPY_END_DEVICE_SUPPORT #ifdef CONFIG_CHIP_COMMISSIONABLE_DEVICE_TYPE From 0124bf2e005f8c834191df903c0f30feb5164a84 Mon Sep 17 00:00:00 2001 From: Kamil Kasperczyk Date: Wed, 20 Apr 2022 14:50:19 +0200 Subject: [PATCH 2/3] Added dependencies between SSED and CSL --- config/zephyr/Kconfig | 19 ++++++++++--------- ...nericThreadStackManagerImpl_OpenThread.cpp | 10 ++++++---- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/config/zephyr/Kconfig b/config/zephyr/Kconfig index 8bfa06ad923d70..b47aa808439ea2 100644 --- a/config/zephyr/Kconfig +++ b/config/zephyr/Kconfig @@ -1,17 +1,17 @@ # # Copyright (c) 2021 Project CHIP Authors # -# Licensed under the Apache License, Version 2.0(the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http: // www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. # menuconfig CHIP @@ -141,6 +141,7 @@ config CHIP_ENABLE_SLEEPY_END_DEVICE_SUPPORT config CHIP_THREAD_SSED bool "Enable Thread Synchronized Sleepy End Device support" + depends on OPENTHREAD_CSL_RECEIVER && CHIP_ENABLE_SLEEPY_END_DEVICE_SUPPORT help Enables Thread Synchronized Sleepy End Device support in Matter. diff --git a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.cpp b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.cpp index d066b9d5bf0514..cee03474b28fff 100644 --- a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.cpp +++ b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.cpp @@ -469,8 +469,10 @@ ConnectivityManager::ThreadDeviceType GenericThreadStackManagerImpl_OpenThread::SetSEDIntervalMode(Connecti Impl()->LockThreadStack(); // For Thread devices, the intervals are defined as: -// * poll period for SED devices that polls for data to the parent +// * poll period for SED devices that polls for data to the parent // * CSL period for SSED devices that listen for messages in scheduled time slots. -#if CHIP_DEVICE_CONFIG_THREAD_SSED +#if CHIP_DEVICE_CONFIG_THREAD_SSED && OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE // Get CSL period in units of 10 symbols, convert it to microseconds and divide by 1000 to get milliseconds. uint32_t curIntervalMS = otLinkCslGetPeriod(mOTInst) * OT_US_PER_TEN_SYMBOLS / 1000; #else @@ -1776,8 +1778,8 @@ GenericThreadStackManagerImpl_OpenThread::SetSEDIntervalMode(Connecti if (interval.count() != curIntervalMS) { -#if CHIP_DEVICE_CONFIG_THREAD_SSED - // Set CSL period in units of 10 symbols, convert it to microseconds and divide by 1000 to get milliseconds. +#if CHIP_DEVICE_CONFIG_THREAD_SSED && OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE + // Set CSL period in units of 10 symbols, convert it to microseconds and divide by 1000 to get milliseconds. otError otErr = otLinkCslSetPeriod(mOTInst, interval.count() * 1000 / OT_US_PER_TEN_SYMBOLS); #else otError otErr = otLinkSetPollPeriod(mOTInst, interval.count()); From fc85bff1e08150cd36cacdc448d879ef0246297b Mon Sep 17 00:00:00 2001 From: Kamil Kasperczyk Date: Thu, 21 Apr 2022 13:23:53 +0200 Subject: [PATCH 3/3] Addressed review comments --- .../GenericThreadStackManagerImpl_OpenThread.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.cpp b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.cpp index cee03474b28fff..1ad335a69312e3 100644 --- a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.cpp +++ b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.cpp @@ -469,7 +469,7 @@ ConnectivityManager::ThreadDeviceType GenericThreadStackManagerImpl_OpenThread::_SetThreadDeviceType(Connec #endif case ConnectivityManager::kThreadDeviceType_MinimalEndDevice: case ConnectivityManager::kThreadDeviceType_SleepyEndDevice: +#if CHIP_DEVICE_CONFIG_THREAD_SSED case ConnectivityManager::kThreadDeviceType_SynchronizedSleepyEndDevice: +#endif break; default: ExitNow(err = CHIP_ERROR_INVALID_ARGUMENT); @@ -520,9 +522,11 @@ GenericThreadStackManagerImpl_OpenThread::_SetThreadDeviceType(Connec case ConnectivityManager::kThreadDeviceType_SleepyEndDevice: deviceTypeStr = "SLEEPY END DEVICE"; break; +#if CHIP_DEVICE_CONFIG_THREAD_SSED case ConnectivityManager::kThreadDeviceType_SynchronizedSleepyEndDevice: deviceTypeStr = "SYNCHRONIZED SLEEPY END DEVICE"; break; +#endif default: deviceTypeStr = "(unknown)"; break; @@ -1653,7 +1657,7 @@ CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::DoInit(otInstanc err = _SetSEDIntervalsConfig(sedIntervalsConfig); if (err != CHIP_NO_ERROR) { - ChipLogError(DeviceLayer, "Sleepy end device intervals config set failed: %s", ErrorStr(err)); + ChipLogError(DeviceLayer, "Failed to set sleepy end device intervals: %s", ErrorStr(err)); } SuccessOrExit(err); #endif @@ -1767,9 +1771,9 @@ GenericThreadStackManagerImpl_OpenThread::SetSEDIntervalMode(Connecti Impl()->LockThreadStack(); // For Thread devices, the intervals are defined as: -// * poll period for SED devices that polls for data to the parent +// * poll period for SED devices that poll the parent for data // * CSL period for SSED devices that listen for messages in scheduled time slots. -#if CHIP_DEVICE_CONFIG_THREAD_SSED && OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE +#if CHIP_DEVICE_CONFIG_THREAD_SSED // Get CSL period in units of 10 symbols, convert it to microseconds and divide by 1000 to get milliseconds. uint32_t curIntervalMS = otLinkCslGetPeriod(mOTInst) * OT_US_PER_TEN_SYMBOLS / 1000; #else @@ -1778,7 +1782,7 @@ GenericThreadStackManagerImpl_OpenThread::SetSEDIntervalMode(Connecti if (interval.count() != curIntervalMS) { -#if CHIP_DEVICE_CONFIG_THREAD_SSED && OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE +#if CHIP_DEVICE_CONFIG_THREAD_SSED // Set CSL period in units of 10 symbols, convert it to microseconds and divide by 1000 to get milliseconds. otError otErr = otLinkCslSetPeriod(mOTInst, interval.count() * 1000 / OT_US_PER_TEN_SYMBOLS); #else