Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

icd management: make the feature map and operating mode managed by AAI #37062

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2023,12 +2023,12 @@ endpoint 0 {
callback attribute clientsSupportedPerFabric;
ram attribute userActiveModeTriggerHint default = 4096;
ram attribute userActiveModeTriggerInstruction default = "Push setup button for Active Mode";
ram attribute operatingMode default = 0;
callback attribute operatingMode;
callback attribute maximumCheckInBackOff;
callback attribute generatedCommandList;
callback attribute acceptedCommandList;
callback attribute attributeList;
ram attribute featureMap default = 0x000F;
callback attribute featureMap;
ram attribute clusterRevision default = 3;

handle command RegisterClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2021,7 +2021,7 @@ endpoint 0 {
callback attribute generatedCommandList;
callback attribute acceptedCommandList;
callback attribute attributeList;
ram attribute featureMap default = 0x0000;
callback attribute featureMap;
ram attribute clusterRevision default = 3;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3136,9 +3136,9 @@ endpoint 0 {
callback attribute clientsSupportedPerFabric;
ram attribute userActiveModeTriggerHint default = 0x1115;
ram attribute userActiveModeTriggerInstruction default = "Power Cycle";
ram attribute operatingMode default = 0;
callback attribute operatingMode;
callback attribute maximumCheckInBackOff;
ram attribute featureMap default = 15;
callback attribute featureMap;
ram attribute clusterRevision default = 3;

handle command RegisterClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3131,7 +3131,7 @@ endpoint 0 {
callback attribute idleModeDuration;
callback attribute activeModeDuration;
callback attribute activeModeThreshold;
ram attribute featureMap default = 0x0000;
callback attribute featureMap;
ram attribute clusterRevision default = 3;
}
}
Expand Down
4 changes: 2 additions & 2 deletions examples/light-switch-app/qpg/zap/switch.matter
Original file line number Diff line number Diff line change
Expand Up @@ -3242,11 +3242,11 @@ endpoint 0 {
callback attribute clientsSupportedPerFabric;
ram attribute userActiveModeTriggerHint default = 0x100;
ram attribute userActiveModeTriggerInstruction default = "Reset the application";
ram attribute operatingMode default = 1;
callback attribute operatingMode;
callback attribute generatedCommandList;
callback attribute acceptedCommandList;
callback attribute attributeList;
ram attribute featureMap default = 0x0007;
callback attribute featureMap;
ram attribute clusterRevision default = 3;

handle command RegisterClient;
Expand Down
4 changes: 2 additions & 2 deletions examples/lit-icd-app/lit-icd-common/lit-icd-server-app.matter
Original file line number Diff line number Diff line change
Expand Up @@ -2089,12 +2089,12 @@ endpoint 0 {
callback attribute clientsSupportedPerFabric;
ram attribute userActiveModeTriggerHint default = 0x111D;
ram attribute userActiveModeTriggerInstruction default = "Restart the application";
ram attribute operatingMode default = 0;
callback attribute operatingMode;
callback attribute maximumCheckInBackOff;
callback attribute generatedCommandList;
callback attribute acceptedCommandList;
callback attribute attributeList;
ram attribute featureMap default = 0x000F;
callback attribute featureMap;
ram attribute clusterRevision default = 3;

handle command RegisterClient;
Expand Down
2 changes: 1 addition & 1 deletion examples/lock-app/lock-common/lock-app.matter
Original file line number Diff line number Diff line change
Expand Up @@ -3175,7 +3175,7 @@ endpoint 0 {
callback attribute idleModeDuration;
callback attribute activeModeDuration;
callback attribute activeModeThreshold;
ram attribute featureMap default = 0x0000;
callback attribute featureMap;
ram attribute clusterRevision default = 3;
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/lock-app/nxp/zap/lock-app.matter
Original file line number Diff line number Diff line change
Expand Up @@ -2683,7 +2683,7 @@ endpoint 0 {
callback attribute generatedCommandList;
callback attribute acceptedCommandList;
callback attribute attributeList;
ram attribute featureMap default = 0x0000;
callback attribute featureMap;
ram attribute clusterRevision default = 1;
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/lock-app/qpg/zap/lock.matter
Original file line number Diff line number Diff line change
Expand Up @@ -2805,7 +2805,7 @@ endpoint 0 {
callback attribute generatedCommandList;
callback attribute acceptedCommandList;
callback attribute attributeList;
ram attribute featureMap default = 0x0000;
callback attribute featureMap;
ram attribute clusterRevision default = 3;
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/lock-app/silabs/data_model/lock-app.matter
Original file line number Diff line number Diff line change
Expand Up @@ -3175,7 +3175,7 @@ endpoint 0 {
callback attribute idleModeDuration;
callback attribute activeModeDuration;
callback attribute activeModeThreshold;
ram attribute featureMap default = 0x0000;
callback attribute featureMap;
ram attribute clusterRevision default = 3;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2471,7 +2471,7 @@ endpoint 0 {
callback attribute generatedCommandList;
callback attribute acceptedCommandList;
callback attribute attributeList;
ram attribute featureMap default = 1;
callback attribute featureMap;
ram attribute clusterRevision default = 3;

handle command RegisterClient;
Expand Down
2 changes: 1 addition & 1 deletion examples/window-app/common/window-app.matter
Original file line number Diff line number Diff line change
Expand Up @@ -2699,7 +2699,7 @@ endpoint 0 {
callback attribute generatedCommandList;
callback attribute acceptedCommandList;
callback attribute attributeList;
ram attribute featureMap default = 0x0000;
callback attribute featureMap;
ram attribute clusterRevision default = 3;
}
}
Expand Down
22 changes: 22 additions & 0 deletions src/app/clusters/icd-management-server/icd-management-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <access/AccessControl.h>
#include <access/Privilege.h>
#include <app-common/zap-generated/attributes/Accessors.h>
#include <app-common/zap-generated/cluster-enums.h>
#include <app-common/zap-generated/cluster-objects.h>
#include <app-common/zap-generated/ids/Clusters.h>
#include <app/AttributeAccessInterface.h>
Expand Down Expand Up @@ -64,6 +65,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);
CHIP_ERROR ReadFeatureMap(EndpointId endpoint, AttributeValueEncoder & encoder)
{
return encoder.Encode(mICDConfigurationData->GetFeatureMap());
}

#if CHIP_CONFIG_ENABLE_ICD_LIT
wqx6 marked this conversation as resolved.
Show resolved Hide resolved
CHIP_ERROR ReadOperatingMode(EndpointId endpoint, AttributeValueEncoder & encoder)
{
return mICDConfigurationData->GetICDMode() == ICDConfigurationData::ICDMode::SIT
? encoder.Encode(IcdManagement::OperatingModeEnum::kSit)
: encoder.Encode(IcdManagement::OperatingModeEnum::kLit);
}

#if CHIP_CONFIG_ENABLE_ICD_CIP
CHIP_ERROR ReadRegisteredClients(EndpointId endpoint, AttributeValueEncoder & encoder);
Expand All @@ -75,6 +88,7 @@ class IcdManagementAttributeAccess : public AttributeAccessInterface
Crypto::SymmetricKeystore * mSymmetricKeystore = nullptr;
FabricTable * mFabricTable = nullptr;
#endif // CHIP_CONFIG_ENABLE_ICD_CIP
#endif // CHIP_CONFIG_ENABLE_ICD_LIT

ICDConfigurationData * mICDConfigurationData = nullptr;
};
Expand All @@ -94,6 +108,13 @@ CHIP_ERROR IcdManagementAttributeAccess::Read(const ConcreteReadAttributePath &
case IcdManagement::Attributes::ActiveModeThreshold::Id:
return ReadActiveModeThreshold(aPath.mEndpointId, aEncoder);

case IcdManagement::Attributes::FeatureMap::Id:
return ReadFeatureMap(aPath.mEndpointId, aEncoder);

#if CHIP_CONFIG_ENABLE_ICD_LIT
case IcdManagement::Attributes::OperatingMode::Id:
return ReadOperatingMode(aPath.mEndpointId, aEncoder);

#if CHIP_CONFIG_ENABLE_ICD_CIP
case IcdManagement::Attributes::RegisteredClients::Id:
return ReadRegisteredClients(aPath.mEndpointId, aEncoder);
Expand All @@ -107,6 +128,7 @@ CHIP_ERROR IcdManagementAttributeAccess::Read(const ConcreteReadAttributePath &
case IcdManagement::Attributes::MaximumCheckInBackOff::Id:
return ReadMaximumCheckInBackOff(aPath.mEndpointId, aEncoder);
#endif // CHIP_CONFIG_ENABLE_ICD_CIP
#endif // CHIP_CONFIG_ENABLE_ICD_LIT
}

return CHIP_NO_ERROR;
Expand Down
25 changes: 24 additions & 1 deletion src/app/icd/server/ICDConfigurationData.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@

#pragma once

#include <app-common/zap-generated/cluster-enums.h>
#include <app/icd/server/ICDServerConfig.h>
#include <lib/core/Optional.h>
#include <lib/support/BitFlags.h>
#include <lib/support/TimeUtils.h>
#include <platform/CHIPDeviceConfig.h>
#include <protocols/secure_channel/CheckInCounter.h>
Expand Down Expand Up @@ -77,6 +79,8 @@ class ICDConfigurationData

System::Clock::Seconds32 GetMaximumCheckInBackoff() { return mMaximumCheckInBackOff; }

BitFlags<app::Clusters::IcdManagement::Feature> GetFeatureMap() { return mFeatureMap; }

/**
* The returned value will depend on the devices operating mode.
* If ICDMode == SIT && the configured slow poll interval is superior to the maximum threshold (15s), the function will return
Expand All @@ -92,7 +96,22 @@ class ICDConfigurationData

private:
// Singleton Object
ICDConfigurationData() = default;
ICDConfigurationData()
{
// Initialize feature map
#if CHIP_CONFIG_ENABLE_ICD_LIT
wqx6 marked this conversation as resolved.
Show resolved Hide resolved
mFeatureMap.Set(app::Clusters::IcdManagement::Feature::kLongIdleTimeSupport);
#if CHIP_CONFIG_ENABLE_ICD_CIP
mFeatureMap.Set(app::Clusters::IcdManagement::Feature::kCheckInProtocolSupport);
#endif // CHIP_CONFIG_ENABLE_ICD_CIP
#if CHIP_CONFIG_ENABLE_ICD_UAT
mFeatureMap.Set(app::Clusters::IcdManagement::Feature::kUserActiveModeTrigger);
#endif // CHIP_CONFIG_ENABLE_ICD_UAT
#if CHIP_CONFIG_ENABLE_ICD_DSLS
wqx6 marked this conversation as resolved.
Show resolved Hide resolved
mFeatureMap.Set(app::Clusters::IcdManagement::Feature::kDynamicSitLitSupport);
#endif // CHIP_CONFIG_ENABLE_ICD_DSLS
#endif // CHIP_CONFIG_ENABLE_ICD_LIT
}
static ICDConfigurationData instance;

// ICD related information is managed by the ICDManager but stored in the ICDConfigurationData to enable consummers to access it
Expand Down Expand Up @@ -125,6 +144,8 @@ class ICDConfigurationData
CHIP_ERROR SetModeDurations(Optional<System::Clock::Milliseconds32> activeModeDuration,
Optional<System::Clock::Milliseconds32> idleModeDuration);

void SetFeatureMap(uint32_t featureMap) { mFeatureMap.SetRaw(featureMap); }

static constexpr System::Clock::Seconds32 kMaxIdleModeDuration = System::Clock::Seconds32(18 * kSecondsPerHour);
static constexpr System::Clock::Seconds32 kMinIdleModeDuration = System::Clock::Seconds32(1);
// As defined in the spec, the maximum guaranteed duration for the StayActiveDuration is 30s "Matter Application
Expand Down Expand Up @@ -169,6 +190,8 @@ class ICDConfigurationData
System::Clock::Milliseconds32 mSlowPollingInterval = CHIP_DEVICE_CONFIG_ICD_SLOW_POLL_INTERVAL;
System::Clock::Milliseconds32 mFastPollingInterval = CHIP_DEVICE_CONFIG_ICD_FAST_POLL_INTERVAL;

BitFlags<app::Clusters::IcdManagement::Feature> mFeatureMap;

ICDMode mICDMode = ICDMode::SIT;
};

Expand Down
15 changes: 1 addition & 14 deletions src/app/icd/server/ICDManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,7 @@ void ICDManager::Shutdown()

bool ICDManager::SupportsFeature(Feature feature)
{
// Can't use attribute accessors/Attributes::FeatureMap::Get in unit tests
#if !(CONFIG_BUILD_FOR_HOST_UNIT_TEST)
uint32_t featureMap = 0;
bool success = (Attributes::FeatureMap::Get(kRootEndpointId, &featureMap) == Status::Success);
return success ? ((featureMap & to_underlying(feature)) != 0) : false;
#else
return ((mFeatureMap & to_underlying(feature)) != 0);
#endif // !(CONFIG_BUILD_FOR_HOST_UNIT_TEST)
return ICDConfigurationData::GetInstance().GetFeatureMap().Has(feature);
}

uint32_t ICDManager::StayActiveRequest(uint32_t stayActiveDuration)
Expand Down Expand Up @@ -394,12 +387,6 @@ void ICDManager::UpdateICDMode()
if (ICDConfigurationData::GetInstance().GetICDMode() != tempMode)
{
ICDConfigurationData::GetInstance().SetICDMode(tempMode);

// Can't use attribute accessors/Attributes::OperatingMode::Set in unit tests
#if !(CONFIG_BUILD_FOR_HOST_UNIT_TEST)
Attributes::OperatingMode::Set(kRootEndpointId, static_cast<OperatingModeEnum>(tempMode));
#endif

postObserverEvent(ObserverEventType::ICDModeChange);
}

Expand Down
6 changes: 0 additions & 6 deletions src/app/icd/server/ICDManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ class ICDManager : public ICDListener, public TestEventTriggerHandler
#endif // CHIP_CONFIG_ENABLE_ICD_CIP

#if CONFIG_BUILD_FOR_HOST_UNIT_TEST
void SetTestFeatureMapValue(uint32_t featureMap) { mFeatureMap = featureMap; };
#if CHIP_CONFIG_PERSIST_SUBSCRIPTIONS && !CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION
bool GetIsBootUpResumeSubscriptionExecuted() { return mIsBootUpResumeSubscriptionExecuted; };
#endif // !CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION && CHIP_CONFIG_PERSIST_SUBSCRIPTIONS
Expand Down Expand Up @@ -381,11 +380,6 @@ class ICDManager : public ICDListener, public TestEventTriggerHandler
ICDCheckInBackOffStrategy * mICDCheckInBackOffStrategy = nullptr;
ObjectPool<ICDCheckInSender, (CHIP_CONFIG_ICD_CLIENTS_SUPPORTED_PER_FABRIC * CHIP_CONFIG_MAX_FABRICS)> mICDSenderPool;
#endif // CHIP_CONFIG_ENABLE_ICD_CIP

#if CONFIG_BUILD_FOR_HOST_UNIT_TEST
// feature map that can be changed at runtime for testing purposes
uint32_t mFeatureMap = 0;
#endif // CONFIG_BUILD_FOR_HOST_UNIT_TEST
};

} // namespace app
Expand Down
2 changes: 2 additions & 0 deletions src/app/icd/server/tests/ICDConfigurationDataTestAccess.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class ICDConfigurationDataTestAccess
return mData->SetModeDurations(activeModeDuration, idleModeDuration);
}

void SetFeatureMap(uint32_t featureMap) { mData->SetFeatureMap(featureMap); }
wqx6 marked this conversation as resolved.
Show resolved Hide resolved

private:
ICDConfigurationData * mData = nullptr;
};
Expand Down
23 changes: 13 additions & 10 deletions src/app/icd/server/tests/TestICDManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ TEST_F(TestICDManager, TestICDModeDurationsWith0ActiveModeDurationWithoutActiveS
ICDConfigurationDataTestAccess privateIcdConfigData(&icdConfigData);

// Set FeatureMap - Configures CIP, UAT and LITS to 1
mICDManager.SetTestFeatureMapValue(0x07);
privateIcdConfigData.SetFeatureMap(0x07);

// Set that there are no matching subscriptions
mSubInfoProvider.SetHasActiveSubscription(false);
Expand Down Expand Up @@ -342,7 +342,7 @@ TEST_F(TestICDManager, TestICDModeDurationsWith0ActiveModeDurationWithActiveSub)
ICDConfigurationDataTestAccess privateIcdConfigData(&icdConfigData);

// Set FeatureMap - Configures CIP, UAT and LITS to 1
mICDManager.SetTestFeatureMapValue(0x07);
privateIcdConfigData.SetFeatureMap(0x07);

// Set that there are not matching subscriptions
mSubInfoProvider.SetHasActiveSubscription(true);
Expand Down Expand Up @@ -480,10 +480,10 @@ TEST_F(TestICDManager, TestICDMRegisterUnregisterEvents)
{
typedef ICDListener::ICDManagementEvents ICDMEvent;
ICDNotifier notifier = ICDNotifier::GetInstance();
ICDConfigurationDataTestAccess privateIcdConfigData(&ICDConfigurationData::GetInstance());

// Set FeatureMap
// Configures CIP, UAT and LITS to 1
mICDManager.SetTestFeatureMapValue(0x07);
// Set FeatureMap - Configures CIP, UAT and LITS to 1
privateIcdConfigData.SetFeatureMap(0x07);

// Check ICDManager starts in SIT mode if no entries are present
EXPECT_EQ(ICDConfigurationData::GetInstance().GetICDMode(), ICDConfigurationData::ICDMode::SIT);
Expand Down Expand Up @@ -704,10 +704,10 @@ TEST_F(TestICDManager, TestICDMDSLS)
{
typedef ICDListener::ICDManagementEvents ICDMEvent;
ICDNotifier notifier = ICDNotifier::GetInstance();
ICDConfigurationDataTestAccess privateIcdConfigData(&ICDConfigurationData::GetInstance());

// Set FeatureMap
// Configures CIP, UAT, LITS and DSLS to 1
mICDManager.SetTestFeatureMapValue(0x0F);
// Set FeatureMap - Configures CIP, UAT, LITS and DSLS to 1
privateIcdConfigData.SetFeatureMap(0x0F);

// Check ICDManager starts in SIT mode if no entries are present
EXPECT_EQ(ICDConfigurationData::GetInstance().GetICDMode(), ICDConfigurationData::ICDMode::SIT);
Expand Down Expand Up @@ -988,9 +988,10 @@ TEST_F(TestICDManager, TestICDStateObserverOnEnterActiveMode)
TEST_F(TestICDManager, TestICDStateObserverOnICDModeChange)
{
typedef ICDListener::ICDManagementEvents ICDMEvent;
ICDConfigurationDataTestAccess privateIcdConfigData(&ICDConfigurationData::GetInstance());

// Set FeatureMap - Configures CIP, UAT and LITS to 1
mICDManager.SetTestFeatureMapValue(0x07);
privateIcdConfigData.SetFeatureMap(0x07);

// Since we don't have a registration, we stay in SIT mode. No changes
EXPECT_FALSE(mICDStateObserver.mOnICDModeChangeCalled);
Expand Down Expand Up @@ -1034,8 +1035,10 @@ TEST_F(TestICDManager, TestICDStateObserverOnICDModeChange)

TEST_F(TestICDManager, TestICDStateObserverOnICDModeChangeOnInit)
{
ICDConfigurationDataTestAccess privateIcdConfigData(&ICDConfigurationData::GetInstance());

// Set FeatureMap - Configures CIP, UAT and LITS to 1
mICDManager.SetTestFeatureMapValue(0x07);
privateIcdConfigData.SetFeatureMap(0x07);

ICDMonitoringTable table(testStorage, kTestFabricIndex1, kMaxTestClients, &(mKeystore));

Expand Down
4 changes: 3 additions & 1 deletion src/app/zap-templates/zcl/zcl-with-test-extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,9 @@
"RegisteredClients",
"ICDCounter",
"ClientsSupportedPerFabric",
"MaximumCheckInBackOff"
"MaximumCheckInBackOff",
"OperatingMode",
"FeatureMap"
],
"Occupancy Sensing": [
"HoldTimeLimits",
Expand Down
4 changes: 3 additions & 1 deletion src/app/zap-templates/zcl/zcl.json
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,9 @@
"RegisteredClients",
"ICDCounter",
"ClientsSupportedPerFabric",
"MaximumCheckInBackOff"
"MaximumCheckInBackOff",
"OperatingMode",
"FeatureMap"
],
"Occupancy Sensing": [
"HoldTimeLimits",
Expand Down
Loading
Loading