From 60b6bebb9ff57edebb494640dc1e61f48310d485 Mon Sep 17 00:00:00 2001 From: yunhanw-google Date: Wed, 27 Mar 2024 10:40:37 -0700 Subject: [PATCH] [ICD] Expose ActiveModeDuration, ActiveModeThreshold, IdleModeDuration to application (#32494) * Expose ICD Active/Idle paramter to application * address comment * Restyled by clang-format * change * address comments * Restyled by clang-format * address comments --------- Co-authored-by: Restyled.io --- .../commands/pairing/PairingCommand.cpp | 6 ++- examples/platform/linux/CommissionerMain.cpp | 3 ++ src/controller/AutoCommissioner.cpp | 2 +- src/controller/CHIPDeviceController.cpp | 47 +++++++++++++++++-- src/controller/CommissioningDelegate.h | 15 ++++-- 5 files changed, 62 insertions(+), 11 deletions(-) diff --git a/examples/chip-tool/commands/pairing/PairingCommand.cpp b/examples/chip-tool/commands/pairing/PairingCommand.cpp index ed80bc007df796..f872692dc45235 100644 --- a/examples/chip-tool/commands/pairing/PairingCommand.cpp +++ b/examples/chip-tool/commands/pairing/PairingCommand.cpp @@ -430,6 +430,8 @@ void PairingCommand::OnReadCommissioningInfo(const Controller::ReadCommissioning ChipLogProgress(AppServer, "OnReadCommissioningInfo - LIT UserActiveModeTriggerInstruction=%s", userActiveModeTriggerInstruction.c_str()); } + ChipLogProgress(AppServer, "OnReadCommissioningInfo ICD - IdleModeDuration=%u activeModeDuration=%u activeModeThreshold=%u", + info.icd.idleModeDuration, info.icd.activeModeDuration, info.icd.activeModeThreshold); } void PairingCommand::OnICDRegistrationComplete(NodeId nodeId, uint32_t icdCounter) @@ -464,9 +466,9 @@ void PairingCommand::OnICDRegistrationComplete(NodeId nodeId, uint32_t icdCounte ChipLogProgress(chipTool, "Saved ICD Symmetric key for " ChipLogFormatX64, ChipLogValueX64(nodeId)); ChipLogProgress(chipTool, "ICD Registration Complete for device " ChipLogFormatX64 " / Check-In NodeID: " ChipLogFormatX64 - " / Monitored Subject: " ChipLogFormatX64 " / Symmetric Key: %s", + " / Monitored Subject: " ChipLogFormatX64 " / Symmetric Key: %s / ICDCounter %u", ChipLogValueX64(nodeId), ChipLogValueX64(mICDCheckInNodeId.Value()), - ChipLogValueX64(mICDMonitoredSubject.Value()), icdSymmetricKeyHex); + ChipLogValueX64(mICDMonitoredSubject.Value()), icdSymmetricKeyHex, icdCounter); } void PairingCommand::OnICDStayActiveComplete(NodeId deviceId, uint32_t promisedActiveDuration) diff --git a/examples/platform/linux/CommissionerMain.cpp b/examples/platform/linux/CommissionerMain.cpp index beaf915cf559c3..465dfa591b0235 100644 --- a/examples/platform/linux/CommissionerMain.cpp +++ b/examples/platform/linux/CommissionerMain.cpp @@ -367,6 +367,9 @@ void PairingCommand::OnReadCommissioningInfo(const Controller::ReadCommissioning ChipLogProgress(AppServer, "OnReadCommissioningInfo - LIT UserActiveModeTriggerInstruction=%s", userActiveModeTriggerInstruction.c_str()); } + + ChipLogProgress(AppServer, "OnReadCommissioningInfo ICD - IdleModeDuration=%u activeModeDuration=%u activeModeThreshold=%u", + info.icd.idleModeDuration, info.icd.activeModeDuration, info.icd.activeModeThreshold); } void PairingCommand::OnFabricCheck(NodeId matchingNodeId) diff --git a/src/controller/AutoCommissioner.cpp b/src/controller/AutoCommissioner.cpp index 42b39a10c7ab48..add9f74dd73f34 100644 --- a/src/controller/AutoCommissioner.cpp +++ b/src/controller/AutoCommissioner.cpp @@ -743,7 +743,7 @@ CHIP_ERROR AutoCommissioner::CommissioningStepFinished(CHIP_ERROR err, Commissio if (mParams.GetCheckForMatchingFabric()) { - chip::NodeId nodeId = mDeviceCommissioningInfo.remoteNodeId; + NodeId nodeId = mDeviceCommissioningInfo.remoteNodeId; if (nodeId != kUndefinedNodeId) { mParams.SetRemoteNodeId(nodeId); diff --git a/src/controller/CHIPDeviceController.cpp b/src/controller/CHIPDeviceController.cpp index af0a66ea834da3..7726366becc67c 100644 --- a/src/controller/CHIPDeviceController.cpp +++ b/src/controller/CHIPDeviceController.cpp @@ -2319,13 +2319,14 @@ CHIP_ERROR DeviceCommissioner::ParseICDInfo(ReadCommissioningInfo & info) CHIP_ERROR err; IcdManagement::Attributes::FeatureMap::TypeInfo::DecodableType featureMap; bool hasUserActiveModeTrigger = false; - + bool isICD = false; err = mAttributeCache->Get(kRootEndpointId, featureMap); if (err == CHIP_NO_ERROR) { info.icd.isLIT = !!(featureMap & to_underlying(IcdManagement::Feature::kLongIdleTimeSupport)); info.icd.checkInProtocolSupport = !!(featureMap & to_underlying(IcdManagement::Feature::kCheckInProtocolSupport)); hasUserActiveModeTrigger = !!(featureMap & to_underlying(IcdManagement::Feature::kUserActiveModeTrigger)); + isICD = true; } else if (err == CHIP_ERROR_KEY_NOT_FOUND) { @@ -2355,6 +2356,7 @@ CHIP_ERROR DeviceCommissioner::ParseICDInfo(ReadCommissioningInfo & info) info.icd.userActiveModeTriggerHint.ClearAll(); info.icd.userActiveModeTriggerInstruction = CharSpan(); + if (hasUserActiveModeTrigger) { // Intentionally ignore errors since they are not mandatory. @@ -2390,6 +2392,37 @@ CHIP_ERROR DeviceCommissioner::ParseICDInfo(ReadCommissioningInfo & info) } } + if (!isICD) + { + info.icd.idleModeDuration = 0; + info.icd.activeModeDuration = 0; + info.icd.activeModeThreshold = 0; + return CHIP_NO_ERROR; + } + + err = mAttributeCache->Get(kRootEndpointId, info.icd.idleModeDuration); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Controller, "IcdManagement.IdleModeDuration expected, but failed to read: %" CHIP_ERROR_FORMAT, err.Format()); + return err; + } + err = + mAttributeCache->Get(kRootEndpointId, info.icd.activeModeDuration); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Controller, "IcdManagement.ActiveModeDuration expected, but failed to read: %" CHIP_ERROR_FORMAT, + err.Format()); + return err; + } + + err = mAttributeCache->Get(kRootEndpointId, + info.icd.activeModeThreshold); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Controller, "IcdManagement.ActiveModeThreshold expected, but failed to read: %" CHIP_ERROR_FORMAT, + err.Format()); + } + return err; } @@ -2680,8 +2713,8 @@ void DeviceCommissioner::PerformCommissioningStep(DeviceProxy * proxy, Commissio // NOTE: this array cannot have more than 9 entries, since the spec mandates that server only needs to support 9 // See R1.1, 2.11.2 Interaction Model Limits - // Currently, we have at most 5 attributes to read in this stage. - app::AttributePathParams readPaths[5]; + // Currently, we have at most 8 attributes to read in this stage. + app::AttributePathParams readPaths[8]; // Mandatory attribute readPaths[numberOfAttributes++] = @@ -2700,12 +2733,18 @@ void DeviceCommissioner::PerformCommissioningStep(DeviceProxy * proxy, Commissio readPaths[numberOfAttributes++] = app::AttributePathParams(endpoint, IcdManagement::Id, IcdManagement::Attributes::FeatureMap::Id); } + // Always read the active mode trigger hint attributes to notify users about it. readPaths[numberOfAttributes++] = app::AttributePathParams(endpoint, IcdManagement::Id, IcdManagement::Attributes::UserActiveModeTriggerHint::Id); readPaths[numberOfAttributes++] = app::AttributePathParams(endpoint, IcdManagement::Id, IcdManagement::Attributes::UserActiveModeTriggerInstruction::Id); - + readPaths[numberOfAttributes++] = + app::AttributePathParams(endpoint, IcdManagement::Id, IcdManagement::Attributes::IdleModeDuration::Id); + readPaths[numberOfAttributes++] = + app::AttributePathParams(endpoint, IcdManagement::Id, IcdManagement::Attributes::ActiveModeDuration::Id); + readPaths[numberOfAttributes++] = + app::AttributePathParams(endpoint, IcdManagement::Id, IcdManagement::Attributes::ActiveModeThreshold::Id); SendCommissioningReadRequest(proxy, timeout, readPaths, numberOfAttributes); } break; diff --git a/src/controller/CommissioningDelegate.h b/src/controller/CommissioningDelegate.h index 4b1040fcd79690..fbcd72270b8589 100644 --- a/src/controller/CommissioningDelegate.h +++ b/src/controller/CommissioningDelegate.h @@ -78,7 +78,7 @@ enum CommissioningStage : uint8_t kNeedsNetworkCreds, }; -enum ICDRegistrationStrategy : uint8_t +enum class ICDRegistrationStrategy : uint8_t { kIgnore, ///< Do not check whether the device is an ICD during commissioning kBeforeComplete, ///< Do commissioner self-registration or external controller registration, @@ -699,11 +699,18 @@ struct GeneralCommissioningInfo struct ICDManagementClusterInfo { // Whether the ICD is capable of functioning as a LIT device. If false, the ICD can only be a SIT device. - bool isLIT; + bool isLIT = false; // Whether the ICD supports the check-in protocol. LIT devices have to support it, but SIT devices // might or might not. - bool checkInProtocolSupport; - + bool checkInProtocolSupport = false; + // Indicate the maximum interval in seconds the server can stay in idle mode. + uint32_t idleModeDuration = 0; + // Indicate the minimum interval in milliseconds the server typically will stay in active mode after initial transition out of + // idle mode. + uint32_t activeModeDuration = 0; + // Indicate the minimum amount of time in milliseconds the server typically will stay active after network activity when in + // active mode. + uint16_t activeModeThreshold = 0; // userActiveModeTriggerHint indicates which user action(s) will trigger the ICD to switch to Active mode. // For a LIT: The device is required to provide a value for the bitmap. // For a SIT: The device may not provide a value. In that case, none of the bits will be set.