Skip to content

Commit

Permalink
[ICD] Expose ActiveModeDuration, ActiveModeThreshold, IdleModeDuratio…
Browse files Browse the repository at this point in the history
…n to application (project-chip#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 <[email protected]>
  • Loading branch information
yunhanw-google and restyled-commits authored Mar 27, 2024
1 parent fe889bd commit 60b6beb
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 11 deletions.
6 changes: 4 additions & 2 deletions examples/chip-tool/commands/pairing/PairingCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions examples/platform/linux/CommissionerMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/controller/AutoCommissioner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
47 changes: 43 additions & 4 deletions src/controller/CHIPDeviceController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<IcdManagement::Attributes::FeatureMap::TypeInfo>(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)
{
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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<IcdManagement::Attributes::IdleModeDuration::TypeInfo>(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<IcdManagement::Attributes::ActiveModeDuration::TypeInfo>(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<IcdManagement::Attributes::ActiveModeThreshold::TypeInfo>(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;
}

Expand Down Expand Up @@ -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++] =
Expand All @@ -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;
Expand Down
15 changes: 11 additions & 4 deletions src/controller/CommissioningDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 60b6beb

Please sign in to comment.