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