Zephyr API Documentation 4.1.99
A Scalable Open Source RTOS
 4.1.99
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
openthread.h File Reference
#include <zephyr/kernel.h>
#include <openthread/instance.h>
#include <openthread/message.h>

Go to the source code of this file.

Data Structures

struct  openthread_state_changed_callback
 OpenThread state change callback
More...
 

Typedefs

typedef void(* openthread_receive_cb) (struct otMessage *message, void *context)
 The common callback type for receiving IPv4 (translated by NAT64) and IPv6 datagrams.
 

Functions

int openthread_state_changed_callback_register (struct openthread_state_changed_callback *cb)
 Register callbacks that will be called when a certain configuration or state changes occur within OpenThread.
 
int openthread_state_changed_callback_unregister (struct openthread_state_changed_callback *cb)
 Unregister OpenThread configuration or state changed callbacks.
 
k_tid_t openthread_thread_id_get (void)
 Get OpenThread thread identification.
 
struct otInstance * openthread_get_default_instance (void)
 Get pointer to default OpenThread instance.
 
int openthread_init (void)
 Initialize the OpenThread module.
 
int openthread_run (void)
 Run the OpenThread network.
 
int openthread_stop (void)
 Disable the OpenThread network.
 
void openthread_set_receive_cb (openthread_receive_cb cb, void *context)
 Set the additional callback for receiving packets.
 
void openthread_mutex_lock (void)
 Lock internal mutex before accessing OpenThread API.
 
int openthread_mutex_try_lock (void)
 Try to lock internal mutex before accessing OpenThread API.
 
void openthread_mutex_unlock (void)
 Unlock internal mutex after accessing OpenThread API.
 

Typedef Documentation

◆ openthread_receive_cb

typedef void(* openthread_receive_cb) (struct otMessage *message, void *context)

The common callback type for receiving IPv4 (translated by NAT64) and IPv6 datagrams.

This callback is called when a datagram is received.

Parameters
messageThe message to receive.
contextThe context to pass to the callback.

Function Documentation

◆ openthread_get_default_instance()

struct otInstance * openthread_get_default_instance ( void )

Get pointer to default OpenThread instance.

Return values
!NULLOn success.
NULLOn failure.

◆ openthread_init()

int openthread_init ( void )

Initialize the OpenThread module.

This function:

  • Initializes the OpenThread module.
  • Creates an OpenThread single instance.
  • Starts the shell.
  • Enables the UART and NCP HDLC for coprocessor purposes.
  • Initializes the NAT64 translator.
  • Creates a work queue for the OpenThread module.
Note
This function is automatically called by Zephyr's networking layer. If you want to initialize the OpenThread independently, call this function in your application init code.
Return values
0On success.
-EIOOn failure.

◆ openthread_mutex_lock()

void openthread_mutex_lock ( void )

Lock internal mutex before accessing OpenThread API.

OpenThread API is not thread-safe. Therefore, before accessing any API function, you need to lock the internal mutex, to prevent the OpenThread thread from pre-empting the API call.

◆ openthread_mutex_try_lock()

int openthread_mutex_try_lock ( void )

Try to lock internal mutex before accessing OpenThread API.

This function behaves like openthread_mutex_lock(), provided that the internal mutex is unlocked. Otherwise, it returns a negative value without waiting.

◆ openthread_mutex_unlock()

void openthread_mutex_unlock ( void )

Unlock internal mutex after accessing OpenThread API.

◆ openthread_run()

int openthread_run ( void )

Run the OpenThread network.

Prepares the OpenThread network and enables it. Depends on active settings: it uses the stored network configuration, starts the joining procedure or uses the default network configuration. Additionally, when the device is MTD, it sets the SED mode to properly attach the network.

◆ openthread_set_receive_cb()

void openthread_set_receive_cb ( openthread_receive_cb cb,
void * context )

Set the additional callback for receiving packets.

This callback is called once a packet is received and can be used to inject packets into the Zephyr networking stack. Setting this callback is optional.

Parameters
cbCallback to set.
contextContext to pass to the callback.

◆ openthread_state_changed_callback_register()

int openthread_state_changed_callback_register ( struct openthread_state_changed_callback * cb)

Register callbacks that will be called when a certain configuration or state changes occur within OpenThread.

Parameters
cbCallback struct to register.

◆ openthread_state_changed_callback_unregister()

int openthread_state_changed_callback_unregister ( struct openthread_state_changed_callback * cb)

Unregister OpenThread configuration or state changed callbacks.

Parameters
cbCallback struct to unregister.

◆ openthread_stop()

int openthread_stop ( void )

Disable the OpenThread network.

◆ openthread_thread_id_get()

k_tid_t openthread_thread_id_get ( void )

Get OpenThread thread identification.