Line data Source code
1 : /*
2 : *
3 : * Copyright (c) 2020-2022 Project CHIP Authors
4 : * Copyright (c) 2019 Google LLC.
5 : *
6 : * Licensed under the Apache License, Version 2.0 (the "License");
7 : * you may not use this file except in compliance with the License.
8 : * You may obtain a copy of the License at
9 : *
10 : * http://www.apache.org/licenses/LICENSE-2.0
11 : *
12 : * Unless required by applicable law or agreed to in writing, software
13 : * distributed under the License is distributed on an "AS IS" BASIS,
14 : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 : * See the License for the specific language governing permissions and
16 : * limitations under the License.
17 : */
18 : #include <lib/core/CHIPError.h>
19 :
20 : #include <lib/core/CHIPConfig.h>
21 : #include <lib/core/ErrorStr.h>
22 :
23 : namespace chip {
24 :
25 : /**
26 : * Register a text error formatter for CHIP core errors.
27 : */
28 48 : void RegisterCHIPLayerErrorFormatter()
29 : {
30 : static ErrorFormatter sCHIPErrorFormatter = { FormatCHIPError, nullptr };
31 :
32 48 : RegisterErrorFormatter(&sCHIPErrorFormatter);
33 48 : }
34 :
35 : /**
36 : * Given a CHIP error, returns a human-readable NULL-terminated C string
37 : * describing the error.
38 : *
39 : * @param[in] buf Buffer into which the error string will be placed.
40 : * @param[in] bufSize Size of the supplied buffer in bytes.
41 : * @param[in] err The error to be described.
42 : *
43 : * @return true If a description string was written into the supplied buffer.
44 : * @return false If the supplied error was not a CHIP error.
45 : *
46 : */
47 1136 : bool FormatCHIPError(char * buf, uint16_t bufSize, CHIP_ERROR err)
48 : {
49 1136 : const char * desc = nullptr;
50 :
51 1136 : if (!err.IsPart(ChipError::SdkPart::kCore))
52 : {
53 4 : return false;
54 : }
55 :
56 : #if !CHIP_CONFIG_SHORT_ERROR_STR
57 1132 : switch (err.AsInteger())
58 : {
59 4 : case CHIP_ERROR_SENDING_BLOCKED.AsInteger():
60 4 : desc = "Sending blocked";
61 4 : break;
62 7 : case CHIP_ERROR_CONNECTION_ABORTED.AsInteger():
63 7 : desc = "Connection aborted";
64 7 : break;
65 46 : case CHIP_ERROR_INCORRECT_STATE.AsInteger():
66 46 : desc = "Incorrect state";
67 46 : break;
68 4 : case CHIP_ERROR_MESSAGE_TOO_LONG.AsInteger():
69 4 : desc = "Message too long";
70 4 : break;
71 4 : case CHIP_ERROR_RECURSION_DEPTH_LIMIT.AsInteger():
72 4 : desc = "Recursion depth limit reached";
73 4 : break;
74 4 : case CHIP_ERROR_TOO_MANY_UNSOLICITED_MESSAGE_HANDLERS.AsInteger():
75 4 : desc = "Too many unsolicited message handlers";
76 4 : break;
77 4 : case CHIP_ERROR_NO_UNSOLICITED_MESSAGE_HANDLER.AsInteger():
78 4 : desc = "No unsolicited message handler";
79 4 : break;
80 4 : case CHIP_ERROR_NO_CONNECTION_HANDLER.AsInteger():
81 4 : desc = "No connection handler";
82 4 : break;
83 4 : case CHIP_ERROR_TOO_MANY_PEER_NODES.AsInteger():
84 4 : desc = "Too many peer nodes";
85 4 : break;
86 4 : case CHIP_ERROR_SENTINEL.AsInteger():
87 4 : desc = "Internal sentinel";
88 4 : break;
89 147 : case CHIP_ERROR_NO_MEMORY.AsInteger():
90 147 : desc = "No memory";
91 147 : break;
92 4 : case CHIP_ERROR_NO_MESSAGE_HANDLER.AsInteger():
93 4 : desc = "No message handler";
94 4 : break;
95 4 : case CHIP_ERROR_MESSAGE_INCOMPLETE.AsInteger():
96 4 : desc = "Message incomplete";
97 4 : break;
98 4 : case CHIP_ERROR_DATA_NOT_ALIGNED.AsInteger():
99 4 : desc = "Data not aligned";
100 4 : break;
101 4 : case CHIP_ERROR_UNKNOWN_KEY_TYPE.AsInteger():
102 4 : desc = "Unknown key type";
103 4 : break;
104 104 : case CHIP_ERROR_KEY_NOT_FOUND.AsInteger():
105 104 : desc = "Key not found";
106 104 : break;
107 4 : case CHIP_ERROR_WRONG_ENCRYPTION_TYPE.AsInteger():
108 4 : desc = "Wrong encryption type";
109 4 : break;
110 4 : case CHIP_ERROR_INVALID_UTF8.AsInteger():
111 4 : desc = "Character string is not a valid utf-8 encoding";
112 4 : break;
113 4 : case CHIP_ERROR_INTEGRITY_CHECK_FAILED.AsInteger():
114 4 : desc = "Integrity check failed";
115 4 : break;
116 4 : case CHIP_ERROR_INVALID_SIGNATURE.AsInteger():
117 4 : desc = "Invalid signature";
118 4 : break;
119 4 : case CHIP_ERROR_INVALID_TLV_CHAR_STRING.AsInteger():
120 4 : desc = "Invalid TLV Char string encoding.";
121 4 : break;
122 4 : case CHIP_ERROR_UNSUPPORTED_SIGNATURE_TYPE.AsInteger():
123 4 : desc = "Unsupported signature type";
124 4 : break;
125 4 : case CHIP_ERROR_INVALID_MESSAGE_LENGTH.AsInteger():
126 4 : desc = "Invalid message length";
127 4 : break;
128 64 : case CHIP_ERROR_BUFFER_TOO_SMALL.AsInteger():
129 64 : desc = "Buffer too small";
130 64 : break;
131 4 : case CHIP_ERROR_DUPLICATE_KEY_ID.AsInteger():
132 4 : desc = "Duplicate key id";
133 4 : break;
134 4 : case CHIP_ERROR_WRONG_KEY_TYPE.AsInteger():
135 4 : desc = "Wrong key type";
136 4 : break;
137 4 : case CHIP_ERROR_UNINITIALIZED.AsInteger():
138 4 : desc = "Uninitialized";
139 4 : break;
140 0 : case CHIP_ERROR_INVALID_IPK.AsInteger():
141 0 : desc = "Invalid IPK";
142 0 : break;
143 4 : case CHIP_ERROR_INVALID_STRING_LENGTH.AsInteger():
144 4 : desc = "Invalid string length";
145 4 : break;
146 4 : case CHIP_ERROR_INVALID_LIST_LENGTH.AsInteger():
147 4 : desc = "Invalid list length";
148 4 : break;
149 4 : case CHIP_ERROR_FAILED_DEVICE_ATTESTATION.AsInteger():
150 4 : desc = "Failed Device Attestation";
151 4 : break;
152 36 : case CHIP_END_OF_TLV.AsInteger():
153 36 : desc = "End of TLV";
154 36 : break;
155 4 : case CHIP_ERROR_TLV_UNDERRUN.AsInteger():
156 4 : desc = "TLV underrun";
157 4 : break;
158 4 : case CHIP_ERROR_INVALID_TLV_ELEMENT.AsInteger():
159 4 : desc = "Invalid TLV element";
160 4 : break;
161 4 : case CHIP_ERROR_INVALID_TLV_TAG.AsInteger():
162 4 : desc = "Invalid TLV tag";
163 4 : break;
164 4 : case CHIP_ERROR_UNKNOWN_IMPLICIT_TLV_TAG.AsInteger():
165 4 : desc = "Unknown implicit TLV tag";
166 4 : break;
167 4 : case CHIP_ERROR_WRONG_TLV_TYPE.AsInteger():
168 4 : desc = "Wrong TLV type";
169 4 : break;
170 4 : case CHIP_ERROR_TLV_CONTAINER_OPEN.AsInteger():
171 4 : desc = "TLV container open";
172 4 : break;
173 17 : case CHIP_ERROR_INVALID_MESSAGE_TYPE.AsInteger():
174 17 : desc = "Invalid message type";
175 17 : break;
176 9 : case CHIP_ERROR_UNEXPECTED_TLV_ELEMENT.AsInteger():
177 9 : desc = "Unexpected TLV element";
178 9 : break;
179 4 : case CHIP_ERROR_NOT_IMPLEMENTED.AsInteger():
180 4 : desc = "Not Implemented";
181 4 : break;
182 4 : case CHIP_ERROR_INVALID_ADDRESS.AsInteger():
183 4 : desc = "Invalid address";
184 4 : break;
185 33 : case CHIP_ERROR_INVALID_ARGUMENT.AsInteger():
186 33 : desc = "Invalid argument";
187 33 : break;
188 4 : case CHIP_ERROR_TLV_TAG_NOT_FOUND.AsInteger():
189 4 : desc = "TLV tag not found";
190 4 : break;
191 4 : case CHIP_ERROR_MISSING_SECURE_SESSION.AsInteger():
192 4 : desc = "Missing secure session";
193 4 : break;
194 4 : case CHIP_ERROR_INVALID_ADMIN_SUBJECT.AsInteger():
195 4 : desc = "CaseAdminSubject is not valid";
196 4 : break;
197 4 : case CHIP_ERROR_INSUFFICIENT_PRIVILEGE.AsInteger():
198 4 : desc = "Required privilege was insufficient during an operation";
199 4 : break;
200 4 : case CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_IB.AsInteger():
201 4 : desc = "Malformed Interacton Model Command Data IB";
202 4 : break;
203 4 : case CHIP_ERROR_INVALID_PATH_LIST.AsInteger():
204 4 : desc = "Invalid TLV path list";
205 4 : break;
206 4 : case CHIP_ERROR_INVALID_DATA_LIST.AsInteger():
207 4 : desc = "Invalid TLV data list";
208 4 : break;
209 4 : case CHIP_ERROR_TRANSACTION_CANCELED.AsInteger():
210 4 : desc = "Transaction canceled";
211 4 : break;
212 12 : case CHIP_ERROR_INVALID_SUBSCRIPTION.AsInteger():
213 12 : desc = "Invalid Subscription Id";
214 12 : break;
215 22 : case CHIP_ERROR_TIMEOUT.AsInteger():
216 22 : desc = "Timeout";
217 22 : break;
218 4 : case CHIP_ERROR_INVALID_DEVICE_DESCRIPTOR.AsInteger():
219 4 : desc = "Invalid device descriptor";
220 4 : break;
221 4 : case CHIP_ERROR_INVALID_PASE_PARAMETER.AsInteger():
222 4 : desc = "Invalid PASE parameter";
223 4 : break;
224 4 : case CHIP_ERROR_INVALID_USE_OF_SESSION_KEY.AsInteger():
225 4 : desc = "Invalid use of session key";
226 4 : break;
227 4 : case CHIP_ERROR_CONNECTION_CLOSED_UNEXPECTEDLY.AsInteger():
228 4 : desc = "Connection closed unexpectedly";
229 4 : break;
230 4 : case CHIP_ERROR_MISSING_TLV_ELEMENT.AsInteger():
231 4 : desc = "Missing TLV element";
232 4 : break;
233 4 : case CHIP_ERROR_RANDOM_DATA_UNAVAILABLE.AsInteger():
234 4 : desc = "Random data unavailable";
235 4 : break;
236 4 : case CHIP_ERROR_HOST_PORT_LIST_EMPTY.AsInteger():
237 4 : desc = "Host/port empty";
238 4 : break;
239 4 : case CHIP_ERROR_FORCED_RESET.AsInteger():
240 4 : desc = "Service manager forced reset";
241 4 : break;
242 4 : case CHIP_ERROR_NO_ENDPOINT.AsInteger():
243 4 : desc = "No endpoint was available to send the message";
244 4 : break;
245 4 : case CHIP_ERROR_INVALID_DESTINATION_NODE_ID.AsInteger():
246 4 : desc = "Invalid destination node id";
247 4 : break;
248 4 : case CHIP_ERROR_NOT_CONNECTED.AsInteger():
249 4 : desc = "Not connected";
250 4 : break;
251 4 : case CHIP_ERROR_CA_CERT_NOT_FOUND.AsInteger():
252 4 : desc = "CA certificate not found";
253 4 : break;
254 4 : case CHIP_ERROR_CERT_PATH_LEN_CONSTRAINT_EXCEEDED.AsInteger():
255 4 : desc = "Certificate path length constraint exceeded";
256 4 : break;
257 4 : case CHIP_ERROR_CERT_PATH_TOO_LONG.AsInteger():
258 4 : desc = "Certificate path too long";
259 4 : break;
260 4 : case CHIP_ERROR_CERT_USAGE_NOT_ALLOWED.AsInteger():
261 4 : desc = "Requested certificate usage is not allowed";
262 4 : break;
263 4 : case CHIP_ERROR_CERT_EXPIRED.AsInteger():
264 4 : desc = "Certificate expired";
265 4 : break;
266 4 : case CHIP_ERROR_CERT_NOT_VALID_YET.AsInteger():
267 4 : desc = "Certificate not yet valid";
268 4 : break;
269 4 : case CHIP_ERROR_UNSUPPORTED_CERT_FORMAT.AsInteger():
270 4 : desc = "Unsupported certificate format";
271 4 : break;
272 4 : case CHIP_ERROR_UNSUPPORTED_ELLIPTIC_CURVE.AsInteger():
273 4 : desc = "Unsupported elliptic curve";
274 4 : break;
275 4 : case CHIP_ERROR_CERT_NOT_FOUND.AsInteger():
276 4 : desc = "Certificate not found";
277 4 : break;
278 6 : case CHIP_ERROR_INVALID_CASE_PARAMETER.AsInteger():
279 6 : desc = "Invalid CASE parameter";
280 6 : break;
281 4 : case CHIP_ERROR_CERT_LOAD_FAILED.AsInteger():
282 4 : desc = "Unable to load certificate";
283 4 : break;
284 4 : case CHIP_ERROR_CERT_NOT_TRUSTED.AsInteger():
285 4 : desc = "Certificate not trusted";
286 4 : break;
287 4 : case CHIP_ERROR_WRONG_CERT_DN.AsInteger():
288 4 : desc = "Wrong certificate distinguished name";
289 4 : break;
290 4 : case CHIP_ERROR_WRONG_NODE_ID.AsInteger():
291 4 : desc = "Wrong node ID";
292 4 : break;
293 4 : case CHIP_ERROR_RETRANS_TABLE_FULL.AsInteger():
294 4 : desc = "Retransmit Table is already full";
295 4 : break;
296 46 : case CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE.AsInteger():
297 46 : desc = "Required feature not supported by this configuration";
298 46 : break;
299 6 : case CHIP_ERROR_UNSOLICITED_MSG_NO_ORIGINATOR.AsInteger():
300 6 : desc = "Unsolicited msg with originator bit clear";
301 6 : break;
302 4 : case CHIP_ERROR_INVALID_FABRIC_INDEX.AsInteger():
303 4 : desc = "Invalid Fabric Index";
304 4 : break;
305 4 : case CHIP_ERROR_TOO_MANY_CONNECTIONS.AsInteger():
306 4 : desc = "Too many connections";
307 4 : break;
308 4 : case CHIP_ERROR_SHUT_DOWN.AsInteger():
309 4 : desc = "The operation was cancelled because a shut down was initiated";
310 4 : break;
311 4 : case CHIP_ERROR_CANCELLED.AsInteger():
312 4 : desc = "The operation has been cancelled";
313 4 : break;
314 4 : case CHIP_ERROR_MESSAGE_COUNTER_EXHAUSTED.AsInteger():
315 4 : desc = "Message counter exhausted";
316 4 : break;
317 4 : case CHIP_ERROR_FABRIC_EXISTS.AsInteger():
318 4 : desc = "Trying to add a NOC for a fabric that already exists";
319 4 : break;
320 4 : case CHIP_ERROR_ENDPOINT_EXISTS.AsInteger():
321 4 : desc = "Trying to add dynamic endpoint that already exists";
322 4 : break;
323 4 : case CHIP_ERROR_WRONG_ENCRYPTION_TYPE_FROM_PEER.AsInteger():
324 4 : desc = "Wrong encryption type error code received from peer";
325 4 : break;
326 4 : case CHIP_ERROR_INVALID_KEY_ID.AsInteger():
327 4 : desc = "Invalid key identifier";
328 4 : break;
329 4 : case CHIP_ERROR_INVALID_TIME.AsInteger():
330 4 : desc = "Valid time value is not available";
331 4 : break;
332 4 : case CHIP_ERROR_SCHEMA_MISMATCH.AsInteger():
333 4 : desc = "Schema mismatch";
334 4 : break;
335 4 : case CHIP_ERROR_INVALID_INTEGER_VALUE.AsInteger():
336 4 : desc = "Invalid integer value";
337 4 : break;
338 7 : case CHIP_ERROR_BAD_REQUEST.AsInteger():
339 7 : desc = "Request cannot be processed or fulfilled";
340 7 : break;
341 4 : case CHIP_ERROR_WRONG_CERT_TYPE.AsInteger():
342 4 : desc = "Wrong certificate type";
343 4 : break;
344 4 : case CHIP_ERROR_PERSISTED_STORAGE_FAILED.AsInteger():
345 4 : desc = "Persisted storage failed";
346 4 : break;
347 6 : case CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND.AsInteger():
348 6 : desc = "Value not found in the persisted storage";
349 6 : break;
350 8 : case CHIP_ERROR_IM_FABRIC_DELETED.AsInteger():
351 8 : desc = "The fabric is deleted, and the corresponding IM resources are released";
352 8 : break;
353 4 : case CHIP_ERROR_IN_PROGRESS.AsInteger():
354 4 : desc = "The operation is still in progress";
355 4 : break;
356 5 : case CHIP_ERROR_ACCESS_DENIED.AsInteger():
357 5 : desc = "The CHIP message is not granted access";
358 5 : break;
359 4 : case CHIP_ERROR_UNKNOWN_RESOURCE_ID.AsInteger():
360 4 : desc = "Unknown resource ID";
361 4 : break;
362 4 : case CHIP_ERROR_VERSION_MISMATCH.AsInteger():
363 4 : desc = "Version mismatch";
364 4 : break;
365 4 : case CHIP_ERROR_ACCESS_RESTRICTED_BY_ARL.AsInteger():
366 4 : desc = "The CHIP message's access is restricted by ARL";
367 4 : break;
368 4 : case CHIP_EVENT_ID_FOUND.AsInteger():
369 4 : desc = "Event ID matching criteria was found";
370 4 : break;
371 104 : case CHIP_ERROR_INTERNAL.AsInteger():
372 104 : desc = "Internal error";
373 104 : break;
374 4 : case CHIP_ERROR_OPEN_FAILED.AsInteger():
375 4 : desc = "Open file failed";
376 4 : break;
377 4 : case CHIP_ERROR_READ_FAILED.AsInteger():
378 4 : desc = "Read from file failed";
379 4 : break;
380 4 : case CHIP_ERROR_WRITE_FAILED.AsInteger():
381 4 : desc = "Write to file failed";
382 4 : break;
383 4 : case CHIP_ERROR_DECODE_FAILED.AsInteger():
384 4 : desc = "Decoding failed";
385 4 : break;
386 4 : case CHIP_ERROR_MDNS_COLLISION.AsInteger():
387 4 : desc = "mDNS collision";
388 4 : break;
389 12 : case CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_PATH_IB.AsInteger():
390 12 : desc = "Malformed Interacton Model Attribute Path IB";
391 12 : break;
392 4 : case CHIP_ERROR_IM_MALFORMED_EVENT_PATH_IB.AsInteger():
393 4 : desc = "Malformed Interacton Model Event Path IB";
394 4 : break;
395 4 : case CHIP_ERROR_IM_MALFORMED_EVENT_DATA_IB.AsInteger():
396 4 : desc = "Malformed Interacton Model Event Data IB";
397 4 : break;
398 4 : case CHIP_ERROR_PEER_NODE_NOT_FOUND.AsInteger():
399 4 : desc = "Unable to find the peer node";
400 4 : break;
401 4 : case CHIP_ERROR_HSM.AsInteger():
402 4 : desc = "Hardware security module";
403 4 : break;
404 1 : case CHIP_ERROR_REAL_TIME_NOT_SYNCED.AsInteger():
405 1 : desc = "Real time not synchronized";
406 1 : break;
407 1 : case CHIP_ERROR_UNEXPECTED_EVENT.AsInteger():
408 1 : desc = "Unexpected event";
409 1 : break;
410 0 : case CHIP_ERROR_ENDPOINT_POOL_FULL.AsInteger():
411 0 : desc = "Endpoint pool full";
412 0 : break;
413 0 : case CHIP_ERROR_INBOUND_MESSAGE_TOO_BIG.AsInteger():
414 0 : desc = "Inbound message too big";
415 0 : break;
416 0 : case CHIP_ERROR_OUTBOUND_MESSAGE_TOO_BIG.AsInteger():
417 0 : desc = "Outbound message too big";
418 0 : break;
419 0 : case CHIP_ERROR_DUPLICATE_MESSAGE_RECEIVED.AsInteger():
420 0 : desc = "Duplicate message received";
421 0 : break;
422 0 : case CHIP_ERROR_INVALID_PUBLIC_KEY.AsInteger():
423 0 : desc = "Invalid public key";
424 0 : break;
425 0 : case CHIP_ERROR_FABRIC_MISMATCH_ON_ICA.AsInteger():
426 0 : desc = "Fabric mismatch on ICA";
427 0 : break;
428 0 : case CHIP_ERROR_NO_SHARED_TRUSTED_ROOT.AsInteger():
429 0 : desc = "No shared trusted root";
430 0 : break;
431 5 : case CHIP_ERROR_IM_STATUS_CODE_RECEIVED.AsInteger():
432 5 : desc = "Interaction Model Error";
433 5 : break;
434 4 : case CHIP_ERROR_IM_MALFORMED_DATA_VERSION_FILTER_IB.AsInteger():
435 4 : desc = "Malformed Interaction Model Data Version Filter IB";
436 4 : break;
437 5 : case CHIP_ERROR_NOT_FOUND.AsInteger():
438 5 : desc = "The item referenced in the function call was not found";
439 5 : break;
440 8 : case CHIP_ERROR_INVALID_FILE_IDENTIFIER.AsInteger():
441 8 : desc = "The file identifier, encoded in the first few bytes of a processed file, has unexpected value";
442 8 : break;
443 9 : case CHIP_ERROR_BUSY.AsInteger():
444 9 : desc = "The Resource is busy and cannot process the request";
445 9 : break;
446 4 : case CHIP_ERROR_MAX_RETRY_EXCEEDED.AsInteger():
447 4 : desc = "The maximum retry limit has been exceeded";
448 4 : break;
449 4 : case CHIP_ERROR_PROVIDER_LIST_EXHAUSTED.AsInteger():
450 4 : desc = "The provider list has been exhausted";
451 4 : break;
452 4 : case CHIP_ERROR_INVALID_SCHEME_PREFIX.AsInteger():
453 4 : desc = "The scheme field contains an invalid prefix";
454 4 : break;
455 4 : case CHIP_ERROR_MISSING_URI_SEPARATOR.AsInteger():
456 4 : desc = "The URI separator is missing";
457 4 : break;
458 4 : case CHIP_ERROR_HANDLER_NOT_SET.AsInteger():
459 4 : desc = "Callback function or callable object is not set";
460 4 : break;
461 : }
462 : #endif // !CHIP_CONFIG_SHORT_ERROR_STR
463 :
464 1132 : FormatError(buf, bufSize, "CHIP", err, desc);
465 :
466 1132 : return true;
467 : }
468 :
469 : } // namespace chip
|