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 /**
30  * @file
31  *   This file includes definitions for Thread URIs.
32  */
33 
34 #ifndef URI_PATHS_HPP_
35 #define URI_PATHS_HPP_
36 
37 #include "openthread-core-config.h"
38 
39 #include "common/error.hpp"
40 
41 namespace ot {
42 
43 /**
44  * This enumeration represents Thread URIs.
45  *
46  */
47 enum Uri : uint8_t
48 {
49     kUriAddressError,           ///< Address Error ("a/ae")
50     kUriAddressNotify,          ///< Address Notify ("a/an")
51     kUriAddressQuery,           ///< Address Query ("a/aq")
52     kUriAddressRelease,         ///< Address Release ("a/ar")
53     kUriAddressSolicit,         ///< Address Solicit ("a/as")
54     kUriServerData,             ///< Server Data Registration ("a/sd")
55     kUriAnycastLocate,          ///< Anycast Locate ("a/yl")
56     kUriBackboneAnswer,         ///< Backbone Answer / Backbone Notification ("b/ba")
57     kUriBackboneMlr,            ///< Backbone Multicast Listener Report ("b/bmr")
58     kUriBackboneQuery,          ///< Backbone Query ("b/bq")
59     kUriAnnounceBegin,          ///< Announce Begin ("c/ab")
60     kUriActiveGet,              ///< MGMT_ACTIVE_GET "c/ag"
61     kUriActiveSet,              ///< MGMT_ACTIVE_SET ("c/as")
62     kUriCommissionerKeepAlive,  ///< Commissioner Keep Alive ("c/ca")
63     kUriCommissionerGet,        ///< MGMT_COMMISSIONER_GET ("c/cg")
64     kUriCommissionerPetition,   ///< Commissioner Petition ("c/cp")
65     kUriCommissionerSet,        ///< MGMT_COMMISSIONER_SET ("c/cs")
66     kUriDatasetChanged,         ///< MGMT_DATASET_CHANGED ("c/dc")
67     kUriEnergyReport,           ///< Energy Report ("c/er")
68     kUriEnergyScan,             ///< Energy Scan ("c/es")
69     kUriJoinerEntrust,          ///< Joiner Entrust  ("c/je")
70     kUriJoinerFinalize,         ///< Joiner Finalize ("c/jf")
71     kUriLeaderKeepAlive,        ///< Leader Keep Alive ("c/la")
72     kUriLeaderPetition,         ///< Leader Petition ("c/lp")
73     kUriPanIdConflict,          ///< PAN ID Conflict ("c/pc")
74     kUriPendingGet,             ///< MGMT_PENDING_GET ("c/pg")
75     kUriPanIdQuery,             ///< PAN ID Query ("c/pq")
76     kUriPendingSet,             ///< MGMT_PENDING_SET ("c/ps")
77     kUriRelayRx,                ///< Relay RX ("c/rx")
78     kUriRelayTx,                ///< Relay TX ("c/tx")
79     kUriProxyRx,                ///< Proxy RX ("c/ur")
80     kUriProxyTx,                ///< Proxy TX ("c/ut")
81     kUriDiagnosticGetAnswer,    ///< Network Diagnostic Get Answer ("d/da")
82     kUriDiagnosticGetRequest,   ///< Network Diagnostic Get Request ("d/dg")
83     kUriDiagnosticGetQuery,     ///< Network Diagnostic Get Query ("d/dq")
84     kUriDiagnosticReset,        ///< Network Diagnostic Reset ("d/dr")
85     kUriDuaRegistrationNotify,  ///< DUA Registration Notification ("n/dn")
86     kUriDuaRegistrationRequest, ///< DUA Registration Request ("n/dr")
87     kUriMlr,                    ///< Multicast Listener Registration ("n/mr")
88     kUriUnknown,                ///< Unknown URI
89 };
90 
91 /**
92  * This function returns URI path string for a given URI.
93  *
94  * @param[in] aUri   A URI.
95  *
96  * @returns The path string for @p aUri.
97  *
98  */
99 const char *PathForUri(Uri aUri);
100 
101 /**
102  * This function looks up the URI from a given path string.
103  *
104  * @param[in] aPath    A path string.
105  *
106  * @returns The URI associated with @p aPath or `kUriUnknown` if no match is found.
107  *
108  */
109 Uri UriFromPath(const char *aPath);
110 
111 /**
112  * This template function converts a given URI to a human-readable string.
113  *
114  * @tparam kUri   The URI to convert to string.
115  *
116  * @returns The string representation of @p kUri.
117  *
118  */
119 template <Uri kUri> const char *UriToString(void);
120 
121 // Declaring specializations of `UriToString` for every `Uri`
122 template <> const char *UriToString<kUriAddressError>(void);
123 template <> const char *UriToString<kUriAddressNotify>(void);
124 template <> const char *UriToString<kUriAddressQuery>(void);
125 template <> const char *UriToString<kUriAddressRelease>(void);
126 template <> const char *UriToString<kUriAddressSolicit>(void);
127 template <> const char *UriToString<kUriServerData>(void);
128 template <> const char *UriToString<kUriAnycastLocate>(void);
129 template <> const char *UriToString<kUriBackboneAnswer>(void);
130 template <> const char *UriToString<kUriBackboneMlr>(void);
131 template <> const char *UriToString<kUriBackboneQuery>(void);
132 template <> const char *UriToString<kUriAnnounceBegin>(void);
133 template <> const char *UriToString<kUriActiveGet>(void);
134 template <> const char *UriToString<kUriActiveSet>(void);
135 template <> const char *UriToString<kUriCommissionerKeepAlive>(void);
136 template <> const char *UriToString<kUriCommissionerGet>(void);
137 template <> const char *UriToString<kUriCommissionerPetition>(void);
138 template <> const char *UriToString<kUriCommissionerSet>(void);
139 template <> const char *UriToString<kUriDatasetChanged>(void);
140 template <> const char *UriToString<kUriEnergyReport>(void);
141 template <> const char *UriToString<kUriEnergyScan>(void);
142 template <> const char *UriToString<kUriJoinerEntrust>(void);
143 template <> const char *UriToString<kUriJoinerFinalize>(void);
144 template <> const char *UriToString<kUriLeaderKeepAlive>(void);
145 template <> const char *UriToString<kUriLeaderPetition>(void);
146 template <> const char *UriToString<kUriPanIdConflict>(void);
147 template <> const char *UriToString<kUriPendingGet>(void);
148 template <> const char *UriToString<kUriPanIdQuery>(void);
149 template <> const char *UriToString<kUriPendingSet>(void);
150 template <> const char *UriToString<kUriRelayRx>(void);
151 template <> const char *UriToString<kUriRelayTx>(void);
152 template <> const char *UriToString<kUriProxyRx>(void);
153 template <> const char *UriToString<kUriProxyTx>(void);
154 template <> const char *UriToString<kUriDiagnosticGetAnswer>(void);
155 template <> const char *UriToString<kUriDiagnosticGetRequest>(void);
156 template <> const char *UriToString<kUriDiagnosticGetQuery>(void);
157 template <> const char *UriToString<kUriDiagnosticReset>(void);
158 template <> const char *UriToString<kUriDuaRegistrationNotify>(void);
159 template <> const char *UriToString<kUriDuaRegistrationRequest>(void);
160 template <> const char *UriToString<kUriMlr>(void);
161 
162 } // namespace ot
163 
164 #endif // URI_PATHS_HPP_
165