1 /*
2 * Copyright (c) 2016-2021, 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 * This file implements the error code functions used by OpenThread core modules.
32 */
33
34 #include "error.hpp"
35
36 #include "common/code_utils.hpp"
37
38 namespace ot {
39
ErrorToString(Error aError)40 const char *ErrorToString(Error aError)
41 {
42 static const char *const kErrorStrings[kNumErrors] = {
43 "OK", // (0) kErrorNone
44 "Failed", // (1) kErrorFailed
45 "Drop", // (2) kErrorDrop
46 "NoBufs", // (3) kErrorNoBufs
47 "NoRoute", // (4) kErrorNoRoute
48 "Busy", // (5) kErrorBusy
49 "Parse", // (6) kErrorParse
50 "InvalidArgs", // (7) kErrorInvalidArgs
51 "Security", // (8) kErrorSecurity
52 "AddressQuery", // (9) kErrorAddressQuery
53 "NoAddress", // (10) kErrorNoAddress
54 "Abort", // (11) kErrorAbort
55 "NotImplemented", // (12) kErrorNotImplemented
56 "InvalidState", // (13) kErrorInvalidState
57 "NoAck", // (14) kErrorNoAck
58 "ChannelAccessFailure", // (15) kErrorChannelAccessFailure
59 "Detached", // (16) kErrorDetached
60 "FcsErr", // (17) kErrorFcs
61 "NoFrameReceived", // (18) kErrorNoFrameReceived
62 "UnknownNeighbor", // (19) kErrorUnknownNeighbor
63 "InvalidSourceAddress", // (20) kErrorInvalidSourceAddress
64 "AddressFiltered", // (21) kErrorAddressFiltered
65 "DestinationAddressFiltered", // (22) kErrorDestinationAddressFiltered
66 "NotFound", // (23) kErrorNotFound
67 "Already", // (24) kErrorAlready
68 "ReservedError25", // (25) Error 25 is reserved
69 "Ipv6AddressCreationFailure", // (26) kErrorIp6AddressCreationFailure
70 "NotCapable", // (27) kErrorNotCapable
71 "ResponseTimeout", // (28) kErrorResponseTimeout
72 "Duplicated", // (29) kErrorDuplicated
73 "ReassemblyTimeout", // (30) kErrorReassemblyTimeout
74 "NotTmf", // (31) kErrorNotTmf
75 "NonLowpanDataFrame", // (32) kErrorNotLowpanDataFrame
76 "ReservedError33", // (33) Error 33 is reserved
77 "LinkMarginLow", // (34) kErrorLinkMarginLow
78 "InvalidCommand", // (35) kErrorInvalidCommand
79 "Pending", // (36) kErrorPending
80 "Rejected", // (37) kErrorRejected
81 };
82
83 return aError < OT_ARRAY_LENGTH(kErrorStrings) ? kErrorStrings[aError] : "UnknownErrorType";
84 }
85
86 } // namespace ot
87