Skip to content

Commit

Permalink
application: serial_lte_modem: Automatic LTE connection
Browse files Browse the repository at this point in the history
Move the lte auto-connect from SLM LwM2M client to full SLM scope.
Support lte auto-connnect by new Kconfig CONFIG_SLM_AUTO_CONNECT.
Default behavior is no automatic LTE connection, same as before.

When auto-connect is enabled, need to customize network-specific
PDN configuration in code. Default is Non-IP in NB-IoT for NIDD.

Impact on LwM2M client:
.Operation "auto_connect" is removed from LwM2M command.
.No more dynamic config of auto_connect (and auto_register).
.CONFIG_SLM_AUTO_CONNECT is enabled by default in overlay.

Change CONFIG_SLM_CUSTOMIZED to CONFIG_SLM_CUSTOMER_VERSION to
allow reporting customer version of SLM after customization.

Remove unused CONFIG_SLM_AT_MODE and CONFIG_SLM_SOCKET_RX_MAX.

Signed-off-by: Jun Qing Zou <[email protected]>
  • Loading branch information
junqingzou authored and nordicjm committed Nov 15, 2023
1 parent 2e298b0 commit 710acdb
Show file tree
Hide file tree
Showing 13 changed files with 125 additions and 130 deletions.
23 changes: 7 additions & 16 deletions applications/serial_lte_modem/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,10 @@ source "Kconfig.zephyr"

menu "Nordic Serial LTE Modem"

config SLM_CUSTOMIZED
bool "Flag for customized functionality"
config SLM_CUSTOMER_VERSION
string "Customer version string"
help
Enable this flag to include customized logic.

config SLM_AT_MODE
bool "Serial LTE Modem by raw AT mode"
default y
select AT_CMD_PARSER
select AT_MONITOR
This version is reported together with baseline versions by AT command "#XSLMVER".

config SLM_AT_MAX_PARAM
int "Maximum number of parameters in AT command"
Expand Down Expand Up @@ -104,15 +98,12 @@ config SLM_INDICATE_TIME
GPIO active indication time in milliseconds. This setting specify the period length for the pin to be active

#
# Socket
# LTE network automatic attach
#
config SLM_SOCKET_RX_MAX
int "Maximum RX buffer size for receiving socket data"
range 576 708
default 576
config SLM_AUTO_CONNECT
bool "Automatically connect to the LTE network on start-up or after a reset"
help
Default: NET_IPV4_MTU (576)
Maximum: MSS setting in modem (708)
Enables automatic connection to the LTE network using the PDN configuration defined in 'slm_auto_connect.h'.

#
# TCP/TLS proxy
Expand Down
14 changes: 10 additions & 4 deletions applications/serial_lte_modem/doc/Generic_AT_commands.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ Response syntax

::

#XSLMVER: <ncs_version>,<libmodem_version>
#XSLMVER: <ncs_version>,<libmodem_version>[,<customer_version>]

The ``<ncs_version>`` value returns a string containing the version of the |NCS|.
The ``<ncs_version>`` value is a string containing the version of the |NCS|.

The ``<libmodem_version>`` value returns a string containing the version of the modem library.
The ``<libmodem_version>`` value is a string containing the version of the modem library.

The ``<customer_version>`` value is the :ref:`CONFIG_SLM_CUSTOMER_VERSION <CONFIG_SLM_CUSTOMER_VERSION>` string, if defined.

Example
~~~~~~~
Expand All @@ -46,7 +48,11 @@ The following command example reads the versions:
::

AT#XSLMVER
#XSLMVER: "2.3.0","2.3.0"
#XSLMVER: "2.5.0","2.5.0-lte-5ccd2d4dd54c"
OK

AT#XSLMVER
#XSLMVER: "2.5.99","2.5.0-lte-5ccd2d4dd54c","Onomondo 2.1.0"
OK

Read command
Expand Down
35 changes: 25 additions & 10 deletions applications/serial_lte_modem/doc/slm_description.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ Configuration options

Check and configure the following configuration options for the sample:

.. _CONFIG_SLM_CUSTOMIZED:
.. _CONFIG_SLM_CUSTOMER_VERSION:

