Skip to content

Commit

Permalink
[lit icd] add sdk support for dsls (Dynamic SIT LIT support) (project…
Browse files Browse the repository at this point in the history
…-chip#35325)

* [lit icd] add sdk support for dsls (Dynamic SIT LIT support)

Signed-off-by: Doru Gucea <doru-cristian.gucea@nxp.com>

* [mcxw71_k32w1][lit icd] add platform support for dsls (Dynamic SIT LIT support)

Signed-off-by: Doru Gucea <doru-cristian.gucea@nxp.com>

* [lit icd] add DSLS Test Event trigger

Signed-off-by: Doru Gucea <doru-cristian.gucea@nxp.com>

* [linux app][lit icd] enable DSLS

Signed-off-by: Doru Gucea <doru-cristian.gucea@nxp.com>

---------

Signed-off-by: Doru Gucea <doru-cristian.gucea@nxp.com>
  • Loading branch information
doru91 authored Sep 17, 2024
1 parent add0bf1 commit 514e810
Show file tree
Hide file tree
Showing 19 changed files with 221 additions and 40 deletions.
1 change: 1 addition & 0 deletions .github/.wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ dpkg
dropdown
dryrun
DS
DSLS
duplicative
DUT
DUTS
Expand Down
1 change: 1 addition & 0 deletions examples/contact-sensor-app/nxp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ This is a list of ICD configuration gn args.
| nxp_active_mode_threshold_ms | 1000 (ms) | Active Mode Threshold value |
| nxp_icd_supported_clients_per_fabric | 2 | Registration slots per fabric |
| chip_enable_icd_lit | false | Enable LIT ICD support |
| chip_enable_icd_dsls | false | Enable LIT ICD DSLS support |
| chip_persist_subscriptions | true | Try once to re-establish subscriptions from the server side after reboot. May be disabled for LIT use case |
| chip_subscription_timeout_resumption | true | Same as above, but try to re-establish timeout out subscriptions |
| using `Fibonacci Backoff` for retries pacing. May be disabled for LIT use case |
Expand Down
15 changes: 8 additions & 7 deletions examples/contact-sensor-app/nxp/k32w1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@ operation by corrupting packages and OTA will not work.

The user actions are summarized below:

| button | action | state | output |
| ------ | ----------- | ---------------------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
| SW2 | short press | not commissioned | Enable BLE advertising |
| SW2 | short press | commissioned + device is LIT | Enable Active Mode |
| SW2 | long press | NA | Initiate a factory reset (can be cancelled by pressing the button again within the factory reset timeout limit - 6 seconds by default) |
| SW3 | short press | NA | Toggle attribute `StateValue` value |
| SW3 | long press | NA | Clean soft reset of the device (takes into account proper Matter shutdown procedure) |
| button | action | state | output |
| ------ | ------------ | -------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
| SW2 | short press | not commissioned | Enable BLE advertising |
| SW2 | short press | commissioned + device is LIT | Enable Active Mode |
| SW2 | double press | commissioned + device is LIT + supports DSLS | Enable / Disable SIT Mode |
| SW2 | long press | NA | Initiate a factory reset (can be cancelled by pressing the button again within the factory reset timeout limit - 6 seconds by default) |
| SW3 | short press | NA | Toggle attribute `StateValue` value |
| SW3 | long press | NA | Clean soft reset of the device (takes into account proper Matter shutdown procedure) |

## Building

Expand Down
1 change: 1 addition & 0 deletions examples/contact-sensor-app/nxp/k32w1/args.gni
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ chip_with_lwip = false

chip_enable_icd_server = true
chip_enable_icd_lit = false
chip_enable_icd_dsls = false
icd_enforce_sit_slow_poll_limit = true
chip_persist_subscriptions = true
chip_subscription_timeout_resumption = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2012,7 +2012,7 @@ endpoint 0 {
callback attribute acceptedCommandList;
callback attribute eventList;
callback attribute attributeList;
ram attribute featureMap default = 0x0007;
ram attribute featureMap default = 0x000F;
ram attribute clusterRevision default = 3;

handle command RegisterClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3818,7 +3818,7 @@
"storageOption": "RAM",
"singleton": 0,
"bounded": 0,
"defaultValue": "0x0007",
"defaultValue": "0x000F",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
Expand Down Expand Up @@ -4317,4 +4317,4 @@
"parentEndpointIdentifier": null
}
]
}
}
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 @@ -31,3 +31,4 @@ chip_enable_icd_server = true
chip_subscription_timeout_resumption = true
chip_icd_report_on_active_mode = true
chip_enable_icd_lit = true
chip_enable_icd_dsls = true
Original file line number Diff line number Diff line change
Expand Up @@ -2097,7 +2097,7 @@ endpoint 0 {
callback attribute acceptedCommandList;
callback attribute eventList;
callback attribute attributeList;
ram attribute featureMap default = 0x0007;
ram attribute featureMap default = 0x000F;
ram attribute clusterRevision default = 3;

handle command RegisterClient;
Expand Down
20 changes: 1 addition & 19 deletions examples/lit-icd-app/lit-icd-common/lit-icd-server-app.zap
Original file line number Diff line number Diff line change
Expand Up @@ -829,24 +829,6 @@
"isIncoming": 0,
"isEnabled": 1
}
],
"attributes": [
{
"name": "ClusterRevision",
"code": 65533,
"mfgCode": null,
"side": "client",
"type": "int16u",
"included": 1,
"storageOption": "RAM",
"singleton": 0,
"bounded": 0,
"defaultValue": "1",
"reportable": 1,
"minInterval": 0,
"maxInterval": 65344,
"reportableChange": 0
}
]
},
{
Expand Down Expand Up @@ -3558,7 +3540,7 @@
"storageOption": "RAM",
"singleton": 0,
"bounded": 0,
"defaultValue": "0x0007",
"defaultValue": "0x000F",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
Expand Down
36 changes: 36 additions & 0 deletions examples/platform/nxp/mcxw71_k32w1/button/ButtonManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ ButtonManager ButtonManager::sInstance;

TimerHandle_t resetTimer;

#if (CHIP_CONFIG_ENABLE_ICD_LIT && CHIP_CONFIG_ENABLE_ICD_DSLS)
static bool sitModeRequested;
#endif // CHIP_CONFIG_ENABLE_ICD_LIT && CHIP_CONFIG_ENABLE_ICD_DSLS

CHIP_ERROR ButtonManager::Init()
{
resetTimer = xTimerCreate("FnTmr", 1, false, (void *) this, [](TimerHandle_t xTimer) {
Expand All @@ -60,6 +64,10 @@ CHIP_ERROR ButtonManager::Init()
});
VerifyOrReturnError(resetTimer != NULL, APP_ERROR_CREATE_TIMER_FAILED);

#if (CHIP_CONFIG_ENABLE_ICD_LIT && CHIP_CONFIG_ENABLE_ICD_DSLS)
static bool sitModeRequested;
#endif // CHIP_CONFIG_ENABLE_ICD_LIT && CHIP_CONFIG_ENABLE_ICD_DSLS

return CHIP_NO_ERROR;
}

Expand All @@ -76,6 +84,13 @@ button_status_t ButtonManager::BleCallback(void * handle, button_callback_messag
case kBUTTON_EventLongPress:
event.Handler = ButtonManager::ResetActionEventHandler;
break;

#if (CHIP_CONFIG_ENABLE_ICD_LIT && CHIP_CONFIG_ENABLE_ICD_DSLS)
case kBUTTON_EventDoubleClick:
event.Handler = ButtonManager::DSLSActionEventHandler;
break;
#endif

default:
/* No action required */
break;
Expand Down Expand Up @@ -187,6 +202,27 @@ void ButtonManager::BleHandler(const AppEvent & event)
chip::NXP::App::GetAppTask().SwitchCommissioningStateHandler();
}

#if (CHIP_CONFIG_ENABLE_ICD_LIT && CHIP_CONFIG_ENABLE_ICD_DSLS)
void ButtonManager::DSLSActionEventHandler(const AppEvent & event)
{
if (chip::DeviceLayer::ConfigurationMgr().IsFullyProvisioned())
{
if (!sitModeRequested)
{
chip::DeviceLayer::PlatformMgr().ScheduleWork(
[](intptr_t arg) { chip::app::ICDNotifier::GetInstance().NotifySITModeRequestNotification(); }, 0);
sitModeRequested = true;
}
else
{
chip::DeviceLayer::PlatformMgr().ScheduleWork(
[](intptr_t arg) { chip::app::ICDNotifier::GetInstance().NotifySITModeRequestWithdrawal(); }, 0);
sitModeRequested = false;
}
}
}
#endif // CHIP_CONFIG_ENABLE_ICD_LIT && CHIP_CONFIG_ENABLE_ICD_DSLS

void ButtonManager::CancelTimer()
{
if (xTimerStop(resetTimer, 0) == pdFAIL)
Expand Down
7 changes: 7 additions & 0 deletions examples/platform/nxp/mcxw71_k32w1/button/ButtonManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ class ButtonManager
*/
static void ResetActionEventHandler(const AppEvent & event);

/**
* @brief This callback schedules a DSLS LIT action (Dynamic SIT LIT Support).
*
* It is used when the app requests SIT mode (check spec, "Runtime Operating Mode Switching")
*/
static void DSLSActionEventHandler(const AppEvent & event);

/**
* @brief This callback performs a factory reset.
*
Expand Down
3 changes: 3 additions & 0 deletions src/app/icd/icd.gni
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ declare_args() {

# Set to true to enforce SIT Slow Polling Max value to 15seconds (spec 9.16.1.5)
icd_enforce_sit_slow_poll_limit = false

# Set to true if device supports dynamic switching from SIT to LIT operating modes (DSLS)
chip_enable_icd_dsls = false
}

# Set the defaults for CIP and UAT features to be consistent with the LIT value.
Expand Down
1 change: 1 addition & 0 deletions src/app/icd/server/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ buildconfig_header("icd-server-buildconfig") {
"CHIP_CONFIG_ENABLE_ICD_LIT=${chip_enable_icd_lit}",
"CHIP_CONFIG_ENABLE_ICD_CIP=${chip_enable_icd_checkin}",
"CHIP_CONFIG_ENABLE_ICD_UAT=${chip_enable_icd_user_active_mode_trigger}",
"CHIP_CONFIG_ENABLE_ICD_DSLS=${chip_enable_icd_dsls}",
"ICD_REPORT_ON_ENTER_ACTIVE_MODE=${chip_icd_report_on_active_mode}",
"ICD_MAX_NOTIFICATION_SUBSCRIBERS=${icd_max_notification_subscribers}",
"ICD_ENFORCE_SIT_SLOW_POLL_LIMIT=${icd_enforce_sit_slow_poll_limit}",
Expand Down
55 changes: 46 additions & 9 deletions src/app/icd/server/ICDManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ enum class ICDTestEventTriggerEvent : uint64_t
kInvalidateHalfCounterValues = 0x0046'0000'00000003,
kInvalidateAllCounterValues = 0x0046'0000'00000004,
kForceMaximumCheckInBackOffState = 0x0046'0000'00000005,
kDSLSForceSitMode = 0x0046'0000'00000006,
kDSLSWithdrawSitMode = 0x0046'0000'00000007,
};
} // namespace

Expand Down Expand Up @@ -367,19 +369,28 @@ void ICDManager::UpdateICDMode()
// Device can only switch to the LIT operating mode if LIT support is present
if (SupportsFeature(Feature::kLongIdleTimeSupport))
{
VerifyOrDie(mStorage != nullptr);
VerifyOrDie(mFabricTable != nullptr);
// We can only get to LIT Mode, if at least one client is registered with the ICD device
for (const auto & fabricInfo : *mFabricTable)
#if CHIP_CONFIG_ENABLE_ICD_DSLS
// Ensure SIT mode is not requested
if (SupportsFeature(Feature::kDynamicSitLitSupport) && !mSITModeRequested)
{
// We only need 1 valid entry to ensure LIT compliance
ICDMonitoringTable table(*mStorage, fabricInfo.GetFabricIndex(), 1 /*Table entry limit*/, mSymmetricKeystore);
if (!table.IsEmpty())
#endif // CHIP_CONFIG_ENABLE_ICD_DSLS

VerifyOrDie(mStorage != nullptr);
VerifyOrDie(mFabricTable != nullptr);
// We can only get to LIT Mode, if at least one client is registered with the ICD device
for (const auto & fabricInfo : *mFabricTable)
{
tempMode = ICDConfigurationData::ICDMode::LIT;
break;
// We only need 1 valid entry to ensure LIT compliance
ICDMonitoringTable table(*mStorage, fabricInfo.GetFabricIndex(), 1 /*Table entry limit*/, mSymmetricKeystore);
if (!table.IsEmpty())
{
tempMode = ICDConfigurationData::ICDMode::LIT;
break;
}
}
#if CHIP_CONFIG_ENABLE_ICD_DSLS
}
#endif // CHIP_CONFIG_ENABLE_ICD_DSLS
}
#endif // CHIP_CONFIG_ENABLE_ICD_LIT

