Skip to content

Commit

Permalink
ICDHandler initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
thivya-amazon committed Dec 3, 2023
1 parent cc3fb6c commit 5682c14
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/app/icd/client/ICDHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@

#include <protocols/secure_channel/Constants.h>

#define PWRTWO(exp) (1 << (exp))

namespace chip {
namespace app {

Expand Down Expand Up @@ -78,17 +80,26 @@ CHIP_ERROR CheckInMessageHandler::OnMessageReceived(Messaging::ExchangeContext *

ByteSpan payloadByteSpan{ payload->Start(), payload->DataLength() };
auto * iterator = mICDClientStorage->IterateICDClientInfo();
CHIP_ERROR err;
CHIP_ERROR err = CHIP_NO_ERROR;
uint32_t counter;
ICDClientInfo clientInfo;
while (iterator->Next(clientInfo))
{
err = mICDClientStorage->ProcessCheckInPayload(payloadByteSpan, clientInfo, &counter);
if (err == CHIP_NO_ERROR)
{
// TODO-1 : Check if the counter received is in range. If yes, proceed to TODO-2
// TODO-2 : Call the callback registered by the application to inform about the incoming checkin message
return err;
auto checkInCounter = (counter - clientInfo.start_icd_counter) % (PWRTWO(32));
// TAk - If this condition fails, do we notify the application through callback with an error?
if (checkInCounter > clientInfo.offset)
{
clientInfo.offset = counter - clientInfo.start_icd_counter;
if (checkInCounter > PWRTWO(31))
{
// TODO - refresh key
}
// TODO - Notify the application through callback
return err;
}
}
}
return err;
Expand Down

0 comments on commit 5682c14

Please sign in to comment.