From ce8a93957fc389f57f3c7fc0c546b9501465cde5 Mon Sep 17 00:00:00 2001 From: Evgeny Margolis Date: Wed, 18 May 2022 19:09:59 -0700 Subject: [PATCH] Renamed CHIP_ERROR_INVALID_FABRIC_ID to CHIP_ERROR_INVALID_FABRIC_INDEX (#18579) --- .../commands/tests/TestCommandBridge.h | 2 +- .../commands/clusters/ModelCommand.cpp | 4 +-- .../src/TargetVideoPlayerInfo.cpp | 2 +- src/app/AttributeAccessInterface.h | 4 +-- .../group-key-mgmt-server.cpp | 6 ++-- .../operational-credentials-server.cpp | 6 ++-- .../commissioner/CommissionerCommands.cpp | 2 +- src/controller/CHIPDeviceController.cpp | 2 +- src/credentials/GroupDataProviderImpl.cpp | 28 +++++++++---------- .../tests/TestGroupDataProvider.cpp | 6 ++-- src/lib/core/CHIPError.cpp | 4 +-- src/lib/core/CHIPError.h | 6 ++-- src/lib/core/DataModelTypes.h | 1 + src/lib/core/tests/TestCHIPErrorStr.cpp | 2 +- 14 files changed, 38 insertions(+), 37 deletions(-) diff --git a/examples/chip-tool-darwin/commands/tests/TestCommandBridge.h b/examples/chip-tool-darwin/commands/tests/TestCommandBridge.h index 11f64b9ed9b317..afd6d4170a0e06 100644 --- a/examples/chip-tool-darwin/commands/tests/TestCommandBridge.h +++ b/examples/chip-tool-darwin/commands/tests/TestCommandBridge.h @@ -442,7 +442,7 @@ NS_ASSUME_NONNULL_BEGIN if (CHIP_ERROR_FABRIC_EXISTS == err) { return StatusIB(Status::Failure, to_underlying(OperationalCertStatus::kFabricConflict)); } - if (CHIP_ERROR_INVALID_FABRIC_ID == err) { + if (CHIP_ERROR_INVALID_FABRIC_INDEX == err) { return StatusIB(Status::Failure, to_underlying(OperationalCertStatus::kInvalidFabricIndex)); } diff --git a/examples/tv-casting-app/tv-casting-common/commands/clusters/ModelCommand.cpp b/examples/tv-casting-app/tv-casting-common/commands/clusters/ModelCommand.cpp index 9085c56f59f08d..a3b100104b9430 100644 --- a/examples/tv-casting-app/tv-casting-common/commands/clusters/ModelCommand.cpp +++ b/examples/tv-casting-app/tv-casting-common/commands/clusters/ModelCommand.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Project CHIP Authors + * Copyright (c) 2020-2022 Project CHIP Authors * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -52,7 +52,7 @@ CHIP_ERROR ModelCommand::RunCommand() if (fabric == nullptr) { ChipLogError(AppServer, "Did not find fabric for index %d", fabricIndex); - return CHIP_ERROR_INVALID_FABRIC_ID; + return CHIP_ERROR_INVALID_FABRIC_INDEX; } PeerId peerID = fabric->GetPeerIdForNode(mNodeId); diff --git a/examples/tv-casting-app/tv-casting-common/src/TargetVideoPlayerInfo.cpp b/examples/tv-casting-app/tv-casting-common/src/TargetVideoPlayerInfo.cpp index d3ad562a9fd012..f53db90263aae2 100644 --- a/examples/tv-casting-app/tv-casting-common/src/TargetVideoPlayerInfo.cpp +++ b/examples/tv-casting-app/tv-casting-common/src/TargetVideoPlayerInfo.cpp @@ -37,7 +37,7 @@ CHIP_ERROR TargetVideoPlayerInfo::Initialize(NodeId nodeId, FabricIndex fabricIn if (fabric == nullptr) { ChipLogError(AppServer, "Did not find fabric for index %d", fabricIndex); - return CHIP_ERROR_INVALID_FABRIC_ID; + return CHIP_ERROR_INVALID_FABRIC_INDEX; } PeerId peerID = fabric->GetPeerIdForNode(nodeId); diff --git a/src/app/AttributeAccessInterface.h b/src/app/AttributeAccessInterface.h index 3c0931b54031b9..1670c35ba75dd1 100644 --- a/src/app/AttributeAccessInterface.h +++ b/src/app/AttributeAccessInterface.h @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2021 Project CHIP Authors + * Copyright (c) 2021-2022 Project CHIP Authors * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -111,7 +111,7 @@ class AttributeValueEncoder template ::value, bool> = true> CHIP_ERROR Encode(T && aArg) const { - VerifyOrReturnError(aArg.GetFabricIndex() != kUndefinedFabricIndex, CHIP_ERROR_INVALID_FABRIC_ID); + VerifyOrReturnError(aArg.GetFabricIndex() != kUndefinedFabricIndex, CHIP_ERROR_INVALID_FABRIC_INDEX); // If we are encoding for a fabric filtered attribute read and the fabric index does not match that present in the // request, skip encoding this list item. diff --git a/src/app/clusters/group-key-mgmt-server/group-key-mgmt-server.cpp b/src/app/clusters/group-key-mgmt-server/group-key-mgmt-server.cpp index e99b7d1334cf91..8ee50c5973109f 100644 --- a/src/app/clusters/group-key-mgmt-server/group-key-mgmt-server.cpp +++ b/src/app/clusters/group-key-mgmt-server/group-key-mgmt-server.cpp @@ -1,6 +1,6 @@ /** * - * Copyright (c) 2020 Project CHIP Authors + * Copyright (c) 2020-2022 Project CHIP Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -202,7 +202,7 @@ class GroupKeyManagementAttributeAccess : public AttributeAccessInterface while (iter.Next()) { const auto & value = iter.GetValue(); - VerifyOrReturnError(fabric_index == value.fabricIndex, CHIP_ERROR_INVALID_FABRIC_ID); + VerifyOrReturnError(fabric_index == value.fabricIndex, CHIP_ERROR_INVALID_FABRIC_INDEX); // Cannot map to IPK, see `GroupKeyMapStruct` in Group Key Management cluster spec VerifyOrReturnError(value.groupKeySetID != 0, CHIP_IM_GLOBAL_STATUS(ConstraintError)); @@ -217,7 +217,7 @@ class GroupKeyManagementAttributeAccess : public AttributeAccessInterface size_t current_count = 0; VerifyOrReturnError(nullptr != provider, CHIP_ERROR_INTERNAL); ReturnErrorOnFailure(aDecoder.Decode(value)); - VerifyOrReturnError(fabric_index == value.fabricIndex, CHIP_ERROR_INVALID_FABRIC_ID); + VerifyOrReturnError(fabric_index == value.fabricIndex, CHIP_ERROR_INVALID_FABRIC_INDEX); // Cannot map to IPK, see `GroupKeyMapStruct` in Group Key Management cluster spec VerifyOrReturnError(value.groupKeySetID != 0, CHIP_IM_GLOBAL_STATUS(ConstraintError)); diff --git a/src/app/clusters/operational-credentials-server/operational-credentials-server.cpp b/src/app/clusters/operational-credentials-server/operational-credentials-server.cpp index ba08f5bb04a0aa..4f4a7c4e0709ba 100644 --- a/src/app/clusters/operational-credentials-server/operational-credentials-server.cpp +++ b/src/app/clusters/operational-credentials-server/operational-credentials-server.cpp @@ -542,7 +542,7 @@ bool emberAfOperationalCredentialsClusterUpdateFabricLabelCallback(app::CommandH // Fetch current fabric FabricInfo * fabric = RetrieveCurrentFabric(commandObj); - VerifyOrExit(fabric != nullptr, err = CHIP_ERROR_INVALID_FABRIC_ID); + VerifyOrExit(fabric != nullptr, err = CHIP_ERROR_INVALID_FABRIC_INDEX); // Set Label on fabric err = fabric->SetFabricLabel(Label); @@ -593,7 +593,7 @@ OperationalCertStatus ConvertToNOCResponseStatus(CHIP_ERROR err) { return OperationalCertStatus::kInvalidPublicKey; } - if (err == CHIP_ERROR_INVALID_FABRIC_ID || err == CHIP_ERROR_WRONG_NODE_ID) + if (err == CHIP_ERROR_INVALID_FABRIC_INDEX || err == CHIP_ERROR_WRONG_NODE_ID) { return OperationalCertStatus::kInvalidNodeOpId; } @@ -777,7 +777,7 @@ bool emberAfOperationalCredentialsClusterUpdateNOCCallback(app::CommandHandler * // Fetch current fabric FabricInfo * fabric = RetrieveCurrentFabric(commandObj); - VerifyOrExit(fabric != nullptr, nocResponse = ConvertToNOCResponseStatus(CHIP_ERROR_INVALID_FABRIC_ID)); + VerifyOrExit(fabric != nullptr, nocResponse = ConvertToNOCResponseStatus(CHIP_ERROR_INVALID_FABRIC_INDEX)); // Flag on the fail-safe context that the UpdateNOC command was invoked. err = failSafeContext.SetUpdateNocCommandInvoked(); diff --git a/src/app/tests/suites/commands/commissioner/CommissionerCommands.cpp b/src/app/tests/suites/commands/commissioner/CommissionerCommands.cpp index c64e4f39339d69..828e30282af9c2 100644 --- a/src/app/tests/suites/commands/commissioner/CommissionerCommands.cpp +++ b/src/app/tests/suites/commands/commissioner/CommissionerCommands.cpp @@ -77,7 +77,7 @@ chip::app::StatusIB ConvertToStatusIB(CHIP_ERROR err) { return StatusIB(Status::Failure, to_underlying(OperationalCertStatus::kFabricConflict)); } - if (CHIP_ERROR_INVALID_FABRIC_ID == err) + if (CHIP_ERROR_INVALID_FABRIC_INDEX == err) { return StatusIB(Status::Failure, to_underlying(OperationalCertStatus::kInvalidFabricIndex)); } diff --git a/src/controller/CHIPDeviceController.cpp b/src/controller/CHIPDeviceController.cpp index fd5e6b5fa50507..75c99b685047f4 100644 --- a/src/controller/CHIPDeviceController.cpp +++ b/src/controller/CHIPDeviceController.cpp @@ -1218,7 +1218,7 @@ CHIP_ERROR DeviceCommissioner::ConvertFromOperationalCertStatus(OperationalCrede case OperationalCertStatus::kLabelConflict: return CHIP_ERROR_INVALID_ARGUMENT; case OperationalCertStatus::kInvalidFabricIndex: - return CHIP_ERROR_INVALID_FABRIC_ID; + return CHIP_ERROR_INVALID_FABRIC_INDEX; } return CHIP_ERROR_CERT_LOAD_FAILED; diff --git a/src/credentials/GroupDataProviderImpl.cpp b/src/credentials/GroupDataProviderImpl.cpp index 6047bfd3a45daa..c5d65bfcb6e850 100644 --- a/src/credentials/GroupDataProviderImpl.cpp +++ b/src/credentials/GroupDataProviderImpl.cpp @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2021 Project CHIP Authors + * Copyright (c) 2021-2022 Project CHIP Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -182,7 +182,7 @@ struct FabricData : public PersistentData uint16_t group_count = 0; uint16_t first_map = 0; uint16_t map_count = 0; - chip::KeysetId first_keyset = 0xffff; + chip::KeysetId first_keyset = kInvalidKeysetId; uint16_t keyset_count = 0; chip::FabricIndex next = kUndefinedFabricIndex; @@ -191,7 +191,7 @@ struct FabricData : public PersistentData CHIP_ERROR UpdateKey(DefaultStorageKeyAllocator & key) override { - VerifyOrReturnError(kUndefinedFabricIndex != fabric_index, CHIP_ERROR_INVALID_FABRIC_ID); + VerifyOrReturnError(kUndefinedFabricIndex != fabric_index, CHIP_ERROR_INVALID_FABRIC_INDEX); key.FabricGroups(fabric_index); return CHIP_NO_ERROR; } @@ -200,7 +200,7 @@ struct FabricData : public PersistentData { first_group = kUndefinedGroupId; group_count = 0; - first_keyset = 0xffff; + first_keyset = kInvalidKeysetId; keyset_count = 0; next = kUndefinedFabricIndex; } @@ -389,7 +389,7 @@ struct GroupData : public GroupDataProvider::GroupInfo, PersistentData static constexpr TLV::Tag TagNext() { return TLV::ContextTag(7); } chip::FabricIndex fabric_index = kUndefinedFabricIndex; - chip::KeysetId next = 0xffff; - chip::KeysetId prev = 0xffff; + chip::KeysetId next = kInvalidKeysetId; + chip::KeysetId prev = kInvalidKeysetId; bool first = true; uint16_t keyset_id = 0; @@ -735,8 +735,8 @@ struct KeySetData : PersistentData CHIP_ERROR UpdateKey(DefaultStorageKeyAllocator & key) override { - VerifyOrReturnError(kUndefinedFabricIndex != fabric_index, CHIP_ERROR_INVALID_FABRIC_ID); - VerifyOrReturnError(kUndefinedFabricIndex != fabric_index, CHIP_ERROR_INVALID_KEY_ID); + VerifyOrReturnError(kUndefinedFabricIndex != fabric_index, CHIP_ERROR_INVALID_FABRIC_INDEX); + VerifyOrReturnError(kInvalidKeysetId != keyset_id, CHIP_ERROR_INVALID_KEY_ID); key.FabricKeyset(fabric_index, keyset_id); return CHIP_NO_ERROR; } @@ -746,7 +746,7 @@ struct KeySetData : PersistentData policy = GroupDataProvider::SecurityPolicy::kCacheAndSync; keys_count = 0; memset(operational_keys, 0x00, sizeof(operational_keys)); - next = 0xffff; + next = kInvalidKeysetId; } OperationalKey * GetCurrentKey() @@ -1397,7 +1397,7 @@ CHIP_ERROR GroupDataProviderImpl::RemoveEndpoints(chip::FabricIndex fabric_index FabricData fabric(fabric_index); GroupData group; - VerifyOrReturnError(CHIP_NO_ERROR == fabric.Load(mStorage), CHIP_ERROR_INVALID_FABRIC_ID); + VerifyOrReturnError(CHIP_NO_ERROR == fabric.Load(mStorage), CHIP_ERROR_INVALID_FABRIC_INDEX); VerifyOrReturnError(group.Find(mStorage, fabric, group_id), CHIP_ERROR_KEY_NOT_FOUND); EndpointData endpoint(fabric_index, group.group_id, group.first_endpoint); @@ -1523,7 +1523,7 @@ CHIP_ERROR GroupDataProviderImpl::RemoveGroupKeys(chip::FabricIndex fabric_index VerifyOrReturnError(IsInitialized(), CHIP_ERROR_INTERNAL); FabricData fabric(fabric_index); - VerifyOrReturnError(CHIP_NO_ERROR == fabric.Load(mStorage), CHIP_ERROR_INVALID_FABRIC_ID); + VerifyOrReturnError(CHIP_NO_ERROR == fabric.Load(mStorage), CHIP_ERROR_INVALID_FABRIC_INDEX); size_t count = 0; KeyMapData map(fabric_index, fabric.first_map); diff --git a/src/credentials/tests/TestGroupDataProvider.cpp b/src/credentials/tests/TestGroupDataProvider.cpp index a3b89aee141bd3..d2b59eedfde5e1 100644 --- a/src/credentials/tests/TestGroupDataProvider.cpp +++ b/src/credentials/tests/TestGroupDataProvider.cpp @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2021 Project CHIP Authors + * Copyright (c) 2021-2022 Project CHIP Authors * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -237,7 +237,7 @@ void TestGroupInfo(nlTestSuite * apSuite, void * apContext) // Get Group Info - NL_TEST_ASSERT(apSuite, CHIP_ERROR_INVALID_FABRIC_ID == provider->GetGroupInfoAt(kUndefinedFabricIndex, 0, group)); + NL_TEST_ASSERT(apSuite, CHIP_ERROR_INVALID_FABRIC_INDEX == provider->GetGroupInfoAt(kUndefinedFabricIndex, 0, group)); NL_TEST_ASSERT(apSuite, CHIP_ERROR_NOT_FOUND == provider->GetGroupInfoAt(kFabric2, 999, group)); NL_TEST_ASSERT(apSuite, sListener.latest == kGroupInfo2_3); @@ -583,7 +583,7 @@ void TestGroupKeys(nlTestSuite * apSuite, void * apContext) // Get Group Info - NL_TEST_ASSERT(apSuite, CHIP_ERROR_INVALID_FABRIC_ID == provider->GetGroupKeyAt(kUndefinedFabricIndex, 0, pair)); + NL_TEST_ASSERT(apSuite, CHIP_ERROR_INVALID_FABRIC_INDEX == provider->GetGroupKeyAt(kUndefinedFabricIndex, 0, pair)); NL_TEST_ASSERT(apSuite, CHIP_ERROR_NOT_FOUND == provider->GetGroupKeyAt(kFabric2, 999, pair)); NL_TEST_ASSERT(apSuite, CHIP_NO_ERROR == provider->GetGroupKeyAt(kFabric1, 3, pair)); diff --git a/src/lib/core/CHIPError.cpp b/src/lib/core/CHIPError.cpp index 8b7fb3ec87b40a..e7006ba8c0b70a 100644 --- a/src/lib/core/CHIPError.cpp +++ b/src/lib/core/CHIPError.cpp @@ -404,8 +404,8 @@ bool FormatCHIPError(char * buf, uint16_t bufSize, CHIP_ERROR err) case CHIP_ERROR_UNSOLICITED_MSG_NO_ORIGINATOR.AsInteger(): desc = "Unsolicited msg with originator bit clear"; break; - case CHIP_ERROR_INVALID_FABRIC_ID.AsInteger(): - desc = "Invalid Fabric Id"; + case CHIP_ERROR_INVALID_FABRIC_INDEX.AsInteger(): + desc = "Invalid Fabric Index"; break; case CHIP_ERROR_TOO_MANY_CONNECTIONS.AsInteger(): desc = "Too many connections"; diff --git a/src/lib/core/CHIPError.h b/src/lib/core/CHIPError.h index 1f87ab631f1526..52c5ff047dec6a 100644 --- a/src/lib/core/CHIPError.h +++ b/src/lib/core/CHIPError.h @@ -1448,13 +1448,13 @@ using CHIP_ERROR = ::chip::ChipError; #define CHIP_ERROR_UNSOLICITED_MSG_NO_ORIGINATOR CHIP_CORE_ERROR(0x70) /** - * @def CHIP_ERROR_INVALID_FABRIC_ID + * @def CHIP_ERROR_INVALID_FABRIC_INDEX * * @brief - * A fabric id is invalid. + * A fabric index is invalid. * */ -#define CHIP_ERROR_INVALID_FABRIC_ID CHIP_CORE_ERROR(0x71) +#define CHIP_ERROR_INVALID_FABRIC_INDEX CHIP_CORE_ERROR(0x71) /** * @def CHIP_ERROR_TOO_MANY_CONNECTIONS diff --git a/src/lib/core/DataModelTypes.h b/src/lib/core/DataModelTypes.h index f6e4d50cf40b8a..c6db07b306b902 100644 --- a/src/lib/core/DataModelTypes.h +++ b/src/lib/core/DataModelTypes.h @@ -49,6 +49,7 @@ constexpr FabricIndex kUndefinedFabricIndex = 0; constexpr EndpointId kInvalidEndpointId = 0xFFFF; constexpr EndpointId kRootEndpointId = 0; constexpr ListIndex kInvalidListIndex = 0xFFFF; // List index is a uint16 thus 0xFFFF is a invalid list index. +constexpr KeysetId kInvalidKeysetId = 0xFFFF; // These are MEIs, 0xFFFF is not a valid manufacturer code, // thus 0xFFFF'FFFF is not a valid MEI. diff --git a/src/lib/core/tests/TestCHIPErrorStr.cpp b/src/lib/core/tests/TestCHIPErrorStr.cpp index 5880f594d761aa..ba3101f3c8a4b7 100644 --- a/src/lib/core/tests/TestCHIPErrorStr.cpp +++ b/src/lib/core/tests/TestCHIPErrorStr.cpp @@ -161,7 +161,7 @@ static const CHIP_ERROR kTestElements[] = CHIP_ERROR_INVALID_PASE_CONFIGURATION, CHIP_ERROR_NO_COMMON_PASE_CONFIGURATIONS, CHIP_ERROR_UNSOLICITED_MSG_NO_ORIGINATOR, - CHIP_ERROR_INVALID_FABRIC_ID, + CHIP_ERROR_INVALID_FABRIC_INDEX, CHIP_ERROR_TOO_MANY_CONNECTIONS, CHIP_ERROR_SHUT_DOWN, CHIP_ERROR_CANCELLED,