Skip to content

Commit

Permalink
applications: serial_lte_modem: SLM server fixes.
Browse files Browse the repository at this point in the history
- Recv even when the connection is being closed.
- Fix statuses of operations to correspond to correct errno values.
- Documentation fixes.

Signed-off-by: Markus Lassila <markus.lassila@nordicsemi.no>
  • Loading branch information
MarkusLassila authored and nordicjm committed Oct 11, 2023
1 parent 9ca2b27 commit 3897787
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 93 deletions.
50 changes: 39 additions & 11 deletions applications/serial_lte_modem/doc/TCPUDP_AT_commands.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Syntax
* The ``<sec_tag>`` parameter is an integer.
If it is given, a TLS server will be started.
It indicates to the modem the credential of the security tag used for establishing a secure connection.
Can only be used when the :file:`overlay-native_tls.conf` configuration file is used.

Response syntax
~~~~~~~~~~~~~~~
Expand All @@ -57,13 +58,40 @@ Response syntax
* The ``<error>`` value is an integer.
It represents the error value according to the standard POSIX *errno*.

Examples
Unsolicited notification
~~~~~~~~~~~~~~~~~~~~~~~~

::

#XTCPSVR: "<peer ip>","connected"

This is emitted when a new connection has been created to the server.

* The ``<peer_ip>`` value is the IPv4 or IPv6 address of the peer.

.. tcpsvr_disconnect_notif_start
::

#XTCPSVR: <error>,"disconnected"

This is emitted when the client has been disconnected.

* The ``<error>`` value is an integer.
It is either ``0`` when the client is disconnected normally, or an *-errno* code.

.. tcpsvr_disconnect_notif_end
Example
~~~~~~~~

::

AT#XTCPSVR=1,3442,600
#XTCPSVR: 2,"started"
#XTCPSVR: "123.456.789.123","connected"
#XTCPSVR: 0,"disconnected"
OK

Read command
Expand Down Expand Up @@ -319,11 +347,9 @@ Syntax
Response syntax
~~~~~~~~~~~~~~~

::

#XTCPSVR: <cause>,"disconnected"

* The ``<cause>`` value is an integer of -111 or ECONNREFUSED.
.. include:: TCPUDP_AT_commands.rst
:start-after: tcpsvr_disconnect_notif_start
:end-before: tcpsvr_disconnect_notif_end

Examples
~~~~~~~~
Expand All @@ -334,7 +360,7 @@ Examples
#XTCPSVR: 1,2,1
OK
AT#XTCPHANGUP=2
#XTCPSVR: -111,"disconnected"
#XTCPSVR: 0,"disconnected"
OK

Read command
Expand Down Expand Up @@ -376,11 +402,12 @@ TCP receive data

::

<data>
#XTCPDATA: <size>
<data>

* The ``<size>`` parameter is an integer that indicates the size of the received data.
This notification comes only when SLM is not operating in :ref:`data mode <slm_data_mode>`.
* The ``<data>`` parameter is a string that contains the data received.
* The ``<size>`` parameter is the size of the string, which is present only when SLM is not operating in ``slm_data_mode``.

UDP server #XUDPSVR
===================
Expand Down Expand Up @@ -655,8 +682,9 @@ UDP receive data

::

<data>
#XUDPDATA: <size>
<data>

* The ``<size>`` parameter is an integer that indicates the size of the received data.
This notification comes only when SLM is not operating in :ref:`data mode <slm_data_mode>`.
* The ``<data>`` parameter is a string that contains the data received.
* The ``<size>`` parameter is the size of the string, which is present only when SLM is not operating in ``slm_data_mode``.
93 changes: 36 additions & 57 deletions applications/serial_lte_modem/doc/slm_testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ TCP client
#XTCPCLI: 1,0
OK
#. Send plain text data to the TCP server and retrieve ten bytes of the returned data.
#. Send plain text data to the TCP server and receive ten bytes of the returned data.

.. parsed-literal::
:class: highlight
Expand All @@ -234,9 +234,8 @@ TCP client
#XTCPSEND: 8
OK
**AT#XTCPRECV=10**
#XTCPDATA: 10
PONG: b'Te
#XTCPRECV: 10
OK
#. Disconnect and confirm the status of the connection.
Expand Down Expand Up @@ -450,20 +449,17 @@ You must register the corresponding credentials on the server side.
#XTCPCLI: 1,0
OK
#. Send plain text data to the TLS server and retrieve the returned data.
#. Send plain text data to the TLS server and receive the returned data.

.. parsed-literal::
:class: highlight
**AT#XTCPSEND="Test TLS client"**
#XTCPSEND: 15
OK
#XTCPDATA: 24
**AT#XTCPRECV**
#XTCPDATA: 24
PONG: b'Test TLS client'
#XTCPRECV: 24
OK
#. Disconnect from the server.

