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>