Instance#

This module includes functions that control the OpenThread Instance.

Typedefs#

typedef struct otInstance

Represents the OpenThread instance structure.

typedef uint32_t

Represents a bit-field indicating specific state/configuration that has changed.

typedef void(*
otStateChangedCallback)(otChangedFlags aFlags, void *aContext)

Pointer is called to notify certain configuration or state changes within OpenThread.

Functions#

otInstanceInit(void *aInstanceBuffer, size_t *aInstanceBufferSize)

Initializes the OpenThread library.

Initializes the static single instance of the OpenThread library.

Gets the pointer to the single OpenThread instance when multiple instances are not in use.

Initializes the OpenThread instance.

otInstanceGetInstance(uint8_t aIdx)

Gets the pointer to an OpenThread instance with the provided index when multiple instances are in use.

uint8_t
otInstanceGetIndex(otInstance *aInstance)

Gets the index of the OpenThread instance when multiple instance is in use.

uint32_t
otInstanceGetId(otInstance *aInstance)

Gets the instance identifier.

bool
otInstanceIsInitialized(otInstance *aInstance)

Indicates whether or not the instance is valid/initialized.

void
otInstanceFinalize(otInstance *aInstance)

Disables the OpenThread library.

uint64_t
otInstanceGetUptime(otInstance *aInstance)

Returns the current instance uptime (in msec).

void
otInstanceGetUptimeAsString(otInstance *aInstance, char *aBuffer, uint16_t aSize)

Returns the current instance uptime as a human-readable string.

otSetStateChangedCallback(otInstance *aInstance, otStateChangedCallback aCallback, void *aContext)

Registers a callback to indicate when certain configuration or state changes within OpenThread.

void
otRemoveStateChangeCallback(otInstance *aInstance, otStateChangedCallback aCallback, void *aContext)

Removes a callback to indicate when certain configuration or state changes within OpenThread.

void
otInstanceReset(otInstance *aInstance)

Triggers a platform reset.

otInstanceResetToBootloader(otInstance *aInstance)

Triggers a platform reset to bootloader mode, if supported.

void
otInstanceFactoryReset(otInstance *aInstance)

Deletes all the settings stored on non-volatile memory, and then triggers a platform reset.

void
otInstanceResetRadioStack(otInstance *aInstance)

Resets the internal states of the OpenThread radio stack.

otInstanceErasePersistentInfo(otInstance *aInstance)

Erases all the OpenThread persistent info (network settings) stored on non-volatile memory.

const char *

Gets the OpenThread version string.

const char *
otGetRadioVersionString(otInstance *aInstance)

Gets the OpenThread radio version string.

Macros#

#define

Recommended size for string representation of uptime.

#define

IPv6 address was added.

#define

IPv6 address was removed.

#define

Role (disabled, detached, child, router, leader) changed.

#define

The link-local address changed.

#define

The mesh-local address changed.

#define

RLOC was added.

#define

RLOC was removed.

#define

Partition ID changed.

#define

Thread Key Sequence changed.

#define

Thread Network Data changed.

#define

Child was added.

#define

Child was removed.

#define

Subscribed to a IPv6 multicast address.

#define

Unsubscribed from a IPv6 multicast address.

#define

Thread network channel changed.

#define

Thread network PAN Id changed.

#define

Thread network name changed.

#define

Thread network extended PAN ID changed.

#define

Network key changed.

#define
OT_CHANGED_PSKC (1U << 19)

PSKc changed.

#define

Security Policy changed.

#define

Channel Manager new pending Thread channel changed.

#define

Supported channel mask changed.

#define

Commissioner state changed.

#define

Thread network interface state changed.

#define

Backbone Router state changed.

#define

Local Backbone Router configuration changed.

#define

Joiner state changed.

#define

Active Operational Dataset changed.

#define

Pending Operational Dataset changed.

#define

The state of NAT64 translator changed.

#define

Parent link quality changed.

Typedef Documentation#

otInstance#

typedef struct otInstance otInstance

