diff --git a/.github/workflows/unit_integration_test.yaml b/.github/workflows/unit_integration_test.yaml index 4272777681a4ce..44bdde06a455fb 100644 --- a/.github/workflows/unit_integration_test.yaml +++ b/.github/workflows/unit_integration_test.yaml @@ -65,7 +65,7 @@ jobs: "clang") GN_ARGS='is_clang=true';; "mbedtls") GN_ARGS='chip_crypto="mbedtls"';; "rotating_device_id") GN_ARGS='chip_crypto="boringssl" chip_enable_rotating_device_id=true';; - "icd") GN_ARGS='chip_enable_icd_server=true';; + "icd") GN_ARGS='chip_enable_icd_server=true chip_enable_icd_cip=true';; *) ;; esac diff --git a/config/nrfconnect/chip-module/CMakeLists.txt b/config/nrfconnect/chip-module/CMakeLists.txt index 672bf5834da196..8b206cb0276121 100644 --- a/config/nrfconnect/chip-module/CMakeLists.txt +++ b/config/nrfconnect/chip-module/CMakeLists.txt @@ -139,6 +139,12 @@ matter_add_gn_arg_bool ("chip_enable_icd_server" CONFIG_CHIP_EN matter_add_gn_arg_bool ("chip_enable_factory_data" CONFIG_CHIP_FACTORY_DATA) matter_add_gn_arg_bool ("chip_enable_read_client" CONFIG_CHIP_ENABLE_READ_CLIENT) +if (CONFIG_CHIP_ENABLE_ICD_SUPPORT) + matter_add_gn_arg_bool ("chip_enable_icd_lit" CONFIG_CHIP_ICD_LIT_SUPPORT) + matter_add_gn_arg_bool ("chip_enable_icd_cip" CONFIG_CHIP_ICD_CHECK_IN_SUPPORT) + matter_add_gn_arg_bool ("chip_enable_icd_uat" CONFIG_CHIP_ICD_UAT_SUPPORT) +endif() + if (CONFIG_CHIP_FACTORY_DATA OR CONFIG_CHIP_FACTORY_DATA_CUSTOM_BACKEND) matter_add_gn_arg_bool("chip_use_transitional_commissionable_data_provider" FALSE) matter_add_gn_arg_bool("chip_use_transitional_device_instance_info_provider" FALSE) diff --git a/config/zephyr/Kconfig b/config/zephyr/Kconfig index 8df6c418aa42e3..ad36a663b5fd1f 100644 --- a/config/zephyr/Kconfig +++ b/config/zephyr/Kconfig @@ -334,6 +334,7 @@ if CHIP_ENABLE_ICD_SUPPORT config CHIP_ICD_SLOW_POLL_INTERVAL int "Intermittently Connected Device slow polling interval (ms)" + default 30000 if CHIP_ICD_LIT_SUPPORT default 1000 help Provides the Intermittently Connected Device slow polling interval in milliseconds while the @@ -347,33 +348,57 @@ config CHIP_ICD_FAST_POLLING_INTERVAL Provides the Intermittently Connected Device fast polling interval in milliseconds while the device is in the active mode. It determines the fastest frequency at which the device will be able to receive the messages in the active mode. The CHIP_ICD_FAST_POLLING_INTERVAL shall be smaller than - CHIP_ICD_ACTIVE_MODE_INTERVAL. + CHIP_ICD_ACTIVE_MODE_DURATION. -config CHIP_ICD_IDLE_MODE_INTERVAL - int "Intermittently Connected Device idle mode interval (s)" +config CHIP_ICD_IDLE_MODE_DURATION + int "Intermittently Connected Device idle mode duration (s)" + default 300 if CHIP_ICD_LIT_SUPPORT default 120 help - Provides the Intermittently Connected Device idle mode interval in seconds. + Provides the Intermittently Connected Device idle mode duration in seconds. It determines the maximum amount of time the device can stay in the idle mode, which means the device may be unreachable and not able to receive messages. -config CHIP_ICD_ACTIVE_MODE_INTERVAL - int "Intermittently Connected Device active mode interval (ms)" +config CHIP_ICD_ACTIVE_MODE_DURATION + int "Intermittently Connected Device active mode duration (ms)" default 300 help - Provides the Intermittently Connected Device active mode interval in milliseconds. + Provides the Intermittently Connected Device active mode duration in milliseconds. It determines the minimum amount of time the device shall stay in the active mode. config CHIP_ICD_ACTIVE_MODE_THRESHOLD int "Intermittently Connected Device active mode threshold (ms)" + default 5000 if CHIP_ICD_LIT_SUPPORT default 300 help Provides the Intermittently Connected Device active mode threshold in milliseconds. It determines the minimum amount of time the device shall stay in the active mode after the network activity. + For LIT devices it cannot be set to a value smaller than 5000 ms. + +config CHIP_ICD_LIT_SUPPORT + bool "Intermittenly Connected Device Long Idle Time support" + imply CHIP_ICD_CHECK_IN_SUPPORT + imply CHIP_ICD_UAT_SUPPORT + help + Enables the Intermittently Connected Device Long Idle Time support in Matter. + It also implies the ICD Check-In and UAT features support that are mandatory for LIT device. + +config CHIP_ICD_CHECK_IN_SUPPORT + bool "Intermittenly Connected Device Check-In protocol support" + help + Enables the Check-In protocol support in Matter. It allows an ICD device to notify the registered + ICD clients that it is available for communication. + +config CHIP_ICD_UAT_SUPPORT + bool "Intermittenly Connected Device User Active Mode Trigger support" + help + Enables the User Active Mode Trigger (UAT) support in Matter. It allows the User to use application specific + means (e.g. button press) to trigger an ICD device to enter the active mode and become responsive. config CHIP_ICD_CLIENTS_PER_FABRIC int "Intermittently Connected Device number of clients per fabric" default 2 + depends on CHIP_ICD_CHECK_IN_SUPPORT help Provides the Intermittently Connected Device number of clients per fabric. It determines the maximum number of clients per fabric that can be registered to receive notification from a device if their subscription is lost. diff --git a/examples/lit-icd-app/linux/args.gni b/examples/lit-icd-app/linux/args.gni index c1421b0c721f9b..09ea58ef2a51d5 100644 --- a/examples/lit-icd-app/linux/args.gni +++ b/examples/lit-icd-app/linux/args.gni @@ -30,3 +30,4 @@ matter_enable_tracing_support = true chip_enable_icd_server = true chip_subscription_timeout_resumption = false chip_icd_report_on_active_mode = true +chip_enable_icd_lit = true diff --git a/examples/lit-icd-app/silabs/build_for_wifi_args.gni b/examples/lit-icd-app/silabs/build_for_wifi_args.gni index 630cb65b53f45d..d8bdeba3f69d49 100644 --- a/examples/lit-icd-app/silabs/build_for_wifi_args.gni +++ b/examples/lit-icd-app/silabs/build_for_wifi_args.gni @@ -28,6 +28,7 @@ chip_enable_icd_server = true chip_subscription_timeout_resumption = false sl_use_subscription_synching = true icd_enforce_sit_slow_poll_limit = true +chip_enable_icd_lit = true # ICD Matter Configuration flags sl_idle_mode_interval_s = 3600 # 60min Idle Mode Interval diff --git a/examples/lit-icd-app/silabs/openthread.gni b/examples/lit-icd-app/silabs/openthread.gni index 69bd7b88e6bdc6..bd93778a53016f 100644 --- a/examples/lit-icd-app/silabs/openthread.gni +++ b/examples/lit-icd-app/silabs/openthread.gni @@ -32,6 +32,7 @@ chip_subscription_timeout_resumption = false sl_use_subscription_synching = true icd_enforce_sit_slow_poll_limit = true chip_icd_report_on_active_mode = true +chip_enable_icd_lit = true # Openthread Configuration flags sl_ot_idle_interval_ms = 3600000 # 60mins Idle Polling Interval diff --git a/src/app/clusters/icd-management-server/icd-management-server.cpp b/src/app/clusters/icd-management-server/icd-management-server.cpp index e748030f1da9d3..7c0f40e4694feb 100644 --- a/src/app/clusters/icd-management-server/icd-management-server.cpp +++ b/src/app/clusters/icd-management-server/icd-management-server.cpp @@ -23,7 +23,6 @@ #include #include #include -#include #include #include #include @@ -46,6 +45,7 @@ class IcdManagementAttributeAccess : public AttributeAccessInterface public: IcdManagementAttributeAccess() : AttributeAccessInterface(MakeOptional(kRootEndpointId), IcdManagement::Id) {} +#if CHIP_CONFIG_ENABLE_ICD_CIP void Init(PersistentStorageDelegate & storage, Crypto::SymmetricKeystore * symmetricKeystore, FabricTable & fabricTable, ICDConfigurationData & icdConfigurationData) { @@ -54,6 +54,9 @@ class IcdManagementAttributeAccess : public AttributeAccessInterface mFabricTable = &fabricTable; mICDConfigurationData = &icdConfigurationData; } +#else + void Init(ICDConfigurationData & icdConfigurationData) { mICDConfigurationData = &icdConfigurationData; } +#endif // CHIP_CONFIG_ENABLE_ICD_CIP CHIP_ERROR Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) override; @@ -61,6 +64,10 @@ class IcdManagementAttributeAccess : public AttributeAccessInterface CHIP_ERROR ReadIdleModeDuration(EndpointId endpoint, AttributeValueEncoder & encoder); CHIP_ERROR ReadActiveModeDuration(EndpointId endpoint, AttributeValueEncoder & encoder); CHIP_ERROR ReadActiveModeThreshold(EndpointId endpoint, AttributeValueEncoder & encoder); + + ICDConfigurationData * mICDConfigurationData = nullptr; + +#if CHIP_CONFIG_ENABLE_ICD_CIP CHIP_ERROR ReadRegisteredClients(EndpointId endpoint, AttributeValueEncoder & encoder); CHIP_ERROR ReadICDCounter(EndpointId endpoint, AttributeValueEncoder & encoder); CHIP_ERROR ReadClientsSupportedPerFabric(EndpointId endpoint, AttributeValueEncoder & encoder); @@ -68,7 +75,7 @@ class IcdManagementAttributeAccess : public AttributeAccessInterface PersistentStorageDelegate * mStorage = nullptr; Crypto::SymmetricKeystore * mSymmetricKeystore = nullptr; FabricTable * mFabricTable = nullptr; - ICDConfigurationData * mICDConfigurationData = nullptr; +#endif // CHIP_CONFIG_ENABLE_ICD_CIP }; CHIP_ERROR IcdManagementAttributeAccess::Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) @@ -86,6 +93,7 @@ CHIP_ERROR IcdManagementAttributeAccess::Read(const ConcreteReadAttributePath & case IcdManagement::Attributes::ActiveModeThreshold::Id: return ReadActiveModeThreshold(aPath.mEndpointId, aEncoder); +#if CHIP_CONFIG_ENABLE_ICD_CIP case IcdManagement::Attributes::RegisteredClients::Id: return ReadRegisteredClients(aPath.mEndpointId, aEncoder); @@ -94,6 +102,10 @@ CHIP_ERROR IcdManagementAttributeAccess::Read(const ConcreteReadAttributePath & case IcdManagement::Attributes::ClientsSupportedPerFabric::Id: return ReadClientsSupportedPerFabric(aPath.mEndpointId, aEncoder); +#endif // CHIP_CONFIG_ENABLE_ICD_CIP + + default: + return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; } return CHIP_NO_ERROR; @@ -114,6 +126,19 @@ CHIP_ERROR IcdManagementAttributeAccess::ReadActiveModeThreshold(EndpointId endp return encoder.Encode(mICDConfigurationData->GetActiveModeThresholdMs()); } +} // namespace + +/* + * ICD Management Implementation + */ + +ICDConfigurationData * ICDManagementServer::mICDConfigurationData = nullptr; +IcdManagementAttributeAccess gAttribute; + +#if CHIP_CONFIG_ENABLE_ICD_CIP + +namespace { + CHIP_ERROR IcdManagementAttributeAccess::ReadRegisteredClients(EndpointId endpoint, AttributeValueEncoder & encoder) { uint16_t supported_clients = mICDConfigurationData->GetClientsSupportedPerFabric(); @@ -186,7 +211,6 @@ class IcdManagementFabricDelegate : public FabricTable::Delegate }; IcdManagementFabricDelegate gFabricDelegate; -IcdManagementAttributeAccess gAttribute; /** * @brief Function checks if the client has admin permissions to the cluster in the commandPath @@ -214,13 +238,15 @@ CHIP_ERROR CheckAdmin(CommandHandler * commandObj, const ConcreteCommandPath & c } // namespace -/* - * ICD Management Implementation - */ - PersistentStorageDelegate * ICDManagementServer::mStorage = nullptr; Crypto::SymmetricKeystore * ICDManagementServer::mSymmetricKeystore = nullptr; -ICDConfigurationData * ICDManagementServer::mICDConfigurationData = nullptr; + +void ICDManagementServer::InitCheckInServer(chip::PersistentStorageDelegate & storage, + chip::Crypto::SymmetricKeystore * symmetricKeystore) +{ + mStorage = &storage; + mSymmetricKeystore = symmetricKeystore; +} Status ICDManagementServer::RegisterClient(CommandHandler * commandObj, const ConcreteCommandPath & commandPath, const Commands::RegisterClient::DecodableType & commandData, uint32_t & icdCounter) @@ -333,6 +359,13 @@ Status ICDManagementServer::UnregisterClient(CommandHandler * commandObj, const return InteractionModel::Status::Success; } +void ICDManagementServer::TriggerICDMTableUpdatedEvent() +{ + ICDNotifier::GetInstance().NotifyICDManagementEvent(ICDListener::ICDManagementEvents::kTableUpdated); +} + +#endif // CHIP_CONFIG_ENABLE_ICD_CIP + Status ICDManagementServer::StayActiveRequest(FabricIndex fabricIndex) { // TODO: Implementent stay awake logic for end device @@ -341,16 +374,8 @@ Status ICDManagementServer::StayActiveRequest(FabricIndex fabricIndex) return InteractionModel::Status::UnsupportedCommand; } -void ICDManagementServer::TriggerICDMTableUpdatedEvent() -{ - ICDNotifier::GetInstance().NotifyICDManagementEvent(ICDListener::ICDManagementEvents::kTableUpdated); -} - -void ICDManagementServer::Init(PersistentStorageDelegate & storage, Crypto::SymmetricKeystore * symmetricKeystore, - ICDConfigurationData & icdConfigurationData) +void ICDManagementServer::Init(ICDConfigurationData & icdConfigurationData) { - mStorage = &storage; - mSymmetricKeystore = symmetricKeystore; mICDConfigurationData = &icdConfigurationData; } @@ -358,6 +383,7 @@ void ICDManagementServer::Init(PersistentStorageDelegate & storage, Crypto::Symm * Callbacks Implementation *********************************************************/ +#if CHIP_CONFIG_ENABLE_ICD_CIP /** * @brief ICD Management Cluster RegisterClient Command callback (from client) * @@ -396,6 +422,7 @@ bool emberAfIcdManagementClusterUnregisterClientCallback(CommandHandler * comman commandObj->AddStatus(commandPath, status); return true; } +#endif // CHIP_CONFIG_ENABLE_ICD_CIP /** * @brief ICD Management Cluster StayActiveRequest Command callback (from client) @@ -412,19 +439,28 @@ bool emberAfIcdManagementClusterStayActiveRequestCallback(CommandHandler * comma void MatterIcdManagementPluginServerInitCallback() { + ICDConfigurationData & icdConfigurationData = ICDConfigurationData::GetInstance().GetInstance(); + +#if CHIP_CONFIG_ENABLE_ICD_CIP PersistentStorageDelegate & storage = Server::GetInstance().GetPersistentStorage(); - FabricTable & fabricTable = Server::GetInstance().GetFabricTable(); Crypto::SymmetricKeystore * symmetricKeystore = Server::GetInstance().GetSessionKeystore(); - ICDConfigurationData & icdConfigurationData = ICDConfigurationData::GetInstance().GetInstance(); + FabricTable & fabricTable = Server::GetInstance().GetFabricTable(); // Configure and register Fabric delegate gFabricDelegate.Init(storage, symmetricKeystore, icdConfigurationData); fabricTable.AddFabricDelegate(&gFabricDelegate); + ICDManagementServer::InitCheckInServer(storage, symmetricKeystore); + // Configure and register Attribute Access Override gAttribute.Init(storage, symmetricKeystore, fabricTable, icdConfigurationData); +#else + // Configure and register Attribute Access Override + gAttribute.Init(icdConfigurationData); +#endif // CHIP_CONFIG_ENABLE_ICD_CIP + registerAttributeAccessOverride(&gAttribute); // Configure ICD Management - ICDManagementServer::Init(storage, symmetricKeystore, icdConfigurationData); + ICDManagementServer::Init(icdConfigurationData); } diff --git a/src/app/clusters/icd-management-server/icd-management-server.h b/src/app/clusters/icd-management-server/icd-management-server.h index 308d50859d2d4b..dbbda8e33eed14 100644 --- a/src/app/clusters/icd-management-server/icd-management-server.h +++ b/src/app/clusters/icd-management-server/icd-management-server.h @@ -19,16 +19,21 @@ #include #include -#include #include -#include #include -#include -#include #include #include #include +#include + +#if CHIP_CONFIG_ENABLE_ICD_CIP +#include +#include +#include +#include +#endif // CHIP_CONFIG_ENABLE_ICD_CIP + using chip::Protocols::InteractionModel::Status; class ICDManagementServer @@ -36,8 +41,10 @@ class ICDManagementServer public: ICDManagementServer() = default; - static void Init(chip::PersistentStorageDelegate & storage, chip::Crypto::SymmetricKeystore * symmetricKeystore, - chip::ICDConfigurationData & ICDConfigurationData); + static void Init(chip::ICDConfigurationData & ICDConfigurationData); + +#if CHIP_CONFIG_ENABLE_ICD_CIP + static void InitCheckInServer(chip::PersistentStorageDelegate & storage, chip::Crypto::SymmetricKeystore * symmetricKeystore); /** * @brief Function that executes the business logic of the RegisterClient Command @@ -52,10 +59,14 @@ class ICDManagementServer Status UnregisterClient(chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, const chip::app::Clusters::IcdManagement::Commands::UnregisterClient::DecodableType & commandData); +#endif // CHIP_CONFIG_ENABLE_ICD_CIP Status StayActiveRequest(chip::FabricIndex fabricIndex); private: + static chip::ICDConfigurationData * mICDConfigurationData; + +#if CHIP_CONFIG_ENABLE_ICD_CIP /** * @brief Triggers table update events to notify subscribers that an entry was added or removed * from the ICDMonitoringTable. @@ -64,5 +75,5 @@ class ICDManagementServer static chip::PersistentStorageDelegate * mStorage; static chip::Crypto::SymmetricKeystore * mSymmetricKeystore; - static chip::ICDConfigurationData * mICDConfigurationData; +#endif // CHIP_CONFIG_ENABLE_ICD_CIP }; diff --git a/src/app/icd/icd.gni b/src/app/icd/icd.gni index 1f2ac247f6fb38..34f4c0c8c5139c 100644 --- a/src/app/icd/icd.gni +++ b/src/app/icd/icd.gni @@ -17,6 +17,10 @@ declare_args() { # TODO - Add Specifics when the design is refined chip_enable_icd_server = false + chip_enable_icd_lit = false + chip_enable_icd_cip = false + chip_enable_icd_uat = false + # Matter SDK Configuration flag to enable ICD client functionality # TODO - Add Specifics when the design is refined chip_enable_icd_client = false diff --git a/src/app/icd/server/BUILD.gn b/src/app/icd/server/BUILD.gn index ee2b2be0034c5c..313c19ea4dd2f1 100644 --- a/src/app/icd/server/BUILD.gn +++ b/src/app/icd/server/BUILD.gn @@ -22,8 +22,17 @@ buildconfig_header("icd-server-buildconfig") { header = "ICDServerBuildConfig.h" header_dir = "app/icd/server" + # Enable mandatory features for the LIT. + if (chip_enable_icd_lit) { + chip_enable_icd_cip = true + chip_enable_icd_uat = true + } + defines = [ "CHIP_CONFIG_ENABLE_ICD_SERVER=${chip_enable_icd_server}", + "CHIP_CONFIG_ENABLE_ICD_LIT=${chip_enable_icd_lit}", + "CHIP_CONFIG_ENABLE_ICD_CIP=${chip_enable_icd_cip}", + "CHIP_CONFIG_ENABLE_ICD_UAT=${chip_enable_icd_uat}", "ICD_REPORT_ON_ENTER_ACTIVE_MODE=${chip_icd_report_on_active_mode}", "ICD_MAX_NOTIFICATION_SUBSCRIBERS=${icd_max_notification_subscribers}", "ICD_ENFORCE_SIT_SLOW_POLL_LIMIT=${icd_enforce_sit_slow_poll_limit}", @@ -62,17 +71,23 @@ source_set("manager") { "ICDManager.h", ] - deps = [ ":icd-server-config" ] + public_deps = [ ":icd-server-config" ] - public_deps = [ + public_deps += [ ":configuration-data", - ":monitoring-table", ":notifier", ":observer", - ":sender", - "${chip_root}/src/app:subscription-manager", + "${chip_root}/src/app:interaction-model", "${chip_root}/src/credentials:credentials", ] + + if (chip_enable_icd_cip) { + public_deps += [ + ":monitoring-table", + ":sender", + "${chip_root}/src/app:subscription-manager", + ] + } } source_set("sender") { diff --git a/src/app/icd/server/ICDManager.cpp b/src/app/icd/server/ICDManager.cpp index 2fbf7ae8fb39b9..08064e8bf164d1 100644 --- a/src/app/icd/server/ICDManager.cpp +++ b/src/app/icd/server/ICDManager.cpp @@ -20,7 +20,6 @@ #include #include #include -#include #include #include #include @@ -39,15 +38,13 @@ using namespace chip::app::Clusters::IcdManagement; static_assert(UINT8_MAX >= CHIP_CONFIG_MAX_EXCHANGE_CONTEXTS, "ICDManager::mOpenExchangeContextCount cannot hold count for the max exchange count"); -void ICDManager::Init(PersistentStorageDelegate * storage, FabricTable * fabricTable, Crypto::SymmetricKeystore * symmetricKeystore, - Messaging::ExchangeManager * exchangeManager, SubscriptionsInfoProvider * manager) +void ICDManager::Init() { - VerifyOrDie(storage != nullptr); - VerifyOrDie(fabricTable != nullptr); - VerifyOrDie(symmetricKeystore != nullptr); - VerifyOrDie(exchangeManager != nullptr); - VerifyOrDie(manager != nullptr); +#if CHIP_CONFIG_ENABLE_ICD_CIP + VerifyOrDie(mCheckInServerInitialized); +#endif // CHIP_CONFIG_ENABLE_ICD_CIP +#if CHIP_CONFIG_ENABLE_ICD_LIT // LIT ICD Verification Checks if (SupportsFeature(Feature::kLongIdleTimeSupport)) { @@ -62,17 +59,10 @@ void ICDManager::Init(PersistentStorageDelegate * storage, FabricTable * fabricT // VerifyOrDieWithMsg((GetSlowPollingInterval() <= GetSITPollingThreshold()) , AppServer, // "LIT support is required for slow polling intervals superior to 15 seconds"); } +#endif // CHIP_CONFIG_ENABLE_ICD_LIT VerifyOrDie(ICDNotifier::GetInstance().Subscribe(this) == CHIP_NO_ERROR); - mStorage = storage; - mFabricTable = fabricTable; - mSymmetricKeystore = symmetricKeystore; - mExchangeManager = exchangeManager; - mSubManager = manager; - - VerifyOrDie(InitCounter() == CHIP_NO_ERROR); - UpdateICDMode(); UpdateOperationState(OperationalState::IdleMode); } @@ -88,13 +78,14 @@ void ICDManager::Shutdown() ICDConfigurationData::GetInstance().SetICDMode(ICDConfigurationData::ICDMode::SIT); mOperationalState = OperationalState::ActiveMode; + mStateObserverPool.ReleaseAll(); +#if CHIP_CONFIG_ENABLE_ICD_CIP mStorage = nullptr; mFabricTable = nullptr; mSubManager = nullptr; - - mStateObserverPool.ReleaseAll(); mICDSenderPool.ReleaseAll(); +#endif // CHIP_CONFIG_ENABLE_ICD_CIP } bool ICDManager::SupportsFeature(Feature feature) @@ -109,6 +100,27 @@ bool ICDManager::SupportsFeature(Feature feature) #endif // !CONFIG_BUILD_FOR_HOST_UNIT_TEST } +#if CHIP_CONFIG_ENABLE_ICD_CIP +void ICDManager::InitCheckInServer(PersistentStorageDelegate * storage, FabricTable * fabricTable, + Crypto::SessionKeystore * symmetricKeystore, Messaging::ExchangeManager * exchangeManager, + SubscriptionsInfoProvider * manager) +{ + VerifyOrDie(storage != nullptr); + VerifyOrDie(fabricTable != nullptr); + VerifyOrDie(symmetricKeystore != nullptr); + VerifyOrDie(exchangeManager != nullptr); + VerifyOrDie(manager != nullptr); + + mStorage = storage; + mFabricTable = fabricTable; + mSymmetricKeystore = symmetricKeystore; + mExchangeManager = exchangeManager; + mSubManager = manager; + + VerifyOrDie(InitCounter() == CHIP_NO_ERROR); + mCheckInServerInitialized = true; +} + void ICDManager::SendCheckInMsgs() { #if !CONFIG_BUILD_FOR_HOST_UNIT_TEST @@ -223,12 +235,52 @@ CHIP_ERROR ICDManager::IncrementCounter() return CHIP_NO_ERROR; } +bool ICDManager::CheckInMessagesWouldBeSent() +{ + for (const auto & fabricInfo : *mFabricTable) + { + uint16_t supported_clients = ICDConfigurationData::GetInstance().GetClientsSupportedPerFabric(); + + ICDMonitoringTable table(*mStorage, fabricInfo.GetFabricIndex(), supported_clients /*Table entry limit*/, + mSymmetricKeystore); + if (table.IsEmpty()) + { + continue; + } + + for (uint16_t i = 0; i < table.Limit(); i++) + { + ICDMonitoringEntry entry(mSymmetricKeystore); + CHIP_ERROR err = table.Get(i, entry); + if (err == CHIP_ERROR_NOT_FOUND) + { + break; + } + + if (err != CHIP_NO_ERROR) + { + // Try to fetch the next entry upon failure (should not happen). + ChipLogError(AppServer, "Failed to retrieved ICDMonitoring entry, will try next entry."); + continue; + } + + // At least one registration would require a Check-In message + VerifyOrReturnValue(mSubManager->SubjectHasActiveSubscription(entry.fabricIndex, entry.monitoredSubject), true); + } + } + + // None of the registrations would require a Check-In message + return false; +} +#endif // CHIP_CONFIG_ENABLE_ICD_CIP + void ICDManager::UpdateICDMode() { assertChipStackLockedByCurrentThread(); ICDConfigurationData::ICDMode tempMode = ICDConfigurationData::ICDMode::SIT; +#if CHIP_CONFIG_ENABLE_ICD_LIT // Device can only switch to the LIT operating mode if LIT support is present if (SupportsFeature(Feature::kLongIdleTimeSupport)) { @@ -246,6 +298,7 @@ void ICDManager::UpdateICDMode() } } } +#endif // CHIP_CONFIG_ENABLE_ICD_LIT if (ICDConfigurationData::GetInstance().GetICDMode() != tempMode) { @@ -280,7 +333,11 @@ void ICDManager::UpdateOperationState(OperationalState state) // When the active mode interval is 0, we stay in idleMode until a notification brings the icd into active mode // unless the device would need to send Check-In messages // TODO(#30281) : Verify how persistent subscriptions affects this at ICDManager::Init - if (ICDConfigurationData::GetInstance().GetActiveModeDurationMs() > 0 || CheckInMessagesWouldBeSent()) + if (ICDConfigurationData::GetInstance().GetActiveModeDurationMs() > 0 +#if CHIP_CONFIG_ENABLE_ICD_CIP + || CheckInMessagesWouldBeSent() +#endif // CHIP_CONFIG_ENABLE_ICD_CIP + ) { uint32_t idleModeDuration = ICDConfigurationData::GetInstance().GetIdleModeDurationSec(); DeviceLayer::SystemLayer().StartTimer(System::Clock::Seconds32(idleModeDuration), OnIdleModeDone, this); @@ -288,8 +345,10 @@ void ICDManager::UpdateOperationState(OperationalState state) System::Clock::Milliseconds32 slowPollInterval = ICDConfigurationData::GetInstance().GetSlowPollingInterval(); +#if CHIP_CONFIG_ENABLE_ICD_CIP // Going back to Idle, all Check-In messages are sent mICDSenderPool.ReleaseAll(); +#endif // CHIP_CONFIG_ENABLE_ICD_CIP CHIP_ERROR err = DeviceLayer::ConnectivityMgr().SetPollingInterval(slowPollInterval); if (err != CHIP_NO_ERROR) @@ -328,10 +387,12 @@ void ICDManager::UpdateOperationState(OperationalState state) ChipLogError(AppServer, "Failed to set Fast Polling Interval: err %" CHIP_ERROR_FORMAT, err.Format()); } +#if CHIP_CONFIG_ENABLE_ICD_CIP if (SupportsFeature(Feature::kCheckInProtocolSupport)) { SendCheckInMsgs(); } +#endif // CHIP_CONFIG_ENABLE_ICD_CIP postObserverEvent(ObserverEventType::EnterActiveMode); } @@ -412,12 +473,14 @@ void ICDManager::OnKeepActiveRequest(KeepActiveFlags request) this->mOpenExchangeContextCount++; } +#if CHIP_CONFIG_ENABLE_ICD_CIP if (request.Has(KeepActiveFlag::kCheckInInProgress)) { // There can be multiple check-in at the same time. // Keep track of the requests count. this->mCheckInRequestCount++; } +#endif // CHIP_CONFIG_ENABLE_ICD_CIP this->SetKeepActiveModeRequirements(request, true /* state */); } @@ -447,6 +510,7 @@ void ICDManager::OnActiveRequestWithdrawal(KeepActiveFlags request) } } +#if CHIP_CONFIG_ENABLE_ICD_CIP if (request.Has(KeepActiveFlag::kCheckInInProgress)) { // There can be multiple open exchange contexts at the same time. @@ -465,6 +529,7 @@ void ICDManager::OnActiveRequestWithdrawal(KeepActiveFlags request) this->SetKeepActiveModeRequirements(KeepActiveFlag::kCheckInInProgress, false /* state */); } } +#endif // CHIP_CONFIG_ENABLE_ICD_CIP if (request.Has(KeepActiveFlag::kCommissioningWindowOpen) || request.Has(KeepActiveFlag::kFailSafeArmed)) { @@ -547,43 +612,5 @@ void ICDManager::postObserverEvent(ObserverEventType event) }); } -bool ICDManager::CheckInMessagesWouldBeSent() -{ - for (const auto & fabricInfo : *mFabricTable) - { - uint16_t supported_clients = ICDConfigurationData::GetInstance().GetClientsSupportedPerFabric(); - - ICDMonitoringTable table(*mStorage, fabricInfo.GetFabricIndex(), supported_clients /*Table entry limit*/, - mSymmetricKeystore); - if (table.IsEmpty()) - { - continue; - } - - for (uint16_t i = 0; i < table.Limit(); i++) - { - ICDMonitoringEntry entry(mSymmetricKeystore); - CHIP_ERROR err = table.Get(i, entry); - if (err == CHIP_ERROR_NOT_FOUND) - { - break; - } - - if (err != CHIP_NO_ERROR) - { - // Try to fetch the next entry upon failure (should not happen). - ChipLogError(AppServer, "Failed to retrieved ICDMonitoring entry, will try next entry."); - continue; - } - - // At least one registration would require a Check-In message - VerifyOrReturnValue(mSubManager->SubjectHasActiveSubscription(entry.fabricIndex, entry.monitoredSubject), true); - } - } - - // None of the registrations would require a Check-In message - return false; -} - } // namespace app } // namespace chip diff --git a/src/app/icd/server/ICDManager.h b/src/app/icd/server/ICDManager.h index 12ae535ce2ed47..2f7377608073fe 100644 --- a/src/app/icd/server/ICDManager.h +++ b/src/app/icd/server/ICDManager.h @@ -17,13 +17,19 @@ #pragma once #include + +#include + +#if CHIP_CONFIG_ENABLE_ICD_CIP #include -#include +#include // nogncheck +#include // nogncheck +#include +#endif // CHIP_CONFIG_ENABLE_ICD_CIP + #include -#include #include #include -#include #include #include #include @@ -66,8 +72,14 @@ class ICDManager : public ICDListener }; ICDManager() {} - void Init(PersistentStorageDelegate * storage, FabricTable * fabricTable, Crypto::SymmetricKeystore * symmetricKeyStore, - Messaging::ExchangeManager * exchangeManager, SubscriptionsInfoProvider * manager); + void Init(); + +#if CHIP_CONFIG_ENABLE_ICD_CIP + void InitCheckInServer(PersistentStorageDelegate * storage, FabricTable * fabricTable, + Crypto::SymmetricKeystore * symmetricKeyStore, Messaging::ExchangeManager * exchangeManager, + SubscriptionsInfoProvider * manager); +#endif // CHIP_CONFIG_ENABLE_ICD_CIP + void Shutdown(); void UpdateICDMode(); void UpdateOperationState(OperationalState state); @@ -94,7 +106,10 @@ class ICDManager : public ICDListener */ void postObserverEvent(ObserverEventType event); OperationalState GetOperationalState() { return mOperationalState; } + +#if CHIP_CONFIG_ENABLE_ICD_CIP void SendCheckInMsgs(); +#endif // CHIP_CONFIG_ENABLE_ICD_CIP #ifdef CONFIG_BUILD_FOR_HOST_UNIT_TEST void SetTestFeatureMapValue(uint32_t featureMap) { mFeatureMap = featureMap; }; @@ -122,14 +137,25 @@ class ICDManager : public ICDListener */ static void OnTransitionToIdle(System::Layer * aLayer, void * appState); +#if CHIP_CONFIG_ENABLE_ICD_CIP // ICD Counter CHIP_ERROR IncrementCounter(); CHIP_ERROR InitCounter(); + uint8_t mCheckInRequestCount = 0; +#endif // CHIP_CONFIG_ENABLE_ICD_CIP + uint8_t mOpenExchangeContextCount = 0; - uint8_t mCheckInRequestCount = 0; private: + KeepActiveFlags mKeepActiveFlags{ 0 }; + + // Initialize mOperationalState to ActiveMode so the init sequence at bootup triggers the IdleMode behaviour first. + OperationalState mOperationalState = OperationalState::ActiveMode; + bool mTransitionToIdleCalled = false; + ObjectPool mStateObserverPool; + +#if CHIP_CONFIG_ENABLE_ICD_CIP /** * @brief Function checks if at least one client registration would require a Check-In message * @@ -139,21 +165,14 @@ class ICDManager : public ICDListener */ bool CheckInMessagesWouldBeSent(); - KeepActiveFlags mKeepActiveFlags{ 0 }; - - // Initialize mOperationalState to ActiveMode so the init sequence at bootup triggers the IdleMode behaviour first. - OperationalState mOperationalState = OperationalState::ActiveMode; - + bool mCheckInServerInitialized = false; PersistentStorageDelegate * mStorage = nullptr; FabricTable * mFabricTable = nullptr; Messaging::ExchangeManager * mExchangeManager = nullptr; Crypto::SymmetricKeystore * mSymmetricKeystore = nullptr; SubscriptionsInfoProvider * mSubManager = nullptr; - - bool mTransitionToIdleCalled = false; - - ObjectPool mStateObserverPool; ObjectPool mICDSenderPool; +#endif // CHIP_CONFIG_ENABLE_ICD_CIP #ifdef CONFIG_BUILD_FOR_HOST_UNIT_TEST // feature map that can be changed at runtime for testing purposes diff --git a/src/app/server/Server.cpp b/src/app/server/Server.cpp index 3c33c45537d5ef..d2589c2cbab180 100644 --- a/src/app/server/Server.cpp +++ b/src/app/server/Server.cpp @@ -339,8 +339,12 @@ CHIP_ERROR Server::Init(const ServerInitParams & initParams) mICDManager.RegisterObserver(mReportScheduler); mICDManager.RegisterObserver(&app::DnssdServer::Instance()); - mICDManager.Init(mDeviceStorage, &GetFabricTable(), mSessionKeystore, &mExchangeMgr, - chip::app::InteractionModelEngine::GetInstance()); +#if CHIP_CONFIG_ENABLE_ICD_CIP + mICDManager.InitCheckInServer(mDeviceStorage, &GetFabricTable(), mSessionKeystore, &mExchangeMgr, + chip::app::InteractionModelEngine::GetInstance()); +#endif // CHIP_CONFIG_ENABLE_ICD_CIP + + mICDManager.Init(); #endif // CHIP_CONFIG_ENABLE_ICD_SERVER // This code is necessary to restart listening to existing groups after a reboot diff --git a/src/app/tests/BUILD.gn b/src/app/tests/BUILD.gn index 88311e2b414e58..0cf1fd0a7e097b 100644 --- a/src/app/tests/BUILD.gn +++ b/src/app/tests/BUILD.gn @@ -141,8 +141,6 @@ chip_test_suite_using_nltest("tests") { "TestEventOverflow.cpp", "TestEventPathParams.cpp", "TestFabricScopedEventLogging.cpp", - "TestICDManager.cpp", - "TestICDMonitoringTable.cpp", "TestInteractionModelEngine.cpp", "TestMessageDef.cpp", "TestNumericAttributeTraits.cpp", @@ -208,7 +206,6 @@ chip_test_suite_using_nltest("tests") { "${chip_root}/src/app", "${chip_root}/src/app/common:cluster-objects", "${chip_root}/src/app/icd/client:manager", - "${chip_root}/src/app/icd/server:manager", "${chip_root}/src/app/tests:helpers", "${chip_root}/src/app/util/mock:mock_ember", "${chip_root}/src/lib/core", @@ -217,6 +214,16 @@ chip_test_suite_using_nltest("tests") { "${nlunit_test_root}:nlunit-test", ] + if (chip_enable_icd_server) { + public_deps += [ "${chip_root}/src/app/icd/server:manager" ] + + test_sources += [ "TestICDManager.cpp" ] + + if (chip_enable_icd_cip) { + test_sources += [ "TestICDMonitoringTable.cpp" ] + } + } + if (chip_device_platform != "android") { test_sources += [ "TestExtensionFieldSets.cpp", diff --git a/src/platform/nrfconnect/CHIPPlatformConfig.h b/src/platform/nrfconnect/CHIPPlatformConfig.h index c8187675c4a100..778372394b35ae 100644 --- a/src/platform/nrfconnect/CHIPPlatformConfig.h +++ b/src/platform/nrfconnect/CHIPPlatformConfig.h @@ -113,15 +113,15 @@ #endif // CHIP_CONFIG_MRP_LOCAL_IDLE_RETRY_INTERVAL #ifndef CHIP_CONFIG_ICD_IDLE_MODE_DURATION_SEC -#ifdef CONFIG_CHIP_ICD_IDLE_MODE_INTERVAL -#define CHIP_CONFIG_ICD_IDLE_MODE_DURATION_SEC CONFIG_CHIP_ICD_IDLE_MODE_INTERVAL -#endif // CONFIG_CHIP_ICD_IDLE_MODE_INTERVAL +#ifdef CONFIG_CHIP_ICD_IDLE_MODE_DURATION +#define CHIP_CONFIG_ICD_IDLE_MODE_DURATION_SEC CONFIG_CHIP_ICD_IDLE_MODE_DURATION +#endif // CONFIG_CHIP_ICD_IDLE_MODE_DURATION #endif // CHIP_CONFIG_ICD_IDLE_MODE_DURATION_SEC #ifndef CHIP_CONFIG_ICD_ACTIVE_MODE_DURATION_MS -#ifdef CONFIG_CHIP_ICD_ACTIVE_MODE_INTERVAL -#define CHIP_CONFIG_ICD_ACTIVE_MODE_DURATION_MS CONFIG_CHIP_ICD_ACTIVE_MODE_INTERVAL -#endif // CONFIG_CHIP_ICD_ACTIVE_MODE_INTERVAL +#ifdef CONFIG_CHIP_ICD_ACTIVE_MODE_DURATION +#define CHIP_CONFIG_ICD_ACTIVE_MODE_DURATION_MS CONFIG_CHIP_ICD_ACTIVE_MODE_DURATION +#endif // CONFIG_CHIP_ICD_ACTIVE_MODE_DURATION #endif // CHIP_CONFIG_ICD_ACTIVE_MODE_DURATION_MS #ifndef CHIP_CONFIG_ICD_ACTIVE_MODE_THRESHOLD_MS diff --git a/src/platform/nxp/zephyr/CHIPPlatformConfig.h b/src/platform/nxp/zephyr/CHIPPlatformConfig.h index cd9873051e5fed..d5ed1717bd64d4 100644 --- a/src/platform/nxp/zephyr/CHIPPlatformConfig.h +++ b/src/platform/nxp/zephyr/CHIPPlatformConfig.h @@ -114,15 +114,15 @@ #endif // CHIP_CONFIG_MRP_LOCAL_IDLE_RETRY_INTERVAL #ifndef CHIP_CONFIG_ICD_IDLE_MODE_DURATION_SEC -#ifdef CONFIG_CHIP_ICD_IDLE_MODE_INTERVAL -#define CHIP_CONFIG_ICD_IDLE_MODE_DURATION_SEC CONFIG_CHIP_ICD_IDLE_MODE_INTERVAL -#endif // CONFIG_CHIP_ICD_IDLE_MODE_INTERVAL +#ifdef CONFIG_CHIP_ICD_IDLE_MODE_DURATION +#define CHIP_CONFIG_ICD_IDLE_MODE_DURATION_SEC CONFIG_CHIP_ICD_IDLE_MODE_DURATION +#endif // CONFIG_CHIP_ICD_IDLE_MODE_DURATION #endif // CHIP_CONFIG_ICD_IDLE_MODE_DURATION_SEC #ifndef CHIP_CONFIG_ICD_ACTIVE_MODE_DURATION_MS -#ifdef CONFIG_CHIP_ICD_ACTIVE_MODE_INTERVAL -#define CHIP_CONFIG_ICD_ACTIVE_MODE_DURATION_MS CONFIG_CHIP_ICD_ACTIVE_MODE_INTERVAL -#endif // CONFIG_CHIP_ICD_ACTIVE_MODE_INTERVAL +#ifdef CONFIG_CHIP_ICD_ACTIVE_MODE_DURATION +#define CHIP_CONFIG_ICD_ACTIVE_MODE_DURATION_MS CONFIG_CHIP_ICD_ACTIVE_MODE_DURATION +#endif // CONFIG_CHIP_ICD_ACTIVE_MODE_DURATION #endif // CHIP_CONFIG_ICD_ACTIVE_MODE_DURATION_MS #ifndef CHIP_CONFIG_ICD_ACTIVE_MODE_THRESHOLD_MS diff --git a/src/platform/telink/CHIPPlatformConfig.h b/src/platform/telink/CHIPPlatformConfig.h index 9e0dc3dd36e8f7..1bb4ab7b07203d 100644 --- a/src/platform/telink/CHIPPlatformConfig.h +++ b/src/platform/telink/CHIPPlatformConfig.h @@ -133,15 +133,15 @@ #endif #ifndef CHIP_CONFIG_ICD_IDLE_MODE_DURATION_SEC -#ifdef CONFIG_CHIP_ICD_IDLE_MODE_INTERVAL -#define CHIP_CONFIG_ICD_IDLE_MODE_DURATION_SEC CONFIG_CHIP_ICD_IDLE_MODE_INTERVAL -#endif // CONFIG_CHIP_ICD_IDLE_MODE_INTERVAL +#ifdef CONFIG_CHIP_ICD_IDLE_MODE_DURATION +#define CHIP_CONFIG_ICD_IDLE_MODE_DURATION_SEC CONFIG_CHIP_ICD_IDLE_MODE_DURATION +#endif // CONFIG_CHIP_ICD_IDLE_MODE_DURATION #endif // CHIP_CONFIG_ICD_IDLE_MODE_DURATION_SEC #ifndef CHIP_CONFIG_ICD_ACTIVE_MODE_DURATION_MS -#ifdef CONFIG_CHIP_ICD_ACTIVE_MODE_INTERVAL -#define CHIP_CONFIG_ICD_ACTIVE_MODE_DURATION_MS CONFIG_CHIP_ICD_ACTIVE_MODE_INTERVAL -#endif // CONFIG_CHIP_ICD_ACTIVE_MODE_INTERVAL +#ifdef CONFIG_CHIP_ICD_ACTIVE_MODE_DURATION +#define CHIP_CONFIG_ICD_ACTIVE_MODE_DURATION_MS CONFIG_CHIP_ICD_ACTIVE_MODE_DURATION +#endif // CONFIG_CHIP_ICD_ACTIVE_MODE_DURATION #endif // CHIP_CONFIG_ICD_ACTIVE_MODE_DURATION_MS #ifndef CHIP_CONFIG_ICD_ACTIVE_MODE_THRESHOLD_MS