3 * Copyright (c) 2020 Project CHIP Authors
4 * Copyright (c) 2019 Google LLC.
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * This file contains functions for working with CHIP errors.
26 #include <core/CHIPCore.h>
27 #include <support/ErrorStr.h>
32 * Register a text error formatter for CHIP core errors.
34 void RegisterCHIPLayerErrorFormatter()
36 static ErrorFormatter sCHIPErrorFormatter = { FormatCHIPError, nullptr };
38 RegisterErrorFormatter(&sCHIPErrorFormatter);
42 * Given a CHIP error, returns a human-readable NULL-terminated C string
43 * describing the error.
45 * @param[in] buf Buffer into which the error string will be placed.
46 * @param[in] bufSize Size of the supplied buffer in bytes.
47 * @param[in] err The error to be described.
49 * @return true If a description string was written into the supplied buffer.
50 * @return false If the supplied error was not a CHIP error.
53 bool FormatCHIPError(char * buf, uint16_t bufSize, int32_t err)
55 const char * desc = nullptr;
57 if (err < CHIP_ERROR_MIN || err > CHIP_ERROR_MAX)
62 #if !CHIP_CONFIG_SHORT_ERROR_STR
65 case CHIP_ERROR_TOO_MANY_CONNECTIONS:
66 desc = "Too many connections";
68 case CHIP_ERROR_SENDING_BLOCKED:
69 desc = "Sending blocked";
71 case CHIP_ERROR_CONNECTION_ABORTED:
72 desc = "Connection aborted";
74 case CHIP_ERROR_INCORRECT_STATE:
75 desc = "Incorrect state";
77 case CHIP_ERROR_MESSAGE_TOO_LONG:
78 desc = "Message too long";
80 case CHIP_ERROR_UNSUPPORTED_EXCHANGE_VERSION:
81 desc = "Unsupported exchange version";
83 case CHIP_ERROR_TOO_MANY_UNSOLICITED_MESSAGE_HANDLERS:
84 desc = "Too many unsolicited message handlers";
86 case CHIP_ERROR_NO_UNSOLICITED_MESSAGE_HANDLER:
87 desc = "No unsolicited message handler";
89 case CHIP_ERROR_NO_CONNECTION_HANDLER:
90 desc = "No connection handler";
92 case CHIP_ERROR_TOO_MANY_PEER_NODES:
93 desc = "Too many peer nodes";
95 case CHIP_ERROR_NO_MEMORY:
98 case CHIP_ERROR_NO_MESSAGE_HANDLER:
99 desc = "No message handler";
101 case CHIP_ERROR_MESSAGE_INCOMPLETE:
102 desc = "Message incomplete";
104 case CHIP_ERROR_DATA_NOT_ALIGNED:
105 desc = "Data not aligned";
107 case CHIP_ERROR_UNKNOWN_KEY_TYPE:
108 desc = "Unknown key type";
110 case CHIP_ERROR_KEY_NOT_FOUND:
111 desc = "Key not found";
113 case CHIP_ERROR_WRONG_ENCRYPTION_TYPE:
114 desc = "Wrong encryption type";
116 case CHIP_ERROR_TOO_MANY_KEYS:
117 desc = "Too many keys";
119 case CHIP_ERROR_INTEGRITY_CHECK_FAILED:
120 desc = "Integrity check failed";
122 case CHIP_ERROR_INVALID_SIGNATURE:
123 desc = "Invalid signature";
125 case CHIP_ERROR_UNSUPPORTED_MESSAGE_VERSION:
126 desc = "Unsupported message version";
128 case CHIP_ERROR_UNSUPPORTED_ENCRYPTION_TYPE:
129 desc = "Unsupported encryption type";
131 case CHIP_ERROR_UNSUPPORTED_SIGNATURE_TYPE:
132 desc = "Unsupported signature type";
134 case CHIP_ERROR_INVALID_MESSAGE_LENGTH:
135 desc = "Invalid message length";
137 case CHIP_ERROR_BUFFER_TOO_SMALL:
138 desc = "Buffer too small";
140 case CHIP_ERROR_DUPLICATE_KEY_ID:
141 desc = "Duplicate key id";
143 case CHIP_ERROR_WRONG_KEY_TYPE:
144 desc = "Wrong key type";
146 case CHIP_ERROR_WELL_UNINITIALIZED:
147 desc = "Well uninitialized";
149 case CHIP_ERROR_WELL_EMPTY:
152 case CHIP_ERROR_INVALID_STRING_LENGTH:
153 desc = "Invalid string length";
155 case CHIP_ERROR_INVALID_LIST_LENGTH:
156 desc = "invalid list length";
158 case CHIP_ERROR_INVALID_INTEGRITY_TYPE:
159 desc = "Invalid integrity type";
161 case CHIP_END_OF_TLV:
164 case CHIP_ERROR_TLV_UNDERRUN:
165 desc = "TLV underrun";
167 case CHIP_ERROR_INVALID_TLV_ELEMENT:
168 desc = "Invalid TLV element";
170 case CHIP_ERROR_INVALID_TLV_TAG:
171 desc = "Invalid TLV tag";
173 case CHIP_ERROR_UNKNOWN_IMPLICIT_TLV_TAG:
174 desc = "Unknown implicit TLV tag";
176 case CHIP_ERROR_WRONG_TLV_TYPE:
177 desc = "Wrong TLV type";
179 case CHIP_ERROR_TLV_CONTAINER_OPEN:
180 desc = "TLV container open";
182 case CHIP_ERROR_INVALID_TRANSFER_MODE:
183 desc = "Invalid transfer mode";
185 case CHIP_ERROR_INVALID_PROFILE_ID:
186 desc = "Invalid profile id";
188 case CHIP_ERROR_INVALID_MESSAGE_TYPE:
189 desc = "Invalid message type";
191 case CHIP_ERROR_UNEXPECTED_TLV_ELEMENT:
192 desc = "Unexpected TLV element";
194 case CHIP_ERROR_STATUS_REPORT_RECEIVED:
195 desc = "Status Report received from peer";
197 case CHIP_ERROR_NOT_IMPLEMENTED:
198 desc = "Not Implemented";
200 case CHIP_ERROR_INVALID_ADDRESS:
201 desc = "Invalid address";
203 case CHIP_ERROR_INVALID_ARGUMENT:
204 desc = "Invalid argument";
206 case CHIP_ERROR_TLV_TAG_NOT_FOUND:
207 desc = "TLV tag not found";
210 case CHIP_ERROR_INVALID_PATH_LIST:
211 desc = "Invalid TLV path list";
213 case CHIP_ERROR_INVALID_DATA_LIST:
214 desc = "Invalid TLV data list";
216 case CHIP_ERROR_TRANSACTION_CANCELED:
217 desc = "Transaction canceled";
219 case CHIP_ERROR_LISTENER_ALREADY_STARTED:
220 desc = "Listener already started";
222 case CHIP_ERROR_LISTENER_ALREADY_STOPPED:
223 desc = "Listener already stopped";
225 case CHIP_ERROR_UNKNOWN_TOPIC:
226 desc = "Unknown Topic";
228 case CHIP_ERROR_TIMEOUT:
231 case CHIP_ERROR_INVALID_DEVICE_DESCRIPTOR:
232 desc = "Invalid device descriptor";
234 case CHIP_ERROR_UNSUPPORTED_DEVICE_DESCRIPTOR_VERSION:
235 desc = "Unsupported device descriptor version";
237 case CHIP_END_OF_INPUT:
238 desc = "End of input";
240 case CHIP_ERROR_RATE_LIMIT_EXCEEDED:
241 desc = "Rate limit exceeded";
243 case CHIP_ERROR_SECURITY_MANAGER_BUSY:
244 desc = "Security manager busy";
246 case CHIP_ERROR_INVALID_PASE_PARAMETER:
247 desc = "Invalid PASE parameter";
249 case CHIP_ERROR_PASE_SUPPORTS_ONLY_CONFIG1:
250 desc = "PASE supports only Config1";
252 case CHIP_ERROR_NO_COMMON_PASE_CONFIGURATIONS:
253 desc = "No supported PASE configurations in common";
255 case CHIP_ERROR_INVALID_PASE_CONFIGURATION:
256 desc = "Invalid PASE configuration";
258 case CHIP_ERROR_KEY_CONFIRMATION_FAILED:
259 desc = "Key confirmation failed";
261 case CHIP_ERROR_INVALID_USE_OF_SESSION_KEY:
262 desc = "Invalid use of session key";
264 case CHIP_ERROR_CONNECTION_CLOSED_UNEXPECTEDLY:
265 desc = "Connection closed unexpectedly";
267 case CHIP_ERROR_MISSING_TLV_ELEMENT:
268 desc = "Missing TLV element";
270 case CHIP_ERROR_RANDOM_DATA_UNAVAILABLE:
271 desc = "Random data unavailable";
273 case CHIP_ERROR_UNSUPPORTED_HOST_PORT_ELEMENT:
274 desc = "Unsupported type in host/port list";
276 case CHIP_ERROR_INVALID_HOST_SUFFIX_INDEX:
277 desc = "Invalid suffix index in host/port list";
279 case CHIP_ERROR_HOST_PORT_LIST_EMPTY:
280 desc = "Host/port empty";
282 case CHIP_ERROR_UNSUPPORTED_AUTH_MODE:
283 desc = "Unsupported authentication mode";
285 case CHIP_ERROR_INVALID_SERVICE_EP:
286 desc = "Invalid service endpoint";
288 case CHIP_ERROR_INVALID_DIRECTORY_ENTRY_TYPE:
289 desc = "Invalid directory entry type";
291 case CHIP_ERROR_FORCED_RESET:
292 desc = "Service manager forced reset";
294 case CHIP_ERROR_NO_ENDPOINT:
295 desc = "No endpoint was available to send the message";
297 case CHIP_ERROR_INVALID_DESTINATION_NODE_ID:
298 desc = "Invalid destination node id";
300 case CHIP_ERROR_NOT_CONNECTED:
301 desc = "Not connected";
303 case CHIP_ERROR_NO_SW_UPDATE_AVAILABLE:
304 desc = "No SW update available";
306 case CHIP_ERROR_CA_CERT_NOT_FOUND:
307 desc = "CA certificate not found";
309 case CHIP_ERROR_CERT_PATH_LEN_CONSTRAINT_EXCEEDED:
310 desc = "Certificate path length constraint exceeded";
312 case CHIP_ERROR_CERT_PATH_TOO_LONG:
313 desc = "Certificate path too long";
315 case CHIP_ERROR_CERT_USAGE_NOT_ALLOWED:
316 desc = "Requested certificate usage is not allowed";
318 case CHIP_ERROR_CERT_EXPIRED:
319 desc = "Certificate expired";
321 case CHIP_ERROR_CERT_NOT_VALID_YET:
322 desc = "Certificate not yet valid";
324 case CHIP_ERROR_UNSUPPORTED_CERT_FORMAT:
325 desc = "Unsupported certificate format";
327 case CHIP_ERROR_UNSUPPORTED_ELLIPTIC_CURVE:
328 desc = "Unsupported elliptic curve";
330 case CHIP_CERT_NOT_USED:
331 desc = "Certificate was not used in chain validation";
333 case CHIP_ERROR_CERT_NOT_FOUND:
334 desc = "Certificate not found";
336 case CHIP_ERROR_INVALID_CASE_PARAMETER:
337 desc = "Invalid CASE parameter";
339 case CHIP_ERROR_UNSUPPORTED_CASE_CONFIGURATION:
340 desc = "Unsupported CASE configuration";
342 case CHIP_ERROR_CERT_LOAD_FAILED:
343 desc = "Unable to load certificate";
345 case CHIP_ERROR_CERT_NOT_TRUSTED:
346 desc = "Certificate not trusted";
348 case CHIP_ERROR_INVALID_ACCESS_TOKEN:
349 desc = "Invalid access token";
351 case CHIP_ERROR_WRONG_CERT_SUBJECT:
352 desc = "Wrong certificate subject";
354 case CHIP_ERROR_INVALID_PROVISIONING_BUNDLE:
355 desc = "Invalid provisioning bundle";
357 case CHIP_ERROR_PROVISIONING_BUNDLE_DECRYPTION_ERROR:
358 desc = "Provisioning bundle decryption error";
360 case CHIP_ERROR_PASE_RECONFIGURE_REQUIRED:
361 desc = "PASE reconfiguration required";
363 case CHIP_ERROR_WRONG_NODE_ID:
364 desc = "Wrong node ID";
366 case CHIP_ERROR_CONN_ACCEPTED_ON_WRONG_PORT:
367 desc = "Connection accepted on wrong port";
369 case CHIP_ERROR_CALLBACK_REPLACED:
370 desc = "Application callback replaced";
372 case CHIP_ERROR_NO_CASE_AUTH_DELEGATE:
373 desc = "No CASE auth delegate set";
375 case CHIP_ERROR_DEVICE_LOCATE_TIMEOUT:
376 desc = "Timeout attempting to locate device";
378 case CHIP_ERROR_DEVICE_CONNECT_TIMEOUT:
379 desc = "Timeout connecting to device";
381 case CHIP_ERROR_DEVICE_AUTH_TIMEOUT:
382 desc = "Timeout authenticating device";
384 case CHIP_ERROR_MESSAGE_NOT_ACKNOWLEDGED:
385 desc = "Message not acknowledged after max retries";
387 case CHIP_ERROR_RETRANS_TABLE_FULL:
388 desc = "Retransmit Table is already full";
390 case CHIP_ERROR_INVALID_ACK_ID:
391 desc = "Invalid Acknowledgment Id";
393 case CHIP_ERROR_SEND_THROTTLED:
394 desc = "Sending to peer is throttled on this Exchange";
396 case CHIP_ERROR_WRONG_MSG_VERSION_FOR_EXCHANGE:
397 desc = "Message version not supported by current exchange context";
399 case CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE:
400 desc = "Required feature not supported by this configuration";
402 case CHIP_ERROR_UNSOLICITED_MSG_NO_ORIGINATOR:
403 desc = "Unsolicited msg with originator bit clear";
405 case CHIP_ERROR_INVALID_FABRIC_ID:
406 desc = "Invalid Fabric Id";
408 case CHIP_ERROR_DRBG_ENTROPY_SOURCE_FAILED:
409 desc = "DRBG entropy source failed to generate entropy data";
411 case CHIP_ERROR_NO_TAKE_AUTH_DELEGATE:
412 desc = "No TAKE auth delegate set";
414 case CHIP_ERROR_TAKE_RECONFIGURE_REQUIRED:
415 desc = "TAKE requires a reconfigure";
417 case CHIP_ERROR_TAKE_REAUTH_POSSIBLE:
418 desc = "TAKE can do a reauthentication";
420 case CHIP_ERROR_INVALID_TAKE_PARAMETER:
421 desc = "TAKE received an invalid parameter";
423 case CHIP_ERROR_UNSUPPORTED_TAKE_CONFIGURATION:
424 desc = "TAKE Unsupported configuration";
426 case CHIP_ERROR_TAKE_TOKEN_IDENTIFICATION_FAILED:
427 desc = "TAKE token identification failed";
429 case CHIP_ERROR_INVALID_TOKENPAIRINGBUNDLE:
430 desc = "Invalid Token Pairing Bundle";
432 case CHIP_ERROR_UNSUPPORTED_TOKENPAIRINGBUNDLE_VERSION:
433 desc = "Unsupported Token Pairing Bundle version";
435 case CHIP_ERROR_KEY_NOT_FOUND_FROM_PEER:
436 desc = "Key not found error code received from peer";
438 case CHIP_ERROR_WRONG_ENCRYPTION_TYPE_FROM_PEER:
439 desc = "Wrong encryption type error code received from peer";
441 case CHIP_ERROR_UNKNOWN_KEY_TYPE_FROM_PEER:
442 desc = "Unknown key type error code received from peer";
444 case CHIP_ERROR_INVALID_USE_OF_SESSION_KEY_FROM_PEER:
445 desc = "Invalid use of session key error code received from peer";
447 case CHIP_ERROR_UNSUPPORTED_ENCRYPTION_TYPE_FROM_PEER:
448 desc = "Unsupported encryption type error code received from peer";
450 case CHIP_ERROR_INTERNAL_KEY_ERROR_FROM_PEER:
451 desc = "Internal key error code received from peer";
453 case CHIP_ERROR_INVALID_KEY_ID:
454 desc = "Invalid key identifier";
456 case CHIP_ERROR_INVALID_TIME:
457 desc = "Valid time value is not available";
459 case CHIP_ERROR_LOCKING_FAILURE:
460 desc = "Failure to lock/unlock OS-provided lock";
462 case CHIP_ERROR_UNSUPPORTED_PASSCODE_CONFIG:
463 desc = "Unsupported passcode encryption configuration";
465 case CHIP_ERROR_PASSCODE_AUTHENTICATION_FAILED:
466 desc = "Passcode authentication failed";
468 case CHIP_ERROR_PASSCODE_FINGERPRINT_FAILED:
469 desc = "Passcode fingerprint failed";
471 case CHIP_ERROR_SERIALIZATION_ELEMENT_NULL:
472 desc = "Element requested is null";
474 case CHIP_ERROR_WRONG_CERT_SIGNATURE_ALGORITHM:
475 desc = "Certificate not signed with required signature algorithm";
477 case CHIP_ERROR_WRONG_CHIP_SIGNATURE_ALGORITHM:
478 desc = "CHIP signature not signed with required signature algorithm";
480 case CHIP_ERROR_SCHEMA_MISMATCH:
481 desc = "Schema mismatch";
483 case CHIP_ERROR_INVALID_INTEGER_VALUE:
484 desc = "Invalid integer value";
486 case CHIP_ERROR_CASE_RECONFIG_REQUIRED:
487 desc = "CASE reconfiguration required";
489 case CHIP_ERROR_TOO_MANY_CASE_RECONFIGURATIONS:
490 desc = "Too many CASE reconfigurations were received";
492 case CHIP_ERROR_BAD_REQUEST:
493 desc = "Request cannot be processed or fulfilled";
495 case CHIP_ERROR_INVALID_MESSAGE_FLAG:
496 desc = "Invalid message flag";
498 case CHIP_ERROR_KEY_EXPORT_RECONFIGURE_REQUIRED:
499 desc = "Key export protocol required to reconfigure";
501 case CHIP_ERROR_NO_COMMON_KEY_EXPORT_CONFIGURATIONS:
502 desc = "No supported key export protocol configurations in common";
504 case CHIP_ERROR_INVALID_KEY_EXPORT_CONFIGURATION:
505 desc = "Invalid key export protocol configuration";
507 case CHIP_ERROR_NO_KEY_EXPORT_DELEGATE:
508 desc = "No key export protocol delegate set";
510 case CHIP_ERROR_UNAUTHORIZED_KEY_EXPORT_REQUEST:
511 desc = "Unauthorized key export request";
513 case CHIP_ERROR_UNAUTHORIZED_KEY_EXPORT_RESPONSE:
514 desc = "Unauthorized key export response";
516 case CHIP_ERROR_EXPORTED_KEY_AUTHENTICATION_FAILED:
517 desc = "Exported key authentication failed";
519 case CHIP_ERROR_TOO_MANY_SHARED_SESSION_END_NODES:
520 desc = "Too many shared session end nodes";
522 case CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_DATA_ELEMENT:
523 desc = "Malformed Interaction Model Attribute DataElement";
525 case CHIP_ERROR_WRONG_CERT_TYPE:
526 desc = "Wrong certificate type";
528 case CHIP_ERROR_DEFAULT_EVENT_HANDLER_NOT_CALLED:
529 desc = "Default event handler not called";
531 case CHIP_ERROR_PERSISTED_STORAGE_FAILED:
532 desc = "Persisted storage failed";
534 case CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND:
535 desc = "Value not found in the persisted storage";
537 case CHIP_ERROR_PROFILE_STRING_CONTEXT_ALREADY_REGISTERED:
538 desc = "String context already registered";
540 case CHIP_ERROR_PROFILE_STRING_CONTEXT_NOT_REGISTERED:
541 desc = "String context not registered";
543 case CHIP_ERROR_INCOMPATIBLE_SCHEMA_VERSION:
544 desc = "Incompatible data schema version";
546 case CHIP_ERROR_MISMATCH_UPDATE_REQUIRED_VERSION:
547 desc = "Update Required Version mismatch";
549 case CHIP_ERROR_ACCESS_DENIED:
550 desc = "The CHIP message is not granted access";
552 case CHIP_ERROR_UNKNOWN_RESOURCE_ID:
553 desc = "Unknown resource ID";
555 case CHIP_ERROR_VERSION_MISMATCH:
556 desc = "Version mismatch";
558 case CHIP_ERROR_UNSUPPORTED_THREAD_NETWORK_CREATE:
559 desc = "Legacy device doesn't support standalone Thread network creation";
561 case CHIP_ERROR_INCONSISTENT_CONDITIONALITY:
562 desc = "The Trait Instance is already being updated with a different conditionality";
564 case CHIP_ERROR_LOCAL_DATA_INCONSISTENT:
565 desc = "The local data does not match any known version of the Trait Instance";
567 case CHIP_EVENT_ID_FOUND:
568 desc = "Event ID matching criteria was found";
570 case CHIP_ERROR_INTERNAL:
571 desc = "Internal error";
573 case CHIP_ERROR_OPEN_FAILED:
574 desc = "Open file failed";
576 case CHIP_ERROR_READ_FAILED:
577 desc = "Read from file failed";
579 case CHIP_ERROR_WRITE_FAILED:
580 desc = "Write to file failed";
582 case CHIP_ERROR_DECODE_FAILED:
583 desc = "Decoding failed";
585 case CHIP_ERROR_SESSION_KEY_SUSPENDED:
586 desc = "Session key suspended";
588 case CHIP_ERROR_UNSUPPORTED_WIRELESS_REGULATORY_DOMAIN:
589 desc = "Unsupported wireless regulatory domain";
591 case CHIP_ERROR_UNSUPPORTED_WIRELESS_OPERATING_LOCATION:
592 desc = "Unsupported wireless operating location";
594 case CHIP_ERROR_MDNS_COLLISSION:
595 desc = "mDNS collission";
597 case CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_PATH:
598 desc = "Malformed Interacton Model Attribute Path";
600 case CHIP_ERROR_IM_MALFORMED_EVENT_PATH:
601 desc = "Malformed Interacton Model Event Path";
603 case CHIP_ERROR_IM_MALFORMED_COMMAND_PATH:
604 desc = "Malformed Interacton Model Command Path";
606 case CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_STATUS_ELEMENT:
607 desc = "Malformed Interacton Model Attribute DataElement";
609 case CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT:
610 desc = "Malformed Interacton Model Attribute DataElement";
612 case CHIP_ERROR_IM_MALFORMED_EVENT_DATA_ELEMENT:
613 desc = "Malformed Interacton Model Event DataElement";
615 case CHIP_ERROR_IM_MALFORMED_STATUS_CODE:
616 desc = "Malformed Interacton Model Status Code";
618 case CHIP_ERROR_PEER_NODE_NOT_FOUND:
619 desc = "Unable to find the peer node";
622 #endif // !CHIP_CONFIG_SHORT_ERROR_STR
624 FormatError(buf, bufSize, "CHIP", err, desc);