Skip to content

Commit f4f7d63

Browse files
dstarke-siemensgregkh
authored andcommitted
tty: n_gsm: fix software flow control handling
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. Chapter 5.4.8.1 states that XON/XOFF characters shall be used instead of Fcon/Fcoff command in advanced option mode to handle flow control. Chapter 5.4.8.2 describes how XON/XOFF characters shall be handled. Basic option mode only used Fcon/Fcoff commands and no XON/XOFF characters. These are treated as data bytes here. The current implementation uses the gsm_mux field 'constipated' to handle flow control from the remote peer and the gsm_dlci field 'constipated' to handle flow control from each DLCI. The later is unrelated to this patch. The gsm_mux field is correctly set for Fcon/Fcoff commands in gsm_control_message(). However, the same is not true for XON/XOFF characters in gsm1_receive(). Disable software flow control handling in the tty to allow explicit handling by n_gsm. Add the missing handling in advanced option mode for gsm_mux in gsm1_receive() to comply with the standard. This patch depends on the following commit: Commit 8838b2a ("tty: n_gsm: fix SW flow control encoding/handling") Fixes: e1eaea4 ("tty: n_gsm line discipline") Cc: stable@vger.kernel.org Signed-off-by: Daniel Starke <daniel.starke@siemens.com> Link: https://lore.kernel.org/r/20220422071025.5490-3-daniel.starke@siemens.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent c19ffe0 commit f4f7d63

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

drivers/tty/n_gsm.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ struct gsm_mux {
232232
int initiator; /* Did we initiate connection */
233233
bool dead; /* Has the mux been shut down */
234234
struct gsm_dlci *dlci[NUM_DLCI];
235+
int old_c_iflag; /* termios c_iflag value before attach */
235236
bool constipated; /* Asked by remote to shut up */
236237

237238
spinlock_t tx_lock;
@@ -2022,6 +2023,16 @@ static void gsm0_receive(struct gsm_mux *gsm, unsigned char c)
20222023

20232024
static void gsm1_receive(struct gsm_mux *gsm, unsigned char c)
20242025
{
2026+
/* handle XON/XOFF */
2027+
if ((c & ISO_IEC_646_MASK) == XON) {
2028+
gsm->constipated = true;
2029+
return;
2030+
} else if ((c & ISO_IEC_646_MASK) == XOFF) {
2031+
gsm->constipated = false;
2032+
/* Kick the link in case it is idling */
2033+
gsm_data_kick(gsm, NULL);
2034+
return;
2035+
}
20252036
if (c == GSM1_SOF) {
20262037
/* EOF is only valid in frame if we have got to the data state */
20272038
if (gsm->state == GSM_DATA) {
@@ -2449,6 +2460,9 @@ static int gsmld_attach_gsm(struct tty_struct *tty, struct gsm_mux *gsm)
24492460
int ret, i;
24502461

24512462
gsm->tty = tty_kref_get(tty);
2463+
/* Turn off tty XON/XOFF handling to handle it explicitly. */
2464+
gsm->old_c_iflag = tty->termios.c_iflag;
2465+
tty->termios.c_iflag &= (IXON | IXOFF);
24522466
ret = gsm_activate_mux(gsm);
24532467
if (ret != 0)
24542468
tty_kref_put(gsm->tty);
@@ -2489,6 +2503,8 @@ static void gsmld_detach_gsm(struct tty_struct *tty, struct gsm_mux *gsm)
24892503
WARN_ON(tty != gsm->tty);
24902504
for (i = 1; i < NUM_DLCI; i++)
24912505
tty_unregister_device(gsm_tty_driver, base + i);
2506+
/* Restore tty XON/XOFF handling. */
2507+
gsm->tty->termios.c_iflag = gsm->old_c_iflag;
24922508
tty_kref_put(gsm->tty);
24932509
gsm->tty = NULL;
24942510
}

0 commit comments

Comments
 (0)