1 /* 2 * Copyright (c) 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 defines the errors used by OpenThread core. 32 */ 33 34 #ifndef ERROR_HPP_ 35 #define ERROR_HPP_ 36 37 #include "openthread-core-config.h" 38 39 #include <openthread/error.h> 40 41 #include <stdint.h> 42 43 namespace ot { 44 45 /** 46 * This type represents error codes used by OpenThread core modules. 47 * 48 */ 49 typedef otError Error; 50 51 /* 52 * The `OT_ERROR_*` enumeration values are re-defined using `kError` style format. 53 * See `openthread/error.h` for more details about each error. 54 * 55 */ 56 constexpr Error kErrorNone = OT_ERROR_NONE; 57 constexpr Error kErrorFailed = OT_ERROR_FAILED; 58 constexpr Error kErrorDrop = OT_ERROR_DROP; 59 constexpr Error kErrorNoBufs = OT_ERROR_NO_BUFS; 60 constexpr Error kErrorNoRoute = OT_ERROR_NO_ROUTE; 61 constexpr Error kErrorBusy = OT_ERROR_BUSY; 62 constexpr Error kErrorParse = OT_ERROR_PARSE; 63 constexpr Error kErrorInvalidArgs = OT_ERROR_INVALID_ARGS; 64 constexpr Error kErrorSecurity = OT_ERROR_SECURITY; 65 constexpr Error kErrorAddressQuery = OT_ERROR_ADDRESS_QUERY; 66 constexpr Error kErrorNoAddress = OT_ERROR_NO_ADDRESS; 67 constexpr Error kErrorAbort = OT_ERROR_ABORT; 68 constexpr Error kErrorNotImplemented = OT_ERROR_NOT_IMPLEMENTED; 69 constexpr Error kErrorInvalidState = OT_ERROR_INVALID_STATE; 70 constexpr Error kErrorNoAck = OT_ERROR_NO_ACK; 71 constexpr Error kErrorChannelAccessFailure = OT_ERROR_CHANNEL_ACCESS_FAILURE; 72 constexpr Error kErrorDetached = OT_ERROR_DETACHED; 73 constexpr Error kErrorFcs = OT_ERROR_FCS; 74 constexpr Error kErrorNoFrameReceived = OT_ERROR_NO_FRAME_RECEIVED; 75 constexpr Error kErrorUnknownNeighbor = OT_ERROR_UNKNOWN_NEIGHBOR; 76 constexpr Error kErrorInvalidSourceAddress = OT_ERROR_INVALID_SOURCE_ADDRESS; 77 constexpr Error kErrorAddressFiltered = OT_ERROR_ADDRESS_FILTERED; 78 constexpr Error kErrorDestinationAddressFiltered = OT_ERROR_DESTINATION_ADDRESS_FILTERED; 79 constexpr Error kErrorNotFound = OT_ERROR_NOT_FOUND; 80 constexpr Error kErrorAlready = OT_ERROR_ALREADY; 81 constexpr Error kErrorIp6AddressCreationFailure = OT_ERROR_IP6_ADDRESS_CREATION_FAILURE; 82 constexpr Error kErrorNotCapable = OT_ERROR_NOT_CAPABLE; 83 constexpr Error kErrorResponseTimeout = OT_ERROR_RESPONSE_TIMEOUT; 84 constexpr Error kErrorDuplicated = OT_ERROR_DUPLICATED; 85 constexpr Error kErrorReassemblyTimeout = OT_ERROR_REASSEMBLY_TIMEOUT; 86 constexpr Error kErrorNotTmf = OT_ERROR_NOT_TMF; 87 constexpr Error kErrorNotLowpanDataFrame = OT_ERROR_NOT_LOWPAN_DATA_FRAME; 88 constexpr Error kErrorLinkMarginLow = OT_ERROR_LINK_MARGIN_LOW; 89 constexpr Error kErrorInvalidCommand = OT_ERROR_INVALID_COMMAND; 90 constexpr Error kErrorPending = OT_ERROR_PENDING; 91 constexpr Error kErrorRejected = OT_ERROR_REJECTED; 92 constexpr Error kErrorGeneric = OT_ERROR_GENERIC; 93 94 constexpr uint8_t kNumErrors = OT_NUM_ERRORS; 95 96 /** 97 * This function converts an `Error` into a string. 98 * 99 * @param[in] aError An error. 100 * 101 * @returns A string representation of @p aError. 102 * 103 */ 104 const char *ErrorToString(Error aError); 105 106 } // namespace ot 107 108 #endif // ERROR_HPP_ 109