Skip to content

Commit 6e0e90e

Browse files
plskeggsrlubos
authored andcommitted
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 <CR><LF> if CONFIG_AT_SHELL_UNESCAPE_LF is enabled. Jira: IRIS-6919 Signed-off-by: Pete Skeggs <[email protected]>
1 parent e8755ef commit 6e0e90e

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

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

+5
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,11 @@ Modem libraries
739739
* To use the ``AT+CMMS`` AT command when sending concatenated SMS message.
740740
* To set "7" as a fallback SMS service center address for type approval SIM cards which do not have it set.
741741

742+
* :ref:`lib_at_shell` library:
743+
744+
* Added the :kconfig:option:`CONFIG_AT_SHELL_UNESCAPE_LF` Kconfig option to enable reception of multiline AT commands.
745+
* Updated the :c:func:`at_shell` function to replace ``\n`` with ``<CR><LF>`` if :kconfig:option:`CONFIG_AT_SHELL_UNESCAPE_LF` is enabled.
746+
742747
Multiprotocol Service Layer libraries
743748
-------------------------------------
744749

lib/at_shell/Kconfig

+8
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,12 @@ config AT_SHELL_CMD_RESPONSE_MAX_LEN
2020
int "Maximum AT command response length"
2121
default 2700
2222

23+
config AT_SHELL_UNESCAPE_LF
24+
bool "Unescape linefeed"
25+
help
26+
Replaces \n with <CR><LF>. This enables commands such as AT%CMNG=0 to
27+
properly receive certificates that ordinarily have multiple lines.
28+
The certificate must have been preprocessed to replace EOL sequences
29+
with a literal \ character followed by an n character.
30+
2331
endif # AT_SHELL

lib/at_shell/at_shell.c

+18
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include <nrf_modem_at.h>
1111
#include <modem/at_monitor.h>
1212

13+
#define CREDENTIALS_CMD "AT%CMNG=0"
14+
1315
static struct shell *global_shell;
1416
static const char at_usage_str[] =
1517
"Usage: at <subcommand>\n"
@@ -54,6 +56,22 @@ int at_shell(const struct shell *shell, size_t argc, char **argv)
5456
at_monitor_pause(&at_shell_monitor);
5557
shell_print(shell, "AT command event handler disabled");
5658
} else {
59+
if (IS_ENABLED(CONFIG_AT_SHELL_UNESCAPE_LF)) {
60+
/* Replace the two character sequence "\n" with <CR><LF> so AT%CMNG=0,
61+
* which accepts multiline input, will work with a properly
62+
* pre-processed cert. Without this, the second and subsequent lines of the
63+
* cert are treated as new shell commands, which of course fail.
64+
*/
65+
if (strncmp(command, CREDENTIALS_CMD, strlen(CREDENTIALS_CMD)) == 0) {
66+
char *c = command;
67+
68+
while ((c = strstr(c, "\\n")) != NULL) {
69+
c[0] = '\r';
70+
c[1] = '\n';
71+
}
72+
}
73+
}
74+
5775
err = nrf_modem_at_cmd(response, sizeof(response), "%s", command);
5876
if (err < 0) {
5977
shell_print(shell, "Sending AT command failed with error code %d", err);

subsys/net/lib/nrf_cloud/Kconfig

+1
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ choice NRF_CLOUD_CREDENTIALS_MGMT
127127
config NRF_CLOUD_CREDENTIALS_MGMT_MODEM
128128
depends on NRF_MODEM_LIB
129129
select MODEM_KEY_MGMT
130+
imply AT_SHELL_UNESCAPE_LF if AT_SHELL
130131
bool "Credentials are managed by the modem"
131132

132133
config NRF_CLOUD_CREDENTIALS_MGMT_TLS_CRED

0 commit comments

Comments
 (0)