Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1840399iob; Thu, 5 May 2022 09:09:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJygvYioOVUHCdJBlZJrlB1XEGyMMkIf98BbpLPcer/vqsQapTeNdBdQci4nhq0yxlxo8RYX X-Received: by 2002:a17:907:3f19:b0:6f5:6b2:9615 with SMTP id hq25-20020a1709073f1900b006f506b29615mr2286193ejc.659.1651766961866; Thu, 05 May 2022 09:09:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651766961; cv=none; d=google.com; s=arc-20160816; b=llLJsZubCkehYL7jxduLQE29eK/RRgWONQ0/pfNpBKcSFqKYpZz28NqsvW8IK7l07U MiXjLRi0d0UAw1x/4ZPskL31aQ8dXv/9wpOlGmrdjoLuk+rzvLMM5Sxi3CtJZ2nWulyA CkACv78juyypp5eL3/HXM7wSObFO+HBVRR62R0N3m/NaYtTYWYVRhiCowIIJqhSnlhGJ phn0rKTIrjm1lauUI+lYC/YYOr+Fr3GGFJLepHOI84DG6E1oTxF2hU7gm5G+fNZXvEtS ABGJu45j7/8H6eolgy2elCNjx9YPHpPPeI3TcsNOehEBt/nPGHtjxVZ1WFWi7m0nk0bT g55g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=zJ3xyCgiwNbPnHISM81GLDXCMoWHY4TAnxRZH7cwsi8=; b=WeXsvr02SnurGLObngmdZCJf5FtsV4Prx55zdiTKw1Gb60VKWDKI+uLhngewyH/rty Qs+wXoJdO5/O/tpDcXytJ+ruqHA6yEPbs5SLbu9NiKyWG+i8HyQdai7i+wGosoqG7jL3 ZazPTdpxJuiw7WH0XtfgHkJXLcm1c061OSGsp74mCvsSABBgu0yI130qzAAhpidiWNqE syxaMtR7/HPI90wLdU23Tg4pnBjrnAXIapC1WUAekON4cNGqcse668avyhgLJI1LFceW dSDrLc/00zYkycRR65kjK1L9eeJZ2h0y+ZLPSX2b0FKK7UNI3OYgE9RZ0XWHMVGXgjRz a9XQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=jVZHXcvd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hr9-20020a1709073f8900b006f397284fc8si3657622ejc.695.2022.05.05.09.08.57; Thu, 05 May 2022 09:09:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=jVZHXcvd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1358274AbiEDR3y (ORCPT + 99 others); Wed, 4 May 2022 13:29:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40222 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356664AbiEDRJh (ORCPT ); Wed, 4 May 2022 13:09:37 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC34AE02E; Wed, 4 May 2022 09:55:22 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A59A8617DE; Wed, 4 May 2022 16:55:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 023CFC385A4; Wed, 4 May 2022 16:55:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1651683321; bh=qyER8K2QxBFIr0Kc3Q6zgBJENfDJNyjEhU0emb+6CjQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jVZHXcvdpg2n3ZwSCIVWNhODwboPdPBjgFVRPsDKfzQOy2O2BJPWiEaK6Ervo1Hbd Ww8FR+S+Oz9h4tmdC9btAI9iQDOvQpBe0Qk6O8Oc3j+rtw9mvqITpjDaB7D/qU5HrY 0NYthd7yEoL5O0a822m0TwpYEgVX5LrW6QfevKtU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Daniel Starke Subject: [PATCH 5.15 172/177] tty: n_gsm: fix software flow control handling Date: Wed, 4 May 2022 18:46:05 +0200 Message-Id: <20220504153109.013429794@linuxfoundation.org> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220504153053.873100034@linuxfoundation.org> References: <20220504153053.873100034@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Daniel Starke commit f4f7d63287217ba25e5c80f5faae5e4f7118790e upstream. 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 8838b2af23ca ("tty: n_gsm: fix SW flow control encoding/handling") Fixes: e1eaea46bb40 ("tty: n_gsm line discipline") Cc: stable@vger.kernel.org Signed-off-by: Daniel Starke Link: https://lore.kernel.org/r/20220422071025.5490-3-daniel.starke@siemens.com Signed-off-by: Greg Kroah-Hartman --- drivers/tty/n_gsm.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) --- a/drivers/tty/n_gsm.c +++ b/drivers/tty/n_gsm.c @@ -233,6 +233,7 @@ struct gsm_mux { int initiator; /* Did we initiate connection */ bool dead; /* Has the mux been shut down */ struct gsm_dlci *dlci[NUM_DLCI]; + int old_c_iflag; /* termios c_iflag value before attach */ bool constipated; /* Asked by remote to shut up */ spinlock_t tx_lock; @@ -1959,6 +1960,16 @@ static void gsm0_receive(struct gsm_mux static void gsm1_receive(struct gsm_mux *gsm, unsigned char c) { + /* handle XON/XOFF */ + if ((c & ISO_IEC_646_MASK) == XON) { + gsm->constipated = true; + return; + } else if ((c & ISO_IEC_646_MASK) == XOFF) { + gsm->constipated = false; + /* Kick the link in case it is idling */ + gsm_data_kick(gsm, NULL); + return; + } if (c == GSM1_SOF) { /* EOF is only valid in frame if we have got to the data state and received at least one byte (the FCS) */ @@ -2377,6 +2388,9 @@ static int gsmld_attach_gsm(struct tty_s int ret, i; gsm->tty = tty_kref_get(tty); + /* Turn off tty XON/XOFF handling to handle it explicitly. */ + gsm->old_c_iflag = tty->termios.c_iflag; + tty->termios.c_iflag &= (IXON | IXOFF); ret = gsm_activate_mux(gsm); if (ret != 0) tty_kref_put(gsm->tty); @@ -2417,6 +2431,8 @@ static void gsmld_detach_gsm(struct tty_ WARN_ON(tty != gsm->tty); for (i = 1; i < NUM_DLCI; i++) tty_unregister_device(gsm_tty_driver, base + i); + /* Restore tty XON/XOFF handling. */ + gsm->tty->termios.c_iflag = gsm->old_c_iflag; tty_kref_put(gsm->tty); gsm->tty = NULL; }