Represents the OpenThread instance structure.


otChangedFlags#

typedef uint32_t otChangedFlags

Represents a bit-field indicating specific state/configuration that has changed.

See OT_CHANGED_* definitions.


otStateChangedCallback#

typedef void(* otStateChangedCallback) (otChangedFlags aFlags, void *aContext) )(otChangedFlags aFlags, void *aContext)

Pointer is called to notify certain configuration or state changes within OpenThread.

Parameters
TypeDirectionArgument NameDescription
[in]aFlags

A bit-field indicating specific state that has changed. See OT_CHANGED_* definitions.

[in]aContext

A pointer to application-specific context.


Function Documentation#

otInstanceInit#

otInstance * otInstanceInit (void * aInstanceBuffer, size_t * aInstanceBufferSize)

Initializes the OpenThread library.

Parameters
TypeDirectionArgument NameDescription
void *[in]aInstanceBuffer

The buffer for OpenThread to use for allocating the otInstance structure.

size_t *[inout]aInstanceBufferSize

On input, the size of aInstanceBuffer. On output, if not enough space for otInstance, the number of bytes required for otInstance.

Initializes OpenThread and prepares it for subsequent OpenThread API calls. This function must be called before any other calls to OpenThread.

Is available and can only be used when support for multiple OpenThread instances is enabled.

Returns

  • A pointer to the new OpenThread instance.

See Also


otInstanceInitSingle#

otInstance * otInstanceInitSingle (void )

Initializes the static single instance of the OpenThread library.

Parameters
TypeDirectionArgument NameDescription
voidN/A

Initializes OpenThread and prepares it for subsequent OpenThread API calls. This function must be called before any other calls to OpenThread.

Is available and can only be used when support for multiple OpenThread instances is disabled.

Returns

  • A pointer to the single OpenThread instance.


otInstanceGetSingle#

otInstance * otInstanceGetSingle (void )

Gets the pointer to the single OpenThread instance when multiple instances are not in use.

Parameters
TypeDirectionArgument NameDescription
voidN/A

Is available and can only be used when support for multiple OpenThread instances is disabled.

Returns

  • A pointer to the single OpenThread instance.


otInstanceInitMultiple#

otInstance * otInstanceInitMultiple (uint8_t aIdx)

Initializes the OpenThread instance.

Parameters
TypeDirectionArgument NameDescription
uint8_t[in]aIdx

The index of the OpenThread instance to initialize.

This function initializes OpenThread and prepares it for subsequent OpenThread API calls. This function must be called before any other calls to OpenThread. This method utilizes static buffer to initialize the OpenThread instance.

This function is available and can only be used when support for multiple OpenThread static instances is enabled (OPENTHREAD_CONFIG_MULTIPLE_STATIC_INSTANCE_ENABLE)

Returns

  • A pointer to the new OpenThread instance.


otInstanceGetInstance#

otInstance * otInstanceGetInstance (uint8_t aIdx)

Gets the pointer to an OpenThread instance with the provided index when multiple instances are in use.

Parameters
TypeDirectionArgument NameDescription
uint8_t[in]aIdx

The index of the OpenThread instance.

This function is available when both OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE and OPENTHREAD_CONFIG_MULTIPLE_STATIC_INSTANCE_ENABLE are enabled.

Returns

  • A pointer to the corresponding OpenThread instance, or NULL if aIdx is out of bounds.


otInstanceGetIndex#

uint8_t otInstanceGetIndex (otInstance * aInstance)

Gets the index of the OpenThread instance when multiple instance is in use.

Parameters
TypeDirectionArgument NameDescription
otInstance *[in]aInstance

The reference of the OpenThread instance to get index.

This function is available when both OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE and OPENTHREAD_CONFIG_MULTIPLE_STATIC_INSTANCE_ENABLE are enabled.

Returns

  • The index of the OpenThread instance.


otInstanceGetId#

uint32_t otInstanceGetId (otInstance * aInstance)

Gets the instance identifier.

