3 * Copyright (c) 2020 Project CHIP Authors
4 * Copyright (c) 2019 Nest Labs, Inc.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
21 * Defines the public interface for the Device Layer ThreadStackManager object.
32 namespace DeviceLayer {
34 class PlatformManagerImpl;
35 class ThreadStackManagerImpl;
36 class ConfigurationManagerImpl;
39 class DeviceNetworkInfo;
40 class DeviceControlServer;
43 class GenericPlatformManagerImpl;
45 class GenericConfigurationManagerImpl;
47 class GenericPlatformManagerImpl_FreeRTOS;
49 class GenericConnectivityManagerImpl_Thread;
51 class GenericThreadStackManagerImpl_OpenThread;
53 class GenericThreadStackManagerImpl_OpenThread_LwIP;
55 class GenericThreadStackManagerImpl_FreeRTOS;
57 class GenericNetworkProvisioningServerImpl;
58 } // namespace Internal
61 * Provides features for initializing and interacting with the Thread stack on
62 * a chip-enabled device.
64 class ThreadStackManager
66 using ImplClass = ThreadStackManagerImpl;
69 // ===== Members that define the public interface of the ThreadStackManager
71 CHIP_ERROR InitThreadStack();
72 void ProcessThreadActivity();
73 CHIP_ERROR StartThreadTask();
74 void LockThreadStack();
75 bool TryLockThreadStack();
76 void UnlockThreadStack();
77 bool HaveRouteToAddress(const chip::Inet::IPAddress & destAddr);
78 CHIP_ERROR GetAndLogThreadStatsCounters();
79 CHIP_ERROR GetAndLogThreadTopologyMinimal();
80 CHIP_ERROR GetAndLogThreadTopologyFull();
81 CHIP_ERROR GetPrimary802154MACAddress(uint8_t * buf);
82 CHIP_ERROR GetFactoryAssignedEUI64(uint8_t (&buf)[8]);
83 CHIP_ERROR GetExternalIPv6Address(chip::Inet::IPAddress & addr);
85 CHIP_ERROR JoinerStart();
86 CHIP_ERROR SetThreadProvision(const Internal::DeviceNetworkInfo & netInfo);
87 CHIP_ERROR SetThreadProvision(const uint8_t * operationalDataset, size_t operationalDatasetLen);
88 CHIP_ERROR SetThreadEnabled(bool val);
90 #if CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT
91 CHIP_ERROR AddSrpService(const char * aInstanceName, const char * aName, uint16_t aPort, chip::Mdns::TextEntry * aTxtEntries,
92 size_t aTxtEntiresSize, uint32_t aLeaseInterval, uint32_t aKeyLeaseInterval);
93 CHIP_ERROR RemoveSrpService(const char * aInstanceName, const char * aName);
94 CHIP_ERROR SetupSrpHost(const char * aHostName);
95 #endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT
98 // ===== Members for internal use by the following friends.
100 friend class PlatformManagerImpl;
101 friend class ConfigurationManagerImpl;
102 #if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
103 friend class Internal::BLEManagerImpl;
105 friend class Internal::DeviceControlServer;
107 friend class Internal::GenericPlatformManagerImpl;
109 friend class Internal::GenericConfigurationManagerImpl;
111 friend class Internal::GenericPlatformManagerImpl_FreeRTOS;
113 friend class Internal::GenericConnectivityManagerImpl_Thread;
115 friend class Internal::GenericThreadStackManagerImpl_OpenThread;
117 friend class Internal::GenericThreadStackManagerImpl_OpenThread_LwIP;
119 friend class Internal::GenericThreadStackManagerImpl_FreeRTOS;
121 friend class Internal::GenericNetworkProvisioningServerImpl;
123 void OnPlatformEvent(const ChipDeviceEvent * event);
124 bool IsThreadEnabled();
125 bool IsThreadProvisioned();
126 bool IsThreadAttached();
127 CHIP_ERROR GetThreadProvision(Internal::DeviceNetworkInfo & netInfo, bool includeCredentials);
128 void ErasePersistentInfo();
129 ConnectivityManager::ThreadDeviceType GetThreadDeviceType();
130 CHIP_ERROR SetThreadDeviceType(ConnectivityManager::ThreadDeviceType threadRole);
131 void GetThreadPollingConfig(ConnectivityManager::ThreadPollingConfig & pollingConfig);
132 CHIP_ERROR SetThreadPollingConfig(const ConnectivityManager::ThreadPollingConfig & pollingConfig);
133 bool HaveMeshConnectivity();
134 void OnMessageLayerActivityChanged(bool messageLayerIsActive);
135 void OnCHIPoBLEAdvertisingStart();
136 void OnCHIPoBLEAdvertisingStop();
139 // Construction/destruction limited to subclasses.
140 ThreadStackManager() = default;
141 ~ThreadStackManager() = default;
143 // No copy, move or assignment.
144 ThreadStackManager(const ThreadStackManager &) = delete;
145 ThreadStackManager(const ThreadStackManager &&) = delete;
146 ThreadStackManager & operator=(const ThreadStackManager &) = delete;
150 * Returns the public interface of the ThreadStackManager singleton object.
152 * chip applications should use this to access features of the ThreadStackManager object
153 * that are common to all platforms.
155 extern ThreadStackManager & ThreadStackMgr();
158 * Returns the platform-specific implementation of the ThreadStackManager singleton object.
160 * chip applications can use this to gain access to features of the ThreadStackManager
161 * that are specific to the selected platform.
163 extern ThreadStackManagerImpl & ThreadStackMgrImpl();
165 } // namespace DeviceLayer
168 /* Include a header file containing the implementation of the ThreadStackManager
169 * object for the selected platform.
171 #ifdef EXTERNAL_THREADSTACKMANAGERIMPL_HEADER
172 #include EXTERNAL_THREADSTACKMANAGERIMPL_HEADER
173 #elif defined(CHIP_DEVICE_LAYER_TARGET)
174 #define THREADSTACKMANAGERIMPL_HEADER <platform/CHIP_DEVICE_LAYER_TARGET/ThreadStackManagerImpl.h>
175 #include THREADSTACKMANAGERIMPL_HEADER
176 #endif // defined(CHIP_DEVICE_LAYER_TARGET)
179 namespace DeviceLayer {
181 inline CHIP_ERROR ThreadStackManager::InitThreadStack()
183 return static_cast<ImplClass *>(this)->_InitThreadStack();
186 inline void ThreadStackManager::ProcessThreadActivity()
188 static_cast<ImplClass *>(this)->_ProcessThreadActivity();
191 inline CHIP_ERROR ThreadStackManager::StartThreadTask()
193 return static_cast<ImplClass *>(this)->_StartThreadTask();
196 inline void ThreadStackManager::LockThreadStack()
198 static_cast<ImplClass *>(this)->_LockThreadStack();
201 inline bool ThreadStackManager::TryLockThreadStack()
203 return static_cast<ImplClass *>(this)->_TryLockThreadStack();
206 inline void ThreadStackManager::UnlockThreadStack()
208 static_cast<ImplClass *>(this)->_UnlockThreadStack();
212 * Determines whether a route exists via the Thread interface to the specified destination address.
214 inline bool ThreadStackManager::HaveRouteToAddress(const chip::Inet::IPAddress & destAddr)
216 return static_cast<ImplClass *>(this)->_HaveRouteToAddress(destAddr);
219 inline void ThreadStackManager::OnPlatformEvent(const ChipDeviceEvent * event)
221 static_cast<ImplClass *>(this)->_OnPlatformEvent(event);
224 inline bool ThreadStackManager::IsThreadEnabled()
226 return static_cast<ImplClass *>(this)->_IsThreadEnabled();
229 inline CHIP_ERROR ThreadStackManager::SetThreadEnabled(bool val)
231 return static_cast<ImplClass *>(this)->_SetThreadEnabled(val);
234 #if CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT
235 inline CHIP_ERROR ThreadStackManager::AddSrpService(const char * aInstanceName, const char * aName, uint16_t aPort,
236 chip::Mdns::TextEntry * aTxtEntries, size_t aTxtEntiresSize,
237 uint32_t aLeaseInterval = 0, uint32_t aKeyLeaseInterval = 0)
239 return static_cast<ImplClass *>(this)->_AddSrpService(aInstanceName, aName, aPort, aTxtEntries, aTxtEntiresSize, aLeaseInterval,
243 inline CHIP_ERROR ThreadStackManager::RemoveSrpService(const char * aInstanceName, const char * aName)
245 return static_cast<ImplClass *>(this)->_RemoveSrpService(aInstanceName, aName);
248 inline CHIP_ERROR ThreadStackManager::SetupSrpHost(const char * aHostName)
250 return static_cast<ImplClass *>(this)->_SetupSrpHost(aHostName);
252 #endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT
254 inline bool ThreadStackManager::IsThreadProvisioned()
256 return static_cast<ImplClass *>(this)->_IsThreadProvisioned();
259 inline bool ThreadStackManager::IsThreadAttached()
261 return static_cast<ImplClass *>(this)->_IsThreadAttached();
264 inline CHIP_ERROR ThreadStackManager::GetThreadProvision(Internal::DeviceNetworkInfo & netInfo, bool includeCredentials)
266 return static_cast<ImplClass *>(this)->_GetThreadProvision(netInfo, includeCredentials);
269 inline CHIP_ERROR ThreadStackManager::SetThreadProvision(const Internal::DeviceNetworkInfo & netInfo)
271 return static_cast<ImplClass *>(this)->_SetThreadProvision(netInfo);
274 inline CHIP_ERROR ThreadStackManager::SetThreadProvision(const uint8_t * operationalDataset, size_t operationalDatasetLen)
276 return static_cast<ImplClass *>(this)->_SetThreadProvision(operationalDataset, operationalDatasetLen);
279 inline void ThreadStackManager::ErasePersistentInfo()
281 static_cast<ImplClass *>(this)->_ErasePersistentInfo();
284 inline ConnectivityManager::ThreadDeviceType ThreadStackManager::GetThreadDeviceType()
286 return static_cast<ImplClass *>(this)->_GetThreadDeviceType();
289 inline CHIP_ERROR ThreadStackManager::SetThreadDeviceType(ConnectivityManager::ThreadDeviceType deviceType)
291 return static_cast<ImplClass *>(this)->_SetThreadDeviceType(deviceType);
294 inline void ThreadStackManager::GetThreadPollingConfig(ConnectivityManager::ThreadPollingConfig & pollingConfig)
296 static_cast<ImplClass *>(this)->_GetThreadPollingConfig(pollingConfig);
299 inline CHIP_ERROR ThreadStackManager::SetThreadPollingConfig(const ConnectivityManager::ThreadPollingConfig & pollingConfig)
301 return static_cast<ImplClass *>(this)->_SetThreadPollingConfig(pollingConfig);
304 inline bool ThreadStackManager::HaveMeshConnectivity()
306 return static_cast<ImplClass *>(this)->_HaveMeshConnectivity();
309 inline void ThreadStackManager::OnMessageLayerActivityChanged(bool messageLayerIsActive)
311 return static_cast<ImplClass *>(this)->_OnMessageLayerActivityChanged(messageLayerIsActive);
314 inline void ThreadStackManager::OnCHIPoBLEAdvertisingStart()
316 static_cast<ImplClass *>(this)->_OnCHIPoBLEAdvertisingStart();
319 inline void ThreadStackManager::OnCHIPoBLEAdvertisingStop()
321 static_cast<ImplClass *>(this)->_OnCHIPoBLEAdvertisingStop();
324 inline CHIP_ERROR ThreadStackManager::GetAndLogThreadStatsCounters()
326 return static_cast<ImplClass *>(this)->_GetAndLogThreadStatsCounters();
329 inline CHIP_ERROR ThreadStackManager::GetAndLogThreadTopologyMinimal()
331 return static_cast<ImplClass *>(this)->_GetAndLogThreadTopologyMinimal();
334 inline CHIP_ERROR ThreadStackManager::GetAndLogThreadTopologyFull()
336 return static_cast<ImplClass *>(this)->_GetAndLogThreadTopologyFull();
339 inline CHIP_ERROR ThreadStackManager::GetPrimary802154MACAddress(uint8_t * buf)
341 return static_cast<ImplClass *>(this)->_GetPrimary802154MACAddress(buf);
344 inline CHIP_ERROR ThreadStackManager::GetFactoryAssignedEUI64(uint8_t (&buf)[8])
346 return static_cast<ImplClass *>(this)->_GetFactoryAssignedEUI64(buf);
349 inline CHIP_ERROR ThreadStackManager::GetExternalIPv6Address(chip::Inet::IPAddress & addr)
351 return static_cast<ImplClass *>(this)->_GetExternalIPv6Address(addr);
354 inline CHIP_ERROR ThreadStackManager::JoinerStart()
356 return static_cast<ImplClass *>(this)->_JoinerStart();
359 } // namespace DeviceLayer