1 /* 2 * Copyright (c) 2016, 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 the Thread network interface. 32 */ 33 34 #ifndef THREAD_NETIF_HPP_ 35 #define THREAD_NETIF_HPP_ 36 37 #include "openthread-core-config.h" 38 39 #include "coap/coap_secure.hpp" 40 #include "mac/mac.hpp" 41 #include "thread/tmf.hpp" 42 43 #if OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE 44 #include "meshcop/border_agent.hpp" 45 #endif 46 #if OPENTHREAD_CONFIG_COMMISSIONER_ENABLE && OPENTHREAD_FTD 47 #include "meshcop/commissioner.hpp" 48 #endif // OPENTHREAD_CONFIG_COMMISSIONER_ENABLE && OPENTHREAD_FTD 49 50 #if (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2) 51 #include "backbone_router/bbr_leader.hpp" 52 #endif 53 #if OPENTHREAD_FTD && OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE 54 #include "backbone_router/backbone_tmf.hpp" 55 #include "backbone_router/bbr_local.hpp" 56 #include "backbone_router/bbr_manager.hpp" 57 #endif 58 59 #if OPENTHREAD_CONFIG_MLR_ENABLE || (OPENTHREAD_FTD && OPENTHREAD_CONFIG_TMF_PROXY_MLR_ENABLE) 60 #include "thread/mlr_manager.hpp" 61 #endif 62 63 #if OPENTHREAD_CONFIG_DUA_ENABLE || (OPENTHREAD_FTD && OPENTHREAD_CONFIG_TMF_PROXY_DUA_ENABLE) 64 #include "thread/dua_manager.hpp" 65 #endif 66 67 #if OPENTHREAD_CONFIG_SRP_SERVER_ENABLE 68 #include "net/srp_server.hpp" 69 #endif 70 71 #include "meshcop/dataset_manager.hpp" 72 73 #if OPENTHREAD_CONFIG_JOINER_ENABLE 74 #include "meshcop/joiner.hpp" 75 #endif // OPENTHREAD_CONFIG_JOINER_ENABLE 76 77 #include "meshcop/joiner_router.hpp" 78 #include "meshcop/meshcop_leader.hpp" 79 #include "net/dhcp6.hpp" 80 #include "net/dhcp6_client.hpp" 81 #include "net/dhcp6_server.hpp" 82 #include "net/dns_client.hpp" 83 #include "net/dnssd_server.hpp" 84 #include "net/ip6_filter.hpp" 85 #include "net/nd_agent.hpp" 86 #include "net/netif.hpp" 87 #include "net/sntp_client.hpp" 88 #include "net/srp_client.hpp" 89 #include "thread/address_resolver.hpp" 90 #include "thread/announce_begin_server.hpp" 91 #include "thread/discover_scanner.hpp" 92 #include "thread/energy_scan_server.hpp" 93 #include "thread/key_manager.hpp" 94 #include "thread/link_metrics.hpp" 95 #include "thread/mesh_forwarder.hpp" 96 #include "thread/mle.hpp" 97 #include "thread/mle_router.hpp" 98 #include "thread/network_data_local.hpp" 99 #include "thread/network_data_notifier.hpp" 100 #include "thread/network_data_publisher.hpp" 101 #include "thread/network_data_service.hpp" 102 #include "thread/network_diagnostic.hpp" 103 #include "thread/panid_query_server.hpp" 104 #include "thread/radio_selector.hpp" 105 #include "thread/time_sync_service.hpp" 106 #include "utils/child_supervision.hpp" 107 #include "utils/srp_client_buffers.hpp" 108 109 #if OPENTHREAD_CONFIG_IP6_SLAAC_ENABLE 110 #include "utils/slaac_address.hpp" 111 #endif 112 113 #if OPENTHREAD_CONFIG_JAM_DETECTION_ENABLE 114 #include "utils/jam_detector.hpp" 115 #endif // OPENTHREAD_CONFIG_JAM_DETECTION_ENABLE 116 117 namespace ot { 118 119 /** 120 * @addtogroup core-netif 121 * 122 * @brief 123 * This module includes definitions for the Thread network interface. 124 * 125 * @{ 126 */ 127 128 class ThreadNetif : public Ip6::Netif 129 { 130 friend class Instance; 131 132 public: 133 /** 134 * This constructor initializes the Thread network interface. 135 * 136 * @param[in] aInstance A reference to the OpenThread instance. 137 * 138 */ 139 explicit ThreadNetif(Instance &aInstance); 140 141 /** 142 * This method enables the Thread network interface. 143 * 144 */ 145 void Up(void); 146 147 /** 148 * This method disables the Thread network interface. 149 * 150 */ 151 void Down(void); 152 153 /** 154 * This method indicates whether or not the Thread network interface is enabled. 155 * 156 * @retval TRUE If the Thread network interface is enabled. 157 * @retval FALSE If the Thread network interface is not enabled. 158 * 159 */ IsUp(void) const160 bool IsUp(void) const { return mIsUp; } 161 162 /** 163 * This method submits a message to the network interface. 164 * 165 * @param[in] aMessage A reference to the message. 166 * 167 * @retval kErrorNone Successfully submitted the message to the interface. 168 * 169 */ SendMessage(Message & aMessage)170 Error SendMessage(Message &aMessage) { return mMeshForwarder.SendMessage(aMessage); } 171 172 /** 173 * This method performs a route lookup. 174 * 175 * @param[in] aSource A reference to the IPv6 source address. 176 * @param[in] aDestination A reference to the IPv6 destination address. 177 * @param[out] aPrefixMatch A pointer where the number of prefix match bits for the chosen route is stored. 178 * 179 * @retval kErrorNone Successfully found a route. 180 * @retval kErrorNoRoute Could not find a valid route. 181 * 182 */ 183 Error RouteLookup(const Ip6::Address &aSource, const Ip6::Address &aDestination, uint8_t *aPrefixMatch); 184 185 /** 186 * This method indicates whether @p aAddress matches an on-mesh prefix. 187 * 188 * @param[in] aAddress The IPv6 address. 189 * 190 * @retval TRUE If @p aAddress matches an on-mesh prefix. 191 * @retval FALSE If @p aAddress does not match an on-mesh prefix. 192 * 193 */ 194 bool IsOnMesh(const Ip6::Address &aAddress) const; 195 196 private: 197 Tmf::Agent mTmfAgent; 198 #if OPENTHREAD_CONFIG_DHCP6_CLIENT_ENABLE 199 Dhcp6::Client mDhcp6Client; 200 #endif 201 #if OPENTHREAD_CONFIG_DHCP6_SERVER_ENABLE 202 Dhcp6::Server mDhcp6Server; 203 #endif 204 #if OPENTHREAD_CONFIG_NEIGHBOR_DISCOVERY_AGENT_ENABLE 205 NeighborDiscovery::Agent mNeighborDiscoveryAgent; 206 #endif 207 #if OPENTHREAD_CONFIG_IP6_SLAAC_ENABLE 208 Utils::Slaac mSlaac; 209 #endif 210 #if OPENTHREAD_CONFIG_DNS_CLIENT_ENABLE 211 Dns::Client mDnsClient; 212 #endif 213 #if OPENTHREAD_CONFIG_SRP_CLIENT_ENABLE 214 Srp::Client mSrpClient; 215 #endif 216 #if OPENTHREAD_CONFIG_SRP_CLIENT_BUFFERS_ENABLE 217 Utils::SrpClientBuffers mSrpClientBuffers; 218 #endif 219 #if OPENTHREAD_CONFIG_DNSSD_SERVER_ENABLE 220 Dns::ServiceDiscovery::Server mDnssdServer; 221 #endif 222 #if OPENTHREAD_CONFIG_SNTP_CLIENT_ENABLE 223 Sntp::Client mSntpClient; 224 #endif 225 MeshCoP::ActiveDataset mActiveDataset; 226 MeshCoP::PendingDataset mPendingDataset; 227 Ip6::Filter mIp6Filter; 228 KeyManager mKeyManager; 229 Lowpan::Lowpan mLowpan; 230 Mac::Mac mMac; 231 MeshForwarder mMeshForwarder; 232 Mle::MleRouter mMleRouter; 233 Mle::DiscoverScanner mDiscoverScanner; 234 #if OPENTHREAD_CONFIG_MULTI_RADIO 235 RadioSelector mRadioSelector; 236 #endif 237 #if OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE || OPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_ENABLE 238 NetworkData::Local mNetworkDataLocal; 239 #endif // OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE || OPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_ENABLE 240 NetworkData::Leader mNetworkDataLeader; 241 #if OPENTHREAD_FTD || OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE || OPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_ENABLE 242 NetworkData::Notifier mNetworkDataNotifier; 243 #endif 244 #if OPENTHREAD_CONFIG_NETDATA_PUBLISHER_ENABLE 245 NetworkData::Publisher mNetworkDataPublisher; 246 #endif 247 NetworkData::Service::Manager mNetworkDataServiceManager; 248 #if OPENTHREAD_FTD || OPENTHREAD_CONFIG_TMF_NETWORK_DIAG_MTD_ENABLE 249 NetworkDiagnostic::NetworkDiagnostic mNetworkDiagnostic; 250 #endif // OPENTHREAD_FTD || OPENTHREAD_CONFIG_TMF_NETWORK_DIAG_MTD_ENABLE 251 bool mIsUp; 252 253 #if OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE 254 MeshCoP::BorderAgent mBorderAgent; 255 #endif 256 #if OPENTHREAD_CONFIG_COMMISSIONER_ENABLE && OPENTHREAD_FTD 257 MeshCoP::Commissioner mCommissioner; 258 #endif // OPENTHREAD_CONFIG_COMMISSIONER_ENABLE 259 260 #if OPENTHREAD_CONFIG_DTLS_ENABLE 261 Coap::CoapSecure mCoapSecure; 262 #endif // OPENTHREAD_CONFIG_DTLS_ENABLE 263 264 #if OPENTHREAD_CONFIG_JOINER_ENABLE 265 MeshCoP::Joiner mJoiner; 266 #endif // OPENTHREAD_CONFIG_JOINER_ENABLE 267 268 #if OPENTHREAD_CONFIG_JAM_DETECTION_ENABLE 269 Utils::JamDetector mJamDetector; 270 #endif // OPENTHREAD_CONFIG_JAM_DETECTION_ENABLE 271 272 #if OPENTHREAD_FTD 273 MeshCoP::JoinerRouter mJoinerRouter; 274 MeshCoP::Leader mLeader; 275 AddressResolver mAddressResolver; 276 #endif // OPENTHREAD_FTD 277 278 #if (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2) 279 BackboneRouter::Leader mBackboneRouterLeader; 280 #endif 281 #if OPENTHREAD_FTD && OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE 282 BackboneRouter::Local mBackboneRouterLocal; 283 BackboneRouter::Manager mBackboneRouterManager; 284 #endif 285 #if OPENTHREAD_CONFIG_MLR_ENABLE || (OPENTHREAD_FTD && OPENTHREAD_CONFIG_TMF_PROXY_MLR_ENABLE) 286 MlrManager mMlrManager; 287 #endif 288 #if OPENTHREAD_CONFIG_DUA_ENABLE || (OPENTHREAD_FTD && OPENTHREAD_CONFIG_TMF_PROXY_DUA_ENABLE) 289 DuaManager mDuaManager; 290 #endif 291 #if OPENTHREAD_CONFIG_SRP_SERVER_ENABLE 292 Srp::Server mSrpServer; 293 #endif 294 295 #if OPENTHREAD_CONFIG_CHILD_SUPERVISION_ENABLE 296 #if OPENTHREAD_FTD 297 Utils::ChildSupervisor mChildSupervisor; 298 #endif 299 Utils::SupervisionListener mSupervisionListener; 300 #endif 301 AnnounceBeginServer mAnnounceBegin; 302 PanIdQueryServer mPanIdQuery; 303 EnergyScanServer mEnergyScan; 304 305 #if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE 306 TimeSync mTimeSync; 307 #endif 308 #if OPENTHREAD_CONFIG_MLE_LINK_METRICS_INITIATOR_ENABLE || OPENTHREAD_CONFIG_MLE_LINK_METRICS_SUBJECT_ENABLE 309 LinkMetrics::LinkMetrics mLinkMetrics; 310 #endif 311 }; 312 313 /** 314 * @} 315 */ 316 317 } // namespace ot 318 319 #endif // THREAD_NETIF_HPP_ 320