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 Feb 8, 2024
1 parent 61724ee commit 5b5c296
Show file tree
Hide file tree
Showing 20 changed files with 313 additions and 164 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/unit_integration_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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_lit=true';;
*) ;;
esac
Expand Down
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_checkin" CONFIG_CHIP_ICD_CHECK_IN_SUPPORT)
matter_add_gn_arg_bool ("chip_enable_icd_user_active_mode_trigger" 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
6 changes: 6 additions & 0 deletions config/telink/chip-module/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ matter_add_gn_arg_bool ("chip_detail_logging" CONFIG_MATTER_
matter_add_gn_arg_bool ("chip_automation_logging" FALSE)
matter_add_gn_arg_bool ("chip_enable_icd_server" CONFIG_CHIP_ENABLE_ICD_SUPPORT)

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_checkin" CONFIG_CHIP_ICD_CHECK_IN_SUPPORT)
matter_add_gn_arg_bool ("chip_enable_icd_user_active_mode_trigger" CONFIG_CHIP_ICD_UAT_SUPPORT)
endif()

if (CONFIG_CHIP_FACTORY_DATA)
matter_add_gn_arg_bool ("chip_use_transitional_commissionable_data_provider" "false")
matter_add_gn_arg_bool ("chip_enable_factory_data" "true")
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/light-switch-app/qpg/args.gni
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ chip_enable_ota_requestor = true
chip_openthread_ftd = false
enable_sleepy_device = true
chip_enable_icd_server = true
chip_enable_icd_lit = true

# Disable lock tracking, since our FreeRTOS configuration does not set
# INCLUDE_xSemaphoreGetMutexHolder
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
2 changes: 2 additions & 0 deletions examples/smoke-co-alarm-app/telink/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,5 @@ CONFIG_CHIP_CERTIFICATION_DECLARATION_STORAGE=n

# Enable Power Management
CONFIG_PM=y

CONFIG_CHIP_ICD_LIT_SUPPORT=y
140 changes: 84 additions & 56 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/server/ICDMonitoringTable.h>
#include <app/icd/server/ICDNotifier.h>
#include <app/server/Server.h>
#include <app/util/af.h>
Expand All @@ -46,12 +45,14 @@ class IcdManagementAttributeAccess : public AttributeAccessInterface
public:
IcdManagementAttributeAccess() : AttributeAccessInterface(MakeOptional(kRootEndpointId), IcdManagement::Id) {}

void Init(PersistentStorageDelegate & storage, Crypto::SymmetricKeystore * symmetricKeystore, FabricTable & fabricTable,
void Init(PersistentStorageDelegate & storage, Crypto::SessionKeystore * symmetricKeystore, FabricTable & fabricTable,
ICDConfigurationData & icdConfigurationData)
{
mStorage = &storage;
mSymmetricKeystore = symmetricKeystore;
mFabricTable = &fabricTable;
#if CHIP_CONFIG_ENABLE_ICD_CIP
mStorage = &storage;
mSymmetricKeystore = symmetricKeystore;
mFabricTable = &fabricTable;
#endif // CHIP_CONFIG_ENABLE_ICD_CIP
mICDConfigurationData = &icdConfigurationData;
}

Expand All @@ -61,14 +62,18 @@ 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);

#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

ICDConfigurationData * mICDConfigurationData = nullptr;
};

CHIP_ERROR IcdManagementAttributeAccess::Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder)
Expand All @@ -86,6 +91,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 +100,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 +124,52 @@ CHIP_ERROR IcdManagementAttributeAccess::ReadActiveModeThreshold(EndpointId endp
return encoder.Encode(mICDConfigurationData->GetActiveModeThreshold().count());
}

#if CHIP_CONFIG_ENABLE_ICD_CIP
/**
* @brief Implementation of Fabric Delegate for ICD Management cluster
*/
class IcdManagementFabricDelegate : public FabricTable::Delegate
{
public:
void Init(PersistentStorageDelegate & storage, Crypto::SymmetricKeystore * symmetricKeystore,
ICDConfigurationData & icdConfigurationData)
{
mStorage = &storage;
mSymmetricKeystore = symmetricKeystore;
mICDConfigurationData = &icdConfigurationData;
}

void OnFabricRemoved(const FabricTable & fabricTable, FabricIndex fabricIndex) override
{
uint16_t supported_clients = mICDConfigurationData->GetClientsSupportedPerFabric();
ICDMonitoringTable table(*mStorage, fabricIndex, supported_clients, mSymmetricKeystore);
table.RemoveAll();
ICDNotifier::GetInstance().NotifyICDManagementEvent(ICDListener::ICDManagementEvents::kTableUpdated);
}

private:
PersistentStorageDelegate * mStorage = nullptr;
Crypto::SymmetricKeystore * mSymmetricKeystore = nullptr;
ICDConfigurationData * mICDConfigurationData = nullptr;
};

