Skip to content
Draft
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 lib/nrf_modem_lib/Kconfig.modemlib
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ config NRF_MODEM_LIB_FAULT_STRERROR
The description can be retrieved with nrf_modem_lib_fault_strerror().

rsource "lte_net_if/Kconfig"
rsource "lte_net_if/Kconfig.ntn"
rsource "shell/Kconfig"

DT_IPC := $(dt_nodelabel_path,ipc)
Expand Down
3 changes: 3 additions & 0 deletions lib/nrf_modem_lib/lte_net_if/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@

target_sources(app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/lte_net_if.c)
target_sources(app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/lte_ip_addr_helper.c)

# Add NTN source file when NTN is enabled
target_sources_ifdef(CONFIG_NRF_MODEM_LIB_NET_IF_NTN app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/lte_net_if_ntn.c)
77 changes: 77 additions & 0 deletions lib/nrf_modem_lib/lte_net_if/Kconfig.ntn
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#
# Copyright (c) 2023 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

menuconfig NRF_MODEM_LIB_NET_IF_NTN
bool "nRF91 LTE network interface for NTN (Non-Terrestrial Network)"
depends on NRF_MODEM_LIB
select CONN_MGR_CONNECTIVITY
help
Enable nRF91 LTE network interface for NTN (Non-Terrestrial Network).
This provides a separate network interface specifically for NTN connectivity,
allowing applications to choose between terrestrial and non-terrestrial networks.

Check failure on line 15 in lib/nrf_modem_lib/lte_net_if/Kconfig.ntn

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

TRAILING_WHITESPACE

lib/nrf_modem_lib/lte_net_if/Kconfig.ntn:15 trailing whitespace
This works alongside the regular LTE network interface and provides similar
functionality but optimized for satellite communication.

if NRF_MODEM_LIB_NET_IF_NTN

config NRF_MODEM_LIB_NET_IF_NTN_AUTO_START
bool "Auto-start NTN interface"
help
Automatically start the NTN network interface when the system starts.
When enabled, the NTN interface will be brought up automatically during
system initialization.

config NRF_MODEM_LIB_NET_IF_NTN_CONNECT_TIMEOUT_SECONDS
int "NTN LTE connection timeout in seconds"
range 0 86400
default 120
help
Time period (in seconds) that the connectivity layer will attempt to establish
an NTN LTE connection for, before timing out. If set to 0, no timeout is applied.

Check failure on line 35 in lib/nrf_modem_lib/lte_net_if/Kconfig.ntn

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

TRAILING_WHITESPACE

lib/nrf_modem_lib/lte_net_if/Kconfig.ntn:35 trailing whitespace
NTN connections may take longer to establish than terrestrial connections
due to the nature of satellite communication, so a longer timeout is recommended.

config NRF_MODEM_LIB_NET_IF_NTN_CONNECTION_PERSISTENCE
bool "NTN Connection persistence"
default y
help
When enabled, the NTN connectivity layer will attempt to keep the NTN LTE connection
active, even after a connection loss, by automatically re-establishing the connection.

Check failure on line 45 in lib/nrf_modem_lib/lte_net_if/Kconfig.ntn

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

TRAILING_WHITESPACE

lib/nrf_modem_lib/lte_net_if/Kconfig.ntn:45 trailing whitespace
This is particularly useful for NTN connections where connectivity may be
intermittent due to satellite coverage patterns.

config NRF_MODEM_LIB_NET_IF_NTN_AUTO_CONNECT
bool "Auto-connect for NTN interface"
default y
help
Automatically connect the NTN interface when it is brought up.
If disabled, the application will need to manually trigger NTN connections.

config NRF_MODEM_LIB_NET_IF_NTN_AUTO_DOWN
bool "Auto-down for NTN interface"
default y
help
Automatically bring down the NTN interface when network connectivity is lost.
If disabled, the interface will remain up even without network connectivity.

config NRF_MODEM_LIB_NET_IF_NTN_DOWN_DEFAULT_LTE_DISCONNECT
bool "Disconnect NTN LTE on interface down"
default y
help
When the NTN network interface is brought down, disconnect from NTN LTE instead
of shutting down the modem completely. This allows for faster re-connection
and preserves the ability to use other network interfaces.

module = NRF_MODEM_LIB_NET_IF_NTN
module-dep = LOG
module-str = nRF91 NTN LTE network interface
module-help = Enables logging for nRF91 NTN LTE network interface.
source "subsys/logging/Kconfig.template.log_config"

endif # NRF_MODEM_LIB_NET_IF_NTN
84 changes: 84 additions & 0 deletions lib/nrf_modem_lib/lte_net_if/lte_net_if_ntn.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*
*/

#include <zephyr/device.h>
#include <zephyr/types.h>
#include <zephyr/net/offloaded_netdev.h>
#include <zephyr/net/conn_mgr_connectivity_impl.h>
#include <zephyr/logging/log.h>
#include <modem/nrf_modem_lib.h>
#include <modem/lte_lc.h>
#include <modem/pdn.h>

#include "lte_ip_addr_helper.h"

LOG_MODULE_REGISTER(nrf_modem_lib_netif_ntn, CONFIG_NRF_MODEM_LIB_NET_IF_NTN_LOG_LEVEL);

/* Forward declarations */
static int lte_net_if_disconnect_ntn(struct conn_mgr_conn_binding *const if_conn);

static void lte_net_if_init_ntn(struct conn_mgr_conn_binding *if_conn)
{
LOG_DBG("Initializing NTN modem network interface");

/* Init stuff goes here */

Check failure on line 28 in lib/nrf_modem_lib/lte_net_if/lte_net_if_ntn.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

lib/nrf_modem_lib/lte_net_if/lte_net_if_ntn.c:28 code indent should use tabs where possible
}

int lte_net_if_enable_ntn(void)
{
LOG_DBG("Enabling NTN");

Check warning on line 33 in lib/nrf_modem_lib/lte_net_if/lte_net_if_ntn.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

lib/nrf_modem_lib/lte_net_if/lte_net_if_ntn.c:33 please, no spaces at the start of a line

Check failure on line 33 in lib/nrf_modem_lib/lte_net_if/lte_net_if_ntn.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

lib/nrf_modem_lib/lte_net_if/lte_net_if_ntn.c:33 code indent should use tabs where possible

if (!nrf_modem_is_initialized()) {
return nrf_modem_lib_init();
}

return 0;
}

int lte_net_if_disable_ntn(void)
{
LOG_DBG("Disabling NTN");

Check warning on line 44 in lib/nrf_modem_lib/lte_net_if/lte_net_if_ntn.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

lib/nrf_modem_lib/lte_net_if/lte_net_if_ntn.c:44 please, no spaces at the start of a line

Check failure on line 44 in lib/nrf_modem_lib/lte_net_if/lte_net_if_ntn.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

lib/nrf_modem_lib/lte_net_if/lte_net_if_ntn.c:44 code indent should use tabs where possible

if (IS_ENABLED(CONFIG_NRF_MODEM_LIB_NET_IF_NTN_DOWN_DEFAULT_LTE_DISCONNECT)) {
return lte_net_if_disconnect_ntn(NULL);
} else {
return nrf_modem_lib_shutdown();
}

return 0;

Check warning on line 52 in lib/nrf_modem_lib/lte_net_if/lte_net_if_ntn.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

lib/nrf_modem_lib/lte_net_if/lte_net_if_ntn.c:52 please, no spaces at the start of a line

Check failure on line 52 in lib/nrf_modem_lib/lte_net_if/lte_net_if_ntn.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

lib/nrf_modem_lib/lte_net_if/lte_net_if_ntn.c:52 code indent should use tabs where possible
}

static int lte_net_if_connect_ntn(struct conn_mgr_conn_binding *const if_conn)
{
ARG_UNUSED(if_conn);

LOG_DBG("Connecting to NTN");

Check warning on line 59 in lib/nrf_modem_lib/lte_net_if/lte_net_if_ntn.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

lib/nrf_modem_lib/lte_net_if/lte_net_if_ntn.c:59 please, no spaces at the start of a line

Check failure on line 59 in lib/nrf_modem_lib/lte_net_if/lte_net_if_ntn.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

lib/nrf_modem_lib/lte_net_if/lte_net_if_ntn.c:59 code indent should use tabs where possible

/* Connect stuff goes here */

Check failure on line 61 in lib/nrf_modem_lib/lte_net_if/lte_net_if_ntn.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

lib/nrf_modem_lib/lte_net_if/lte_net_if_ntn.c:61 code indent should use tabs where possible

return 0;
}

