Skip to content

Commit acd5aa9

Browse files
jepenven-silabsraul-marquez-csa
authored andcommitted
[IM] Remove the EMBER_ZCL_STATUS_DUPLICATE_EXISTS error code (project-chip#32017)
* Remove the EMBER_ZCL_STATUS_DUPLICATE_EXISTS error code * fix comments
1 parent 6f2622e commit acd5aa9

File tree

13 files changed

+55
-39
lines changed

13 files changed

+55
-39
lines changed

docs/ERROR_CODES.md

+1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ This file was **AUTOMATICALLY** generated by
102102
| 121 | 0x79 | `CHIP_ERROR_INSUFFICIENT_PRIVILEGE` |
103103
| 125 | 0x7D | `CHIP_ERROR_MESSAGE_COUNTER_EXHAUSTED` |
104104
| 126 | 0x7E | `CHIP_ERROR_FABRIC_EXISTS` |
105+
| 127 | 0x7F | `CHIP_ERROR_ENDPOINT_EXISTS` |
105106
| 128 | 0x80 | `CHIP_ERROR_WRONG_ENCRYPTION_TYPE_FROM_PEER` |
106107
| 133 | 0x85 | `CHIP_ERROR_INVALID_KEY_ID` |
107108
| 134 | 0x86 | `CHIP_ERROR_INVALID_TIME` |

examples/bridge-app/asr/subdevice/SubDeviceManager.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,19 @@ int AddDeviceEndpoint(SubDevice * dev, EmberAfEndpointType * ep, const Span<cons
5656
if (NULL == gSubDevices[index])
5757
{
5858
gSubDevices[index] = dev;
59-
EmberAfStatus ret;
59+
CHIP_ERROR err;
6060
while (1)
6161
{
6262
dev->SetEndpointId(gCurrentEndpointId);
63-
ret =
63+
err =
6464
emberAfSetDynamicEndpoint(index, gCurrentEndpointId, ep, dataVersionStorage, deviceTypeList, parentEndpointId);
65-
if (ret == EMBER_ZCL_STATUS_SUCCESS)
65+
if (err == CHIP_NO_ERROR)
6666
{
6767
ChipLogProgress(DeviceLayer, "Added device %s to dynamic endpoint %d (index=%d)", dev->GetName(),
6868
gCurrentEndpointId, index);
6969
return index;
7070
}
71-
else if (ret != EMBER_ZCL_STATUS_DUPLICATE_EXISTS)
71+
else if (err != CHIP_ERROR_ENDPOINT_EXISTS)
7272
{
7373
return -1;
7474
}

examples/bridge-app/esp32/main/main.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -166,19 +166,19 @@ int AddDeviceEndpoint(Device * dev, EmberAfEndpointType * ep, const Span<const E
166166
if (NULL == gDevices[index])
167167
{
168168
gDevices[index] = dev;
169-
EmberAfStatus ret;
169+
CHIP_ERROR err;
170170
while (true)
171171
{
172172
dev->SetEndpointId(gCurrentEndpointId);
173-
ret =
173+
err =
174174
emberAfSetDynamicEndpoint(index, gCurrentEndpointId, ep, dataVersionStorage, deviceTypeList, parentEndpointId);
175-
if (ret == EMBER_ZCL_STATUS_SUCCESS)
175+
if (err == CHIP_NO_ERROR)
176176
{
177177
ChipLogProgress(DeviceLayer, "Added device %s to dynamic endpoint %d (index=%d)", dev->GetName(),
178178
gCurrentEndpointId, index);
179179
return index;
180180
}
181-
else if (ret != EMBER_ZCL_STATUS_DUPLICATE_EXISTS)
181+
else if (err != CHIP_ERROR_ENDPOINT_EXISTS)
182182
{
183183
return -1;
184184
}

examples/bridge-app/linux/main.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -259,22 +259,22 @@ int AddDeviceEndpoint(Device * dev, EmberAfEndpointType * ep, const Span<const E
259259
if (nullptr == gDevices[index])
260260
{
261261
gDevices[index] = dev;
262-
EmberAfStatus ret;
262+
CHIP_ERROR err;
263263
while (true)
264264
{
265265
// Todo: Update this to schedule the work rather than use this lock
266266
DeviceLayer::StackLock lock;
267267
dev->SetEndpointId(gCurrentEndpointId);
268268
dev->SetParentEndpointId(parentEndpointId);
269-
ret =
269+
err =
270270
emberAfSetDynamicEndpoint(index, gCurrentEndpointId, ep, dataVersionStorage, deviceTypeList, parentEndpointId);
271-
if (ret == EMBER_ZCL_STATUS_SUCCESS)
271+
if (err == CHIP_NO_ERROR)
272272
{
273273
ChipLogProgress(DeviceLayer, "Added device %s to dynamic endpoint %d (index=%d)", dev->GetName(),
274274
gCurrentEndpointId, index);
275275
return index;
276276
}
277-
if (ret != EMBER_ZCL_STATUS_DUPLICATE_EXISTS)
277+
if (err != CHIP_ERROR_ENDPOINT_EXISTS)
278278
{
279279
return -1;
280280
}

examples/bridge-app/telink/src/AppTask.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -189,19 +189,19 @@ int AddDeviceEndpoint(Device * dev, EmberAfEndpointType * ep, const Span<const E
189189
if (NULL == gDevices[index])
190190
{
191191
gDevices[index] = dev;
192-
EmberAfStatus ret;
192+
CHIP_ERROR err;
193193
while (true)
194194
{
195195
dev->SetEndpointId(gCurrentEndpointId);
196-
ret =
196+
err =
197197
emberAfSetDynamicEndpoint(index, gCurrentEndpointId, ep, dataVersionStorage, deviceTypeList, parentEndpointId);
198-
if (ret == EMBER_ZCL_STATUS_SUCCESS)
198+
if (err == CHIP_NO_ERROR)
199199
{
200200
ChipLogProgress(DeviceLayer, "Added device %s to dynamic endpoint %d (index=%d)", dev->GetName(),
201201
gCurrentEndpointId, index);
202202
return index;
203203
}
204-
else if (ret != EMBER_ZCL_STATUS_DUPLICATE_EXISTS)
204+
else if (err != CHIP_ERROR_ENDPOINT_EXISTS)
205205
{
206206
return -1;
207207
}

src/app/app-platform/ContentAppPlatform.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,13 @@ EndpointId ContentAppPlatform::AddContentApp(ContentApp * app, EmberAfEndpointTy
136136
index++;
137137
continue;
138138
}
139-
EmberAfStatus ret;
139+
CHIP_ERROR err;
140140
EndpointId initEndpointId = mCurrentEndpointId;
141141

142142
do
143143
{
144-
ret = emberAfSetDynamicEndpoint(index, mCurrentEndpointId, ep, dataVersionStorage, deviceTypeList);
145-
if (ret == EMBER_ZCL_STATUS_SUCCESS)
144+
err = emberAfSetDynamicEndpoint(index, mCurrentEndpointId, ep, dataVersionStorage, deviceTypeList);
145+
if (err == CHIP_NO_ERROR)
146146
{
147147
ChipLogProgress(DeviceLayer, "Added ContentApp %s to dynamic endpoint %d (index=%d)", vendorApp.applicationId,
148148
mCurrentEndpointId, index);
@@ -151,9 +151,9 @@ EndpointId ContentAppPlatform::AddContentApp(ContentApp * app, EmberAfEndpointTy
151151
IncrementCurrentEndpointID();
152152
return app->GetEndpointId();
153153
}
154-
else if (ret != EMBER_ZCL_STATUS_DUPLICATE_EXISTS)
154+
else if (err != CHIP_ERROR_ENDPOINT_EXISTS)
155155
{
156-
ChipLogError(DeviceLayer, "Adding ContentApp error=%d", ret);
156+
ChipLogError(DeviceLayer, "Adding ContentApp error=%" CHIP_ERROR_FORMAT, err.Format());
157157
return kNoCurrentEndpointId;
158158
}
159159
IncrementCurrentEndpointID();
@@ -202,10 +202,10 @@ EndpointId ContentAppPlatform::AddContentApp(ContentApp * app, EmberAfEndpointTy
202202
index++;
203203
continue;
204204
}
205-
EmberAfStatus ret = emberAfSetDynamicEndpoint(index, desiredEndpointId, ep, dataVersionStorage, deviceTypeList);
206-
if (ret != EMBER_ZCL_STATUS_SUCCESS)
205+
CHIP_ERROR err = emberAfSetDynamicEndpoint(index, desiredEndpointId, ep, dataVersionStorage, deviceTypeList);
206+
if (err != CHIP_NO_ERROR)
207207
{
208-
ChipLogError(DeviceLayer, "Adding ContentApp error=%d", ret);
208+
ChipLogError(DeviceLayer, "Adding ContentApp error : %" CHIP_ERROR_FORMAT, err.Format());
209209
return kNoCurrentEndpointId;
210210
}
211211
ChipLogProgress(DeviceLayer, "Added ContentApp %s to dynamic endpoint %d (index=%d)", vendorApp.applicationId,

src/app/util/af-enums.h

-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ enum EmberAfStatus : uint8_t
3939
EMBER_ZCL_STATUS_CONSTRAINT_ERROR = 0x87,
4040
EMBER_ZCL_STATUS_UNSUPPORTED_WRITE = 0x88,
4141
EMBER_ZCL_STATUS_RESOURCE_EXHAUSTED = 0x89,
42-
EMBER_ZCL_STATUS_DUPLICATE_EXISTS = 0x8A,
4342
EMBER_ZCL_STATUS_NOT_FOUND = 0x8B,
4443
EMBER_ZCL_STATUS_UNREPORTABLE_ATTRIBUTE = 0x8C,
4544
EMBER_ZCL_STATUS_INVALID_DATA_TYPE = 0x8D,

src/app/util/attribute-storage.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -253,33 +253,33 @@ uint16_t emberAfGetDynamicIndexFromEndpoint(EndpointId id)
253253
return kEmberInvalidEndpointIndex;
254254
}
255255

256-
EmberAfStatus emberAfSetDynamicEndpoint(uint16_t index, EndpointId id, const EmberAfEndpointType * ep,
257-
const chip::Span<chip::DataVersion> & dataVersionStorage,
258-
chip::Span<const EmberAfDeviceType> deviceTypeList, EndpointId parentEndpointId)
256+
CHIP_ERROR emberAfSetDynamicEndpoint(uint16_t index, EndpointId id, const EmberAfEndpointType * ep,
257+
const chip::Span<chip::DataVersion> & dataVersionStorage,
258+
chip::Span<const EmberAfDeviceType> deviceTypeList, EndpointId parentEndpointId)
259259
{
260260
auto realIndex = index + FIXED_ENDPOINT_COUNT;
261261

262262
if (realIndex >= MAX_ENDPOINT_COUNT)
263263
{
264-
return EMBER_ZCL_STATUS_RESOURCE_EXHAUSTED;
264+
return CHIP_ERROR_NO_MEMORY;
265265
}
266266
if (id == kInvalidEndpointId)
267267
{
268-
return EMBER_ZCL_STATUS_CONSTRAINT_ERROR;
268+
return CHIP_ERROR_INVALID_ARGUMENT;
269269
}
270270

271271
auto serverClusterCount = emberAfClusterCountForEndpointType(ep, /* server = */ true);
272272
if (dataVersionStorage.size() < serverClusterCount)
273273
{
274-
return EMBER_ZCL_STATUS_RESOURCE_EXHAUSTED;
274+
return CHIP_ERROR_NO_MEMORY;
275275
}
276276

277277
index = static_cast<uint16_t>(realIndex);
278278
for (uint16_t i = FIXED_ENDPOINT_COUNT; i < MAX_ENDPOINT_COUNT; i++)
279279
{
280280
if (emAfEndpoints[i].endpoint == id)
281281
{
282-
return EMBER_ZCL_STATUS_DUPLICATE_EXISTS;
282+
return CHIP_ERROR_ENDPOINT_EXISTS;
283283
}
284284
}
285285

@@ -307,7 +307,7 @@ EmberAfStatus emberAfSetDynamicEndpoint(uint16_t index, EndpointId id, const Emb
307307
// Now enable the endpoint.
308308
emberAfEndpointEnableDisable(id, true);
309309

310-
return EMBER_ZCL_STATUS_SUCCESS;
310+
return CHIP_NO_ERROR;
311311
}
312312

313313
EndpointId emberAfClearDynamicEndpoint(uint16_t index)

src/app/util/attribute-storage.h

+9-4
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,15 @@ CHIP_ERROR SetTagList(chip::EndpointId endpoint,
190190
//
191191
// An optional parent endpoint id should be passed for child endpoints of composed device.
192192
//
193-
EmberAfStatus emberAfSetDynamicEndpoint(uint16_t index, chip::EndpointId id, const EmberAfEndpointType * ep,
194-
const chip::Span<chip::DataVersion> & dataVersionStorage,
195-
chip::Span<const EmberAfDeviceType> deviceTypeList = {},
196-
chip::EndpointId parentEndpointId = chip::kInvalidEndpointId);
193+
// Returns CHIP_NO_ERROR No error.
194+
// CHIP_ERROR_NO_MEMORY MAX_ENDPOINT_COUNT is reached or when no storage is left for clusters
195+
// CHIP_ERROR_INVALID_ARGUMENT The EndpointId value passed is kInvalidEndpointId
196+
// CHIP_ERROR_ENDPOINT_EXISTS If the EndpointId value passed already exists
197+
//
198+
CHIP_ERROR emberAfSetDynamicEndpoint(uint16_t index, chip::EndpointId id, const EmberAfEndpointType * ep,
199+
const chip::Span<chip::DataVersion> & dataVersionStorage,
200+
chip::Span<const EmberAfDeviceType> deviceTypeList = {},
201+
chip::EndpointId parentEndpointId = chip::kInvalidEndpointId);
197202
chip::EndpointId emberAfClearDynamicEndpoint(uint16_t index);
198203
uint16_t emberAfGetDynamicIndexFromEndpoint(chip::EndpointId id);
199204

src/darwin/Framework/CHIP/ServerEndpoint/MTRServerEndpoint.mm

+1-1
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ - (void)registerMatterEndpoint
347347
&_matterEndpointMetadata,
348348
Span<DataVersion>(_matterDataVersions.get(), _matterEndpointMetadata.clusterCount),
349349
Span<EmberAfDeviceType>(_matterDeviceTypes.get(), _deviceTypes.count));
350-
if (status != EMBER_ZCL_STATUS_SUCCESS) {
350+
if (status != CHIP_NO_ERROR) {
351351
MTR_LOG_ERROR("Unexpected failure to define our Matter endpoint");
352352
}
353353

src/lib/core/CHIPError.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,9 @@ bool FormatCHIPError(char * buf, uint16_t bufSize, CHIP_ERROR err)
320320
case CHIP_ERROR_FABRIC_EXISTS.AsInteger():
321321
desc = "Trying to add a NOC for a fabric that already exists";
322322
break;
323+
case CHIP_ERROR_ENDPOINT_EXISTS.AsInteger():
324+
desc = "Trying to add dynamic endpoint that already exists";
325+
break;
323326
case CHIP_ERROR_WRONG_ENCRYPTION_TYPE_FROM_PEER.AsInteger():
324327
desc = "Wrong encryption type error code received from peer";
325328
break;

src/lib/core/CHIPError.h

+8-1
Original file line numberDiff line numberDiff line change
@@ -1259,7 +1259,14 @@ using CHIP_ERROR = ::chip::ChipError;
12591259
*/
12601260
#define CHIP_ERROR_FABRIC_EXISTS CHIP_CORE_ERROR(0x7e)
12611261

1262-
// AVAILABLE: 0x7f
1262+
/**
1263+
* @def CHIP_ERROR_ENDPOINT_EXISTS
1264+
*
1265+
* @brief
1266+
* The endpoint with the given endpoint id already exists.
1267+
*
1268+
*/
1269+
#define CHIP_ERROR_ENDPOINT_EXISTS CHIP_CORE_ERROR(0x7f)
12631270

12641271
/**
12651272
* @def CHIP_ERROR_WRONG_ENCRYPTION_TYPE_FROM_PEER

src/lib/core/tests/TestCHIPErrorStr.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ static const CHIP_ERROR kTestElements[] =
134134
CHIP_ERROR_INSUFFICIENT_PRIVILEGE,
135135
CHIP_ERROR_MESSAGE_COUNTER_EXHAUSTED,
136136
CHIP_ERROR_FABRIC_EXISTS,
137+
CHIP_ERROR_ENDPOINT_EXISTS,
137138
CHIP_ERROR_WRONG_ENCRYPTION_TYPE_FROM_PEER,
138139
CHIP_ERROR_INVALID_KEY_ID,
139140
CHIP_ERROR_INVALID_TIME,

0 commit comments

Comments
 (0)