Cellular: PDN

The PDN sample demonstrates how to create and configure a Packet Data Protocol (PDP) context, activate a Packet Data Network connection, and receive events on its state and connectivity using the PDN functionality in the LTE link control library.

Requirements

The sample supports the following development kits:

Hardware platforms

PCA

Board name

Board target

nRF9161 DK

PCA10153

nrf9161dk

nrf9161dk/nrf9161/ns

nRF9160 DK

PCA10090

nrf9160dk

nrf9160dk/nrf9160/ns

nRF9151 DK

PCA10171

nrf9151dk

nrf9151dk/nrf9151/ns

For more security, it is recommended to use the */ns variant of the board target. When built for this variant, the sample is configured to compile and run as a non-secure application using security by separation. Therefore, it automatically includes Trusted Firmware-M that prepares the required peripherals and secure services to be available for the application.

Overview

The sample first initializes the Modem library. Next, the sample registers a callback for PDN events using the LTE link control library, including events pertaining to the default PDP context. This is done before changing the function mode to 1 (AT+CFUN=1) to receive the activation event for the default PDP context. The sample then creates a new PDP context and configures it to use the default APN, and activates the PDN connection. Finally, the sample prints the PDP context IDs and PDN IDs of both the default PDP context and the new PDP context that it has created.

Note

The sample uses the LTE link control library to change the modem’s functional mode. Hence, the LTE link control library can automatically register to the necessary packet domain events notifications using the AT+CGEREP=1 AT command, and notifications for unsolicited reporting of error codes sent by the network using the AT+CNEC=16 AT command. See the AT+CGEREP set command and the AT+CNEC set command sections, respectively, in the nRF9160 AT Commands Reference Guide or the nRF91x1 AT+CGEREP set command and the nRF91x1 AT+CNEC set command sections in the nRF91x1 AT Commands Reference Guide, depending on the SiP you are using. If your application does not use the LTE link control library to change the modem’s functional mode, you have to subscribe to these notifications manually before the functional mode is changed.

Sending traces over UART on an nRF91 Series DK

To send modem traces over UART on an nRF91 Series DK, configuration must be added for the UART device in the devicetree and Kconfig. This is done by adding the modem trace UART snippet when building and programming.

Use the Cellular Monitor app for capturing and analyzing modem traces.

TF-M logging must use the same UART as the application. For more details, see shared TF-M logging.

Building and running

This sample can be found under samples/cellular/pdn in the nRF Connect SDK folder structure.

For more security, it is recommended to use the */ns variant of the board target (see the Requirements section above.) When built for this variant, the sample is configured to compile and run as a non-secure application using security by separation. Therefore, it automatically includes Trusted Firmware-M that prepares the required peripherals and secure services to be available for the application.

To build the sample, follow the instructions in Building an application for your preferred building environment. See also Programming an application for programming steps and Testing and optimization for general information about testing and debugging in the nRF Connect SDK.

Note

When building repository applications in the SDK repositories, building with sysbuild is enabled by default. If you work with out-of-tree freestanding applications, you need to manually pass the --sysbuild parameter to every build command or configure west to always use it.

Testing

After programming the sample to your development kit, complete the following steps to test it:

  1. Connect the kit to the computer using a USB cable. The kit is assigned a serial port. Serial ports are referred to as COM ports on Windows, /dev/ttyACM devices on Linux, and /dev/tty devices on macOS. To list Nordic Semiconductor devices connected to your computer together with their serial ports, open a terminal and run the nrfutil device list command. Alternatively, check your operating system’s device manager or its equivalent.

  2. Connect to the kit with a terminal emulator (for example, the Serial Terminal app). See Testing and optimization for the required settings and steps.

  3. Power on or reset your nRF91 Series DK.

  4. Observe that the sample starts, creates and configures a PDP context, and then activates a PDN connection.

Sample output

The sample shows the following output, which may vary based on the network provider:

*** Booting nRF Connect SDK v2.9.99-0f7da9c375d1 ***
*** Using Zephyr OS v3.7.99-2d1e173dfed0 ***
PDN sample started
Event: PDP context 0 activated
Default APN is telenor.smart
Created new PDP context 1
PDP context 1 configured: APN telenor.smart, Family IPV4V6
Event: PDP context 1 activated
Event: PDP context 0 IPv6 up
Event: PDP context 1 IPv6 up
PDP Context 0, PDN ID 0
PDP Context 1, PDN ID 0
Dynamic info for cid 0:
Primary IPv4 DNS address: 111.222.233.4
Secondary IPv4 DNS address: 111.222.233.4
Primary IPv6 DNS address: 1111:2222:3:fff::55
Secondary IPv6 DNS address: 1111:2222:3:fff::55
IPv4 MTU: 1500, IPv6 MTU: 1500
Dynamic info for cid 1:
Primary IPv4 DNS address: 111.222.233.4
Secondary IPv4 DNS address: 111.222.233.4
Primary IPv6 DNS address: 1111:2222:3:fff::55
Secondary IPv6 DNS address: 1111:2222:3:fff::55
IPv4 MTU: 1500, IPv6 MTU: 1500

Interface addresses:
l0: (AF_INET) 10.22.233.44
l0: (AF_INET6) aaaa::bbbb:cccc
l0: (AF_INET6) aaa:bbbbb:cccc:dddd::eeee:2cd2

Event: PDP context 0 network detach
Event: PDP context 1 network detach
Event: PDP context 1 context destroyed
Bye

Dependencies

This sample uses the following nRF Connect SDK libraries:

It uses the following sdk-nrfxlib library:

In addition, it uses the following secure firmware component: