openthread-br  0.3.0-72c0388
Public Types | Public Member Functions | Static Public Member Functions | List of all members
otbr::agent::ThreadHelper Class Reference

#include <src/utils/thread_helper.hpp>

Public Types

using DeviceRoleHandler = std::function< void(otDeviceRole)>
 
using ScanHandler = std::function< void(otError, const std::vector< otActiveScanResult > &)>
 
using EnergyScanHandler = std::function< void(otError, const std::vector< otEnergyScanResult > &)>
 
using ResultHandler = std::function< void(otError)>
 
using AttachHandler = std::function< void(otError, int64_t)>
 
using UpdateMeshCopTxtHandler = std::function< void(std::map< std::string, std::vector< uint8_t > >)>
 
using DatasetChangeHandler = std::function< void(const otOperationalDatasetTlvs &)>
 

Public Member Functions

 ThreadHelper (otInstance *aInstance, otbr::Ncp::ControllerOpenThread *aNcp)
 
void AddDeviceRoleHandler (DeviceRoleHandler aHandler)
 
void AddActiveDatasetChangeHandler (DatasetChangeHandler aHandler)
 
otError PermitUnsecureJoin (uint16_t aPort, uint32_t aSeconds)
 
void Scan (ScanHandler aHandler)
 
void EnergyScan (uint32_t aScanDuration, EnergyScanHandler aHandler)
 
void Attach (const std::string &aNetworkName, uint16_t aPanId, uint64_t aExtPanId, const std::vector< uint8_t > &aNetworkKey, const std::vector< uint8_t > &aPSKc, uint32_t aChannelMask, AttachHandler aHandler)
 
otError Detach (void)
 
void Attach (AttachHandler aHandler)
 
void AttachAllNodesTo (const std::vector< uint8_t > &aDatasetTlvs, AttachHandler aHandler)
 
otError Reset (void)
 
void JoinerStart (const std::string &aPskd, const std::string &aProvisioningUrl, const std::string &aVendorName, const std::string &aVendorModel, const std::string &aVendorSwVersion, const std::string &aVendorData, ResultHandler aHandler)
 
otError TryResumeNetwork (void)
 
otInstance * GetInstance (void)
 
void StateChangedCallback (otChangedFlags aFlags)
 
void DetachGracefully (ResultHandler aHandler)
 

Static Public Member Functions

static void LogOpenThreadResult (const char *aAction, otError aError)
 

Detailed Description

This class implements Thread helper.

Constructor & Destructor Documentation

◆ ThreadHelper()

otbr::agent::ThreadHelper::ThreadHelper ( otInstance *  aInstance,
otbr::Ncp::ControllerOpenThread aNcp 
)

The constructor of a Thread helper.

Parameters
[in]aInstanceThe Thread instance.
[in]aNcpThe ncp controller.

Member Function Documentation

◆ AddActiveDatasetChangeHandler()

void otbr::agent::ThreadHelper::AddActiveDatasetChangeHandler ( DatasetChangeHandler  aHandler)

This method adds a callback for active dataset change.

Parameters
[in]aHandlerThe active dataset change handler.

◆ AddDeviceRoleHandler()

void otbr::agent::ThreadHelper::AddDeviceRoleHandler ( DeviceRoleHandler  aHandler)

This method adds a callback for device role change.

Parameters
[in]aHandlerThe device role handler.

◆ Attach() [1/2]

void otbr::agent::ThreadHelper::Attach ( AttachHandler  aHandler)

This method attaches the device to the Thread network.

Note
The joiner start and the attach proccesses are exclusive, and the network parameter will be set through the active dataset.
Parameters
[in]aHandlerThe attach result handler.

◆ Attach() [2/2]

void otbr::agent::ThreadHelper::Attach ( const std::string &  aNetworkName,
uint16_t  aPanId,
uint64_t  aExtPanId,
const std::vector< uint8_t > &  aNetworkKey,
const std::vector< uint8_t > &  aPSKc,
uint32_t  aChannelMask,
AttachHandler  aHandler 
)

This method attaches the device to the Thread network.

Note
The joiner start and the attach proccesses are exclusive
Parameters
[in]aNetworkNameThe network name.
[in]aPanIdThe pan id, UINT16_MAX for random.
[in]aExtPanIdThe extended pan id, UINT64_MAX for random.
[in]aNetworkKeyThe network key, empty for random.
[in]aPSKcThe pre-shared commissioner key, empty for random.
[in]aChannelMaskA bitmask for valid channels, will random select one.
[in]aHandlerThe attach result handler.

◆ AttachAllNodesTo()

void otbr::agent::ThreadHelper::AttachAllNodesTo ( const std::vector< uint8_t > &  aDatasetTlvs,
AttachHandler  aHandler 
)

This method makes all nodes in the current network attach to the network specified by the dataset TLVs.

Parameters
[in]aDatasetTlvsThe dataset TLVs.
[in]aHandlerThe result handler.

◆ Detach()

otError otbr::agent::ThreadHelper::Detach ( void  )

This method detaches the device from the Thread network.

Returns
The error value of underlying OpenThread API calls.

◆ EnergyScan()

void otbr::agent::ThreadHelper::EnergyScan ( uint32_t  aScanDuration,
EnergyScanHandler  aHandler 
)

This method performs an IEEE 802.15.4 Energy Scan.

Parameters
[in]aScanDurationThe duration for the scan, in milliseconds.
[in]aHandlerThe scan result handler.

◆ GetInstance()

otInstance* otbr::agent::ThreadHelper::GetInstance ( void  )
inline

This method returns the underlying OpenThread instance.

Returns
The underlying instance.

◆ JoinerStart()

void otbr::agent::ThreadHelper::JoinerStart ( const std::string &  aPskd,
const std::string &  aProvisioningUrl,
const std::string &  aVendorName,
const std::string &  aVendorModel,
const std::string &  aVendorSwVersion,
const std::string &  aVendorData,
ResultHandler  aHandler 
)

This method triggers a thread join process.

Note
The joiner start and the attach proccesses are exclusive
Parameters
[in]aPskdThe pre-shared key for device.
[in]aProvisioningUrlThe provision url.
[in]aVendorNameThe vendor name.
[in]aVendorModelThe vendor model.
[in]aVendorSwVersionThe vendor software version.
[in]aVendorDataThe vendor custom data.
[in]aHandlerThe join result handler.

◆ LogOpenThreadResult()

void otbr::agent::ThreadHelper::LogOpenThreadResult ( const char *  aAction,
otError  aError 
)
static

This method logs OpenThread action result.

Parameters
[in]aActionThe action OpenThread performs.
[in]aErrorThe action result.

◆ PermitUnsecureJoin()

otError otbr::agent::ThreadHelper::PermitUnsecureJoin ( uint16_t  aPort,
uint32_t  aSeconds 
)

This method permits unsecure join on port.

Parameters
[in]aPortThe port number.
[in]aSecondsThe timeout to close the port, 0 for never close.
Returns
The error value of underlying OpenThread api calls.

◆ Reset()

otError otbr::agent::ThreadHelper::Reset ( void  )

This method resets the OpenThread stack.

Returns
The error value of underlying OpenThread api calls.

◆ Scan()

void otbr::agent::ThreadHelper::Scan ( ScanHandler  aHandler)

This method performs a Thread network scan.

Parameters
[in]aHandlerThe scan result handler.

◆ StateChangedCallback()

void otbr::agent::ThreadHelper::StateChangedCallback ( otChangedFlags  aFlags)

This method handles OpenThread state changed notification.

Parameters
[in]aFlagsA bit-field indicating specific state that has changed. See OT_CHANGED_* definitions.

◆ TryResumeNetwork()

otError otbr::agent::ThreadHelper::TryResumeNetwork ( void  )

This method tries to restore the network after reboot

Returns
The error value of underlying OpenThread api calls.

The documentation for this class was generated from the following files: