Skip to content

Commit

Permalink
icd management: make the feature map and operating mode managed by AAI (
Browse files Browse the repository at this point in the history
#37062)

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

* Restyled by clang-format

* review changes

* Restyled by clang-format

* change the macro for operating mode

* review change

* run zap regen

* Update TestICDManager.cpp

---------

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
wqx6 and restyled-commits authored Jan 17, 2025
1 parent f3e4e39 commit 594ffe2
Show file tree
Hide file tree
Showing 24 changed files with 110 additions and 164 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2235,12 +2235,12 @@ endpoint 0 {
callback attribute clientsSupportedPerFabric;
ram attribute userActiveModeTriggerHint default = 0x100;
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 @@ -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 @@ -3173,7 +3173,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
20 changes: 20 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,19 @@ 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
CHIP_ERROR ReadOperatingMode(EndpointId endpoint, AttributeValueEncoder & encoder)
{
return mICDConfigurationData->GetICDMode() == ICDConfigurationData::ICDMode::SIT
? encoder.Encode(IcdManagement::OperatingModeEnum::kSit)
: encoder.Encode(IcdManagement::OperatingModeEnum::kLit);
}
#endif // CHIP_CONFIG_ENABLE_ICD_LIT

#if CHIP_CONFIG_ENABLE_ICD_CIP
CHIP_ERROR ReadRegisteredClients(EndpointId endpoint, AttributeValueEncoder & encoder);
Expand Down Expand Up @@ -94,6 +108,12 @@ 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);
#endif // CHIP_CONFIG_ENABLE_ICD_LIT
#if CHIP_CONFIG_ENABLE_ICD_CIP
case IcdManagement::Attributes::RegisteredClients::Id:
return ReadRegisteredClients(aPath.mEndpointId, aEncoder);
Expand Down
4 changes: 4 additions & 0 deletions src/app/icd/server/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ buildconfig_header("icd-server-buildconfig") {
assert(chip_enable_icd_checkin && chip_enable_icd_user_active_mode_trigger)
}

if (chip_enable_icd_dsls) {
assert(chip_enable_icd_lit)
}

defines = [
"CHIP_CONFIG_ENABLE_ICD_SERVER=${chip_enable_icd_server}",
"CHIP_CONFIG_ENABLE_ICD_LIT=${chip_enable_icd_lit}",
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_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_LIT
mFeatureMap.Set(app::Clusters::IcdManagement::Feature::kLongIdleTimeSupport);
#if CHIP_CONFIG_ENABLE_ICD_DSLS
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(BitFlags<app::Clusters::IcdManagement::Feature> featureMap) { mFeatureMap = 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
4 changes: 4 additions & 0 deletions src/app/icd/server/tests/ICDConfigurationDataTestAccess.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@

#pragma once

#include <app-common/zap-generated/cluster-enums.h>
#include <app/icd/server/ICDConfigurationData.h>
#include <lib/support/BitFlags.h>

namespace chip {
namespace Test {
Expand All @@ -39,6 +41,8 @@ class ICDConfigurationDataTestAccess
return mData->SetModeDurations(activeModeDuration, idleModeDuration);
}

void SetFeatureMap(BitFlags<app::Clusters::IcdManagement::Feature> featureMap) { mData->SetFeatureMap(featureMap); }

private:
ICDConfigurationData * mData = nullptr;
};
Expand Down
Loading

0 comments on commit 594ffe2

Please sign in to comment.