Skip to content
Merged
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
4 changes: 4 additions & 0 deletions applications/serial_lte_modem/doc/SOCKET_AT_commands.rst
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,10 @@ Syntax
Indicates that the socket is in active use by a server application.
This lets the modem stay in connected mode longer.

* ``62`` - :c:macro:`SO_IPV6_DELAYED_ADDR_REFRESH`.

* ``<value>`` is an integer that indicates whether delayed IPv6 address refresh is enabled.
It is ``0`` for disabled or ``1`` for enabled.

See :ref:`nRF socket options <nrfxlib:nrf_sockets>` for explanation of the supported options.

Expand Down
3 changes: 3 additions & 0 deletions applications/serial_lte_modem/src/slm_at_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,9 @@ static int at_sockopt_to_sockopt(enum at_sockopt at_option, int *level, int *opt
*level = IPPROTO_IPV6;
*option = SO_IPV6_ECHO_REPLY;
break;
case AT_SO_IPV6_DELAYED_ADDR_REFRESH:
*level = IPPROTO_IPV6;
*option = SO_IPV6_DELAYED_ADDR_REFRESH;
case AT_SO_BINDTOPDN:
*level = SOL_SOCKET;
*option = SO_BINDTOPDN;
Expand Down
1 change: 1 addition & 0 deletions applications/serial_lte_modem/src/slm_sockopt.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ enum at_sockopt {
AT_SO_BINDTOPDN = 40,
AT_SO_TCP_SRV_SESSTIMEO = 55,
AT_SO_RAI = 61,
AT_SO_IPV6_DELAYED_ADDR_REFRESH = 62,
};

/**
Expand Down
6 changes: 3 additions & 3 deletions applications/serial_lte_modem/src/slm_trap_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
* when forwarding intercepted AT commands from within the callbacks.
* Alternatives to these functions are available in slm_util.h.
*/
#define nrf_modem_at_printf(...) function_disallowed_use_slm_util_alternative(void)
#define nrf_modem_at_scanf(...) function_disallowed_use_slm_util_alternative(void)
#define nrf_modem_at_cmd_async(...) function_disallowed(void)
#define nrf_modem_at_printf(...) function_disallowed_use_slm_util_printf_alternative(__VA_ARGS__)
#define nrf_modem_at_scanf(...) function_disallowed_use_slm_util_scanf_alternative(__VA_ARGS__)
#define nrf_modem_at_cmd_async(...) function_disallowed(__VA_ARGS__)

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ Serial LTE modem
* DTLS support for the ``#XUDPSVR`` and ``#XSSOCKET`` (UDP server sockets) AT commands when the :file:`overlay-native_tls.conf` configuration file is used.
* The :kconfig:option:`CONFIG_SLM_PPP_FALLBACK_MTU` Kconfig option that is used to control the MTU used by PPP when the cellular link MTU is not returned by the modem in response to the ``AT+CGCONTRDP=0`` AT command.
* Handler for new nRF Cloud event type ``NRF_CLOUD_EVT_RX_DATA_DISCON``.
* Support for socket option ``AT_SO_IPV6_DELAYED_ADDR_REFRESH``.

* Removed:

Expand Down Expand Up @@ -828,13 +829,19 @@ Modem libraries

* :ref:`nrf_modem_lib_readme`:

* Added support for socket option ``SO_IPV6_DELAYED_ADDR_REFRESH``.

* Updated:

* The RTT trace backend to allocate the RTT channel at boot, instead of when the modem is activated.
* The flash trace backend to solve concurrency issues when reading traces while writing, and when reinitializing the application (warm start).

* Rename the nRF91 socket offload layer from ``nrf91_sockets`` to ``nrf9x_sockets`` to reflect that the offload layer is not exclusive to the nRF91 Series SiPs.
* Removed support for deprecated RAI socket options ``SO_RAI_LAST``, ``SO_RAI_NO_DATA``, ``SO_RAI_ONE_RESP``, ``SO_RAI_ONGOING``, and ``SO_RAI_WAIT_MORE``.

* Removed:

* Support for deprecated RAI socket options ``SO_RAI_LAST``, ``SO_RAI_NO_DATA``, ``SO_RAI_ONE_RESP``, ``SO_RAI_ONGOING``, and ``SO_RAI_WAIT_MORE``.
* The mutex in the :c:func:`nrf9x_socket_offload_getaddrinfo` function after updating the :c:func:`nrf_getaddrinfo` function to handle concurrent requests.

* :ref:`modem_info_readme` library:

Expand Down
6 changes: 3 additions & 3 deletions lib/gcf_sms/gcf_sms.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ int gcf_sms_filter_callback(char *buf, size_t len, char *at_cmd)
/* AT command is filtered. */
err = (*callback)(buf_remaining, len_remaining, msg);
} else {
err = nrf_modem_at_cmd(buf_remaining, len_remaining, msg);
err = nrf_modem_at_cmd(buf_remaining, len_remaining, "%s", msg);
}

