Contiki-NG
Loading...
Searching...
No Matches
edhoc-error.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024, RISE Research Institutes of Sweden AB
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the copyright holder nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30/**
31 * \file
32 * Error handling module for EDHOC.
33 * \author
34 * Niclas Finne <niclas.finne@ri.se>, Nicolas Tsiftes <nicolas.tsiftes@ri.se>
35 */
36
37#include "edhoc-error.h"
38#include <string.h>
39
40/* Static storage for error context */
41static edhoc_error_context_t last_error_context = { EDHOC_SUCCESS, NULL, 0, NULL, NULL };
42/*---------------------------------------------------------------------------*/
43const char *
45{
46 switch(error) {
47 case EDHOC_SUCCESS:
48 return "Success";
49
50 /* Memory errors */
52 return "Memory allocation failed";
54 return "Buffer too small";
56 return "Buffer overflow";
58 return "Null pointer";
60 return "Invalid length";
61
62 /* Cryptographic errors */
64 return "Cryptographic key generation failed";
66 return "Digital signature failed";
68 return "Signature verification failed";
70 return "Encryption failed";
72 return "Decryption failed";
74 return "Hash operation failed";
76 return "Key derivation failed";
78 return "Authentication failed";
80 return "Invalid cryptographic key";
81
82 /* Protocol errors */
84 return "Cipher suite not supported";
86 return "Malformed message";
88 return "EDHOC method not supported";
90 return "Invalid connection identifier";
92 return "Wrong connection identifier";
94 return "Invalid credential";
96 return "Malformed credential identifier";
98 return "Message sequence error";
100 return "Message correlation error";
102 return "Critical EAD item cannot be processed";
103
104 /* Storage errors */
106 return "Key not found";
108 return "Key storage full";
110 return "Credential not found";
112 return "Storage initialization failed";
114 return "Duplicate key";
115
116 /* Network errors */
118 return "Network timeout";
120 return "Network connection error";
122 return "CoAP error";
124 return "Message too large";
125
126 /* CBOR errors */
128 return "CBOR encoding failed";
130 return "CBOR decoding failed";
132 return "Invalid CBOR type";
134 return "Malformed CBOR data";
135
136 /* State errors */
138 return "Invalid state";
140 return "Context not initialized";
142 return "Already initialized";
144 return "Identity not allowed";
145
146 /* General errors */
148 return "Invalid parameter";
150 return "Not implemented";
152 return "Internal error";
154 return "Unknown error";
155
156 default:
157 return "Unrecognized error code";
158 }
159}
160/*---------------------------------------------------------------------------*/
163 int line, const char *function,
164 const char *message)
165{
166 last_error_context.code = code;
167 last_error_context.file = file;
168 last_error_context.line = line;
169 last_error_context.function = function;
170 last_error_context.message = message;
171
172 return code;
173}
174/*---------------------------------------------------------------------------*/
177{
178 if(last_error_context.code == EDHOC_SUCCESS) {
179 return NULL;
180 }
181 return &last_error_context;
182}
edhoc_error_t edhoc_set_error_context(edhoc_error_t code, const char *file, int line, const char *function, const char *message)
Set error context for debugging (internal use).
const char * edhoc_error_string(edhoc_error_t error)
Get a human-readable error message for an error code.
Definition edhoc-error.c:44
const edhoc_error_context_t * edhoc_get_last_error_context(void)
Get the last error context (for debugging).
Error handling module header for EDHOC.
edhoc_error_t
Unified error type for EDHOC operations.
Definition edhoc-error.h:60
@ EDHOC_ERR_CBOR_ENCODING
CBOR encoding failed.
@ EDHOC_ERR_CRYPTO_DECRYPT
Decryption operation failed.
Definition edhoc-error.h:76
@ EDHOC_ERR_CREDENTIAL_INVALID
Invalid credential.
Definition edhoc-error.h:88
@ EDHOC_ERR_CREDENTIAL_NOT_FOUND
Credential not found.
Definition edhoc-error.h:97
@ EDHOC_ERR_ALREADY_INITIALIZED
Already initialized.
@ EDHOC_ERR_CRYPTO_VERIFY
Signature verification failed.
Definition edhoc-error.h:74
@ EDHOC_ERR_STORAGE_INIT_FAILED
Storage initialization failed.
Definition edhoc-error.h:98
@ EDHOC_ERR_NETWORK_TIMEOUT
Network operation timeout.
@ EDHOC_ERR_NULL_POINTER
Null pointer provided.
Definition edhoc-error.h:68
@ EDHOC_ERR_CRYPTO_HASH
Hash operation failed.
Definition edhoc-error.h:77
@ EDHOC_ERR_NETWORK_CONNECTION
Network connection error.
@ EDHOC_ERR_MESSAGE_TOO_LARGE
Message too large for transport.
@ EDHOC_ERR_ID_CRED_MALFORMED
Malformed credential identifier.
Definition edhoc-error.h:89
@ EDHOC_ERR_CRITICAL_EAD_UNSUPPORTED
Critical EAD item cannot be processed (RFC 9528 Section 6).
Definition edhoc-error.h:92
@ EDHOC_ERR_CRYPTO_ENCRYPT
Encryption operation failed.
Definition edhoc-error.h:75
@ EDHOC_ERR_INTERNAL_ERROR
Internal implementation error.
@ EDHOC_ERR_CRYPTO_INVALID_KEY
Invalid cryptographic key.
Definition edhoc-error.h:80
@ EDHOC_ERR_WRONG_CID
Wrong connection identifier.
Definition edhoc-error.h:87
@ EDHOC_ERR_CRYPTO_AUTHENTICATION
Authentication failed.
Definition edhoc-error.h:79
@ EDHOC_ERR_INVALID_STATE
Invalid context state.
@ EDHOC_ERR_KEY_NOT_FOUND
Key not found in storage.
Definition edhoc-error.h:95
@ EDHOC_ERR_DUPLICATE_KEY
Duplicate key in storage.
Definition edhoc-error.h:99
@ EDHOC_ERR_CRYPTO_KDF
Key derivation failed.
Definition edhoc-error.h:78
@ EDHOC_ERR_NOT_IMPLEMENTED
Feature not implemented.
@ EDHOC_ERR_BUFFER_OVERFLOW
Buffer overflow detected.
Definition edhoc-error.h:67
@ EDHOC_ERR_SUITE_NOT_SUPPORTED
Cipher suite not supported.
Definition edhoc-error.h:83
@ EDHOC_ERR_MSG_MALFORMED
Malformed message received.
Definition edhoc-error.h:84
@ EDHOC_ERR_COAP_ERROR
CoAP protocol error.
@ EDHOC_ERR_CORRELATION
Message correlation error.
Definition edhoc-error.h:91
@ EDHOC_ERR_KEY_STORAGE_FULL
Key storage is full.
Definition edhoc-error.h:96
@ EDHOC_ERR_INVALID_LENGTH
Invalid length parameter.
Definition edhoc-error.h:69
@ EDHOC_ERR_UNKNOWN
Unknown error condition.
@ EDHOC_ERR_CID_INVALID
Invalid connection identifier.
Definition edhoc-error.h:86
@ EDHOC_ERR_NOT_ALLOWED_IDENTITY
Identity not allowed.
@ EDHOC_ERR_BUFFER_TOO_SMALL
Provided buffer is too small.
Definition edhoc-error.h:66
@ EDHOC_ERR_CRYPTO_KEYGEN
Key generation failed.
Definition edhoc-error.h:72
@ EDHOC_ERR_CBOR_MALFORMED
Malformed CBOR data.
@ EDHOC_ERR_CRYPTO_SIGN
Digital signature failed.
Definition edhoc-error.h:73
@ EDHOC_ERR_CONTEXT_NOT_INITIALIZED
Context not initialized.
@ EDHOC_ERR_METHOD_NOT_SUPPORTED
EDHOC method not supported.
Definition edhoc-error.h:85
@ EDHOC_ERR_CBOR_DECODING
CBOR decoding failed.
@ EDHOC_ERR_CBOR_INVALID_TYPE
Invalid CBOR data type.
@ EDHOC_ERR_INVALID_PARAMETER
Invalid parameter provided.
@ EDHOC_ERR_MEMORY_ALLOCATION
Memory allocation failed.
Definition edhoc-error.h:65
@ EDHOC_ERR_SEQUENCE_ERROR
Message sequence error.
Definition edhoc-error.h:90
Error context structure for debugging.