From 3406886dcbfa6d986bd1e0e38870e22f35b6943a Mon Sep 17 00:00:00 2001 From: Junior Martinez <67972863+jmartinez-silabs@users.noreply.github.com> Date: Mon, 10 Jul 2023 17:31:05 -0400 Subject: [PATCH] ICD manager Implemenation (#27283) * Add Events for ICD (WIP) * Rename SED defines, Add some timer funcionality to Extend a existing timer. Implemented ICDModes and initial operationalState logic WIP * Change SetFastPolling and SetSlowPolling to setPollingInterval with a param. Call is handled by ICD Manager. Replace the sed ifdef by icd for silabs platform WIP * Fix a bunch of dependencies, includes and build issues WIP * Use a init function instead of the constructor, as the attributes value aren't ready * Add a Keep active mechanism for commisisoning window and failsafe * cleanup, add app user wakeup change #ifdef to #if fix missing rename. add // nogncheck on some conditional include Fix some error caught by the ci * Addresses comments + conditional define for tests * SetPollingInterval causes issue for apps that has both thread and wifi. Priority to the thread imp for now. Needs to be reworked * Rebase, It brings updated system Apis, And addresse most of the comments * Stay active when an exchange context expect a response. * Update The message rx handling event naming. Move related ICD events to PublicEventTypes for the time being * #if ICD_SERVER the icd related event posts * Address comments and nits --- .../k32w/k32w0/include/CHIPProjectConfig.h | 4 +- .../light-switch-app/silabs/src/AppTask.cpp | 2 +- examples/lighting-app/silabs/src/AppTask.cpp | 2 +- .../k32w/k32w0/include/CHIPProjectConfig.h | 4 +- examples/lock-app/silabs/src/AppTask.cpp | 2 +- .../silabs/ICDSubscriptionCallback.cpp | 2 +- .../silabs/SiWx917/BaseApplication.cpp | 26 +-- examples/platform/silabs/efr32/BUILD.gn | 3 +- .../platform/silabs/efr32/BaseApplication.cpp | 42 +++-- .../platform/silabs/efr32/matter_config.cpp | 6 +- .../efr32/project_include/OpenThreadConfig.h | 4 +- .../platform/silabs/efr32/rs911x/rsi_if.c | 4 +- .../platform/silabs/efr32/rs911x/wfx_rsi.h | 4 +- .../silabs/efr32/rs911x/wfx_rsi_host.c | 4 +- .../platform/silabs/efr32/wf200/host_if.cpp | 4 +- .../smoke-co-alarm-app/silabs/src/AppTask.cpp | 2 +- examples/thermostat/silabs/src/AppTask.cpp | 2 +- scripts/build/builders/efr32.py | 2 +- scripts/examples/gn_silabs_example.sh | 6 +- src/app/BUILD.gn | 1 + src/app/FailSafeContext.cpp | 13 ++ src/app/icd/BUILD.gn | 18 +- src/app/icd/ICDEventManager.cpp | 69 +++++++- src/app/icd/ICDEventManager.h | 2 +- src/app/icd/ICDManager.cpp | 158 +++++++++++++++++- src/app/icd/ICDManager.h | 55 +++++- src/app/server/CommissioningWindowManager.cpp | 16 +- src/app/server/Dnssd.cpp | 4 +- src/app/server/Server.cpp | 6 +- src/app/server/Server.h | 4 +- src/app/util/IcdMonitoringTable.cpp | 6 + src/app/util/IcdMonitoringTable.h | 6 + src/include/platform/CHIPDeviceConfig.h | 21 +-- src/include/platform/CHIPDeviceEvent.h | 66 +++++++- src/include/platform/ConnectivityManager.h | 11 ++ src/include/platform/ThreadStackManager.h | 12 +- .../GenericConnectivityManagerImpl_Thread.h | 12 ++ .../GenericConnectivityManagerImpl_WiFi.h | 12 ++ src/messaging/BUILD.gn | 5 + src/messaging/ExchangeContext.cpp | 65 ++++++- src/messaging/ReliableMessageMgr.cpp | 10 +- .../ReliableMessageProtocolConfig.cpp | 13 +- src/platform/Linux/ThreadStackManagerImpl.cpp | 8 + src/platform/Linux/ThreadStackManagerImpl.h | 3 + ...GenericThreadStackManagerImpl_OpenThread.h | 3 + ...nericThreadStackManagerImpl_OpenThread.hpp | 59 ++++++- .../nrfconnect/CHIPDevicePlatformConfig.h | 12 +- .../silabs/CHIPDevicePlatformConfig.h | 20 +-- src/platform/silabs/ConnectivityManagerImpl.h | 9 +- .../silabs/ConnectivityManagerImpl_WIFI.cpp | 31 +--- .../silabs/efr32/wifi/wfx_host_events.h | 4 +- .../telink/CHIPDevicePlatformConfig.h | 12 +- third_party/silabs/SiWx917_sdk.gni | 14 +- third_party/silabs/efr32_sdk.gni | 7 +- 54 files changed, 707 insertions(+), 185 deletions(-) diff --git a/examples/contact-sensor-app/nxp/k32w/k32w0/include/CHIPProjectConfig.h b/examples/contact-sensor-app/nxp/k32w/k32w0/include/CHIPProjectConfig.h index 62262725f397f2..71960deda7e3a5 100644 --- a/examples/contact-sensor-app/nxp/k32w/k32w0/include/CHIPProjectConfig.h +++ b/examples/contact-sensor-app/nxp/k32w/k32w0/include/CHIPProjectConfig.h @@ -191,8 +191,8 @@ #define CHIP_CONFIG_MAX_FABRICS 5 // 5 is the minimum number of supported fabrics #define CHIP_DEVICE_CONFIG_ENABLE_SED 1 -#define CHIP_DEVICE_CONFIG_SED_IDLE_INTERVAL 1000_ms32 -#define CHIP_DEVICE_CONFIG_SED_ACTIVE_INTERVAL 100_ms32 +#define CHIP_DEVICE_CONFIG_ICD_SLOW_POLL_INTERVAL 1000_ms32 +#define CHIP_DEVICE_CONFIG_ICD_FAST_POLL_INTERVAL 100_ms32 /** * @def CHIP_IM_MAX_NUM_COMMAND_HANDLER * diff --git a/examples/light-switch-app/silabs/src/AppTask.cpp b/examples/light-switch-app/silabs/src/AppTask.cpp index e64c7da0c220a9..2f8d01275863be 100644 --- a/examples/light-switch-app/silabs/src/AppTask.cpp +++ b/examples/light-switch-app/silabs/src/AppTask.cpp @@ -119,7 +119,7 @@ void AppTask::AppTaskMain(void * pvParameter) appError(err); } -#if !(defined(CHIP_DEVICE_CONFIG_ENABLE_SED) && CHIP_DEVICE_CONFIG_ENABLE_SED) +#if !(defined(CHIP_CONFIG_ENABLE_ICD_SERVER) && CHIP_CONFIG_ENABLE_ICD_SERVER) sAppTask.StartStatusLEDTimer(); #endif diff --git a/examples/lighting-app/silabs/src/AppTask.cpp b/examples/lighting-app/silabs/src/AppTask.cpp index af6bbdf8af38ea..c3797797644b5b 100644 --- a/examples/lighting-app/silabs/src/AppTask.cpp +++ b/examples/lighting-app/silabs/src/AppTask.cpp @@ -126,7 +126,7 @@ void AppTask::AppTaskMain(void * pvParameter) appError(err); } -#if !(defined(CHIP_DEVICE_CONFIG_ENABLE_SED) && CHIP_DEVICE_CONFIG_ENABLE_SED) +#if !(defined(CHIP_CONFIG_ENABLE_ICD_SERVER) && CHIP_CONFIG_ENABLE_ICD_SERVER) sAppTask.StartStatusLEDTimer(); #endif diff --git a/examples/lock-app/nxp/k32w/k32w0/include/CHIPProjectConfig.h b/examples/lock-app/nxp/k32w/k32w0/include/CHIPProjectConfig.h index 0ce39a8e498993..a25fa7e12f1498 100644 --- a/examples/lock-app/nxp/k32w/k32w0/include/CHIPProjectConfig.h +++ b/examples/lock-app/nxp/k32w/k32w0/include/CHIPProjectConfig.h @@ -182,8 +182,8 @@ #define CHIP_CONFIG_MAX_FABRICS 5 // 5 is the minimum number of supported fabrics #define CHIP_DEVICE_CONFIG_ENABLE_SED 1 -#define CHIP_DEVICE_CONFIG_SED_IDLE_INTERVAL 1000_ms32 -#define CHIP_DEVICE_CONFIG_SED_ACTIVE_INTERVAL 100_ms32 +#define CHIP_DEVICE_CONFIG_ICD_SLOW_POLL_INTERVAL 1000_ms32 +#define CHIP_DEVICE_CONFIG_ICD_FAST_POLL_INTERVAL 100_ms32 /** * CHIP_CONFIG_EVENT_LOGGING_DEFAULT_IMPORTANCE diff --git a/examples/lock-app/silabs/src/AppTask.cpp b/examples/lock-app/silabs/src/AppTask.cpp index b3c3423079a08d..8afe7d6cc8d9e5 100644 --- a/examples/lock-app/silabs/src/AppTask.cpp +++ b/examples/lock-app/silabs/src/AppTask.cpp @@ -219,7 +219,7 @@ void AppTask::AppTaskMain(void * pvParameter) appError(err); } -#if !(defined(CHIP_DEVICE_CONFIG_ENABLE_SED) && CHIP_DEVICE_CONFIG_ENABLE_SED) +#if !(defined(CHIP_CONFIG_ENABLE_ICD_SERVER) && CHIP_CONFIG_ENABLE_ICD_SERVER) sAppTask.StartStatusLEDTimer(); #endif diff --git a/examples/platform/silabs/ICDSubscriptionCallback.cpp b/examples/platform/silabs/ICDSubscriptionCallback.cpp index 30fbf683e6e8dc..735246f042af87 100644 --- a/examples/platform/silabs/ICDSubscriptionCallback.cpp +++ b/examples/platform/silabs/ICDSubscriptionCallback.cpp @@ -24,7 +24,7 @@ CHIP_ERROR ICDSubscriptionCallback::OnSubscriptionRequested(chip::app::ReadHandl { using namespace chip::System::Clock; - Seconds32 interval_s32 = std::chrono::duration_cast(CHIP_DEVICE_CONFIG_SED_IDLE_INTERVAL); + Seconds32 interval_s32 = std::chrono::duration_cast(CHIP_DEVICE_CONFIG_ICD_SLOW_POLL_INTERVAL); if (interval_s32 > Seconds16::max()) { diff --git a/examples/platform/silabs/SiWx917/BaseApplication.cpp b/examples/platform/silabs/SiWx917/BaseApplication.cpp index 418729236d8340..feab970b95fe5b 100644 --- a/examples/platform/silabs/SiWx917/BaseApplication.cpp +++ b/examples/platform/silabs/SiWx917/BaseApplication.cpp @@ -94,14 +94,14 @@ app::Clusters::NetworkCommissioning::Instance sWiFiNetworkCommissioningInstance(0 /* Endpoint Id */, &(NetworkCommissioning::SlWiFiDriver::GetInstance())); #endif /* SL_WIFI */ -#if !(defined(CHIP_DEVICE_CONFIG_ENABLE_SED) && CHIP_DEVICE_CONFIG_ENABLE_SED) +#if !(defined(CHIP_CONFIG_ENABLE_ICD_SERVER) && CHIP_CONFIG_ENABLE_ICD_SERVER) bool sIsProvisioned = false; bool sIsEnabled = false; bool sIsAttached = false; bool sHaveBLEConnections = false; -#endif // CHIP_DEVICE_CONFIG_ENABLE_SED +#endif // CHIP_CONFIG_ENABLE_ICD_SERVER uint8_t sAppEventQueueBuffer[APP_EVENT_QUEUE_SIZE * sizeof(AppEvent)]; StaticQueue_t sAppEventQueueStruct; @@ -257,9 +257,9 @@ void BaseApplication::FunctionFactoryReset(void) // Actually trigger Factory Reset mFunction = kFunction_NoneSelected; -#if CHIP_DEVICE_CONFIG_ENABLE_SED == 1 +#if CHIP_CONFIG_ENABLE_ICD_SERVER == 1 StopStatusLEDTimer(); -#endif // CHIP_DEVICE_CONFIG_ENABLE_SED +#endif // CHIP_CONFIG_ENABLE_ICD_SERVER chip::Server::GetInstance().ScheduleFactoryReset(); } @@ -314,7 +314,7 @@ bool BaseApplication::ActivateStatusLedPatterns() } #endif // EMBER_AF_PLUGIN_IDENTIFY_SERVER -#if !(defined(CHIP_DEVICE_CONFIG_ENABLE_SED) && CHIP_DEVICE_CONFIG_ENABLE_SED) +#if !(defined(CHIP_CONFIG_ENABLE_ICD_SERVER) && CHIP_CONFIG_ENABLE_ICD_SERVER) // Identify Patterns have priority over Status patterns if (!isPatternSet) { @@ -340,7 +340,7 @@ bool BaseApplication::ActivateStatusLedPatterns() } isPatternSet = true; } -#endif // CHIP_DEVICE_CONFIG_ENABLE_SED +#endif // CHIP_CONFIG_ENABLE_ICD_SERVER #endif // ENABLE_WSTK_LEDS) && SL_CATALOG_SIMPLE_LED_LED1_PRESENT return isPatternSet; } @@ -352,7 +352,7 @@ void BaseApplication::LightEventHandler() // locked while these values are queried. However we use a non-blocking // lock request (TryLockCHIPStack()) to avoid blocking other UI activities // when the CHIP task is busy (e.g. with a long crypto operation). -#if !(defined(CHIP_DEVICE_CONFIG_ENABLE_SED) && CHIP_DEVICE_CONFIG_ENABLE_SED) +#if !(defined(CHIP_CONFIG_ENABLE_ICD_SERVER) && CHIP_CONFIG_ENABLE_ICD_SERVER) if (PlatformMgr().TryLockChipStack()) { #ifdef SL_WIFI @@ -368,7 +368,7 @@ void BaseApplication::LightEventHandler() sHaveBLEConnections = (ConnectivityMgr().NumBLEConnections() != 0); PlatformMgr().UnlockChipStack(); } -#endif // CHIP_DEVICE_CONFIG_ENABLE_SED +#endif // CHIP_CONFIG_ENABLE_ICD_SERVER // Update the status LED if factory reset has not been initiated. // @@ -441,7 +441,7 @@ void BaseApplication::ButtonHandler(AppEvent * aEvent) { mFunction = kFunction_NoneSelected; -#if CHIP_DEVICE_CONFIG_ENABLE_SED == 1 +#if CHIP_CONFIG_ENABLE_ICD_SERVER == 1 StopStatusLEDTimer(); #endif @@ -514,7 +514,7 @@ void BaseApplication::OnIdentifyStart(Identify * identify) { ChipLogProgress(Zcl, "onIdentifyStart"); -#if CHIP_DEVICE_CONFIG_ENABLE_SED == 1 +#if CHIP_CONFIG_ENABLE_ICD_SERVER == 1 StartStatusLEDTimer(); #endif } @@ -523,7 +523,7 @@ void BaseApplication::OnIdentifyStop(Identify * identify) { ChipLogProgress(Zcl, "onIdentifyStop"); -#if CHIP_DEVICE_CONFIG_ENABLE_SED == 1 +#if CHIP_CONFIG_ENABLE_ICD_SERVER == 1 StopStatusLEDTimer(); #endif } @@ -533,7 +533,7 @@ void BaseApplication::OnTriggerIdentifyEffectCompleted(chip::System::Layer * sys ChipLogProgress(Zcl, "Trigger Identify Complete"); sIdentifyEffect = Clusters::Identify::EffectIdentifierEnum::kStopEffect; -#if CHIP_DEVICE_CONFIG_ENABLE_SED == 1 +#if CHIP_CONFIG_ENABLE_ICD_SERVER == 1 StopStatusLEDTimer(); #endif } @@ -547,7 +547,7 @@ void BaseApplication::OnTriggerIdentifyEffect(Identify * identify) ChipLogDetail(AppServer, "Identify Effect Variant unsupported. Using default"); } -#if CHIP_DEVICE_CONFIG_ENABLE_SED == 1 +#if CHIP_CONFIG_ENABLE_ICD_SERVER == 1 StartStatusLEDTimer(); #endif diff --git a/examples/platform/silabs/efr32/BUILD.gn b/examples/platform/silabs/efr32/BUILD.gn index 43c46639bd4522..38d77a45e19498 100644 --- a/examples/platform/silabs/efr32/BUILD.gn +++ b/examples/platform/silabs/efr32/BUILD.gn @@ -15,6 +15,7 @@ import("//build_overrides/chip.gni") import("//build_overrides/efr32_sdk.gni") import("${chip_root}/examples/common/pigweed/pigweed_rpcs.gni") +import("${chip_root}/src/app/icd/icd.gni") import("${chip_root}/src/lib/lib.gni") import("${chip_root}/src/platform/device.gni") import("${efr32_sdk_build_root}/efr32_sdk.gni") @@ -40,7 +41,7 @@ declare_args() { chip_default_wifi_psk = "" # Use default handler to negotiate subscription max interval - chip_config_use_icd_subscription_callbacks = enable_sleepy_device + chip_config_use_icd_subscription_callbacks = chip_enable_icd_server # Enable TestEventTrigger in GeneralDiagnostics cluster silabs_test_event_trigger_enabled = false diff --git a/examples/platform/silabs/efr32/BaseApplication.cpp b/examples/platform/silabs/efr32/BaseApplication.cpp index 4dc1fc95c81d1b..77a91236554ae5 100644 --- a/examples/platform/silabs/efr32/BaseApplication.cpp +++ b/examples/platform/silabs/efr32/BaseApplication.cpp @@ -107,11 +107,11 @@ app::Clusters::NetworkCommissioning::Instance bool sIsProvisioned = false; -#if !(defined(CHIP_DEVICE_CONFIG_ENABLE_SED) && CHIP_DEVICE_CONFIG_ENABLE_SED) +#if !(defined(CHIP_CONFIG_ENABLE_ICD_SERVER) && CHIP_CONFIG_ENABLE_ICD_SERVER) bool sIsEnabled = false; bool sIsAttached = false; bool sHaveBLEConnections = false; -#endif // CHIP_DEVICE_CONFIG_ENABLE_SED +#endif // CHIP_CONFIG_ENABLE_ICD_SERVER uint8_t sAppEventQueueBuffer[APP_EVENT_QUEUE_SIZE * sizeof(AppEvent)]; StaticQueue_t sAppEventQueueStruct; @@ -273,9 +273,9 @@ void BaseApplication::FunctionEventHandler(AppEvent * aEvent) // cancel, if required. StartFunctionTimer(FACTORY_RESET_CANCEL_WINDOW_TIMEOUT); -#if CHIP_DEVICE_CONFIG_ENABLE_SED == 1 +#if CHIP_CONFIG_ENABLE_ICD_SERVER == 1 StartStatusLEDTimer(); -#endif // CHIP_DEVICE_CONFIG_ENABLE_SED +#endif // CHIP_CONFIG_ENABLE_ICD_SERVER mFunction = kFunction_FactoryReset; @@ -291,9 +291,9 @@ void BaseApplication::FunctionEventHandler(AppEvent * aEvent) // Actually trigger Factory Reset mFunction = kFunction_NoneSelected; -#if CHIP_DEVICE_CONFIG_ENABLE_SED == 1 +#if CHIP_CONFIG_ENABLE_ICD_SERVER == 1 StopStatusLEDTimer(); -#endif // CHIP_DEVICE_CONFIG_ENABLE_SED +#endif // CHIP_CONFIG_ENABLE_ICD_SERVER ScheduleFactoryReset(); } @@ -349,7 +349,7 @@ bool BaseApplication::ActivateStatusLedPatterns() } #endif // EMBER_AF_PLUGIN_IDENTIFY_SERVER -#if !(defined(CHIP_DEVICE_CONFIG_ENABLE_SED) && CHIP_DEVICE_CONFIG_ENABLE_SED) +#if !(defined(CHIP_CONFIG_ENABLE_ICD_SERVER) && CHIP_CONFIG_ENABLE_ICD_SERVER) // Identify Patterns have priority over Status patterns if (!isPatternSet) { @@ -375,7 +375,7 @@ bool BaseApplication::ActivateStatusLedPatterns() } isPatternSet = true; } -#endif // CHIP_DEVICE_CONFIG_ENABLE_SED +#endif // CHIP_CONFIG_ENABLE_ICD_SERVER #endif // ENABLE_WSTK_LEDS) && SL_CATALOG_SIMPLE_LED_LED1_PRESENT return isPatternSet; } @@ -387,7 +387,7 @@ void BaseApplication::LightEventHandler() // locked while these values are queried. However we use a non-blocking // lock request (TryLockCHIPStack()) to avoid blocking other UI activities // when the CHIP task is busy (e.g. with a long crypto operation). -#if !(defined(CHIP_DEVICE_CONFIG_ENABLE_SED) && CHIP_DEVICE_CONFIG_ENABLE_SED) +#if !(defined(CHIP_CONFIG_ENABLE_ICD_SERVER) && CHIP_CONFIG_ENABLE_ICD_SERVER) if (PlatformMgr().TryLockChipStack()) { #ifdef SL_WIFI @@ -402,7 +402,7 @@ void BaseApplication::LightEventHandler() sHaveBLEConnections = (ConnectivityMgr().NumBLEConnections() != 0); PlatformMgr().UnlockChipStack(); } -#endif // CHIP_DEVICE_CONFIG_ENABLE_SED +#endif // CHIP_CONFIG_ENABLE_ICD_SERVER #if defined(ENABLE_WSTK_LEDS) && defined(SL_CATALOG_SIMPLE_LED_LED1_PRESENT) // Update the status LED if factory reset has not been initiated. @@ -472,13 +472,23 @@ void BaseApplication::ButtonHandler(AppEvent * aEvent) SILABS_LOG("Failed to open the Basic Commissioning Window"); } } - else { SILABS_LOG("Network is already provisioned, Ble advertissement not enabled"); } + else + { + SILABS_LOG("Network is already provisioned, Ble advertissement not enabled"); + DeviceLayer::ChipDeviceEvent event; + event.Type = DeviceLayer::DeviceEventType::kAppWakeUpEvent; + CHIP_ERROR err = DeviceLayer::PlatformMgr().PostEvent(&event); + if (err != CHIP_NO_ERROR) + { + ChipLogError(AppServer, "Failed to post App wake up Event event %" CHIP_ERROR_FORMAT, err.Format()); + } + } } else if (mFunctionTimerActive && mFunction == kFunction_FactoryReset) { CancelFunctionTimer(); -#if CHIP_DEVICE_CONFIG_ENABLE_SED == 1 +#if CHIP_CONFIG_ENABLE_ICD_SERVER == 1 StopStatusLEDTimer(); #endif @@ -548,7 +558,7 @@ void BaseApplication::OnIdentifyStart(Identify * identify) { ChipLogProgress(Zcl, "onIdentifyStart"); -#if CHIP_DEVICE_CONFIG_ENABLE_SED == 1 +#if CHIP_CONFIG_ENABLE_ICD_SERVER == 1 StartStatusLEDTimer(); #endif } @@ -557,7 +567,7 @@ void BaseApplication::OnIdentifyStop(Identify * identify) { ChipLogProgress(Zcl, "onIdentifyStop"); -#if CHIP_DEVICE_CONFIG_ENABLE_SED == 1 +#if CHIP_CONFIG_ENABLE_ICD_SERVER == 1 StopStatusLEDTimer(); #endif } @@ -567,7 +577,7 @@ void BaseApplication::OnTriggerIdentifyEffectCompleted(chip::System::Layer * sys ChipLogProgress(Zcl, "Trigger Identify Complete"); sIdentifyEffect = Clusters::Identify::EffectIdentifierEnum::kStopEffect; -#if CHIP_DEVICE_CONFIG_ENABLE_SED == 1 +#if CHIP_CONFIG_ENABLE_ICD_SERVER == 1 StopStatusLEDTimer(); #endif } @@ -581,7 +591,7 @@ void BaseApplication::OnTriggerIdentifyEffect(Identify * identify) ChipLogDetail(AppServer, "Identify Effect Variant unsupported. Using default"); } -#if CHIP_DEVICE_CONFIG_ENABLE_SED == 1 +#if CHIP_CONFIG_ENABLE_ICD_SERVER == 1 StartStatusLEDTimer(); #endif diff --git a/examples/platform/silabs/efr32/matter_config.cpp b/examples/platform/silabs/efr32/matter_config.cpp index 88da81bf787f1c..c876abd6eaea1b 100644 --- a/examples/platform/silabs/efr32/matter_config.cpp +++ b/examples/platform/silabs/efr32/matter_config.cpp @@ -100,11 +100,11 @@ CHIP_ERROR SilabsMatterConfig::InitOpenThread(void) #if CHIP_DEVICE_CONFIG_THREAD_FTD ReturnErrorOnFailure(ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_Router)); #else // CHIP_DEVICE_CONFIG_THREAD_FTD -#if CHIP_DEVICE_CONFIG_ENABLE_SED +#if CHIP_CONFIG_ENABLE_ICD_SERVER ReturnErrorOnFailure(ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_SleepyEndDevice)); -#else // CHIP_DEVICE_CONFIG_ENABLE_SED +#else // CHIP_CONFIG_ENABLE_ICD_SERVER ReturnErrorOnFailure(ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_MinimalEndDevice)); -#endif // CHIP_DEVICE_CONFIG_ENABLE_SED +#endif // CHIP_CONFIG_ENABLE_ICD_SERVER #endif // CHIP_DEVICE_CONFIG_THREAD_FTD SILABS_LOG("Starting OpenThread task"); diff --git a/examples/platform/silabs/efr32/project_include/OpenThreadConfig.h b/examples/platform/silabs/efr32/project_include/OpenThreadConfig.h index ea67df3ba27829..90ecfcbf712718 100644 --- a/examples/platform/silabs/efr32/project_include/OpenThreadConfig.h +++ b/examples/platform/silabs/efr32/project_include/OpenThreadConfig.h @@ -36,7 +36,7 @@ // Enable use of external heap allocator (calloc/free) for OpenThread. #define OPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE 1 -#if CHIP_DEVICE_CONFIG_ENABLE_SED +#if CHIP_CONFIG_ENABLE_ICD_SERVER #define OPENTHREAD_CONFIG_PARENT_SEARCH_ENABLE 0 @@ -46,7 +46,7 @@ // Timeout after 2 missed checkin or 4 mins if sleep interval is too short. #define OPENTHREAD_CONFIG_MLE_CHILD_TIMEOUT_DEFAULT ((SL_MLE_TIMEOUT_s < 120) ? 240 : ((SL_MLE_TIMEOUT_s * 2) + 1)) -#endif // CHIP_DEVICE_CONFIG_ENABLE_SED +#endif // CHIP_CONFIG_ENABLE_ICD_SERVER /****Uncomment below section for OpenThread Debug logs*/ // #define OPENTHREAD_CONFIG_LOG_LEVEL OT_LOG_LEVEL_DEBG diff --git a/examples/platform/silabs/efr32/rs911x/rsi_if.c b/examples/platform/silabs/efr32/rs911x/rsi_if.c index d0d5844448d618..900e07a42ce235 100644 --- a/examples/platform/silabs/efr32/rs911x/rsi_if.c +++ b/examples/platform/silabs/efr32/rs911x/rsi_if.c @@ -184,7 +184,7 @@ int32_t wfx_rsi_disconnect() return status; } -#if CHIP_DEVICE_CONFIG_ENABLE_SED +#if CHIP_CONFIG_ENABLE_ICD_SERVER /****************************************************************** * @fn wfx_rsi_power_save() * @brief @@ -215,7 +215,7 @@ int32_t wfx_rsi_power_save() SILABS_LOG("Powersave Config Success"); return status; } -#endif /* CHIP_DEVICE_CONFIG_ENABLE_SED */ +#endif /* CHIP_CONFIG_ENABLE_ICD_SERVER */ /****************************************************************** * @fn wfx_rsi_join_cb(uint16_t status, const uint8_t *buf, const uint16_t len) diff --git a/examples/platform/silabs/efr32/rs911x/wfx_rsi.h b/examples/platform/silabs/efr32/rs911x/wfx_rsi.h index cd18672faf42ba..d793244aa23cca 100644 --- a/examples/platform/silabs/efr32/rs911x/wfx_rsi.h +++ b/examples/platform/silabs/efr32/rs911x/wfx_rsi.h @@ -90,9 +90,9 @@ int32_t wfx_rsi_get_ap_info(wfx_wifi_scan_result_t * ap); int32_t wfx_rsi_get_ap_ext(wfx_wifi_scan_ext_t * extra_info); int32_t wfx_rsi_reset_count(); int32_t wfx_rsi_disconnect(); -#if CHIP_DEVICE_CONFIG_ENABLE_SED +#if CHIP_CONFIG_ENABLE_ICD_SERVER int32_t wfx_rsi_power_save(); -#endif /* CHIP_DEVICE_CONFIG_ENABLE_SED */ +#endif /* CHIP_CONFIG_ENABLE_ICD_SERVER */ #ifdef __cplusplus } diff --git a/examples/platform/silabs/efr32/rs911x/wfx_rsi_host.c b/examples/platform/silabs/efr32/rs911x/wfx_rsi_host.c index 80368c1b66734b..a448f3a0a45667 100644 --- a/examples/platform/silabs/efr32/rs911x/wfx_rsi_host.c +++ b/examples/platform/silabs/efr32/rs911x/wfx_rsi_host.c @@ -193,7 +193,7 @@ sl_status_t wfx_connect_to_ap(void) return SL_STATUS_OK; } -#if CHIP_DEVICE_CONFIG_ENABLE_SED +#if CHIP_CONFIG_ENABLE_ICD_SERVER /********************************************************************* * @fn sl_status_t wfx_power_save() * @brief @@ -210,7 +210,7 @@ sl_status_t wfx_power_save() } return SL_STATUS_OK; } -#endif /* CHIP_DEVICE_CONFIG_ENABLE_SED */ +#endif /* CHIP_CONFIG_ENABLE_ICD_SERVER */ /********************************************************************* * @fn void wfx_setup_ip6_link_local(sl_wfx_interface_t whichif) diff --git a/examples/platform/silabs/efr32/wf200/host_if.cpp b/examples/platform/silabs/efr32/wf200/host_if.cpp index c48c5754640de4..a8fd053e0c77c7 100644 --- a/examples/platform/silabs/efr32/wf200/host_if.cpp +++ b/examples/platform/silabs/efr32/wf200/host_if.cpp @@ -602,7 +602,7 @@ static void wfx_events_task(void * p_arg) retryJoin = 0; retryInterval = WLAN_MIN_RETRY_TIMER_MS; wfx_lwip_set_sta_link_up(); -#if CHIP_DEVICE_CONFIG_ENABLE_SED +#if CHIP_CONFIG_ENABLE_ICD_SERVER if (!(wfx_get_wifi_state() & SL_WFX_AP_INTERFACE_UP)) { // Enable the power save @@ -610,7 +610,7 @@ static void wfx_events_task(void * p_arg) sl_wfx_set_power_mode(WFM_PM_MODE_DTIM, WFM_PM_POLL_FAST_PS, BEACON_1); sl_wfx_enable_device_power_save(); } -#endif /* CHIP_DEVICE_CONFIG_ENABLE_SED */ +#endif /* CHIP_CONFIG_ENABLE_ICD_SERVER */ } if (flags & SL_WFX_DISCONNECT) diff --git a/examples/smoke-co-alarm-app/silabs/src/AppTask.cpp b/examples/smoke-co-alarm-app/silabs/src/AppTask.cpp index 4c5ee14f584d1b..21873ea7488c2c 100644 --- a/examples/smoke-co-alarm-app/silabs/src/AppTask.cpp +++ b/examples/smoke-co-alarm-app/silabs/src/AppTask.cpp @@ -122,7 +122,7 @@ void AppTask::AppTaskMain(void * pvParameter) appError(err); } -#if !(defined(CHIP_DEVICE_CONFIG_ENABLE_SED) && CHIP_DEVICE_CONFIG_ENABLE_SED) +#if !(defined(CHIP_CONFIG_ENABLE_ICD_SERVER) && CHIP_CONFIG_ENABLE_ICD_SERVER) sAppTask.StartStatusLEDTimer(); #endif diff --git a/examples/thermostat/silabs/src/AppTask.cpp b/examples/thermostat/silabs/src/AppTask.cpp index 77cd60f279dcf4..22d0bb3010b9ab 100644 --- a/examples/thermostat/silabs/src/AppTask.cpp +++ b/examples/thermostat/silabs/src/AppTask.cpp @@ -123,7 +123,7 @@ void AppTask::AppTaskMain(void * pvParameter) appError(err); } -#if !(defined(CHIP_DEVICE_CONFIG_ENABLE_SED) && CHIP_DEVICE_CONFIG_ENABLE_SED) +#if !(defined(CHIP_CONFIG_ENABLE_ICD_SERVER) && CHIP_CONFIG_ENABLE_ICD_SERVER) sAppTask.StartStatusLEDTimer(); #endif diff --git a/scripts/build/builders/efr32.py b/scripts/build/builders/efr32.py index e0058edc262e2b..0dc85cdf6d5623 100644 --- a/scripts/build/builders/efr32.py +++ b/scripts/build/builders/efr32.py @@ -158,7 +158,7 @@ def __init__(self, self.extra_gn_options.append('chip_enable_ota_requestor=true') if enable_sed: - self.extra_gn_options.append('enable_sleepy_device=true chip_openthread_ftd=false') + self.extra_gn_options.append('chip_enable_icd_server=true chip_openthread_ftd=false') if enable_low_power: self.extra_gn_options.append( diff --git a/scripts/examples/gn_silabs_example.sh b/scripts/examples/gn_silabs_example.sh index 06f6ee57599c23..1f181fc75564af 100755 --- a/scripts/examples/gn_silabs_example.sh +++ b/scripts/examples/gn_silabs_example.sh @@ -83,8 +83,8 @@ if [ "$#" == "0" ]; then Thresholds: 30 <= kvs_max_entries <= 255 show_qr_code Enables QR code on LCD for devices with an LCD - enable_sleepy_device - Enable Sleepy end device. (Default false) + chip_enable_icd_server + Configure has a Intermitently connected device. (Default false) Must also set chip_openthread_ftd=false use_rs9116 Build wifi example with extension board rs9116. (Default false) @@ -176,7 +176,7 @@ else shift ;; --sed) - optArgs+="enable_sleepy_device=true chip_openthread_ftd=false " + optArgs+="chip_enable_icd_server=true chip_openthread_ftd=false " shift ;; --low-power) diff --git a/src/app/BUILD.gn b/src/app/BUILD.gn index 30042e6ddfef47..8211d22bf707b7 100644 --- a/src/app/BUILD.gn +++ b/src/app/BUILD.gn @@ -56,6 +56,7 @@ buildconfig_header("app_buildconfig") { "CHIP_CONFIG_ACCESS_CONTROL_POLICY_LOGGING_VERBOSITY=${chip_access_control_policy_logging_verbosity}", "CHIP_CONFIG_PERSIST_SUBSCRIPTIONS=${chip_persist_subscriptions}", "CHIP_CONFIG_ENABLE_EVENTLIST_ATTRIBUTE=${enable_eventlist_attribute}", + "CHIP_CONFIG_ENABLE_ICD_SERVER=${chip_enable_icd_server}", ] } diff --git a/src/app/FailSafeContext.cpp b/src/app/FailSafeContext.cpp index 4e802e064c5d9d..d79a36f14f045b 100644 --- a/src/app/FailSafeContext.cpp +++ b/src/app/FailSafeContext.cpp @@ -60,6 +60,19 @@ void FailSafeContext::SetFailSafeArmed(bool armed) DeviceLayer::ConnectivityMgr().RequestSEDActiveMode(armed); } #endif // CHIP_DEVICE_CONFIG_ENABLE_SED +#if CHIP_CONFIG_ENABLE_ICD_SERVER + if (IsFailSafeArmed() != armed) + { + DeviceLayer::ChipDeviceEvent event; + event.Type = DeviceLayer::DeviceEventType::kFailSafeStateChanged; + event.FailSafeState.armed = armed; + CHIP_ERROR err = DeviceLayer::PlatformMgr().PostEvent(&event); + if (err != CHIP_NO_ERROR) + { + ChipLogError(AppServer, "Failed to post kFailSafeStateChanged event %" CHIP_ERROR_FORMAT, err.Format()); + } + } +#endif mFailSafeArmed = armed; } diff --git a/src/app/icd/BUILD.gn b/src/app/icd/BUILD.gn index 63157175f12e7b..d70f5077b75dea 100644 --- a/src/app/icd/BUILD.gn +++ b/src/app/icd/BUILD.gn @@ -25,13 +25,10 @@ source_set("manager-srcs") { "ICDManager.h", ] - public_deps = [ "${chip_root}/src/lib/core" ] -} - -# ICD Server Configuration -# All configurations necessary to the ICD Server featureset need to in this configuration -config("server-config") { - defines = [ "CHIP_CONFIG_ENABLE_ICD_SERVER" ] + public_deps = [ + "${chip_root}/src/lib/core", + "${chip_root}/src/platform:platform", + ] } # servers-srcs source-set contains all the sources and configurations necessary to build the ICD Server functionality @@ -44,10 +41,5 @@ source_set("server-srcs") { "ICDEventManager.h", ] - public_deps = [ - ":manager-srcs", - "${chip_root}/src/platform:platform", - ] - - public_configs = [ ":server-config" ] + public_deps = [ ":manager-srcs" ] } diff --git a/src/app/icd/ICDEventManager.cpp b/src/app/icd/ICDEventManager.cpp index 827276b81ebcfb..a8e4e11de5fb1b 100644 --- a/src/app/icd/ICDEventManager.cpp +++ b/src/app/icd/ICDEventManager.cpp @@ -22,12 +22,15 @@ using namespace chip::DeviceLayer; namespace chip { namespace app { +uint8_t ICDEventManager::expectedMsgCount = 0; +static_assert(UINT8_MAX >= CHIP_CONFIG_MAX_EXCHANGE_CONTEXTS, + "ICDEventManager::expectedMsgCount cannot hold count for the max exchange count"); + CHIP_ERROR ICDEventManager::Init(ICDManager * icdManager) { VerifyOrReturnError(icdManager != nullptr, CHIP_ERROR_INVALID_ARGUMENT); mICDManager = icdManager; - - PlatformMgr().AddEventHandler(ICDEventHandler, reinterpret_cast(nullptr)); + PlatformMgr().AddEventHandler(ICDEventHandler, reinterpret_cast(mICDManager)); return CHIP_NO_ERROR; } @@ -42,8 +45,66 @@ CHIP_ERROR ICDEventManager::Shutdown() void ICDEventManager::ICDEventHandler(const ChipDeviceEvent * event, intptr_t arg) { - // TODO -} + ICDManager * icdManager = reinterpret_cast(arg); + + if (icdManager == nullptr) + { + return; + } + switch (event->Type) + { + case DeviceEventType::kCommissioningWindowStatusChanged: + icdManager->SetKeepActiveModeRequirements(ICDManager::KeepActiveFlags::kCommissioningWindowOpen, + event->CommissioningWindowStatus.open); + break; + case DeviceEventType::kFailSafeStateChanged: + icdManager->SetKeepActiveModeRequirements(ICDManager::KeepActiveFlags::kFailSafeArmed, event->FailSafeState.armed); + break; + case DeviceEventType::kChipMsgSentEvent: + + // When we expect a response to a message sent, We keep the ICD in active mode until it is received + // Otherwise, just a kick off an active mode interval/active mode threshold + if (event->MessageSent.ExpectResponse) + { + expectedMsgCount++; + icdManager->SetKeepActiveModeRequirements(ICDManager::KeepActiveFlags::kExpectingMsgResponse, true); + } + else + { + icdManager->UpdateOperationState(ICDManager::OperationalState::ActiveMode); + } + break; + case DeviceEventType::kChipMsgRxEventHandled: + if (event->RxEventContext.clearsExpectedResponse) + { + if (expectedMsgCount > 0) + { + expectedMsgCount--; + } + else + { + // Should we assert? + ChipLogError(DeviceLayer, "No response was expected by the ICD Manager"); + } + + if (expectedMsgCount == 0) + { + icdManager->SetKeepActiveModeRequirements(ICDManager::KeepActiveFlags::kExpectingMsgResponse, false); + } + } + else if (event->RxEventContext.wasReceived) + { + icdManager->UpdateOperationState(ICDManager::OperationalState::ActiveMode); + } + + break; + case DeviceEventType::kAppWakeUpEvent: + icdManager->UpdateOperationState(ICDManager::OperationalState::ActiveMode); + break; + default: + break; + } +} } // namespace app } // namespace chip diff --git a/src/app/icd/ICDEventManager.h b/src/app/icd/ICDEventManager.h index c6a305d24d57a9..fffbbb8dc334fb 100644 --- a/src/app/icd/ICDEventManager.h +++ b/src/app/icd/ICDEventManager.h @@ -47,7 +47,7 @@ class ICDEventManager * Function dispatchs the event to the ICDManager member */ static void ICDEventHandler(const chip::DeviceLayer::ChipDeviceEvent * event, intptr_t arg); - + static uint8_t expectedMsgCount; ICDManager * mICDManager; }; diff --git a/src/app/icd/ICDManager.cpp b/src/app/icd/ICDManager.cpp index a71ca14457c546..297daa59d2fbf3 100644 --- a/src/app/icd/ICDManager.cpp +++ b/src/app/icd/ICDManager.cpp @@ -15,12 +15,168 @@ * limitations under the License. */ +#include +#include +#include #include +#include +#include +#include +#include +#include namespace chip { namespace app { -ICDManager::ICDManager() {} +using namespace chip::app; +using namespace chip::app::Clusters; +using namespace chip::app::Clusters::IcdManagement; +void ICDManager::ICDManager::Init() +{ + uint32_t activeModeInterval; + if (Attributes::ActiveModeInterval::Get(kRootEndpointId, &activeModeInterval) != EMBER_ZCL_STATUS_SUCCESS) + { + activeModeInterval = kMinActiveModeInterval; + } + VerifyOrDie(kFastPollingInterval.count() < activeModeInterval); + UpdateIcdMode(); + UpdateOperationState(OperationalState::ActiveMode); +} + +void ICDManager::ICDManager::Shutdown() +{ + // cancel any running timer of the icd + DeviceLayer::SystemLayer().CancelTimer(OnIdleModeDone, this); + DeviceLayer::SystemLayer().CancelTimer(OnActiveModeDone, this); + mIcdMode = ICDMode::SIT; + mOperationalState = OperationalState::IdleMode; +} + +bool ICDManager::SupportsCheckInProtocol() +{ + bool success; + uint32_t featureMap; + success = (Attributes::FeatureMap::Get(kRootEndpointId, &featureMap) == EMBER_ZCL_STATUS_SUCCESS); + + return success ? ((featureMap & to_underlying(Feature::kCheckInProtocolSupport)) != 0) : false; +} + +void ICDManager::UpdateIcdMode() +{ + assertChipStackLockedByCurrentThread(); + + ICDMode tempMode = ICDMode::SIT; + + // TODO ICD LIT FIX DEPENDENCY ISSUE with app/util/IcdMonitoringTable.h and app/server:server + // The Check In Protocol Feature is required and the slow polling interval shall also be greater than 15 seconds + // to run an ICD in LIT mode. + // if (kSlowPollingInterval > kICDSitModePollingThreashold && SupportsCheckInProtocol()) + // { + // // We can only get to LIT Mode, if at least one client is registered to the ICD device + // const auto & fabricTable = Server::GetInstance().GetFabricTable(); + // for (const auto & fabricInfo : fabricTable) + // { + // PersistentStorageDelegate & storage = Server::GetInstance().GetPersistentStorage(); + // IcdMonitoringTable table(storage, fabricInfo.GetFabricIndex(), 1); + // if (!table.IsEmpty()) + // { + // tempMode = ICDMode::LIT; + // break; + // } + // } + // } + mIcdMode = tempMode; +} + +void ICDManager::UpdateOperationState(OperationalState state) +{ + assertChipStackLockedByCurrentThread(); + // Active mode can be re-triggered. + VerifyOrReturn(mOperationalState != state || state == OperationalState::ActiveMode); + + if (state == OperationalState::IdleMode) + { + mOperationalState = OperationalState::IdleMode; + uint32_t idleModeInterval = 0; + if (Attributes::IdleModeInterval::Get(kRootEndpointId, &idleModeInterval) != EMBER_ZCL_STATUS_SUCCESS) + { + idleModeInterval = kMinIdleModeInterval; + } + DeviceLayer::SystemLayer().StartTimer(System::Clock::Timeout(idleModeInterval), OnIdleModeDone, this); + + CHIP_ERROR err = DeviceLayer::ConnectivityMgr().SetPollingInterval(GetSlowPollingInterval()); + if (err != CHIP_NO_ERROR) + { + ChipLogError(AppServer, "Failed to set Polling Interval: err %" CHIP_ERROR_FORMAT, err.Format()); + } + } + else if (state == OperationalState::ActiveMode) + { + if (mOperationalState == OperationalState::IdleMode) + { + // An event could have brought us to the active mode. + // Make sure the idle mode timer is stopped + DeviceLayer::SystemLayer().CancelTimer(OnIdleModeDone, this); + + mOperationalState = OperationalState::ActiveMode; + uint32_t activeModeInterval = 0; + if (Attributes::ActiveModeInterval::Get(kRootEndpointId, &activeModeInterval) != EMBER_ZCL_STATUS_SUCCESS) + { + activeModeInterval = kMinActiveModeInterval; + } + DeviceLayer::SystemLayer().StartTimer(System::Clock::Timeout(activeModeInterval), OnActiveModeDone, this); + + CHIP_ERROR err = DeviceLayer::ConnectivityMgr().SetPollingInterval(GetFastPollingInterval()); + if (err != CHIP_NO_ERROR) + { + ChipLogError(AppServer, "Failed to set Polling Interval: err %" CHIP_ERROR_FORMAT, err.Format()); + } + } + else + { + uint16_t activeModeThreshold = 0; + if (Attributes::ActiveModeThreshold::Get(kRootEndpointId, &activeModeThreshold) != EMBER_ZCL_STATUS_SUCCESS) + { + activeModeThreshold = kMinActiveModeThreshold; + } + DeviceLayer::SystemLayer().ExtendTimerTo(System::Clock::Timeout(activeModeThreshold), OnActiveModeDone, this); + } + } +} + +void ICDManager::SetKeepActiveModeRequirements(KeepActiveFlags flag, bool state) +{ + assertChipStackLockedByCurrentThread(); + + mKeepActiveFlags.Set(flag, state); + if (mOperationalState == OperationalState::IdleMode && mKeepActiveFlags.HasAny()) + { + UpdateOperationState(OperationalState::ActiveMode); + } + else if (mOperationalState == OperationalState::ActiveMode && !mKeepActiveFlags.HasAny() && + !DeviceLayer::SystemLayer().IsTimerActive(OnActiveModeDone, this)) + { + // The normal active period had ended and nothing else requires the system to be active. + UpdateOperationState(OperationalState::IdleMode); + } +} + +void ICDManager::OnIdleModeDone(System::Layer * aLayer, void * appState) +{ + ICDManager * pIcdManager = reinterpret_cast(appState); + pIcdManager->UpdateOperationState(OperationalState::ActiveMode); +} + +void ICDManager::OnActiveModeDone(System::Layer * aLayer, void * appState) +{ + ICDManager * pIcdManager = reinterpret_cast(appState); + + // Don't go to idle mode when we have a keep active requirement + if (!pIcdManager->mKeepActiveFlags.HasAny()) + { + pIcdManager->UpdateOperationState(OperationalState::IdleMode); + } +} } // namespace app } // namespace chip diff --git a/src/app/icd/ICDManager.h b/src/app/icd/ICDManager.h index 8c8e55916c3fa8..b7edf325f767b8 100644 --- a/src/app/icd/ICDManager.h +++ b/src/app/icd/ICDManager.h @@ -16,6 +16,11 @@ */ #pragma once +#include +#include +#include +#include + namespace chip { namespace app { @@ -25,9 +30,57 @@ namespace app { class ICDManager { public: - ICDManager(); + enum class OperationalState : uint8_t + { + IdleMode, + ActiveMode, + }; + + enum class ICDMode : uint8_t + { + SIT, // Short Interval Time ICD + LIT, // Long Interval Time ICD + }; + + enum class KeepActiveFlags : uint8_t + { + kCommissioningWindowOpen = 0x01, + kFailSafeArmed = 0x02, + kExpectingMsgResponse = 0x03, + }; + + ICDManager() {} + void Init(); + void Shutdown(); + void UpdateIcdMode(); + void UpdateOperationState(OperationalState state); + void SetKeepActiveModeRequirements(KeepActiveFlags flag, bool state); + bool IsKeepActive() { return mKeepActiveFlags.HasAny(); } + ICDMode GetIcdMode() { return mIcdMode; } + OperationalState GetOperationalState() { return mOperationalState; } + + static System::Clock::Milliseconds32 GetSlowPollingInterval() { return kSlowPollingInterval; } + static System::Clock::Milliseconds32 GetFastPollingInterval() { return kFastPollingInterval; } + +protected: + static void OnIdleModeDone(System::Layer * aLayer, void * appState); + static void OnActiveModeDone(System::Layer * aLayer, void * appState); private: + static constexpr System::Clock::Milliseconds32 kICDSitModePollingThreashold = System::Clock::Milliseconds32(15000); + static constexpr System::Clock::Milliseconds32 kSlowPollingInterval = CHIP_DEVICE_CONFIG_ICD_SLOW_POLL_INTERVAL; + static constexpr System::Clock::Milliseconds32 kFastPollingInterval = CHIP_DEVICE_CONFIG_ICD_FAST_POLL_INTERVAL; + + // Minimal constraint value of the the ICD attributes. + static constexpr uint32_t kMinIdleModeInterval = 500; + static constexpr uint32_t kMinActiveModeInterval = 300; + static constexpr uint16_t kMinActiveModeThreshold = 300; + + bool SupportsCheckInProtocol(); + + BitFlags mKeepActiveFlags{ 0 }; + OperationalState mOperationalState = OperationalState::IdleMode; + ICDMode mIcdMode = ICDMode::SIT; }; } // namespace app diff --git a/src/app/server/CommissioningWindowManager.cpp b/src/app/server/CommissioningWindowManager.cpp index 0b06dc6c070101..ea5ab150556bf1 100644 --- a/src/app/server/CommissioningWindowManager.cpp +++ b/src/app/server/CommissioningWindowManager.cpp @@ -564,7 +564,21 @@ void CommissioningWindowManager::ExpireFailSafeIfArmed() void CommissioningWindowManager::UpdateWindowStatus(CommissioningWindowStatusEnum aNewStatus) { CommissioningWindowStatusEnum oldClusterStatus = CommissioningWindowStatusForCluster(); - mWindowStatus = aNewStatus; + if (mWindowStatus != aNewStatus) + { + mWindowStatus = aNewStatus; +#if CHIP_CONFIG_ENABLE_ICD_SERVER + DeviceLayer::ChipDeviceEvent event; + event.Type = DeviceLayer::DeviceEventType::kCommissioningWindowStatusChanged; + event.CommissioningWindowStatus.open = (mWindowStatus != CommissioningWindowStatusEnum::kWindowNotOpen); + CHIP_ERROR err = DeviceLayer::PlatformMgr().PostEvent(&event); + if (err != CHIP_NO_ERROR) + { + ChipLogError(AppServer, "Failed to post kCommissioningWindowStatusChanged event %" CHIP_ERROR_FORMAT, err.Format()); + } +#endif // CHIP_CONFIG_ENABLE_ICD_SERVER + } + if (CommissioningWindowStatusForCluster() != oldClusterStatus) { // The Administrator Commissioning cluster is always on the root endpoint. diff --git a/src/app/server/Dnssd.cpp b/src/app/server/Dnssd.cpp index b2bb1eca1075d9..17c9b4a459af9e 100644 --- a/src/app/server/Dnssd.cpp +++ b/src/app/server/Dnssd.cpp @@ -50,8 +50,8 @@ void OnPlatformEvent(const DeviceLayer::ChipDeviceEvent * event) { case DeviceLayer::DeviceEventType::kDnssdInitialized: case DeviceLayer::DeviceEventType::kDnssdRestartNeeded: -#if CHIP_DEVICE_CONFIG_ENABLE_SED - case DeviceLayer::DeviceEventType::kSEDIntervalChange: +#if CHIP_CONFIG_ENABLE_ICD_SERVER + case DeviceLayer::DeviceEventType::kICDPollingIntervalChange: #endif app::DnssdServer::Instance().StartServer(); break; diff --git a/src/app/server/Server.cpp b/src/app/server/Server.cpp index 5eff5ea0be7344..948be1e4fe6cb3 100644 --- a/src/app/server/Server.cpp +++ b/src/app/server/Server.cpp @@ -248,7 +248,8 @@ CHIP_ERROR Server::Init(const ServerInitParams & initParams) } #endif // CHIP_CONFIG_ENABLE_SERVER_IM_EVENT -#ifdef CHIP_CONFIG_ENABLE_ICD_SERVER +#if CHIP_CONFIG_ENABLE_ICD_SERVER + mICDManager.Init(); mICDEventManager.Init(&mICDManager); #endif // CHIP_CONFIG_ENABLE_ICD_SERVER @@ -489,8 +490,9 @@ void Server::Shutdown() mAccessControl.Finish(); Access::ResetAccessControlToDefault(); Credentials::SetGroupDataProvider(nullptr); -#ifdef CHIP_CONFIG_ENABLE_ICD_SERVER +#if CHIP_CONFIG_ENABLE_ICD_SERVER mICDEventManager.Shutdown(); + mICDManager.Shutdown(); #endif // CHIP_CONFIG_ENABLE_ICD_SERVER mAttributePersister.Shutdown(); // TODO(16969): Remove chip::Platform::MemoryInit() call from Server class, it belongs to outer code diff --git a/src/app/server/Server.h b/src/app/server/Server.h index d2cdaacb7f48ea..9c4a3ee499dca3 100644 --- a/src/app/server/Server.h +++ b/src/app/server/Server.h @@ -65,7 +65,7 @@ #endif #include -#ifdef CHIP_CONFIG_ENABLE_ICD_SERVER +#if CHIP_CONFIG_ENABLE_ICD_SERVER #include // nogncheck #include // nogncheck #endif @@ -600,7 +600,7 @@ class Server Inet::InterfaceId mInterfaceId; System::Clock::Microseconds64 mInitTimestamp; -#ifdef CHIP_CONFIG_ENABLE_ICD_SERVER +#if CHIP_CONFIG_ENABLE_ICD_SERVER app::ICDEventManager mICDEventManager; app::ICDManager mICDManager; #endif // CHIP_CONFIG_ENABLE_ICD_SERVER diff --git a/src/app/util/IcdMonitoringTable.cpp b/src/app/util/IcdMonitoringTable.cpp index 2f208812db74f2..e861e78c2cbf2d 100644 --- a/src/app/util/IcdMonitoringTable.cpp +++ b/src/app/util/IcdMonitoringTable.cpp @@ -103,6 +103,12 @@ CHIP_ERROR IcdMonitoringTable::RemoveAll() return CHIP_NO_ERROR; } +bool IcdMonitoringTable::IsEmpty() +{ + IcdMonitoringEntry entry(this->mFabric); + return (this->Get(0, entry) == CHIP_ERROR_NOT_FOUND); +} + uint16_t IcdMonitoringTable::Limit() const { return mLimit; diff --git a/src/app/util/IcdMonitoringTable.h b/src/app/util/IcdMonitoringTable.h index b488d515759df8..a3a144937b4b04 100644 --- a/src/app/util/IcdMonitoringTable.h +++ b/src/app/util/IcdMonitoringTable.h @@ -110,6 +110,12 @@ struct IcdMonitoringTable */ CHIP_ERROR RemoveAll(); + /** + * @brief Check if the table is empty + * @return True when there is no entry in the table. False if there is at least one + */ + bool IsEmpty(); + /** * @return Maximum number of entries allowed in the RegisteredClients table. */ diff --git a/src/include/platform/CHIPDeviceConfig.h b/src/include/platform/CHIPDeviceConfig.h index a3512e8f944925..f9c963da7eddda 100644 --- a/src/include/platform/CHIPDeviceConfig.h +++ b/src/include/platform/CHIPDeviceConfig.h @@ -137,32 +137,23 @@ #endif /** - * CHIP_DEVICE_CONFIG_ENABLE_SED - * - * Enable support for sleepy end device behavior. - */ -#ifndef CHIP_DEVICE_CONFIG_ENABLE_SED -#define CHIP_DEVICE_CONFIG_ENABLE_SED 0 -#endif - -/** - * CHIP_DEVICE_CONFIG_SED_IDLE_INTERVAL + * CHIP_DEVICE_CONFIG_ICD_SLOW_POLL_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_IDLE_INTERVAL -#define CHIP_DEVICE_CONFIG_SED_IDLE_INTERVAL 5000_ms32 +#ifndef CHIP_DEVICE_CONFIG_ICD_SLOW_POLL_INTERVAL +#define CHIP_DEVICE_CONFIG_ICD_SLOW_POLL_INTERVAL System::Clock::Milliseconds32(5000) #endif /** - * CHIP_DEVICE_CONFIG_SED_ACTIVE_INTERVAL + * CHIP_DEVICE_CONFIG_ICD_FAST_POLL_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_ACTIVE_INTERVAL -#define CHIP_DEVICE_CONFIG_SED_ACTIVE_INTERVAL 200_ms32 +#ifndef CHIP_DEVICE_CONFIG_ICD_FAST_POLL_INTERVAL +#define CHIP_DEVICE_CONFIG_ICD_FAST_POLL_INTERVAL System::Clock::Milliseconds32(200) #endif /** diff --git a/src/include/platform/CHIPDeviceEvent.h b/src/include/platform/CHIPDeviceEvent.h index 2ca528f2cd0924..47f32fc1346d39 100644 --- a/src/include/platform/CHIPDeviceEvent.h +++ b/src/include/platform/CHIPDeviceEvent.h @@ -152,7 +152,7 @@ enum PublicEventTypes * * Signals a change to the sleepy end device interval. */ - kSEDIntervalChange, + kICDPollingIntervalChange, /** * CHIPoBLE Connection Established @@ -195,6 +195,11 @@ enum PublicEventTypes */ kInterfaceIpAddressChanged, + /** + * Signals that the commissioning window has opened or closed. + */ + kCommissioningWindowStatusChanged, + /** * Commissioning has completed by a call to the general commissioning cluster command. */ @@ -206,6 +211,11 @@ enum PublicEventTypes */ kFailSafeTimerExpired, + /** + * Signals that the fail-safe state changed (Armed/Disarmed) + */ + kFailSafeStateChanged, + /** * */ @@ -239,6 +249,35 @@ enum PublicEventTypes * sending messages to other nodes. */ kServerReady, + + /** + * TODO ICD: kChipMsgSentEvent and kChipMsgRxEventHandled should be InternalEventTypes. + * However the ICD manager leverages those events and its event handler is registered as an application + * event handler. + * ICDEventManager will have to expose 'ICDEventHandler' publicly to 'DispatchEventToDeviceLayer'. + */ + + /** + * An Exchange Context sent a message. + * This event contains a with MessageSent structure. + */ + kChipMsgSentEvent, + + /** + * An Exchange Context that was waiting for a response is no longer waiting for it. + * This event can occur due to any of the following: + * - A response message was received. + * - An exchange context timed out waiting for a response. + * - The exchange context was closed while a response was expected. + * + * This event contains an RxEventContext structure. + */ + kChipMsgRxEventHandled, + + /** + * An application event occured that should wake up the system/device + */ + kAppWakeUpEvent, }; /** @@ -506,6 +545,16 @@ struct ChipDeviceEvent final bool updateNocCommandHasBeenInvoked; } FailSafeTimerExpired; + struct + { + bool armed; + } FailSafeState; + + struct + { + bool open; + } CommissioningWindowStatus; + struct { // TODO(cecille): This should just specify wifi or thread since we assume at most 1. @@ -516,6 +565,21 @@ struct ChipDeviceEvent final { OtaState newState; } OtaStateChanged; + + struct + { + bool ExpectResponse; + } MessageSent; + + struct + { + /* + * wasReceived is only true when the event was triggered by a response message reception. + * See the brief of kChipMsgRxEventHandled, above in this file, for additional details. + */ + bool wasReceived; + bool clearsExpectedResponse; + } RxEventContext; }; void Clear() { memset(this, 0, sizeof(*this)); } diff --git a/src/include/platform/ConnectivityManager.h b/src/include/platform/ConnectivityManager.h index fa104a68e0f6b3..79eaa37423542a 100755 --- a/src/include/platform/ConnectivityManager.h +++ b/src/include/platform/ConnectivityManager.h @@ -226,6 +226,8 @@ class ConnectivityManager CHIP_ERROR RequestSEDActiveMode(bool onOff, bool delayIdle = false); #endif + CHIP_ERROR SetPollingInterval(System::Clock::Milliseconds32 pollingInterval); + // CHIPoBLE service methods Ble::BleLayer * GetBleLayer(); bool IsBLEAdvertisingEnabled(); @@ -485,6 +487,15 @@ inline CHIP_ERROR ConnectivityManager::RequestSEDActiveMode(bool onOff, bool del } #endif +inline CHIP_ERROR ConnectivityManager::SetPollingInterval(System::Clock::Milliseconds32 pollingInterval) +{ +#if CHIP_CONFIG_ENABLE_ICD_SERVER + return static_cast(this)->_SetPollingInterval(pollingInterval); +#else + return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; +#endif +} + inline bool ConnectivityManager::IsThreadAttached() { return static_cast(this)->_IsThreadAttached(); diff --git a/src/include/platform/ThreadStackManager.h b/src/include/platform/ThreadStackManager.h index b3fc19dc5454e3..3f72378e285653 100755 --- a/src/include/platform/ThreadStackManager.h +++ b/src/include/platform/ThreadStackManager.h @@ -168,7 +168,7 @@ class ThreadStackManager CHIP_ERROR GetSEDIntervalsConfig(ConnectivityManager::SEDIntervalsConfig & intervalsConfig); /** - * Sets Sleepy End Device intervals configuration and posts kSEDIntervalChange event to inform other software + * Sets Sleepy End Device intervals configuration and posts kICDPollingIntervalChange event to inform other software * modules about the change. * * @param[in] intervalsConfig intervals configuration to be set @@ -184,6 +184,9 @@ class ThreadStackManager */ CHIP_ERROR RequestSEDActiveMode(bool onOff, bool delayIdle = false); #endif +#if CHIP_CONFIG_ENABLE_ICD_SERVER + CHIP_ERROR SetPollingInterval(System::Clock::Milliseconds32 pollingInterval); +#endif bool HaveMeshConnectivity(); @@ -408,6 +411,13 @@ inline CHIP_ERROR ThreadStackManager::RequestSEDActiveMode(bool onOff, bool dela } #endif +#if CHIP_CONFIG_ENABLE_ICD_SERVER +inline CHIP_ERROR ThreadStackManager::SetPollingInterval(System::Clock::Milliseconds32 pollingInterval) +{ + return static_cast(this)->_SetPollingInterval(pollingInterval); +} +#endif // CHIP_CONFIG_ENABLE_ICD_SERVER + inline bool ThreadStackManager::HaveMeshConnectivity() { return static_cast(this)->_HaveMeshConnectivity(); diff --git a/src/include/platform/internal/GenericConnectivityManagerImpl_Thread.h b/src/include/platform/internal/GenericConnectivityManagerImpl_Thread.h index 4e0d8ddd349874..0f8b568d0393dd 100755 --- a/src/include/platform/internal/GenericConnectivityManagerImpl_Thread.h +++ b/src/include/platform/internal/GenericConnectivityManagerImpl_Thread.h @@ -68,6 +68,9 @@ class GenericConnectivityManagerImpl_Thread CHIP_ERROR _SetSEDIntervalsConfig(const ConnectivityManager::SEDIntervalsConfig & intervalsConfig); CHIP_ERROR _RequestSEDActiveMode(bool onOff, bool delayIdle = false); #endif +#if CHIP_CONFIG_ENABLE_ICD_SERVER + CHIP_ERROR _SetPollingInterval(System::Clock::Milliseconds32 pollingInterval); +#endif /* CHIP_CONFIG_ENABLE_ICD_SERVER */ bool _IsThreadAttached(); bool _IsThreadProvisioned(); void _ErasePersistentInfo(); @@ -163,6 +166,15 @@ inline CHIP_ERROR GenericConnectivityManagerImpl_Thread::_RequestSEDA } #endif +#if CHIP_CONFIG_ENABLE_ICD_SERVER +template +inline CHIP_ERROR +GenericConnectivityManagerImpl_Thread::_SetPollingInterval(System::Clock::Milliseconds32 pollingInterval) +{ + return ThreadStackMgrImpl().SetPollingInterval(pollingInterval); +} +#endif // CHIP_CONFIG_ENABLE_ICD_SERVER + template inline void GenericConnectivityManagerImpl_Thread::_ResetThreadNetworkDiagnosticsCounts() { diff --git a/src/include/platform/internal/GenericConnectivityManagerImpl_WiFi.h b/src/include/platform/internal/GenericConnectivityManagerImpl_WiFi.h index 1de4a57ea3b168..61c2db51954c8e 100644 --- a/src/include/platform/internal/GenericConnectivityManagerImpl_WiFi.h +++ b/src/include/platform/internal/GenericConnectivityManagerImpl_WiFi.h @@ -76,6 +76,10 @@ class GenericConnectivityManagerImpl_WiFi bool _CanStartWiFiScan(); void _OnWiFiScanDone(); void _OnWiFiStationProvisionChange(); +// TODO ICD rework: ambiguous declaration of _SetPollingInterval when thread and wifi are both build together +#if CHIP_CONFIG_ENABLE_ICD_SERVER && !CHIP_DEVICE_CONFIG_ENABLE_THREAD + CHIP_ERROR _SetPollingInterval(System::Clock::Milliseconds32 pollingInterval); +#endif static const char * _WiFiStationModeToStr(ConnectivityManager::WiFiStationMode mode); static const char * _WiFiAPModeToStr(ConnectivityManager::WiFiAPMode mode); static const char * _WiFiStationStateToStr(ConnectivityManager::WiFiStationState state); @@ -181,6 +185,14 @@ template inline void GenericConnectivityManagerImpl_WiFi::_OnWiFiStationProvisionChange() {} +#if CHIP_CONFIG_ENABLE_ICD_SERVER && !CHIP_DEVICE_CONFIG_ENABLE_THREAD +template +inline CHIP_ERROR GenericConnectivityManagerImpl_WiFi::_SetPollingInterval(System::Clock::Milliseconds32 pollingInterval) +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} +#endif + } // namespace Internal } // namespace DeviceLayer } // namespace chip diff --git a/src/messaging/BUILD.gn b/src/messaging/BUILD.gn index bf363c7239db71..d5e51fc0f61056 100644 --- a/src/messaging/BUILD.gn +++ b/src/messaging/BUILD.gn @@ -13,6 +13,7 @@ # limitations under the License. import("//build_overrides/chip.gni") +import("${chip_root}/src/app/icd/icd.gni") declare_args() { # Allows to change time between retries during the case session @@ -74,4 +75,8 @@ static_library("messaging") { "${chip_root}/src/transport", "${chip_root}/src/transport/raw", ] + + if (chip_enable_icd_server) { + public_deps += [ "${chip_root}/src/app/icd:server-srcs" ] + } } diff --git a/src/messaging/ExchangeContext.cpp b/src/messaging/ExchangeContext.cpp index 05d2b5fc026bec..cac98cd95017f0 100644 --- a/src/messaging/ExchangeContext.cpp +++ b/src/messaging/ExchangeContext.cpp @@ -238,15 +238,28 @@ CHIP_ERROR ExchangeContext::SendMessage(Protocols::Id protocolId, uint8_t msgTyp session->AsSecureSession()->MarkAsDefunct(); } } - - // Standalone acks are not application-level message sends. - if (!isStandaloneAck && err == CHIP_NO_ERROR) + else { - // - // Once we've sent the message successfully, we can clear out the WillSendMessage flag. - // - mFlags.Clear(Flags::kFlagWillSendMessage); - MessageHandled(); +#if CONFIG_DEVICE_LAYER && CHIP_CONFIG_ENABLE_ICD_SERVER + DeviceLayer::ChipDeviceEvent event; + event.Type = DeviceLayer::DeviceEventType::kChipMsgSentEvent; + event.MessageSent.ExpectResponse = IsResponseExpected(); + CHIP_ERROR status = DeviceLayer::PlatformMgr().PostEvent(&event); + if (status != CHIP_NO_ERROR) + { + ChipLogError(DeviceLayer, "Failed to post Message sent event %" CHIP_ERROR_FORMAT, status.Format()); + } +#endif // CONFIG_DEVICE_LAYER + + // Standalone acks are not application-level message sends. + if (!isStandaloneAck) + { + // + // Once we've sent the message successfully, we can clear out the WillSendMessage flag. + // + mFlags.Clear(Flags::kFlagWillSendMessage); + MessageHandled(); + } } return err; @@ -286,6 +299,18 @@ void ExchangeContext::DoClose(bool clearRetransTable) { // Cancel the response timer. CancelResponseTimer(); +#if CONFIG_DEVICE_LAYER && CHIP_CONFIG_ENABLE_ICD_SERVER + DeviceLayer::ChipDeviceEvent event; + event.Type = DeviceLayer::DeviceEventType::kChipMsgRxEventHandled; + event.RxEventContext.wasReceived = false; + event.RxEventContext.clearsExpectedResponse = true; + CHIP_ERROR status = DeviceLayer::PlatformMgr().PostEvent(&event); + if (status != CHIP_NO_ERROR) + { + ChipLogError(DeviceLayer, "Failed to post Msg Handled event at ExchangeContext closure %" CHIP_ERROR_FORMAT, + status.Format()); + } +#endif // CONFIG_DEVICE_LAYER && CHIP_CONFIG_ENABLE_ICD_SERVER } } @@ -496,6 +521,18 @@ void ExchangeContext::HandleResponseTimeout(System::Layer * aSystemLayer, void * void ExchangeContext::NotifyResponseTimeout(bool aCloseIfNeeded) { +#if CONFIG_DEVICE_LAYER && CHIP_CONFIG_ENABLE_ICD_SERVER + DeviceLayer::ChipDeviceEvent event; + event.Type = DeviceLayer::DeviceEventType::kChipMsgRxEventHandled; + event.RxEventContext.wasReceived = false; + event.RxEventContext.clearsExpectedResponse = true; + CHIP_ERROR status = DeviceLayer::PlatformMgr().PostEvent(&event); + if (status != CHIP_NO_ERROR) + { + ChipLogError(DeviceLayer, "Failed to post Message Response Timeout event %" CHIP_ERROR_FORMAT, status.Format()); + } +#endif // CONFIG_DEVICE_LAYER && CHIP_CONFIG_ENABLE_ICD_SERVER + SetResponseExpected(false); // Hold a ref to ourselves so we can make calls into our delegate that might @@ -608,6 +645,18 @@ CHIP_ERROR ExchangeContext::HandleMessage(uint32_t messageCounter, const Payload return CHIP_ERROR_INCORRECT_STATE; } +#if CONFIG_DEVICE_LAYER && CHIP_CONFIG_ENABLE_ICD_SERVER + DeviceLayer::ChipDeviceEvent event; + event.Type = DeviceLayer::DeviceEventType::kChipMsgRxEventHandled; + event.RxEventContext.wasReceived = true; + event.RxEventContext.clearsExpectedResponse = IsResponseExpected(); + CHIP_ERROR status = DeviceLayer::PlatformMgr().PostEvent(&event); + if (status != CHIP_NO_ERROR) + { + ChipLogError(DeviceLayer, "Failed to post Message received event %" CHIP_ERROR_FORMAT, status.Format()); + } +#endif // CONFIG_DEVICE_LAYER && CHIP_CONFIG_ENABLE_ICD_SERVER + if (IsResponseExpected()) { // Since we got the response, cancel the response timer. diff --git a/src/messaging/ReliableMessageMgr.cpp b/src/messaging/ReliableMessageMgr.cpp index 8a9e88d426b41f..a556aaa18be778 100644 --- a/src/messaging/ReliableMessageMgr.cpp +++ b/src/messaging/ReliableMessageMgr.cpp @@ -37,6 +37,10 @@ #include #include +#if CHIP_CONFIG_ENABLE_ICD_SERVER +#include // nogncheck +#endif + using namespace chip::System::Clock::Literals; namespace chip { @@ -249,10 +253,12 @@ System::Clock::Timestamp ReliableMessageMgr::GetBackoff(System::Clock::Timestamp uint32_t jitter = MRP_BACKOFF_JITTER_BASE + (computeMaxPossible ? UINT8_MAX : Crypto::GetRandU8()); mrpBackoffTime = mrpBackoffTime * jitter / MRP_BACKOFF_JITTER_BASE; -#if CHIP_DEVICE_CONFIG_ENABLE_SED +#if CHIP_CONFIG_ENABLE_ICD_SERVER // Implement: - // "A sleepy sender SHOULD increase t to also account for its own sleepy interval + // "An ICD sender SHOULD increase t to also account for its own sleepy interval // required to receive the acknowledgment" + mrpBackoffTime += app::ICDManager::GetFastPollingInterval(); +#elif CHIP_DEVICE_CONFIG_ENABLE_SED DeviceLayer::ConnectivityManager::SEDIntervalsConfig sedIntervals; if (DeviceLayer::ConnectivityMgr().GetSEDIntervalsConfig(sedIntervals) == CHIP_NO_ERROR) diff --git a/src/messaging/ReliableMessageProtocolConfig.cpp b/src/messaging/ReliableMessageProtocolConfig.cpp index a0ff8ab64ceec1..442d1ee81d4596 100644 --- a/src/messaging/ReliableMessageProtocolConfig.cpp +++ b/src/messaging/ReliableMessageProtocolConfig.cpp @@ -27,6 +27,10 @@ #include #include +#if CHIP_CONFIG_ENABLE_ICD_SERVER +#include // nogncheck +#endif + namespace chip { using namespace System::Clock::Literals; @@ -59,8 +63,13 @@ ReliableMessageProtocolConfig GetDefaultMRPConfig() Optional GetLocalMRPConfig() { ReliableMessageProtocolConfig config(CHIP_CONFIG_MRP_LOCAL_IDLE_RETRY_INTERVAL, CHIP_CONFIG_MRP_LOCAL_ACTIVE_RETRY_INTERVAL); - -#if CHIP_DEVICE_CONFIG_ENABLE_SED +#if CHIP_CONFIG_ENABLE_ICD_SERVER + // TODO ICD LIT shall not advertise the SII key + // Increase local MRP retry intervals by ICD polling intervals. That is, intervals for + // which the device can be at sleep and not be able to receive any messages). + config.mIdleRetransTimeout += app::ICDManager::GetSlowPollingInterval(); + config.mActiveRetransTimeout += app::ICDManager::GetFastPollingInterval(); +#elif CHIP_DEVICE_CONFIG_ENABLE_SED DeviceLayer::ConnectivityManager::SEDIntervalsConfig sedIntervalsConfig; if (DeviceLayer::ConnectivityMgr().GetSEDIntervalsConfig(sedIntervalsConfig) == CHIP_NO_ERROR) diff --git a/src/platform/Linux/ThreadStackManagerImpl.cpp b/src/platform/Linux/ThreadStackManagerImpl.cpp index b59e0602edb63b..8e27a9fece2b0f 100755 --- a/src/platform/Linux/ThreadStackManagerImpl.cpp +++ b/src/platform/Linux/ThreadStackManagerImpl.cpp @@ -546,6 +546,14 @@ CHIP_ERROR ThreadStackManagerImpl::_RequestSEDActiveMode(bool onOff, bool delayI return CHIP_ERROR_NOT_IMPLEMENTED; } #endif +#if CHIP_CONFIG_ENABLE_ICD_SERVER +CHIP_ERROR ThreadStackManagerImpl::_SetPollingInterval(System::Clock::Milliseconds32 pollingInterval) +{ + (void) pollingInterval; + ChipLogError(DeviceLayer, "Set ICD Polling on linux"); + return CHIP_ERROR_NOT_IMPLEMENTED; +} +#endif /* CHIP_CONFIG_ENABLE_ICD_SERVER */ bool ThreadStackManagerImpl::_HaveMeshConnectivity() { diff --git a/src/platform/Linux/ThreadStackManagerImpl.h b/src/platform/Linux/ThreadStackManagerImpl.h index 2c4a47a43a0c62..3914c04524b14c 100755 --- a/src/platform/Linux/ThreadStackManagerImpl.h +++ b/src/platform/Linux/ThreadStackManagerImpl.h @@ -91,6 +91,9 @@ class ThreadStackManagerImpl : public ThreadStackManager CHIP_ERROR _SetSEDIntervalsConfig(const ConnectivityManager::SEDIntervalsConfig & intervalsConfig); CHIP_ERROR _RequestSEDActiveMode(bool onOff, bool delayIdle = false); #endif +#if CHIP_CONFIG_ENABLE_ICD_SERVER + CHIP_ERROR _SetPollingInterval(System::Clock::Milliseconds32 pollingInterval); +#endif /* CHIP_CONFIG_ENABLE_ICD_SERVER */ bool _HaveMeshConnectivity(); diff --git a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.h b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.h index 2397b5e143828d..603161900b788f 100755 --- a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.h +++ b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.h @@ -107,6 +107,9 @@ class GenericThreadStackManagerImpl_OpenThread CHIP_ERROR SEDUpdateMode(); static void RequestSEDModeUpdate(chip::System::Layer * apSystemLayer, void * apAppState); #endif +#if CHIP_CONFIG_ENABLE_ICD_SERVER + CHIP_ERROR _SetPollingInterval(System::Clock::Milliseconds32 pollingInterval); +#endif // CHIP_CONFIG_ENABLE_ICD_SERVER bool _HaveMeshConnectivity(void); CHIP_ERROR _GetAndLogThreadStatsCounters(void); diff --git a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.hpp b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.hpp index 001fd0a883c74e..05ad6d1a3b7550 100644 --- a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.hpp +++ b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.hpp @@ -385,10 +385,9 @@ CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::_StartThreadScan(NetworkCommissioning::ThreadDriver::ScanCallback * callback) { CHIP_ERROR error = CHIP_NO_ERROR; -#if CHIP_DEVICE_CONFIG_ENABLE_SED +#if CHIP_DEVICE_CONFIG_ENABLE_SED || CHIP_CONFIG_ENABLE_ICD_SERVER otLinkModeConfig linkMode; #endif - // If there is another ongoing scan request, reject the new one. VerifyOrReturnError(mpScanCallback == nullptr, CHIP_ERROR_INCORRECT_STATE); @@ -402,7 +401,7 @@ GenericThreadStackManagerImpl_OpenThread::_StartThreadScan(NetworkCom SuccessOrExit(error = MapOpenThreadError(otIp6SetEnabled(mOTInst, true))); } -#if CHIP_DEVICE_CONFIG_ENABLE_SED +#if CHIP_DEVICE_CONFIG_ENABLE_SED || CHIP_CONFIG_ENABLE_ICD_SERVER // Thread network discovery makes Sleepy End Devices detach from a network, so temporarily disable the SED mode. linkMode = otThreadGetLinkMode(mOTInst); @@ -440,7 +439,7 @@ void GenericThreadStackManagerImpl_OpenThread::_OnNetworkScanFinished { if (aResult == nullptr) // scan completed { -#if CHIP_DEVICE_CONFIG_ENABLE_SED +#if CHIP_DEVICE_CONFIG_ENABLE_SED || CHIP_CONFIG_ENABLE_ICD_SERVER if (mTemporaryRxOnWhenIdle) { otLinkModeConfig linkMode = otThreadGetLinkMode(mOTInst); @@ -1736,8 +1735,8 @@ CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::DoInit(otInstanc #if CHIP_DEVICE_CONFIG_ENABLE_SED ConnectivityManager::SEDIntervalsConfig sedIntervalsConfig; using namespace System::Clock::Literals; - sedIntervalsConfig.ActiveIntervalMS = CHIP_DEVICE_CONFIG_SED_ACTIVE_INTERVAL; - sedIntervalsConfig.IdleIntervalMS = CHIP_DEVICE_CONFIG_SED_IDLE_INTERVAL; + sedIntervalsConfig.ActiveIntervalMS = CHIP_DEVICE_CONFIG_ICD_FAST_POLL_INTERVAL; + sedIntervalsConfig.IdleIntervalMS = CHIP_DEVICE_CONFIG_ICD_SLOW_POLL_INTERVAL; err = _SetSEDIntervalsConfig(sedIntervalsConfig); if (err != CHIP_NO_ERROR) { @@ -1824,7 +1823,7 @@ CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::_SetSEDIntervals if (err == CHIP_NO_ERROR) { ChipDeviceEvent event; - event.Type = DeviceEventType::kSEDIntervalChange; + event.Type = DeviceEventType::kICDPollingIntervalChange; err = chip::DeviceLayer::PlatformMgr().PostEvent(&event); } @@ -1964,6 +1963,52 @@ void GenericThreadStackManagerImpl_OpenThread::RequestSEDModeUpdate(c } #endif +#if CHIP_CONFIG_ENABLE_ICD_SERVER +template +CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::_SetPollingInterval(System::Clock::Milliseconds32 pollingInterval) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + Impl()->LockThreadStack(); + +// For Thread devices, the intervals are defined as: +// * 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 + // 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 + otError otErr = OT_ERROR_NONE; + if (pollingInterval.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. + otErr = otLinkCslSetPeriod(mOTInst, pollingInterval.count() * 1000 / OT_US_PER_TEN_SYMBOLS); + curIntervalMS = otLinkCslGetPeriod(mOTInst) * OT_US_PER_TEN_SYMBOLS / 1000; +#else + otErr = otLinkSetPollPeriod(mOTInst, pollingInterval.count()); + curIntervalMS = otLinkGetPollPeriod(mOTInst); +#endif + err = MapOpenThreadError(otErr); + } + + Impl()->UnlockThreadStack(); + + if (otErr != OT_ERROR_NONE) + { + ChipLogError(DeviceLayer, "Failed to set SED interval to %" PRId32 "ms. Defaulting to %" PRId32 "ms", + pollingInterval.count(), curIntervalMS); + } + else + { + ChipLogProgress(DeviceLayer, "OpenThread SED interval is %" PRId32 "ms", curIntervalMS); + } + + return err; +} +#endif // CHIP_CONFIG_ENABLE_ICD_SERVER + template void GenericThreadStackManagerImpl_OpenThread::_ErasePersistentInfo(void) { diff --git a/src/platform/nrfconnect/CHIPDevicePlatformConfig.h b/src/platform/nrfconnect/CHIPDevicePlatformConfig.h index 5e08040f7b2381..837b963b7a31fc 100644 --- a/src/platform/nrfconnect/CHIPDevicePlatformConfig.h +++ b/src/platform/nrfconnect/CHIPDevicePlatformConfig.h @@ -226,17 +226,17 @@ #define CHIP_DEVICE_CONFIG_ENABLE_SED 1 #endif // CONFIG_NRF_WIFI_LOW_POWER -#ifndef CHIP_DEVICE_CONFIG_SED_IDLE_INTERVAL +#ifndef CHIP_DEVICE_CONFIG_ICD_SLOW_POLL_INTERVAL #ifdef CONFIG_CHIP_SED_IDLE_INTERVAL -#define CHIP_DEVICE_CONFIG_SED_IDLE_INTERVAL chip::System::Clock::Milliseconds32(CONFIG_CHIP_SED_IDLE_INTERVAL) +#define CHIP_DEVICE_CONFIG_ICD_SLOW_POLL_INTERVAL chip::System::Clock::Milliseconds32(CONFIG_CHIP_SED_IDLE_INTERVAL) #endif // CONFIG_CHIP_SED_IDLE_INTERVAL -#endif // CHIP_DEVICE_CONFIG_SED_IDLE_INTERVAL +#endif // CHIP_DEVICE_CONFIG_ICD_SLOW_POLL_INTERVAL -#ifndef CHIP_DEVICE_CONFIG_SED_ACTIVE_INTERVAL +#ifndef CHIP_DEVICE_CONFIG_ICD_FAST_POLL_INTERVAL #ifdef CONFIG_CHIP_SED_ACTIVE_INTERVAL -#define CHIP_DEVICE_CONFIG_SED_ACTIVE_INTERVAL chip::System::Clock::Milliseconds32(CONFIG_CHIP_SED_ACTIVE_INTERVAL) +#define CHIP_DEVICE_CONFIG_ICD_FAST_POLL_INTERVAL chip::System::Clock::Milliseconds32(CONFIG_CHIP_SED_ACTIVE_INTERVAL) #endif // CONFIG_CHIP_SED_ACTIVE_INTERVAL -#endif // CHIP_DEVICE_CONFIG_SED_ACTIVE_INTERVAL +#endif // CHIP_DEVICE_CONFIG_ICD_FAST_POLL_INTERVAL #ifdef CONFIG_CHIP_COMMISSIONABLE_DEVICE_TYPE #define CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONABLE_DEVICE_TYPE 1 diff --git a/src/platform/silabs/CHIPDevicePlatformConfig.h b/src/platform/silabs/CHIPDevicePlatformConfig.h index 3462402a228a58..7ea977bf54aa88 100644 --- a/src/platform/silabs/CHIPDevicePlatformConfig.h +++ b/src/platform/silabs/CHIPDevicePlatformConfig.h @@ -104,10 +104,10 @@ #define CHIP_DEVICE_CONFIG_ENABLE_IPV4 0 #endif /* CHIP_DEVICE_CONFIG_ENABLE_IPV4 */ -#ifdef CHIP_DEVICE_CONFIG_ENABLE_SED -#define CHIP_DEVICE_CONFIG_SED_IDLE_INTERVAL chip::System::Clock::Milliseconds32(300) -#define CHIP_DEVICE_CONFIG_SED_ACTIVE_INTERVAL chip::System::Clock::Milliseconds32(10) -#endif /* CHIP_DEVICE_CONFIG_ENABLE_SED */ +#if CHIP_CONFIG_ENABLE_ICD_SERVER +#define CHIP_DEVICE_CONFIG_ICD_SLOW_POLL_INTERVAL chip::System::Clock::Milliseconds32(300) +#define CHIP_DEVICE_CONFIG_ICD_FAST_POLL_INTERVAL chip::System::Clock::Milliseconds32(10) +#endif /* CHIP_CONFIG_ENABLE_ICD_SERVER */ #endif /* SL_WIFI */ @@ -138,13 +138,13 @@ #define CHIP_DEVICE_CONFIG_CHIP_TASK_STACK_SIZE (6 * 1024) #endif // CHIP_DEVICE_CONFIG_CHIP_TASK_STACK_SIZE -#ifndef CHIP_DEVICE_CONFIG_SED_IDLE_INTERVAL -#define CHIP_DEVICE_CONFIG_SED_IDLE_INTERVAL chip::System::Clock::Milliseconds32(SL_OT_IDLE_INTERVAL) -#endif // CHIP_DEVICE_CONFIG_SED_IDLE_INTERVAL +#ifndef CHIP_DEVICE_CONFIG_ICD_SLOW_POLL_INTERVAL +#define CHIP_DEVICE_CONFIG_ICD_SLOW_POLL_INTERVAL chip::System::Clock::Milliseconds32(SL_OT_IDLE_INTERVAL) +#endif // CHIP_DEVICE_CONFIG_ICD_SLOW_POLL_INTERVAL -#ifndef CHIP_DEVICE_CONFIG_SED_ACTIVE_INTERVAL -#define CHIP_DEVICE_CONFIG_SED_ACTIVE_INTERVAL chip::System::Clock::Milliseconds32(SL_OT_ACTIVE_INTERVAL) -#endif // CHIP_DEVICE_CONFIG_SED_ACTIVE_INTERVAL +#ifndef CHIP_DEVICE_CONFIG_ICD_FAST_POLL_INTERVAL +#define CHIP_DEVICE_CONFIG_ICD_FAST_POLL_INTERVAL chip::System::Clock::Milliseconds32(SL_OT_ACTIVE_INTERVAL) +#endif // CHIP_DEVICE_CONFIG_ICD_FAST_POLL_INTERVAL #ifndef CHIP_DEVICE_CONFIG_SED_ACTIVE_THRESHOLD #define CHIP_DEVICE_CONFIG_SED_ACTIVE_THRESHOLD chip::System::Clock::Milliseconds32(SL_ACTIVE_MODE_THRESHOLD) diff --git a/src/platform/silabs/ConnectivityManagerImpl.h b/src/platform/silabs/ConnectivityManagerImpl.h index fd464a65c84720..54a6b97c5e5fa1 100644 --- a/src/platform/silabs/ConnectivityManagerImpl.h +++ b/src/platform/silabs/ConnectivityManagerImpl.h @@ -105,12 +105,9 @@ class ConnectivityManagerImpl final : public ConnectivityManager, bool _CanStartWiFiScan(); void _OnWiFiScanDone(); void _OnWiFiStationProvisionChange(); -#if CHIP_DEVICE_CONFIG_ENABLE_SED - ConnectivityManager::SEDIntervalsConfig mIntervalsConfig; - CHIP_ERROR _GetSEDIntervalsConfig(ConnectivityManager::SEDIntervalsConfig & intervalsConfig); - CHIP_ERROR _SetSEDIntervalsConfig(const ConnectivityManager::SEDIntervalsConfig & intervalsConfig); - CHIP_ERROR _RequestSEDActiveMode(bool onOff, bool delayIdle = false); -#endif /* CHIP_DEVICE_CONFIG_ENABLE_SED */ +#if CHIP_CONFIG_ENABLE_ICD_SERVER + CHIP_ERROR _SetPollingInterval(System::Clock::Milliseconds32 pollingInterval); +#endif /* CHIP_CONFIG_ENABLE_ICD_SERVER */ #endif /* CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION */ // ===== Members for internal use by the following friends. diff --git a/src/platform/silabs/ConnectivityManagerImpl_WIFI.cpp b/src/platform/silabs/ConnectivityManagerImpl_WIFI.cpp index ae3bb69ea4d2b7..c1a1a7de4c0ed1 100644 --- a/src/platform/silabs/ConnectivityManagerImpl_WIFI.cpp +++ b/src/platform/silabs/ConnectivityManagerImpl_WIFI.cpp @@ -220,28 +220,15 @@ void ConnectivityManagerImpl::_OnWiFiStationProvisionChange() DeviceLayer::SystemLayer().ScheduleWork(DriveStationState, NULL); } -#if CHIP_DEVICE_CONFIG_ENABLE_SED -CHIP_ERROR ConnectivityManagerImpl::_GetSEDIntervalsConfig(ConnectivityManager::SEDIntervalsConfig & SEDIntervalsConfig) +#if CHIP_CONFIG_ENABLE_ICD_SERVER +CHIP_ERROR ConnectivityManagerImpl::_SetPollingInterval(System::Clock::Milliseconds32 pollingInterval) { - // For now Wi-Fi uses DTIM power save mode so it varies from AP to AP - // TODO: Change this to DTIM read from DUT once it is done. For now hardcoding it - SEDIntervalsConfig.ActiveIntervalMS = CHIP_DEVICE_CONFIG_SED_ACTIVE_INTERVAL; - SEDIntervalsConfig.IdleIntervalMS = CHIP_DEVICE_CONFIG_SED_IDLE_INTERVAL; - return CHIP_NO_ERROR; -} - -CHIP_ERROR ConnectivityManagerImpl::_SetSEDIntervalsConfig(const ConnectivityManager::SEDIntervalsConfig & intervalsConfig) -{ - // not required - return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; -} - -CHIP_ERROR ConnectivityManagerImpl::_RequestSEDActiveMode(bool onOff, bool delayIdle) -{ - // not required - return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; + // TODO ICD + (void) pollingInterval; + ChipLogError(DeviceLayer, "Set ICD Fast Polling on Silabs Wifi platform"); + return CHIP_ERROR_NOT_IMPLEMENTED; } -#endif /* CHIP_DEVICE_CONFIG_ENABLE_SED */ +#endif /* CHIP_CONFIG_ENABLE_ICD_SERVER */ // == == == == == == == == == == ConnectivityManager Private Methods == == == == == == == == == == @@ -380,13 +367,13 @@ void ConnectivityManagerImpl::OnStationConnected() event.WiFiConnectivityChange.Result = kConnectivity_Established; (void) PlatformMgr().PostEvent(&event); // Setting the rs911x in the power save mode -#if (CHIP_DEVICE_CONFIG_ENABLE_SED && RS911X_WIFI) +#if (CHIP_CONFIG_ENABLE_ICD_SERVER && RS911X_WIFI) sl_status_t err = wfx_power_save(); if (err != SL_STATUS_OK) { ChipLogError(DeviceLayer, "Power save config for Wifi failed"); } -#endif /* CHIP_DEVICE_CONFIG_ENABLE_SED && RS911X_WIFI */ +#endif /* CHIP_CONFIG_ENABLE_ICD_SERVER && RS911X_WIFI */ UpdateInternetConnectivityState(); } diff --git a/src/platform/silabs/efr32/wifi/wfx_host_events.h b/src/platform/silabs/efr32/wifi/wfx_host_events.h index 3c9d12be5dff6e..5fae93e82053f0 100644 --- a/src/platform/silabs/efr32/wifi/wfx_host_events.h +++ b/src/platform/silabs/efr32/wifi/wfx_host_events.h @@ -353,9 +353,9 @@ void wfx_ipv6_notify(int got_ip); #ifdef RS911X_WIFI /* RSI Power Save */ -#if CHIP_DEVICE_CONFIG_ENABLE_SED +#if CHIP_CONFIG_ENABLE_ICD_SERVER sl_status_t wfx_power_save(); -#endif /* CHIP_DEVICE_CONFIG_ENABLE_SED */ +#endif /* CHIP_CONFIG_ENABLE_ICD_SERVER */ /* RSI for LWIP */ void * wfx_rsi_alloc_pkt(void); void wfx_rsi_pkt_add_data(void * p, uint8_t * buf, uint16_t len, uint16_t off); diff --git a/src/platform/telink/CHIPDevicePlatformConfig.h b/src/platform/telink/CHIPDevicePlatformConfig.h index 1b218875aae8e4..2527a3e8fc785a 100644 --- a/src/platform/telink/CHIPDevicePlatformConfig.h +++ b/src/platform/telink/CHIPDevicePlatformConfig.h @@ -227,14 +227,14 @@ #define CHIP_DEVICE_CONFIG_THREAD_SSED CONFIG_CHIP_THREAD_SSED #endif // CONFIG_CHIP_ENABLE_SLEEPY_END_DEVICE_SUPPORT -#ifndef CHIP_DEVICE_CONFIG_SED_IDLE_INTERVAL +#ifndef CHIP_DEVICE_CONFIG_ICD_SLOW_POLL_INTERVAL #ifdef CONFIG_CHIP_SED_IDLE_INTERVAL -#define CHIP_DEVICE_CONFIG_SED_IDLE_INTERVAL chip::System::Clock::Milliseconds32(CONFIG_CHIP_SED_IDLE_INTERVAL) +#define CHIP_DEVICE_CONFIG_ICD_SLOW_POLL_INTERVAL chip::System::Clock::Milliseconds32(CONFIG_CHIP_SED_IDLE_INTERVAL) #endif // CONFIG_CHIP_SED_IDLE_INTERVAL -#endif // CHIP_DEVICE_CONFIG_SED_IDLE_INTERVAL +#endif // CHIP_DEVICE_CONFIG_ICD_SLOW_POLL_INTERVAL -#ifndef CHIP_DEVICE_CONFIG_SED_ACTIVE_INTERVAL +#ifndef CHIP_DEVICE_CONFIG_ICD_FAST_POLL_INTERVAL #ifdef CONFIG_CHIP_SED_ACTIVE_INTERVAL -#define CHIP_DEVICE_CONFIG_SED_ACTIVE_INTERVAL chip::System::Clock::Milliseconds32(CONFIG_CHIP_SED_ACTIVE_INTERVAL) +#define CHIP_DEVICE_CONFIG_ICD_FAST_POLL_INTERVAL chip::System::Clock::Milliseconds32(CONFIG_CHIP_SED_ACTIVE_INTERVAL) #endif // CONFIG_CHIP_SED_ACTIVE_INTERVAL -#endif // CHIP_DEVICE_CONFIG_SED_ACTIVE_INTERVAL +#endif // CHIP_DEVICE_CONFIG_ICD_FAST_POLL_INTERVAL diff --git a/third_party/silabs/SiWx917_sdk.gni b/third_party/silabs/SiWx917_sdk.gni index 09dedcb4885074..28c1b73e6faa47 100644 --- a/third_party/silabs/SiWx917_sdk.gni +++ b/third_party/silabs/SiWx917_sdk.gni @@ -18,6 +18,7 @@ import("//build_overrides/jlink.gni") import("//build_overrides/mbedtls.gni") import("${efr32_sdk_build_root}/efr32_sdk.gni") +import("${chip_root}/src/app/icd/icd.gni") import("${chip_root}/src/lib/lib.gni") import("silabs_board.gni") @@ -153,14 +154,11 @@ template("siwx917_sdk") { defines += [ "ENABLE_WSTK_LEDS" ] } - if (defined(invoker.enable_sleepy_device)) { - if (invoker.enable_sleepy_device) { - defines += [ - "CHIP_DEVICE_CONFIG_ENABLE_SED=1", - "SL_CATALOG_POWER_MANAGER_PRESENT", - "SL_CATALOG_SLEEPTIMER_PRESENT", - ] - } + if (chip_enable_icd_server) { + defines += [ + "SL_CATALOG_POWER_MANAGER_PRESENT", + "SL_CATALOG_SLEEPTIMER_PRESENT", + ] } if (chip_build_libshell) { # matter shell diff --git a/third_party/silabs/efr32_sdk.gni b/third_party/silabs/efr32_sdk.gni index fbbdc8bc5db0fb..de1f70f42c5ce2 100644 --- a/third_party/silabs/efr32_sdk.gni +++ b/third_party/silabs/efr32_sdk.gni @@ -17,6 +17,7 @@ import("//build_overrides/efr32_sdk.gni") import("//build_overrides/jlink.gni") import("//build_overrides/mbedtls.gni") +import("${chip_root}/src/app/icd/icd.gni") import("${chip_root}/src/lib/lib.gni") import("silabs_board.gni") @@ -52,9 +53,6 @@ declare_args() { silabs_log_enabled = true - # Enable Sleepy end device - enable_sleepy_device = false - # Argument to enable IPv4 for wifi # aligning to match chip_inet_config_enable_ipv4 default configuration chip_enable_wifi_ipv4 = false @@ -326,9 +324,8 @@ template("efr32_sdk") { _include_dirs += [ "${efr32_sdk_root}/platform/driver/button/inc" ] } - if (enable_sleepy_device) { + if (chip_enable_icd_server) { defines += [ - "CHIP_DEVICE_CONFIG_ENABLE_SED=1", "SL_OT_IDLE_INTERVAL=${sl_ot_idle_interval_ms}", "SL_OT_ACTIVE_INTERVAL=${sl_ot_active_interval_ms}", "SL_ACTIVE_MODE_THRESHOLD=${sl_active_mode_threshold}",