diff --git a/examples/chip-tool/BUILD.gn b/examples/chip-tool/BUILD.gn index 2b99f1cc106a58..fc9e1e63a7d31f 100644 --- a/examples/chip-tool/BUILD.gn +++ b/examples/chip-tool/BUILD.gn @@ -48,6 +48,8 @@ static_library("chip-tool-utils") { sources = [ "${chip_root}/src/app/tests/suites/include/ConstraintsChecker.h", "${chip_root}/src/app/tests/suites/include/ValueChecker.h", + "${chip_root}/src/controller/ExamplePersistentStorage.cpp", + "${chip_root}/src/controller/ExamplePersistentStorage.h", "${chip_root}/zzz_generated/chip-tool/zap-generated/cluster/ComplexArgumentParser.cpp", "${chip_root}/zzz_generated/chip-tool/zap-generated/cluster/logging/DataModelLogger.cpp", "commands/clusters/ModelCommand.cpp", @@ -68,17 +70,11 @@ static_library("chip-tool-utils") { "commands/discover/DiscoverCommand.cpp", "commands/discover/DiscoverCommissionablesCommand.cpp", "commands/discover/DiscoverCommissionersCommand.cpp", - "commands/pairing/PairingCommand.cpp", - - # TODO - enable CommissionedListCommand once DNS Cache is implemented - # "commands/pairing/CommissionedListCommand.cpp", - # "commands/pairing/CommissionedListCommand.h", - "${chip_root}/src/controller/ExamplePersistentStorage.cpp", - "${chip_root}/src/controller/ExamplePersistentStorage.h", "commands/pairing/CloseSessionCommand.cpp", "commands/pairing/CloseSessionCommand.h", "commands/pairing/OpenCommissioningWindowCommand.cpp", "commands/pairing/OpenCommissioningWindowCommand.h", + "commands/pairing/PairingCommand.cpp", "commands/payload/AdditionalDataParseCommand.cpp", "commands/payload/SetupPayloadGenerateCommand.cpp", "commands/payload/SetupPayloadParseCommand.cpp", diff --git a/examples/chip-tool/commands/pairing/Commands.h b/examples/chip-tool/commands/pairing/Commands.h index 0db8e0c59e2fef..a1f11855f93d26 100644 --- a/examples/chip-tool/commands/pairing/Commands.h +++ b/examples/chip-tool/commands/pairing/Commands.h @@ -20,7 +20,6 @@ #include "commands/common/Commands.h" #include "commands/pairing/CloseSessionCommand.h" -#include "commands/pairing/CommissionedListCommand.h" #include "commands/pairing/GetCommissionerNodeIdCommand.h" #include "commands/pairing/OpenCommissioningWindowCommand.h" #include "commands/pairing/PairingCommand.h" diff --git a/examples/chip-tool/commands/pairing/CommissionedListCommand.cpp b/examples/chip-tool/commands/pairing/CommissionedListCommand.cpp deleted file mode 100644 index ef30ef4978819f..00000000000000 --- a/examples/chip-tool/commands/pairing/CommissionedListCommand.cpp +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright (c) 2021 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 "CommissionedListCommand.h" - -#include -#include -#include -#include - -CHIP_ERROR CommissionedListCommand::Run() -{ - ReturnLogErrorOnFailure(mStorage.Init()); - return PrintInformation(); -} - -CHIP_ERROR CommissionedListCommand::PrintInformation() -{ - uint64_t pairedNodesIds[chip::Controller::kNumMaxPairedDevices]; - uint16_t pairedNodesIdsSize = sizeof(pairedNodesIds); - memset(pairedNodesIds, 0, pairedNodesIdsSize); - - // TODO: Get the list of paired node IDs. chip-tool needs to store that as - // devices get paired. - uint16_t pairedDevicesCount = 0; - while (pairedNodesIds[pairedDevicesCount] != 0x0 && pairedDevicesCount < chip::Controller::kNumMaxPairedDevices) - { - pairedDevicesCount++; - } - - if (pairedDevicesCount == 0) - { - ChipLogProgress(chipTool, "No paired devices."); - } - else - { - fprintf(stdout, "NOTES: Only the devices locally commissioned with chip-tool are displayed.\n"); - fprintf(stdout, "+---------------------------------------------------------------------------------------------+\n"); - fprintf(stdout, "| NodeId | Address | Port | Interface |\n"); - fprintf(stdout, "+---------------------------------------------------------------------------------------------+\n"); - for (uint16_t i = 0; i < pairedDevicesCount; i++) - { - ReturnLogErrorOnFailure(PrintDeviceInformation(pairedNodesIds[i])); - } - fprintf(stdout, "+---------------------------------------------------------------------------------------------+\n"); - } - - return CHIP_NO_ERROR; -} - -CHIP_ERROR CommissionedListCommand::PrintDeviceInformation(chip::NodeId deviceId) -{ - // TODO: Controller::SerializedDevice and Controller::SerializableDevice are - // gone. Need to figure out what chip-tool should actually store/retrieve - // here. - chip::Controller::SerializedDevice deviceInfo; - uint16_t size = sizeof(deviceInfo.inner); - - chip::Controller::SerializableDevice serializable; - constexpr size_t maxlen = BASE64_ENCODED_LEN(sizeof(serializable)); - const size_t len = strnlen(chip::Uint8::to_const_char(&deviceInfo.inner[0]), maxlen); - - VerifyOrReturnError(len < sizeof(chip::Controller::SerializedDevice), CHIP_ERROR_INVALID_ARGUMENT); - VerifyOrReturnError(chip::CanCastTo(len), CHIP_ERROR_INVALID_ARGUMENT); - - CHIP_ZERO_AT(serializable); - const uint16_t deserializedLen = chip::Base64Decode(chip::Uint8::to_const_char(deviceInfo.inner), static_cast(len), - chip::Uint8::to_uchar(reinterpret_cast(&serializable))); - - VerifyOrReturnError(deserializedLen > 0, CHIP_ERROR_INVALID_ARGUMENT); - VerifyOrReturnError(deserializedLen <= sizeof(serializable), CHIP_ERROR_INVALID_ARGUMENT); - - const uint16_t port = chip::Encoding::LittleEndian::HostSwap16(serializable.mDevicePort); - fprintf(stderr, "| 0x%-16" PRIx64 " | %-45s | %-5u| %-15s |\n", deviceId, serializable.mDeviceAddr, port, - serializable.mInterfaceName); - - return CHIP_NO_ERROR; -} diff --git a/examples/chip-tool/commands/pairing/CommissionedListCommand.h b/examples/chip-tool/commands/pairing/CommissionedListCommand.h deleted file mode 100644 index ca63c553c409bd..00000000000000 --- a/examples/chip-tool/commands/pairing/CommissionedListCommand.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2021 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/Command.h" -#include - -class CommissionedListCommand : public Command -{ -public: - CommissionedListCommand() : Command("list") {} - CHIP_ERROR Run() override; - -private: - CHIP_ERROR PrintInformation(); - CHIP_ERROR PrintDeviceInformation(chip::NodeId deviceId); - - PersistentStorage mStorage; -};