From 6e0e90ef17462312cc79278c5d5e88ab177b50f4 Mon Sep 17 00:00:00 2001 From: Pete Skeggs Date: Wed, 18 Sep 2024 15:54:28 -0700 Subject: [PATCH] lib: at_shell: Add optional multiline support Added CONFIG_AT_SHELL_UNESCAPE_LF to enable reception of multiline AT commands. Updated the at_shell() function to replace the 2 character sequence "\n" with if CONFIG_AT_SHELL_UNESCAPE_LF is enabled. Jira: IRIS-6919 Signed-off-by: Pete Skeggs --- .../releases/release-notes-changelog.rst | 5 +++++ lib/at_shell/Kconfig | 8 ++++++++ lib/at_shell/at_shell.c | 18 ++++++++++++++++++ subsys/net/lib/nrf_cloud/Kconfig | 1 + 4 files changed, 32 insertions(+) diff --git a/doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst b/doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst index 6f12d931f9bf..df2954755c70 100644 --- a/doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst +++ b/doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst @@ -739,6 +739,11 @@ Modem libraries * To use the ``AT+CMMS`` AT command when sending concatenated SMS message. * To set "7" as a fallback SMS service center address for type approval SIM cards which do not have it set. +* :ref:`lib_at_shell` library: + + * Added the :kconfig:option:`CONFIG_AT_SHELL_UNESCAPE_LF` Kconfig option to enable reception of multiline AT commands. + * Updated the :c:func:`at_shell` function to replace ``\n`` with ```` if :kconfig:option:`CONFIG_AT_SHELL_UNESCAPE_LF` is enabled. + Multiprotocol Service Layer libraries ------------------------------------- diff --git a/lib/at_shell/Kconfig b/lib/at_shell/Kconfig index 5eaac34785af..2fdd4b673930 100644 --- a/lib/at_shell/Kconfig +++ b/lib/at_shell/Kconfig @@ -20,4 +20,12 @@ config AT_SHELL_CMD_RESPONSE_MAX_LEN int "Maximum AT command response length" default 2700 +config AT_SHELL_UNESCAPE_LF + bool "Unescape linefeed" + help + Replaces \n with . This enables commands such as AT%CMNG=0 to + properly receive certificates that ordinarily have multiple lines. + The certificate must have been preprocessed to replace EOL sequences + with a literal \ character followed by an n character. + endif # AT_SHELL diff --git a/lib/at_shell/at_shell.c b/lib/at_shell/at_shell.c index 5bbee78e5bd9..1806632f892a 100644 --- a/lib/at_shell/at_shell.c +++ b/lib/at_shell/at_shell.c @@ -10,6 +10,8 @@ #include #include +#define CREDENTIALS_CMD "AT%CMNG=0" + static struct shell *global_shell; static const char at_usage_str[] = "Usage: at \n" @@ -54,6 +56,22 @@ int at_shell(const struct shell *shell, size_t argc, char **argv) at_monitor_pause(&at_shell_monitor); shell_print(shell, "AT command event handler disabled"); } else { + if (IS_ENABLED(CONFIG_AT_SHELL_UNESCAPE_LF)) { + /* Replace the two character sequence "\n" with so AT%CMNG=0, + * which accepts multiline input, will work with a properly + * pre-processed cert. Without this, the second and subsequent lines of the + * cert are treated as new shell commands, which of course fail. + */ + if (strncmp(command, CREDENTIALS_CMD, strlen(CREDENTIALS_CMD)) == 0) { + char *c = command; + + while ((c = strstr(c, "\\n")) != NULL) { + c[0] = '\r'; + c[1] = '\n'; + } + } + } + err = nrf_modem_at_cmd(response, sizeof(response), "%s", command); if (err < 0) { shell_print(shell, "Sending AT command failed with error code %d", err); diff --git a/subsys/net/lib/nrf_cloud/Kconfig b/subsys/net/lib/nrf_cloud/Kconfig index f3ea2773181b..38aa7a370ca4 100644 --- a/subsys/net/lib/nrf_cloud/Kconfig +++ b/subsys/net/lib/nrf_cloud/Kconfig @@ -127,6 +127,7 @@ choice NRF_CLOUD_CREDENTIALS_MGMT config NRF_CLOUD_CREDENTIALS_MGMT_MODEM depends on NRF_MODEM_LIB select MODEM_KEY_MGMT + imply AT_SHELL_UNESCAPE_LF if AT_SHELL bool "Credentials are managed by the modem" config NRF_CLOUD_CREDENTIALS_MGMT_TLS_CRED