Parameters
TypeDirectionArgument NameDescription
otInstance *N/AaInstance

The instance identifier is set to a random value when the instance is constructed, and then its value will not change after initialization.

Returns

  • The instance identifier.


otInstanceIsInitialized#

bool otInstanceIsInitialized (otInstance * aInstance)

Indicates whether or not the instance is valid/initialized.

Parameters
TypeDirectionArgument NameDescription
otInstance *[in]aInstance

A pointer to an OpenThread instance.

The instance is considered valid if it is acquired and initialized using either otInstanceInitSingle() (in single instance case) or otInstanceInit() (in multi instance case). A subsequent call to otInstanceFinalize() causes the instance to be considered as uninitialized.

Returns

  • TRUE if the given instance is valid/initialized, FALSE otherwise.


otInstanceFinalize#

void otInstanceFinalize (otInstance * aInstance)

Disables the OpenThread library.

Parameters
TypeDirectionArgument NameDescription
otInstance *[in]aInstance

A pointer to an OpenThread instance.

Call this function when OpenThread is no longer in use.


otInstanceGetUptime#

uint64_t otInstanceGetUptime (otInstance * aInstance)

Returns the current instance uptime (in msec).

Parameters
TypeDirectionArgument NameDescription
otInstance *[in]aInstance

A pointer to an OpenThread instance.

Requires OPENTHREAD_CONFIG_UPTIME_ENABLE to be enabled.

The uptime is given as number of milliseconds since OpenThread instance was initialized.

Returns

  • The uptime (number of milliseconds).


otInstanceGetUptimeAsString#

void otInstanceGetUptimeAsString (otInstance * aInstance, char * aBuffer, uint16_t aSize)

Returns the current instance uptime as a human-readable string.

Parameters
TypeDirectionArgument NameDescription
otInstance *[in]aInstance

A pointer to an OpenThread instance.

char *[out]aBuffer

A pointer to a char array to output the string.

uint16_t[in]aSize

The size of aBuffer (in bytes). Recommended to use OT_UPTIME_STRING_SIZE.

Requires OPENTHREAD_CONFIG_UPTIME_ENABLE to be enabled.

The string follows the format "<hh>:<mm>:<ss>.<mmmm>" for hours, minutes, seconds and millisecond (if uptime is shorter than one day) or "<dd>d.<hh>:<mm>:<ss>.<mmmm>" (if longer than a day).

If the resulting string does not fit in aBuffer (within its aSize characters), the string will be truncated but the outputted string is always null-terminated.


otSetStateChangedCallback#

otError otSetStateChangedCallback (otInstance * aInstance, otStateChangedCallback aCallback, void * aContext)

Registers a callback to indicate when certain configuration or state changes within OpenThread.

Parameters
TypeDirectionArgument NameDescription
otInstance *[in]aInstance

A pointer to an OpenThread instance.

otStateChangedCallback[in]aCallback

A pointer to a function that is called with certain configuration or state changes.

void *[in]aContext

A pointer to application-specific context.


otRemoveStateChangeCallback#

void otRemoveStateChangeCallback (otInstance * aInstance, otStateChangedCallback aCallback, void * aContext)

Removes a callback to indicate when certain configuration or state changes within OpenThread.

Parameters
TypeDirectionArgument NameDescription
otInstance *[in]aInstance

A pointer to an OpenThread instance.

otStateChangedCallback[in]aCallback

A pointer to a function that is called with certain configuration or state changes.

void *[in]aContext

A pointer to application-specific context.


otInstanceReset#

void otInstanceReset (otInstance * aInstance)

Triggers a platform reset.

Parameters
TypeDirectionArgument NameDescription
otInstance *[in]aInstance

A pointer to an OpenThread instance.

The reset process ensures that all the OpenThread state/info (stored in volatile memory) is erased. Note that the otPlatformReset does not erase any persistent state/info saved in non-volatile memory.


otInstanceResetToBootloader#

otError otInstanceResetToBootloader (otInstance * aInstance)

Triggers a platform reset to bootloader mode, if supported.

