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

[SL-ONLY] Add custom rules to selective listening #174

Merged
merged 7 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 3 additions & 0 deletions examples/platform/silabs/MatterConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,9 @@ CHIP_ERROR SilabsMatterConfig::InitMatter(const char * appName)
// Register ReadHandler::ApplicationCallback
app::InteractionModelEngine::GetInstance()->RegisterReadHandlerAppCallback(
&app::Silabs::ApplicationSleepManager::GetInstance());

// Register ICDStateObserver
chip::Server::GetInstance().GetICDManager().RegisterObserver(&app::Silabs::ApplicationSleepManager::GetInstance());
#endif // SL_MATTER_ENABLE_APP_SLEEP_MANAGER

// Init Matter Server and Start Event Loop
Expand Down
89 changes: 84 additions & 5 deletions examples/platform/silabs/wifi/icd/ApplicationSleepManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,23 @@
******************************************************************************/

#include "ApplicationSleepManager.h"
#include <lib/core/DataModelTypes.h>
#include <lib/support/logging/CHIPLogging.h>

namespace chip {
namespace app {
namespace Silabs {

namespace {

enum class SpecialCaseVendorID : uint16_t
{
kAppleHome = 4937,
mkardous-silabs marked this conversation as resolved.
Show resolved Hide resolved
kAppleKeychain = 4996,
};

} // namespace

ApplicationSleepManager ApplicationSleepManager::mInstance;

CHIP_ERROR ApplicationSleepManager::Init()
Expand Down Expand Up @@ -92,24 +103,92 @@ bool ApplicationSleepManager::CanGoToLIBasedSleep()
ChipLogProgress(AppServer, "Commissioning Window is Open - Cannot go to LI based sleep");
canGoToLIBasedSleep = false;
}
else if (mIsInActiveMode)
{
ChipLogProgress(AppServer, "Device is in active mode - Cannot go to LI based sleep");
canGoToLIBasedSleep = false;
}
else
{
for (auto it = mFabricTable->begin(); it != mFabricTable->end(); ++it)
{
if (!mSubscriptionsInfoProvider->FabricHasAtLeastOneActiveSubscription(it->GetFabricIndex()))
{
ChipLogProgress(AppServer, "Fabric index %u has no active subscriptions - Cannot go to LI based sleep",
it->GetFabricIndex());
canGoToLIBasedSleep = false;
break;
ChipLogProgress(AppServer, "Fabric index %u has no active subscriptions", it->GetFabricIndex());
canGoToLIBasedSleep = ProcessSpecialVendorIDCase(it->GetVendorId());

if (canGoToLIBasedSleep)
{
ChipLogProgress(AppServer,
"Fabric index %u with vendor ID : %d has an edge case that allows for LI based sleep",
it->GetFabricIndex(), it->GetVendorId());
}
else
{
// Fabric doesn't meet the requirements to allow us to go to LI based sleep
break;
}
}
ChipLogProgress(AppServer, "Fabric index %u has an active subscriptions!", it->GetFabricIndex());
}
}

return canGoToLIBasedSleep;
}

bool ApplicationSleepManager::ProcessSpecialVendorIDCase(chip::VendorId vendorId)
{
bool hasValidException = false;
switch (to_underlying(vendorId))
{
case to_underlying(SpecialCaseVendorID::kAppleKeychain):
hasValidException = ProcessKeychainEdgeCase();
break;

default:
break;
}
mkardous-silabs marked this conversation as resolved.
Show resolved Hide resolved

return hasValidException;
}

bool ApplicationSleepManager::ProcessKeychainEdgeCase()
{
bool hasValidException = false;

for (auto it = mFabricTable->begin(); it != mFabricTable->end(); ++it)
{
if (to_underlying(it->GetVendorId()) == to_underlying(SpecialCaseVendorID::kAppleHome) &&
mkardous-silabs marked this conversation as resolved.
Show resolved Hide resolved
mSubscriptionsInfoProvider->FabricHasAtLeastOneActiveSubscription(it->GetFabricIndex()))
{
hasValidException = true;
mkardous-silabs marked this conversation as resolved.
Show resolved Hide resolved
}
}

return hasValidException;
}

void ApplicationSleepManager::OnEnterActiveMode()
{
mIsInActiveMode = true;
mWifiSleepManager->VerifyAndTransitionToLowPowerMode();
}

void ApplicationSleepManager::OnEnterIdleMode()
{
mIsInActiveMode = false;
mWifiSleepManager->VerifyAndTransitionToLowPowerMode();
}

void ApplicationSleepManager::OnTransitionToIdle()
{
// Nothing to do
}

void ApplicationSleepManager::OnICDModeChange()
{
// Nothing to do
}

} // namespace Silabs
} // namespace app
} // namespace chip
38 changes: 37 additions & 1 deletion examples/platform/silabs/wifi/icd/ApplicationSleepManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include <app/ReadHandler.h>
#include <app/SubscriptionsInfoProvider.h>
#include <app/icd/server/ICDStateObserver.h>
#include <app/server/CommissioningWindowManager.h>
#include <credentials/FabricTable.h>
#include <platform/silabs/wifi/icd/WifiSleepManager.h>
Expand All @@ -29,7 +30,8 @@ namespace Silabs {

class ApplicationSleepManager : public chip::app::ReadHandler::ApplicationCallback,
public chip::DeviceLayer::Silabs::WifiSleepManager::ApplicationCallback,
public chip::FabricTable::Delegate
public chip::FabricTable::Delegate,
public chip::app::ICDStateObserver
{
public:
static ApplicationSleepManager & GetInstance() { return mInstance; }
Expand Down Expand Up @@ -131,20 +133,54 @@ class ApplicationSleepManager : public chip::app::ReadHandler::ApplicationCallba

void OnFabricUpdated(const chip::FabricTable & fabricTable, chip::FabricIndex fabricIndex) override {}

// ICDStateObserver implementation
void OnEnterActiveMode() override;
void OnEnterIdleMode() override;
void OnTransitionToIdle() override;
void OnICDModeChange() override;

private:
ApplicationSleepManager() = default;
~ApplicationSleepManager() = default;

ApplicationSleepManager(const ApplicationSleepManager &) = delete;
ApplicationSleepManager & operator=(const ApplicationSleepManager &) = delete;

/**
* @brief Processes special cases based on the vendor ID.
*
* This method checks if the given vendor ID has any special cases that allow
* the device to go to LI based sleep when the fabric associated to the vendor ID does not have an active subscription.
*
* @param vendorId The vendor ID to check for special cases.
* @return true if the vendor ID has a special case that allows LI based sleep, false otherwise.
*/
bool ProcessSpecialVendorIDCase(chip::VendorId vendorId);

/**
* @brief Processes the Apple Keychain edge case.
*
* Apple, when commissioning, adds two fabric to the device. One for Apple Home and one for the Appley Keychain.
* Apple Home is the active fabric which is used to communication with the device. The associated fabric also has the active
* subcription. Applye Keychain fabric acts as a safety and doesn't have an active fabric with the device. As such, we need an
* alternate method to check if the device can go to LI based sleep.
*
* This method checks if there is any fabric with the Apple Home vendor ID that
* has at least one active subscription. If such a fabric is found, it allows
* the device to go to LI based sleep.
*
* @return true if the Apple Keychain edge case allows low-power mode, false otherwise.
*/
bool ProcessKeychainEdgeCase();
mkardous-silabs marked this conversation as resolved.
Show resolved Hide resolved

static ApplicationSleepManager mInstance;
chip::FabricTable * mFabricTable = nullptr;
chip::app::SubscriptionsInfoProvider * mSubscriptionsInfoProvider = nullptr;
chip::CommissioningWindowManager * mCommissioningWindowManager = nullptr;
chip::DeviceLayer::Silabs::WifiSleepManager * mWifiSleepManager = nullptr;

bool mIsCommissionningWindowOpen = false;
bool mIsInActiveMode = false;
};

} // namespace Silabs
Expand Down
5 changes: 5 additions & 0 deletions src/platform/silabs/CHIPPlatformConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@
#define CHIP_CONFIG_ICD_CLIENTS_SUPPORTED_PER_FABRIC SL_ICD_SUPPORTED_CLIENTS_PER_FABRIC
#endif // CHIP_CONFIG_ICD_CLIENTS_SUPPORTED_PER_FABRIC

#ifndef CHIP_CONFIG_ICD_OBSERVERS_POOL_SIZE
#define CHIP_CONFIG_ICD_OBSERVERS_POOL_SIZE 3
mkardous-silabs marked this conversation as resolved.
Show resolved Hide resolved
#endif // CHIP_CONFIG_ICD_OBSERVERS_POOL_SIZE
static_assert(CHIP_CONFIG_ICD_OBSERVERS_POOL_SIZE >= 3, "ICD Observers pool size must be at least 3");
mkardous-silabs marked this conversation as resolved.
Show resolved Hide resolved

#endif // defined(CHIP_CONFIG_ENABLE_ICD_SERVER) && CHIP_CONFIG_ENABLE_ICD_SERVER

/**
Expand Down
Loading