Skip to content

Commit db2d830

Browse files
jtguggedaljorgenmk
authored andcommitted
lib: lte_lc: Integrate PDN library
Copies the PDN functionality from the PDN library that is about to be deprecated, and adds it as a module in the LTE link controller library. The functionality is the same, but with naming changes to types and APIs to align with the rest of LTE link controller. In addition, PDN events are now part of the LTE LC events, and there is no longer need for a separate event handler. Signed-off-by: Jan Tore Guggedal <[email protected]>
1 parent dbddb9c commit db2d830

File tree

10 files changed

+1727
-2
lines changed

10 files changed

+1727
-2
lines changed

doc/nrf/libraries/modem/lte_lc.rst

Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,30 @@ Environment Evaluation:
165165
* :c:func:`lte_lc_env_eval`
166166
* :c:func:`lte_lc_env_eval_cancel`
167167

168+
PDN (Packet Data Network):
169+
Use the :kconfig:option:`CONFIG_LTE_LC_PDN_MODULE` Kconfig option to enable all the following functionalities related to PDP context and PDN connection management:
170+
171+
* :c:enumerator:`LTE_LC_EVT_PDN_ACTIVATED` events
172+
* :c:enumerator:`LTE_LC_EVT_PDN_DEACTIVATED` events
173+
* :c:enumerator:`LTE_LC_EVT_PDN_IPV6_UP` events
174+
* :c:enumerator:`LTE_LC_EVT_PDN_IPV6_DOWN` events
175+
* :c:enumerator:`LTE_LC_EVT_PDN_NETWORK_DETACH` events
176+
* :c:enumerator:`LTE_LC_EVT_PDN_APN_RATE_CONTROL_ON` events
177+
* :c:enumerator:`LTE_LC_EVT_PDN_APN_RATE_CONTROL_OFF` events
178+
* :c:enumerator:`LTE_LC_EVT_PDN_CTX_DESTROYED` events
179+
* :c:enumerator:`LTE_LC_EVT_PDN_ESM_ERROR` events
180+
* :c:func:`lte_lc_pdn_ctx_create`
181+
* :c:func:`lte_lc_pdn_ctx_configure`
182+
* :c:func:`lte_lc_pdn_ctx_auth_set`
183+
* :c:func:`lte_lc_pdn_activate`
184+
* :c:func:`lte_lc_pdn_deactivate`
185+
* :c:func:`lte_lc_pdn_ctx_destroy`
186+
* :c:func:`lte_lc_pdn_id_get`
187+
* :c:func:`lte_lc_pdn_dynamic_info_get`
188+
* :c:func:`lte_lc_pdn_ctx_default_apn_get`
189+
* :c:func:`lte_lc_pdn_esm_strerror`
190+
* :kconfig:option:`CONFIG_LTE_LC_PDN_DEFAULTS_OVERRIDE`
191+
168192
For more information on the callback events received in :c:type:`lte_lc_evt_handler_t` and data associated with each event, see the documentation on :c:struct:`lte_lc_evt`.
169193
For more information on the functions and data associated with each, refer to the API documentation.
170194

@@ -275,6 +299,201 @@ The :c:func:`lte_lc_env_eval` function starts the environment evaluation for the
275299
When the environment evaluation is complete, an :c:enumerator:`LTE_LC_EVT_ENV_EVAL_RESULT` event with the evaluation results is received.
276300
For each found PLMN, the :c:struct:`lte_lc_conn_eval_params` structure is populated with the evaluation results.
277301

