Skip to content

Commit

Permalink
lib: at_shell: Add optional multiline support
Browse files Browse the repository at this point in the history
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 <CR><LF> if CONFIG_AT_SHELL_UNESCAPE_LF
is enabled.

Jira: IRIS-6919

Signed-off-by: Pete Skeggs <[email protected]>
  • Loading branch information
plskeggs authored and rlubos committed Sep 20, 2024
1 parent e8755ef commit 6e0e90e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 ``<CR><LF>`` if :kconfig:option:`CONFIG_AT_SHELL_UNESCAPE_LF` is enabled.

Multiprotocol Service Layer libraries
-------------------------------------

Expand Down
8 changes: 8 additions & 0 deletions lib/at_shell/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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 <CR><LF>. 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
18 changes: 18 additions & 0 deletions lib/at_shell/at_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include <nrf_modem_at.h>
#include <modem/at_monitor.h>

#define CREDENTIALS_CMD "AT%CMNG=0"

static struct shell *global_shell;
static const char at_usage_str[] =
"Usage: at <subcommand>\n"
Expand Down Expand Up @@ -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 <CR><LF> 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);
Expand Down
1 change: 1 addition & 0 deletions subsys/net/lib/nrf_cloud/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6e0e90e

Please sign in to comment.