Expand Down Expand Up @@ -624,7 +620,7 @@ To act as a TCP server, |global_private_address|
:class: highlight
**AT#XSOCKET=1,1,1**
#XSOCKET: 2,1,6
#XSOCKET: 0,1,6
OK
**AT#XBIND=**\ *1234*
Expand All @@ -640,16 +636,16 @@ To act as a TCP server, |global_private_address|
.. parsed-literal::
:class: highlight
**AT#XACCEPT**
#XACCEPT: connected with *IP address*
#XACCEPT: 3
OK
**AT#XACCEPT=60**
#XACCEPT: 1,"*IP address*"
OK
**AT#XRECV=0**
#XRECV: 26
Hello, TCP#1!Hello, TCP#2!
OK
**AT#XSEND="TCP1/2 received"**
#XSEND: 15
OK
Expand Down Expand Up @@ -682,7 +678,7 @@ To act as a TCP server, |global_private_address|
:class: highlight
**AT#XSOCKET=0**
#XSOCKET: "closed"
#XSOCKET: 0,"closed"
OK
Expand All @@ -698,7 +694,7 @@ To act as a TCP server, |global_private_address|
OK
**AT#XTCPSVR?**
#XTCPSVR: -1,-1
#XTCPSVR: -1,-1,0
OK
#. Create a TCP server and read the information about the current state.
Expand All @@ -708,59 +704,59 @@ To act as a TCP server, |global_private_address|
:class: highlight
**AT#XTCPSVR=1,**\ *1234*
#XTCPSVR: 2,"started"
#XTCPSVR: 0,"started"
OK
**AT#XTCPSVR?**
#XTCPSVR: 1,-1,0
#XTCPSVR: 0,-1,1
OK
#. Run the :file:`client_tcp.py` script to start sending data to the server.

#. Observe that the server accepts the connection from the client.
#. Observe that the server accepts the connection from the client and receives the first packets.
Read the information about the current state again.

.. parsed-literal::
:class: highlight
#XTCPSVR: *IP address* connected
#XTCPSVR: "*IP address*","connected"
#XTCPDATA: 13
Hello, TCP#1!
#XTCPDATA: 13
Hello, TCP#2!
**AT#XTCPSVR?**
#XTCPSVR: 1,2,0
#XTCPSVR: 0,1,1
OK
#. Start receiving and acknowledging the data.
#. Send responses and receive the rest of the data.
Client disconnects after receiving the last response.

.. parsed-literal::
:class: highlight
**AT#XTCPRECV**
Hello, TCP#1!Hello, TCP#2!
#XTCPRECV: 26
OK
**AT#XTCPSEND="TCP1/2 received"**
#XTCPSEND: 15
OK
#XTCPDATA: 13
Hello, TCP#3!
#XTCPDATA: 13
Hello, TCP#4!
#XTCPDATA: 13
Hello, TCP#5!
**AT#XTCPSVR?**
#XTCPSVR: 1,2,0
OK
**AT#XTCPRECV**
Hello, TCP#3!Hello, TCP#4!Hello, TCP#5!
#XTCPRECV: 39
OK
**AT#XTCPSEND="TCP3/4/5 received"**
**AT#XTCPSEND=1,"TCP3/4/5 received"**
#XTCPSEND: 17
OK
#XTCPSVR: 0,"disconnected"
#. Observe the output of the Python script::

$ python client_tcp.py
Expand All @@ -780,7 +776,7 @@ To act as a TCP server, |global_private_address|
:class: highlight
**AT#XTCPSVR?**
#XTCPSVR: 1,2,0
#XTCPSVR: 0,-1,1
OK
#. Stop the server.
Expand All @@ -789,11 +785,11 @@ To act as a TCP server, |global_private_address|
:class: highlight
**AT#XTCPSVR=0**
#XTCPSVR:-1,"stopped"
#XTCPSVR:0,"stopped"
OK
**AT#XTCPSVR?**
#XTCPSVR: -1,-1
#XTCPSVR: -1,-1,0
OK
UDP server
Expand Down Expand Up @@ -1003,31 +999,14 @@ To act as a UDP server, |global_private_address|
TLS server
==========

The TLS server role is currently not supported.
The TLS server role is currently only supported when using the :file:`overlay-native_tls.conf` configuration file.

.. parsed-literal::
:class: highlight
**AT#XSOCKET=1,1,1,16842753**
#XSOCKET: "(D)TLS Server not supported"
ERROR
**AT#XTCPSVR=1,3443,16842753**
#XTCPSVR: "TLS Server not supported"
ERROR

DTLS server
===========

The DTLS server role is currently not supported (modem limitation).

.. parsed-literal::
:class: highlight
**AT#XSOCKET=1,2,1,16842755**
#XSOCKET: "(D)TLS Server not supported"
ERROR
DNS lookup
==========

Expand Down
5 changes: 2 additions & 3 deletions applications/serial_lte_modem/src/slm_at_host.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,16 +221,15 @@ K_TIMER_DEFINE(inactivity_timer, inactivity_timer_handler, NULL);
static size_t raw_rx_handler(const uint8_t *buf, const size_t len)
{
size_t processed;
bool quit_str_match;
bool prev_quit_str_match;
bool quit_str_match = false;
bool prev_quit_str_match = false;
uint8_t quit_str_match_count;
uint8_t prev_quit_str_match_count;

k_mutex_lock(&mutex_data, K_FOREVER);

/* Initialize from previous time.*/
prev_quit_str_match_count = quit_str_partial_match;
quit_str_match = false;
quit_str_match_count = prev_quit_str_match_count;
if (prev_quit_str_match_count != 0) {
prev_quit_str_match = true;
Expand Down
Loading

0 comments on commit 3897787

Please sign in to comment.