1 /*
2  *  Copyright (c) 2016-2017, 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 OpenThread instance class.
32  */
33 
34 #ifndef INSTANCE_HPP_
35 #define INSTANCE_HPP_
36 
37 #include "openthread-core-config.h"
38 
39 #include <stdbool.h>
40 #include <stdint.h>
41 
42 #include <openthread/heap.h>
43 #if OPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE
44 #include <openthread/platform/memory.h>
45 #endif
46 
47 #include "common/array.hpp"
48 #include "common/as_core_type.hpp"
49 #include "common/debug.hpp"
50 #include "common/error.hpp"
51 #include "common/heap.hpp"
52 #include "common/locator.hpp"
53 #include "common/log.hpp"
54 #include "common/message.hpp"
55 #include "common/non_copyable.hpp"
56 #include "common/random.hpp"
57 #include "common/serial_number.hpp"
58 #include "common/tasklet.hpp"
59 #include "common/time_ticker.hpp"
60 #include "common/timer.hpp"
61 #include "common/type_traits.hpp"
62 #include "common/uptime.hpp"
63 #include "diags/factory_diags.hpp"
64 #include "instance/extension.hpp"
65 #include "mac/link_raw.hpp"
66 #include "radio/radio.hpp"
67 #include "utils/otns.hpp"
68 #include "utils/power_calibration.hpp"
69 #include "utils/static_counter.hpp"
70 
71 #if OPENTHREAD_FTD || OPENTHREAD_MTD
72 #include "backbone_router/backbone_tmf.hpp"
73 #include "backbone_router/bbr_leader.hpp"
74 #include "backbone_router/bbr_local.hpp"
75 #include "backbone_router/bbr_manager.hpp"
76 #include "border_router/routing_manager.hpp"
77 #include "coap/coap_secure.hpp"
78 #include "common/code_utils.hpp"
79 #include "common/notifier.hpp"
80 #include "common/settings.hpp"
81 #include "crypto/mbedtls.hpp"
82 #include "crypto/storage.hpp"
83 #include "mac/mac.hpp"
84 #include "mac/wakeup_tx_scheduler.hpp"
85 #include "meshcop/border_agent.hpp"
86 #include "meshcop/commissioner.hpp"
87 #include "meshcop/dataset_manager.hpp"
88 #include "meshcop/dataset_updater.hpp"
89 #include "meshcop/extended_panid.hpp"
90 #include "meshcop/joiner.hpp"
91 #include "meshcop/joiner_router.hpp"
92 #include "meshcop/meshcop_leader.hpp"
93 #include "meshcop/network_name.hpp"
94 #include "net/dhcp6.hpp"
95 #include "net/dhcp6_client.hpp"
96 #include "net/dhcp6_server.hpp"
97 #include "net/dns_client.hpp"
98 #include "net/dns_dso.hpp"
99 #include "net/dnssd.hpp"
100 #include "net/dnssd_server.hpp"
101 #include "net/ip6.hpp"
102 #include "net/ip6_filter.hpp"
103 #include "net/mdns.hpp"
104 #include "net/nat64_translator.hpp"
105 #include "net/nd_agent.hpp"
106 #include "net/netif.hpp"
107 #include "net/sntp_client.hpp"
108 #include "net/srp_advertising_proxy.hpp"
109 #include "net/srp_client.hpp"
110 #include "net/srp_server.hpp"
111 #include "radio/ble_secure.hpp"
112 #include "thread/address_resolver.hpp"
113 #include "thread/announce_begin_server.hpp"
114 #include "thread/announce_sender.hpp"
115 #include "thread/anycast_locator.hpp"
116 #include "thread/child_supervision.hpp"
117 #include "thread/discover_scanner.hpp"
118 #include "thread/dua_manager.hpp"
119 #include "thread/energy_scan_server.hpp"
120 #include "thread/key_manager.hpp"
121 #include "thread/link_metrics.hpp"
122 #include "thread/link_quality.hpp"
123 #include "thread/mesh_forwarder.hpp"
124 #include "thread/mle.hpp"
125 #include "thread/mle_router.hpp"
126 #include "thread/mlr_manager.hpp"
127 #include "thread/network_data_local.hpp"
128 #include "thread/network_data_notifier.hpp"
129 #include "thread/network_data_publisher.hpp"
130 #include "thread/network_data_service.hpp"
131 #include "thread/network_diagnostic.hpp"
132 #include "thread/panid_query_server.hpp"
133 #include "thread/radio_selector.hpp"
134 #include "thread/thread_netif.hpp"
135 #include "thread/time_sync_service.hpp"
136 #include "thread/tmf.hpp"
137 #include "utils/channel_manager.hpp"
138 #include "utils/channel_monitor.hpp"
139 #include "utils/heap.hpp"
140 #include "utils/history_tracker.hpp"
141 #include "utils/jam_detector.hpp"
142 #include "utils/link_metrics_manager.hpp"
143 #include "utils/mesh_diag.hpp"
144 #include "utils/ping_sender.hpp"
145 #include "utils/slaac_address.hpp"
146 #include "utils/srp_client_buffers.hpp"
147 #endif // OPENTHREAD_FTD || OPENTHREAD_MTD
148 
149 /**
150  * @addtogroup core-instance
151  *
152  * @brief
153  *   This module includes definitions for OpenThread instance.
154  *
155  * @{
156  */
157 
158 /**
159  * Represents an opaque (and empty) type corresponding to an OpenThread instance object.
160  */
161 typedef struct otInstance
162 {
163 } otInstance;
164 
165 namespace ot {
166 
167 /**
168  * Represents an OpenThread instance.
169  *
170  * Contains all the components used by OpenThread.
171  */
172 class Instance : public otInstance, private NonCopyable
173 {
174 public:
175     /**
176      * Represents the message buffer information (number of messages/buffers in all OT stack message queues).
177      */
178     class BufferInfo : public otBufferInfo, public Clearable<BufferInfo>
179     {
180     };
181 
182 #if OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE
183     /**
184       * Initializes the OpenThread instance.
185       *
186       * Must be called before any other calls on OpenThread instance.
187       *
188       * @param[in]     aBuffer      The buffer for OpenThread to use for allocating the Instance.
189       * @param[in,out] aBufferSize  On input, the size of `aBuffer`. On output, if not enough space for `Instance`, the
190                                     number of bytes required for `Instance`.
191       *
192       * @returns  A pointer to the new OpenThread instance.
193       */
194     static Instance *Init(void *aBuffer, size_t *aBufferSize);
195 
196 #if OPENTHREAD_CONFIG_MULTIPLE_STATIC_INSTANCE_ENABLE
197     /**
198      * This static method initializes the OpenThread instance.
199      *
200      * This method utilizes static buffer to initialize the OpenThread instance.
201      * This function must be called before any other calls on OpenThread instance.
202      *
203      * @param[in] aIdx The index of the OpenThread instance to initialize.
204      *
205      * @returns  A pointer to the new OpenThread instance.
206      */
207     static Instance *InitMultiple(uint8_t aIdx);
208 
209     /**
210      * Returns a reference to the OpenThread instance.
211      *
212      * @param[in] aIdx The index of the OpenThread instance to get.
213      *
214      * @returns A reference to the OpenThread instance.
215      */
216     static Instance &Get(uint8_t aIdx);
217 
218     /**
219      * Returns the index of the OpenThread instance.
220      *
221      * @param[in] aInstance The reference of the OpenThread instance to get index.
222      *
223      * @returns The index of the OpenThread instance.
224      */
225     static uint8_t GetIdx(Instance *aInstance);
226 #endif
227 
228 #else // OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE
229 
230     /**
231      * Initializes the single OpenThread instance.
232      *
233      * Initializes OpenThread and prepares it for subsequent OpenThread API calls. This function must be
234      * called before any other calls to OpenThread.
235      *
236      * @returns A reference to the single OpenThread instance.
237      */
238     static Instance &InitSingle(void);
239 
240     /**
241      * Returns a reference to the single OpenThread instance.
242      *
243      * @returns A reference to the single OpenThread instance.
244      */
245     static Instance &Get(void);
246 #endif
247 
248     /**
249      * Gets the instance identifier.
250      *
251      * The instance identifier is set to a random value when the instance is constructed, and then its value will not
252      * change after initialization.
253      *
254      * @returns The instance identifier.
255      */
GetId(void) const256     uint32_t GetId(void) const { return mId; }
257 
258 #if OPENTHREAD_PLATFORM_NEXUS
259     /**
260      * Sets the instance identifier.
261      *
262      * @param[in] aId  The identifier to assign to the `Instance`.
263      */
SetId(uint32_t aId)264     void SetId(uint32_t aId) { mId = aId; }
265 #endif
266 
267     /**
268      * Indicates whether or not the instance is valid/initialized and not yet finalized.
269      *
270      * @returns TRUE if the instance is valid/initialized, FALSE otherwise.
271      */
IsInitialized(void) const272     bool IsInitialized(void) const { return mIsInitialized; }
273 
274     /**
275      * Triggers a platform reset.
276      *
277      * The reset process ensures that all the OpenThread state/info (stored in volatile memory) is erased. Note that
278      * this method does not erase any persistent state/info saved in non-volatile memory.
279      */
280     void Reset(void);
281 
282 #if OPENTHREAD_CONFIG_PLATFORM_BOOTLOADER_MODE_ENABLE
283     /**
284      * Triggers a platform reset to bootloader mode, if supported.
285      *
286      * @retval kErrorNone        Reset to bootloader successfully.
287      * @retval kErrorBusy        Failed due to another operation is ongoing.
288      * @retval kErrorNotCapable  Not capable of resetting to bootloader.
289      */
290     Error ResetToBootloader(void);
291 #endif
292 
293 #if OPENTHREAD_RADIO
294     /**
295      * Resets the internal states of the radio.
296      */
297     void ResetRadioStack(void);
298 #endif
299 
300     /**
301      * Returns the active log level.
302      *
303      * @returns The log level.
304      */
GetLogLevel(void)305     static LogLevel GetLogLevel(void)
306 #if OPENTHREAD_CONFIG_LOG_LEVEL_DYNAMIC_ENABLE
307     {
308         return sLogLevel;
309     }
310 #else
311     {
312         return static_cast<LogLevel>(OPENTHREAD_CONFIG_LOG_LEVEL);
313     }
314 #endif
315 
316 #if OPENTHREAD_CONFIG_LOG_LEVEL_DYNAMIC_ENABLE
317     /**
318      * Sets the log level.
319      *
320      * @param[in] aLogLevel  A log level.
321      */
322     static void SetLogLevel(LogLevel aLogLevel);
323 #endif
324 
325     /**
326      * Finalizes the OpenThread instance.
327      *
328      * Should be called when OpenThread instance is no longer in use.
329      */
330     void Finalize(void);
331 
332 #if OPENTHREAD_MTD || OPENTHREAD_FTD
333     /**
334      * Deletes all the settings stored in non-volatile memory, and then triggers a platform reset.
335      */
336     void FactoryReset(void);
337 
338     /**
339      * Erases all the OpenThread persistent info (network settings) stored in non-volatile memory.
340      *
341      * Erase is successful/allowed only if the device is in `disabled` state/role.
342      *
343      * @retval kErrorNone          All persistent info/state was erased successfully.
344      * @retval kErrorInvalidState  Device is not in `disabled` state/role.
345      */
346     Error ErasePersistentInfo(void);
347 
348 #if !OPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE
349     /**
350      * Returns a reference to the Heap object.
351      *
352      * @returns A reference to the Heap object.
353      */
354     static Utils::Heap &GetHeap(void);
355 #endif
356 
357 #if OPENTHREAD_CONFIG_COAP_API_ENABLE
358     /**
359      * Returns a reference to application COAP object.
360      *
361      * @returns A reference to the application COAP object.
362      */
GetApplicationCoap(void)363     Coap::Coap &GetApplicationCoap(void) { return mApplicationCoap; }
364 #endif
365 
366 #if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE
367     /**
368      * Returns a reference to application COAP Secure object.
369      *
370      * @returns A reference to the application COAP Secure object.
371      */
GetApplicationCoapSecure(void)372     Coap::ApplicationCoapSecure &GetApplicationCoapSecure(void) { return mApplicationCoapSecure; }
373 #endif
374 
375 #if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
376     /**
377      * Enables/disables the "DNS name compressions" mode.
378      *
379      * By default DNS name compression is enabled. When disabled, DNS names are appended as full and never compressed.
380      * This is applicable to OpenThread's DNS and SRP client/server modules.
381      *
382      * This is intended for testing only and available under a `REFERENCE_DEVICE` config.
383      *
384      * @param[in] aEnabled   TRUE to enable the "DNS name compression" mode, FALSE to disable.
385      */
SetDnsNameCompressionEnabled(bool aEnabled)386     static void SetDnsNameCompressionEnabled(bool aEnabled) { sDnsNameCompressionEnabled = aEnabled; }
387 
388     /**
389      * Indicates whether the "DNS name compression" mode is enabled or not.
390      *
391      * @returns TRUE if the "DNS name compressions" mode is enabled, FALSE otherwise.
392      */
IsDnsNameCompressionEnabled(void)393     static bool IsDnsNameCompressionEnabled(void) { return sDnsNameCompressionEnabled; }
394 #endif
395 
396     /**
397      * Retrieves the the Message Buffer information.
398      *
399      * @param[out]  aInfo  A `BufferInfo` where information is written.
400      */
401     void GetBufferInfo(BufferInfo &aInfo);
402 
403     /**
404      * Resets the Message Buffer information counter tracking maximum number buffers in use at the same
405      * time.
406      *
407      * Resets `mMaxUsedBuffers` in `BufferInfo`.
408      */
409     void ResetBufferInfo(void);
410 
411 #endif // OPENTHREAD_MTD || OPENTHREAD_FTD
412 
413     /**
414      * Returns a reference to a given `Type` object belonging to the OpenThread instance.
415      *
416      * For example, `Get<MeshForwarder>()` returns a reference to the `MeshForwarder` object of the instance.
417      *
418      * Note that any `Type` for which the `Get<Type>` is defined MUST be uniquely accessible from the OpenThread
419      * `Instance` through the member variable property hierarchy.
420      *
421      * Specializations of the `Get<Type>()` method are defined in this file after the `Instance` class definition.
422      *
423      * @returns A reference to the `Type` object of the instance.
424      */
425     template <typename Type> inline Type &Get(void);
426 
427 #if OPENTHREAD_PLATFORM_NEXUS
428     /**
429      * Constructor to initialize an `Instance`
430      */
431     Instance(void);
432 
433     /**
434      * Called after constructor initialization.
435      */
436     void AfterInit(void);
437 #endif
438 
439 private:
440 #if !OPENTHREAD_PLATFORM_NEXUS
441     Instance(void);
442     void AfterInit(void);
443 #endif
444 
445     // Order of variables (their initialization in `Instance`)
446     // is important.
447     //
448     // Tasklet and Timer Schedulers are first to ensure other
449     // objects/classes can use them from their constructors.
450 
451     Tasklet::Scheduler    mTaskletScheduler;
452     TimerMilli::Scheduler mTimerMilliScheduler;
453 #if OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE
454     TimerMicro::Scheduler mTimerMicroScheduler;
455 #endif
456 
457 #if OPENTHREAD_MTD || OPENTHREAD_FTD
458     // Random::Manager is initialized before other objects. Note that it
459     // requires MbedTls which itself may use Heap.
460 #if !OPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE
461     static Utils::Heap *sHeap;
462 #endif
463     Crypto::MbedTls mMbedTls;
464 #endif // OPENTHREAD_MTD || OPENTHREAD_FTD
465 
466     Random::Manager mRandomManager;
467 
468 #if OPENTHREAD_CONFIG_PLATFORM_KEY_REFERENCES_ENABLE
469     Crypto::Storage::KeyRefManager mCryptoStorageKeyRefManager;
470 #endif
471 
472     // Radio is initialized before other member variables
473     // (particularly, SubMac and Mac) to allow them to use its methods
474     // from their constructor.
475     Radio mRadio;
476 
477 #if OPENTHREAD_CONFIG_UPTIME_ENABLE
478     Uptime mUptime;
479 #endif
480 
481 #if OPENTHREAD_MTD || OPENTHREAD_FTD
482     // Notifier, TimeTicker, Settings, and MessagePool are initialized
483     // before other member variables since other classes/objects from
484     // their constructor may use them.
485     Notifier       mNotifier;
486     TimeTicker     mTimeTicker;
487     Settings       mSettings;
488     SettingsDriver mSettingsDriver;
489     MessagePool    mMessagePool;
490 
491 #if OPENTHREAD_CONFIG_PLATFORM_DNSSD_ENABLE || OPENTHREAD_CONFIG_MULTICAST_DNS_ENABLE
492     // DNS-SD (mDNS) platform is initialized early to
493     // allow other modules to use it.
494     Dnssd mDnssd;
495 #endif
496 
497     Ip6::Ip6    mIp6;
498     ThreadNetif mThreadNetif;
499     Tmf::Agent  mTmfAgent;
500 
501 #if OPENTHREAD_CONFIG_DHCP6_CLIENT_ENABLE
502     Dhcp6::Client mDhcp6Client;
503 #endif
504 
505 #if OPENTHREAD_CONFIG_DHCP6_SERVER_ENABLE
506     Dhcp6::Server mDhcp6Server;
507 #endif
508 
509 #if OPENTHREAD_CONFIG_NEIGHBOR_DISCOVERY_AGENT_ENABLE
510     NeighborDiscovery::Agent mNeighborDiscoveryAgent;
511 #endif
512 
513 #if OPENTHREAD_CONFIG_IP6_SLAAC_ENABLE
514     Utils::Slaac mSlaac;
515 #endif
516 
517 #if OPENTHREAD_CONFIG_DNS_CLIENT_ENABLE
518     Dns::Client mDnsClient;
519 #endif
520 
521 #if OPENTHREAD_CONFIG_SRP_CLIENT_ENABLE
522     Srp::Client mSrpClient;
523 #endif
524 
525 #if OPENTHREAD_CONFIG_SRP_CLIENT_BUFFERS_ENABLE
526     Utils::SrpClientBuffers mSrpClientBuffers;
527 #endif
528 
529 #if OPENTHREAD_CONFIG_DNSSD_SERVER_ENABLE
530     Dns::ServiceDiscovery::Server mDnssdServer;
531 #endif
532 
533 #if OPENTHREAD_CONFIG_DNS_DSO_ENABLE
534     Dns::Dso mDnsDso;
535 #endif
536 
537 #if OPENTHREAD_CONFIG_MULTICAST_DNS_ENABLE
538     Dns::Multicast::Core mMdnsCore;
539 #endif
540 
541 #if OPENTHREAD_CONFIG_SNTP_CLIENT_ENABLE
542     Sntp::Client mSntpClient;
543 #endif
544 
545 #if OPENTHREAD_FTD && OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE
546     BackboneRouter::Local mBackboneRouterLocal;
547 #endif
548 
549     MeshCoP::ActiveDatasetManager  mActiveDataset;
550     MeshCoP::PendingDatasetManager mPendingDataset;
551     MeshCoP::ExtendedPanIdManager  mExtendedPanIdManager;
552     MeshCoP::NetworkNameManager    mNetworkNameManager;
553     Ip6::Filter                    mIp6Filter;
554     KeyManager                     mKeyManager;
555     Lowpan::Lowpan                 mLowpan;
556     Mac::Mac                       mMac;
557     MeshForwarder                  mMeshForwarder;
558     Mle::MleRouter                 mMleRouter;
559     Mle::DiscoverScanner           mDiscoverScanner;
560     AddressResolver                mAddressResolver;
561 
562 #if OPENTHREAD_CONFIG_MULTI_RADIO
563     RadioSelector mRadioSelector;
564 #endif
565 
566 #if OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE || OPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_ENABLE
567     NetworkData::Local mNetworkDataLocal;
568 #endif
569 
570     NetworkData::Leader mNetworkDataLeader;
571 
572 #if OPENTHREAD_FTD || OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE || OPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_ENABLE
573     NetworkData::Notifier mNetworkDataNotifier;
574 #endif
575 
576 #if OPENTHREAD_CONFIG_NETDATA_PUBLISHER_ENABLE
577     NetworkData::Publisher mNetworkDataPublisher;
578 #endif
579 
580     NetworkData::Service::Manager mNetworkDataServiceManager;
581 
582     NetworkDiagnostic::Server mNetworkDiagnosticServer;
583 #if OPENTHREAD_CONFIG_TMF_NETDIAG_CLIENT_ENABLE
584     NetworkDiagnostic::Client mNetworkDiagnosticClient;
585 #endif
586 
587 #if OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE
588     MeshCoP::BorderAgent mBorderAgent;
589 #endif
590 
591 #if OPENTHREAD_CONFIG_COMMISSIONER_ENABLE && OPENTHREAD_FTD
592     MeshCoP::Commissioner mCommissioner;
593 #endif
594 
595 #if OPENTHREAD_CONFIG_SECURE_TRANSPORT_ENABLE
596     Tmf::SecureAgent mTmfSecureAgent;
597 #endif
598 
599 #if OPENTHREAD_CONFIG_JOINER_ENABLE
600     MeshCoP::Joiner mJoiner;
601 #endif
602 
603 #if OPENTHREAD_CONFIG_JAM_DETECTION_ENABLE
604     Utils::JamDetector mJamDetector;
605 #endif
606 
607 #if OPENTHREAD_FTD
608     MeshCoP::JoinerRouter mJoinerRouter;
609     MeshCoP::Leader       mLeader;
610 #endif
611 
612 #if (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)
613     BackboneRouter::Leader mBackboneRouterLeader;
614 #endif
615 
616 #if OPENTHREAD_FTD && OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE
617     BackboneRouter::Manager mBackboneRouterManager;
618 #endif
619 
620 #if OPENTHREAD_CONFIG_MLR_ENABLE || (OPENTHREAD_FTD && OPENTHREAD_CONFIG_TMF_PROXY_MLR_ENABLE)
621     MlrManager mMlrManager;
622 #endif
623 
624 #if OPENTHREAD_CONFIG_DUA_ENABLE || (OPENTHREAD_FTD && OPENTHREAD_CONFIG_TMF_PROXY_DUA_ENABLE)
625     DuaManager mDuaManager;
626 #endif
627 
628 #if OPENTHREAD_CONFIG_SRP_SERVER_ENABLE
629     Srp::Server mSrpServer;
630 #if OPENTHREAD_CONFIG_SRP_SERVER_ADVERTISING_PROXY_ENABLE
631     Srp::AdvertisingProxy mSrpAdvertisingProxy;
632 #endif
633 #endif
634 
635 #if OPENTHREAD_FTD
636     ChildSupervisor mChildSupervisor;
637 #endif
638     SupervisionListener mSupervisionListener;
639 
640     AnnounceBeginServer mAnnounceBegin;
641     PanIdQueryServer    mPanIdQuery;
642     EnergyScanServer    mEnergyScan;
643 
644 #if OPENTHREAD_CONFIG_TMF_ANYCAST_LOCATOR_ENABLE
645     AnycastLocator mAnycastLocator;
646 #endif
647 
648 #if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE
649     TimeSync mTimeSync;
650 #endif
651 
652 #if OPENTHREAD_CONFIG_MLE_LINK_METRICS_INITIATOR_ENABLE
653     LinkMetrics::Initiator mInitiator;
654 #endif
655 
656 #if OPENTHREAD_CONFIG_MLE_LINK_METRICS_SUBJECT_ENABLE
657     LinkMetrics::Subject mSubject;
658 #endif
659 
660 #if OPENTHREAD_CONFIG_COAP_API_ENABLE
661     Coap::Coap mApplicationCoap;
662 #endif
663 
664 #if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE
665     Coap::ApplicationCoapSecure mApplicationCoapSecure;
666 #endif
667 
668 #if OPENTHREAD_CONFIG_BLE_TCAT_ENABLE
669     Ble::BleSecure mApplicationBleSecure;
670 #endif
671 
672 #if OPENTHREAD_CONFIG_PING_SENDER_ENABLE
673     Utils::PingSender mPingSender;
674 #endif
675 
676 #if OPENTHREAD_CONFIG_CHANNEL_MONITOR_ENABLE
677     Utils::ChannelMonitor mChannelMonitor;
678 #endif
679 
680 #if OPENTHREAD_CONFIG_CHANNEL_MANAGER_ENABLE && \
681     (OPENTHREAD_FTD || OPENTHREAD_CONFIG_CHANNEL_MANAGER_CSL_CHANNEL_SELECT_ENABLE)
682     Utils::ChannelManager mChannelManager;
683 #endif
684 
685 #if OPENTHREAD_CONFIG_MESH_DIAG_ENABLE && OPENTHREAD_FTD
686     Utils::MeshDiag mMeshDiag;
687 #endif
688 
689 #if OPENTHREAD_CONFIG_HISTORY_TRACKER_ENABLE
690     Utils::HistoryTracker mHistoryTracker;
691 #endif
692 
693 #if OPENTHREAD_CONFIG_LINK_METRICS_MANAGER_ENABLE
694     Utils::LinkMetricsManager mLinkMetricsManager;
695 #endif
696 
697 #if (OPENTHREAD_CONFIG_DATASET_UPDATER_ENABLE || OPENTHREAD_CONFIG_CHANNEL_MANAGER_ENABLE) && OPENTHREAD_FTD
698     MeshCoP::DatasetUpdater mDatasetUpdater;
699 #endif
700 
701 #if OPENTHREAD_CONFIG_ANNOUNCE_SENDER_ENABLE
702     AnnounceSender mAnnounceSender;
703 #endif
704 
705 #if OPENTHREAD_CONFIG_OTNS_ENABLE
706     Utils::Otns mOtns;
707 #endif
708 
709 #if OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE
710     BorderRouter::RoutingManager mRoutingManager;
711 #endif
712 
713 #if OPENTHREAD_CONFIG_NAT64_TRANSLATOR_ENABLE
714     Nat64::Translator mNat64Translator;
715 #endif
716 
717 #endif // OPENTHREAD_MTD || OPENTHREAD_FTD
718 
719 #if OPENTHREAD_RADIO || OPENTHREAD_CONFIG_LINK_RAW_ENABLE
720     Mac::LinkRaw mLinkRaw;
721 #endif
722 
723 #if OPENTHREAD_CONFIG_LOG_LEVEL_DYNAMIC_ENABLE
724     static LogLevel sLogLevel;
725 #endif
726 
727 #if OPENTHREAD_ENABLE_VENDOR_EXTENSION
728     Extension::ExtensionBase &mExtension;
729 #endif
730 
731 #if OPENTHREAD_CONFIG_DIAG_ENABLE
732     FactoryDiags::Diags mDiags;
733 #endif
734 #if OPENTHREAD_CONFIG_POWER_CALIBRATION_ENABLE && OPENTHREAD_CONFIG_PLATFORM_POWER_CALIBRATION_ENABLE
735     Utils::PowerCalibration mPowerCalibration;
736 #endif
737 
738     bool mIsInitialized;
739 
740 #if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE && (OPENTHREAD_FTD || OPENTHREAD_MTD)
741     static bool sDnsNameCompressionEnabled;
742 #endif
743 
744     uint32_t mId;
745 };
746 
747 DefineCoreType(otInstance, Instance);
748 DefineCoreType(otBufferInfo, Instance::BufferInfo);
749 
750 // Specializations of the `Get<Type>()` method.
751 
Get(void)752 template <> inline Instance &Instance::Get(void) { return *this; }
753 
Get(void)754 template <> inline Radio &Instance::Get(void) { return mRadio; }
755 
Get(void)756 template <> inline Radio::Callbacks &Instance::Get(void) { return mRadio.mCallbacks; }
757 
758 #if OPENTHREAD_CONFIG_RADIO_STATS_ENABLE && (OPENTHREAD_FTD || OPENTHREAD_MTD)
Get(void)759 template <> inline Radio::Statistics &Instance::Get(void) { return mRadio.mStatistics; }
760 #endif
761 
762 #if OPENTHREAD_CONFIG_UPTIME_ENABLE
Get(void)763 template <> inline Uptime &Instance::Get(void) { return mUptime; }
764 #endif
765 
766 #if OPENTHREAD_MTD || OPENTHREAD_FTD
Get(void)767 template <> inline Notifier &Instance::Get(void) { return mNotifier; }
768 
Get(void)769 template <> inline TimeTicker &Instance::Get(void) { return mTimeTicker; }
770 
Get(void)771 template <> inline Settings &Instance::Get(void) { return mSettings; }
772 
Get(void)773 template <> inline SettingsDriver &Instance::Get(void) { return mSettingsDriver; }
774 
Get(void)775 template <> inline MeshForwarder &Instance::Get(void) { return mMeshForwarder; }
776 
777 #if OPENTHREAD_CONFIG_PLATFORM_KEY_REFERENCES_ENABLE
Get(void)778 template <> inline Crypto::Storage::KeyRefManager &Instance::Get(void) { return mCryptoStorageKeyRefManager; }
779 #endif
780 
781 #if OPENTHREAD_CONFIG_MULTI_RADIO
Get(void)782 template <> inline RadioSelector &Instance::Get(void) { return mRadioSelector; }
783 #endif
784 
Get(void)785 template <> inline Mle::Mle &Instance::Get(void) { return mMleRouter; }
786 
787 #if OPENTHREAD_FTD
Get(void)788 template <> inline Mle::MleRouter &Instance::Get(void) { return mMleRouter; }
789 #endif
790 
Get(void)791 template <> inline Mle::DiscoverScanner &Instance::Get(void) { return mDiscoverScanner; }
792 
Get(void)793 template <> inline NeighborTable &Instance::Get(void) { return mMleRouter.mNeighborTable; }
794 
795 #if OPENTHREAD_FTD
Get(void)796 template <> inline ChildTable &Instance::Get(void) { return mMleRouter.mChildTable; }
797 
Get(void)798 template <> inline RouterTable &Instance::Get(void) { return mMleRouter.mRouterTable; }
799 #endif
800 
801 #if OPENTHREAD_CONFIG_WAKEUP_COORDINATOR_ENABLE
Get(void)802 template <> inline WakeupTxScheduler &Instance::Get(void) { return mMleRouter.mWakeupTxScheduler; }
803 #endif
804 
Get(void)805 template <> inline Ip6::Netif &Instance::Get(void) { return mThreadNetif; }
806 
Get(void)807 template <> inline ThreadNetif &Instance::Get(void) { return mThreadNetif; }
808 
Get(void)809 template <> inline Ip6::Ip6 &Instance::Get(void) { return mIp6; }
810 
Get(void)811 template <> inline Mac::Mac &Instance::Get(void) { return mMac; }
812 
Get(void)813 template <> inline Mac::SubMac &Instance::Get(void) { return mMac.mLinks.mSubMac; }
814 
815 #if OPENTHREAD_CONFIG_RADIO_LINK_TREL_ENABLE
Get(void)816 template <> inline Trel::Link &Instance::Get(void) { return mMac.mLinks.mTrel; }
817 
Get(void)818 template <> inline Trel::Interface &Instance::Get(void) { return mMac.mLinks.mTrel.mInterface; }
819 #endif
820 
821 #if OPENTHREAD_CONFIG_MAC_FILTER_ENABLE
Get(void)822 template <> inline Mac::Filter &Instance::Get(void) { return mMac.mFilter; }
823 #endif
824 
Get(void)825 template <> inline Lowpan::Lowpan &Instance::Get(void) { return mLowpan; }
826 
Get(void)827 template <> inline KeyManager &Instance::Get(void) { return mKeyManager; }
828 
Get(void)829 template <> inline Ip6::Filter &Instance::Get(void) { return mIp6Filter; }
830 
Get(void)831 template <> inline AddressResolver &Instance::Get(void) { return mAddressResolver; }
832 
833 #if OPENTHREAD_FTD || OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE
Get(void)834 template <> inline IndirectSender &Instance::Get(void) { return mMeshForwarder.mIndirectSender; }
835 #endif
836 
837 #if OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE
Get(void)838 template <> inline CslTxScheduler &Instance::Get(void) { return mMeshForwarder.mIndirectSender.mCslTxScheduler; }
839 #endif
840 
841 #if OPENTHREAD_FTD
842 
Get(void)843 template <> inline SourceMatchController &Instance::Get(void)
844 {
845     return mMeshForwarder.mIndirectSender.mSourceMatchController;
846 }
847 
Get(void)848 template <> inline DataPollHandler &Instance::Get(void) { return mMeshForwarder.mIndirectSender.mDataPollHandler; }
849 
Get(void)850 template <> inline MeshCoP::Leader &Instance::Get(void) { return mLeader; }
851 
Get(void)852 template <> inline MeshCoP::JoinerRouter &Instance::Get(void) { return mJoinerRouter; }
853 #endif // OPENTHREAD_FTD
854 
Get(void)855 template <> inline AnnounceBeginServer &Instance::Get(void) { return mAnnounceBegin; }
856 
Get(void)857 template <> inline DataPollSender &Instance::Get(void) { return mMeshForwarder.mDataPollSender; }
858 
Get(void)859 template <> inline EnergyScanServer &Instance::Get(void) { return mEnergyScan; }
860 
Get(void)861 template <> inline PanIdQueryServer &Instance::Get(void) { return mPanIdQuery; }
862 
863 #if OPENTHREAD_CONFIG_TMF_ANYCAST_LOCATOR_ENABLE
Get(void)864 template <> inline AnycastLocator &Instance::Get(void) { return mAnycastLocator; }
865 #endif
866 
867 #if OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE || OPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_ENABLE
Get(void)868 template <> inline NetworkData::Local &Instance::Get(void) { return mNetworkDataLocal; }
869 #endif
870 
Get(void)871 template <> inline NetworkData::Leader &Instance::Get(void) { return mNetworkDataLeader; }
872 
873 #if OPENTHREAD_FTD || OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE || OPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_ENABLE
Get(void)874 template <> inline NetworkData::Notifier &Instance::Get(void) { return mNetworkDataNotifier; }
875 #endif
876 
877 #if OPENTHREAD_CONFIG_NETDATA_PUBLISHER_ENABLE
Get(void)878 template <> inline NetworkData::Publisher &Instance::Get(void) { return mNetworkDataPublisher; }
879 #endif
880 
Get(void)881 template <> inline NetworkData::Service::Manager &Instance::Get(void) { return mNetworkDataServiceManager; }
882 
883 #if OPENTHREAD_CONFIG_TCP_ENABLE
Get(void)884 template <> inline Ip6::Tcp &Instance::Get(void) { return mIp6.mTcp; }
885 #endif
886 
Get(void)887 template <> inline Ip6::Udp &Instance::Get(void) { return mIp6.mUdp; }
888 
Get(void)889 template <> inline Ip6::Icmp &Instance::Get(void) { return mIp6.mIcmp; }
890 
Get(void)891 template <> inline Ip6::Mpl &Instance::Get(void) { return mIp6.mMpl; }
892 
Get(void)893 template <> inline Tmf::Agent &Instance::Get(void) { return mTmfAgent; }
894 
895 #if OPENTHREAD_CONFIG_SECURE_TRANSPORT_ENABLE
Get(void)896 template <> inline Tmf::SecureAgent &Instance::Get(void) { return mTmfSecureAgent; }
897 #endif
898 
Get(void)899 template <> inline MeshCoP::ExtendedPanIdManager &Instance::Get(void) { return mExtendedPanIdManager; }
900 
Get(void)901 template <> inline MeshCoP::NetworkNameManager &Instance::Get(void) { return mNetworkNameManager; }
902 
Get(void)903 template <> inline MeshCoP::ActiveDatasetManager &Instance::Get(void) { return mActiveDataset; }
904 
Get(void)905 template <> inline MeshCoP::PendingDatasetManager &Instance::Get(void) { return mPendingDataset; }
906 
907 #if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE
Get(void)908 template <> inline TimeSync &Instance::Get(void) { return mTimeSync; }
909 #endif
910 
911 #if OPENTHREAD_CONFIG_COMMISSIONER_ENABLE && OPENTHREAD_FTD
Get(void)912 template <> inline MeshCoP::Commissioner &Instance::Get(void) { return mCommissioner; }
913 
Get(void)914 template <> inline AnnounceBeginClient &Instance::Get(void) { return mCommissioner.GetAnnounceBeginClient(); }
915 
Get(void)916 template <> inline EnergyScanClient &Instance::Get(void) { return mCommissioner.GetEnergyScanClient(); }
917 
Get(void)918 template <> inline PanIdQueryClient &Instance::Get(void) { return mCommissioner.GetPanIdQueryClient(); }
919 #endif
920 
921 #if OPENTHREAD_CONFIG_PLATFORM_DNSSD_ENABLE || OPENTHREAD_CONFIG_MULTICAST_DNS_ENABLE
Get(void)922 template <> inline Dnssd &Instance::Get(void) { return mDnssd; }
923 #endif
924 
925 #if OPENTHREAD_CONFIG_JOINER_ENABLE
Get(void)926 template <> inline MeshCoP::Joiner &Instance::Get(void) { return mJoiner; }
927 #endif
928 
929 #if OPENTHREAD_CONFIG_DNS_CLIENT_ENABLE
Get(void)930 template <> inline Dns::Client &Instance::Get(void) { return mDnsClient; }
931 #endif
932 
933 #if OPENTHREAD_CONFIG_SRP_CLIENT_ENABLE
Get(void)934 template <> inline Srp::Client &Instance::Get(void) { return mSrpClient; }
935 #endif
936 
937 #if OPENTHREAD_CONFIG_SRP_CLIENT_BUFFERS_ENABLE
Get(void)938 template <> inline Utils::SrpClientBuffers &Instance::Get(void) { return mSrpClientBuffers; }
939 #endif
940 
941 #if OPENTHREAD_CONFIG_DNSSD_SERVER_ENABLE
Get(void)942 template <> inline Dns::ServiceDiscovery::Server &Instance::Get(void) { return mDnssdServer; }
943 #endif
944 
945 #if OPENTHREAD_CONFIG_DNS_DSO_ENABLE
Get(void)946 template <> inline Dns::Dso &Instance::Get(void) { return mDnsDso; }
947 #endif
948 
949 #if OPENTHREAD_CONFIG_MULTICAST_DNS_ENABLE
Get(void)950 template <> inline Dns::Multicast::Core &Instance::Get(void) { return mMdnsCore; }
951 #endif
952 
Get(void)953 template <> inline NetworkDiagnostic::Server &Instance::Get(void) { return mNetworkDiagnosticServer; }
954 
955 #if OPENTHREAD_CONFIG_TMF_NETDIAG_CLIENT_ENABLE
Get(void)956 template <> inline NetworkDiagnostic::Client &Instance::Get(void) { return mNetworkDiagnosticClient; }
957 #endif
958 
959 #if OPENTHREAD_CONFIG_DHCP6_CLIENT_ENABLE
Get(void)960 template <> inline Dhcp6::Client &Instance::Get(void) { return mDhcp6Client; }
961 #endif
962 
963 #if OPENTHREAD_CONFIG_DHCP6_SERVER_ENABLE
Get(void)964 template <> inline Dhcp6::Server &Instance::Get(void) { return mDhcp6Server; }
965 #endif
966 
967 #if OPENTHREAD_CONFIG_NEIGHBOR_DISCOVERY_AGENT_ENABLE
Get(void)968 template <> inline NeighborDiscovery::Agent &Instance::Get(void) { return mNeighborDiscoveryAgent; }
969 #endif
970 
971 #if OPENTHREAD_CONFIG_IP6_SLAAC_ENABLE
Get(void)972 template <> inline Utils::Slaac &Instance::Get(void) { return mSlaac; }
973 #endif
974 
975 #if OPENTHREAD_CONFIG_JAM_DETECTION_ENABLE
Get(void)976 template <> inline Utils::JamDetector &Instance::Get(void) { return mJamDetector; }
977 #endif
978 
979 #if OPENTHREAD_CONFIG_SNTP_CLIENT_ENABLE
Get(void)980 template <> inline Sntp::Client &Instance::Get(void) { return mSntpClient; }
981 #endif
982 
983 #if OPENTHREAD_FTD
Get(void)984 template <> inline ChildSupervisor &Instance::Get(void) { return mChildSupervisor; }
985 #endif
Get(void)986 template <> inline SupervisionListener &Instance::Get(void) { return mSupervisionListener; }
987 
988 #if OPENTHREAD_CONFIG_PING_SENDER_ENABLE
Get(void)989 template <> inline Utils::PingSender &Instance::Get(void) { return mPingSender; }
990 #endif
991 
992 #if OPENTHREAD_CONFIG_CHANNEL_MONITOR_ENABLE
Get(void)993 template <> inline Utils::ChannelMonitor &Instance::Get(void) { return mChannelMonitor; }
994 #endif
995 
996 #if OPENTHREAD_CONFIG_CHANNEL_MANAGER_ENABLE && \
997     (OPENTHREAD_FTD || OPENTHREAD_CONFIG_CHANNEL_MANAGER_CSL_CHANNEL_SELECT_ENABLE)
Get(void)998 template <> inline Utils::ChannelManager &Instance::Get(void) { return mChannelManager; }
999 #endif
1000 
1001 #if OPENTHREAD_CONFIG_MESH_DIAG_ENABLE && OPENTHREAD_FTD
Get(void)1002 template <> inline Utils::MeshDiag &Instance::Get(void) { return mMeshDiag; }
1003 #endif
1004 
1005 #if OPENTHREAD_CONFIG_HISTORY_TRACKER_ENABLE
Get(void)1006 template <> inline Utils::HistoryTracker &Instance::Get(void) { return mHistoryTracker; }
1007 #endif
1008 
1009 #if OPENTHREAD_CONFIG_LINK_METRICS_MANAGER_ENABLE
Get(void)1010 template <> inline Utils::LinkMetricsManager &Instance::Get(void) { return mLinkMetricsManager; }
1011 #endif
1012 
1013 #if (OPENTHREAD_CONFIG_DATASET_UPDATER_ENABLE || OPENTHREAD_CONFIG_CHANNEL_MANAGER_ENABLE) && OPENTHREAD_FTD
Get(void)1014 template <> inline MeshCoP::DatasetUpdater &Instance::Get(void) { return mDatasetUpdater; }
1015 #endif
1016 
1017 #if OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE
Get(void)1018 template <> inline MeshCoP::BorderAgent &Instance::Get(void) { return mBorderAgent; }
1019 #endif
1020 
1021 #if OPENTHREAD_CONFIG_ANNOUNCE_SENDER_ENABLE
Get(void)1022 template <> inline AnnounceSender &Instance::Get(void) { return mAnnounceSender; }
1023 #endif
1024 
Get(void)1025 template <> inline MessagePool &Instance::Get(void) { return mMessagePool; }
1026 
1027 #if (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)
1028 
Get(void)1029 template <> inline BackboneRouter::Leader &Instance::Get(void) { return mBackboneRouterLeader; }
1030 
1031 #if OPENTHREAD_FTD && OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE
Get(void)1032 template <> inline BackboneRouter::Local   &Instance::Get(void) { return mBackboneRouterLocal; }
Get(void)1033 template <> inline BackboneRouter::Manager &Instance::Get(void) { return mBackboneRouterManager; }
1034 
1035 #if OPENTHREAD_CONFIG_BACKBONE_ROUTER_MULTICAST_ROUTING_ENABLE
Get(void)1036 template <> inline BackboneRouter::MulticastListenersTable &Instance::Get(void)
1037 {
1038     return mBackboneRouterManager.GetMulticastListenersTable();
1039 }
1040 #endif
1041 
1042 #if OPENTHREAD_CONFIG_BACKBONE_ROUTER_DUA_NDPROXYING_ENABLE
Get(void)1043 template <> inline BackboneRouter::NdProxyTable &Instance::Get(void)
1044 {
1045     return mBackboneRouterManager.GetNdProxyTable();
1046 }
1047 #endif
1048 
Get(void)1049 template <> inline BackboneRouter::BackboneTmfAgent &Instance::Get(void)
1050 {
1051     return mBackboneRouterManager.GetBackboneTmfAgent();
1052 }
1053 #endif
1054 
1055 #if OPENTHREAD_CONFIG_MLR_ENABLE || (OPENTHREAD_FTD && OPENTHREAD_CONFIG_TMF_PROXY_MLR_ENABLE)
Get(void)1056 template <> inline MlrManager &Instance::Get(void) { return mMlrManager; }
1057 #endif
1058 
1059 #if OPENTHREAD_CONFIG_DUA_ENABLE || (OPENTHREAD_FTD && OPENTHREAD_CONFIG_TMF_PROXY_DUA_ENABLE)
Get(void)1060 template <> inline DuaManager &Instance::Get(void) { return mDuaManager; }
1061 #endif
1062 
1063 #if OPENTHREAD_CONFIG_MLE_LINK_METRICS_INITIATOR_ENABLE
Get(void)1064 template <> inline LinkMetrics::Initiator &Instance::Get(void) { return mInitiator; }
1065 #endif
1066 
1067 #if OPENTHREAD_CONFIG_MLE_LINK_METRICS_SUBJECT_ENABLE
Get(void)1068 template <> inline LinkMetrics::Subject &Instance::Get(void) { return mSubject; }
1069 #endif
1070 
1071 #endif // (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)
1072 
1073 #if OPENTHREAD_CONFIG_OTNS_ENABLE
Get(void)1074 template <> inline Utils::Otns &Instance::Get(void) { return mOtns; }
1075 #endif
1076 
1077 #if OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE
Get(void)1078 template <> inline BorderRouter::RoutingManager &Instance::Get(void) { return mRoutingManager; }
1079 
Get(void)1080 template <> inline BorderRouter::InfraIf &Instance::Get(void) { return mRoutingManager.mInfraIf; }
1081 #endif
1082 
1083 #if OPENTHREAD_CONFIG_NAT64_TRANSLATOR_ENABLE
Get(void)1084 template <> inline Nat64::Translator &Instance::Get(void) { return mNat64Translator; }
1085 #endif
1086 
1087 #if OPENTHREAD_CONFIG_SRP_SERVER_ENABLE
Get(void)1088 template <> inline Srp::Server &Instance::Get(void) { return mSrpServer; }
1089 #if OPENTHREAD_CONFIG_SRP_SERVER_ADVERTISING_PROXY_ENABLE
Get(void)1090 template <> inline Srp::AdvertisingProxy &Instance::Get(void) { return mSrpAdvertisingProxy; }
1091 #endif
1092 #endif // OPENTHREAD_CONFIG_SRP_SERVER_ENABLE
1093 
1094 #if OPENTHREAD_CONFIG_BLE_TCAT_ENABLE
Get(void)1095 template <> inline Ble::BleSecure &Instance::Get(void) { return mApplicationBleSecure; }
1096 #endif
1097 
1098 #endif // OPENTHREAD_MTD || OPENTHREAD_FTD
1099 
1100 #if OPENTHREAD_RADIO || OPENTHREAD_CONFIG_LINK_RAW_ENABLE
Get(void)1101 template <> inline Mac::LinkRaw &Instance::Get(void) { return mLinkRaw; }
1102 
1103 #if OPENTHREAD_RADIO
Get(void)1104 template <> inline Mac::SubMac &Instance::Get(void) { return mLinkRaw.mSubMac; }
1105 #endif
1106 
1107 #endif // OPENTHREAD_RADIO || OPENTHREAD_CONFIG_LINK_RAW_ENABLE
1108 
Get(void)1109 template <> inline Tasklet::Scheduler &Instance::Get(void) { return mTaskletScheduler; }
1110 
Get(void)1111 template <> inline TimerMilli::Scheduler &Instance::Get(void) { return mTimerMilliScheduler; }
1112 
1113 #if OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE
Get(void)1114 template <> inline TimerMicro::Scheduler &Instance::Get(void) { return mTimerMicroScheduler; }
1115 #endif
1116 
1117 #if OPENTHREAD_ENABLE_VENDOR_EXTENSION
Get(void)1118 template <> inline Extension::ExtensionBase &Instance::Get(void) { return mExtension; }
1119 #endif
1120 
1121 #if OPENTHREAD_CONFIG_DIAG_ENABLE
Get(void)1122 template <> inline FactoryDiags::Diags &Instance::Get(void) { return mDiags; }
1123 #endif
1124 
1125 #if OPENTHREAD_CONFIG_POWER_CALIBRATION_ENABLE && OPENTHREAD_CONFIG_PLATFORM_POWER_CALIBRATION_ENABLE
Get(void)1126 template <> inline Utils::PowerCalibration &Instance::Get(void) { return mPowerCalibration; }
1127 #endif
1128 
1129 //---------------------------------------------------------------------------------------------------------------------
1130 
1131 template <typename InstanceGetProvider>
1132 template <typename Type>
Get(void) const1133 inline Type &GetProvider<InstanceGetProvider>::Get(void) const
1134 {
1135     return static_cast<const InstanceGetProvider *>(this)->GetInstance().template Get<Type>();
1136 }
1137 
1138 template <typename Owner, void (Owner::*HandleTaskletPtr)(void)>
HandleTasklet(Tasklet & aTasklet)1139 void TaskletIn<Owner, HandleTaskletPtr>::HandleTasklet(Tasklet &aTasklet)
1140 {
1141     (aTasklet.Get<Owner>().*HandleTaskletPtr)();
1142 }
1143 
1144 template <typename Owner, void (Owner::*HandleTimertPtr)(void)>
HandleTimer(Timer & aTimer)1145 void TimerMilliIn<Owner, HandleTimertPtr>::HandleTimer(Timer &aTimer)
1146 {
1147     (aTimer.Get<Owner>().*HandleTimertPtr)();
1148 }
1149 
1150 #if OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE
1151 template <typename Owner, void (Owner::*HandleTimertPtr)(void)>
HandleTimer(Timer & aTimer)1152 void TimerMicroIn<Owner, HandleTimertPtr>::HandleTimer(Timer &aTimer)
1153 {
1154     (aTimer.Get<Owner>().*HandleTimertPtr)();
1155 }
1156 #endif
1157 
1158 /**
1159  * @}
1160  */
1161 
1162 } // namespace ot
1163 
1164 #endif // INSTANCE_HPP_
1165