Skip to content

Commit

Permalink
[icd] Introduced gn flags to allow conditional code compilation
Browse files Browse the repository at this point in the history
The ICD implementation is compiled with a full set of features,
even if the device uses SIT configuration. It results in a big
flash memory waste on a functionalities that cannot be used by
certain configuration.

Introduced new gn flags corresponding to the ICD features
- LIT, CIP and UAT. Modified the ICD Manager implementation
and icd-management-server code to use created defines
and cut off unused code by the preprocessor.
  • Loading branch information
kkasperczyk-no committed Jan 31, 2024
1 parent a9edb72 commit 9d0d3df
Show file tree
Hide file tree
Showing 15 changed files with 218 additions and 79 deletions.
6 changes: 6 additions & 0 deletions config/nrfconnect/chip-module/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
39 changes: 32 additions & 7 deletions config/zephyr/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
1 change: 1 addition & 0 deletions examples/lit-icd-app/linux/args.gni
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions examples/lit-icd-app/silabs/build_for_wifi_args.gni
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions examples/lit-icd-app/silabs/openthread.gni
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
75 changes: 55 additions & 20 deletions src/app/clusters/icd-management-server/icd-management-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include <app-common/zap-generated/cluster-objects.h>
#include <app-common/zap-generated/ids/Clusters.h>
#include <app/AttributeAccessInterface.h>
#include <app/icd/ICDMonitoringTable.h>
#include <app/icd/ICDNotifier.h>
#include <app/server/Server.h>
#include <app/util/af.h>
Expand All @@ -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)
{
Expand All @@ -54,21 +54,28 @@ 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;

private:
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);

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)
Expand All @@ -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);

Expand All @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -214,13 +238,14 @@ 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)
Expand Down Expand Up @@ -333,6 +358,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
Expand All @@ -341,23 +373,16 @@ 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;
}

/**********************************************************
* Callbacks Implementation
*********************************************************/

#if CHIP_CONFIG_ENABLE_ICD_CIP
/**
* @brief ICD Management Cluster RegisterClient Command callback (from client)
*
Expand Down Expand Up @@ -396,6 +421,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)
Expand All @@ -412,19 +438,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);
}
25 changes: 18 additions & 7 deletions src/app/clusters/icd-management-server/icd-management-server.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,32 @@

#include <app-common/zap-generated/cluster-objects.h>
#include <app/CommandHandler.h>
#include <app/ConcreteAttributePath.h>
#include <app/icd/ICDConfigurationData.h>
#include <app/icd/ICDMonitoringTable.h>
#include <app/util/basic-types.h>
#include <crypto/SessionKeystore.h>
#include <lib/core/CHIPPersistentStorageDelegate.h>
#include <lib/core/Optional.h>
#include <lib/support/Span.h>
#include <protocols/interaction_model/StatusCode.h>

#include <app/icd/ICDBuildConfig.h>

#if CHIP_CONFIG_ENABLE_ICD_CIP
#include <app/ConcreteAttributePath.h>
#include <app/icd/ICDMonitoringTable.h>
#include <crypto/SessionKeystore.h>
#include <lib/core/CHIPPersistentStorageDelegate.h>
#endif // CHIP_CONFIG_ENABLE_ICD_CIP

using chip::Protocols::InteractionModel::Status;

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
Expand All @@ -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.
Expand All @@ -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
};
12 changes: 10 additions & 2 deletions src/app/icd/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ buildconfig_header("icd_buildconfig") {

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}",
Expand Down Expand Up @@ -66,13 +69,18 @@ source_set("manager") {

public_deps = [
":configuration-data",
":monitoring-table",
":notifier",
":observer",
":sender",
"${chip_root}/src/app:interaction-model",
"${chip_root}/src/credentials:credentials",
]

if (chip_enable_icd_cip) {
public_deps += [
":sender",
":monitoring-table",
]
}
}

source_set("sender") {
Expand Down
Loading

0 comments on commit 9d0d3df

Please sign in to comment.