CONFIG_SLM_CUSTOMIZED - Flag for customized functionality
This flag can be used to enable customized functionality.
To add your own custom logic, enclose the code by ``#if defined(CONFIG_SLM_CUSTOMIZED)`` and enable this flag.
CONFIG_SLM_CUSTOMER_VERSION - Customer version string
Version string defined by the customer after customizing the application.
When defined, this version is reported with the baseline versions by the ``#XSLMVER`` AT command.

.. _CONFIG_SLM_AT_MAX_PARAM:

Expand Down Expand Up @@ -124,14 +124,29 @@ CONFIG_SLM_INDICATE_TIME - Indicate GPIO active time
This option specifies the length, in milliseconds, of the time interval during which the indicate GPIO must stay active.
The default value is 100 milliseconds.

.. _CONFIG_SLM_SOCKET_RX_MAX:
.. _CONFIG_SLM_AUTO_CONNECT:

CONFIG_SLM_SOCKET_RX_MAX - Maximum RX buffer size for receiving socket data
This option specifies the maximum buffer size for receiving data through the socket interface.
By default, this size is set to :c:enumerator:`NET_IPV4_MTU` (576), which is defined in Zephyr.
The maximum value is 708, which is the maximum segment size (MSS) defined for the modem.
CONFIG_SLM_AUTO_CONNECT - Connect to LTE network at start-up or reset
This option enables connecting to the LTE network at start-up or reset using a defined PDN configuration.
This option is enabled by the LwM2M Carrier overlay, but is otherwise disabled by default.

This option impacts the total RAM usage.
.. note::
This option requires network-specific configuration in the ``slm_auto_connect.h`` file.

Here is a sample configuration for NIDD connection in the :file:`slm_auto_connect.h` file::

/* Network-specific default system mode configured by %XSYSTEMMODE (refer to AT command manual) */
0, /* LTE support */
1, /* NB-IoT support */
0, /* GNSS support, also define CONFIG_MODEM_ANTENNA if not Nordic DK */
0, /* LTE preference */
/* Network-specific default PDN configured by +CGDCONT and +CGAUTH (refer to AT command manual) */
true, /* PDP context definition required or not */
"Non-IP", /* PDP type: "IP", "IPV6", "IPV4V6", "Non-IP" */
"", /* Access point name */
0, /* PDP authentication protocol: 0(None), 1(PAP), 2(CHAP) */
"", /* PDN connection authentication username */
"" /* PDN connection authentication password */

.. _CONFIG_SLM_CR_TERMINATION:

Expand Down
9 changes: 2 additions & 7 deletions applications/serial_lte_modem/overlay-carrier.conf
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,7 @@ CONFIG_AT_HOST_LIBRARY=n
# Credential management
CONFIG_MODEM_KEY_MGMT=y

# Non-volatile Storage
CONFIG_NVS=y
CONFIG_MPU_ALLOW_FLASH_WRITE=y

# Default partition for NVS is unused
CONFIG_PM_PARTITION_SIZE_NVS_STORAGE=0

# Enable LwM2M carrier support in SLM
CONFIG_SLM_CARRIER=y
CONFIG_SLM_AUTO_CONNECT=y
CONFIG_SLM_CUSTOMER_VERSION="lwm2m_carrier"
6 changes: 5 additions & 1 deletion applications/serial_lte_modem/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,14 @@ CONFIG_MODEM_JWT=y
#CONFIG_MQTT_KEEPALIVE=60
CONFIG_MQTT_CLEAN_SESSION=y

# AT command helper libraries
CONFIG_AT_CMD_PARSER=y
CONFIG_AT_MONITOR=y

#
# SLM-specific configurations
#
CONFIG_SLM_CUSTOMIZED=n
CONFIG_SLM_CUSTOMER_VERSION=""
CONFIG_SLM_EXTERNAL_XTAL=n
CONFIG_SLM_START_SLEEP=n
CONFIG_SLM_DATAMODE_URC=n
Expand Down
35 changes: 0 additions & 35 deletions applications/serial_lte_modem/src/lwm2m_carrier/slm_at_carrier.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ LOG_MODULE_REGISTER(slm_carrier, CONFIG_SLM_LOG_LEVEL);

