34 #ifndef OTBR_THREAD_HELPER_HPP_
35 #define OTBR_THREAD_HELPER_HPP_
44 #include <openthread/instance.h>
45 #include <openthread/ip6.h>
46 #include <openthread/jam_detection.h>
47 #include <openthread/joiner.h>
48 #include <openthread/netdata.h>
49 #include <openthread/thread.h>
53 class ControllerOpenThread;
66 using DeviceRoleHandler = std::function<void(otDeviceRole)>;
67 using ScanHandler = std::function<void(otError,
const std::vector<otActiveScanResult> &)>;
68 using EnergyScanHandler = std::function<void(otError,
const std::vector<otEnergyScanResult> &)>;
69 using ResultHandler = std::function<void(otError)>;
70 using AttachHandler = std::function<void(otError, int64_t)>;
71 using UpdateMeshCopTxtHandler = std::function<void(std::map<std::string, std::vector<uint8_t>>)>;
72 using DatasetChangeHandler = std::function<void(
const otOperationalDatasetTlvs &)>;
115 void Scan(ScanHandler aHandler);
124 void EnergyScan(uint32_t aScanDuration, EnergyScanHandler aHandler);
140 void Attach(
const std::string & aNetworkName,
143 const std::vector<uint8_t> &aNetworkKey,
144 const std::vector<uint8_t> &aPSKc,
145 uint32_t aChannelMask,
146 AttachHandler aHandler);
165 void Attach(AttachHandler aHandler);
174 void AttachAllNodesTo(
const std::vector<uint8_t> &aDatasetTlvs, AttachHandler aHandler);
199 const std::string &aProvisioningUrl,
200 const std::string &aVendorName,
201 const std::string &aVendorModel,
202 const std::string &aVendorSwVersion,
203 const std::string &aVendorData,
204 ResultHandler aHandler);
230 #if OTBR_ENABLE_DBUS_SERVER
237 void SetUpdateMeshCopTxtHandler(UpdateMeshCopTxtHandler aHandler)
239 mUpdateMeshCopTxtHandler = std::move(aHandler);
248 void OnUpdateMeshCopTxt(std::map<std::string, std::vector<uint8_t>> aUpdate);
251 void DetachGracefully(ResultHandler aHandler);
263 static void ActiveScanHandler(otActiveScanResult *aResult,
void *aThreadHelper);
264 void ActiveScanHandler(otActiveScanResult *aResult);
266 static void EnergyScanCallback(otEnergyScanResult *aResult,
void *aThreadHelper);
267 void EnergyScanCallback(otEnergyScanResult *aResult);
269 static void JoinerCallback(otError aError,
void *aThreadHelper);
270 void JoinerCallback(otError aResult);
272 static void MgmtSetResponseHandler(otError aResult,
void *aContext);
273 void MgmtSetResponseHandler(otError aResult);
275 static void DetachGracefullyCallback(
void *aContext);
276 void DetachGracefullyCallback(
void);
278 void RandomFill(
void *aBuf,
size_t size);
279 uint8_t RandomChannelFromChannelMask(uint32_t aChannelMask);
281 void ActiveDatasetChangedCallback(
void);
283 otInstance *mInstance;
287 ScanHandler mScanHandler;
288 std::vector<otActiveScanResult> mScanResults;
289 EnergyScanHandler mEnergyScanHandler;
290 std::vector<otEnergyScanResult> mEnergyScanResults;
292 std::vector<DeviceRoleHandler> mDeviceRoleHandlers;
293 std::vector<DatasetChangeHandler> mActiveDatasetChangeHandlers;
295 std::map<uint16_t, size_t> mUnsecurePortRefCounter;
297 int64_t mAttachDelayMs = 0;
298 AttachHandler mAttachHandler;
299 ResultHandler mJoinerHandler;
301 ResultHandler mDetachGracefullyHandler =
nullptr;
303 otOperationalDatasetTlvs mAttachPendingDatasetTlvs = {};
305 std::random_device mRandomDevice;
307 #if OTBR_ENABLE_DBUS_SERVER
308 UpdateMeshCopTxtHandler mUpdateMeshCopTxtHandler;
315 #endif // OTBR_THREAD_HELPER_HPP_