#endif // CHIP_CONFIG_ENABLE_ICD_CIP

} // namespace

/*
* ICD Management Implementation
*/

ICDConfigurationData * ICDManagementServer::mICDConfigurationData = nullptr;
IcdManagementAttributeAccess gAttribute;

#if CHIP_CONFIG_ENABLE_ICD_CIP

namespace {

IcdManagementFabricDelegate gFabricDelegate;

CHIP_ERROR IcdManagementAttributeAccess::ReadRegisteredClients(EndpointId endpoint, AttributeValueEncoder & encoder)
{
uint16_t supported_clients = mICDConfigurationData->GetClientsSupportedPerFabric();
Expand Down Expand Up @@ -157,37 +213,6 @@ CHIP_ERROR IcdManagementAttributeAccess::ReadClientsSupportedPerFabric(EndpointI
return encoder.Encode(mICDConfigurationData->GetClientsSupportedPerFabric());
}

/**
* @brief Implementation of Fabric Delegate for ICD Management cluster
*/
class IcdManagementFabricDelegate : public FabricTable::Delegate
{
public:
void Init(PersistentStorageDelegate & storage, Crypto::SymmetricKeystore * symmetricKeystore,
ICDConfigurationData & icdConfigurationData)
{
mStorage = &storage;
mSymmetricKeystore = symmetricKeystore;
mICDConfigurationData = &icdConfigurationData;
}

void OnFabricRemoved(const FabricTable & fabricTable, FabricIndex fabricIndex) override
{
uint16_t supported_clients = mICDConfigurationData->GetClientsSupportedPerFabric();
ICDMonitoringTable table(*mStorage, fabricIndex, supported_clients, mSymmetricKeystore);
table.RemoveAll();
ICDNotifier::GetInstance().NotifyICDManagementEvent(ICDListener::ICDManagementEvents::kTableUpdated);
}

private:
PersistentStorageDelegate * mStorage = nullptr;
Crypto::SymmetricKeystore * mSymmetricKeystore = nullptr;
ICDConfigurationData * mICDConfigurationData = nullptr;
};

IcdManagementFabricDelegate gFabricDelegate;
IcdManagementAttributeAccess gAttribute;

/**
* @brief Function checks if the client has admin permissions to the cluster in the commandPath
*
Expand All @@ -214,13 +239,8 @@ 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;
PersistentStorageDelegate * ICDManagementServer::mStorage = nullptr;
Crypto::SessionKeystore * ICDManagementServer::mSymmetricKeystore = nullptr;

Status ICDManagementServer::RegisterClient(CommandHandler * commandObj, const ConcreteCommandPath & commandPath,
const Commands::RegisterClient::DecodableType & commandData, uint32_t & icdCounter)
Expand Down Expand Up @@ -333,6 +353,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 +368,21 @@ 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,
void ICDManagementServer::Init(PersistentStorageDelegate & storage, Crypto::SessionKeystore * symmetricKeystore,
ICDConfigurationData & icdConfigurationData)
{
mStorage = &storage;
mSymmetricKeystore = symmetricKeystore;
#if CHIP_CONFIG_ENABLE_ICD_CIP
mStorage = &storage;
mSymmetricKeystore = symmetricKeystore;
#endif // CHIP_CONFIG_ENABLE_ICD_CIP
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,14 +438,16 @@ bool emberAfIcdManagementClusterStayActiveRequestCallback(CommandHandler * comma

void MatterIcdManagementPluginServerInitCallback()
{
PersistentStorageDelegate & storage = Server::GetInstance().GetPersistentStorage();
FabricTable & fabricTable = Server::GetInstance().GetFabricTable();
Crypto::SymmetricKeystore * symmetricKeystore = Server::GetInstance().GetSessionKeystore();
ICDConfigurationData & icdConfigurationData = ICDConfigurationData::GetInstance().GetInstance();
PersistentStorageDelegate & storage = Server::GetInstance().GetPersistentStorage();
Crypto::SessionKeystore * symmetricKeystore = Server::GetInstance().GetSessionKeystore();
FabricTable & fabricTable = Server::GetInstance().GetFabricTable();
ICDConfigurationData & icdConfigurationData = ICDConfigurationData::GetInstance().GetInstance();

#if CHIP_CONFIG_ENABLE_ICD_CIP
// Configure and register Fabric delegate
gFabricDelegate.Init(storage, symmetricKeystore, icdConfigurationData);
fabricTable.AddFabricDelegate(&gFabricDelegate);
#endif // CHIP_CONFIG_ENABLE_ICD_CIP

// Configure and register Attribute Access Override
gAttribute.Init(storage, symmetricKeystore, fabricTable, icdConfigurationData);
Expand Down
Loading

0 comments on commit 5b5c296

Please sign in to comment.