From 2a8b3258ce0ff930acb6f4515da2614562bb110d Mon Sep 17 00:00:00 2001 From: Jean-Francois Penven <67962328+jepenven-silabs@users.noreply.github.com> Date: Fri, 9 Feb 2024 01:25:50 -0500 Subject: [PATCH] [IM] Remove the EMBER_ZCL_STATUS_DUPLICATE_EXISTS error code (#32017) * Remove the EMBER_ZCL_STATUS_DUPLICATE_EXISTS error code * fix comments --- docs/ERROR_CODES.md | 1 + .../asr/subdevice/SubDeviceManager.cpp | 8 ++++---- examples/bridge-app/esp32/main/main.cpp | 8 ++++---- examples/bridge-app/linux/main.cpp | 8 ++++---- examples/bridge-app/telink/src/AppTask.cpp | 8 ++++---- src/app/app-platform/ContentAppPlatform.cpp | 16 ++++++++-------- src/app/util/af-enums.h | 1 - src/app/util/attribute-storage.cpp | 16 ++++++++-------- src/app/util/attribute-storage.h | 13 +++++++++---- .../CHIP/ServerEndpoint/MTRServerEndpoint.mm | 2 +- src/lib/core/CHIPError.cpp | 3 +++ src/lib/core/CHIPError.h | 9 ++++++++- src/lib/core/tests/TestCHIPErrorStr.cpp | 1 + 13 files changed, 55 insertions(+), 39 deletions(-) diff --git a/docs/ERROR_CODES.md b/docs/ERROR_CODES.md index 8cd4a4c80940e3..122d188f8e0f70 100644 --- a/docs/ERROR_CODES.md +++ b/docs/ERROR_CODES.md @@ -102,6 +102,7 @@ This file was **AUTOMATICALLY** generated by | 121 | 0x79 | `CHIP_ERROR_INSUFFICIENT_PRIVILEGE` | | 125 | 0x7D | `CHIP_ERROR_MESSAGE_COUNTER_EXHAUSTED` | | 126 | 0x7E | `CHIP_ERROR_FABRIC_EXISTS` | +| 127 | 0x7F | `CHIP_ERROR_ENDPOINT_EXISTS` | | 128 | 0x80 | `CHIP_ERROR_WRONG_ENCRYPTION_TYPE_FROM_PEER` | | 133 | 0x85 | `CHIP_ERROR_INVALID_KEY_ID` | | 134 | 0x86 | `CHIP_ERROR_INVALID_TIME` | diff --git a/examples/bridge-app/asr/subdevice/SubDeviceManager.cpp b/examples/bridge-app/asr/subdevice/SubDeviceManager.cpp index caa4690eb0e25c..72fbcc663d8582 100644 --- a/examples/bridge-app/asr/subdevice/SubDeviceManager.cpp +++ b/examples/bridge-app/asr/subdevice/SubDeviceManager.cpp @@ -56,19 +56,19 @@ int AddDeviceEndpoint(SubDevice * dev, EmberAfEndpointType * ep, const SpanSetEndpointId(gCurrentEndpointId); - ret = + err = emberAfSetDynamicEndpoint(index, gCurrentEndpointId, ep, dataVersionStorage, deviceTypeList, parentEndpointId); - if (ret == EMBER_ZCL_STATUS_SUCCESS) + if (err == CHIP_NO_ERROR) { ChipLogProgress(DeviceLayer, "Added device %s to dynamic endpoint %d (index=%d)", dev->GetName(), gCurrentEndpointId, index); return index; } - else if (ret != EMBER_ZCL_STATUS_DUPLICATE_EXISTS) + else if (err != CHIP_ERROR_ENDPOINT_EXISTS) { return -1; } diff --git a/examples/bridge-app/esp32/main/main.cpp b/examples/bridge-app/esp32/main/main.cpp index 41bca07f6fc9df..92298a488c3186 100644 --- a/examples/bridge-app/esp32/main/main.cpp +++ b/examples/bridge-app/esp32/main/main.cpp @@ -166,19 +166,19 @@ int AddDeviceEndpoint(Device * dev, EmberAfEndpointType * ep, const SpanSetEndpointId(gCurrentEndpointId); - ret = + err = emberAfSetDynamicEndpoint(index, gCurrentEndpointId, ep, dataVersionStorage, deviceTypeList, parentEndpointId); - if (ret == EMBER_ZCL_STATUS_SUCCESS) + if (err == CHIP_NO_ERROR) { ChipLogProgress(DeviceLayer, "Added device %s to dynamic endpoint %d (index=%d)", dev->GetName(), gCurrentEndpointId, index); return index; } - else if (ret != EMBER_ZCL_STATUS_DUPLICATE_EXISTS) + else if (err != CHIP_ERROR_ENDPOINT_EXISTS) { return -1; } diff --git a/examples/bridge-app/linux/main.cpp b/examples/bridge-app/linux/main.cpp index 59f1514504c478..2c825fe8e5e010 100644 --- a/examples/bridge-app/linux/main.cpp +++ b/examples/bridge-app/linux/main.cpp @@ -259,22 +259,22 @@ int AddDeviceEndpoint(Device * dev, EmberAfEndpointType * ep, const SpanSetEndpointId(gCurrentEndpointId); dev->SetParentEndpointId(parentEndpointId); - ret = + err = emberAfSetDynamicEndpoint(index, gCurrentEndpointId, ep, dataVersionStorage, deviceTypeList, parentEndpointId); - if (ret == EMBER_ZCL_STATUS_SUCCESS) + if (err == CHIP_NO_ERROR) { ChipLogProgress(DeviceLayer, "Added device %s to dynamic endpoint %d (index=%d)", dev->GetName(), gCurrentEndpointId, index); return index; } - if (ret != EMBER_ZCL_STATUS_DUPLICATE_EXISTS) + if (err != CHIP_ERROR_ENDPOINT_EXISTS) { return -1; } diff --git a/examples/bridge-app/telink/src/AppTask.cpp b/examples/bridge-app/telink/src/AppTask.cpp index f5593247b976a9..3b4066bd87c2c7 100644 --- a/examples/bridge-app/telink/src/AppTask.cpp +++ b/examples/bridge-app/telink/src/AppTask.cpp @@ -189,19 +189,19 @@ int AddDeviceEndpoint(Device * dev, EmberAfEndpointType * ep, const SpanSetEndpointId(gCurrentEndpointId); - ret = + err = emberAfSetDynamicEndpoint(index, gCurrentEndpointId, ep, dataVersionStorage, deviceTypeList, parentEndpointId); - if (ret == EMBER_ZCL_STATUS_SUCCESS) + if (err == CHIP_NO_ERROR) { ChipLogProgress(DeviceLayer, "Added device %s to dynamic endpoint %d (index=%d)", dev->GetName(), gCurrentEndpointId, index); return index; } - else if (ret != EMBER_ZCL_STATUS_DUPLICATE_EXISTS) + else if (err != CHIP_ERROR_ENDPOINT_EXISTS) { return -1; } diff --git a/src/app/app-platform/ContentAppPlatform.cpp b/src/app/app-platform/ContentAppPlatform.cpp index fa720418264739..bb4638c45d95ba 100644 --- a/src/app/app-platform/ContentAppPlatform.cpp +++ b/src/app/app-platform/ContentAppPlatform.cpp @@ -136,13 +136,13 @@ EndpointId ContentAppPlatform::AddContentApp(ContentApp * app, EmberAfEndpointTy index++; continue; } - EmberAfStatus ret; + CHIP_ERROR err; EndpointId initEndpointId = mCurrentEndpointId; do { - ret = emberAfSetDynamicEndpoint(index, mCurrentEndpointId, ep, dataVersionStorage, deviceTypeList); - if (ret == EMBER_ZCL_STATUS_SUCCESS) + err = emberAfSetDynamicEndpoint(index, mCurrentEndpointId, ep, dataVersionStorage, deviceTypeList); + if (err == CHIP_NO_ERROR) { ChipLogProgress(DeviceLayer, "Added ContentApp %s to dynamic endpoint %d (index=%d)", vendorApp.applicationId, mCurrentEndpointId, index); @@ -151,9 +151,9 @@ EndpointId ContentAppPlatform::AddContentApp(ContentApp * app, EmberAfEndpointTy IncrementCurrentEndpointID(); return app->GetEndpointId(); } - else if (ret != EMBER_ZCL_STATUS_DUPLICATE_EXISTS) + else if (err != CHIP_ERROR_ENDPOINT_EXISTS) { - ChipLogError(DeviceLayer, "Adding ContentApp error=%d", ret); + ChipLogError(DeviceLayer, "Adding ContentApp error=%" CHIP_ERROR_FORMAT, err.Format()); return kNoCurrentEndpointId; } IncrementCurrentEndpointID(); @@ -202,10 +202,10 @@ EndpointId ContentAppPlatform::AddContentApp(ContentApp * app, EmberAfEndpointTy index++; continue; } - EmberAfStatus ret = emberAfSetDynamicEndpoint(index, desiredEndpointId, ep, dataVersionStorage, deviceTypeList); - if (ret != EMBER_ZCL_STATUS_SUCCESS) + CHIP_ERROR err = emberAfSetDynamicEndpoint(index, desiredEndpointId, ep, dataVersionStorage, deviceTypeList); + if (err != CHIP_NO_ERROR) { - ChipLogError(DeviceLayer, "Adding ContentApp error=%d", ret); + ChipLogError(DeviceLayer, "Adding ContentApp error : %" CHIP_ERROR_FORMAT, err.Format()); return kNoCurrentEndpointId; } ChipLogProgress(DeviceLayer, "Added ContentApp %s to dynamic endpoint %d (index=%d)", vendorApp.applicationId, diff --git a/src/app/util/af-enums.h b/src/app/util/af-enums.h index 3bb5745e43cc87..4a5df28eec34c7 100644 --- a/src/app/util/af-enums.h +++ b/src/app/util/af-enums.h @@ -39,7 +39,6 @@ enum EmberAfStatus : uint8_t EMBER_ZCL_STATUS_CONSTRAINT_ERROR = 0x87, EMBER_ZCL_STATUS_UNSUPPORTED_WRITE = 0x88, EMBER_ZCL_STATUS_RESOURCE_EXHAUSTED = 0x89, - EMBER_ZCL_STATUS_DUPLICATE_EXISTS = 0x8A, EMBER_ZCL_STATUS_NOT_FOUND = 0x8B, EMBER_ZCL_STATUS_UNREPORTABLE_ATTRIBUTE = 0x8C, EMBER_ZCL_STATUS_INVALID_DATA_TYPE = 0x8D, diff --git a/src/app/util/attribute-storage.cpp b/src/app/util/attribute-storage.cpp index 9b9129f1b018a1..43f86843f187c2 100644 --- a/src/app/util/attribute-storage.cpp +++ b/src/app/util/attribute-storage.cpp @@ -253,25 +253,25 @@ uint16_t emberAfGetDynamicIndexFromEndpoint(EndpointId id) return kEmberInvalidEndpointIndex; } -EmberAfStatus emberAfSetDynamicEndpoint(uint16_t index, EndpointId id, const EmberAfEndpointType * ep, - const chip::Span & dataVersionStorage, - chip::Span deviceTypeList, EndpointId parentEndpointId) +CHIP_ERROR emberAfSetDynamicEndpoint(uint16_t index, EndpointId id, const EmberAfEndpointType * ep, + const chip::Span & dataVersionStorage, + chip::Span deviceTypeList, EndpointId parentEndpointId) { auto realIndex = index + FIXED_ENDPOINT_COUNT; if (realIndex >= MAX_ENDPOINT_COUNT) { - return EMBER_ZCL_STATUS_RESOURCE_EXHAUSTED; + return CHIP_ERROR_NO_MEMORY; } if (id == kInvalidEndpointId) { - return EMBER_ZCL_STATUS_CONSTRAINT_ERROR; + return CHIP_ERROR_INVALID_ARGUMENT; } auto serverClusterCount = emberAfClusterCountForEndpointType(ep, /* server = */ true); if (dataVersionStorage.size() < serverClusterCount) { - return EMBER_ZCL_STATUS_RESOURCE_EXHAUSTED; + return CHIP_ERROR_NO_MEMORY; } index = static_cast(realIndex); @@ -279,7 +279,7 @@ EmberAfStatus emberAfSetDynamicEndpoint(uint16_t index, EndpointId id, const Emb { if (emAfEndpoints[i].endpoint == id) { - return EMBER_ZCL_STATUS_DUPLICATE_EXISTS; + return CHIP_ERROR_ENDPOINT_EXISTS; } } @@ -307,7 +307,7 @@ EmberAfStatus emberAfSetDynamicEndpoint(uint16_t index, EndpointId id, const Emb // Now enable the endpoint. emberAfEndpointEnableDisable(id, true); - return EMBER_ZCL_STATUS_SUCCESS; + return CHIP_NO_ERROR; } EndpointId emberAfClearDynamicEndpoint(uint16_t index) diff --git a/src/app/util/attribute-storage.h b/src/app/util/attribute-storage.h index 210e327aaad977..abc04021fb0a9a 100644 --- a/src/app/util/attribute-storage.h +++ b/src/app/util/attribute-storage.h @@ -190,10 +190,15 @@ CHIP_ERROR SetTagList(chip::EndpointId endpoint, // // An optional parent endpoint id should be passed for child endpoints of composed device. // -EmberAfStatus emberAfSetDynamicEndpoint(uint16_t index, chip::EndpointId id, const EmberAfEndpointType * ep, - const chip::Span & dataVersionStorage, - chip::Span deviceTypeList = {}, - chip::EndpointId parentEndpointId = chip::kInvalidEndpointId); +// Returns CHIP_NO_ERROR No error. +// CHIP_ERROR_NO_MEMORY MAX_ENDPOINT_COUNT is reached or when no storage is left for clusters +// CHIP_ERROR_INVALID_ARGUMENT The EndpointId value passed is kInvalidEndpointId +// CHIP_ERROR_ENDPOINT_EXISTS If the EndpointId value passed already exists +// +CHIP_ERROR emberAfSetDynamicEndpoint(uint16_t index, chip::EndpointId id, const EmberAfEndpointType * ep, + const chip::Span & dataVersionStorage, + chip::Span deviceTypeList = {}, + chip::EndpointId parentEndpointId = chip::kInvalidEndpointId); chip::EndpointId emberAfClearDynamicEndpoint(uint16_t index); uint16_t emberAfGetDynamicIndexFromEndpoint(chip::EndpointId id); diff --git a/src/darwin/Framework/CHIP/ServerEndpoint/MTRServerEndpoint.mm b/src/darwin/Framework/CHIP/ServerEndpoint/MTRServerEndpoint.mm index 5e6df865115be6..256528384b58fd 100644 --- a/src/darwin/Framework/CHIP/ServerEndpoint/MTRServerEndpoint.mm +++ b/src/darwin/Framework/CHIP/ServerEndpoint/MTRServerEndpoint.mm @@ -347,7 +347,7 @@ - (void)registerMatterEndpoint &_matterEndpointMetadata, Span(_matterDataVersions.get(), _matterEndpointMetadata.clusterCount), Span(_matterDeviceTypes.get(), _deviceTypes.count)); - if (status != EMBER_ZCL_STATUS_SUCCESS) { + if (status != CHIP_NO_ERROR) { MTR_LOG_ERROR("Unexpected failure to define our Matter endpoint"); } diff --git a/src/lib/core/CHIPError.cpp b/src/lib/core/CHIPError.cpp index 565e1b065b5c4c..64f10daa48b2c5 100644 --- a/src/lib/core/CHIPError.cpp +++ b/src/lib/core/CHIPError.cpp @@ -320,6 +320,9 @@ bool FormatCHIPError(char * buf, uint16_t bufSize, CHIP_ERROR err) case CHIP_ERROR_FABRIC_EXISTS.AsInteger(): desc = "Trying to add a NOC for a fabric that already exists"; break; + case CHIP_ERROR_ENDPOINT_EXISTS.AsInteger(): + desc = "Trying to add dynamic endpoint that already exists"; + break; case CHIP_ERROR_WRONG_ENCRYPTION_TYPE_FROM_PEER.AsInteger(): desc = "Wrong encryption type error code received from peer"; break; diff --git a/src/lib/core/CHIPError.h b/src/lib/core/CHIPError.h index da3af4c29e681d..4e4808e88b3d39 100644 --- a/src/lib/core/CHIPError.h +++ b/src/lib/core/CHIPError.h @@ -1259,7 +1259,14 @@ using CHIP_ERROR = ::chip::ChipError; */ #define CHIP_ERROR_FABRIC_EXISTS CHIP_CORE_ERROR(0x7e) -// AVAILABLE: 0x7f +/** + * @def CHIP_ERROR_ENDPOINT_EXISTS + * + * @brief + * The endpoint with the given endpoint id already exists. + * + */ +#define CHIP_ERROR_ENDPOINT_EXISTS CHIP_CORE_ERROR(0x7f) /** * @def CHIP_ERROR_WRONG_ENCRYPTION_TYPE_FROM_PEER diff --git a/src/lib/core/tests/TestCHIPErrorStr.cpp b/src/lib/core/tests/TestCHIPErrorStr.cpp index 08c0f19199e257..06ba1c8040f8d1 100644 --- a/src/lib/core/tests/TestCHIPErrorStr.cpp +++ b/src/lib/core/tests/TestCHIPErrorStr.cpp @@ -134,6 +134,7 @@ static const CHIP_ERROR kTestElements[] = CHIP_ERROR_INSUFFICIENT_PRIVILEGE, CHIP_ERROR_MESSAGE_COUNTER_EXHAUSTED, CHIP_ERROR_FABRIC_EXISTS, + CHIP_ERROR_ENDPOINT_EXISTS, CHIP_ERROR_WRONG_ENCRYPTION_TYPE_FROM_PEER, CHIP_ERROR_INVALID_KEY_ID, CHIP_ERROR_INVALID_TIME,