static int lte_net_if_disconnect_ntn(struct conn_mgr_conn_binding *const if_conn)
{
ARG_UNUSED(if_conn);

LOG_DBG("Disconnecting from NTN");

Check warning on line 70 in lib/nrf_modem_lib/lte_net_if/lte_net_if_ntn.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

lib/nrf_modem_lib/lte_net_if/lte_net_if_ntn.c:70 please, no spaces at the start of a line

Check failure on line 70 in lib/nrf_modem_lib/lte_net_if/lte_net_if_ntn.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

lib/nrf_modem_lib/lte_net_if/lte_net_if_ntn.c:70 code indent should use tabs where possible

/* Disconnect stuff goes here */

return 0;
}

/* Bind connectivity APIs for NTN.
* extern in nrf9x_sockets.c
*/
struct conn_mgr_conn_api lte_net_if_conn_mgr_api_ntn = {
.init = lte_net_if_init_ntn,
.connect = lte_net_if_connect_ntn,
.disconnect = lte_net_if_disconnect_ntn,
};
49 changes: 49 additions & 0 deletions lib/nrf_modem_lib/nrf9x_sockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
* Required but not implemented.
*/
#define NRF_MODEM_LIB_NET_IF_CTX_TYPE void *
#define NRF_MODEM_LIB_NET_IF_NTN_CTX_TYPE void *

#define OBJ_TO_SD(obj) (((struct nrf_sock_ctx *)obj)->nrf_fd)
#define OBJ_TO_CTX(obj) ((struct nrf_sock_ctx *)obj)
Expand Down Expand Up @@ -1177,10 +1178,58 @@ NET_DEVICE_OFFLOAD_INIT(nrf9x_socket, "nrf9x_socket",
&nrf9x_iface_data, NULL,
0, &nrf9x_iface_offload_api, 1280);

#if defined(CONFIG_NRF_MODEM_LIB_NET_IF_NTN)
static struct nrf9x_iface_data_ntn {
struct net_if *iface;
} nrf9x_iface_data_ntn;

static void nrf9x_iface_api_init_ntn(struct net_if *iface)
{
nrf9x_iface_data_ntn.iface = iface;

iface->if_dev->socket_offload = nrf9x_socket_create;

/* NTN shares the same DNS offload operations */
socket_offload_dns_register(&nrf9x_socket_dns_offload_ops);

if (!IS_ENABLED(CONFIG_NRF_MODEM_LIB_NET_IF_NTN_AUTO_START)) {
net_if_flag_set(iface, NET_IF_NO_AUTO_START);
}
}

static int nrf9x_iface_enable_ntn(const struct net_if *iface, bool enabled)
{
/* Enables or disable the NTN device (in response to admin state change) */
extern int lte_net_if_enable_ntn(void);
extern int lte_net_if_disable_ntn(void);

return enabled ? lte_net_if_enable_ntn() :
lte_net_if_disable_ntn();
}

static struct offloaded_if_api nrf9x_iface_offload_api_ntn = {
.iface_api.init = nrf9x_iface_api_init_ntn,
.enable = nrf9x_iface_enable_ntn,
};

/* NTN network device for Non-Terrestrial Network */
NET_DEVICE_OFFLOAD_INIT(nrf9x_socket_ntn, "nrf9x_socket_ntn",
nrf9x_socket_offload_init,
NULL,
&nrf9x_iface_data_ntn, NULL,
0, &nrf9x_iface_offload_api_ntn, 1280);
#endif /* CONFIG_NRF_MODEM_LIB_NET_IF_NTN */

#if defined(CONFIG_NRF_MODEM_LIB_NET_IF)
extern struct conn_mgr_conn_api lte_net_if_conn_mgr_api;
CONN_MGR_CONN_DEFINE(NRF_MODEM_LIB_NET_IF, &lte_net_if_conn_mgr_api);
CONN_MGR_BIND_CONN(nrf9x_socket, NRF_MODEM_LIB_NET_IF);
#endif /* CONFIG_NRF_MODEM_LIB_NET_IF */

#if defined(CONFIG_NRF_MODEM_LIB_NET_IF_NTN)
extern struct conn_mgr_conn_api lte_net_if_conn_mgr_api_ntn;
CONN_MGR_CONN_DEFINE(NRF_MODEM_LIB_NET_IF_NTN, &lte_net_if_conn_mgr_api_ntn);
CONN_MGR_BIND_CONN(nrf9x_socket_ntn, NRF_MODEM_LIB_NET_IF_NTN);
#endif /* CONFIG_NRF_MODEM_LIB_NET_IF_NTN */

