Skip to content

Commit

Permalink
[IM] Remove the EMBER_ZCL_STATUS_DUPLICATE_EXISTS error code (project…
Browse files Browse the repository at this point in the history
…-chip#32017)

* Remove the EMBER_ZCL_STATUS_DUPLICATE_EXISTS error code

* fix comments
  • Loading branch information
jepenven-silabs authored and erwinpan1 committed Feb 13, 2024
1 parent 95e7dcb commit 5f513db
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 39 deletions.
1 change: 1 addition & 0 deletions docs/ERROR_CODES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` |
Expand Down
8 changes: 4 additions & 4 deletions examples/bridge-app/asr/subdevice/SubDeviceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,19 @@ int AddDeviceEndpoint(SubDevice * dev, EmberAfEndpointType * ep, const Span<cons
if (NULL == gSubDevices[index])
{
gSubDevices[index] = dev;
EmberAfStatus ret;
CHIP_ERROR err;
while (1)
{
dev->SetEndpointId(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;
}
Expand Down
8 changes: 4 additions & 4 deletions examples/bridge-app/esp32/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,19 +166,19 @@ int AddDeviceEndpoint(Device * dev, EmberAfEndpointType * ep, const Span<const E
if (NULL == gDevices[index])
{
gDevices[index] = dev;
EmberAfStatus ret;
CHIP_ERROR err;
while (true)
{
dev->SetEndpointId(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;
}
Expand Down
8 changes: 4 additions & 4 deletions examples/bridge-app/linux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,22 +259,22 @@ int AddDeviceEndpoint(Device * dev, EmberAfEndpointType * ep, const Span<const E
if (nullptr == gDevices[index])
{
gDevices[index] = dev;
EmberAfStatus ret;
CHIP_ERROR err;
while (true)
{
// Todo: Update this to schedule the work rather than use this lock
DeviceLayer::StackLock lock;
dev->SetEndpointId(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;
}
Expand Down
8 changes: 4 additions & 4 deletions examples/bridge-app/telink/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,19 +189,19 @@ int AddDeviceEndpoint(Device * dev, EmberAfEndpointType * ep, const Span<const E
if (NULL == gDevices[index])
{
gDevices[index] = dev;
EmberAfStatus ret;
CHIP_ERROR err;
while (true)
{
dev->SetEndpointId(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;
}
Expand Down
16 changes: 8 additions & 8 deletions src/app/app-platform/ContentAppPlatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
Expand Down Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion src/app/util/af-enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 8 additions & 8 deletions src/app/util/attribute-storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,33 +253,33 @@ uint16_t emberAfGetDynamicIndexFromEndpoint(EndpointId id)
return kEmberInvalidEndpointIndex;
}

EmberAfStatus emberAfSetDynamicEndpoint(uint16_t index, EndpointId id, const EmberAfEndpointType * ep,
const chip::Span<chip::DataVersion> & dataVersionStorage,
chip::Span<const EmberAfDeviceType> deviceTypeList, EndpointId parentEndpointId)
CHIP_ERROR emberAfSetDynamicEndpoint(uint16_t index, EndpointId id, const EmberAfEndpointType * ep,
const chip::Span<chip::DataVersion> & dataVersionStorage,
chip::Span<const EmberAfDeviceType> 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<uint16_t>(realIndex);
for (uint16_t i = FIXED_ENDPOINT_COUNT; i < MAX_ENDPOINT_COUNT; i++)
{
if (emAfEndpoints[i].endpoint == id)
{
return EMBER_ZCL_STATUS_DUPLICATE_EXISTS;
return CHIP_ERROR_ENDPOINT_EXISTS;
}
}

Expand Down Expand Up @@ -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)
Expand Down
13 changes: 9 additions & 4 deletions src/app/util/attribute-storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<chip::DataVersion> & dataVersionStorage,
chip::Span<const EmberAfDeviceType> 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<chip::DataVersion> & dataVersionStorage,
chip::Span<const EmberAfDeviceType> deviceTypeList = {},
chip::EndpointId parentEndpointId = chip::kInvalidEndpointId);
chip::EndpointId emberAfClearDynamicEndpoint(uint16_t index);
uint16_t emberAfGetDynamicIndexFromEndpoint(chip::EndpointId id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ - (void)registerMatterEndpoint
&_matterEndpointMetadata,
Span<DataVersion>(_matterDataVersions.get(), _matterEndpointMetadata.clusterCount),
Span<EmberAfDeviceType>(_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");
}

Expand Down
3 changes: 3 additions & 0 deletions src/lib/core/CHIPError.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 8 additions & 1 deletion src/lib/core/CHIPError.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/lib/core/tests/TestCHIPErrorStr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 5f513db

Please sign in to comment.