Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / third_party / ot-br-posix / repo / src / dbus / server / error_helper.cpp
1 /*
2  *    Copyright (c) 2020, 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 #include "dbus/server/error_helper.hpp"
30 #include "common/code_utils.hpp"
31 #include "dbus/common/dbus_message_helper.hpp"
32
33 #define OPENTHREAD_ERROR_PREFIX "io.openthread.Error"
34
35 static const std::pair<otError, const char *> sErrorNames[] = {
36     {OT_ERROR_NONE, OPENTHREAD_ERROR_PREFIX ".OK"},
37     {OT_ERROR_GENERIC, OPENTHREAD_ERROR_PREFIX ".Generic"},
38     {OT_ERROR_FAILED, OPENTHREAD_ERROR_PREFIX ".Failed"},
39     {OT_ERROR_DROP, OPENTHREAD_ERROR_PREFIX ".Drop"},
40     {OT_ERROR_NO_BUFS, OPENTHREAD_ERROR_PREFIX ".NoBufs"},
41     {OT_ERROR_NO_ROUTE, OPENTHREAD_ERROR_PREFIX ".NoRoute"},
42     {OT_ERROR_BUSY, OPENTHREAD_ERROR_PREFIX ".Busy"},
43     {OT_ERROR_PARSE, OPENTHREAD_ERROR_PREFIX ".Parse"},
44     {OT_ERROR_INVALID_ARGS, OPENTHREAD_ERROR_PREFIX ".InvalidArgs"},
45     {OT_ERROR_SECURITY, OPENTHREAD_ERROR_PREFIX ".Security"},
46     {OT_ERROR_ADDRESS_QUERY, OPENTHREAD_ERROR_PREFIX ".AddressQuery"},
47     {OT_ERROR_NO_ADDRESS, OPENTHREAD_ERROR_PREFIX ".NoAddress"},
48     {OT_ERROR_ABORT, OPENTHREAD_ERROR_PREFIX ".Abort"},
49     {OT_ERROR_NOT_IMPLEMENTED, OPENTHREAD_ERROR_PREFIX ".NotImplemented"},
50     {OT_ERROR_INVALID_STATE, OPENTHREAD_ERROR_PREFIX ".InvalidState"},
51     {OT_ERROR_NO_ACK, OPENTHREAD_ERROR_PREFIX ".NoAck"},
52     {OT_ERROR_CHANNEL_ACCESS_FAILURE, OPENTHREAD_ERROR_PREFIX ".ChannelAccessFailure"},
53     {OT_ERROR_DETACHED, OPENTHREAD_ERROR_PREFIX ".Detached"},
54     {OT_ERROR_FCS, OPENTHREAD_ERROR_PREFIX ".FcsErr"},
55     {OT_ERROR_NO_FRAME_RECEIVED, OPENTHREAD_ERROR_PREFIX ".NoFrameReceived"},
56     {OT_ERROR_UNKNOWN_NEIGHBOR, OPENTHREAD_ERROR_PREFIX ".UnknownNeighbor"},
57     {OT_ERROR_INVALID_SOURCE_ADDRESS, OPENTHREAD_ERROR_PREFIX ".InvalidSourceAddress"},
58     {OT_ERROR_ADDRESS_FILTERED, OPENTHREAD_ERROR_PREFIX ".AddressFiltered"},
59     {OT_ERROR_DESTINATION_ADDRESS_FILTERED, OPENTHREAD_ERROR_PREFIX ".DestinationAddressFiltered"},
60     {OT_ERROR_NOT_FOUND, OPENTHREAD_ERROR_PREFIX ".NotFound"},
61     {OT_ERROR_ALREADY, OPENTHREAD_ERROR_PREFIX ".Already"},
62     {OT_ERROR_IP6_ADDRESS_CREATION_FAILURE, OPENTHREAD_ERROR_PREFIX ".Ipv6AddressCreationFailure"},
63     {OT_ERROR_NOT_CAPABLE, OPENTHREAD_ERROR_PREFIX ".NotCapable"},
64     {OT_ERROR_RESPONSE_TIMEOUT, OPENTHREAD_ERROR_PREFIX ".ResponseTimeout"},
65     {OT_ERROR_DUPLICATED, OPENTHREAD_ERROR_PREFIX ".Duplicated"},
66     {OT_ERROR_REASSEMBLY_TIMEOUT, OPENTHREAD_ERROR_PREFIX ".ReassemblyTimeout"},
67     {OT_ERROR_NOT_TMF, OPENTHREAD_ERROR_PREFIX ".NotTmf"},
68     {OT_ERROR_NOT_LOWPAN_DATA_FRAME, OPENTHREAD_ERROR_PREFIX ".NonLowpanDatatFrame"},
69     {OT_ERROR_LINK_MARGIN_LOW, OPENTHREAD_ERROR_PREFIX ".LinkMarginLow"},
70 };
71
72 namespace otbr {
73 namespace DBus {
74
75 const char *ConvertToDBusErrorName(otError aError)
76 {
77     const char *name = sErrorNames[0].second;
78
79     for (const auto &p : sErrorNames)
80     {
81         if (p.first == aError)
82         {
83             name = p.second;
84             break;
85         }
86     }
87     return name;
88 }
89
90 } // namespace DBus
91 } // namespace otbr