Failed to activate PDN for CID

I'm having trouble activating a PDN on a running/connected device. Here's the code:

int set_apn(char *apn)
{
    int err = 0;
    int esm = 0;
    char current[128];

    /* Get the current default */
    err = pdn_default_apn_get(current, sizeof(current));
    if (err)
    {
        LOG_ERR("pdn_default_apn_get error: %i", err);
        return err;
    }

    /* Don't do anything if APN is the same */
    if (strcmp(current, apn) == 0)
    {
        LOG_INF("No update neded. APN matches: %s", log_strdup(apn));
        return 0;
    }

    /* Create a PDP context and assign an event handler to receive events */
    err = pdn_ctx_create(&cid, pdn_event_handler);
    if (err)
    {
        LOG_ERR("pdn_ctx_create() failed, err %i", err);
        pdn_ctx_destroy(cid);
        return err;
    }

    LOG_INF("Created new PDP context %d", cid);

    /* Configure a PDP context with APN and Family */
    err = pdn_ctx_configure(cid, apn, PDN_FAM_IPV4V6, NULL);
    if (err)
    {
        LOG_ERR("pdn_ctx_configure() failed, err %i", err);
        pdn_ctx_destroy(cid);
        return err;
    }

    LOG_INF("PDP context %i configured: APN %s", cid, log_strdup(apn));

    /* Activate a PDN connection */
    err = pdn_activate(cid, &esm, NULL);
    if (err < 0)
    {
        LOG_ERR("pdn_activate() failed, err %i esm %i",
                err, esm);
        pdn_ctx_destroy(cid);
        return err;
    }

    return 0;
}

Seems like I'm missing something here. pdn_init does get called on system setup. (using CONFIG_PDN_SYS_INIT=y)

[00:00:25.517,486] <inf> main: Evt: APP_EVENT_APN_UPDATE
[00:00:25.517,517] <inf> main: ------------------- POST status 43
[00:00:25.517,547] <inf> main: Set apn to: Att (len: 3)
[00:00:25.531,402] <inf> main: Created new PDP context 1
[00:00:25.531,890] <inf> main: PDP context 1 configured: APN Att
[00:00:25.772,003] <wrn> pdn: Failed to activate PDN for CID 1, err 65536
[00:00:26.772,125] <err> main: pdn_activate() failed, err -8 esm 0 <unknown>

  • Hi,

     

    What is the order of initialization here?

    If you are initializing the modem library in the application, you'd need to call pdn_init() after modem init, with CONFIG_PDN_SYS_INIT=n, but before AT+CFUN=1 is set (ie. lte_lc_connect() is called)

     

    Kind regards,

    Håkon

  •  CONFIG_PDN_SYS_INIT was set to 'y' by default. I've changed the order of operations to see if that makes a difference. No go.

    Does the modem need to be in a disconnected state when creating and applying a new PDN context?

    Here is a log below where the device inits the modem library, then PDN, connects and then later on sets the PDN as set by the user.

    [00:01:30.965,972] <inf> main: Set apn to: Att (len: 3)
    [00:01:30.973,846] <inf> main: Created new PDP context 1
    [00:01:30.974,334] <inf> main: PDP context 1 configured: APN Att
    [00:01:31.005,157] <inf> main: LTE_LC_EVT_MODEM_SLEEP_EXIT 1
    [00:01:31.433,197] <wrn> pdn: Failed to activate PDN for CID 1, err 65536
    [00:01:32.433,319] <err> main: pdn_activate() failed, err -8 esm 0

  • I also tried putting the modem in offline mode using lte_lc_offline before applying the PDN. Same result. The device does obtain a default beforehand. Is that the problem? I'm using MFW 1.3.1 by the way.

  • Hi,

     

    Jared said:
    The device does obtain a default beforehand. Is that the problem?

    What is the output if you run AT+CGDCONT? at your end? If you run the "pdn" sample, are you able to successfully set the pdn then?

     

    Jared said:
    CONFIG_PDN_SYS_INIT was set to 'y' by default.

    This means that NRF_MODEM_LIB is sys-init'ed prior to entering main, correct?

    Can you try to set this to 'n' and run pdn_init() in your application?

     

    Kind regards,

    Håkon

  • Hi  

    This means that NRF_MODEM_LIB is sys-init'ed prior to entering main, correct?

    Can you try to set this to 'n' and run pdn_init() in your application?

    I tried this exact thing with the same result.

    As far as I can tell, CONFIG_PDN_SYS_INIT is getting selected because 

    CONFIG_NRF_MODEM_LIB_SYS_INIT is also selected/enabled.

    Here's the response after my attempt of running AT+CGDCONT?

    [00:00:37.759,399] <inf> main: Set apn to: Att (len: 3)
    [00:00:37.761,291] <inf> main: Created new PDP context 1
    [00:00:37.761,779] <inf> main: PDP context 1 configured: APN Att
    [00:00:39.250,213] <wrn> pdn: Failed to activate PDN for CID 1, err 65536
    [00:00:40.250,335] <err> main: pdn_activate() failed, err -8 esm 0
    [00:00:40.251,373] <inf> main: +CGDCONT: 0,"IP","hologram","10.95.240.159",0,0
    OK

    We are using NCS 1.9.1 with MFW 1.3.1. Are there any caveats we need to be aware of?

    If you run the "pdn" sample, are you able to successfully set the pdn then?

    Here is the sample. This just re-programs the same APN and works.

    [00:00:00.214,965] <inf> main: PDN sample started
    [00:00:02.750,976] <inf> main: Event: PDP context 0 activated
    [00:00:02.753,570] <inf> main: Default APN is hologram
    [00:00:02.753,967] <inf> main: Created new PDP context 1
    [00:00:02.754,486] <inf> main: PDP context 1 configured: APN hologram, Family IPV4V6
    [00:00:02.755,218] <inf> main: Event: PDP context 1 activated
    [00:00:03.764,312] <inf> main: PDP Context 0, PDN ID 0
    [00:00:03.764,801] <inf> main: PDP Context 1, PDN ID 0
    [00:00:03.859,497] <inf> main: Event: PDP context 0 deactivated
    [00:00:03.860,046] <inf> main: Event: PDP context 1 deactivated
    [00:00:05.382,812] <inf> main: Bye

    This is what happens when a different one is attempted:

    [00:00:00.215,026] <inf> main: PDN sample started
    [00:00:02.356,994] <inf> main: Event: PDP context 0 activated
    [00:00:02.359,130] <inf> main: Default APN is hologram
    [00:00:02.359,527] <inf> main: Created new PDP context 1
    [00:00:02.360,046] <inf> main: PDP context 1 configured: APN hologram, Family IPV4V6
    [00:00:02.524,841] <inf> main: Event: PDP context 1, Requested service option not subscribed
    [00:00:02.524,902] <wrn> pdn: Failed to activate PDN for CID 1, err 65536
    [00:00:02.524,932] <inf> main: pdn_activate() failed, err -8 esm 33 Requested service option not subscribed

Related