#endif /* CONFIG_NET_SOCKETS_OFFLOAD */
16 changes: 16 additions & 0 deletions samples/net/ntn/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#
# Copyright (c) 2023 Nordic Semiconductor
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

cmake_minimum_required(VERSION 3.20.0)

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(ntn)

# NORDIC SDK APP START
target_sources(app PRIVATE src/main.c)
# NORDIC SDK APP END

zephyr_include_directories(src)
33 changes: 33 additions & 0 deletions samples/net/ntn/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#
# Copyright (c) 2023 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

menu "NTN sample settings"

config NTN_SAMPLE_DATA_UPLOAD_SIZE_BYTES
int "Number of bytes transmitted to the server"
default 10

config NTN_SAMPLE_DATA_UPLOAD_FREQUENCY_SECONDS
int "How often data is transmitted to the server"
default 900

config NTN_SAMPLE_SERVER_ADDRESS_STATIC
string "UDP server IP address"
default "8.8.8.8"

config NTN_SAMPLE_SERVER_PORT
int "UDP server port number"
default "2469"

endmenu

module = NTN_SAMPLE
module-str = NTN sample
source "$(ZEPHYR_BASE)/subsys/logging/Kconfig.template.log_config"

menu "Zephyr Kernel"
source "Kconfig.zephyr"
endmenu
40 changes: 40 additions & 0 deletions samples/net/ntn/boards/nrf9151dk_nrf9151_ns.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#
# Copyright (c) 2024 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

# Modem trace
CONFIG_NRF_MODEM_LIB_TRACE=y
CONFIG_NRF_MODEM_LIB_TRACE_BACKEND_UART=y
CONFIG_SERIAL=y
CONFIG_UART_ASYNC_API=y
CONFIG_UART_1_ASYNC=y
CONFIG_UART_1_INTERRUPT_DRIVEN=n

# Disable Duplicate Address Detection (DAD)
# due to not being properly implemented for offloaded interfaces.
CONFIG_NET_IPV6_NBR_CACHE=n
CONFIG_NET_IPV6_MLD=n

# Offload network operations to the modem.
CONFIG_NET_SOCKETS_OFFLOAD=y

# Zephyr NET Connection Manager and Connectivity layer.
CONFIG_NET_CONNECTION_MANAGER_MONITOR_STACK_SIZE=1024
CONFIG_NRF_MODEM_LIB_NET_IF=y
CONFIG_NRF_MODEM_LIB_NET_IF_LOG_LEVEL_DBG=y
CONFIG_NRF_MODEM_LIB_NET_IF_NTN=y
CONFIG_NRF_MODEM_LIB_NET_IF_NTN_LOG_LEVEL_DBG=y

## PSM
CONFIG_LTE_PSM_REQ=y
CONFIG_LTE_PSM_REQ_RPTAU="00100001"
CONFIG_LTE_PSM_REQ_RAT="00000000"

## eDRX
CONFIG_LTE_EDRX_REQ=n
CONFIG_LTE_EDRX_REQ_VALUE_LTE_M="1001"

## RAI
CONFIG_LTE_RAI_REQ=n
18 changes: 18 additions & 0 deletions samples/net/ntn/boards/nrf9151dk_nrf9151_ns.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright (c) 2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

/* Enable uart1 for tracing. */
&uart1 {
status = "okay";
current-speed = < 1000000 >;
hw-flow-control;
};

/ {
chosen {
nordic,modem-trace-uart = &uart1;
};
};
21 changes: 21 additions & 0 deletions samples/net/ntn/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#
# Copyright (c) 2023 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

# General configurations
CONFIG_LOG=y

# Network
CONFIG_NETWORKING=y
CONFIG_NET_NATIVE=y
CONFIG_NET_IPV4=y
CONFIG_NET_SOCKETS=y
CONFIG_POSIX_API=y
CONFIG_NET_CONNECTION_MANAGER=y

# Heap and stacks
CONFIG_HEAP_MEM_POOL_SIZE=1280
CONFIG_MAIN_STACK_SIZE=4096
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
Loading
Loading