Skip to content

Commit

Permalink
Merge 8d0e4a6 into d825d51
Browse files Browse the repository at this point in the history
  • Loading branch information
jepenven-silabs authored Oct 6, 2023
2 parents d825d51 + 8d0e4a6 commit 4221825
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/app/icd/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ source_set("manager-srcs") {
":cluster-srcs",
":observer-srcs",
"${chip_root}/src/credentials:credentials",
"${chip_root}/src/protocols/secure_channel",
]
}

Expand Down
69 changes: 66 additions & 3 deletions src/app/icd/ICDManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <platform/ConnectivityManager.h>
#include <platform/LockTracker.h>
#include <platform/internal/CHIPDeviceLayerInternal.h>
#include <protocols/secure_channel/CheckinMessage.h>
#include <stdlib.h>

#ifndef ICD_ENFORCE_SIT_SLOW_POLL_LIMIT
Expand All @@ -40,6 +41,9 @@ using namespace chip::app;
using namespace chip::app::Clusters;
using namespace chip::app::Clusters::IcdManagement;

using namespace chip::Protocols;
using namespace chip::Protocols::SecureChannel;

void ICDManager::Init(PersistentStorageDelegate * storage, FabricTable * fabricTable, ICDStateObserver * stateObserver)
{
VerifyOrDie(storage != nullptr);
Expand Down Expand Up @@ -74,12 +78,65 @@ bool ICDManager::SupportsCheckInProtocol()
bool success = false;
uint32_t featureMap = 0;
// Can't use attribute accessors/Attributes::FeatureMap::Get in unit tests
#ifndef CONFIG_BUILD_FOR_HOST_UNIT_TEST
#if !CONFIG_BUILD_FOR_HOST_UNIT_TEST
success = (Attributes::FeatureMap::Get(kRootEndpointId, &featureMap) == EMBER_ZCL_STATUS_SUCCESS);
#endif
return success ? ((featureMap & to_underlying(Feature::kCheckInProtocolSupport)) != 0) : false;
}

void ICDManager::SendCheckInMsgs()
{
VerifyOrDie(mStorage != nullptr);
VerifyOrDie(mFabricTable != nullptr);
for (const auto & fabricInfo : *mFabricTable)
{
uint16_t supported_clients = IcdManagementServer::GetInstance().GetClientsSupportedPerFabric();
// TODO retrieve Check-in counter
// SecureChannel::CounterType counter = GetCheckInCounter();

ChipLogProgress(AppServer, "Max clients ICD per fabric %d", supported_clients);

IcdMonitoringTable table(*mStorage, fabricInfo.GetFabricIndex(), supported_clients /*Table entry limit*/);
if (!table.IsEmpty())
{
ChipLogProgress(AppServer, "Retrieving ICD Check-in Clients");
for (uint16_t i = 0; i < table.Limit(); i++)
{
IcdMonitoringEntry entry;
if (CHIP_NO_ERROR != table.Get(i, entry))
{
// No more entries in the table
break;
}

// TODO check for active subscription

// bool active = InteractionModelEngine::GetInstance()->IsSubscriptionActive(entry.fabricIndex, entry.checkInNodeID,
// entry.monitoredSubject); if (!active)
// {
// // TODO After PR 29260 is merged.
// ByteSpan appData;
// uint8_t b[CheckinMessage::sMinPayloadSize] = { 0 };
// MutableByteSpan output{ b };

// // Prepare Check-in payload
// if(CHIP_NO_ERROR != CheckinMessage::GenerateCheckinMessagePayload( entry.key,
// counter,
// appData,
// output))
// {
// ChipLogError(AppServer, "skipping node %lu", entry.checkInNodeID);
// continue;
// }

// // Todo send this somewhere so that the address can be resolved and
// // the payload can be send throught the network interface
// }
}
}
}
}

void ICDManager::UpdateIcdMode()
{
assertChipStackLockedByCurrentThread();
Expand Down Expand Up @@ -139,7 +196,7 @@ void ICDManager::UpdateOperationState(OperationalState state)
CHIP_ERROR err = DeviceLayer::ConnectivityMgr().SetPollingInterval(slowPollInterval);
if (err != CHIP_NO_ERROR)
{
ChipLogError(AppServer, "Failed to set Polling Interval: err %" CHIP_ERROR_FORMAT, err.Format());
ChipLogError(AppServer, "Failed to set Slow Polling Interval: err %" CHIP_ERROR_FORMAT, err.Format());
}
}
else if (state == OperationalState::ActiveMode)
Expand All @@ -160,7 +217,13 @@ void ICDManager::UpdateOperationState(OperationalState state)
CHIP_ERROR err = DeviceLayer::ConnectivityMgr().SetPollingInterval(GetFastPollingInterval());
if (err != CHIP_NO_ERROR)
{
ChipLogError(AppServer, "Failed to set Polling Interval: err %" CHIP_ERROR_FORMAT, err.Format());
ChipLogError(AppServer, "Failed to set Fast Polling Interval: err %" CHIP_ERROR_FORMAT, err.Format());
}

if (SupportsCheckInProtocol())
{
ChipLogProgress(AppServer, "Sending Check-in");
SendCheckInMsgs();
}

mStateObserver->OnEnterActiveMode();
Expand Down
1 change: 1 addition & 0 deletions src/app/icd/ICDManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class ICDManager
bool IsKeepActive() { return mKeepActiveFlags.HasAny(); }
ICDMode GetICDMode() { return mICDMode; }
OperationalState GetOperationalState() { return mOperationalState; }
void SendCheckInMsgs();

static System::Clock::Milliseconds32 GetSITPollingThreshold() { return kSITPollingThreshold; }
static System::Clock::Milliseconds32 GetSlowPollingInterval() { return kSlowPollingInterval; }
Expand Down
4 changes: 0 additions & 4 deletions src/messaging/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,4 @@ static_library("messaging") {
"${chip_root}/src/transport",
"${chip_root}/src/transport/raw",
]

if (chip_enable_icd_server) {
public_deps += [ "${chip_root}/src/app/icd:server-srcs" ]
}
}

0 comments on commit 4221825

Please sign in to comment.