Skip to content

Commit db38991

Browse files
eivindj-nordicjorgenmk
authored andcommitted
lib: pdn: use heap for AT response buffer and make size configurable
Add CONFIG_PDN_DYNAMIC_INFO_AT_BUF_SIZE to make the AT response buffer size for AT+CGCONTRDP configurable, as it depends on the APN. Use k_malloc for AT buffer to avoid increasing system workqueue stack size requirement. Signed-off-by: Eivind Jølsgard <[email protected]>
1 parent 436fd2f commit db38991

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,7 @@ Modem libraries
531531

532532
* :ref:`pdn_readme` library:
533533

534+
* Added the :kconfig:option:`CONFIG_PDN_DYNAMIC_INFO_AT_BUF_SIZE ` Kconfig option to set the response buffer size for the ``AT+CGCONTRDP`` AT command.
534535
* Deprecated the :c:func:`pdn_dynamic_params_get` function.
535536
Use the new function :c:func:`pdn_dynamic_info_get` instead.
536537

lib/pdn/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ config PDN_INIT_PRIORITY
2727
int "Initialization priority"
2828
default APPLICATION_INIT_PRIORITY
2929

30+
config PDN_DYNAMIC_INFO_AT_BUF_SIZE
31+
int "Dynamic info AT buffer size"
32+
default 512
33+
help
34+
Buffer size for storing the response of the AT+CGCONTRDP AT command used in the
35+
pdn_dynamic_info_get() function.
36+
3037
config PDN_DEFAULTS_OVERRIDE
3138
bool "Override defaults for PDP context 0"
3239
help

lib/pdn/pdn.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ int pdn_dynamic_info_get(uint32_t cid, struct pdn_dynamic_info *pdn_info)
688688
struct at_parser parser;
689689
size_t param_str_len;
690690

691-
char cgcontrdp_at_rsp_buf[512];
691+
char *cgcontrdp_at_rsp_buf;
692692

693693
char *at_ptr;
694694
char *tmp_ptr;
@@ -706,18 +706,24 @@ int pdn_dynamic_info_get(uint32_t cid, struct pdn_dynamic_info *pdn_info)
706706
return -EINVAL;
707707
}
708708

709+
cgcontrdp_at_rsp_buf = k_malloc(CONFIG_PDN_DYNAMIC_INFO_AT_BUF_SIZE);
710+
if (!cgcontrdp_at_rsp_buf) {
711+
LOG_ERR("k_malloc failed for CGDCONTRDP response buffer");
712+
return -ENOMEM;
713+
}
714+
709715
at_ptr = cgcontrdp_at_rsp_buf;
710716
tmp_ptr = cgcontrdp_at_rsp_buf;
711717

712718
sprintf(at_cmd_pdn_context_read_info_cmd_str, AT_CMD_PDN_CONTEXT_READ_INFO, cid);
713-
ret = nrf_modem_at_cmd(cgcontrdp_at_rsp_buf, sizeof(cgcontrdp_at_rsp_buf), "%s",
719+
ret = nrf_modem_at_cmd(cgcontrdp_at_rsp_buf, CONFIG_PDN_DYNAMIC_INFO_AT_BUF_SIZE, "%s",
714720
at_cmd_pdn_context_read_info_cmd_str);
715721
if (ret) {
716722
LOG_ERR(
717723
"nrf_modem_at_cmd returned err: %d for %s",
718724
ret,
719725
at_cmd_pdn_context_read_info_cmd_str);
720-
return ret;
726+
goto clean_exit;
721727
}
722728

723729
/* Check how many rows of info do we have */
@@ -732,7 +738,7 @@ int pdn_dynamic_info_get(uint32_t cid, struct pdn_dynamic_info *pdn_info)
732738
if (ret) {
733739
LOG_ERR("Could not init AT parser for %s, error: %d\n",
734740
at_cmd_pdn_context_read_info_cmd_str, ret);
735-
return ret;
741+
goto clean_exit;
736742
}
737743

738744
parse:
@@ -813,6 +819,7 @@ int pdn_dynamic_info_get(uint32_t cid, struct pdn_dynamic_info *pdn_info)
813819
}
814820

815821
clean_exit:
822+
k_free(cgcontrdp_at_rsp_buf);
816823
return ret;
817824
}
818825

tests/lib/pdn/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ add_compile_definitions(CONFIG_PDN_ESM_TIMEOUT=1000)
2828
add_compile_definitions(CONFIG_PDN_DEFAULTS_OVERRIDE)
2929
add_compile_definitions(CONFIG_PDN_DEFAULT_APN="apn0")
3030
add_compile_definitions(CONFIG_PDN_DEFAULT_FAM=2)
31+
add_compile_definitions(CONFIG_PDN_DYNAMIC_INFO_AT_BUF_SIZE=512)

0 commit comments

Comments
 (0)