3 * Copyright (c) 2020 Project CHIP Authors
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
24 #include "platform/internal/CHIPDeviceLayerInternal.h"
26 #include "dbus/client/thread_api_dbus.hpp"
27 #include "platform/internal/DeviceNetworkInfo.h"
30 namespace DeviceLayer {
32 class ThreadStackManagerImpl : public ThreadStackManager
35 ThreadStackManagerImpl();
37 CHIP_ERROR _InitThreadStack();
38 void _ProcessThreadActivity();
40 CHIP_ERROR _StartThreadTask() { return CHIP_NO_ERROR; } // Intentionally left blank
41 void _LockThreadStack() {} // Intentionally left blank
42 bool _TryLockThreadStack() { return false; } // Intentionally left blank
43 void _UnlockThreadStack() {} // Intentionally left blank
45 bool _HaveRouteToAddress(const Inet::IPAddress & destAddr);
47 void _OnPlatformEvent(const ChipDeviceEvent * event);
49 CHIP_ERROR _GetThreadProvision(Internal::DeviceNetworkInfo & netInfo, bool includeCredentials);
51 CHIP_ERROR _SetThreadProvision(const Internal::DeviceNetworkInfo & netInfo);
53 CHIP_ERROR _SetThreadProvision(const uint8_t * operationalDataset, size_t operationalDatasetLen);
55 void _ErasePersistentInfo();
57 bool _IsThreadProvisioned();
59 bool _IsThreadEnabled();
61 bool _IsThreadAttached();
63 CHIP_ERROR _SetThreadEnabled(bool val);
65 ConnectivityManager::ThreadDeviceType _GetThreadDeviceType();
67 CHIP_ERROR _SetThreadDeviceType(ConnectivityManager::ThreadDeviceType deviceType);
69 void _GetThreadPollingConfig(ConnectivityManager::ThreadPollingConfig & pollingConfig);
71 CHIP_ERROR _SetThreadPollingConfig(const ConnectivityManager::ThreadPollingConfig & pollingConfig);
73 bool _HaveMeshConnectivity();
75 void _OnMessageLayerActivityChanged(bool messageLayerIsActive);
77 void _OnCHIPoBLEAdvertisingStart();
79 void _OnCHIPoBLEAdvertisingStop();
81 CHIP_ERROR _GetAndLogThreadStatsCounters();
83 CHIP_ERROR _GetAndLogThreadTopologyMinimal();
85 CHIP_ERROR _GetAndLogThreadTopologyFull();
87 CHIP_ERROR _GetPrimary802154MACAddress(uint8_t * buf);
89 CHIP_ERROR _GetFactoryAssignedEUI64(uint8_t (&buf)[8]);
91 CHIP_ERROR _GetExternalIPv6Address(chip::Inet::IPAddress & addr);
93 CHIP_ERROR _JoinerStart();
95 ~ThreadStackManagerImpl() = default;
97 static ThreadStackManagerImpl sInstance;
100 struct DBusConnectionDeleter
102 void operator()(DBusConnection * aConnection)
104 dbus_connection_close(aConnection);
105 dbus_connection_unref(aConnection);
109 using UniqueDBusConnection = std::unique_ptr<DBusConnection, DBusConnectionDeleter>;
111 void _ThreadDevcieRoleChangedHandler(otbr::DBus::DeviceRole role);
113 std::unique_ptr<otbr::DBus::ThreadApiDBus> mThreadApi;
114 UniqueDBusConnection mConnection;
115 std::vector<uint8_t> mOperationalDatasetTlv;
116 Internal::DeviceNetworkInfo mNetworkInfo;
118 std::thread mDBusEventLoop;
121 } // namespace DeviceLayer