diff --git a/applications/serial_lte_modem/doc/SOCKET_AT_commands.rst b/applications/serial_lte_modem/doc/SOCKET_AT_commands.rst index 036dd3e89205..c60fd125a01d 100644 --- a/applications/serial_lte_modem/doc/SOCKET_AT_commands.rst +++ b/applications/serial_lte_modem/doc/SOCKET_AT_commands.rst @@ -540,35 +540,37 @@ Syntax * ```` is an integer that indicates the packet data network ID to bind to. - * ``50`` - :c:macro:`SO_RAI_NO_DATA` (set-only). - Immediately release the RRC. - - * ```` is ignored. - - * ``51`` - :c:macro:`SO_RAI_LAST` (set-only). - Enter Radio Resource Control (RRC) idle immediately after the next send operation. + * ``55`` - :c:macro:`SO_TCP_SRV_SESSTIMEO`. - * ```` is ignored. + * ```` is an integer that indicates the TCP server session inactivity timeout for a socket. + It accepts value from range ``0`` to ``135``, where ``0`` is no timeout and ``135`` is 2 h 15 min. - * ``52`` - :c:macro:`SO_RAI_ONE_RESP` (set-only). - Wait for one incoming packet after the next send operation, before entering RRC idle mode. + * ``61`` - :c:macro:`SO_RAI` (set-only). + Release Assistance Indication (RAI). - * ```` is ignored. + * ```` The option accepts an integer, indicating the type of RAI. + Accepted values for the option are: - * ``53`` - :c:macro:`SO_RAI_ONGOING` (set-only). - Keep RRC in connected mode after the next send operation (client). + * ``1`` - :c:macro:`RAI_NO_DATA`. + Indicates that the application does not intend to send more data. + This socket option applies immediately and lets the modem exit connected mode more quickly. - * ```` is ignored. + * ``2`` - :c:macro:`RAI_LAST`. + Indicates that the application does not intend to send more data after the next call to :c:func:`send` or :c:func:`sendto`. + This lets the modem exit connected mode more quickly after sending the data. - * ``54`` - :c:macro:`SO_RAI_WAIT_MORE` (set-only). - Keep RRC in connected mode after the next send operation (server). + * ``3`` - :c:macro:`RAI_ONE_RESP`. + Indicates that the application is expecting to receive just one data packet after the next call to :c:func:`send` or :c:func:`sendto`. + This lets the modem exit connected mode more quickly after having received the data. - * ```` is ignored. + * ``4`` - :c:macro:`RAI_ONGOING`. + Indicates that the application is expecting to receive just one data packet after the next call to :c:func:`send` or :c:func:`sendto`. + This lets the modem exit connected mode more quickly after having received the data. - * ``55`` - :c:macro:`SO_TCP_SRV_SESSTIMEO`. + * ``5`` - :c:macro:`RAI_WAIT_MORE`. + Indicates that the socket is in active use by a server application. + This lets the modem stay in connected mode longer. - * ```` is an integer that indicates the TCP server session inactivity timeout for a socket. - It accepts value from range ``0`` to ``135``, where ``0`` is no timeout and ``135`` is 2 h 15 min. See `nRF socket options`_ for explanation of the supported options. diff --git a/applications/serial_lte_modem/src/slm_at_socket.c b/applications/serial_lte_modem/src/slm_at_socket.c index e67b7b3f7eb2..87d25228c96c 100644 --- a/applications/serial_lte_modem/src/slm_at_socket.c +++ b/applications/serial_lte_modem/src/slm_at_socket.c @@ -349,6 +349,10 @@ static int at_sockopt_to_sockopt(enum at_sockopt at_option, int *level, int *opt *level = SOL_SOCKET; *option = SO_BINDTOPDN; break; + case AT_SO_RAI: + *level = SOL_SOCKET; + *option = SO_RAI; + break; case AT_SO_RAI_NO_DATA: *level = SOL_SOCKET; *option = SO_RAI_NO_DATA; diff --git a/applications/serial_lte_modem/src/slm_sockopt.h b/applications/serial_lte_modem/src/slm_sockopt.h index 377596651cd9..c0a2ff46bb67 100644 --- a/applications/serial_lte_modem/src/slm_sockopt.h +++ b/applications/serial_lte_modem/src/slm_sockopt.h @@ -29,7 +29,8 @@ enum at_sockopt { AT_SO_RAI_ONE_RESP = 52, AT_SO_RAI_ONGOING = 53, AT_SO_RAI_WAIT_MORE = 54, - AT_SO_TCP_SRV_SESSTIMEO = 55 + AT_SO_TCP_SRV_SESSTIMEO = 55, + AT_SO_RAI = 61, }; /** diff --git a/doc/nrf/libraries/modem/lte_lc.rst b/doc/nrf/libraries/modem/lte_lc.rst index f32a12f57db8..e491dc4abb2a 100644 --- a/doc/nrf/libraries/modem/lte_lc.rst +++ b/doc/nrf/libraries/modem/lte_lc.rst @@ -201,6 +201,12 @@ These callbacks allow any part of the application to perform certain operations For example, one kind of operation that the application or a library may need to perform and repeat, whenever the modem enters a certain functional mode is the subscription to AT notifications. The application can set up a callback for modem`s functional mode changes using the :c:macro:`LTE_LC_ON_CFUN` macro. +.. important:: + When the :c:macro:`LTE_LC_ON_CFUN` macro is used, the application must not call :c:func:`nrf_modem_at_cfun_handler_set` as that will override the handler set by the modem library integration layer. + +.. note:: + The CFUN callback is not supported with :c:func:`nrf_modem_at_cmd_async`. + The following code snippet shows how to use the :c:macro:`LTE_LC_ON_CFUN` macro: .. code-block:: c diff --git a/doc/nrf/libraries/modem/nrf_modem_lib/nrf_modem_lib_wrapper.rst b/doc/nrf/libraries/modem/nrf_modem_lib/nrf_modem_lib_wrapper.rst index 6f05e9fd9061..92fc23ce965c 100644 --- a/doc/nrf/libraries/modem/nrf_modem_lib/nrf_modem_lib_wrapper.rst +++ b/doc/nrf/libraries/modem/nrf_modem_lib/nrf_modem_lib_wrapper.rst @@ -22,10 +22,13 @@ When using the Modem library in |NCS|, the library must be initialized and shutd .. _mlil_callbacks: -Callbacks -********* +Modem library callbacks +*********************** -The library wrapper also provides callbacks for the initialization and shutdown operations. +Modem initialization and shutdown +================================= + +The library wrapper provides callbacks for the modem initialization and shutdown operations. The application can set up a callback for the :c:func:`nrf_modem_lib_init` function using the :c:macro:`NRF_MODEM_LIB_ON_INIT` macro, and a callback for :c:func:`nrf_modem_lib_shutdown` function using the :c:macro:`NRF_MODEM_LIB_ON_SHUTDOWN` macro. These compile-time callbacks allow any part of the application to perform any setup steps that require the modem to be in a certain state. Furthermore, the callbacks ensure that the setup steps are repeated whenever another part of the application turns the modem on or off. @@ -43,3 +46,19 @@ The callbacks registered using the :c:macro:`NRF_MODEM_LIB_ON_SHUTDOWN` macro ar The callback context is provided to these callbacks. Callbacks for the macro :c:macro:`NRF_MODEM_LIB_ON_SHUTDOWN` must have the signature ``void callback_name(void *ctx)``, where ``ctx`` is the context passed to the macro. See the :ref:`modem_callbacks_sample` sample for more information. + +Modem functional mode changes +============================= + +The library wrapper provides macros for registering multiple callbacks on changes to the modem functional mode. +The application can set up a callback for AT CFUN calls using the :c:macro:`NRF_MODEM_LIB_ON_CFUN` macro. +This compile-time callback allows any part of the application to perform any steps that is required when the modem changes functional mode. +The callbacks registered using the :c:macro:`NRF_MODEM_LIB_ON_CFUN` macro are executed after the functional mode has been successfully set. +See the :ref:`modem_callbacks_sample` sample for more information. + +.. important:: + The application should not call :c:func:`nrf_modem_at_cfun_handler_set` as that will override the handler set by the modem library integration layer. + Instead, the application should use the :c:macro:`NRF_MODEM_LIB_ON_CFUN` macro to register to functional mode changes. + +.. note:: + The CFUN callback is not supported with :c:func:`nrf_modem_at_cmd_async`. diff --git a/doc/nrf/libraries/modem/pdn.rst b/doc/nrf/libraries/modem/pdn.rst index 43893c76998f..f0fa0b938d0f 100644 --- a/doc/nrf/libraries/modem/pdn.rst +++ b/doc/nrf/libraries/modem/pdn.rst @@ -21,9 +21,8 @@ The library uses several AT commands, and it relies on the following two types o * Notifications for unsolicited reporting of error codes sent by the network (``+CNEC``) - Subscribed by using the ``AT+CNEC=16`` command. See the `AT+CNEC set command`_ section in the nRF9160 AT Commands Reference Guide or the `same section `_ in the nRF91x1 AT Commands Reference Guide, depending on the SiP you are using. -If the application uses the :ref:`lte_lc_readme` library to change the modem's functional mode, the PDN library automatically subscribes to the necessary AT notifications. +The PDN library automatically subscribes to the necessary AT notifications using :ref:`mlil_callbacks`. This includes automatically resubscribing to the notifications upon functional mode changes. -If the application does not use the :ref:`lte_lc_readme` library to change the modem's functional mode, the application must subscribe to the necessary AT notifications manually. .. note:: The subscription to AT notifications is lost upon changing the modem functional mode to ``+CFUN=0``. diff --git a/doc/nrf/releases_and_maturity/migration/migration_guide_2.6.rst b/doc/nrf/releases_and_maturity/migration/migration_guide_2.6.rst index 9a079a13a3ea..c503b68646e3 100644 --- a/doc/nrf/releases_and_maturity/migration/migration_guide_2.6.rst +++ b/doc/nrf/releases_and_maturity/migration/migration_guide_2.6.rst @@ -19,6 +19,46 @@ The following changes are mandatory to make your application work in the same wa The setting controls whether the SLM connects automatically to the network on startup. You can read and write it using the ``AT#XCARRIER="auto_connect"`` command. + * The handling of Release Assistance Indication (RAI) socket options has been updated in the ``#XSOCKETOPT`` command. + The individual RAI-related socket options have been consolidated into a single ``SO_RAI`` option. + You must modify your application to use the new ``SO_RAI`` option with the corresponding value to specify the RAI behavior. + The changes are as follows: + + The ``SO_RAI_NO_DATA``, ``SO_RAI_LAST``, ``SO_RAI_ONE_RESP``, ``SO_RAI_ONGOING``, and ``SO_RAI_WAIT_MORE`` options have been replaced by the ``SO_RAI`` option with values from ``1`` to ``5``. + + Here are the changes you need to make in your application code: + + * If you previously used ``AT#XSOCKETOPT=1,50,`` replace it with ``AT#XSOCKETOPT=1,61,1`` to indicate ``RAI_NO_DATA``. + * If you previously used ``AT#XSOCKETOPT=1,51,`` replace it with ``AT#XSOCKETOPT=1,61,2`` to indicate ``RAI_LAST``. + * If you previously used ``AT#XSOCKETOPT=1,52,`` replace it with ``AT#XSOCKETOPT=1,61,3`` to indicate ``RAI_ONE_RESP``. + * If you previously used ``AT#XSOCKETOPT=1,53,`` replace it with ``AT#XSOCKETOPT=1,61,4`` to indicate ``RAI_ONGOING``. + * If you previously used ``AT#XSOCKETOPT=1,54,`` replace it with ``AT#XSOCKETOPT=1,61,5`` to indicate ``RAI_WAIT_MORE``. + +* For applications using :ref:`nrf_modem_lib_readme`: + + * The ``lte_connectivity`` module is renamed to ``lte_net_if``. Please make sure that all references are updated accordingly, including function names and Kconfig options. + + * If your application is using the ``lte_net_if`` (formerly ``lte_connectivity``) without disabling :kconfig:option:`CONFIG_NRF_MODEM_LIB_NET_IF_AUTO_START`, :kconfig:option:`CONFIG_NRF_MODEM_LIB_NET_IF_AUTO_CONNECT`, and :kconfig:option:`CONFIG_NRF_MODEM_LIB_NET_IF_AUTO_DOWN` Kconfig options, changes are required as the default values are changed from enabled to disabled. + + * Consider using the :c:func:`conn_mgr_all_if_up`, :c:func:`conn_mgr_if_connect` and :c:func:`conn_mgr_if_disconnect` functions instead of enabling the Kconfig options to have better control of the initialization and connection establishment. + + * The Release Assistance Indication (RAI) socket options have been deprecated and replaced with a new consolidated socket option. + If your application uses ``SO_RAI_*`` socket options, you need to update your socket configuration as follows: + + #. Replace the deprecated socket options :c:macro:`SO_RAI_NO_DATA`, :c:macro:`SO_RAI_LAST`, :c:macro:`SO_RAI_ONE_RESP`, :c:macro:`SO_RAI_ONGOING`, and :c:macro:`SO_RAI_WAIT_MORE` with the new :c:macro:`SO_RAI` option. + #. Set the optval parameter of the :c:macro:`SO_RAI` socket option to one of the new values :c:macro:`RAI_NO_DATA`, :c:macro:`RAI_LAST`, :c:macro:`RAI_ONE_RESP`, :c:macro:`RAI_ONGOING`, or :c:macro:`RAI_WAIT_MORE` to specify the desired indication. + + Example of migration: + + .. code-block:: c + + /* Before migration. */ + setsockopt(socket_fd, SOL_SOCKET, SO_RAI_LAST, NULL, 0); + + /* After migration. */ + int rai_option = RAI_LAST; + setsockopt(socket_fd, SOL_SOCKET, SO_RAI, &rai_option, sizeof(rai_option)); + * The ``AT#XCMNG`` AT command, which is activated with the :file:`overlay-native_tls.conf` overlay file, has been changed from using modem certificate storage to Zephyr settings storage. You need to use the ``AT#XCMNG`` command to store previously stored credentials again. diff --git a/doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst b/doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst index 932e3887dc7d..2ac98fd497f2 100644 --- a/doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst +++ b/doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst @@ -852,13 +852,26 @@ Modem libraries * A mention about enabling TF-M logging while using modem traces in the :ref:`modem_trace_module`. * The :kconfig:option:`CONFIG_NRF_MODEM_LIB_NET_IF_DOWN_DEFAULT_LTE_DISCONNECT` option, allowing the user to change the behavior of the driver's :c:func:`net_if_down` implementation at build time. + * The :c:macro:`SO_RAI` socket option for Release Assistance Indication (RAI). + The socket option uses values :c:macro:`RAI_NO_DATA`, :c:macro:`RAI_LAST`, :c:macro:`RAI_ONE_RESP`, :c:macro:`RAI_ONGOING`, or :c:macro:`RAI_WAIT_MORE` to specify the desired indication. + This socket option substitutes the deprecated RAI (``SO_RAI_*``) socket options. * Updated: - * The library by renaming ``lte_connectivity`` module to ``lte_net_if``. - All related Kconfig options have been renamed accordingly. - * The default value of the :kconfig:option:`CONFIG_NRF_MODEM_LIB_NET_IF_AUTO_START`, :kconfig:option:`CONFIG_NRF_MODEM_LIB_NET_IF_AUTO_CONNECT`, and :kconfig:option:`CONFIG_NRF_MODEM_LIB_NET_IF_AUTO_DOWN` Kconfig options from enabled to disabled. - * The modem trace shell command implementation is moved from :ref:`modem_shell_application` sample into :ref:`nrf_modem_lib_readme` to be used by any application with the :kconfig:option:`CONFIG_NRF_MODEM_LIB_SHELL_TRACE` option enabled. + * The following socket options have been deprecated: + + * :c:macro:`SO_RAI_NO_DATA` + * :c:macro:`SO_RAI_LAST` + * :c:macro:`SO_RAI_ONE_RESP` + * :c:macro:`SO_RAI_ONGOING` + * :c:macro:`SO_RAI_WAIT_MORE` + + Use the :c:macro:`SO_RAI` socket option instead. + + * The library by renaming ``lte_connectivity`` module to ``lte_net_if``. + All related Kconfig options have been renamed accordingly. + * The default value of the :kconfig:option:`CONFIG_NRF_MODEM_LIB_NET_IF_AUTO_START`, :kconfig:option:`CONFIG_NRF_MODEM_LIB_NET_IF_AUTO_CONNECT`, and :kconfig:option:`CONFIG_NRF_MODEM_LIB_NET_IF_AUTO_DOWN` Kconfig options from enabled to disabled. + * The modem trace shell command implementation is moved from :ref:`modem_shell_application` sample into :ref:`nrf_modem_lib_readme` to be used by any application with the :kconfig:option:`CONFIG_NRF_MODEM_LIB_SHELL_TRACE` option enabled. * Fixed: @@ -881,6 +894,7 @@ Modem libraries * Added the :c:func:`pdn_dynamic_params_get` function to retrieve dynamic parameters of an active PDN connection. * Fixed a potential issue where the library tries to free the PDN context twice, causing the application to crash. * Updated the library to add PDP auto configuration to the :c:enumerator:`LTE_LC_FUNC_MODE_POWER_OFF` event. + * Removed the dependency on the :ref:`lte_lc_readme` library. * :ref:`lib_at_host` library: diff --git a/doc/nrf/test_and_optimize/optimizing/power_nrf91.rst b/doc/nrf/test_and_optimize/optimizing/power_nrf91.rst index a965e70c3ba5..7b7ab719bbba 100644 --- a/doc/nrf/test_and_optimize/optimizing/power_nrf91.rst +++ b/doc/nrf/test_and_optimize/optimizing/power_nrf91.rst @@ -396,7 +396,7 @@ Release Assistance Indication (RAI) If you have low-level control over the protocol your IOT device uses, you might know when you should not expect more data. In that case, you can request to skip the RRC idle mode using :term:`Release Assistance Indication (RAI)`. -The recommended way to do this is using setsockopt with an option like ``SO_RAI_LAST``. +The recommended way to do this is using :c:func:`setsockopt` with the option ``SO_RAI`` and value ``RAI_LAST``. Low battery behavior ==================== diff --git a/include/modem/lte_lc.h b/include/modem/lte_lc.h index 0e78fab44f02..3ac2ae8ee779 100644 --- a/include/modem/lte_lc.h +++ b/include/modem/lte_lc.h @@ -1583,7 +1583,7 @@ int lte_lc_edrx_get(struct lte_lc_edrx_cfg *edrx_cfg); * * For reference see 3GPP 24.301 Ch. 9.9.4.25. * - * @deprecated Use @kconfig{CONFIG_LTE_RAI_REQ} and socket options SO_RAI_* instead. + * @deprecated Use @kconfig{CONFIG_LTE_RAI_REQ} and socket option @ref SO_RAI instead. * * @note This feature is only supported by modem firmware versions < 2.0.0. * @@ -1600,7 +1600,7 @@ __deprecated int lte_lc_rai_param_set(const char *value); * Used RAI value can be set using @kconfig{CONFIG_LTE_RAI_REQ_VALUE} or by calling * lte_lc_rai_param_set(). * - * @deprecated Use @kconfig{CONFIG_LTE_RAI_REQ} and socket options SO_RAI_* instead. + * @deprecated Use @kconfig{CONFIG_LTE_RAI_REQ} and socket option @ref SO_RAI instead. * * @note This feature is only supported by modem firmware versions < 2.0.0. * diff --git a/include/modem/nrf_modem_lib.h b/include/modem/nrf_modem_lib.h index c1785cdd2135..936034431f08 100644 --- a/include/modem/nrf_modem_lib.h +++ b/include/modem/nrf_modem_lib.h @@ -130,11 +130,19 @@ struct nrf_modem_lib_shutdown_cb { void *context; }; +/** + * @brief AT CFUN callback entry. + */ +struct nrf_modem_lib_at_cfun_cb { + /** CFUN callback. */ + void (*callback)(int mode, void *ctx); + /** User defined context */ + void *context; +}; + /** * @brief Define a callback for DFU result @ref nrf_modem_lib_init calls. * - * The callback function @p _callback is invoked after the library has been initialized. - * * @note The @c NRF_MODEM_LIB_ON_DFU_RES callback can be used to subscribe to the result of a modem * DFU operation. * @@ -188,6 +196,20 @@ struct nrf_modem_lib_shutdown_cb { .context = _context, \ }; +/** + * @brief Define a callback for successful AT CFUN calls. + * + * @param name Callback name + * @param _callback Callback function name + * @param _context User-defined context for the callback + */ +#define NRF_MODEM_LIB_ON_CFUN(name, _callback, _context) \ + static void _callback(int mode, void *ctx); \ + STRUCT_SECTION_ITERABLE(nrf_modem_lib_at_cfun_cb, nrf_modem_at_cfun_hook_##name) = { \ + .callback = _callback, \ + .context = _context, \ + }; + /** * @brief Modem fault handler. * diff --git a/lib/lte_link_control/Kconfig b/lib/lte_link_control/Kconfig index ec46a6627289..c171c3dd61b9 100644 --- a/lib/lte_link_control/Kconfig +++ b/lib/lte_link_control/Kconfig @@ -262,7 +262,7 @@ config LTE_RAI_REQ bool "Release Assistance Indication (RAI) request" help Request use of RAI using AT%RAI. When RAI is enabled, the application needs to use - the RAI socket options (SO_RAI_*) to inform the modem when no more data is expected + the RAI socket option (SO_RAI) to inform the modem when no more data is expected and the RRC connection can be released. config LTE_RAI_REQ_VALUE diff --git a/lib/lte_link_control/lte_lc.c b/lib/lte_link_control/lte_lc.c index dad27d0f866f..656f45e1ef48 100644 --- a/lib/lte_link_control/lte_lc.c +++ b/lib/lte_link_control/lte_lc.c @@ -1390,11 +1390,6 @@ int lte_lc_func_mode_set(enum lte_lc_func_mode mode) return -EFAULT; } - STRUCT_SECTION_FOREACH(lte_lc_cfun_cb, e) { - LOG_DBG("CFUN monitor callback: %p", e->callback); - e->callback(mode, e->context); - } - return 0; } diff --git a/lib/lte_link_control/lte_lc_modem_hooks.c b/lib/lte_link_control/lte_lc_modem_hooks.c index 321ac49a2851..d766cdcfec5e 100644 --- a/lib/lte_link_control/lte_lc_modem_hooks.c +++ b/lib/lte_link_control/lte_lc_modem_hooks.c @@ -14,6 +14,8 @@ LOG_MODULE_DECLARE(lte_lc, CONFIG_LTE_LINK_CONTROL_LOG_LEVEL); NRF_MODEM_LIB_ON_INIT(lte_lc_init_hook, on_modem_init, NULL); NRF_MODEM_LIB_ON_SHUTDOWN(lte_lc_shutdown_hook, on_modem_shutdown, NULL); +NRF_MODEM_LIB_ON_CFUN(lte_lc_cfun_hook, on_modem_cfun, NULL); + static void on_modem_init(int err, void *ctx) { extern const enum lte_lc_system_mode lte_lc_sys_mode; @@ -127,3 +129,13 @@ static void on_modem_shutdown(void *ctx) (void)lte_lc_power_off(); } } + +static void on_modem_cfun(int mode, void *ctx) +{ + ARG_UNUSED(ctx); + + STRUCT_SECTION_FOREACH(lte_lc_cfun_cb, e) { + LOG_DBG("CFUN monitor callback: %p", e->callback); + e->callback(mode, e->context); + } +} diff --git a/lib/nrf_modem_lib/CMakeLists.txt b/lib/nrf_modem_lib/CMakeLists.txt index 1581f9671de7..f494b209c337 100644 --- a/lib/nrf_modem_lib/CMakeLists.txt +++ b/lib/nrf_modem_lib/CMakeLists.txt @@ -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_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 nrf91_sockets.c) zephyr_library_include_directories_ifdef(CONFIG_NET_SOCKETS ${ZEPHYR_BASE}/subsys/net/lib/sockets) @@ -23,3 +24,4 @@ zephyr_library_sources(fault.c) zephyr_library_sources(sanity.c) zephyr_linker_sources(RODATA nrf_modem_lib.ld) +zephyr_linker_sources_IFDEF(CONFIG_NRF_MODEM_LIB_CFUN_HOOKS RODATA cfun_hooks.ld) diff --git a/lib/nrf_modem_lib/Kconfig.modemlib b/lib/nrf_modem_lib/Kconfig.modemlib index 498318c89ca2..dadbac65ed81 100644 --- a/lib/nrf_modem_lib/Kconfig.modemlib +++ b/lib/nrf_modem_lib/Kconfig.modemlib @@ -217,6 +217,13 @@ config NRF_MODEM_LIB_ON_FAULT_APPLICATION_SPECIFIC endchoice # NRF_MODEM_LIB_ON_FAULT +config NRF_MODEM_LIB_CFUN_HOOKS + bool "Modem CFUN hooks" + default y + help + Allow the application to subscribe to functional mode changes in the modem + using the NRF_MODEM_LIB_ON_CFUN macro. + config NRF_MODEM_LIB_FAULT_STRERROR bool "Compile fault reason table" help diff --git a/lib/nrf_modem_lib/cfun_hooks.c b/lib/nrf_modem_lib/cfun_hooks.c new file mode 100644 index 000000000000..7ae6c866508a --- /dev/null +++ b/lib/nrf_modem_lib/cfun_hooks.c @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause + */ + +#include +#include +#include +#include +#include + +LOG_MODULE_DECLARE(nrf_modem, CONFIG_NRF_MODEM_LIB_LOG_LEVEL); + +static void cfun_callback(int mode) +{ + STRUCT_SECTION_FOREACH(nrf_modem_lib_at_cfun_cb, e) { + LOG_DBG("CFUN callback %p", e->callback); + e->callback(mode, e->context); + } +} + +static int nrf_modem_lib_cfun_hooks_init(void) +{ + nrf_modem_at_cfun_handler_set(cfun_callback); + + return 0; +} + +SYS_INIT(nrf_modem_lib_cfun_hooks_init, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY); diff --git a/lib/nrf_modem_lib/cfun_hooks.ld b/lib/nrf_modem_lib/cfun_hooks.ld new file mode 100644 index 000000000000..2ff4b79f89de --- /dev/null +++ b/lib/nrf_modem_lib/cfun_hooks.ld @@ -0,0 +1,4 @@ +. = ALIGN(4); +_nrf_modem_lib_at_cfun_cb_list_start = .; +KEEP(*(SORT_BY_NAME("._nrf_modem_lib_at_cfun_cb.*"))); +_nrf_modem_lib_at_cfun_cb_list_end = .; diff --git a/lib/nrf_modem_lib/nrf91_sockets.c b/lib/nrf_modem_lib/nrf91_sockets.c index 0a392be77d49..23ab665337f6 100644 --- a/lib/nrf_modem_lib/nrf91_sockets.c +++ b/lib/nrf_modem_lib/nrf91_sockets.c @@ -198,6 +198,9 @@ static int z_to_nrf_optname(int z_in_level, int z_in_optname, case SO_ERROR: *nrf_out_optname = NRF_SO_ERROR; break; + case SO_KEEPOPEN: + *nrf_out_optname = NRF_SO_KEEPOPEN; + break; case SO_EXCEPTIONAL_DATA: *nrf_out_optname = NRF_SO_EXCEPTIONAL_DATA; break; @@ -213,6 +216,8 @@ static int z_to_nrf_optname(int z_in_level, int z_in_optname, case SO_REUSEADDR: *nrf_out_optname = NRF_SO_REUSEADDR; break; + + /* SO_RAI_* and NRF_SO_RAI_* are deprecated */ case SO_RAI_LAST: *nrf_out_optname = NRF_SO_RAI_LAST; break; @@ -227,6 +232,9 @@ static int z_to_nrf_optname(int z_in_level, int z_in_optname, break; case SO_RAI_WAIT_MORE: *nrf_out_optname = NRF_SO_RAI_WAIT_MORE; + + case SO_RAI: + *nrf_out_optname = NRF_SO_RAI; break; default: retval = -1; @@ -518,7 +526,7 @@ static int nrf91_socket_offload_setsockopt(void *obj, int level, int optname, nrf_optlen = sizeof(struct nrf_timeval); } } else if ((level == SOL_TLS) && (optname == TLS_SESSION_CACHE)) { - nrf_optlen = sizeof(nrf_sec_session_cache_t); + nrf_optlen = sizeof(int); } retval = nrf_setsockopt(sd, nrf_level, nrf_optname, nrf_optval, diff --git a/lib/nrf_modem_lib/nrf_modem_os.c b/lib/nrf_modem_lib/nrf_modem_os.c index e64d7af14458..f48099a0bb4e 100644 --- a/lib/nrf_modem_lib/nrf_modem_os.c +++ b/lib/nrf_modem_lib/nrf_modem_os.c @@ -255,6 +255,10 @@ int nrf_modem_os_sem_init(void **sem, __ASSERT(used < NRF_MODEM_OS_NUM_SEM_REQUIRED, "Not enough semaphores in glue layer"); + if (used >= NRF_MODEM_OS_NUM_SEM_REQUIRED) { + return -NRF_ENOMEM; + } + *sem = &nrf_modem_os_sems[used++]; recycle: @@ -289,6 +293,53 @@ unsigned int nrf_modem_os_sem_count_get(void *sem) return k_sem_count_get(sem); } +static struct k_mutex nrf_modem_os_mutexes[NRF_MODEM_OS_NUM_MUTEX_REQUIRED]; + +int nrf_modem_os_mutex_init(void **mutex) +{ + static uint8_t used; + + if (PART_OF_ARRAY(nrf_modem_os_mutexes, (struct k_mutex *)*mutex)) { + goto recycle; + } + + __ASSERT(used < NRF_MODEM_OS_NUM_MUTEX_REQUIRED, + "Not enough mutexes in glue layer"); + + if (used >= NRF_MODEM_OS_NUM_MUTEX_REQUIRED) { + return -NRF_ENOMEM; + } + + *mutex = &nrf_modem_os_mutexes[used++]; + +recycle: + return k_mutex_init((struct k_mutex *)*mutex); +} + +int nrf_modem_os_mutex_unlock(void *mutex) +{ + __ASSERT(PART_OF_ARRAY(nrf_modem_os_mutexes, (struct k_mutex *)mutex), + "Uninitialised mutex"); + + return k_mutex_unlock((struct k_mutex *)mutex); +} + +int nrf_modem_os_mutex_lock(void *mutex, int timeout) +{ + int err; + + __ASSERT(PART_OF_ARRAY(nrf_modem_os_mutexes, (struct k_mutex *)mutex), + "Uninitialised mutex"); + + err = k_mutex_lock((struct k_mutex *)mutex, timeout == -1 ? K_FOREVER : K_MSEC(timeout)); + if (err) { + return -NRF_EAGAIN; + } + + return 0; +} + + void nrf_modem_os_event_notify(uint32_t context) { atomic_inc(&rpc_event_cnt); diff --git a/lib/pdn/Kconfig b/lib/pdn/Kconfig index ffdca69aa520..e621e8b47d51 100644 --- a/lib/pdn/Kconfig +++ b/lib/pdn/Kconfig @@ -29,7 +29,6 @@ config PDN_INIT_PRIORITY config PDN_DEFAULTS_OVERRIDE bool "Override defaults for PDP context 0" - depends on LTE_LINK_CONTROL help The defaults are overridden automatically as soon as the modem has been initialized. diff --git a/lib/pdn/pdn.c b/lib/pdn/pdn.c index 00d1b3e09ec2..d7ba2106f7bc 100644 --- a/lib/pdn/pdn.c +++ b/lib/pdn/pdn.c @@ -19,9 +19,6 @@ #include #include #include -#if defined(CONFIG_LTE_LINK_CONTROL) -#include -#endif LOG_MODULE_REGISTER(pdn, CONFIG_PDN_LOG_LEVEL); @@ -33,6 +30,10 @@ LOG_MODULE_REGISTER(pdn, CONFIG_PDN_LOG_LEVEL); #define APN_STR_MAX_LEN 64 +#define MODEM_CFUN_POWER_OFF 0 +#define MODEM_CFUN_NORMAL 1 +#define MODEM_CFUN_ACTIVATE_LTE 21 + static K_MUTEX_DEFINE(list_mutex); static sys_slist_t pdn_contexts = SYS_SLIST_STATIC_INIT(&pdn_context); @@ -651,15 +652,14 @@ int pdn_default_apn_get(char *buf, size_t len) return 0; } -#if defined(CONFIG_LTE_LINK_CONTROL) -LTE_LC_ON_CFUN(pdn_cfun_hook, on_cfun, NULL); +NRF_MODEM_LIB_ON_CFUN(pdn_cfun_hook, on_cfun, NULL); -static void on_cfun(enum lte_lc_func_mode mode, void *ctx) +static void on_cfun(int mode, void *ctx) { int err; - if (mode == LTE_LC_FUNC_MODE_NORMAL || - mode == LTE_LC_FUNC_MODE_ACTIVATE_LTE) { + if (mode == MODEM_CFUN_NORMAL || + mode == MODEM_CFUN_ACTIVATE_LTE) { LOG_DBG("Subscribing to +CNEC=16 and +CGEREP=1"); err = nrf_modem_at_printf("AT+CNEC=16"); if (err) { @@ -671,10 +671,9 @@ static void on_cfun(enum lte_lc_func_mode mode, void *ctx) } } - if (mode == LTE_LC_FUNC_MODE_POWER_OFF) { + if (mode == MODEM_CFUN_POWER_OFF) { #if defined(CONFIG_PDN_DEFAULTS_OVERRIDE) pdn_defaults_override(); #endif } } -#endif /* CONFIG_LTE_LINK_CONTROL */ diff --git a/samples/cellular/ciphersuites/src/main.c b/samples/cellular/ciphersuites/src/main.c index 28002e227a9a..3fa8c03ac51d 100644 --- a/samples/cellular/ciphersuites/src/main.c +++ b/samples/cellular/ciphersuites/src/main.c @@ -145,7 +145,7 @@ int main(void) .ai_family = AF_INET, .ai_socktype = SOCK_STREAM, }; - nrf_sec_cipher_t ciphersuite_list[] = { 0 }; + int ciphersuite_list[] = { 0 }; printk("TLS Ciphersuites sample started\n\r"); diff --git a/samples/cellular/modem_callbacks/src/main.c b/samples/cellular/modem_callbacks/src/main.c index 3be0e7052a6c..2c7fa02b8d96 100644 --- a/samples/cellular/modem_callbacks/src/main.c +++ b/samples/cellular/modem_callbacks/src/main.c @@ -23,9 +23,9 @@ static void on_modem_shutdown(void *ctx) printk("> Shutting down\n"); } -LTE_LC_ON_CFUN(cfun_monitor, on_cfun, NULL); +NRF_MODEM_LIB_ON_CFUN(cfun_monitor, on_cfun, NULL); -static void on_cfun(enum lte_lc_func_mode mode, void *ctx) +static void on_cfun(int mode, void *ctx) { printk("> Functional mode has changed to %d\n", mode); } diff --git a/samples/cellular/modem_shell/src/gnss/gnss.c b/samples/cellular/modem_shell/src/gnss/gnss.c index bd3740c2dd7d..9ce091a9a201 100644 --- a/samples/cellular/modem_shell/src/gnss/gnss.c +++ b/samples/cellular/modem_shell/src/gnss/gnss.c @@ -308,6 +308,9 @@ static void print_pvt_flags(struct nrf_modem_gnss_pvt_data_frame *pvt) mosh_print( "Velocity valid: %s", pvt->flags & NRF_MODEM_GNSS_PVT_FLAG_VELOCITY_VALID ? "true" : "false"); + mosh_print( + "Scheduled download: %s", + pvt->flags & NRF_MODEM_GNSS_PVT_FLAG_SCHED_DOWNLOAD ? "true" : "false"); } static void print_pvt(struct nrf_modem_gnss_pvt_data_frame *pvt) @@ -1147,8 +1150,17 @@ int gnss_delete_data(enum gnss_data_delete data) delete_mask = NRF_MODEM_GNSS_DELETE_EPHEMERIDES; break; + case GNSS_DATA_DELETE_EKF: + delete_mask = NRF_MODEM_GNSS_DELETE_EKF; + break; + case GNSS_DATA_DELETE_ALL: - /* Delete everything else but TCXO frequency offset data */ + /* Delete everything else but TCXO frequency offset data. Deleting EKF state is not + * supported by older MFWs and returns an error. Because of this EKF state is + * deleted separately and the return value is ignored. + */ + (void)nrf_modem_gnss_nv_data_delete(NRF_MODEM_GNSS_DELETE_EKF); + delete_mask = NRF_MODEM_GNSS_DELETE_EPHEMERIDES | NRF_MODEM_GNSS_DELETE_ALMANACS | NRF_MODEM_GNSS_DELETE_IONO_CORRECTION_DATA | @@ -1177,6 +1189,19 @@ int gnss_delete_data(enum gnss_data_delete data) return err; } +int gnss_delete_data_custom(uint32_t mask) +{ + int err; + + err = nrf_modem_gnss_nv_data_delete(mask); + if (err) { + mosh_error("GNSS: Failed to delete NV data, error: %d (%s)", + err, gnss_err_to_str(err)); + } + + return err; +} + int gnss_set_continuous_mode(void) { int err; diff --git a/samples/cellular/modem_shell/src/gnss/gnss.h b/samples/cellular/modem_shell/src/gnss/gnss.h index 928155971939..5835391387f7 100644 --- a/samples/cellular/modem_shell/src/gnss/gnss.h +++ b/samples/cellular/modem_shell/src/gnss/gnss.h @@ -17,6 +17,7 @@ enum gnss_duty_cycling_policy { enum gnss_data_delete { GNSS_DATA_DELETE_EPHEMERIDES, + GNSS_DATA_DELETE_EKF, GNSS_DATA_DELETE_ALL, GNSS_DATA_DELETE_TCXO }; @@ -89,6 +90,16 @@ int gnss_stop(void); */ int gnss_delete_data(enum gnss_data_delete data); +/** + * @brief Deletes GNSS data from NV memory using custom bitmask. + * + * @param mask Bitmask indicating which is deleted. + * + * @retval 0 if the operation was successful. + * Otherwise, a (negative) error code is returned. + */ +int gnss_delete_data_custom(uint32_t mask); + /** * @brief Sets continuous tracking mode. * diff --git a/samples/cellular/modem_shell/src/gnss/gnss_shell.c b/samples/cellular/modem_shell/src/gnss/gnss_shell.c index 8d730f792ea1..02e6f3781d9d 100644 --- a/samples/cellular/modem_shell/src/gnss/gnss_shell.c +++ b/samples/cellular/modem_shell/src/gnss/gnss_shell.c @@ -29,6 +29,11 @@ static int cmd_gnss_delete_ephe(const struct shell *shell, size_t argc, char **a return gnss_delete_data(GNSS_DATA_DELETE_EPHEMERIDES) == 0 ? 0 : -ENOEXEC; } +static int cmd_gnss_delete_ekf(const struct shell *shell, size_t argc, char **argv) +{ + return gnss_delete_data(GNSS_DATA_DELETE_EKF) == 0 ? 0 : -ENOEXEC; +} + static int cmd_gnss_delete_all(const struct shell *shell, size_t argc, char **argv) { return gnss_delete_data(GNSS_DATA_DELETE_ALL) == 0 ? 0 : -ENOEXEC; @@ -39,6 +44,22 @@ static int cmd_gnss_delete_tcxo(const struct shell *shell, size_t argc, char **a return gnss_delete_data(GNSS_DATA_DELETE_TCXO) == 0 ? 0 : -ENOEXEC; } +static int cmd_gnss_delete_mask(const struct shell *shell, size_t argc, char **argv) +{ + int err = 0; + uint32_t mask; + + mask = shell_strtoul(argv[1], 16, &err); + + if (err) { + mosh_error("mask: invalid mask value %s", argv[1]); + + return -ENOEXEC; + } + + return gnss_delete_data_custom(mask) == 0 ? 0 : -ENOEXEC; +} + static int cmd_gnss_mode_cont(const struct shell *shell, size_t argc, char **argv) { return gnss_set_continuous_mode() == 0 ? 0 : -ENOEXEC; @@ -672,12 +693,20 @@ static int cmd_gnss_output(const struct shell *shell, size_t argc, char **argv) SHELL_STATIC_SUBCMD_SET_CREATE( sub_gnss_delete, - SHELL_CMD_ARG(ephe, NULL, "Delete ephemerides (forces a warm start).", + SHELL_CMD_ARG(ephe, NULL, "Delete ephemerides (forces a warm start).\n" + "With modem firmware v2.0.1 or later, also the EKF state must " + "be deleted separately to force a warm start.", cmd_gnss_delete_ephe, 1, 0), + SHELL_CMD_ARG(ekf, NULL, "Delete Extended Kalman Filter (EKF) state.\n" + "Only supported by modem firmware v2.0.1 or later.", + cmd_gnss_delete_ekf, 1, 0), SHELL_CMD_ARG(all, NULL, "Delete all data, except the TCXO offset (forces a cold start).", cmd_gnss_delete_all, 1, 0), SHELL_CMD_ARG(tcxo, NULL, "Delete the TCXO offset.", cmd_gnss_delete_tcxo, 1, 0), + SHELL_CMD_ARG(mask, NULL, "\nDelete data using a custom bitmask. The bitmask " + "is given in hex, for example \"17f\".", + cmd_gnss_delete_mask, 2, 0), SHELL_SUBCMD_SET_END ); diff --git a/samples/cellular/modem_shell/src/ping/icmp_ping.c b/samples/cellular/modem_shell/src/ping/icmp_ping.c index 313069db9d87..1b4a8373f951 100644 --- a/samples/cellular/modem_shell/src/ping/icmp_ping.c +++ b/samples/cellular/modem_shell/src/ping/icmp_ping.c @@ -321,12 +321,12 @@ static uint32_t send_ping_wait_reply(struct icmp_ping_shell_cmd_argv *ping_args, #endif if (rai != PING_RAI_NONE) { /* Set RAI option ONGOING except for the last packet for which we set ONE_RESP */ - int rai_option = SO_RAI_ONGOING; + int rai_option = RAI_ONGOING; if (rai == PING_RAI_LAST_PACKET) { - rai_option = SO_RAI_ONE_RESP; + rai_option = RAI_ONE_RESP; } - ret = setsockopt(fd, SOL_SOCKET, rai_option, NULL, 0); + ret = setsockopt(fd, SOL_SOCKET, SO_RAI, &rai_option, sizeof(rai_option)); if (ret) { ping_error(ping_args, "setsockopt() for RAI failed with error %d", errno); goto close_end; @@ -414,8 +414,9 @@ static uint32_t send_ping_wait_reply(struct icmp_ping_shell_cmd_argv *ping_args, } while (true); if (rai == PING_RAI_LAST_PACKET) { + int rai = RAI_NO_DATA; /* Set RAI option NO_DATA after last response has been received */ - ret = setsockopt(fd, SOL_SOCKET, SO_RAI_NO_DATA, NULL, 0); + ret = setsockopt(fd, SOL_SOCKET, SO_RAI, &rai, sizeof(rai)); if (ret) { ping_error( ping_args, "setsockopt() for SO_RAI_NO_DATA failed with error %d", diff --git a/samples/cellular/modem_shell/src/sock/sock.c b/samples/cellular/modem_shell/src/sock/sock.c index 8d9461b1fc80..a6fd91411d88 100644 --- a/samples/cellular/modem_shell/src/sock/sock.c +++ b/samples/cellular/modem_shell/src/sock/sock.c @@ -1223,10 +1223,11 @@ int sock_close(int socket_id) static int sock_rai_option_set(int fd, int option, char *option_string) { - int err = setsockopt(fd, SOL_SOCKET, option, NULL, 0); + int err = setsockopt(fd, SOL_SOCKET, SO_RAI, &option, sizeof(option)); if (err) { - mosh_error("setsockopt() for %s failed, errno %d", option_string, errno); + mosh_error("setsockopt() for SO_RAI with value %s failed with error %d", + option_string, errno); return err; } @@ -1248,41 +1249,41 @@ int sock_rai(int socket_id, bool rai_last, bool rai_no_data, mosh_error("No socket specific RAI options given with -i"); } - /* SO_RAI_LAST */ + /* RAI_LAST */ if (rai_last) { - err = sock_rai_option_set(socket_info->fd, SO_RAI_LAST, "SO_RAI_LAST"); + err = sock_rai_option_set(socket_info->fd, RAI_LAST, "RAI_LAST"); if (err) { return err; } } - /* SO_RAI_NO_DATA */ + /* RAI_NO_DATA */ if (rai_no_data) { - err = sock_rai_option_set(socket_info->fd, SO_RAI_NO_DATA, "SO_RAI_NO_DATA"); + err = sock_rai_option_set(socket_info->fd, RAI_NO_DATA, "RAI_NO_DATA"); if (err) { return err; } } - /* SO_RAI_ONE_RESP */ + /* RAI_ONE_RESP */ if (rai_one_resp) { - err = sock_rai_option_set(socket_info->fd, SO_RAI_ONE_RESP, "SO_RAI_ONE_RESP"); + err = sock_rai_option_set(socket_info->fd, RAI_ONE_RESP, "RAI_ONE_RESP"); if (err) { return err; } } - /* SO_RAI_ONGOING */ + /* RAI_ONGOING */ if (rai_ongoing) { - err = sock_rai_option_set(socket_info->fd, SO_RAI_ONGOING, "SO_RAI_ONGOING"); + err = sock_rai_option_set(socket_info->fd, RAI_ONGOING, "RAI_ONGOING"); if (err) { return err; } } - /* SO_RAI_WAIT_MORE */ + /* RAI_WAIT_MORE */ if (rai_wait_more) { - err = sock_rai_option_set(socket_info->fd, SO_RAI_WAIT_MORE, "SO_RAI_WAIT_MORE"); + err = sock_rai_option_set(socket_info->fd, RAI_WAIT_MORE, "RAI_WAIT_MORE"); if (err) { return err; } diff --git a/samples/cellular/modem_shell/src/sock/sock_shell.c b/samples/cellular/modem_shell/src/sock/sock_shell.c index 4cde7c1c1c1e..592decb3de71 100644 --- a/samples/cellular/modem_shell/src/sock/sock_shell.c +++ b/samples/cellular/modem_shell/src/sock/sock_shell.c @@ -139,27 +139,27 @@ static const char sock_rai_usage_str[] = "Options:\n" " -i, --id, [int] Socket id. Use 'sock list' command to see open\n" " sockets.\n" - " --rai_last, Sets NRF_SO_RAI_LAST option.\n" + " --rai_last, Sets SO_RAI option with value RAI_LAST.\n" " Indicates that the next call to send/sendto will be\n" " the last one for some time, which means that the\n" " modem can get out of connected mode quicker when\n" " this data is sent.\n" - " --rai_no_data, Sets NRF_SO_RAI_NO_DATA option.\n" + " --rai_no_data, Sets SO_RAI option with value RAI_NO_DATA.\n" " Indicates that the application will not send any\n" " more data. This socket option will apply\n" " immediately, and does not require a call to send\n" " afterwards.\n" - " --rai_one_resp, Sets NRF_SO_RAI_ONE_RESP option.\n" + " --rai_one_resp, Sets SO_RAI option with value RAI_ONE_RESP.\n" " Indicates that after the next call to send/sendto,\n" " the application is expecting to receive one more\n" " data packet before this socket will not be used\n" " again for some time.\n" - " --rai_ongoing, Sets NRF_SO_RAI_ONGOING option.\n" + " --rai_ongoing, Sets SO_RAI option with value RAI_ONGOING.\n" " If a client application expects to use the socket\n" " more it can indicate that by setting this socket\n" " option before the next send call which will keep\n" " the modem in connected mode longer.\n" - " --rai_wait_more, Sets NRF_SO_RAI_WAIT_MORE option.\n" + " --rai_wait_more, Sets SO_RAI option with value RAI_WAIT_MORE.\n" " If a server application expects to use the socket\n" " more it can indicate that by setting this socket\n" " option before the next send call.\n" diff --git a/samples/cellular/udp/src/main.c b/samples/cellular/udp/src/main.c index 20f746d24bae..92a6b5c63443 100644 --- a/samples/cellular/udp/src/main.c +++ b/samples/cellular/udp/src/main.c @@ -25,6 +25,7 @@ static void socket_transmission_work_fn(struct k_work *work) { int err; char buffer[CONFIG_UDP_DATA_UPLOAD_SIZE_BYTES] = {"\0"}; + int rai; printk("Transmitting UDP/IP payload of %d bytes to the ", CONFIG_UDP_DATA_UPLOAD_SIZE_BYTES + UDP_IP_HEADER_SIZE); @@ -36,7 +37,8 @@ static void socket_transmission_work_fn(struct k_work *work) /* Let the modem know that this is the last packet for now and we do not * wait for a response. */ - err = setsockopt(client_fd, SOL_SOCKET, SO_RAI_LAST, NULL, 0); + rai = RAI_LAST; + err = setsockopt(client_fd, SOL_SOCKET, SO_RAI, &rai, sizeof(rai)); if (err) { printk("Failed to set socket option, error: %d\n", errno); } diff --git a/subsys/net/lib/lwm2m_client_utils/lwm2m/lwm2m_rai.c b/subsys/net/lib/lwm2m_client_utils/lwm2m/lwm2m_rai.c index b65804cf6623..22a0c18366b7 100644 --- a/subsys/net/lib/lwm2m_client_utils/lwm2m/lwm2m_rai.c +++ b/subsys/net/lib/lwm2m_client_utils/lwm2m/lwm2m_rai.c @@ -99,7 +99,7 @@ void lwm2m_utils_rai_event_cb(struct lwm2m_ctx *client, static void lwm2m_set_socket_state(int sock_fd, enum lwm2m_socket_states state) { - int opt = -1; + int optval = -1; int ret; static enum lwm2m_socket_states last_state; static const char * const opt_names[] = { @@ -114,10 +114,10 @@ static void lwm2m_set_socket_state(int sock_fd, enum lwm2m_socket_states state) } switch (state) { case LWM2M_SOCKET_STATE_ONGOING: - opt = SO_RAI_ONGOING; + optval = RAI_ONGOING; break; case LWM2M_SOCKET_STATE_ONE_RESPONSE: - opt = SO_RAI_ONE_RESP; + optval = RAI_ONE_RESP; break; case LWM2M_SOCKET_STATE_LAST: if (last_state == LWM2M_SOCKET_STATE_NO_DATA) { @@ -127,21 +127,21 @@ static void lwm2m_set_socket_state(int sock_fd, enum lwm2m_socket_states state) * We don't know how many packets are coming, so indicate that * communication is ongoing and disable until we go back to RX_OFF. */ - opt = SO_RAI_ONGOING; + optval = RAI_ONGOING; state = LWM2M_SOCKET_STATE_ONGOING; activate_rai = false; LOG_INF("Ongoing traffic, RAI disabled"); } else { - opt = SO_RAI_LAST; + optval = RAI_LAST; } break; case LWM2M_SOCKET_STATE_NO_DATA: - opt = SO_RAI_NO_DATA; + optval = RAI_NO_DATA; break; } - LOG_DBG("Set socket option SO_RAI_%s\n", opt_names[state]); - ret = setsockopt(sock_fd, SOL_SOCKET, opt, NULL, 0); + LOG_DBG("Set socket option SO_RAI with value %s\n", opt_names[state]); + ret = setsockopt(sock_fd, SOL_SOCKET, SO_RAI, &optval, sizeof(optval)); if (ret < 0) { ret = -errno; diff --git a/tests/lib/nrf_modem_lib/nrf91_sockets/src/nrf91_sockets_test.c b/tests/lib/nrf_modem_lib/nrf91_sockets/src/nrf91_sockets_test.c index 48fdd831ca4d..df14a9beea81 100644 --- a/tests/lib/nrf_modem_lib/nrf91_sockets/src/nrf91_sockets_test.c +++ b/tests/lib/nrf_modem_lib/nrf91_sockets/src/nrf91_sockets_test.c @@ -124,7 +124,7 @@ void test_nrf91_socket_offload_getaddrinfo_errors(void) for (int i = 0; i < ERROR_SIZE; i++) { __cmock_nrf_getaddrinfo_ExpectAndReturn(HTTPS_HOSTNAME, NULL, - NULL, NULL, nrf_errors[i]); + NULL, NULL, nrf_errors[i]); __cmock_nrf_getaddrinfo_IgnoreArg_hints(); __cmock_nrf_getaddrinfo_IgnoreArg_res(); @@ -233,8 +233,7 @@ void test_nrf91_socket_offload_create_close_success(void) int type = SOCK_STREAM; int proto = IPPROTO_TCP; - __cmock_nrf_socket_ExpectAndReturn(NRF_AF_INET, NRF_SOCK_STREAM, - NRF_IPPROTO_TCP, nrf_fd); + __cmock_nrf_socket_ExpectAndReturn(NRF_AF_INET, NRF_SOCK_STREAM, NRF_IPPROTO_TCP, nrf_fd); fd = socket(family, type, proto); @@ -254,8 +253,7 @@ void test_nrf91_socket_offload_socket_error(void) int type = SOCK_STREAM; int proto = IPPROTO_TCP; - __cmock_nrf_socket_ExpectAndReturn(NRF_AF_INET, NRF_SOCK_STREAM, - NRF_IPPROTO_TCP, -1); + __cmock_nrf_socket_ExpectAndReturn(NRF_AF_INET, NRF_SOCK_STREAM, NRF_IPPROTO_TCP, -1); fd = socket(family, type, proto); @@ -296,8 +294,7 @@ void test_nrf91_socket_offload_create_close_proto_zero_success(void) int family = AF_INET; int type = SOCK_STREAM; - __cmock_nrf_socket_ExpectAndReturn(NRF_AF_INET, NRF_SOCK_STREAM, - 0, nrf_fd); + __cmock_nrf_socket_ExpectAndReturn(NRF_AF_INET, NRF_SOCK_STREAM, 0, nrf_fd); fd = socket(family, type, 0); @@ -334,15 +331,13 @@ void test_nrf91_socket_offload_connect_ipv4_success(void) /* IPv4 */ address.sa_family = AF_INET; - __cmock_nrf_socket_ExpectAndReturn(NRF_AF_INET, NRF_SOCK_STREAM, - NRF_IPPROTO_TCP, nrf_fd); + __cmock_nrf_socket_ExpectAndReturn(NRF_AF_INET, NRF_SOCK_STREAM, NRF_IPPROTO_TCP, nrf_fd); fd = socket(family, type, proto); TEST_ASSERT_EQUAL(fd, 0); - __cmock_nrf_connect_ExpectAndReturn(nrf_fd, NULL, - sizeof(struct nrf_sockaddr_in), 0); + __cmock_nrf_connect_ExpectAndReturn(nrf_fd, NULL, sizeof(struct nrf_sockaddr_in), 0); __cmock_nrf_connect_IgnoreArg_address(); ret = connect(fd, &address, sizeof(address)); @@ -369,15 +364,13 @@ void test_nrf91_socket_offload_connect_ipv6_success(void) /* IPv6 */ address.sa_family = AF_INET6; - __cmock_nrf_socket_ExpectAndReturn(NRF_AF_INET6, NRF_SOCK_STREAM, - NRF_IPPROTO_TCP, nrf_fd); + __cmock_nrf_socket_ExpectAndReturn(NRF_AF_INET6, NRF_SOCK_STREAM, NRF_IPPROTO_TCP, nrf_fd); fd = socket(family, type, proto); TEST_ASSERT_EQUAL(fd, 0); - __cmock_nrf_connect_ExpectAndReturn(nrf_fd, NULL, - sizeof(struct nrf_sockaddr_in6), 0); + __cmock_nrf_connect_ExpectAndReturn(nrf_fd, NULL, sizeof(struct nrf_sockaddr_in6), 0); __cmock_nrf_connect_IgnoreArg_address(); ret = connect(fd, &address, sizeof(address)); @@ -401,8 +394,7 @@ void test_nrf91_socket_offload_connect_non_ip_success(void) int proto = IPPROTO_TCP; struct sockaddr address = { 0 }; - __cmock_nrf_socket_ExpectAndReturn(NRF_AF_PACKET, NRF_SOCK_STREAM, - NRF_IPPROTO_TCP, nrf_fd); + __cmock_nrf_socket_ExpectAndReturn(NRF_AF_PACKET, NRF_SOCK_STREAM, NRF_IPPROTO_TCP, nrf_fd); fd = socket(family, type, proto); @@ -578,8 +570,7 @@ void test_nrf91_socket_offload_accept_ebadf(void) address.sin_addr.s_addr = INADDR_ANY; address.sin_port = htons(PORT); - ret = accept(-1, (struct sockaddr *)&address, - (socklen_t *)&addrlen); + ret = accept(-1, (struct sockaddr *)&address, (socklen_t *)&addrlen); TEST_ASSERT_EQUAL(ret, -1); TEST_ASSERT_EQUAL(errno, EBADF); @@ -799,8 +790,7 @@ void test_nrf91_socket_offload_setsockopt_bindtodevice_eopnotsup(void) int proto = IPPROTO_TCP; struct timeval data = { 0 }; - __cmock_nrf_socket_ExpectAndReturn(NRF_AF_INET, NRF_SOCK_STREAM, - NRF_IPPROTO_TCP, nrf_fd); + __cmock_nrf_socket_ExpectAndReturn(NRF_AF_INET, NRF_SOCK_STREAM, NRF_IPPROTO_TCP, nrf_fd); fd = socket(family, type, proto); @@ -827,15 +817,14 @@ void test_nrf91_socket_offload_setsockopt_rcvtimeo_success(void) int proto = IPPROTO_TCP; struct timeval data = { 0 }; - __cmock_nrf_socket_ExpectAndReturn(NRF_AF_INET, NRF_SOCK_STREAM, - NRF_IPPROTO_TCP, nrf_fd); + __cmock_nrf_socket_ExpectAndReturn(NRF_AF_INET, NRF_SOCK_STREAM, NRF_IPPROTO_TCP, nrf_fd); fd = socket(family, type, proto); TEST_ASSERT_EQUAL(fd, 0); __cmock_nrf_setsockopt_ExpectAndReturn(nrf_fd, NRF_SOL_SOCKET, NRF_SO_RCVTIMEO, - NULL, sizeof(struct nrf_timeval), 0); + NULL, sizeof(struct nrf_timeval), 0); __cmock_nrf_setsockopt_IgnoreArg_option_value(); ret = setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &data, sizeof(data)); @@ -858,15 +847,14 @@ void test_nrf91_socket_offload_setsockopt_sndtimeo_success(void) int proto = IPPROTO_TCP; struct timeval data = { 0 }; - __cmock_nrf_socket_ExpectAndReturn(NRF_AF_INET, NRF_SOCK_STREAM, - NRF_IPPROTO_TCP, nrf_fd); + __cmock_nrf_socket_ExpectAndReturn(NRF_AF_INET, NRF_SOCK_STREAM, NRF_IPPROTO_TCP, nrf_fd); fd = socket(family, type, proto); TEST_ASSERT_EQUAL(fd, 0); __cmock_nrf_setsockopt_ExpectAndReturn(nrf_fd, NRF_SOL_SOCKET, NRF_SO_SNDTIMEO, - NULL, sizeof(struct nrf_timeval), 0); + NULL, sizeof(struct nrf_timeval), 0); __cmock_nrf_setsockopt_IgnoreArg_option_value(); ret = setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &data, sizeof(data)); @@ -890,15 +878,14 @@ void test_nrf91_socket_offload_setsockopt_tls_session_cache_success(void) int proto = IPPROTO_TCP; uint8_t data = 0; - __cmock_nrf_socket_ExpectAndReturn(NRF_AF_INET, NRF_SOCK_STREAM, - NRF_IPPROTO_TCP, nrf_fd); + __cmock_nrf_socket_ExpectAndReturn(NRF_AF_INET, NRF_SOCK_STREAM, NRF_IPPROTO_TCP, nrf_fd); fd = socket(family, type, proto); TEST_ASSERT_EQUAL(fd, 0); __cmock_nrf_setsockopt_ExpectAndReturn(nrf_fd, NRF_SOL_SECURE, NRF_SO_SEC_SESSION_CACHE, - NULL, sizeof(nrf_sec_session_cache_t), 0); + NULL, sizeof(int), 0); __cmock_nrf_setsockopt_IgnoreArg_option_value(); ret = setsockopt(fd, SOL_TLS, TLS_SESSION_CACHE, &data, sizeof(data)); @@ -933,15 +920,14 @@ void test_nrf91_socket_offload_getsockopt_rcvtimeo_error(void) struct timeval data = { 0 }; int data_len = sizeof(data); - __cmock_nrf_socket_ExpectAndReturn(NRF_AF_INET, NRF_SOCK_STREAM, - NRF_IPPROTO_TCP, nrf_fd); + __cmock_nrf_socket_ExpectAndReturn(NRF_AF_INET, NRF_SOCK_STREAM, NRF_IPPROTO_TCP, nrf_fd); fd = socket(family, type, proto); TEST_ASSERT_EQUAL(fd, 0); __cmock_nrf_getsockopt_ExpectAndReturn(nrf_fd, NRF_SOL_SOCKET, NRF_SO_RCVTIMEO, - NULL, NULL, -1); + NULL, NULL, -1); __cmock_nrf_getsockopt_IgnoreArg_option_value(); __cmock_nrf_getsockopt_IgnoreArg_option_len(); @@ -967,15 +953,14 @@ void test_nrf91_socket_offload_getsockopt_sndtimeo_error(void) struct timeval data = { 0 }; int data_len = sizeof(data); - __cmock_nrf_socket_ExpectAndReturn(NRF_AF_INET, NRF_SOCK_STREAM, - NRF_IPPROTO_TCP, nrf_fd); + __cmock_nrf_socket_ExpectAndReturn(NRF_AF_INET, NRF_SOCK_STREAM, NRF_IPPROTO_TCP, nrf_fd); fd = socket(family, type, proto); TEST_ASSERT_EQUAL(fd, 0); __cmock_nrf_getsockopt_ExpectAndReturn(nrf_fd, NRF_SOL_SOCKET, NRF_SO_SNDTIMEO, - NULL, NULL, -1); + NULL, NULL, -1); __cmock_nrf_getsockopt_IgnoreArg_option_value(); __cmock_nrf_getsockopt_IgnoreArg_option_len(); @@ -1001,15 +986,14 @@ void test_nrf91_socket_offload_getsockopt_rcvtimeo_success(void) struct timeval data = { 0 }; int data_len = sizeof(data); - __cmock_nrf_socket_ExpectAndReturn(NRF_AF_INET, NRF_SOCK_STREAM, - NRF_IPPROTO_TCP, nrf_fd); + __cmock_nrf_socket_ExpectAndReturn(NRF_AF_INET, NRF_SOCK_STREAM, NRF_IPPROTO_TCP, nrf_fd); fd = socket(family, type, proto); TEST_ASSERT_EQUAL(fd, 0); __cmock_nrf_getsockopt_ExpectAndReturn(nrf_fd, NRF_SOL_SOCKET, NRF_SO_RCVTIMEO, - NULL, NULL, 0); + NULL, NULL, 0); __cmock_nrf_getsockopt_IgnoreArg_option_value(); __cmock_nrf_getsockopt_IgnoreArg_option_len(); @@ -1041,15 +1025,14 @@ void test_nrf91_socket_offload_getsockopt_sndtimeo_success(void) struct timeval data = { 0 }; int data_len = sizeof(data); - __cmock_nrf_socket_ExpectAndReturn(NRF_AF_INET, NRF_SOCK_STREAM, - NRF_IPPROTO_TCP, nrf_fd); + __cmock_nrf_socket_ExpectAndReturn(NRF_AF_INET, NRF_SOCK_STREAM, NRF_IPPROTO_TCP, nrf_fd); fd = socket(family, type, proto); TEST_ASSERT_EQUAL(fd, 0); __cmock_nrf_getsockopt_ExpectAndReturn(nrf_fd, NRF_SOL_SOCKET, NRF_SO_SNDTIMEO, - NULL, NULL, 0); + NULL, NULL, 0); __cmock_nrf_getsockopt_IgnoreArg_option_value(); __cmock_nrf_getsockopt_IgnoreArg_option_len(); @@ -1081,15 +1064,13 @@ void test_nrf91_socket_offload_getsockopt_so_error_success(void) int data = 1; int data_len = 42; - __cmock_nrf_socket_ExpectAndReturn(NRF_AF_INET, NRF_SOCK_STREAM, - NRF_IPPROTO_TCP, nrf_fd); + __cmock_nrf_socket_ExpectAndReturn(NRF_AF_INET, NRF_SOCK_STREAM, NRF_IPPROTO_TCP, nrf_fd); fd = socket(family, type, proto); TEST_ASSERT_EQUAL(fd, 0); - __cmock_nrf_getsockopt_ExpectAndReturn(nrf_fd, NRF_SOL_SOCKET, NRF_SO_ERROR, - NULL, NULL, 0); + __cmock_nrf_getsockopt_ExpectAndReturn(nrf_fd, NRF_SOL_SOCKET, NRF_SO_ERROR, NULL, NULL, 0); __cmock_nrf_getsockopt_IgnoreArg_option_value(); __cmock_nrf_getsockopt_IgnoreArg_option_len(); __cmock_nrf_modem_os_errno_set_Expect(data); @@ -1129,8 +1110,7 @@ void test_nrf91_socket_offload_recvfrom_from_null_error(void) int flags = MSG_WAITALL; socklen_t fromlen = 0; - __cmock_nrf_socket_ExpectAndReturn(NRF_AF_INET, NRF_SOCK_STREAM, - NRF_IPPROTO_TCP, nrf_fd); + __cmock_nrf_socket_ExpectAndReturn(NRF_AF_INET, NRF_SOCK_STREAM, NRF_IPPROTO_TCP, nrf_fd); fd = socket(family, type, proto); @@ -1144,7 +1124,7 @@ void test_nrf91_socket_offload_recvfrom_from_null_error(void) * `fromlen` NULL as well despite passing a pointer to the Zephyr call */ __cmock_nrf_recvfrom_ExpectAndReturn(nrf_fd, data, data_len, NRF_MSG_WAITALL, - NULL, NULL, -1); + NULL, NULL, -1); ret = recvfrom(fd, data, data_len, flags, NULL, &fromlen); @@ -1170,8 +1150,7 @@ void test_nrf91_socket_offload_recvfrom_from_null_success(void) int flags = MSG_WAITALL; socklen_t fromlen = 0; - __cmock_nrf_socket_ExpectAndReturn(NRF_AF_INET, NRF_SOCK_STREAM, - NRF_IPPROTO_TCP, nrf_fd); + __cmock_nrf_socket_ExpectAndReturn(NRF_AF_INET, NRF_SOCK_STREAM, NRF_IPPROTO_TCP, nrf_fd); fd = socket(family, type, proto); @@ -1185,7 +1164,7 @@ void test_nrf91_socket_offload_recvfrom_from_null_success(void) * `fromlen` NULL as well despite passing a pointer to the Zephyr call */ __cmock_nrf_recvfrom_ExpectAndReturn(nrf_fd, data, data_len, NRF_MSG_WAITALL, - NULL, NULL, 8); + NULL, NULL, 8); ret = recvfrom(fd, data, data_len, flags, NULL, &fromlen); @@ -1212,8 +1191,7 @@ void test_nrf91_socket_offload_recvfrom_ipv4_success(void) struct sockaddr from = { 0 }; socklen_t fromlen = 0; - __cmock_nrf_socket_ExpectAndReturn(NRF_AF_INET, NRF_SOCK_STREAM, - NRF_IPPROTO_TCP, nrf_fd); + __cmock_nrf_socket_ExpectAndReturn(NRF_AF_INET, NRF_SOCK_STREAM, NRF_IPPROTO_TCP, nrf_fd); fd = socket(family, type, proto); @@ -1256,8 +1234,7 @@ void test_nrf91_socket_offload_recvfrom_ipv6_success(void) struct sockaddr from = { 0 }; socklen_t fromlen = 0; - __cmock_nrf_socket_ExpectAndReturn(NRF_AF_INET, NRF_SOCK_STREAM, - NRF_IPPROTO_TCP, nrf_fd); + __cmock_nrf_socket_ExpectAndReturn(NRF_AF_INET, NRF_SOCK_STREAM, NRF_IPPROTO_TCP, nrf_fd); fd = socket(family, type, proto); @@ -1308,8 +1285,7 @@ void test_nrf91_socket_offload_sendto_to_null_success(void) size_t data_len = sizeof(data); int flags = MSG_DONTWAIT; - __cmock_nrf_socket_ExpectAndReturn(NRF_AF_INET, NRF_SOCK_STREAM, - NRF_IPPROTO_TCP, nrf_fd); + __cmock_nrf_socket_ExpectAndReturn(NRF_AF_INET, NRF_SOCK_STREAM, NRF_IPPROTO_TCP, nrf_fd); fd = socket(family, type, proto); @@ -1322,8 +1298,7 @@ void test_nrf91_socket_offload_sendto_to_null_success(void) /* Observe that the `tolen` parameter will be changed to zero when * the `to` parameter is NULL */ - __cmock_nrf_sendto_ExpectAndReturn(nrf_fd, data, data_len, - NRF_MSG_DONTWAIT, NULL, 0, 8); + __cmock_nrf_sendto_ExpectAndReturn(nrf_fd, data, data_len, NRF_MSG_DONTWAIT, NULL, 0, 8); ret = sendto(fd, data, data_len, flags, NULL, 42); @@ -1349,8 +1324,7 @@ void test_nrf91_socket_offload_sendto_ipv4_error(void) int flags = MSG_DONTWAIT; struct sockaddr to = { .sa_family = family }; - __cmock_nrf_socket_ExpectAndReturn(NRF_AF_INET, NRF_SOCK_STREAM, - NRF_IPPROTO_TCP, nrf_fd); + __cmock_nrf_socket_ExpectAndReturn(NRF_AF_INET, NRF_SOCK_STREAM, NRF_IPPROTO_TCP, nrf_fd); fd = socket(family, type, proto); @@ -1365,8 +1339,8 @@ void test_nrf91_socket_offload_sendto_ipv4_error(void) * `AF_INET` */ __cmock_nrf_sendto_ExpectAndReturn(nrf_fd, data, data_len, - NRF_MSG_DONTWAIT, NULL, - sizeof(struct nrf_sockaddr_in), -1); + NRF_MSG_DONTWAIT, NULL, + sizeof(struct nrf_sockaddr_in), -1); __cmock_nrf_sendto_IgnoreArg_dest_addr(); ret = sendto(fd, data, data_len, flags, &to, 42); @@ -1393,8 +1367,7 @@ void test_nrf91_socket_offload_sendto_ipv4_success(void) int flags = MSG_DONTWAIT; struct sockaddr to = { .sa_family = family }; - __cmock_nrf_socket_ExpectAndReturn(NRF_AF_INET, NRF_SOCK_STREAM, - NRF_IPPROTO_TCP, nrf_fd); + __cmock_nrf_socket_ExpectAndReturn(NRF_AF_INET, NRF_SOCK_STREAM, NRF_IPPROTO_TCP, nrf_fd); fd = socket(family, type, proto); @@ -1409,8 +1382,8 @@ void test_nrf91_socket_offload_sendto_ipv4_success(void) * `AF_INET` */ __cmock_nrf_sendto_ExpectAndReturn(nrf_fd, data, data_len, - NRF_MSG_DONTWAIT, NULL, - sizeof(struct nrf_sockaddr_in), 8); + NRF_MSG_DONTWAIT, NULL, + sizeof(struct nrf_sockaddr_in), 8); __cmock_nrf_sendto_IgnoreArg_dest_addr(); ret = sendto(fd, data, data_len, flags, &to, 42); @@ -1437,8 +1410,7 @@ void test_nrf91_socket_offload_sendto_ipv6_success(void) int flags = MSG_DONTWAIT; struct sockaddr to = { .sa_family = family }; - __cmock_nrf_socket_ExpectAndReturn(NRF_AF_INET6, NRF_SOCK_STREAM, - NRF_IPPROTO_TCP, nrf_fd); + __cmock_nrf_socket_ExpectAndReturn(NRF_AF_INET6, NRF_SOCK_STREAM, NRF_IPPROTO_TCP, nrf_fd); fd = socket(family, type, proto); @@ -1453,8 +1425,8 @@ void test_nrf91_socket_offload_sendto_ipv6_success(void) * `AF_INET` */ __cmock_nrf_sendto_ExpectAndReturn(nrf_fd, data, data_len, - NRF_MSG_DONTWAIT, NULL, - sizeof(struct nrf_sockaddr_in6), 8); + NRF_MSG_DONTWAIT, NULL, + sizeof(struct nrf_sockaddr_in6), 8); __cmock_nrf_sendto_IgnoreArg_dest_addr(); ret = sendto(fd, data, data_len, flags, &to, 42); @@ -1481,8 +1453,7 @@ void test_nrf91_socket_offload_sendto_not_ipv4_not_ipv6_eafnosupport(void) int flags = MSG_DONTWAIT; struct sockaddr to = { 0 }; - __cmock_nrf_socket_ExpectAndReturn(NRF_AF_INET, NRF_SOCK_STREAM, - NRF_IPPROTO_TCP, nrf_fd); + __cmock_nrf_socket_ExpectAndReturn(NRF_AF_INET, NRF_SOCK_STREAM, NRF_IPPROTO_TCP, nrf_fd); fd = socket(family, type, proto); @@ -1524,8 +1495,7 @@ void test_nrf91_socket_offload_sendmsg_msg_null_einval(void) int proto = IPPROTO_TCP; int flags = MSG_DONTWAIT; - __cmock_nrf_socket_ExpectAndReturn(NRF_AF_INET, NRF_SOCK_STREAM, - NRF_IPPROTO_TCP, nrf_fd); + __cmock_nrf_socket_ExpectAndReturn(NRF_AF_INET, NRF_SOCK_STREAM, NRF_IPPROTO_TCP, nrf_fd); fd = socket(family, type, proto); @@ -1561,8 +1531,7 @@ void test_nrf91_socket_offload_sendmsg_fits_buf(void) int chunk_1 = 42; int chunk_2 = 43; - __cmock_nrf_socket_ExpectAndReturn(NRF_AF_INET, NRF_SOCK_STREAM, - NRF_IPPROTO_TCP, nrf_fd); + __cmock_nrf_socket_ExpectAndReturn(NRF_AF_INET, NRF_SOCK_STREAM, NRF_IPPROTO_TCP, nrf_fd); fd = socket(family, type, proto); @@ -1580,8 +1549,8 @@ void test_nrf91_socket_offload_sendmsg_fits_buf(void) msg.msg_iovlen = 2; __cmock_nrf_sendto_ExpectAndReturn(nrf_fd, NULL, 2 * sizeof(int), - NRF_MSG_DONTWAIT, - NULL, 0, 2 * sizeof(int)); + NRF_MSG_DONTWAIT, + NULL, 0, 2 * sizeof(int)); __cmock_nrf_sendto_IgnoreArg_message(); ret = sendmsg(fd, &msg, flags); @@ -1614,8 +1583,7 @@ void test_nrf91_socket_offload_sendmsg_not_fits_buf(void) int chunk_2 = 43; int chunk_3 = 44; - __cmock_nrf_socket_ExpectAndReturn(NRF_AF_INET, NRF_SOCK_STREAM, - NRF_IPPROTO_TCP, nrf_fd); + __cmock_nrf_socket_ExpectAndReturn(NRF_AF_INET, NRF_SOCK_STREAM, NRF_IPPROTO_TCP, nrf_fd); fd = socket(family, type, proto); @@ -1636,18 +1604,18 @@ void test_nrf91_socket_offload_sendmsg_not_fits_buf(void) /* First send doesn't send all data of the first chunk */ __cmock_nrf_sendto_ExpectAndReturn(nrf_fd, &chunk_1, sizeof(int), - NRF_MSG_DONTWAIT, - NULL, 0, sizeof(int) - 1); + NRF_MSG_DONTWAIT, + NULL, 0, sizeof(int) - 1); /* Second send will send the remaining part of the first chunk */ __cmock_nrf_sendto_ExpectAndReturn(nrf_fd, ((uint8_t *)&chunk_1) + sizeof(int) - 1, 1, - NRF_MSG_DONTWAIT, - NULL, 0, 1); + NRF_MSG_DONTWAIT, + NULL, 0, 1); __cmock_nrf_sendto_ExpectAndReturn(nrf_fd, &chunk_2, sizeof(int), - NRF_MSG_DONTWAIT, - NULL, 0, sizeof(int)); + NRF_MSG_DONTWAIT, + NULL, 0, sizeof(int)); __cmock_nrf_sendto_ExpectAndReturn(nrf_fd, &chunk_3, sizeof(int), - NRF_MSG_DONTWAIT, - NULL, 0, sizeof(int)); + NRF_MSG_DONTWAIT, + NULL, 0, sizeof(int)); __cmock_nrf_sendto_IgnoreArg_message(); ret = sendmsg(fd, &msg, flags); @@ -1671,8 +1639,7 @@ void test_nrf91_socket_offload_fcntl_einval(void) int proto = IPPROTO_TCP; int wrong_command = ~(F_SETFL | F_GETFL); - __cmock_nrf_socket_ExpectAndReturn(NRF_AF_INET, NRF_SOCK_STREAM, - NRF_IPPROTO_TCP, nrf_fd); + __cmock_nrf_socket_ExpectAndReturn(NRF_AF_INET, NRF_SOCK_STREAM, NRF_IPPROTO_TCP, nrf_fd); fd = socket(family, type, proto); @@ -1703,8 +1670,7 @@ void test_nrf91_socket_offload_fcntl_f_setfl(void) int type = SOCK_STREAM; int proto = IPPROTO_TCP; - __cmock_nrf_socket_ExpectAndReturn(NRF_AF_INET, NRF_SOCK_STREAM, - NRF_IPPROTO_TCP, nrf_fd); + __cmock_nrf_socket_ExpectAndReturn(NRF_AF_INET, NRF_SOCK_STREAM, NRF_IPPROTO_TCP, nrf_fd); fd = socket(family, type, proto); @@ -1736,8 +1702,7 @@ void test_nrf91_socket_offload_fcntl_f_getfl(void) int type = SOCK_STREAM; int proto = IPPROTO_TCP; - __cmock_nrf_socket_ExpectAndReturn(NRF_AF_INET, NRF_SOCK_STREAM, - NRF_IPPROTO_TCP, nrf_fd); + __cmock_nrf_socket_ExpectAndReturn(NRF_AF_INET, NRF_SOCK_STREAM, NRF_IPPROTO_TCP, nrf_fd); fd = socket(family, type, proto); diff --git a/tests/lib/sms/src/sms_test.c b/tests/lib/sms/src/sms_test.c index 456d045ac32f..d55c57ccf089 100644 --- a/tests/lib/sms/src/sms_test.c +++ b/tests/lib/sms/src/sms_test.c @@ -298,8 +298,6 @@ void test_sms_reregister_unknown_cms_error_code(void) */ void test_sms_lte_lc_cb_reregisteration(void) { - char cnmi_reg_nok[] = "+CNMI: 0,0,0,0,1\r\n"; - sms_reg_helper(); __mock_nrf_modem_at_printf_ExpectAndReturn("AT+CFUN=4", 0); @@ -309,13 +307,6 @@ void test_sms_lte_lc_cb_reregisteration(void) __mock_nrf_modem_at_printf_ExpectAndReturn("AT+CSCON=1", 0); __mock_nrf_modem_at_printf_ExpectAndReturn("AT+CFUN=21", 0); - __cmock_nrf_modem_at_cmd_ExpectAndReturn(NULL, 0, "AT+CNMI?", 0); - __cmock_nrf_modem_at_cmd_IgnoreArg_buf(); - __cmock_nrf_modem_at_cmd_IgnoreArg_len(); - __cmock_nrf_modem_at_cmd_ReturnArrayThruPtr_buf(cnmi_reg_nok, sizeof(cnmi_reg_nok)); - - __mock_nrf_modem_at_printf_ExpectAndReturn("AT+CNMI=3,2,0,1", 0); - lte_lc_func_mode_set(LTE_LC_FUNC_MODE_ACTIVATE_LTE); sms_unreg_helper(); @@ -329,51 +320,17 @@ void test_sms_lte_lc_cb_reregisteration(void) */ void test_sms_lte_lc_cb_registration_already_exists(void) { - char cnmi_reg_ok[] = "+CNMI: 3,2,0,1,1\r\n"; - sms_reg_helper(); __mock_nrf_modem_at_printf_ExpectAndReturn("AT+CEREG=5", 0); __mock_nrf_modem_at_printf_ExpectAndReturn("AT+CSCON=1", 0); __mock_nrf_modem_at_printf_ExpectAndReturn("AT+CFUN=1", 0); - __cmock_nrf_modem_at_cmd_ExpectAndReturn(NULL, 0, "AT+CNMI?", 0); - __cmock_nrf_modem_at_cmd_IgnoreArg_buf(); - __cmock_nrf_modem_at_cmd_IgnoreArg_len(); - __cmock_nrf_modem_at_cmd_ReturnArrayThruPtr_buf(cnmi_reg_ok, sizeof(cnmi_reg_ok)); lte_lc_func_mode_set(LTE_LC_FUNC_MODE_NORMAL); sms_unreg_helper(); } -/* Test lte_lc callback handling SMS re-registration. - * Tests the following: - * - SMS registration - * - modem offline - * - modem online, SMS re-registeration failing - */ -void test_sms_lte_lc_cb_reregisteration_fail(void) -{ - sms_reg_helper(); - - __mock_nrf_modem_at_printf_ExpectAndReturn("AT+CFUN=4", 0); - lte_lc_func_mode_set(LTE_LC_FUNC_MODE_OFFLINE); - - __mock_nrf_modem_at_printf_ExpectAndReturn("AT+CEREG=5", 0); - __mock_nrf_modem_at_printf_ExpectAndReturn("AT+CSCON=1", 0); - __mock_nrf_modem_at_printf_ExpectAndReturn("AT+CFUN=1", 0); - - __cmock_nrf_modem_at_cmd_ExpectAndReturn(NULL, 0, "AT+CNMI?", -EINVAL); - __cmock_nrf_modem_at_cmd_IgnoreArg_buf(); - __cmock_nrf_modem_at_cmd_IgnoreArg_len(); - - lte_lc_func_mode_set(LTE_LC_FUNC_MODE_NORMAL); - - /* Unregister listener. SMS got unregistered already above */ - sms_unregister_listener(test_handle); - test_handle = -1; -} - /* Test lte_lc callback handling SMS re-registration. * Tests the following: * - modem offline diff --git a/west.yml b/west.yml index b3090141f7d3..39ea3aa6ac82 100644 --- a/west.yml +++ b/west.yml @@ -61,7 +61,7 @@ manifest: # https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/guides/modules.html - name: zephyr repo-path: sdk-zephyr - revision: 17d9e0f7bdfda0a4c88e6ba880d2b0a7314c6cf7 + revision: pull/1530/head import: # In addition to the zephyr repository itself, NCS also # imports the contents of zephyr/west.yml at the above @@ -142,7 +142,7 @@ manifest: - name: nrfxlib repo-path: sdk-nrfxlib path: nrfxlib - revision: b02a54c3ae1421744d5fcd6b9519240f63192e8d + revision: pull/1227/head - name: trusted-firmware-m repo-path: sdk-trusted-firmware-m path: modules/tee/tf-m/trusted-firmware-m