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