Parameters
TypeDirectionArgument NameDescription
otInstance *[in]aInstance

A pointer to an OpenThread instance.

Requires OPENTHREAD_CONFIG_PLATFORM_BOOTLOADER_MODE_ENABLE.


otInstanceFactoryReset#

void otInstanceFactoryReset (otInstance * aInstance)

Deletes all the settings stored on non-volatile memory, and then triggers a platform reset.

Parameters
TypeDirectionArgument NameDescription
otInstance *[in]aInstance

A pointer to an OpenThread instance.


otInstanceResetRadioStack#

void otInstanceResetRadioStack (otInstance * aInstance)

Resets the internal states of the OpenThread radio stack.

Parameters
TypeDirectionArgument NameDescription
otInstance *[in]aInstance

A pointer to an OpenThread instance.

Callbacks and configurations are preserved.

This API is only available under radio builds (OPENTHREAD_RADIO = 1).


otInstanceErasePersistentInfo#

otError otInstanceErasePersistentInfo (otInstance * aInstance)

Erases all the OpenThread persistent info (network settings) stored on non-volatile memory.

Parameters
TypeDirectionArgument NameDescription
otInstance *[in]aInstance

A pointer to an OpenThread instance.

Erase is successful only if the device is in disabled state/role.


otGetVersionString#

const char * otGetVersionString (void )

Gets the OpenThread version string.

Parameters
TypeDirectionArgument NameDescription
voidN/A

Returns

  • A pointer to the OpenThread version.


otGetRadioVersionString#

const char * otGetRadioVersionString (otInstance * aInstance)

Gets the OpenThread radio version string.

Parameters
TypeDirectionArgument NameDescription
otInstance *[in]aInstance

A pointer to an OpenThread instance.

Returns

  • A pointer to the OpenThread radio version.


Macro Definition Documentation#

OT_UPTIME_STRING_SIZE#

#define OT_UPTIME_STRING_SIZE
Value:
24

Recommended size for string representation of uptime.


OT_CHANGED_IP6_ADDRESS_ADDED#

#define OT_CHANGED_IP6_ADDRESS_ADDED
Value:
(1U << 0)

IPv6 address was added.


OT_CHANGED_IP6_ADDRESS_REMOVED#

#define OT_CHANGED_IP6_ADDRESS_REMOVED
Value:
(1U << 1)

IPv6 address was removed.


OT_CHANGED_THREAD_ROLE#

#define OT_CHANGED_THREAD_ROLE
Value:
(1U << 2)

Role (disabled, detached, child, router, leader) changed.


OT_CHANGED_THREAD_LL_ADDR#

#define OT_CHANGED_THREAD_LL_ADDR
Value:
(1U << 3)

The link-local address changed.


OT_CHANGED_THREAD_ML_ADDR#

#define OT_CHANGED_THREAD_ML_ADDR
Value:
(1U << 4)

The mesh-local address changed.


OT_CHANGED_THREAD_RLOC_ADDED#

#define OT_CHANGED_THREAD_RLOC_ADDED
Value:
(1U << 5)

RLOC was added.


OT_CHANGED_THREAD_RLOC_REMOVED#

#define OT_CHANGED_THREAD_RLOC_REMOVED
Value:
(1U << 6)

RLOC was removed.


OT_CHANGED_THREAD_PARTITION_ID#

#define OT_CHANGED_THREAD_PARTITION_ID
Value:
(1U << 7)

Partition ID changed.


OT_CHANGED_THREAD_KEY_SEQUENCE_COUNTER#

#define OT_CHANGED_THREAD_KEY_SEQUENCE_COUNTER
Value:
(1U << 8)

Thread Key Sequence changed.


OT_CHANGED_THREAD_NETDATA#

#define OT_CHANGED_THREAD_NETDATA
Value:
(1U << 9)

Thread Network Data changed.


OT_CHANGED_THREAD_CHILD_ADDED#

#define OT_CHANGED_THREAD_CHILD_ADDED
Value:
(1U << 10)

