forked from project-chip/connectedhomeip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[icd] integrate ICD management command into CHIP tool (project-chip#3…
…0863) * [icd] integrate ICD management command into CHIP tool * Delete entry on failure * Fix build
- Loading branch information
Showing
10 changed files
with
185 additions
and
3 deletions.
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
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,69 @@ | ||
/* | ||
* Copyright (c) 2023 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 "ICDCommand.h" | ||
|
||
#include <crypto/DefaultSessionKeystore.h> | ||
#include <crypto/RawKeySessionKeystore.h> | ||
|
||
using namespace ::chip; | ||
|
||
CHIP_ERROR ICDListCommand::RunCommand() | ||
{ | ||
app::ICDClientInfo info; | ||
auto iter = CHIPCommand::sICDClientStorage.IterateICDClientInfo(); | ||
char icdSymmetricKeyHex[Crypto::kAES_CCM128_Key_Length * 2 + 1]; | ||
|
||
fprintf(stderr, " +-----------------------------------------------------------------------------+\n"); | ||
fprintf(stderr, " | %-75s |\n", "Known ICDs:"); | ||
fprintf(stderr, " +-----------------------------------------------------------------------------+\n"); | ||
fprintf(stderr, " | %20s | %15s | %15s | %16s |\n", "Fabric Index:Node ID", "Start Counter", "Counter Offset", | ||
"MonitoredSubject"); | ||
|
||
while (iter->Next(info)) | ||
{ | ||
fprintf(stderr, " +-----------------------------------------------------------------------------+\n"); | ||
fprintf(stderr, " | %3" PRIu32 ":" ChipLogFormatX64 " | %15" PRIu32 " | %15" PRIu32 " | " ChipLogFormatX64 " |\n", | ||
static_cast<uint32_t>(info.peer_node.GetFabricIndex()), ChipLogValueX64(info.peer_node.GetNodeId()), | ||
info.start_icd_counter, info.offset, ChipLogValueX64(info.monitored_subject)); | ||
|
||
static_assert(std::is_same<decltype(CHIPCommand::sSessionKeystore), Crypto::RawKeySessionKeystore>::value, | ||
"The following BytesToHex can copy/encode the key bytes from sharedKey to hexadecimal format, which only " | ||
"works for RawKeySessionKeystore"); | ||
Encoding::BytesToHex(info.shared_key.As<Crypto::Symmetric128BitsKeyByteArray>(), Crypto::kAES_CCM128_Key_Length, | ||
icdSymmetricKeyHex, sizeof(icdSymmetricKeyHex), chip::Encoding::HexFlags::kNullTerminate); | ||
fprintf(stderr, " | Symmetric Key: %60s |\n", icdSymmetricKeyHex); | ||
} | ||
|
||
fprintf(stderr, " +-----------------------------------------------------------------------------+\n"); | ||
|
||
iter->Release(); | ||
SetCommandExitStatus(CHIP_NO_ERROR); | ||
return CHIP_NO_ERROR; | ||
} | ||
|
||
void registerCommandsICD(Commands & commands, CredentialIssuerCommands * credsIssuerConfig) | ||
{ | ||
const char * name = "ICD"; | ||
|
||
commands_list list = { | ||
make_unique<ICDListCommand>(credsIssuerConfig), | ||
}; | ||
|
||
commands.RegisterCommandSet(name, list, "Commands for client-side ICD management."); | ||
} |
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,45 @@ | ||
/* | ||
* Copyright (c) 2023 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 "../common/CHIPCommand.h" | ||
#include "commands/common/Commands.h" | ||
|
||
#include <lib/support/Span.h> | ||
|
||
class ICDCommand : public CHIPCommand | ||
{ | ||
public: | ||
ICDCommand(const char * commandName, CredentialIssuerCommands * credIssuerCmds, const char * description) : | ||
CHIPCommand(commandName, credIssuerCmds, description) | ||
{} | ||
|
||
chip::System::Clock::Timeout GetWaitDuration() const override { return chip::System::Clock::Seconds16(10); } | ||
}; | ||
|
||
class ICDListCommand : public ICDCommand | ||
{ | ||
public: | ||
ICDListCommand(CredentialIssuerCommands * credIssuerCmds) : | ||
ICDCommand("list", credIssuerCmds, "List ICDs registed by this controller.") | ||
{} | ||
CHIP_ERROR RunCommand() override; | ||
}; | ||
|
||
void registerCommandsICD(Commands & commands, CredentialIssuerCommands * credsIssuerConfig); |
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
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