302+
.. _lte_lc_pdn:
303+
304+
PDN management
305+
==============
306+
307+
The LTE link control library provides functionality to manage Packet Data Protocol (PDP) contexts and Packet Data Network (PDN) connections.
308+
309+
The PDN functionality provides the following capabilities:
310+
311+
* Creating and configuring PDP contexts
312+
* Receiving events pertaining to PDN connections
313+
* Managing PDN connections
314+
* Retrieving PDN connection information
315+
316+
To enable PDN functionality, set the :kconfig:option:`CONFIG_LTE_LC_PDN_MODULE` Kconfig option to ``y``.
317+
318+
AT commands used
319+
----------------
320+
321+
The PDN functionality uses several AT commands, and it relies on the following two types of AT notifications to work:
322+
323+
* Packet domain events notifications (``+CGEV``) - Subscribed by using the ``AT+CGEREP=1`` command.
324+
See the `AT+CGEREP set command`_ section in the nRF9160 AT Commands Reference Guide or the `nRF91x1 AT+CGEREP set command`_ section in the nRF91x1 AT Commands Reference Guide, depending on the SiP you are using.
325+
* Notifications for unsolicited reporting of error codes sent by the network (``+CNEC``) - Subscribed by using the ``AT+CNEC=16`` command.
326+
See the `AT+CNEC set command`_ section in the nRF9160 AT Commands Reference Guide or the `nRF91x1 AT+CNEC set command`_ section in the nRF91x1 AT Commands Reference Guide, depending on the SiP you are using.
327+
328+
The LTE link control library automatically subscribes to the necessary AT notifications.
329+
This includes automatically resubscribing to the notifications upon functional mode changes.
330+
331+
.. note::
332+
The subscription to AT notifications is lost upon changing the functional mode of the modem to ``+CFUN=0``.
333+
If the application subscribes to these notifications manually, it must also take care of resubscription.
334+
335+
Following are the AT commands that are used by the PDN functionality:
336+
337+
* ``AT%XNEWCID`` - To create a PDP context
338+
* ``AT+CGDCONT`` - To configure or destroy a PDP context
339+
* ``AT+CGACT`` - To activate or deactivate a PDN connection
340+
* ``AT%XGETPDNID`` - To retrieve the PDN ID for a given PDP context
341+
* ``AT+CGAUTH`` - To set the PDN connection authentication parameters
342+
343+
For more information about these commands, see `Packet Domain AT commands`_ in the nRF9160 AT Commands Reference Guide or the `nRF91x1 packet Domain AT commands`_ section in the nRF91x1 AT Commands Reference Guide, depending on the SiP you are using.
344+
345+
Creating and managing PDN connections
346+
--------------------------------------
347+
348+
The application can create PDP contexts by using the :c:func:`lte_lc_pdn_ctx_create` function.
349+
PDN events are sent to all registered LTE link control event handlers.
350+
The application can use the :c:func:`lte_lc_register_handler` function to register an event handler for events pertaining to all PDP contexts, including the default PDP context.
351+
352+
A PDN connection is identified by an ID as reported by ``AT%XGETPDNID``, and it is distinct from the PDP context ID (CID).
353+
The modem creates a PDN connection for a PDP context as necessary.
354+
Multiple PDP contexts might share the same PDN connection if they are configured similarly.
355+
356+
The application can use the following functions to manage PDP contexts and PDN connections:
357+
358+
* :c:func:`lte_lc_pdn_ctx_create` - Creates a PDP context.
359+
* :c:func:`lte_lc_register_handler` - Registers an event handler for events pertaining to all PDP contexts, including the default PDP context.
360+
* :c:func:`lte_lc_pdn_ctx_configure` - Configures a PDP context with address family, access point name, and optional additional configuration options.
361+
* :c:func:`lte_lc_pdn_ctx_auth_set` - Sets authentication parameters for a PDP context.
362+
* :c:func:`lte_lc_pdn_activate` - Activates a PDN connection for a PDP context.
363+
* :c:func:`lte_lc_pdn_deactivate` - Deactivates a PDN connection.
364+
* :c:func:`lte_lc_pdn_ctx_destroy` - Destroys a PDP context.
365+
The PDN connection must be inactive when the PDP context is destroyed.
366+
* :c:func:`lte_lc_pdn_id_get` - Retrieves the PDN ID for a given PDP context.
367+
The PDN ID can be used to route traffic through a specific PDN connection.
368+
* :c:func:`lte_lc_pdn_dynamic_info_get` - Retrieves dynamic parameters such as DNS addresses and MTU sizes for a given PDN connection.
369+
* :c:func:`lte_lc_pdn_ctx_default_apn_get` - Retrieves the default Access Point Name (APN) of the default PDP context (CID 0).
370+
371+
PDN events
372+
----------
373+
374+
The following PDN events are sent to registered LTE link control event handlers:
375+
376+
* :c:enumerator:`LTE_LC_EVT_PDN_ACTIVATED` - PDN connection activated
377+
* :c:enumerator:`LTE_LC_EVT_PDN_DEACTIVATED` - PDN connection deactivated
378+
* :c:enumerator:`LTE_LC_EVT_PDN_IPV6_UP` - PDN has IPv6 connectivity
379+
* :c:enumerator:`LTE_LC_EVT_PDN_IPV6_DOWN` - PDN has lost IPv6 connectivity
380+
* :c:enumerator:`LTE_LC_EVT_PDN_NETWORK_DETACH` - PDN connection lost due to network detach
381+
* :c:enumerator:`LTE_LC_EVT_PDN_APN_RATE_CONTROL_ON` - APN rate control is active
382+
* :c:enumerator:`LTE_LC_EVT_PDN_APN_RATE_CONTROL_OFF` - APN rate control is inactive
383+
* :c:enumerator:`LTE_LC_EVT_PDN_CTX_DESTROYED` - PDP context destroyed
384+
* :c:enumerator:`LTE_LC_EVT_PDN_ESM_ERROR` - ESM error occurred
385+
386+
The associated payload for PDN events is the :c:member:`lte_lc_evt.pdn` member of type :c:struct:`lte_lc_pdn_evt`.
387+
This structure contains the PDP context ID (CID) and, for :c:enumerator:`LTE_LC_EVT_PDN_ESM_ERROR` events, the ESM error code.
388+
389+
PDN configuration
390+
-----------------
391+
392+
The LTE link control library can override the default PDP context configuration automatically after the :ref:`nrfxlib:nrf_modem` is initialized, if the :kconfig:option:`CONFIG_LTE_LC_PDN_DEFAULTS_OVERRIDE` Kconfig option is set.
393+
The default PDP context configuration consists of the following parameters, each controlled with a Kconfig setting:
394+
395+
* Access point name - :kconfig:option:`CONFIG_LTE_LC_PDN_DEFAULT_APN`
396+
* Address family - :kconfig:option:`CONFIG_LTE_LC_PDN_DEFAULT_FAM_IPV4`, :kconfig:option:`CONFIG_LTE_LC_PDN_DEFAULT_FAM_IPV6`, :kconfig:option:`CONFIG_LTE_LC_PDN_DEFAULT_FAM_IPV4V6`, or :kconfig:option:`CONFIG_LTE_LC_PDN_DEFAULT_FAM_NONIP`
397+
* Authentication method - :kconfig:option:`CONFIG_LTE_LC_PDN_DEFAULT_AUTH_NONE`, :kconfig:option:`CONFIG_LTE_LC_PDN_DEFAULT_AUTH_PAP`, or :kconfig:option:`CONFIG_LTE_LC_PDN_DEFAULT_AUTH_CHAP`
398+
* Authentication credentials - :kconfig:option:`CONFIG_LTE_LC_PDN_DEFAULT_USERNAME` and :kconfig:option:`CONFIG_LTE_LC_PDN_DEFAULT_PASSWORD`
399+
400+
.. note::
401+
The default PDP context configuration must be overridden before the device is registered with the network.
402+
403+
Additional configuration options:
404+
405+
* :kconfig:option:`CONFIG_LTE_LC_PDN_LEGACY_PCO` - Use legacy PCO mode instead of ePCO during PDN connection establishment
406+
* :kconfig:option:`CONFIG_LTE_LC_PDN_ESM_TIMEOUT` - Timeout for waiting for an ESM notification when activating a PDN
407+
* :kconfig:option:`CONFIG_LTE_LC_PDN_ESM_STRERROR` - Compile a table with textual descriptions of ESM error reasons
408+
409+
PDN usage example
410+
-----------------
411+
412+
The following code snippet demonstrates how to use the PDN functionality:
413+
414+
.. code-block:: c
415+
416+
#include <zephyr/kernel.h>
417+
#include <modem/lte_lc.h>
418+
419+
static void lte_handler(const struct lte_lc_evt *const evt)
420+
{
421+
switch (evt->type) {
422+
case LTE_LC_EVT_PDN_ACTIVATED:
423+
printk("PDN context %d activated\n", evt->pdn.cid);
424+
break;
425+
case LTE_LC_EVT_PDN_DEACTIVATED:
426+
printk("PDN context %d deactivated\n", evt->pdn.cid);
427+
break;
428+
case LTE_LC_EVT_PDN_ESM_ERROR:
429+
printk("PDN context %d ESM error: %d\n",
430+
evt->pdn.cid, evt->pdn.esm_err);
431+
break;
432+
default:
433+
break;
434+
}
435+
}
436+
437+
int main(void)
438+
{
439+
int err;
440+
uint8_t cid;
441+
int esm;
442+
char apn[32];
443+
int pdn_id;
444+
445+
err = lte_lc_register_handler(lte_handler);
446+
if (err) {
447+
LOG_ERR("Registration failed, error: %d", err);
448+
449+
return err;
450+
}
451+
452+
err = lte_lc_connect();
453+
if (err) {
454+
return err;
455+
}
456+
457+
/* Get default APN */
458+
err = lte_lc_pdn_ctx_default_apn_get(apn, sizeof(apn));
459+
if (err) {
460+
return err;
461+
}
462+
463+
/* Create a new PDP context */
464+
err = lte_lc_pdn_ctx_create(&cid);
465+
if (err) {
466+
return err;
467+
}
468+
469+
/* Configure the PDP context */
470+
err = lte_lc_pdn_ctx_configure(cid, apn, LTE_LC_PDN_FAM_IPV4V6, NULL);
471+
if (err) {
472+
return err;
473+
}
474+
475+
/* Activate the PDN connection */
476+
err = lte_lc_pdn_activate(cid, &esm, NULL);
477+
if (err) {
478+
LOG_ERR("Activation failed, ESM error: %d", esm);
479+
480+
return err;
481+
}
482+
483+
/* Get PDN ID */
484+
pdn_id = lte_lc_pdn_id_get(cid);
485+
if (pdn_id < 0) {
486+
return pdn_id;
487+
}
488+
489+
LOG_INF("PDN connection activated with PDN ID: %d", pdn_id);
490+
491+
/* Continue execution... */
492+
}
493+
494+
.. note::
495+
You have to register the event handler for LTE events before the device is registered to the network (``CFUN=1``) to receive the first activation event.
496+
278497
Limitations
279498
***********
280499

