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 * 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 kUriActiveReplace, ///< MGMT_ACTIVE_REPLACE ("c/ar") 62 kUriActiveSet, ///< MGMT_ACTIVE_SET ("c/as") 63 kUriCommissionerKeepAlive, ///< Commissioner Keep Alive ("c/ca") 64 kUriCommissionerGet, ///< MGMT_COMMISSIONER_GET ("c/cg") 65 kUriCommissionerPetition, ///< Commissioner Petition ("c/cp") 66 kUriCommissionerSet, ///< MGMT_COMMISSIONER_SET ("c/cs") 67 kUriDatasetChanged, ///< MGMT_DATASET_CHANGED ("c/dc") 68 kUriEnergyReport, ///< Energy Report ("c/er") 69 kUriEnergyScan, ///< Energy Scan ("c/es") 70 kUriJoinerEntrust, ///< Joiner Entrust ("c/je") 71 kUriJoinerFinalize, ///< Joiner Finalize ("c/jf") 72 kUriLeaderKeepAlive, ///< Leader Keep Alive ("c/la") 73 kUriLeaderPetition, ///< Leader Petition ("c/lp") 74 kUriPanIdConflict, ///< PAN ID Conflict ("c/pc") 75 kUriPendingGet, ///< MGMT_PENDING_GET ("c/pg") 76 kUriPanIdQuery, ///< PAN ID Query ("c/pq") 77 kUriPendingSet, ///< MGMT_PENDING_SET ("c/ps") 78 kUriRelayRx, ///< Relay RX ("c/rx") 79 kUriRelayTx, ///< Relay TX ("c/tx") 80 kUriProxyRx, ///< Proxy RX ("c/ur") 81 kUriProxyTx, ///< Proxy TX ("c/ut") 82 kUriDiagnosticGetAnswer, ///< Network Diagnostic Get Answer ("d/da") 83 kUriDiagnosticGetRequest, ///< Network Diagnostic Get Request ("d/dg") 84 kUriDiagnosticGetQuery, ///< Network Diagnostic Get Query ("d/dq") 85 kUriDiagnosticReset, ///< Network Diagnostic Reset ("d/dr") 86 kUriDuaRegistrationNotify, ///< DUA Registration Notification ("n/dn") 87 kUriDuaRegistrationRequest, ///< DUA Registration Request ("n/dr") 88 kUriMlr, ///< Multicast Listener Registration ("n/mr") 89 kUriUnknown, ///< Unknown URI 90 }; 91 92 /** 93 * Returns URI path string for a given URI. 94 * 95 * @param[in] aUri A URI. 96 * 97 * @returns The path string for @p aUri. 98 * 99 */ 100 const char *PathForUri(Uri aUri); 101 102 /** 103 * Looks up the URI from a given path string. 104 * 105 * @param[in] aPath A path string. 106 * 107 * @returns The URI associated with @p aPath or `kUriUnknown` if no match is found. 108 * 109 */ 110 Uri UriFromPath(const char *aPath); 111 112 /** 113 * This template function converts a given URI to a human-readable string. 114 * 115 * @tparam kUri The URI to convert to string. 116 * 117 * @returns The string representation of @p kUri. 118 * 119 */ 120 template <Uri kUri> const char *UriToString(void); 121 122 // Declaring specializations of `UriToString` for every `Uri` 123 template <> const char *UriToString<kUriAddressError>(void); 124 template <> const char *UriToString<kUriAddressNotify>(void); 125 template <> const char *UriToString<kUriAddressQuery>(void); 126 template <> const char *UriToString<kUriAddressRelease>(void); 127 template <> const char *UriToString<kUriAddressSolicit>(void); 128 template <> const char *UriToString<kUriServerData>(void); 129 template <> const char *UriToString<kUriAnycastLocate>(void); 130 template <> const char *UriToString<kUriBackboneAnswer>(void); 131 template <> const char *UriToString<kUriBackboneMlr>(void); 132 template <> const char *UriToString<kUriBackboneQuery>(void); 133 template <> const char *UriToString<kUriAnnounceBegin>(void); 134 template <> const char *UriToString<kUriActiveGet>(void); 135 template <> const char *UriToString<kUriActiveReplace>(void); 136 template <> const char *UriToString<kUriActiveSet>(void); 137 template <> const char *UriToString<kUriCommissionerKeepAlive>(void); 138 template <> const char *UriToString<kUriCommissionerGet>(void); 139 template <> const char *UriToString<kUriCommissionerPetition>(void); 140 template <> const char *UriToString<kUriCommissionerSet>(void); 141 template <> const char *UriToString<kUriDatasetChanged>(void); 142 template <> const char *UriToString<kUriEnergyReport>(void); 143 template <> const char *UriToString<kUriEnergyScan>(void); 144 template <> const char *UriToString<kUriJoinerEntrust>(void); 145 template <> const char *UriToString<kUriJoinerFinalize>(void); 146 template <> const char *UriToString<kUriLeaderKeepAlive>(void); 147 template <> const char *UriToString<kUriLeaderPetition>(void); 148 template <> const char *UriToString<kUriPanIdConflict>(void); 149 template <> const char *UriToString<kUriPendingGet>(void); 150 template <> const char *UriToString<kUriPanIdQuery>(void); 151 template <> const char *UriToString<kUriPendingSet>(void); 152 template <> const char *UriToString<kUriRelayRx>(void); 153 template <> const char *UriToString<kUriRelayTx>(void); 154 template <> const char *UriToString<kUriProxyRx>(void); 155 template <> const char *UriToString<kUriProxyTx>(void); 156 template <> const char *UriToString<kUriDiagnosticGetAnswer>(void); 157 template <> const char *UriToString<kUriDiagnosticGetRequest>(void); 158 template <> const char *UriToString<kUriDiagnosticGetQuery>(void); 159 template <> const char *UriToString<kUriDiagnosticReset>(void); 160 template <> const char *UriToString<kUriDuaRegistrationNotify>(void); 161 template <> const char *UriToString<kUriDuaRegistrationRequest>(void); 162 template <> const char *UriToString<kUriMlr>(void); 163 164 } // namespace ot 165 166 #endif // URI_PATHS_HPP_ 167