Expand Down Expand Up @@ -622,6 +633,24 @@ void ICDManager::OnActiveRequestWithdrawal(KeepActiveFlags request)
}
}

#if CHIP_CONFIG_ENABLE_ICD_DSLS
void ICDManager::OnSITModeRequest()
{
mSITModeRequested = true;
this->UpdateICDMode();
// Update the poll interval also to comply with SIT requirements
UpdateOperationState(OperationalState::ActiveMode);
}

void ICDManager::OnSITModeRequestWithdrawal()
{
mSITModeRequested = false;
this->UpdateICDMode();
// Update the poll interval also to comply with LIT requirements
UpdateOperationState(OperationalState::ActiveMode);
}
#endif // CHIP_CONFIG_ENABLE_ICD_DSLS

void ICDManager::OnNetworkActivity()
{
this->UpdateOperationState(OperationalState::ActiveMode);
Expand Down Expand Up @@ -685,6 +714,14 @@ CHIP_ERROR ICDManager::HandleEventTrigger(uint64_t eventTrigger)
err = mICDCheckInBackOffStrategy->ForceMaximumCheckInBackoff();
break;
#endif // CHIP_CONFIG_ENABLE_ICD_CIP
#if CHIP_CONFIG_ENABLE_ICD_DSLS
case ICDTestEventTriggerEvent::kDSLSForceSitMode:
OnSITModeRequest();
break;
case ICDTestEventTriggerEvent::kDSLSWithdrawSitMode:
OnSITModeRequestWithdrawal();
break;
#endif // CHIP_CONFIG_ENABLE_ICD_DSLS
default:
err = CHIP_ERROR_INVALID_ARGUMENT;
break;
Expand Down
10 changes: 10 additions & 0 deletions src/app/icd/server/ICDManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,12 @@ class ICDManager : public ICDListener, public TestEventTriggerHandler
void OnNetworkActivity() override;
void OnKeepActiveRequest(KeepActiveFlags request) override;
void OnActiveRequestWithdrawal(KeepActiveFlags request) override;

#if CHIP_CONFIG_ENABLE_ICD_DSLS
void OnSITModeRequest() override;
void OnSITModeRequestWithdrawal() override;
#endif

void OnICDManagementServerEvent(ICDManagementEvents event) override;
void OnSubscriptionReport() override;

Expand Down Expand Up @@ -356,6 +362,10 @@ class ICDManager : public ICDListener, public TestEventTriggerHandler
ObjectPool<ObserverPointer, CHIP_CONFIG_ICD_OBSERVERS_POOL_SIZE> mStateObserverPool;
uint8_t mOpenExchangeContextCount = 0;

#if CHIP_CONFIG_ENABLE_ICD_DSLS
bool mSITModeRequested = false;
#endif

#if CHIP_CONFIG_ENABLE_ICD_CIP
uint8_t mCheckInRequestCount = 0;

Expand Down
24 changes: 24 additions & 0 deletions src/app/icd/server/ICDNotifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,30 @@ void ICDNotifier::NotifyActiveRequestWithdrawal(ICDListener::KeepActiveFlags req
}
}

