Skip to content

Commit 7b979c4

Browse files
TaeZStkyohtjukkar
authored andcommitted
slm: fix IPv6 only case
If ISP sends only IPv6 DNS records, pdn_dynamic_params_get was failing. pdn_dynamic_params_get_v6 was implemented and used as a fallback on the SLM's ppp. DevZone Nordic Case ID: 336147 Signed-off-by: Oguzhan Turk <[email protected]>
1 parent b7a903a commit 7b979c4

File tree

4 files changed

+70
-2
lines changed

4 files changed

+70
-2
lines changed

applications/serial_lte_modem/src/slm_ppp.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,11 @@ static int ppp_start_internal(void)
213213
ret = pdn_dynamic_params_get(PDP_CID, &ctx->ipcp.my_options.dns1_address,
214214
&ctx->ipcp.my_options.dns2_address, &mtu);
215215
if (ret) {
216-
return ret;
216+
/* If any error happened on pdn getting with IPv4, try to parse with IPv6 */
217+
ret = pdn_dynamic_params_get_v6(PDP_CID, NULL, NULL, &mtu);
218+
if (ret) {
219+
return ret;
220+
}
217221
}
218222

219223
if (mtu) {

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,9 @@ Security libraries
451451
Modem libraries
452452
---------------
453453

454-
|no_changes_yet_note|
454+
* :ref:`pdn_readme` library:
455+
456+
* Added the :c:func:`pdn_dynamic_params_get_v6` function to get PDN parameters for IPv6-only.
455457

456458
Multiprotocol Service Layer libraries
457459
-------------------------------------

include/modem/pdn.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,19 @@ int pdn_id_get(uint8_t cid);
193193
int pdn_dynamic_params_get(uint8_t cid, struct in_addr *dns4_pri,
194194
struct in_addr *dns4_sec, unsigned int *ipv4_mtu);
195195

196+
/**
197+
* @brief Retrieve dynamic parameters of a given PDP context.
198+
*
199+
* @param cid The PDP context ID.
200+
* @param[out] dns6_pri The address of the primary IPv6 DNS server. Optional, can be NULL.
201+
* @param[out] dns6_sec The address of the secondary IPv6 DNS server. Optional, can be NULL.
202+
* @param[out] ipv6_mtu The IPv6 MTU. Optional, can be NULL.
203+
*
204+
* @return Zero on success or an error code on failure.
205+
*/
206+
int pdn_dynamic_params_get_v6(uint8_t cid, struct in6_addr *dns6_pri,
207+
struct in6_addr *dns6_sec, unsigned int *ipv6_mtu);
208+
196209
/**
197210
* @brief Retrieve the default Access Point Name (APN).
198211
*

lib/pdn/pdn.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,55 @@ int pdn_dynamic_params_get(uint8_t cid, struct in_addr *dns4_pri,
659659
return 0;
660660
}
661661

662+
int pdn_dynamic_params_get_v6(uint8_t cid, struct in6_addr *dns6_pri,
663+
struct in6_addr *dns6_sec, unsigned int *ipv6_mtu)
664+
{
665+
int matched;
666+
const char *fmt;
667+
unsigned int mtu;
668+
char dns6_pri_str[INET6_ADDRSTRLEN];
669+
char dns6_sec_str[INET6_ADDRSTRLEN];
670+
char at_cmd[sizeof("AT+CGCONTRDP=10")];
671+
672+
if (snprintf(at_cmd, sizeof(at_cmd), "AT+CGCONTRDP=%u", cid) >= sizeof(at_cmd)) {
673+
return -E2BIG;
674+
}
675+
/* "+CGCONTRDP: 0,,"ims","","",
676+
* "0000:0000:0000:0000:0000:0000:0000:0000",
677+
* "0000:0000:0000:0000:0000:0000:0000:0000",,,,,1500"
678+
*/
679+
fmt = "+CGCONTRDP: %*u,,\"%*[^\"]\",\"\",\"\","
680+
"\"%45[0-9A-Fa-f:]\",\"%45[0-9A-Fa-f:]\",,,,,%u";
681+
682+
/* If IPv6 is enabled, it will be the first response line. */
683+
matched = nrf_modem_at_scanf(at_cmd, fmt, &dns6_pri_str, &dns6_sec_str, &mtu);
684+
/* Need to match at least the two IP addresses, or there is an error */
685+
if (matched < 2) {
686+
return -EBADMSG;
687+
}
688+
689+
if (dns6_pri) {
690+
if (zsock_inet_pton(AF_INET6, dns6_pri_str, dns6_pri) != 1) {
691+
return -EADDRNOTAVAIL;
692+
}
693+
}
694+
if (dns6_sec) {
695+
if (zsock_inet_pton(AF_INET6, dns6_sec_str, dns6_sec) != 1) {
696+
return -EADDRNOTAVAIL;
697+
}
698+
}
699+
if (ipv6_mtu) {
700+
/* If we matched the MTU, copy it here, otherwise report zero */
701+
if (matched == 3) {
702+
*ipv6_mtu = mtu;
703+
} else {
704+
*ipv6_mtu = 0;
705+
}
706+
}
707+
708+
return 0;
709+
}
710+
662711
int pdn_default_apn_get(char *buf, size_t len)
663712
{
664713
int err;

0 commit comments

Comments
 (0)