tty: n_gsm: add keep alive support
Subsystems (2)
PATCH v5 1/1 tty: n_gsm: add keep alive support
From: Daniel Starke <[email protected]>
n_gsm is based on the 3GPP 07.010 and its newer version is the 3GPP 27.010.
See https://portal.3gpp.org/desktopmodules/Specifications/SpecificationDetails.aspx?specificationId=1516
The changes from 07.010 to 27.010 are non-functional. Therefore, I refer to
the newer 27.010 here. Chapters 5.4.6.3.4 and 5.1.8.1.3 describe the test
command which can be used to test the mux connection between both sides.
Currently, no algorithm is implemented to make use of this command. This requires that each multiplexed upper layer protocol supervises the underlying muxer connection to handle possible connection losses.
Introduce ioctl commands and functions to optionally enable keep alive handling via the test command as described in chapter 5.4.6.3.4. A single incrementing octet "ka_num" is being used for unique identification of each single keep alive packet. Retries will use the same "ka_num" value as the original packet. Retry count and interval are taken from the general parameters N2 and T2.
Add usage description and basic example for the new ioctl to the n_gsm documentation.
Note that support for the test command is mandatory and already present in the muxer implementation since the very first version.
Also note that the previous ioctl structure gsm_config cannot be extended due to missing checks against zero of the field "unused".
--- Documentation/driver-api/tty/n_gsm.rst | 19 +++++ drivers/tty/n_gsm.c | 106 ++++++++++++++++++++++++- include/uapi/linux/gsmmux.h | 10 +++ 3 files changed, 133 insertions(+), 2 deletions(-)
v4 -> v5:
Applied changes from review comments:
Added remark for "ka_num" in the commit message to show relation with the code.
Added usage documentation and example to the kernel documentation. Changed type of gsm_mux field "ka_retries" to "signed int" and added cast from n2. Also added description for special value of -1.
Fixed long code line intention in gsm_control_response() for better readability.
Changed pr_info() to pr_debug() in gsm_control_keep_alive(). Added remark to gsm_config_ext field "reserved" that this must be set zero.
Documentation/driver-api/tty/n_gsm.rst +19 -0
@@ -25,6 +25,8 @@ Config Initiator #. Switch the serial line to using the n_gsm line discipline by using ``TIOCSETD`` ioctl. +#. Configure the mux using ``GSMIOC_GETCONF_EXT``/``GSMIOC_SETCONF_EXT`` ioctl if needed. + #. Configure the mux using ``GSMIOC_GETCONF``/``GSMIOC_SETCONF`` ioctl. #. Obtain base gsmtty number for the used serial port.
@@ -42,6 +44,7 @@ Config Initiator int ldisc = N_GSM0710; struct gsm_config c; + struct gsm_config_ext ce; struct termios configuration; uint32_t first;
@@ -62,6 +65,12 @@ Config Initiator /* use n_gsm line discipline */ ioctl(fd, TIOCSETD, &ldisc); + /* get n_gsm extended configuration */ + ioctl(fd, GSMIOC_GETCONF_EXT, &ce); + /* use keep-alive once every 5s for modem connection supervision */ + ce.keep_alive = 500; + /* set the new extended configuration */ + ioctl(fd, GSMIOC_SETCONF_EXT, &ce); /* get n_gsm configuration */ ioctl(fd, GSMIOC_GETCONF, &c); /* we are initiator and need encoding 0 (basic) */
@@ -106,6 +115,9 @@ Config Requester #. Switch the serial line to using the *n_gsm* line discipline by using ``TIOCSETD`` ioctl. +#. Configure the mux using ``GSMIOC_GETCONF_EXT``/``GSMIOC_SETCONF_EXT`` + ioctl if needed. + #. Configure the mux using ``GSMIOC_GETCONF``/``GSMIOC_SETCONF`` ioctl. #. Obtain base gsmtty number for the used serial port::
@@ -119,6 +131,7 @@ Config Requester int ldisc = N_GSM0710; struct gsm_config c; + struct gsm_config_ext ce; struct termios configuration; uint32_t first;
@@ -132,6 +145,12 @@ Config Requester /* use n_gsm line discipline */ ioctl(fd, TIOCSETD, &ldisc); + /* get n_gsm extended configuration */ + ioctl(fd, GSMIOC_GETCONF_EXT, &ce); + /* use keep-alive once every 5s for peer connection supervision */ + ce.keep_alive = 500; + /* set the new extended configuration */ + ioctl(fd, GSMIOC_SETCONF_EXT, &ce); /* get n_gsm configuration */ ioctl(fd, GSMIOC_GETCONF, &c); /* we are requester and need encoding 0 (basic) */
drivers/tty/n_gsm.c +104 -2
191 lines not on this page · raw message
include/uapi/linux/gsmmux.h +10 -0
@@ -39,4 +39,14 @@ struct gsm_netconfig {/* get the base tty number for a configured gsmmux tty */ #define GSMIOC_GETFIRST _IOR('G', 4, __u32) +struct gsm_config_ext { +__u32 keep_alive;/* Control channel keep-alive in 1/100th of a +* second (0 to disable) +*/ +__u32 reserved[7 ];/* For future use, must be initialized to zero */ +}; + +#define GSMIOC_GETCONF_EXT _IOR('G', 5, struct gsm_config_ext) +#define GSMIOC_SETCONF_EXT _IOW('G', 6, struct gsm_config_ext) +#endif
Signature · 1 line
2.34.1
D. Starke schreef op 2023-02-13 10:43:
Quoted 2 lines
From: Daniel Starke <[email protected]>
drivers/tty/n_gsm.c +1
-0+u32 keep_alive;/* Control channel keep-alive in ms */
[...]
drivers/tty/n_gsm.c static void gsm_control_response(struct gsm_mux *gsm, unsigned int command, · line 1937
Quoted 2 lines
drivers/tty/n_gsm.c +2
-0+if (dlci && !dlci->dead) +mod_timer (&gsm->ka_timer, jiffies + gsm->keep_alive *HZ /100 );
keep-alive is in ms? or in 10ms?
Maarten
Quoted 7 lines
Quoted 2 lines
From: Daniel Starke <[email protected]>
drivers/tty/n_gsm.c +1
-0+u32 keep_alive;/* Control channel keep-alive in ms */ [...]
drivers/tty/n_gsm.c static void gsm_control_response(struct gsm_mux *gsm, unsigned int command, · line 1937
Quoted 2 lines
drivers/tty/n_gsm.c +2
-0+if (dlci && !dlci->dead) +mod_timer (&gsm->ka_timer, jiffies + gsm->keep_alive *HZ /100 );keep-alive is in ms? or in 10ms?
Good found. The comment is wrong. It is in 10ms as also written in the comment for "keep_alive" within gsmmux.h to be in line with t1 and t2. I will correct this for v6 of the patch.
Best regards,
Daniel Starke