doc/nrf/nrf.doxyfile.in

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2465,7 +2465,9 @@ PREDEFINED = __DOXYGEN__ \
24652465
"CONFIG_LTE_LC_RAI_MODULE=y" \
24662466
"CONFIG_LTE_LC_MODEM_SLEEP_MODULE=y" \
24672467
"CONFIG_LTE_LC_TAU_PRE_WARNING_MODULE=y" \
2468-
"CONFIG_LTE_LC_ENV_EVAL_MODULE=y"
2468+
"CONFIG_LTE_LC_ENV_EVAL_MODULE=y" \
2469+
"CONFIG_LTE_LC_PDN_MODULE=y"
2470+
24692471

24702472
# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this
24712473
# tag can be used to specify a list of macro names that should be expanded. The

doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,8 @@ Modem libraries
907907
* Description of new features supported by mfw_nrf91x1 and mfw_nrf9151-ntn in receive only functional mode.
908908
* Sending of the ``LTE_LC_EVT_PSM_UPDATE`` event with ``tau`` and ``active_time`` set to ``-1`` when registration status is ``LTE_LC_NW_REG_NOT_REGISTERED``.
909909
* New registration statuses and functional modes for the ``mfw_nrf9151-ntn`` modem firmware.
910+
* Support for PDP context and PDN connection management.
911+
The functionality is available when the :kconfig:option:`CONFIG_LTE_LC_PDN_MODULE` Kconfig option is enabled.
910912

911913
* Updated:
912914

0 commit comments

Comments
 (0)