Skip to content

Commit

Permalink
finish ICD Check-In cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mkardous-silabs committed Dec 11, 2023
1 parent d5d82d7 commit 9d4a4b1
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 22 deletions.
1 change: 1 addition & 0 deletions src/app/icd/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ source_set("sender") {
]

public_deps = [
":configuration-data",
":monitoring-table",
":notifier",
"${chip_root}/src/credentials:credentials",
Expand Down
26 changes: 16 additions & 10 deletions src/app/icd/ICDCheckInSender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,12 @@
* limitations under the License.
*/

#include "ICDCheckInSender.h"

#include "ICDNotifier.h"

#include <system/SystemPacketBuffer.h>

#include <protocols/secure_channel/CheckinMessage.h>

#include <app/icd/ICDCheckInSender.h>
#include <app/icd/ICDConfigurationData.h>
#include <app/icd/ICDNotifier.h>
#include <lib/dnssd/Resolver.h>
#include <protocols/secure_channel/CheckinMessage.h>
#include <system/SystemPacketBuffer.h>

namespace chip {
namespace app {
Expand Down Expand Up @@ -61,7 +58,13 @@ CHIP_ERROR ICDCheckInSender::SendCheckInMsg(const Transport::PeerAddress & addr)
VerifyOrReturnError(!buffer.IsNull(), CHIP_ERROR_NO_MEMORY);
MutableByteSpan output{ buffer->Start(), buffer->MaxDataLength() };

ReturnErrorOnFailure(CheckinMessage::GenerateCheckinMessagePayload(mAesKeyHandle, mICDCounter, ByteSpan(), output));
// Encoded ActiveModeThreshold in littleEndian for Check-In message application data
uint8_t activeModeThresholdBuffer[2] = {};
ByteSpan activeModeThresholdByteSpan(activeModeThresholdBuffer);
Encoding::LittleEndian::Put16((uint8_t *) activeModeThresholdByteSpan.data(), ICDConfigurationData::GetInstance().GetActiveModeThresholdMs());

ReturnErrorOnFailure(CheckinMessage::GenerateCheckinMessagePayload(mAes128KeyHandle, mHmac128KeyHandle, mICDCounter,
activeModeThresholdByteSpan, output));
buffer->SetDataLength(static_cast<uint16_t>(output.size()));

VerifyOrReturnError(mExchangeManager->GetSessionManager() != nullptr, CHIP_ERROR_INTERNAL);
Expand Down Expand Up @@ -89,9 +92,12 @@ CHIP_ERROR ICDCheckInSender::RequestResolve(ICDMonitoringEntry & entry, FabricTa

AddressResolve::NodeLookupRequest request(peerId);

memcpy(mAesKeyHandle.AsMutable<Crypto::Symmetric128BitsKeyByteArray>(),
memcpy(mAes128KeyHandle.AsMutable<Crypto::Symmetric128BitsKeyByteArray>(),
entry.aesKeyHandle.As<Crypto::Symmetric128BitsKeyByteArray>(), sizeof(Crypto::Symmetric128BitsKeyByteArray));

memcpy(mHmac128KeyHandle.AsMutable<Crypto::Symmetric128BitsKeyByteArray>(),
entry.hmacKeyHandle.As<Crypto::Symmetric128BitsKeyByteArray>(), sizeof(Crypto::Symmetric128BitsKeyByteArray));

CHIP_ERROR err = AddressResolve::Resolver::Instance().LookupNode(request, mAddressLookupHandle);

if (err == CHIP_NO_ERROR)
Expand Down
3 changes: 2 additions & 1 deletion src/app/icd/ICDCheckInSender.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ class ICDCheckInSender : public AddressResolve::NodeListener

Messaging::ExchangeManager * mExchangeManager = nullptr;

Crypto::Aes128KeyHandle mAesKeyHandle = Crypto::Aes128KeyHandle();
Crypto::Aes128KeyHandle mAes128KeyHandle = Crypto::Aes128KeyHandle();
Crypto::Hmac128KeyHandle mHmac128KeyHandle = Crypto::Hmac128KeyHandle();

uint32_t mICDCounter = 0;
};
Expand Down
4 changes: 2 additions & 2 deletions src/app/icd/ICDConfigurationData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ System::Clock::Milliseconds32 ICDConfigurationData::GetSlowPollingInterval()
// When in SIT mode, the slow poll interval SHOULDN'T be greater than the SIT mode polling threshold, per spec.
// This is important for ICD device configured for LIT operation but currently operating as a SIT
// due to a lack of client registration
if (mICDMode == ICDMode::SIT && GetSlowPollingInterval() > GetSITPollingThreshold())
if (mICDMode == ICDMode::SIT && mSlowPollingInterval > kSITPollingThreshold)
{
return GetSITPollingThreshold();
return kSITPollingThreshold;
}
#endif
return mSlowPollingInterval;
Expand Down
9 changes: 0 additions & 9 deletions src/app/icd/ICDManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,15 +275,6 @@ void ICDManager::UpdateOperationState(OperationalState state)

System::Clock::Milliseconds32 slowPollInterval = ICDConfigurationData::GetInstance().GetSlowPollingInterval();

#if ICD_ENFORCE_SIT_SLOW_POLL_LIMIT
// When in SIT mode, the slow poll interval SHOULDN'T be greater than the SIT mode polling threshold, per spec.
if (ICDConfigurationData::GetInstance().GetICDMode() == ICDConfigurationData::ICDMode::SIT &&
GetSlowPollingInterval() > GetSITPollingThreshold())
{
slowPollInterval = GetSITPollingThreshold();
}
#endif

// Going back to Idle, all Check-In messages are sent
mICDSenderPool.ReleaseAll();

Expand Down

0 comments on commit 9d4a4b1

Please sign in to comment.