-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
[chip-tool] Create ChipToolCheckInDelegate #32885
Closed
erjiaqing
wants to merge
6
commits into
project-chip:master
from
erjiaqing:icd/chip-tool-checkin-delegate
Closed
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
625293e
[chip-tool] Create ChipToolCheckInDelegate
erjiaqing 7762024
remove overdesign callback
erjiaqing b67a457
Update examples/chip-tool/commands/common/ChipToolCheckInDelegate.cpp
yunhanw-google 8ebadd4
Update examples/chip-tool/commands/common/ChipToolCheckInDelegate.h
yunhanw-google 6c051bc
remove unnecessary check-in delegate since the ChipToolCheckInDelegat…
yunhanw-google 5f673c3
Fix build and style
erjiaqing File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
examples/chip-tool/commands/common/ChipToolCheckInDelegate.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* Copyright (c) 2024 Project CHIP Authors | ||
* All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include "ChipToolCheckInDelegate.h" | ||
|
||
#include <app/icd/client/RefreshKeySender.h> | ||
#include <crypto/CHIPCryptoPAL.h> | ||
#include <lib/support/CodeUtils.h> | ||
#include <lib/support/logging/CHIPLogging.h> | ||
|
||
using namespace chip; | ||
using namespace chip::app; | ||
|
||
CHIP_ERROR ChipToolCheckInDelegate::Init(ICDClientStorage * storage, InteractionModelEngine * engine) | ||
erjiaqing marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
VerifyOrReturnError(storage != nullptr, CHIP_ERROR_INVALID_ARGUMENT); | ||
VerifyOrReturnError(mpStorage == nullptr, CHIP_ERROR_INCORRECT_STATE); | ||
VerifyOrReturnError(engine != nullptr, CHIP_ERROR_INVALID_ARGUMENT); | ||
mpStorage = storage; | ||
mpImEngine = engine; | ||
return CHIP_NO_ERROR; | ||
} | ||
|
||
void ChipToolCheckInDelegate::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 (mpCheckInCompleteCallbacks != nullptr) | ||
{ | ||
mpCheckInCompleteCallbacks->OnCheckInComplete(clientInfo); | ||
} | ||
} | ||
|
||
RefreshKeySender * ChipToolCheckInDelegate::OnKeyRefreshNeeded(ICDClientInfo & clientInfo, ICDClientStorage * clientStorage) | ||
{ | ||
CHIP_ERROR err = CHIP_NO_ERROR; | ||
RefreshKeySender::RefreshKeyBuffer newKey; | ||
|
||
err = Crypto::DRBG_get_bytes(newKey.Bytes(), newKey.Capacity()); | ||
if (err != CHIP_NO_ERROR) | ||
{ | ||
ChipLogError(ICD, "Generation of new key failed: %" CHIP_ERROR_FORMAT, err.Format()); | ||
return nullptr; | ||
} | ||
|
||
auto refreshKeySender = Platform::New<RefreshKeySender>(this, clientInfo, clientStorage, mpImEngine, newKey); | ||
if (refreshKeySender == nullptr) | ||
{ | ||
return nullptr; | ||
} | ||
return refreshKeySender; | ||
yunhanw-google marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
void ChipToolCheckInDelegate::OnKeyRefreshDone(RefreshKeySender * refreshKeySender, CHIP_ERROR error) | ||
{ | ||
if (error == CHIP_NO_ERROR) | ||
{ | ||
ChipLogProgress(ICD, "Re-registration with new key completed successfully"); | ||
} | ||
else | ||
{ | ||
ChipLogError(ICD, "Re-registration with new key failed with error : %" CHIP_ERROR_FORMAT, error.Format()); | ||
// The callee can take corrective action based on the error received. | ||
} | ||
if (refreshKeySender != nullptr) | ||
{ | ||
Platform::Delete(refreshKeySender); | ||
refreshKeySender = nullptr; | ||
} | ||
} | ||
|
||
void ChipToolCheckInDelegate::SetOnCheckInCompleteCallback(CheckInCompleteCallback * handler) | ||
{ | ||
mpCheckInCompleteCallbacks = handler; | ||
} | ||
|
||
void ChipToolCheckInDelegate::UnsetOnCheckInCompleteCallback() | ||
{ | ||
mpCheckInCompleteCallbacks = nullptr; | ||
} |
74 changes: 74 additions & 0 deletions
74
examples/chip-tool/commands/common/ChipToolCheckInDelegate.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* | ||
* Copyright (c) 2024 Project CHIP Authors | ||
* All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <set> | ||
|
||
#include <app/InteractionModelEngine.h> | ||
#include <app/icd/client/CheckInDelegate.h> | ||
#include <app/icd/client/ICDClientStorage.h> | ||
|
||
class CheckInCompleteCallback | ||
{ | ||
public: | ||
virtual ~CheckInCompleteCallback() {} | ||
|
||
/** | ||
* @brief Callback used to let the application know that a check-in message was received and validated. | ||
* | ||
* The callback will be executed in CHIP main loop. Implementations should avoid blocking operations in this callback. | ||
* | ||
* @param[in] clientInfo - ICDClientInfo object representing the state associated with the | ||
* node that sent the check-in message. | ||
*/ | ||
virtual void OnCheckInComplete(const chip::app::ICDClientInfo & clientInfo); | ||
yunhanw-google marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
|
||
class ChipToolCheckInDelegate : public chip::app::CheckInDelegate | ||
{ | ||
public: | ||
virtual ~ChipToolCheckInDelegate() {} | ||
CHIP_ERROR Init(chip::app::ICDClientStorage * storage, chip::app::InteractionModelEngine * engine); | ||
void OnCheckInComplete(const chip::app::ICDClientInfo & clientInfo) override; | ||
chip::app::RefreshKeySender * OnKeyRefreshNeeded(chip::app::ICDClientInfo & clientInfo, | ||
chip::app::ICDClientStorage * clientStorage) override; | ||
void OnKeyRefreshDone(chip::app::RefreshKeySender * refreshKeySender, CHIP_ERROR error) override; | ||
|
||
/** | ||
* @brief Sets a callback for when the Check-In processing completes. | ||
* | ||
* This method does not consider the race condition that the callback is changed during OnCheckInComplete. | ||
* | ||
* @param[in] handler - A pointer to the CheckInCompleteCallback to register. | ||
*/ | ||
void SetOnCheckInCompleteCallback(CheckInCompleteCallback * handler); | ||
|
||
/** | ||
* @brief Unsets the callback for when the Check-In processing completes. | ||
* | ||
* This method does not consider the race condition that the callback is changed during OnCheckInComplete. | ||
*/ | ||
void UnsetOnCheckInCompleteCallback(); | ||
yunhanw-google marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
private: | ||
chip::app::ICDClientStorage * mpStorage = nullptr; | ||
chip::app::InteractionModelEngine * mpImEngine = nullptr; | ||
|
||
CheckInCompleteCallback * mpCheckInCompleteCallbacks; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this plural? There is one callback... |
||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably better as: