1 /*
2  *  Copyright (c) 2016, The OpenThread Authors.
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 are met:
7  *  1. Redistributions of source code must retain the above copyright
8  *     notice, this list of conditions and the following disclaimer.
9  *  2. Redistributions in binary form must reproduce the above copyright
10  *     notice, this list of conditions and the following disclaimer in the
11  *     documentation and/or other materials provided with the distribution.
12  *  3. Neither the name of the copyright holder nor the
13  *     names of its contributors may be used to endorse or promote products
14  *     derived from this software without specific prior written permission.
15  *
16  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  *  POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 /**
30  * @file
31  * @brief
32  *  This file defines the errors used in the OpenThread.
33  */
34 
35 #ifndef OPENTHREAD_ERROR_H_
36 #define OPENTHREAD_ERROR_H_
37 
38 #include <openthread/platform/toolchain.h>
39 
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43 
44 /**
45  * @addtogroup api-error
46  *
47  * @brief
48  *   This module includes error definitions used in OpenThread.
49  *
50  * @{
51  *
52  */
53 
54 /**
55  * This enumeration represents error codes used throughout OpenThread.
56  *
57  */
58 typedef enum OT_MUST_USE_RESULT otError
59 {
60     /**
61      * No error.
62      */
63     OT_ERROR_NONE = 0,
64 
65     /**
66      * Operational failed.
67      */
68     OT_ERROR_FAILED = 1,
69 
70     /**
71      * Message was dropped.
72      */
73     OT_ERROR_DROP = 2,
74 
75     /**
76      * Insufficient buffers.
77      */
78     OT_ERROR_NO_BUFS = 3,
79 
80     /**
81      * No route available.
82      */
83     OT_ERROR_NO_ROUTE = 4,
84 
85     /**
86      * Service is busy and could not service the operation.
87      */
88     OT_ERROR_BUSY = 5,
89 
90     /**
91      * Failed to parse message.
92      */
93     OT_ERROR_PARSE = 6,
94 
95     /**
96      * Input arguments are invalid.
97      */
98     OT_ERROR_INVALID_ARGS = 7,
99 
100     /**
101      * Security checks failed.
102      */
103     OT_ERROR_SECURITY = 8,
104 
105     /**
106      * Address resolution requires an address query operation.
107      */
108     OT_ERROR_ADDRESS_QUERY = 9,
109 
110     /**
111      * Address is not in the source match table.
112      */
113     OT_ERROR_NO_ADDRESS = 10,
114 
115     /**
116      * Operation was aborted.
117      */
118     OT_ERROR_ABORT = 11,
119 
120     /**
121      * Function or method is not implemented.
122      */
123     OT_ERROR_NOT_IMPLEMENTED = 12,
124 
125     /**
126      * Cannot complete due to invalid state.
127      */
128     OT_ERROR_INVALID_STATE = 13,
129 
130     /**
131      * No acknowledgment was received after macMaxFrameRetries (IEEE 802.15.4-2006).
132      */
133     OT_ERROR_NO_ACK = 14,
134 
135     /**
136      * A transmission could not take place due to activity on the channel, i.e., the CSMA-CA mechanism has failed
137      * (IEEE 802.15.4-2006).
138      */
139     OT_ERROR_CHANNEL_ACCESS_FAILURE = 15,
140 
141     /**
142      * Not currently attached to a Thread Partition.
143      */
144     OT_ERROR_DETACHED = 16,
145 
146     /**
147      * FCS check failure while receiving.
148      */
149     OT_ERROR_FCS = 17,
150 
151     /**
152      * No frame received.
153      */
154     OT_ERROR_NO_FRAME_RECEIVED = 18,
155 
156     /**
157      * Received a frame from an unknown neighbor.
158      */
159     OT_ERROR_UNKNOWN_NEIGHBOR = 19,
160 
161     /**
162      * Received a frame from an invalid source address.
163      */
164     OT_ERROR_INVALID_SOURCE_ADDRESS = 20,
165 
166     /**
167      * Received a frame filtered by the address filter (allowlisted or denylisted).
168      */
169     OT_ERROR_ADDRESS_FILTERED = 21,
170 
171     /**
172      * Received a frame filtered by the destination address check.
173      */
174     OT_ERROR_DESTINATION_ADDRESS_FILTERED = 22,
175 
176     /**
177      * The requested item could not be found.
178      */
179     OT_ERROR_NOT_FOUND = 23,
180 
181     /**
182      * The operation is already in progress.
183      */
184     OT_ERROR_ALREADY = 24,
185 
186     /**
187      * The creation of IPv6 address failed.
188      */
189     OT_ERROR_IP6_ADDRESS_CREATION_FAILURE = 26,
190 
191     /**
192      * Operation prevented by mode flags
193      */
194     OT_ERROR_NOT_CAPABLE = 27,
195 
196     /**
197      * Coap response or acknowledgment or DNS, SNTP response not received.
198      */
199     OT_ERROR_RESPONSE_TIMEOUT = 28,
200 
201     /**
202      * Received a duplicated frame.
203      */
204     OT_ERROR_DUPLICATED = 29,
205 
206     /**
207      * Message is being dropped from reassembly list due to timeout.
208      */
209     OT_ERROR_REASSEMBLY_TIMEOUT = 30,
210 
211     /**
212      * Message is not a TMF Message.
213      */
214     OT_ERROR_NOT_TMF = 31,
215 
216     /**
217      * Received a non-lowpan data frame.
218      */
219     OT_ERROR_NOT_LOWPAN_DATA_FRAME = 32,
220 
221     /**
222      * The link margin was too low.
223      */
224     OT_ERROR_LINK_MARGIN_LOW = 34,
225 
226     /**
227      * Input (CLI) command is invalid.
228      */
229     OT_ERROR_INVALID_COMMAND = 35,
230 
231     /**
232      * Special error code used to indicate success/error status is pending and not yet known.
233      *
234      */
235     OT_ERROR_PENDING = 36,
236 
237     /**
238      * Request rejected.
239      */
240     OT_ERROR_REJECTED = 37,
241 
242     /**
243      * The number of defined errors.
244      */
245     OT_NUM_ERRORS,
246 
247     /**
248      * Generic error (should not use).
249      */
250     OT_ERROR_GENERIC = 255,
251 } otError;
252 
253 /**
254  * This function converts an otError enum into a string.
255  *
256  * @param[in]  aError     An otError enum.
257  *
258  * @returns  A string representation of an otError.
259  *
260  */
261 const char *otThreadErrorToString(otError aError);
262 
263 /**
264  * @}
265  *
266  */
267 
268 #ifdef __cplusplus
269 } // extern "C"
270 #endif
271 
272 #endif // OPENTHREAD_ERROR_H_
273