Child was added.


OT_CHANGED_THREAD_CHILD_REMOVED#

#define OT_CHANGED_THREAD_CHILD_REMOVED
Value:
(1U << 11)

Child was removed.


OT_CHANGED_IP6_MULTICAST_SUBSCRIBED#

#define OT_CHANGED_IP6_MULTICAST_SUBSCRIBED
Value:
(1U << 12)

Subscribed to a IPv6 multicast address.


OT_CHANGED_IP6_MULTICAST_UNSUBSCRIBED#

#define OT_CHANGED_IP6_MULTICAST_UNSUBSCRIBED
Value:
(1U << 13)

Unsubscribed from a IPv6 multicast address.


OT_CHANGED_THREAD_CHANNEL#

#define OT_CHANGED_THREAD_CHANNEL
Value:
(1U << 14)

Thread network channel changed.


OT_CHANGED_THREAD_PANID#

#define OT_CHANGED_THREAD_PANID
Value:
(1U << 15)

Thread network PAN Id changed.


OT_CHANGED_THREAD_NETWORK_NAME#

#define OT_CHANGED_THREAD_NETWORK_NAME
Value:
(1U << 16)

Thread network name changed.


OT_CHANGED_THREAD_EXT_PANID#

#define OT_CHANGED_THREAD_EXT_PANID
Value:
(1U << 17)

Thread network extended PAN ID changed.


OT_CHANGED_NETWORK_KEY#

#define OT_CHANGED_NETWORK_KEY
Value:
(1U << 18)

Network key changed.


OT_CHANGED_PSKC#

#define OT_CHANGED_PSKC
Value:
(1U << 19)

PSKc changed.


OT_CHANGED_SECURITY_POLICY#

#define OT_CHANGED_SECURITY_POLICY
Value:
(1U << 20)

Security Policy changed.


OT_CHANGED_CHANNEL_MANAGER_NEW_CHANNEL#

#define OT_CHANGED_CHANNEL_MANAGER_NEW_CHANNEL
Value:
(1U << 21)

Channel Manager new pending Thread channel changed.


OT_CHANGED_SUPPORTED_CHANNEL_MASK#

#define OT_CHANGED_SUPPORTED_CHANNEL_MASK
Value:
(1U << 22)

Supported channel mask changed.


OT_CHANGED_COMMISSIONER_STATE#

#define OT_CHANGED_COMMISSIONER_STATE
Value:
(1U << 23)

Commissioner state changed.


OT_CHANGED_THREAD_NETIF_STATE#

#define OT_CHANGED_THREAD_NETIF_STATE
Value:
(1U << 24)

Thread network interface state changed.


OT_CHANGED_THREAD_BACKBONE_ROUTER_STATE#

#define OT_CHANGED_THREAD_BACKBONE_ROUTER_STATE
Value:
(1U << 25)

Backbone Router state changed.


OT_CHANGED_THREAD_BACKBONE_ROUTER_LOCAL#

#define OT_CHANGED_THREAD_BACKBONE_ROUTER_LOCAL
Value:
(1U << 26)

Local Backbone Router configuration changed.


OT_CHANGED_JOINER_STATE#

#define OT_CHANGED_JOINER_STATE
Value:
(1U << 27)

Joiner state changed.


OT_CHANGED_ACTIVE_DATASET#

#define OT_CHANGED_ACTIVE_DATASET
Value:
(1U << 28)

Active Operational Dataset changed.


OT_CHANGED_PENDING_DATASET#

#define OT_CHANGED_PENDING_DATASET
Value:
(1U << 29)

Pending Operational Dataset changed.


OT_CHANGED_NAT64_TRANSLATOR_STATE#

#define OT_CHANGED_NAT64_TRANSLATOR_STATE
Value:
(1U << 30)

The state of NAT64 translator changed.


OT_CHANGED_PARENT_LINK_QUALITY#

#define OT_CHANGED_PARENT_LINK_QUALITY
Value:
(1U << 31)

Parent link quality changed.