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] Move OnActiveModeNotification out from onCheckInComplete #32159

Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 4 additions & 2 deletions examples/chip-tool/commands/common/CHIPCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,11 @@ CHIP_ERROR CHIPCommand::MaybeSetUpStack()

ReturnErrorOnFailure(GetAttestationTrustStore(mPaaTrustStorePath.ValueOr(nullptr), &sTrustStore));

ReturnLogErrorOnFailure(sCheckInDelegate.Init(&sICDClientStorage));
auto engine = chip::app::InteractionModelEngine::GetInstance();
VerifyOrReturnError(engine != nullptr, CHIP_ERROR_INCORRECT_STATE);
ReturnLogErrorOnFailure(sCheckInDelegate.Init(&sICDClientStorage, engine));
ReturnLogErrorOnFailure(sCheckInHandler.Init(DeviceControllerFactory::GetInstance().GetSystemState()->ExchangeMgr(),
&sICDClientStorage, &sCheckInDelegate));
&sICDClientStorage, &sCheckInDelegate, engine));

CommissionerIdentity nullIdentity{ kIdentityNull, chip::kUndefinedNodeId };
ReturnLogErrorOnFailure(InitializeCommissioner(nullIdentity, kIdentityNullFabricId));
Expand Down
9 changes: 7 additions & 2 deletions src/app/icd/client/CheckInHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
*
*/

#include <app/AppConfig.h>
#include <app/InteractionModelEngine.h>
#include <app/InteractionModelTimeout.h>
#include <app/icd/client/CheckInHandler.h>
#include <app/icd/client/RefreshKeySender.h>
Expand All @@ -44,7 +46,7 @@ inline constexpr uint32_t kKeyRefreshLimit = (1U << 31);
CheckInHandler::CheckInHandler() {}

CHIP_ERROR CheckInHandler::Init(Messaging::ExchangeManager * exchangeManager, ICDClientStorage * clientStorage,
CheckInDelegate * delegate)
CheckInDelegate * delegate, InteractionModelEngine * engine)
{
VerifyOrReturnError(exchangeManager != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(clientStorage != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
Expand All @@ -54,7 +56,7 @@ CHIP_ERROR CheckInHandler::Init(Messaging::ExchangeManager * exchangeManager, IC
mpExchangeManager = exchangeManager;
mpICDClientStorage = clientStorage;
mpCheckInDelegate = delegate;

mpImEngine = engine;
return mpExchangeManager->RegisterUnsolicitedMessageHandlerForType(Protocols::SecureChannel::MsgType::ICD_CheckIn, this);
}

Expand Down Expand Up @@ -127,6 +129,9 @@ CHIP_ERROR CheckInHandler::OnMessageReceived(Messaging::ExchangeContext * ec, co
else
{
mpCheckInDelegate->OnCheckInComplete(clientInfo);
#if CHIP_CONFIG_ENABLE_READ_CLIENT
yunhanw-google marked this conversation as resolved.
Show resolved Hide resolved
mpImEngine->OnActiveModeNotification(clientInfo.peer_node);
yunhanw-google marked this conversation as resolved.
Show resolved Hide resolved
#endif // CHIP_CONFIG_ENABLE_READ_CLIENT
}

return CHIP_NO_ERROR;
Expand Down
6 changes: 4 additions & 2 deletions src/app/icd/client/CheckInHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@

namespace chip {
namespace app {

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

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

CheckInHandler();
Expand Down Expand Up @@ -87,6 +88,7 @@ class CheckInHandler : public Messaging::ExchangeDelegate, public Messaging::Uns
Messaging::ExchangeManager * mpExchangeManager = nullptr;
CheckInDelegate * mpCheckInDelegate = nullptr;
ICDClientStorage * mpICDClientStorage = nullptr;
InteractionModelEngine * mpImEngine = nullptr;
};

} // namespace app
Expand Down
11 changes: 4 additions & 7 deletions src/app/icd/client/DefaultCheckInDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
* limitations under the License.
*/

#include <app/InteractionModelEngine.h>
#include <app/icd/client/DefaultCheckInDelegate.h>
#include <app/icd/client/RefreshKeySender.h>
#include <crypto/CHIPCryptoPAL.h>
Expand All @@ -25,11 +24,12 @@
namespace chip {
namespace app {

CHIP_ERROR DefaultCheckInDelegate::Init(ICDClientStorage * storage)
CHIP_ERROR DefaultCheckInDelegate::Init(ICDClientStorage * storage, InteractionModelEngine * engine)
{
VerifyOrReturnError(storage != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(mpStorage == nullptr, CHIP_ERROR_INCORRECT_STATE);
mpStorage = storage;
mpStorage = storage;
mpImEngine = engine;
return CHIP_NO_ERROR;
}

Expand All @@ -38,9 +38,6 @@ void DefaultCheckInDelegate::OnCheckInComplete(const ICDClientInfo & clientInfo)
ChipLogProgress(
ICD, "Check In Message processing complete: start_counter=%" PRIu32 " offset=%" PRIu32 " nodeid=" ChipLogFormatScopedNodeId,
clientInfo.start_icd_counter, clientInfo.offset, ChipLogValueScopedNodeId(clientInfo.peer_node));
#if CHIP_CONFIG_ENABLE_READ_CLIENT
InteractionModelEngine::GetInstance()->OnActiveModeNotification(clientInfo.peer_node);
#endif
}

RefreshKeySender * DefaultCheckInDelegate::OnKeyRefreshNeeded(ICDClientInfo & clientInfo, ICDClientStorage * clientStorage)
Expand All @@ -55,7 +52,7 @@ RefreshKeySender * DefaultCheckInDelegate::OnKeyRefreshNeeded(ICDClientInfo & cl
return nullptr;
}

auto refreshKeySender = Platform::New<RefreshKeySender>(this, clientInfo, clientStorage, newKey);
auto refreshKeySender = Platform::New<RefreshKeySender>(this, clientInfo, clientStorage, mpImEngine, newKey);
if (refreshKeySender == nullptr)
{
return nullptr;
Expand Down
7 changes: 5 additions & 2 deletions src/app/icd/client/DefaultCheckInDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,21 @@ namespace app {

using namespace std;

class InteractionModelEngine;

/// Callbacks for check in protocol
class DefaultCheckInDelegate : public CheckInDelegate
{
public:
virtual ~DefaultCheckInDelegate() {}
CHIP_ERROR Init(ICDClientStorage * storage);
CHIP_ERROR Init(ICDClientStorage * storage, InteractionModelEngine * engine);
void OnCheckInComplete(const ICDClientInfo & clientInfo) override;
RefreshKeySender * OnKeyRefreshNeeded(ICDClientInfo & clientInfo, ICDClientStorage * clientStorage) override;
void OnKeyRefreshDone(RefreshKeySender * refreshKeySender, CHIP_ERROR error) override;

private:
ICDClientStorage * mpStorage = nullptr;
ICDClientStorage * mpStorage = nullptr;
InteractionModelEngine * mpImEngine = nullptr;
};

} // namespace app
Expand Down
13 changes: 9 additions & 4 deletions src/app/icd/client/RefreshKeySender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "CheckInDelegate.h"
#include "controller/InvokeInteraction.h"
#include <app-common/zap-generated/cluster-objects.h>
#include <app/AppConfig.h>
#include <app/CommandPathParams.h>
#include <app/InteractionModelEngine.h>
#include <app/OperationalSessionSetup.h>
Expand All @@ -28,10 +29,11 @@ namespace chip {
namespace app {

RefreshKeySender::RefreshKeySender(CheckInDelegate * checkInDelegate, const ICDClientInfo & icdClientInfo,
ICDClientStorage * icdClientStorage, const RefreshKeyBuffer & refreshKeyBuffer) :
mICDClientInfo(icdClientInfo),
mpICDClientStorage(icdClientStorage), mpCheckInDelegate(checkInDelegate), mOnConnectedCallback(HandleDeviceConnected, this),
mOnConnectionFailureCallback(HandleDeviceConnectionFailure, this)
ICDClientStorage * icdClientStorage, InteractionModelEngine * engine,
const RefreshKeyBuffer & refreshKeyBuffer) :
mpCheckInDelegate(checkInDelegate),
mICDClientInfo(icdClientInfo), mpICDClientStorage(icdClientStorage), mpImEngine(engine),
mOnConnectedCallback(HandleDeviceConnected, this), mOnConnectionFailureCallback(HandleDeviceConnectionFailure, this)

{
mNewKey = refreshKeyBuffer;
Expand Down Expand Up @@ -64,6 +66,9 @@ CHIP_ERROR RefreshKeySender::RegisterClientWithNewKey(Messaging::ExchangeManager
}

mpCheckInDelegate->OnCheckInComplete(mICDClientInfo);
#if CHIP_CONFIG_ENABLE_READ_CLIENT
yunhanw-google marked this conversation as resolved.
Show resolved Hide resolved
mpImEngine->OnActiveModeNotification(mICDClientInfo.peer_node);
#endif // CHIP_CONFIG_ENABLE_READ_CLIENT
mpCheckInDelegate->OnKeyRefreshDone(this, CHIP_NO_ERROR);
};

Expand Down
7 changes: 4 additions & 3 deletions src/app/icd/client/RefreshKeySender.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace chip {
namespace app {

class CheckInDelegate;

class InteractionModelEngine;
/**
* @brief RefreshKeySender contains all the data and methods needed for key refresh and re-registration of an ICD client.
*/
Expand All @@ -44,7 +44,7 @@ class RefreshKeySender
typedef Crypto::SensitiveDataBuffer<Crypto::kAES_CCM128_Key_Length> RefreshKeyBuffer;

RefreshKeySender(CheckInDelegate * checkInDelegate, const ICDClientInfo & icdClientInfo, ICDClientStorage * icdClientStorage,
const RefreshKeyBuffer & refreshKeyBuffer);
InteractionModelEngine * engine, const RefreshKeyBuffer & refreshKeyBuffer);

/**
* @brief Sets up a CASE session to the peer for re-registering a client with the peer when a key refresh is required to avoid
Expand Down Expand Up @@ -82,9 +82,10 @@ class RefreshKeySender
*/
CHIP_ERROR RegisterClientWithNewKey(Messaging::ExchangeManager & exchangeMgr, const SessionHandle & sessionHandle);

CheckInDelegate * mpCheckInDelegate = nullptr;
ICDClientInfo mICDClientInfo;
ICDClientStorage * mpICDClientStorage = nullptr;
CheckInDelegate * mpCheckInDelegate = nullptr;
InteractionModelEngine * mpImEngine = nullptr;
RefreshKeyBuffer mNewKey;
Callback::Callback<OnDeviceConnected> mOnConnectedCallback;
Callback::Callback<OnDeviceConnectionFailure> mOnConnectionFailureCallback;
Expand Down
Loading