Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/nrf/protocols/thread/configuring.rst
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ For a list of all supported features in the |NCS|, see the :ref:`thread_ug_featu

.. _ug_thread_configuring_eui64:

//TODO:
IEEE 802.15.4 EUI-64 configuration options
==========================================

Expand Down
8 changes: 8 additions & 0 deletions modules/openthread/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,14 @@ target_link_libraries(zephyr PRIVATE ${ot_libs})

endif()

# Create a library for the OpenThread Zephyr utils
zephyr_library_named(openthread_utils)
zephyr_library_sources(
openthread.c
)
zephyr_library_sources_ifdef(CONFIG_OPENTHREAD_SHELL shell.c)
zephyr_include_directories(include)

add_subdirectory(platform)

endif()
36 changes: 35 additions & 1 deletion modules/openthread/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,27 @@ config OPENTHREAD
select ENTROPY_GENERATOR
select NRF_802154_RADIO_DRIVER if HAS_HW_NRF_RADIO_IEEE802154 && !NET_L2_OPENTHREAD
select NRF_802154_SER_HOST if !HAS_HW_NRF_RADIO_IEEE802154 && !NET_L2_OPENTHREAD
select NRF_802154_RADIO_CONFIG if !NET_L2_OPENTHREAD
select NRF_802154_RADIO_CONFIG if HAS_HW_NRF_RADIO_IEEE802154 && !NET_L2_OPENTHREAD
help
This option enables the OpenThread library

if OPENTHREAD

config OPENTHREAD_SYS_INIT
bool "Initialize OpenThread stack during system initialization"
default y
depends on !NET_L2_OPENTHREAD
help
This option initializes the OpenThread automatically by calling the openthread_init()
function during system initialization.

config OPENTHREAD_SYS_INIT_PRIORITY
int "OpenThread system initialization priority"
default 90
depends on OPENTHREAD_SYS_INIT
help
This option sets the priority of the OpenThread system initialization.

choice OPENTHREAD_IMPLEMENTATION
prompt "OpenThread origin selection"
help
Expand Down Expand Up @@ -319,6 +334,21 @@ config OPENTHREAD_INTERFACE_EARLY_UP
Otherwise, OpenThread interface will be marked operational UP only
after the device joins a Thread network.

config OPENTHREAD_PLATFORM_PKT_TXTIME
bool
default y if NET_PKT_TXTIME
default y if !NET_L2_OPENTHREAD
help
Enable packet TX time support. This is needed for when the application
wants to set the exact time when the packet should be sent.

config OPENTHREAD_PLATFORM_CARRIER_FUNCTIONS
bool
default y if OPENTHREAD_DIAG && IEEE802154_CARRIER_FUNCTIONS
default y if OPENTHREAD_DIAG && NRF5_CARRIER_FUNCTIONS
help
Enable support for functions such as modulated carrier and continuous carrier.

menu "OpenThread stack features"
rsource "Kconfig.features"
endmenu
Expand All @@ -327,4 +357,8 @@ menu "Thread Network configuration"
rsource "Kconfig.thread"
endmenu

menu "NRF5 radio configuration"
rsource "Kconfig.nrf5"
endmenu

endif # OPENTHREAD
69 changes: 69 additions & 0 deletions modules/openthread/Kconfig.nrf5
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Copyright (c) 2025 Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0

if !CONFIG_NET_L2_OPENTHREAD

config NRF5_SELECTIVE_TXCHANNEL
bool "Support for selective TX channel setting"
help
Enable support for selectively setting TX channel for every timed transmission request.

config NRF5_CARRIER_FUNCTIONS
bool "Support for carrier functions"
default y if OPENTHREAD_DIAG
help
Enable support for functions such as modulated carrier and continuous carrier.

config NRF5_VENDOR_OUI_ENABLE
bool "Support setting Vendor Organizationally Unique Identifier"
help
This option enables setting custom vendor
OUI using NRF5_VENDOR_OUI . After enabling,
user is obliged to set NRF5_VENDOR_OUI value,
as this option has no default value.

if NRF5_VENDOR_OUI_ENABLE

config NRF5_VENDOR_OUI
int "Vendor Organizationally Unique Identifier"
help
Custom vendor OUI, which makes 24 most-significant
bits of MAC address

endif # NRF5_VENDOR_OUI_ENABLE

config NRF5_UICR_EUI64_ENABLE
bool "Support usage of EUI64 value stored in UICR registers"
depends on !NRF5_VENDOR_OUI_ENABLE
depends on SOC_SERIES_NRF52X || SOC_SERIES_NRF53X
help
This option enables setting custom vendor EUI64 value
stored in User information configuration registers (UICR).
Notice that this disables the default setting of EUI64
value from Factory information configuration registers
(FICR).

if NRF5_UICR_EUI64_ENABLE

config NRF5_UICR_EUI64_REG
int "UICR base register for the EUI64 value"
range 0 30 if SOC_SERIES_NRF52X
range 0 190 if SOC_SERIES_NRF53X
default 0
help
Base of the two consecutive registers from the UICR customer
section in which custom EUI64 is stored.

endif # NRF5_UICR_EUI64_ENABLE

config NRF5_LOG_RX_FAILURES
bool "Frame reception failures logging"
help
There are few cases where the frame reception failure can happen because of
internal cause. These cases are reported forward by general code error.

This options enables logging the reason of frame reception failure.
It can be helpful for the network traffic analyze but it generates also
a lot of log records in a stress environment.

endif # !CONFIG_NET_L2_OPENTHREAD
163 changes: 163 additions & 0 deletions modules/openthread/include/openthread.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
/*
* Copyright (c) 2025 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef ZEPHYR_MODULES_OPENTHREAD_OPENTHREAD_H_
#define ZEPHYR_MODULES_OPENTHREAD_OPENTHREAD_H_

#include <zephyr/kernel.h>

#include <openthread/instance.h>
#include <openthread/message.h>

#ifdef __cplusplus
extern "C" {
#endif

/**
* @brief The common callback type for receiving IPv4 (translated by NAT64) and IPv6 datagrams.
*
* This callback is called when a datagram is received.
*
* @param message The message to receive.
* @param context The context to pass to the callback.
*/
typedef void (*openthread_receive_cb)(struct otMessage *message, void *context);

/** OpenThread state change callback */

/**
* @brief OpenThread state change callback structure
*
* Used to register a callback in the callback list. As many
* callbacks as needed can be added as long as each of them
* are unique pointers of struct openthread_state_changed_callback.
*
* @note You may destroy the object only after it is unregistered from the callback list.
*/
struct openthread_state_changed_callback {
/**
* @brief Callback for notifying configuration or state changes.
*
* @param otCallback OpenThread callback to register.
* See https://openthread.io/reference/group/api-instance#otstatechangedcallback for
* details.
*/
otStateChangedCallback otCallback;

/** User data if required */
void *user_data;

/**
* Internally used field for list handling
* - user must not directly modify
*/
sys_snode_t node;
};

/**
* @brief Register callbacks that will be called when a certain configuration
* or state changes occur within OpenThread.
*
* @param cb Callback struct to register.
*/
int openthread_state_changed_callback_register(struct openthread_state_changed_callback *cb);

/**
* @brief Unregister OpenThread configuration or state changed callbacks.
*
* @param cb Callback struct to unregister.
*/
int openthread_state_changed_callback_unregister(struct openthread_state_changed_callback *cb);

/**
* @brief Get OpenThread thread identification.
*/
k_tid_t openthread_thread_id_get(void);

/**
* @brief Get pointer to default OpenThread instance.
*
* @retval !NULL On success.
* @retval NULL On failure.
*/
struct otInstance *openthread_get_default_instance(void);

/**
* @brief 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.
*
* @retval 0 On success.
* @retval -EIO On failure.
*/
int openthread_init(void);

/**
* @brief Run the OpenThread network.
*
* @details 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.
*/
int openthread_run(void);

/**
* @brief Disable the OpenThread network.
*/
int openthread_stop(void);

/**
* @brief Set the additional callback for receiving packets.
*
* @details 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.
*
* @param cb Callback to set.
* @param context Context to pass to the callback.
*/
void openthread_set_receive_cb(openthread_receive_cb cb, void *context);

/**
* @brief Lock internal mutex before accessing OpenThread API.
*
* @details 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.
*/
void openthread_mutex_lock(void);

/**
* @brief Try to lock internal mutex before accessing OpenThread API.
*
* @details This function behaves like openthread_mutex_lock(), provided that
* the internal mutex is unlocked. Otherwise, it returns a negative value without
* waiting.
*/
int openthread_mutex_try_lock(void);

/**
* @brief Unlock internal mutex after accessing OpenThread API.
*/
void openthread_mutex_unlock(void);

#ifdef __cplusplus
}
#endif

#endif /* ZEPHYR_MODULES_OPENTHREAD_OPENTHREAD_H_ */
Loading