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

Icd handler #30731

Merged
merged 99 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
99 commits
Select commit Hold shift + click to select a range
e080807
ICDHandler initialization
thivya-amazon Nov 29, 2023
e403ef3
ICDHandler initialization
thivya-amazon Nov 29, 2023
2aeecb5
Restyled by gn
restyled-commits Nov 30, 2023
20b833b
Update src/app/icd/ICDHandler.cpp
thivya-amazon Nov 30, 2023
1c4e530
ICDHandler initialization
thivya-amazon Nov 30, 2023
b520fa9
ICDHandler initialization
thivya-amazon Dec 3, 2023
fb15b18
ICDHandler initialization
thivya-amazon Dec 3, 2023
a8421b8
Restyled by gn
restyled-commits Dec 3, 2023
482d7ff
ICDHandler initialization
thivya-amazon Dec 3, 2023
48aecdb
ICDHandler initialization
thivya-amazon Dec 3, 2023
0f0dbac
Restyled by gn
restyled-commits Dec 3, 2023
bec8bf9
ICDHandler initialization
thivya-amazon Dec 3, 2023
955eaf1
Restyled by gn
restyled-commits Dec 3, 2023
72fec59
ICDHandler initialization
thivya-amazon Dec 3, 2023
03b0e41
ICDHandler initialization
thivya-amazon Dec 3, 2023
5a8209d
ICDHandler initialization
thivya-amazon Dec 3, 2023
bbe4561
ICDHandler initialization
thivya-amazon Dec 3, 2023
8fed72c
ICDHandler initialization
thivya-amazon Dec 3, 2023
f2152fe
Moved counter validation to DefaultICDClientStorage.
thivya-amazon Dec 3, 2023
2af67df
Renamed ICDHandler to CheckInHandler
thivya-amazon Dec 5, 2023
c1fbf04
Included CheckInDelegate in BUILD.gn
thivya-amazon Dec 5, 2023
d2559d7
Restyled by gn
restyled-commits Dec 5, 2023
0ce35c2
Added DefaultCheckInDelegate
thivya-amazon Dec 5, 2023
a3f50e5
Restyled by whitespace
restyled-commits Dec 5, 2023
11693ea
Restyled by gn
restyled-commits Dec 5, 2023
94d4bd7
Modified error codes
thivya-amazon Dec 6, 2023
41ab1ea
Updated variables
thivya-amazon Dec 6, 2023
2834b0f
Added condition for VerifyOrReturnError
thivya-amazon Dec 6, 2023
6b14bc8
Resolve conflicts with master branch
thivya-amazon Dec 6, 2023
7b9cd38
Added CheckInHandler init in chiptool
thivya-amazon Dec 6, 2023
5226d1a
Restyled by clang-format
restyled-commits Dec 6, 2023
f6a7b01
Restyled by gn
restyled-commits Dec 6, 2023
5be52af
Added include file
thivya-amazon Dec 6, 2023
22ad2e6
Modified the access operator
thivya-amazon Dec 6, 2023
d215f5f
Added ICD client deps for tv-casting-app
thivya-amazon Dec 6, 2023
f9c8d58
Restyled by gn
restyled-commits Dec 6, 2023
7159a7c
Added unit test case for ProcessCheckInPayload
thivya-amazon Dec 6, 2023
2c46716
Updated doxygen comments
thivya-amazon Dec 6, 2023
d6b829b
Addressed review comments
thivya-amazon Dec 6, 2023
cd9e91a
Addressed review comments
thivya-amazon Dec 6, 2023
9f19c72
Addressed review comments.
thivya-amazon Dec 6, 2023
440c84f
Moved checkin counter validation to CheckInHandler.
thivya-amazon Dec 7, 2023
9a86075
Removed TestDefaultICDClientStorage from iotsdk.
thivya-amazon Dec 8, 2023
d09f601
Restyled by gn
restyled-commits Dec 8, 2023
d415eec
add CheckInExchangeDispatch to accept unsecure check-in message
yunhanw-google Dec 8, 2023
77f4ec4
Restyled by clang-format
restyled-commits Dec 8, 2023
a1f77d5
Removed DefaultICDClientInfoPersistentStorage.cpp.
thivya-amazon Dec 8, 2023
02a8c5c
Addressed a few review comments.
thivya-amazon Dec 8, 2023
4b94518
Modified a macro to make sure it is taken as a 64-bit interger.
thivya-amazon Dec 8, 2023
2e6d649
Restyled by clang-format
restyled-commits Dec 8, 2023
957c716
Removed redundant error code CHIP_ERROR_DUPLICATE_MESSAGE
thivya-amazon Dec 8, 2023
c2f2c53
Restyled by clang-format
restyled-commits Dec 8, 2023
7975ee2
Modified the datatype for checkInCounter to CounterType from auto.
thivya-amazon Dec 9, 2023
7e0d59a
Added code to refresh key.
thivya-amazon Dec 12, 2023
0404f35
ICDHandler initialization
thivya-amazon Nov 29, 2023
559fb3a
ICDHandler initialization
thivya-amazon Dec 3, 2023
0eec8be
Resolve conflicts with master branch
thivya-amazon Dec 6, 2023
89f7145
Added CheckInHandler init in chiptool
thivya-amazon Dec 6, 2023
fb81b59
Moved checkin counter validation to CheckInHandler.
thivya-amazon Dec 7, 2023
7a84cdc
[icd] integrate ICD management command into CHIP tool (#30863)
erjiaqing Dec 12, 2023
8cf0630
ICDHandler initialization
thivya-amazon Dec 3, 2023
3a85145
Added CheckInHandler init in chiptool
thivya-amazon Dec 6, 2023
4952042
Fixing merge conflicts
thivya-amazon Dec 12, 2023
ec3afd8
Added OnRefreshKey callback
thivya-amazon Dec 12, 2023
ef1541a
Restyled by gn
restyled-commits Dec 12, 2023
168556c
Modified APPDATA_LENGTh macro to inline consexpr variable.
thivya-amazon Dec 12, 2023
524e984
Modified CheckInDelegate and CheckInHandler to static members in chip…
thivya-amazon Dec 13, 2023
6ae6657
Return CHIP_NO_ERROR for failures in processing checkin message.
thivya-amazon Dec 13, 2023
03fe6e9
Merge branch 'master' into ICDHandler
thivya-amazon Dec 13, 2023
ada48e8
Addressed review comments
thivya-amazon Dec 13, 2023
fd779e9
Merge branch 'project-chip:master' into ICDHandler
thivya-amazon Dec 13, 2023
2e4e948
Fixed a spelling error
thivya-amazon Dec 13, 2023
510e39d
Moved variable definition
thivya-amazon Dec 14, 2023
b619180
Reenable TestDefaultClientStorage for open iot.
thivya-amazon Dec 15, 2023
30e705c
Restyled by gn
restyled-commits Dec 15, 2023
bdcac8b
Merge branch 'master' into ICDHandler
thivya-amazon Dec 15, 2023
2f5a35a
Modified code to use updated API
thivya-amazon Dec 15, 2023
0cf1672
Removed obsolete comments
thivya-amazon Dec 15, 2023
56ff8fc
Added comments
thivya-amazon Dec 16, 2023
f68c96b
Addressed review comments
thivya-amazon Dec 18, 2023
6e93fdf
Improve ICDClientStorage (#30931)
yunhanw-google Dec 15, 2023
10dbb2a
Added const qualifier to payload
thivya-amazon Dec 18, 2023
68fab70
Merge branch 'master' into ICDHandler
thivya-amazon Dec 18, 2023
c131254
Return CHIP_NO_ERROR for duplicate check in message and log error.
thivya-amazon Dec 20, 2023
a35887b
Merge branch 'project-chip:master' into ICDHandler
thivya-amazon Dec 20, 2023
5982e39
Return CHIP_NO_ERROR on duplicate checkin messages
thivya-amazon Dec 21, 2023
72a6391
Merge branch 'project-chip:master' into ICDHandler
thivya-amazon Dec 21, 2023
10e61ab
Added OnRefreshKeyRetrieve and addressed review comments
thivya-amazon Dec 29, 2023
fe849c6
Update src/lib/core/CHIPError.h
thivya-amazon Dec 29, 2023
9f6bbf0
Restyled by whitespace
restyled-commits Dec 29, 2023
a3e4b23
Restyled by clang-format
restyled-commits Dec 29, 2023
9843156
Restyled by gn
restyled-commits Dec 29, 2023
96b4d2b
Added a temporary suppression of error for including <unordered_map>
thivya-amazon Dec 29, 2023
0b54b26
Added a comment to suppress Lint error
thivya-amazon Dec 29, 2023
1eba16b
Addressed review comments
thivya-amazon Jan 4, 2024
435ffe6
Addressed review comments
thivya-amazon Jan 5, 2024
6563e97
Addressed review comments.
thivya-amazon Jan 9, 2024
f83002f
Removed code pertaining to key refresh. Will be a separate PR.
thivya-amazon Jan 10, 2024
b51d58d
Added a link to an issue
thivya-amazon Jan 10, 2024
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
1 change: 0 additions & 1 deletion examples/chip-tool/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ static_library("chip-tool-utils") {
public_deps = [
"${chip_root}/examples/common/tracing:commandline",
"${chip_root}/src/app/icd/client:handler",
yunhanw-google marked this conversation as resolved.
Show resolved Hide resolved
"${chip_root}/src/app/icd/client:handler",
"${chip_root}/src/app/icd/client:manager",
"${chip_root}/src/app/server",
"${chip_root}/src/app/tests/suites/commands/interaction_model",
Expand Down
2 changes: 1 addition & 1 deletion examples/chip-tool/commands/common/CHIPCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ chip::Credentials::GroupDataProviderImpl CHIPCommand::sGroupDataProvider{ kMaxGr
chip::app::DefaultICDClientStorage CHIPCommand::sICDClientStorage;
chip::Crypto::RawKeySessionKeystore CHIPCommand::sSessionKeystore;
chip::app::DefaultCheckInDelegate CHIPCommand::sCheckInDelegate;
chip::app::CheckInMessageHandler CHIPCommand::sCheckInHandler;
chip::app::CheckInHandler CHIPCommand::sCheckInHandler;

namespace {

Expand Down
17 changes: 13 additions & 4 deletions examples/chip-tool/commands/common/CHIPCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,10 @@ class CHIPCommand : public Command

// Shut down the command. After a Shutdown call the command object is ready
// to be used for another command invocation.
virtual void Shutdown() { ResetArguments(); }
virtual void Shutdown()
{
ResetArguments();
}

// Clean up any resources allocated by the command. Some commands may hold
// on to resources after Shutdown(), but Cleanup() will guarantee those are
Expand All @@ -140,12 +143,18 @@ class CHIPCommand : public Command
// can keep doing work as needed. Cleanup() will be called when quitting
// interactive mode. This method will be called before Shutdown, so it can
// use member values that Shutdown will normally reset.
virtual bool DeferInteractiveCleanup() { return false; }
virtual bool DeferInteractiveCleanup()
{
return false;
}

// If true, the controller will be created with server capabilities enabled,
// such as advertising operational nodes over DNS-SD and accepting incoming
// CASE sessions.
virtual bool NeedsOperationalAdvertising() { return mAdvertiseOperational; }
virtual bool NeedsOperationalAdvertising()
{
return mAdvertiseOperational;
}

// Execute any deferred cleanups. Used when exiting interactive mode.
static void ExecuteDeferredCleanups(intptr_t ignored);
Expand All @@ -163,7 +172,7 @@ class CHIPCommand : public Command
static chip::Credentials::GroupDataProviderImpl sGroupDataProvider;
static chip::app::DefaultICDClientStorage sICDClientStorage;
static chip::app::DefaultCheckInDelegate sCheckInDelegate;
static chip::app::CheckInMessageHandler sCheckInHandler;
static chip::app::CheckInHandler sCheckInHandler;
CredentialIssuerCommands * mCredIssuerCmds;

std::string GetIdentity();
Expand Down
1 change: 1 addition & 0 deletions src/app/icd/client/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,6 @@ source_set("handler") {
"${chip_root}/src/lib/core",
"${chip_root}/src/messaging",
"${chip_root}/src/protocols",
"${chip_root}/src/app",
]
}
45 changes: 35 additions & 10 deletions src/app/icd/client/CheckInDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,38 +19,63 @@
#pragma once

#include <app/icd/client/ICDClientInfo.h>
#include <app/icd/client/ICDRefreshKeyInfo.h>

namespace chip {
namespace app {

/// Callbacks for check in protocol
thivya-amazon marked this conversation as resolved.
Show resolved Hide resolved
/**
* @brief The application implementing an ICD client should inherit the CheckInDelegate and implement the listed callbacks
* OnCheckInComplete will be called on successful processing of a received checkIn message from the server
* OnRefreshKey will be called when the key needs to be refreshed to avoid check in counter roll over problems. On receiving
* OnRefreshKey callback, the application needs to generate a new key.
*/
class DLL_EXPORT CheckInDelegate
{
public:
virtual ~CheckInDelegate() {}

/**
* @brief Callback used to let the application know that a checkin message was received and validated.
* @brief Callback used to let the application know that a check-in message was received and validated.
*
* @param[in] clientInfo - ClientInfo object of the peer node
* @param[in] clientInfo - ICDClientInfo object representing the state associated with the
node that sent the check-in message.
*/
virtual void OnCheckInComplete(ICDClientInfo & clientInfo) = 0;
virtual void OnCheckInComplete(const ICDClientInfo & clientInfo) = 0;

/**
* @brief Callback used to let the application know that a key refresh is
* needed to avoid counter roolover problems.
* needed to avoid counter rollover problems.
*
* The implementer of this function should generate a new key
* The implementer of this function should generate a new key and store it in a map with peer nodeID as the key and
thivya-amazon marked this conversation as resolved.
Show resolved Hide resolved
* ICDRefreshKeyInfo as the value.
bzbarsky-apple marked this conversation as resolved.
Show resolved Hide resolved
*
* @param[out] keyData - new key generated
* @param[in] clientInfo - ICDClientInfo object representing the state associated with the
node that sent the check-in message. The callee can use the clientInfo to determine the type of key
to generate.
* @param[out] keyData - pointer to the keyData buffer of size keyDataLength. The implementer of this callback should generate a
new key of size keyLength and copy it to the keyData buffer
* @param[in] keyLength - length of the new key to be generated
bzbarsky-apple marked this conversation as resolved.
Show resolved Hide resolved
*/
virtual void OnRefreshKey(ByteSpan & keyData) = 0;
virtual void OnRefreshKeyGenerate(const ICDClientInfo & clientInfo, uint8_t * keyData, uint8_t keyLength) = 0;
thivya-amazon marked this conversation as resolved.
Show resolved Hide resolved
thivya-amazon marked this conversation as resolved.
Show resolved Hide resolved

/**
* @brief Callback used to retrieve the refresh key information from the application after establishing a new secure session for
* re-registration. The application should maintain a map to store the corresponding ICDRefreshKeyInfo for every peer node.
thivya-amazon marked this conversation as resolved.
Show resolved Hide resolved
* Please refer to ICDRefreshKeyInfo.h for details.
*
* @param[in] nodeId - node ID of the peer with whom the client needs to re-register with a new key to avoid rollover problems.
thivya-amazon marked this conversation as resolved.
Show resolved Hide resolved
* @param[out] refreshKeyInfo - stored refreshKeyInfo for the corresponding nodeId from the ICDRefreshKeyMap
bzbarsky-apple marked this conversation as resolved.
Show resolved Hide resolved
*/
virtual CHIP_ERROR OnRefreshKeyRetrieve(const ScopedNodeId & nodeId, ICDRefreshKeyInfo & refreshKeyInfo) = 0;
bzbarsky-apple marked this conversation as resolved.
Show resolved Hide resolved

/**
* @brief Callback used to let the application know that the re-registration with the new key was successful and provides the
bzbarsky-apple marked this conversation as resolved.
Show resolved Hide resolved
* updated ICDClientInfo
*
* @param[in] clientInfo - ICDClientInfo object representing the state associated with the
node that sent the check-in message. This will have the new key used for registration and the updated icd
counter.
*/
virtual void OnRegistrationComplete(const ICDClientInfo & clientInfo) = 0;
};

} // namespace app
Expand Down
88 changes: 72 additions & 16 deletions src/app/icd/client/CheckInHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
*
*/

#include <app/InteractionModelTimeout.h>
#include <app/icd/client/CheckInDelegate.h>
#include <app/icd/client/CheckInHandler.h>
#include <app/icd/client/ICDRefreshKeyInfo.h>

#include <cinttypes>

Expand All @@ -32,6 +34,9 @@
#include <messaging/Flags.h>
#include <protocols/Protocols.h>

#include "controller/InvokeInteraction.h"
thivya-amazon marked this conversation as resolved.
Show resolved Hide resolved
#include <app/InteractionModelEngine.h>
#include <app/OperationalSessionSetup.h>
#include <protocols/secure_channel/Constants.h>

namespace chip {
Expand All @@ -40,8 +45,12 @@ namespace app {
inline constexpr uint64_t kCheckInCounterMax = (1ULL << 32);
inline constexpr uint32_t kKeyRefreshLimit = (1U << 31);

CHIP_ERROR CheckInMessageHandler::Init(Messaging::ExchangeManager * exchangeManager, ICDClientStorage * clientStorage,
CheckInDelegate * delegate)
CheckInHandler::CheckInHandler() :
mOnConnectedCallback(HandleDeviceConnected, this), mOnConnectionFailureCallback(HandleDeviceConnectionFailure, this)
{}

CHIP_ERROR CheckInHandler::Init(Messaging::ExchangeManager * exchangeManager, ICDClientStorage * clientStorage,
CheckInDelegate * delegate)
{
VerifyOrReturnError(exchangeManager != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(clientStorage != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
Expand All @@ -55,17 +64,18 @@ CHIP_ERROR CheckInMessageHandler::Init(Messaging::ExchangeManager * exchangeMana
return mpExchangeManager->RegisterUnsolicitedMessageHandlerForType(Protocols::SecureChannel::MsgType::ICD_CheckIn, this);
thivya-amazon marked this conversation as resolved.
Show resolved Hide resolved
}

void CheckInMessageHandler::Shutdown()
void CheckInHandler::Shutdown()
{
mpICDClientStorage = nullptr;
mpCheckInDelegate = nullptr;
if (mpExchangeManager)
{
mpExchangeManager->UnregisterUnsolicitedMessageHandlerForType(Protocols::SecureChannel::MsgType::ICD_CheckIn);
mpExchangeManager = nullptr;
}
}

CHIP_ERROR CheckInMessageHandler::OnUnsolicitedMessageReceived(const PayloadHeader & payloadHeader, ExchangeDelegate *& newDelegate)
CHIP_ERROR CheckInHandler::OnUnsolicitedMessageReceived(const PayloadHeader & payloadHeader, ExchangeDelegate *& newDelegate)
{
// Return error for wrong message type
VerifyOrReturnError(payloadHeader.HasMessageType(Protocols::SecureChannel::MsgType::ICD_CheckIn),
Expand All @@ -75,24 +85,24 @@ CHIP_ERROR CheckInMessageHandler::OnUnsolicitedMessageReceived(const PayloadHead
return CHIP_NO_ERROR;
}

CHIP_ERROR CheckInMessageHandler::OnMessageReceived(Messaging::ExchangeContext * ec, const PayloadHeader & payloadHeader,
System::PacketBufferHandle && payload)
CHIP_ERROR CheckInHandler::OnMessageReceived(Messaging::ExchangeContext * ec, const PayloadHeader & payloadHeader,
System::PacketBufferHandle && payload)
{
// If the message type is not ICD_CheckIn, return CHIP_NO_ERROR and exit
VerifyOrReturnError(payloadHeader.HasMessageType(Protocols::SecureChannel::MsgType::ICD_CheckIn), CHIP_NO_ERROR);

ByteSpan payloadByteSpan{ payload->Start(), payload->DataLength() };
ICDClientInfo clientInfo;
CounterType counter = 0;
// If the CheckIn message processing fails, return CHIP_NO_ERROR and exit.
// If the check-in message processing fails, return CHIP_NO_ERROR and exit.
VerifyOrReturnError(CHIP_NO_ERROR == mpICDClientStorage->ProcessCheckInPayload(payloadByteSpan, clientInfo, counter),
thivya-amazon marked this conversation as resolved.
Show resolved Hide resolved
bzbarsky-apple marked this conversation as resolved.
Show resolved Hide resolved
CHIP_NO_ERROR);
CounterType receivedCheckInCounterOffset = (counter - clientInfo.start_icd_counter) % kCheckInCounterMax;

// Detect duplicate CheckIn messages and return CHIP_NO_ERROR on receiving a duplicate message
// Detect duplicate check-in messages and return CHIP_NO_ERROR on receiving a duplicate message
if (receivedCheckInCounterOffset <= clientInfo.offset)
yunhanw-google marked this conversation as resolved.
Show resolved Hide resolved
{
ChipLogError(ICD, "A duplicate CheckIn message was received and discarded");
ChipLogError(ICD, "A duplicate check-in message was received and discarded");
return CHIP_NO_ERROR;
}

Expand All @@ -101,20 +111,66 @@ CHIP_ERROR CheckInMessageHandler::OnMessageReceived(Messaging::ExchangeContext *

if (refreshKey)
{
ByteSpan newKeyData;
mpCheckInDelegate->OnRefreshKey(newKeyData);
RegisterClientWithNewKey(clientInfo, newKeyData);
uint8_t newKeyData[chip::Crypto::kAES_CCM128_Key_Length];
bzbarsky-apple marked this conversation as resolved.
Show resolved Hide resolved
mpCheckInDelegate->OnRefreshKeyGenerate(clientInfo, newKeyData, chip::Crypto::kAES_CCM128_Key_Length);
// A new session should be established to re-register the client using the new key. The registration will happen in
// mOnDeviceConnected callback
EstablishSessionToPeer(clientInfo.peer_node);
bzbarsky-apple marked this conversation as resolved.
Show resolved Hide resolved
}
else
{
mpCheckInDelegate->OnCheckInComplete(clientInfo);
}
mpCheckInDelegate->OnCheckInComplete(clientInfo);

return CHIP_NO_ERROR;
}

CHIP_ERROR CheckInMessageHandler::RegisterClientWithNewKey(ICDClientInfo & clientInfo, const ByteSpan keyData)
CHIP_ERROR CheckInHandler::RegisterClientWithNewKey(ICDClientInfo & clientInfo, ByteSpan newKey,
Messaging::ExchangeManager & exchangeMgr, const SessionHandle & sessionHandle)
{
// TODO - Register the client. On successful registration, update the clientInfo with the new key and store the clientInfo
Clusters::IcdManagement::Commands::RegisterClient::Type request;
request.checkInNodeID = clientInfo.peer_node.GetNodeId();
request.monitoredSubject = clientInfo.monitored_subject;
request.key = newKey;
// TODO1 : We don't have plain data for the old key
// TODO2 : Find the right way to send the registration command. Both the success and failure callbacks for registration should
// call OnCheckInComplete

return CHIP_NO_ERROR;
}
void CheckInMessageHandler::OnResponseTimeout(Messaging::ExchangeContext * ec) {}

void CheckInHandler::EstablishSessionToPeer(ScopedNodeId peerId)
{
ChipLogProgress(ICD, "Trying to establish a CASE session for re-registering an ICD client");
auto * caseSessionManager = InteractionModelEngine::GetInstance()->GetCASESessionManager();
VerifyOrReturn(caseSessionManager != nullptr);
caseSessionManager->FindOrEstablishSession(peerId, &mOnConnectedCallback, &mOnConnectionFailureCallback);
bzbarsky-apple marked this conversation as resolved.
Show resolved Hide resolved
}

void CheckInHandler::HandleDeviceConnected(void * context, Messaging::ExchangeManager & exchangeMgr,
const SessionHandle & sessionHandle)
{
CheckInHandler * const _this = static_cast<CheckInHandler *>(context);
VerifyOrDie(_this != nullptr);
ICDRefreshKeyInfo refreshKeyInfo;
if (CHIP_NO_ERROR !=
_this->mpCheckInDelegate->OnRefreshKeyRetrieve(sessionHandle->AsSecureSession()->GetPeer(), refreshKeyInfo))
{
ChipLogError(ICD, "Failed to retrieve a new key for re-registration of the ICD client");
}
ByteSpan newKey(refreshKeyInfo.newKey);
_this->RegisterClientWithNewKey(refreshKeyInfo.clientInfo, newKey, exchangeMgr, sessionHandle);
}

void CheckInHandler::HandleDeviceConnectionFailure(void * context, const ScopedNodeId & peerId, CHIP_ERROR err)
{
CheckInHandler * const _this = static_cast<CheckInHandler *>(context);
VerifyOrDie(_this != nullptr);

ChipLogError(ICD, "Failed to establish CASE for re-registration with error '%" CHIP_ERROR_FORMAT "'", err.Format());
}

void CheckInHandler::OnResponseTimeout(Messaging::ExchangeContext * ec) {}

} // namespace app
} // namespace chip
38 changes: 30 additions & 8 deletions src/app/icd/client/CheckInHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@

/**
* @file
* This file defines objects for a CHIP CheckInMessage unsolicited
* This file defines objects for a CHIP check-in message unsolicited
* handler
*
*/

#pragma once

#include <app-common/zap-generated/cluster-objects.h>
#include <app/OperationalSessionSetup.h>
#include <app/icd/client/CheckInDelegate.h>
#include <app/icd/client/DefaultICDClientStorage.h>
#include <lib/support/logging/CHIPLogging.h>
Expand All @@ -33,19 +35,27 @@

namespace chip {
namespace app {
class CheckInMessageHandler : public Messaging::ExchangeDelegate, public Messaging::UnsolicitedMessageHandler

class CheckInHandler : public Messaging::ExchangeDelegate, public Messaging::UnsolicitedMessageHandler
{

public:
CHIP_ERROR Init(Messaging::ExchangeManager * exchangeManager, ICDClientStorage * clientStorage, CheckInDelegate * delegate);
void Shutdown();

virtual ~CheckInMessageHandler() = default;
CheckInHandler();

virtual ~CheckInHandler() = default;

static void HandleDeviceConnected(void * context, Messaging::ExchangeManager & exchangeMgr,
thivya-amazon marked this conversation as resolved.
Show resolved Hide resolved
const SessionHandle & sessionHandle);
static void HandleDeviceConnectionFailure(void * context, const ScopedNodeId & peerId, CHIP_ERROR err);
thivya-amazon marked this conversation as resolved.
Show resolved Hide resolved

protected:
// ExchangeDelegate
CHIP_ERROR OnMessageReceived(Messaging::ExchangeContext * ec, const PayloadHeader & payloadHeader,
System::PacketBufferHandle && payload) override;
CHIP_ERROR
OnMessageReceived(Messaging::ExchangeContext * ec, const PayloadHeader & payloadHeader,
System::PacketBufferHandle && payload) override;

// UnsolicitedMessageHandler
CHIP_ERROR OnUnsolicitedMessageReceived(const PayloadHeader & payloadHeader, ExchangeDelegate *& newDelegate) override;
Expand All @@ -62,7 +72,20 @@ class CheckInMessageHandler : public Messaging::ExchangeDelegate, public Messagi
* @param[in] clientInfo clientInfo object
* @param[in] keyData New key data to use to re-register the client with the server
thivya-amazon marked this conversation as resolved.
Show resolved Hide resolved
*/
CHIP_ERROR RegisterClientWithNewKey(ICDClientInfo & clientInfo, const ByteSpan keyData);
CHIP_ERROR RegisterClientWithNewKey(ICDClientInfo & clientInfo, ByteSpan newKey, Messaging::ExchangeManager & exchangeMgr,
const SessionHandle & sessionHandle);

/**
* @brief Sets up a CASE session to the peer, if we can locate a
thivya-amazon marked this conversation as resolved.
Show resolved Hide resolved
* CASESessionManager. Returns error if we did not even manage to kick off
* a CASE attempt.
*
* @param[in] peerId Node ID of the peer
*/
void EstablishSessionToPeer(ScopedNodeId peerId);

chip::Callback::Callback<OnDeviceConnected> mOnConnectedCallback;
chip::Callback::Callback<OnDeviceConnectionFailure> mOnConnectionFailureCallback;

class CheckInExchangeDispatch : public Messaging::ExchangeMessageDispatch
{
Expand All @@ -86,8 +109,7 @@ class CheckInMessageHandler : public Messaging::ExchangeDelegate, public Messagi

Messaging::ExchangeManager * mpExchangeManager = nullptr;
CheckInDelegate * mpCheckInDelegate = nullptr;
Messaging::ExchangeManager * GetExchangeManager(void) const { return mpExchangeManager; }
ICDClientStorage * mpICDClientStorage = nullptr;
ICDClientStorage * mpICDClientStorage = nullptr;
};

} // namespace app
Expand Down
Loading
Loading