if (err != 0) {
Expand Down Expand Up @@ -370,7 +370,7 @@ static int at_cmd_callback_cmss(char *buf, size_t len, char *at_cmd)
}

/* Send AT+CMGS command to modem. */
err = nrf_modem_at_cmd(buf, len, "AT+CMGS=%d\r%s\x1a\0",
err = nrf_modem_at_cmd(buf, len, "AT+CMGS=%d\r%s\x1a",
sms_buffers[sms_buffer_index].pdu_size,
sms_buffers[sms_buffer_index].data);
if (err) {
Expand All @@ -393,7 +393,7 @@ static int at_cmd_callback_cmms(char *buf, size_t len, char *at_cmd)
int err;

/* Send to modem without buffer. */
err = nrf_modem_at_printf(at_cmd);
err = nrf_modem_at_printf("%s", at_cmd);
if (err) {
if (err > 0) {
LOG_ERR("%s failed, error_type: %d, error_value: %d", at_cmd,
Expand Down
2 changes: 1 addition & 1 deletion lib/modem_attest_token/modem_attest_token.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ int modem_attest_token_get(struct nrf_attestation_token *const token)

/* Execute AT command to get attestation token */
ret = nrf_modem_at_scanf(AT_ATTEST_CMD,
"%%ATTESTTOKEN: \"%127[^.].%127[^\"]\"", &attest, &cose);
"%%ATTESTTOKEN: \"%127[^.].%127[^\"]\"", attest, cose);
if (ret != 2) {
return -EBADMSG;
}
Expand Down
1 change: 1 addition & 0 deletions lib/nrf_modem_lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
zephyr_library()
zephyr_library_sources(nrf_modem_lib.c)
zephyr_library_sources(nrf_modem_os.c)
zephyr_library_sources_ifdef(CONFIG_SOC_SERIES_NRF92X nrf_modem_os_rpc.c)
zephyr_library_sources_ifdef(CONFIG_NRF_MODEM_LIB_CFUN_HOOKS cfun_hooks.c)
zephyr_library_sources_ifdef(CONFIG_NRF_MODEM_LIB_MEM_DIAG diag.c)
zephyr_library_sources_ifdef(CONFIG_NET_SOCKETS nrf9x_sockets.c)
Expand Down
4 changes: 2 additions & 2 deletions lib/nrf_modem_lib/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

menuconfig NRF_MODEM_LIB
bool "Modem library"
depends on SOC_SERIES_NRF91X
depends on TRUSTED_EXECUTION_NONSECURE
depends on (SOC_SERIES_NRF91X && TRUSTED_EXECUTION_NONSECURE) || SOC_NRF9280_CPUAPP
select EXPERIMENTAL if SOC_NRF9280_CPUAPP
select NRF_MODEM
imply NET_SOCKETS_OFFLOAD
imply NET_SOCKETS_POSIX_NAMES if !POSIX_API
Expand Down
17 changes: 17 additions & 0 deletions lib/nrf_modem_lib/Kconfig.modemlib
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ config NRF_MODEM_LIB_SHMEM_CTRL_SIZE
This is a constant for a given library build, and is exported
by the library via NRF_MODEM_SHMEM_CTRL_SIZE.

if SOC_SERIES_NRF91X || UNITY

config NRF_MODEM_LIB_SHMEM_TX_SIZE
int "TX region size"
range 1024 32768
Expand Down Expand Up @@ -67,6 +69,20 @@ config NRF_MODEM_LIB_SHMEM_TRACE_SIZE
help
Size of the shared memory region used to receive modem traces.

endif # SOC_SERIES_NRF91X || UNITY

if SOC_SERIES_NRF92X

config NRF_MODEM_LIB_TRANSPORT_MBOX
bool
default y
select MBOX
select IPC_SERVICE
select IPC_SERVICE_ICMSG
select IPC_SERVICE_ICMSG_SHMEM_ACCESS_SYNC

endif # SOC_SERIES_NRF92X

config NRF_MODEM_LIB_SENDMSG_BUF_SIZE
int "Size of the sendmsg intermediate buffer"
default 128
Expand Down Expand Up @@ -108,6 +124,7 @@ endmenu # Memory config

menuconfig NRF_MODEM_LIB_TRACE
bool "Tracing"
depends on SOC_SERIES_NRF91X || UNITY
help
When enabled, a portion of RAM (called Trace region) will be shared with the modem to receive modem's trace data.
The size of the Trace region is defined by the NRF_MODEM_LIB_SHMEM_TRACE_SIZE option.
Expand Down
9 changes: 4 additions & 5 deletions lib/nrf_modem_lib/nrf9x_sockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@ static int z_to_nrf_optname(int z_in_level, int z_in_optname,
case SO_IPV6_ECHO_REPLY:
*nrf_out_optname = NRF_SO_IPV6_ECHO_REPLY;
break;
case SO_IPV6_DELAYED_ADDR_REFRESH:
*nrf_out_optname = NRF_SO_IPV6_DELAYED_ADDR_REFRESH;
break;
default:
retval = -1;
break;
Expand Down Expand Up @@ -760,7 +763,6 @@ static int nrf9x_socket_offload_getaddrinfo(const char *node,
struct nrf_addrinfo nrf_hints;
struct nrf_addrinfo *nrf_res = NULL;
struct nrf_addrinfo *nrf_hints_ptr = NULL;
static K_MUTEX_DEFINE(getaddrinfo_lock);

memset(&nrf_hints, 0, sizeof(struct nrf_addrinfo));

Expand All @@ -769,11 +771,10 @@ static int nrf9x_socket_offload_getaddrinfo(const char *node,
nrf_hints_ptr = &nrf_hints;
}

k_mutex_lock(&getaddrinfo_lock, K_FOREVER);
int retval = nrf_getaddrinfo(node, service, nrf_hints_ptr, &nrf_res);

if (retval != 0) {
goto error;
return retval;
}

struct nrf_addrinfo *next_nrf_res = nrf_res;
Expand Down Expand Up @@ -817,8 +818,6 @@ static int nrf9x_socket_offload_getaddrinfo(const char *node,
}
nrf_freeaddrinfo(nrf_res);

error:
k_mutex_unlock(&getaddrinfo_lock);
return retval;
}

Expand Down
51 changes: 40 additions & 11 deletions lib/nrf_modem_lib/nrf_modem_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,42 @@
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

#include <nrfx_ipc.h>
#include <modem/nrf_modem_lib.h>
#include <nrf_modem.h>
#include <nrf_modem_at.h>
#include <zephyr/init.h>
#include <zephyr/device.h>
#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>
#include <zephyr/toolchain.h>
#include <modem/nrf_modem_lib.h>

#include <zephyr/logging/log.h>
LOG_MODULE_DECLARE(nrf_modem, CONFIG_NRF_MODEM_LIB_LOG_LEVEL);

#define AT_CFUN_READ "AT+CFUN?"
#define AT_CFUN0_VAL 0
#define AT_CFUN4_VAL 4

static void nrf_modem_lib_dfu_handler(uint32_t dfu_res);

#ifdef CONFIG_SOC_SERIES_NRF91X
#include <modem/nrf_modem_lib_trace.h>
#include <nrfx_ipc.h>
#include <pm_config.h>

#ifndef CONFIG_TRUSTED_EXECUTION_NONSECURE
#error nrf_modem_lib must be run as non-secure firmware.\
Are you building for the correct board ?
#endif /* CONFIG_TRUSTED_EXECUTION_NONSECURE */

LOG_MODULE_DECLARE(nrf_modem, CONFIG_NRF_MODEM_LIB_LOG_LEVEL);

/* Interrupt used for communication with the network layer. */
#define NRF_MODEM_IPC_IRQ DT_IRQ_BY_IDX(DT_NODELABEL(ipc), 0, irq)
BUILD_ASSERT(IPC_IRQn == NRF_MODEM_IPC_IRQ, "NRF_MODEM_IPC_IRQ mismatch");

#define AT_CFUN_READ "AT+CFUN?"
#define AT_CFUN0_VAL 0
#define AT_CFUN4_VAL 4

/* The heap implementation in `nrf_modem_os.c` require some overhead
* to allow allocating up to `NRF_MODEM_LIB_SHMEM_TX_SIZE` bytes.
*/
#define NRF_MODEM_LIB_SHMEM_TX_HEAP_OVERHEAD_SIZE 128

static void nrf_modem_lib_dfu_handler(uint32_t dfu_res);

static const struct nrf_modem_init_params init_params = {
.ipc_irq_prio = CONFIG_NRF_MODEM_LIB_IPC_IRQ_PRIO,
.shmem.ctrl = {
Expand Down Expand Up @@ -69,6 +71,27 @@ static const struct nrf_modem_bootloader_init_params bootloader_init_params = {
.shmem.size = PM_NRF_MODEM_LIB_SRAM_SIZE,
.fault_handler = nrf_modem_fault_handler
};
#endif /* CONFIG_SOC_SERIES_NRF91X */

#ifdef CONFIG_SOC_SERIES_NRF92X

static const struct nrf_modem_init_params init_params = {
.shmem.ctrl = {
.base = DT_REG_ADDR(DT_NODELABEL(cpuapp_cpucell_ipc_shm)),
.size = CONFIG_NRF_MODEM_LIB_SHMEM_CTRL_SIZE,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use DT for size as well and get rid of the KConfig values for nRF92?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, not currently. It must be set to the value of CONFIG_NRF_MODEM_SHMEM_CTRL_SIZE exported by nrf_modem. This is not in the devicetree. Let's see if we can improve this in some later work.

},
.shmem.tx = {
.base = DT_REG_ADDR(DT_NODELABEL(cpuapp_cpucell_ipc_shm_heap)),
.size = DT_REG_SIZE(DT_NODELABEL(cpuapp_cpucell_ipc_shm_heap)),
},
.shmem.rx = {
.base = DT_REG_ADDR(DT_NODELABEL(cpucell_cpuapp_ipc_shm_heap)),
.size = DT_REG_SIZE(DT_NODELABEL(cpucell_cpuapp_ipc_shm_heap)),
},
.fault_handler = nrf_modem_fault_handler,
.dfu_handler = nrf_modem_lib_dfu_handler,
};
#endif /* CONFIG_SOC_SERIES_NRF92X */

#if CONFIG_NRF_MODEM_LIB_TRACE
extern void nrf_modem_lib_trace_init(void);
Expand Down Expand Up @@ -129,11 +152,13 @@ int nrf_modem_lib_init(void)
{
int err;

#ifdef CONFIG_SOC_SERIES_NRF91X
/* Setup the network IRQ used by the Modem library.
* Note: No call to irq_enable() here, that is done through nrf_modem_init().
*/
IRQ_CONNECT(NRF_MODEM_IPC_IRQ, CONFIG_NRF_MODEM_LIB_IPC_IRQ_PRIO,
nrfx_isr, nrfx_ipc_irq_handler, 0);
#endif /* CONFIG_SOC_SERIES_NRF91X */

err = nrf_modem_init(&init_params);
if (err) {
Expand Down Expand Up @@ -161,7 +186,11 @@ int nrf_modem_lib_init(void)

int nrf_modem_lib_bootloader_init(void)
{
#ifdef CONFIG_SOC_SERIES_NRF91X
return nrf_modem_bootloader_init(&bootloader_init_params);
#else
return -ENOSYS;
#endif
}

int nrf_modem_lib_shutdown(void)
Expand Down
25 changes: 20 additions & 5 deletions lib/nrf_modem_lib/nrf_modem_os.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,23 @@
#include <nrf.h>
#include <nrf_errno.h>
#include <errno.h>
#include <pm_config.h>

#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(nrf_modem, CONFIG_NRF_MODEM_LIB_LOG_LEVEL);

#if CONFIG_SOC_SERIES_NRF91X
#include <pm_config.h>
#define SHMEM_TX_HEAP_ADDR (PM_NRF_MODEM_LIB_TX_ADDRESS)
#define SHMEM_TX_HEAP_SIZE (CONFIG_NRF_MODEM_LIB_SHMEM_TX_SIZE)
#elif CONFIG_SOC_SERIES_NRF92X
#define SHMEM_TX_HEAP_ADDR (DT_REG_ADDR(DT_NODELABEL(cpuapp_cpucell_ipc_shm_heap)))
#define SHMEM_TX_HEAP_SIZE (DT_REG_SIZE(DT_NODELABEL(cpuapp_cpucell_ipc_shm_heap)))
#endif


#define UNUSED_FLAGS 0
#define THREAD_MONITOR_ENTRIES 10

LOG_MODULE_REGISTER(nrf_modem, CONFIG_NRF_MODEM_LIB_LOG_LEVEL);

struct sleeping_thread {
sys_snode_t node;
struct k_sem sem;
Expand Down Expand Up @@ -375,7 +384,14 @@ void nrf_modem_os_free(void *mem)
void *nrf_modem_os_shm_tx_alloc(size_t bytes)
{
extern uint32_t nrf_modem_lib_shmem_failed_allocs;

#if (CONFIG_SOC_SERIES_NRF92X && CONFIG_DCACHE)
/* Allocate cache line aligned memory. */
void * const addr = k_heap_aligned_alloc(&nrf_modem_lib_shmem_heap, CONFIG_DCACHE_LINE_SIZE,
ROUND_UP(bytes, CONFIG_DCACHE_LINE_SIZE), K_NO_WAIT);
#else
void * const addr = k_heap_alloc(&nrf_modem_lib_shmem_heap, bytes, K_NO_WAIT);
#endif

if (IS_ENABLED(CONFIG_NRF_MODEM_LIB_MEM_DIAG_ALLOC) && !addr) {
nrf_modem_lib_shmem_failed_allocs++;
Expand Down Expand Up @@ -487,8 +503,7 @@ void nrf_modem_os_init(void)
{
/* Initialize heaps */
k_heap_init(&nrf_modem_lib_heap, library_heap_buf, sizeof(library_heap_buf));
k_heap_init(&nrf_modem_lib_shmem_heap, (void *)PM_NRF_MODEM_LIB_TX_ADDRESS,
CONFIG_NRF_MODEM_LIB_SHMEM_TX_SIZE);
k_heap_init(&nrf_modem_lib_shmem_heap, (void *)SHMEM_TX_HEAP_ADDR, SHMEM_TX_HEAP_SIZE);
}

void nrf_modem_os_shutdown(void)
Expand Down
Loading
Loading