#if CHIP_CONFIG_ENABLE_ICD_DSLS
void ICDNotifier::NotifySITModeRequestNotification()
{
for (auto subscriber : mSubscribers)
{
if (subscriber != nullptr)
{
subscriber->OnSITModeRequest();
}
}
}

void ICDNotifier::NotifySITModeRequestWithdrawal()
{
for (auto subscriber : mSubscribers)
{
if (subscriber != nullptr)
{
subscriber->OnSITModeRequestWithdrawal();
}
}
}
#endif // CHIP_CONFIG_ENABLE_ICD_DSLS

void ICDNotifier::NotifyICDManagementEvent(ICDListener::ICDManagementEvents event)
{
for (auto subscriber : mSubscribers)
Expand Down
18 changes: 18 additions & 0 deletions src/app/icd/server/ICDNotifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,20 @@ class ICDListener
*/
virtual void OnKeepActiveRequest(KeepActiveFlags request) = 0;

#if CHIP_CONFIG_ENABLE_ICD_DSLS
/**
* @brief This function is called for all subscribers of the ICDNotifier when it calls NotifySITModeRequestNotification.
* It informs the subscriber that the ICD must be kept in SIT mode.
*/
virtual void OnSITModeRequest() = 0;

/**
* @brief This function is called for all subscribers of the ICDNotifier when it calls NotifySITModeRequestWithdrawal.
* It informs the subscriber that a previous request no longer needs ICD to be kept in SIT mode.
*/
virtual void OnSITModeRequestWithdrawal() = 0;
#endif // CHIP_CONFIG_ENABLE_ICD_DSLS

/**
* @brief This function is called for all subscribers of the ICDNotifier when it calls NotifyActiveRequestWithdrawal.
* It informs the subscriber that a previous request no longer needs ICD to maintain its Active Mode.
Expand Down Expand Up @@ -109,6 +123,10 @@ class ICDNotifier
void NotifyNetworkActivityNotification();
void NotifyActiveRequestNotification(ICDListener::KeepActiveFlags request);
void NotifyActiveRequestWithdrawal(ICDListener::KeepActiveFlags request);
#if CHIP_CONFIG_ENABLE_ICD_DSLS
void NotifySITModeRequestNotification();
void NotifySITModeRequestWithdrawal();
#endif // CHIP_CONFIG_ENABLE_ICD_DSLS
void NotifyICDManagementEvent(ICDListener::ICDManagementEvents event);
void NotifySubscriptionReport();

Expand Down
Loading

0 comments on commit 514e810

Please sign in to comment.