/**@brief LwM2M Carrier operations. */
enum slm_carrier_operation {
/* LTE auto-connect operation for LwM2M Carrier */
CARRIER_OP_AUTO_CONNECT,
/* Carrier AppData Operation */
CARRIER_OP_APPDATA_SEND,
/* Carrier Device Operation */
Expand Down Expand Up @@ -60,7 +58,6 @@ struct carrier_op_list {
static int m_mem_free;

/** forward declaration of cmd handlers **/
static int do_carrier_auto_connect(void);
static int do_carrier_appdata_send(void);
static int do_carrier_device_battery_level(void);
static int do_carrier_device_battery_status(void);
Expand All @@ -84,7 +81,6 @@ static int do_carrier_request_link_up(void);

/**@brief SLM AT Command list type. */
static struct carrier_op_list op_list[CARRIER_OP_MAX] = {
{CARRIER_OP_AUTO_CONNECT, "auto_connect", do_carrier_auto_connect},
{CARRIER_OP_APPDATA_SEND, "app_data", do_carrier_appdata_send},
{CARRIER_OP_DEVICE_BATTERY_LEVEL, "battery_level", do_carrier_device_battery_level},
{CARRIER_OP_DEVICE_BATTERY_STATUS, "battery_status", do_carrier_device_battery_status},
Expand Down Expand Up @@ -839,37 +835,6 @@ static int do_carrier_request_link_up(void)
return lwm2m_carrier_request(LWM2M_CARRIER_REQUEST_LINK_UP);
}

/* AT#XCARRIER="auto_connect","read|write"[,<auto-connect-flag>] */
static int do_carrier_auto_connect(void)
{
int ret = 0;
int flag;
char operation[6];
size_t size = sizeof(operation);

ret = util_string_get(&slm_at_param_list, 2, operation, &size);
if (ret) {
return ret;
}

if (slm_util_cmd_casecmp(operation, "READ")) {
rsp_send("\r\n#XCARRIER: auto_connect %d\r\n", slm_carrier_auto_connect);
} else if (slm_util_cmd_casecmp(operation, "WRITE")) {
ret = at_params_int_get(&slm_at_param_list, 3, &flag);
if (ret) {
return ret;
}
if (flag == 0 || flag == 1) {
slm_carrier_auto_connect = flag;
(void)slm_settings_auto_connect_save();
} else {
ret = -EINVAL;
}
}

return ret;
}

/**@brief API to handle Carrier AT command
*/
int handle_at_carrier(enum at_cmd_type cmd_type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
* @brief Vendor-specific AT command for LwM2M Carrier service.
* @{
*/

/* Whether to auto-connect to the network at startup or after a FOTA update. */
extern int32_t slm_carrier_auto_connect;

/**
* @brief Initialize Carrier AT command parser.
*
Expand Down
53 changes: 39 additions & 14 deletions applications/serial_lte_modem/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@
#include "slm_at_fota.h"
#include "slm_settings.h"
#include "slm_uart_handler.h"
#if defined(CONFIG_SLM_CARRIER)
#include "slm_at_carrier.h"
#endif
#include "slm_util.h"

LOG_MODULE_REGISTER(slm, CONFIG_SLM_LOG_LEVEL);

Expand Down Expand Up @@ -338,32 +336,59 @@ static void check_app_fota_status(void)
int lte_auto_connect(void)
{
int err = 0;

#if defined(CONFIG_SLM_CARRIER)
#if defined(CONFIG_SLM_AUTO_CONNECT)
int stat;
struct network_config {
/* Refer to AT command manual of %XSYSTEMMODE for system mode settings */
int lte_m_support; /* 0 ~ 1 */
int nb_iot_support; /* 0 ~ 1 */
int gnss_support; /* 0 ~ 1 */
int lte_preference; /* 0 ~ 4 */
/* Refer to AT command manual of +CGDCONT and +CGAUTH for PDN configuration */
bool pdp_config; /* PDP context definition required or not */
char *pdn_fam; /* PDP type: "IP", "IPV6", "IPV4V6", "Non-IP" */
char *pdn_apn; /* Access point name */
int pdn_auth; /* PDN authentication protocol 0(None), 1(PAP), 2(CHAP) */
char *pdn_username; /* PDN connection authentication username */
char *pdn_password; /* PDN connection authentication password */
};
const struct network_config cfg = {
#include "slm_auto_connect.h"
};

if (!slm_carrier_auto_connect) {
return 0;
}
err = nrf_modem_at_scanf("AT+CEREG?", "+CEREG: %d", &stat);
if (err != 1 || (stat == 1 || stat == 5)) {
return 0;
}

LOG_INF("auto connect");
#if defined(CONFIG_LWM2M_CARRIER_SERVER_BINDING_N)
err = nrf_modem_at_printf("AT%%XSYSTEMMODE=0,1,0,0");
LOG_INF("lte auto connect");
err = nrf_modem_at_printf("AT%%XSYSTEMMODE=%d,%d,%d,%d", cfg.lte_m_support,
cfg.nb_iot_support, cfg.gnss_support, cfg.lte_preference);
if (err) {
LOG_ERR("Failed to configure RAT: %d", err);
LOG_ERR("Failed to configure system mode: %d", err);
return err;
}
#endif /* CONFIG_LWM2M_CARRIER_SERVER_BINDING_N */
if (cfg.pdp_config) {
err = nrf_modem_at_printf("AT+CGDCONT=0,%s,%s", cfg.pdn_fam, cfg.pdn_apn);
if (err) {
LOG_ERR("Failed to configure PDN: %d", err);
return err;
}
}
if (cfg.pdp_config && cfg.pdn_auth != 0) {
err = nrf_modem_at_printf("AT+CGAUTH=0,%d,%s,%s", cfg.pdn_auth,
cfg.pdn_username, cfg.pdn_password);
if (err) {
LOG_ERR("Failed to configure AUTH: %d", err);
return err;
}
}
err = nrf_modem_at_printf("AT+CFUN=1");
if (err) {
LOG_ERR("Failed to turn on radio: %d", err);
return err;
}
#endif /* CONFIG_SLM_CARRIER */
#endif /* CONFIG_SLM_AUTO_CONNECT */

return err;
}
Expand Down
9 changes: 8 additions & 1 deletion applications/serial_lte_modem/src/slm_at_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,14 @@ static int handle_at_slmver(enum at_cmd_type type)
if (type == AT_CMD_TYPE_SET_COMMAND) {
char *libmodem = nrf_modem_build_version();

rsp_send("\r\n#XSLMVER: %s,\"%s\"\r\n", STRINGIFY(NCS_VERSION_STRING), libmodem);
if (strlen(CONFIG_SLM_CUSTOMER_VERSION) > 0) {
rsp_send("\r\n#XSLMVER: %s,\"%s\",\"%s\"\r\n",
STRINGIFY(NCS_VERSION_STRING), libmodem,
CONFIG_SLM_CUSTOMER_VERSION);
} else {
rsp_send("\r\n#XSLMVER: %s,\"%s\"\r\n",
STRINGIFY(NCS_VERSION_STRING), libmodem);
}
ret = 0;
}

Expand Down
22 changes: 22 additions & 0 deletions applications/serial_lte_modem/src/slm_auto_connect.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

/*
* This file defines the network configuration when CONFIG_SLM_AUTO_CONNECT is enabled.
*/

/* Network-specific default system mode configured by %XSYSTEMMODE (refer to AT command manual) */
1, /* LTE support */
1, /* NB-IoT support */
1, /* GNSS support, also define CONFIG_MODEM_ANTENNA if not Nordic DK */
0, /* LTE preference */
/* Network-specific default PDN configured by +CGDCONT and +CGAUTH (refer to AT command manual) */
false, /* PDP context definition required or not */
"", /* PDP type: "IP", "IPV6", "IPV4V6", "Non-IP" */
"", /* Access point name */
0, /* PDP authentication protocol: 0(None), 1(PAP), 2(CHAP) */
"", /* PDN connection authentication username */
"" /* PDN connection authentication password */
Loading

0 comments on commit 710acdb

Please sign in to comment.