From patchwork Fri Feb 3 14:50:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "D. Starke" X-Patchwork-Id: 52548 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp884075wrn; Fri, 3 Feb 2023 07:00:21 -0800 (PST) X-Google-Smtp-Source: AK7set/6b3Rl0YRObj3OH2FIGlkGuH+KaOQgxiTtd+1Xr1gAf0yq0G9LG/A97GjDUcd6wRpTW7yf X-Received: by 2002:a05:6a20:6904:b0:bf:58d1:ce87 with SMTP id q4-20020a056a20690400b000bf58d1ce87mr5745773pzj.6.1675436421174; Fri, 03 Feb 2023 07:00:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675436421; cv=none; d=google.com; s=arc-20160816; b=i1GB4llJZwpwutyCi+0K41z5+iO4NnoCF3MPExWNDed3SrKt7RiMbUQCdyQg+epiJq O/6zCk8LAmsbBesFDIvmZi95InLQb6LJL2vMzma802o+tKpoXasddfH5w8ix4e7pV6fr Gm1fqcuf47IHz9rWSy4uGhLRVVLd1fLtfkNaWQ6qzAFo6lGYuOCyhaCwoOzuZq9H+yct euNlGI9BwyOxySuRl73hDQHIq/Ma9yHmo8ncmnETMsHybFd/BV/hwf+CkPX9jiBSCAQ2 wIyoRBP3Lsm0rJlDUE0aGrzCI9sXZWvHSTuepecXnsKITNDE5qQ2fnJCmcq6BO6NlPd0 nnYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:feedback-id:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=2NyostHau00yFANqCpLq5nifgI6rwhrmtoY/jfHx2Is=; b=PpdS8QymNNtWN/QqRZdR9FnQaTx37uWUkLdEJ3JNcijoqx7JM55DGsok1gIDZ2Cq2O +cCssgB1mHuF3nvo18rCsqgHqi/uLi6INjmAn45e6jnmJMG4VUdiodIF9ItVnMRyKFFX ZxLIZBJJTseEOD6FaMcMgeuUmyFVvL7TN9qSGp9l9FvsHrvEKBYdBgVjZ0X1u64FmScJ 7vcpZhQp9E+sttP5GrBmoBy0WjXV7yg/lV3FybvQ1SHOKk5Ng+s/v07TMmtHnmpKLQnE Z4Cmh24GlJnp+pIiZIZoLmabfuqg9xuYHJiPKjF8EdvZIzWROU/OeD/bgRG6mTYHzW9f Pp9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@siemens.com header.s=fm1 header.b=CJBGn6O5; 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=siemens.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 123-20020a630181000000b004790f4d9ad2si3038771pgb.636.2023.02.03.07.00.08; Fri, 03 Feb 2023 07:00:21 -0800 (PST) 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=@siemens.com header.s=fm1 header.b=CJBGn6O5; 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=siemens.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232774AbjBCOwA (ORCPT + 99 others); Fri, 3 Feb 2023 09:52:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233652AbjBCOvs (ORCPT ); Fri, 3 Feb 2023 09:51:48 -0500 X-Greylist: delayed 61 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Fri, 03 Feb 2023 06:51:47 PST Received: from mta-65-227.siemens.flowmailer.net (mta-65-227.siemens.flowmailer.net [185.136.65.227]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A26F9EE14 for ; Fri, 3 Feb 2023 06:51:46 -0800 (PST) Received: by mta-65-227.siemens.flowmailer.net with ESMTPSA id 20230203145042fb6f5c09fa4e60e438 for ; Fri, 03 Feb 2023 15:50:42 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=fm1; d=siemens.com; i=daniel.starke@siemens.com; h=Date:From:Subject:To:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:Cc; bh=2NyostHau00yFANqCpLq5nifgI6rwhrmtoY/jfHx2Is=; b=CJBGn6O5tt+YtviI7Rqvp915HSd/PvX58OE1ttGShpokhNS4cP2PVb4h+VmzX8aoU49BxQ xj/mpKUdVwkhDxpAZesf4Ci8fcGZYn9wBk0KMrFjyGqTysO8pDQRVR/BKTrDs9BeOoLWAg7t 41VN7coSQdsxCGiw01BIdq6ZaNsfg=; From: "D. Starke" To: linux-serial@vger.kernel.org, gregkh@linuxfoundation.org, jirislaby@kernel.org, ilpo.jarvinen@linux.intel.com Cc: linux-kernel@vger.kernel.org, Daniel Starke Subject: [PATCH v3 1/4] tty: n_gsm: mark unusable ioctl structure fields accordingly Date: Fri, 3 Feb 2023 15:50:20 +0100 Message-Id: <20230203145023.6012-1-daniel.starke@siemens.com> MIME-Version: 1.0 X-Flowmailer-Platform: Siemens Feedback-ID: 519:519-314044:519-21489:flowmailer X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756822420916592559?= X-GMAIL-MSGID: =?utf-8?q?1756822420916592559?= From: Daniel Starke gsm_config and gsm_netconfig includes unused fields that have been included to allow future extension without changing the structure size. Unfortunately, no checks have been included for these field. The actual value set by old user space code remains undefined. This means that future extensions can not use these fields without breaking old user space code which may set unexpected values. Mark these fields accordingly to avoid breaking code changes. Signed-off-by: Daniel Starke --- include/uapi/linux/gsmmux.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) v2 -> v3: Split previous patch 1/3 into two commits as recommended in the review. No other changes. Link: https://lore.kernel.org/all/Y9vYxgGd6kC+ZIgR@kroah.com/ diff --git a/include/uapi/linux/gsmmux.h b/include/uapi/linux/gsmmux.h index cb8693b39cb7..785d6b253f6d 100644 --- a/include/uapi/linux/gsmmux.h +++ b/include/uapi/linux/gsmmux.h @@ -19,8 +19,7 @@ struct gsm_config unsigned int mtu; unsigned int k; unsigned int i; - unsigned int unused[8]; /* Padding for expansion without - breaking stuff */ + unsigned int unused[8]; /* Can not be used */ }; #define GSMIOC_GETCONF _IOR('G', 0, struct gsm_config) @@ -29,9 +28,9 @@ struct gsm_config struct gsm_netconfig { unsigned int adaption; /* Adaption to use in network mode */ unsigned short protocol;/* Protocol to use - only ETH_P_IP supported */ - unsigned short unused2; + unsigned short unused2; /* Can not be used */ char if_name[IFNAMSIZ]; /* interface name format string */ - __u8 unused[28]; /* For future use */ + __u8 unused[28]; /* Can not be used */ }; #define GSMIOC_ENABLE_NET _IOW('G', 2, struct gsm_netconfig) From patchwork Fri Feb 3 14:50:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "D. Starke" X-Patchwork-Id: 52547 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp883481wrn; Fri, 3 Feb 2023 06:59:19 -0800 (PST) X-Google-Smtp-Source: AK7set9DLUP9NclG/6aizNGScwTBSe5+FPd+Pr+w0Cb71y7gfebPw0v65u8M/CI+8uQXfw3gKpGY X-Received: by 2002:a17:90b:4b0f:b0:22c:5f7c:af28 with SMTP id lx15-20020a17090b4b0f00b0022c5f7caf28mr10634572pjb.14.1675436359620; Fri, 03 Feb 2023 06:59:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675436359; cv=none; d=google.com; s=arc-20160816; b=cmkIJGdt4T5Gh6JWvwQWE47QJakoF4AqXlfpssDBkNWOn6UPUNj0uH/pmkM7Tnk1iX SLnJI+RVFn79BzsidlZXClzKeDrxQtbziDo7maRMXLZ4PyicBcSTCuAbCZh+CDH9mU1D n4fFVo19pKO8O41fVLglFOeLoiMxO25DsgcrDQeYYzTp//wlWaxLIjYYbDI1MhVDX/AZ zEXJI6ObpLuOyee/0QNKuOFmJ69/rrzSn9R/U2qX3KubglExht3QTImEl7FeM44jsQvg u3u86oMoPZcg5fix4sE7ltuEzO6xYjNfR6bUJIRn+SfxEfsJKPwALDQFdBWr6Nz+1YGO JXDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:feedback-id:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=YpqeZ3byNbXItMkiEEwqaca7q2YfwgLJOyZrrrK7gLE=; b=h9kmGoo8DJasvvAABfhmu28fKGMDAzUWP2SfQEZF4wI3B8FDN78Z9iOUclGBHBM7b+ hta7XUTdk25mR4388Ax0qq5Bn1N0qgMsR0mtyltsnAqHEyjYxyskHvoASesbAo+B8Ay3 FqDz1v15nH8TDZxPPKYN8baDqbJV3IPtUpV4zNUmT6Ju8RwiycM7vwAOIk+DBvVlgG6e R6kjWuur+BwpI9P53Hd51iiuuTC2sxu1MY+Z84TSUjHBH4k3FyPvlUdwqL88KYDISYRz C78v06eRTx+PW32MpvUstoeIZGmk+ZfeUxSyfgUJvaWMMXYkO3fS1PsIFEgxj6LUP2h2 PA/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@siemens.com header.s=fm1 header.b=WQQVVQZn; 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=siemens.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n18-20020a638f12000000b004c697f2f109si3223765pgd.309.2023.02.03.06.59.07; Fri, 03 Feb 2023 06:59:19 -0800 (PST) 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=@siemens.com header.s=fm1 header.b=WQQVVQZn; 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=siemens.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233338AbjBCOuz (ORCPT + 99 others); Fri, 3 Feb 2023 09:50:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233037AbjBCOut (ORCPT ); Fri, 3 Feb 2023 09:50:49 -0500 Received: from mta-64-227.siemens.flowmailer.net (mta-64-227.siemens.flowmailer.net [185.136.64.227]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E01591187 for ; Fri, 3 Feb 2023 06:50:44 -0800 (PST) Received: by mta-64-227.siemens.flowmailer.net with ESMTPSA id 20230203145042e11562bacedb818edf for ; Fri, 03 Feb 2023 15:50:42 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=fm1; d=siemens.com; i=daniel.starke@siemens.com; h=Date:From:Subject:To:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:Cc:References:In-Reply-To; bh=YpqeZ3byNbXItMkiEEwqaca7q2YfwgLJOyZrrrK7gLE=; b=WQQVVQZnY5m0GrTrLW1FgS/cxhS+WTs/wGCTQZ5cSv/pViBDORuybBmRT7U0KcaEJF8zLA lMvTxiLwq6b3RUcfsHcu2tXQqIXvFK6P3YAihOib8rhFWnLnd3/ELwJZOQiudoN6+SHQFLK/ jV2OqnH2reFqhYrXYa31R+hrJk7jI=; From: "D. Starke" To: linux-serial@vger.kernel.org, gregkh@linuxfoundation.org, jirislaby@kernel.org, ilpo.jarvinen@linux.intel.com Cc: linux-kernel@vger.kernel.org, Daniel Starke Subject: [PATCH v3 2/4] tty: n_gsm: add keep alive support Date: Fri, 3 Feb 2023 15:50:21 +0100 Message-Id: <20230203145023.6012-2-daniel.starke@siemens.com> In-Reply-To: <20230203145023.6012-1-daniel.starke@siemens.com> References: <20230203145023.6012-1-daniel.starke@siemens.com> MIME-Version: 1.0 X-Flowmailer-Platform: Siemens Feedback-ID: 519:519-314044:519-21489:flowmailer X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756822355816582559?= X-GMAIL-MSGID: =?utf-8?q?1756822355816582559?= From: Daniel Starke 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 an 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 is being used to distinguish between multiple retries. Retry count and interval are taken from the general parameters N2 and T2. 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". Signed-off-by: Daniel Starke --- drivers/tty/n_gsm.c | 106 +++++++++++++++++++++++++++++++++++- include/uapi/linux/gsmmux.h | 10 ++++ 2 files changed, 114 insertions(+), 2 deletions(-) v2 -> v3: Split previous patch 1/3 into two commits as recommended in the review. No other changes. Link: https://lore.kernel.org/all/Y9vYxgGd6kC+ZIgR@kroah.com/ diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c index 5783801d6524..d068df1cf2fd 100644 --- a/drivers/tty/n_gsm.c +++ b/drivers/tty/n_gsm.c @@ -318,6 +318,11 @@ struct gsm_mux { struct gsm_control *pending_cmd;/* Our current pending command */ spinlock_t control_lock; /* Protects the pending command */ + /* Keep-alive */ + struct timer_list ka_timer; /* Keep-alive response timer */ + u8 ka_num; /* Keep-alive match pattern */ + int ka_retries; /* Keep-alive retry counter */ + /* Configuration */ int adaption; /* 1 or 2 supported */ u8 ftype; /* UI or UIH */ @@ -325,6 +330,7 @@ struct gsm_mux { unsigned int t3; /* Power wake-up timer in seconds. */ int n2; /* Retry count */ u8 k; /* Window size */ + u32 keep_alive; /* Control channel keep-alive in ms */ /* Statistics (not currently exposed) */ unsigned long bad_fcs; @@ -1897,11 +1903,13 @@ static void gsm_control_response(struct gsm_mux *gsm, unsigned int command, const u8 *data, int clen) { struct gsm_control *ctrl; + struct gsm_dlci *dlci; unsigned long flags; spin_lock_irqsave(&gsm->control_lock, flags); ctrl = gsm->pending_cmd; + dlci = gsm->dlci[0]; command |= 1; /* Does the reply match our command */ if (ctrl != NULL && (command == ctrl->cmd || command == CMD_NSC)) { @@ -1916,6 +1924,54 @@ static void gsm_control_response(struct gsm_mux *gsm, unsigned int command, /* Or did we receive the PN response to our PN command */ } else if (command == CMD_PN) { gsm_control_negotiation(gsm, 0, data, clen); + /* Or did we receive the TEST response to our TEST command */ + } else if (command == CMD_TEST && clen == 1 && *data == gsm->ka_num) { + gsm->ka_retries = -1; /* trigger new keep-alive message */ + if (dlci && !dlci->dead) + mod_timer(&gsm->ka_timer, + jiffies + gsm->keep_alive * HZ / 100); + } + spin_unlock_irqrestore(&gsm->control_lock, flags); +} + +/** + * gsm_control_keep_alive - check timeout or start keep-alive + * @t: timer contained in our gsm object + * + * Called off the keep-alive timer expiry signaling that our link + * partner is not responding anymore. Link will be closed. + * This is also called to startup our timer. + */ + +static void gsm_control_keep_alive(struct timer_list *t) +{ + struct gsm_mux *gsm = from_timer(gsm, t, ka_timer); + unsigned long flags; + + spin_lock_irqsave(&gsm->control_lock, flags); + if (gsm->ka_num && gsm->ka_retries == 0) { + /* Keep-alive expired -> close the link */ + if (debug & DBG_ERRORS) + pr_info("%s keep-alive timed out\n", __func__); + spin_unlock_irqrestore(&gsm->control_lock, flags); + if (gsm->dlci[0]) + gsm_dlci_begin_close(gsm->dlci[0]); + return; + } else if (gsm->keep_alive && gsm->dlci[0] && !gsm->dlci[0]->dead) { + if (gsm->ka_retries > 0) { + /* T2 expired for keep-alive -> resend */ + gsm->ka_retries--; + } else { + /* Start keep-alive timer */ + gsm->ka_num++; + if (!gsm->ka_num) + gsm->ka_num++; + gsm->ka_retries = gsm->n2; + } + gsm_control_command(gsm, CMD_TEST, &gsm->ka_num, + sizeof(gsm->ka_num)); + mod_timer(&gsm->ka_timer, + jiffies + gsm->t2 * HZ / 100); } spin_unlock_irqrestore(&gsm->control_lock, flags); } @@ -2061,8 +2117,10 @@ static void gsm_dlci_close(struct gsm_dlci *dlci) /* Ensure that gsmtty_open() can return. */ tty_port_set_initialized(&dlci->port, false); wake_up_interruptible(&dlci->port.open_wait); - } else + } else { + del_timer(&dlci->gsm->ka_timer); dlci->gsm->dead = true; + } /* A DLCI 0 close is a MUX termination so we need to kick that back to userspace somehow */ gsm_dlci_data_kick(dlci); @@ -2078,6 +2136,8 @@ static void gsm_dlci_close(struct gsm_dlci *dlci) static void gsm_dlci_open(struct gsm_dlci *dlci) { + struct gsm_mux *gsm = dlci->gsm; + /* Note that SABM UA .. SABM UA first UA lost can mean that we go open -> open */ del_timer(&dlci->t1); @@ -2087,8 +2147,15 @@ static void gsm_dlci_open(struct gsm_dlci *dlci) if (debug & DBG_ERRORS) pr_debug("DLCI %d goes open.\n", dlci->addr); /* Send current modem state */ - if (dlci->addr) + if (dlci->addr) { gsm_modem_update(dlci, 0); + } else { + /* Start keep-alive control */ + gsm->ka_num = 0; + gsm->ka_retries = -1; + mod_timer(&gsm->ka_timer, + jiffies + gsm->keep_alive * HZ / 100); + } gsm_dlci_data_kick(dlci); wake_up(&dlci->gsm->event); } @@ -2840,6 +2907,7 @@ static void gsm_cleanup_mux(struct gsm_mux *gsm, bool disc) /* Finish outstanding timers, making sure they are done */ del_timer_sync(&gsm->kick_timer); del_timer_sync(&gsm->t2_timer); + del_timer_sync(&gsm->ka_timer); /* Finish writing to ldisc */ flush_work(&gsm->tx_work); @@ -2987,6 +3055,7 @@ static struct gsm_mux *gsm_alloc_mux(void) INIT_LIST_HEAD(&gsm->tx_data_list); timer_setup(&gsm->kick_timer, gsm_kick_timer, 0); timer_setup(&gsm->t2_timer, gsm_control_retransmit, 0); + timer_setup(&gsm->ka_timer, gsm_control_keep_alive, 0); INIT_WORK(&gsm->tx_work, gsmld_write_task); init_waitqueue_head(&gsm->event); spin_lock_init(&gsm->control_lock); @@ -3003,6 +3072,7 @@ static struct gsm_mux *gsm_alloc_mux(void) gsm->mru = 64; /* Default to encoding 1 so these should be 64 */ gsm->mtu = 64; gsm->dead = true; /* Avoid early tty opens */ + gsm->keep_alive = 0; /* Disabled */ /* Store the instance to the mux array or abort if no space is * available. @@ -3138,6 +3208,28 @@ static int gsm_config(struct gsm_mux *gsm, struct gsm_config *c) return 0; } +static void gsm_copy_config_ext_values(struct gsm_mux *gsm, + struct gsm_config_ext *ce) +{ + memset(ce, 0, sizeof(*ce)); + ce->keep_alive = gsm->keep_alive; +} + +static int gsm_config_ext(struct gsm_mux *gsm, struct gsm_config_ext *ce) +{ + unsigned int i; + + gsm->keep_alive = ce->keep_alive; + /* + * Check that userspace doesn't put stuff in here to prevent breakages + * in the future. + */ + for (i = 0; i < ARRAY_SIZE(ce->reserved); i++) + if (ce->reserved[i]) + return -EINVAL; + return 0; +} + /** * gsmld_output - write to link * @gsm: our mux @@ -3456,6 +3548,7 @@ static int gsmld_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg) { struct gsm_config c; + struct gsm_config_ext ce; struct gsm_mux *gsm = tty->disc_data; unsigned int base; @@ -3472,6 +3565,15 @@ static int gsmld_ioctl(struct tty_struct *tty, unsigned int cmd, case GSMIOC_GETFIRST: base = mux_num_to_base(gsm); return put_user(base + 1, (__u32 __user *)arg); + case GSMIOC_GETCONF_EXT: + gsm_copy_config_ext_values(gsm, &ce); + if (copy_to_user((void __user *)arg, &ce, sizeof(ce))) + return -EFAULT; + return 0; + case GSMIOC_SETCONF_EXT: + if (copy_from_user(&ce, (void __user *)arg, sizeof(ce))) + return -EFAULT; + return gsm_config_ext(gsm, &ce); default: return n_tty_ioctl_helper(tty, cmd, arg); } diff --git a/include/uapi/linux/gsmmux.h b/include/uapi/linux/gsmmux.h index 785d6b253f6d..98de2570d79b 100644 --- a/include/uapi/linux/gsmmux.h +++ b/include/uapi/linux/gsmmux.h @@ -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 */ +}; + +#define GSMIOC_GETCONF_EXT _IOR('G', 5, struct gsm_config_ext) +#define GSMIOC_SETCONF_EXT _IOW('G', 6, struct gsm_config_ext) + #endif From patchwork Fri Feb 3 14:50:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "D. Starke" X-Patchwork-Id: 52546 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp883112wrn; Fri, 3 Feb 2023 06:58:29 -0800 (PST) X-Google-Smtp-Source: AK7set9dSCenyfANrW/D26ujG2j5J8ZR9Wubh5Xz9GgoytiF26PWqXqT8cRrrL7dod9UkCbNXT6n X-Received: by 2002:a17:903:1110:b0:196:2124:c590 with SMTP id n16-20020a170903111000b001962124c590mr5132157plh.33.1675436309414; Fri, 03 Feb 2023 06:58:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675436309; cv=none; d=google.com; s=arc-20160816; b=yWGX69DHfW5wa72rE+hxI8yCbuWFmHImYha9dSvuqFf5wY6zid7pwZ6QSCVZoKi+7b zIfriNZqSMHncNK7x9IaREaSkPIi6kcy7pqc8R54WPL4p1+275+2cWYJ4OQWr3iKu92M eTdmE+F68B22bo2nRoSTMob2I8tL3yhNx5AQL8fYF72TeyIRaJpwvaZO9BKjab2h5yuB jbGpxDz90QYAR3RRIih726+BoLEMlgDe1PEwdXLWhb2sy5MIHW62e1Noma4i1DBco6Io aDoCWVvLnr5kw+g/M1LysB+ziaH1P/R5PY+Pk39WZLgC7pUiOAl/nOe4uO9AMrLME66u BI6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:feedback-id:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=+nOvG2X3HLgF03w2fTPt3ooPfqHvAZ6ZsfqKleubf/o=; b=ZGEss1I0D8VPCt5HICeDfQNiKMLR94VnvxKdDxVpA6v7noN9XzNwjF0N6tz6a78915 CatTO3Awu6z9uU4pQZMKV91yHXFwj4Th7fHZdZs6HW6AvZV4PKNsS6xbfZFWqEctkr8M gCZuaQtWGqza8dNLVC8mi0okkMaWdL1Fd3GJhMCEzrUzqvFP4fw+fVRZ7FYbOkSgvK65 NbjX1w3kysNCLR2SEprRpfypKbC2SIr17R50zCrNmld8znLfVuPjOTOfVDez3DyFzgOy V/f55kH4I+Nm7ccGOfWUoRRvKm3j9UoegF+E/FJQI1K+axivUdq6rqYTTfPsj8Bj2aPq opZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@siemens.com header.s=fm1 header.b=MSAb0Qsd; 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=siemens.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y21-20020a1709027c9500b001933989d4f8si2280264pll.344.2023.02.03.06.58.16; Fri, 03 Feb 2023 06:58:29 -0800 (PST) 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=@siemens.com header.s=fm1 header.b=MSAb0Qsd; 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=siemens.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232959AbjBCOut (ORCPT + 99 others); Fri, 3 Feb 2023 09:50:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32868 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232611AbjBCOur (ORCPT ); Fri, 3 Feb 2023 09:50:47 -0500 Received: from mta-64-226.siemens.flowmailer.net (mta-64-226.siemens.flowmailer.net [185.136.64.226]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4DCC68F249 for ; Fri, 3 Feb 2023 06:50:44 -0800 (PST) Received: by mta-64-226.siemens.flowmailer.net with ESMTPSA id 20230203145042fe7659cbb89a805056 for ; Fri, 03 Feb 2023 15:50:43 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=fm1; d=siemens.com; i=daniel.starke@siemens.com; h=Date:From:Subject:To:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:Cc:References:In-Reply-To; bh=+nOvG2X3HLgF03w2fTPt3ooPfqHvAZ6ZsfqKleubf/o=; b=MSAb0QsdUJ/AWk9AaXt1zcoinF/++j29BUvdzRbtjI4GwNUBVaMDiNC1vBi1tNZuwvxgtH IqHAkhUURQjKAPPXif0ppEThsEQRbOfgUPadng0EwKW/sod2Jt+/PAkv5W7kFVndmfXoP44F 9hnGufJ2qIhBof5tihYoIIkLSUBNY=; From: "D. Starke" To: linux-serial@vger.kernel.org, gregkh@linuxfoundation.org, jirislaby@kernel.org, ilpo.jarvinen@linux.intel.com Cc: linux-kernel@vger.kernel.org, Daniel Starke Subject: [PATCH v3 3/4] tty: n_gsm: add RING/CD control support Date: Fri, 3 Feb 2023 15:50:22 +0100 Message-Id: <20230203145023.6012-3-daniel.starke@siemens.com> In-Reply-To: <20230203145023.6012-1-daniel.starke@siemens.com> References: <20230203145023.6012-1-daniel.starke@siemens.com> MIME-Version: 1.0 X-Flowmailer-Platform: Siemens Feedback-ID: 519:519-314044:519-21489:flowmailer X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756822303235173576?= X-GMAIL-MSGID: =?utf-8?q?1756822303235173576?= From: Daniel Starke The status lines ring and carrier detect are used by the modem to signal incoming calls (RING) or an established connection (CD). This is implemented as physical lines on a standard RS232 connection. However, the muxer protocol encodes these status lines as modem bits IC and DV. These incoming lines are masked by tty driver (see tty_io.c) and cannot be set by a user application. Allow setting RING via TIOCM_OUT1 and CD via TIOCM_OUT2 to allow implementation of a modem or modem emulator. Signed-off-by: Daniel Starke --- drivers/tty/n_gsm.c | 5 +++++ 1 file changed, 5 insertions(+) v2 -> v3: No changes. diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c index d068df1cf2fd..cf1ab7d619d9 100644 --- a/drivers/tty/n_gsm.c +++ b/drivers/tty/n_gsm.c @@ -546,6 +546,11 @@ static u8 gsm_encode_modem(const struct gsm_dlci *dlci) modembits |= MDM_IC; if (dlci->modem_tx & TIOCM_CD || dlci->gsm->initiator) modembits |= MDM_DV; + /* special mappings for passive side to operate as UE */ + if (dlci->modem_tx & TIOCM_OUT1) + modembits |= MDM_IC; + if (dlci->modem_tx & TIOCM_OUT2) + modembits |= MDM_DV; return modembits; } From patchwork Fri Feb 3 14:50:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "D. Starke" X-Patchwork-Id: 52545 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp883025wrn; Fri, 3 Feb 2023 06:58:18 -0800 (PST) X-Google-Smtp-Source: AK7set+YiUOxN7gKNBq264Fw5mZ6i/EODm6VpY4wU7AYP1KojysPwvzXfHSqc+0T0QXmGl6luS9u X-Received: by 2002:a05:6a20:7d87:b0:bc:e1ce:605d with SMTP id v7-20020a056a207d8700b000bce1ce605dmr15704340pzj.20.1675436298673; Fri, 03 Feb 2023 06:58:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675436298; cv=none; d=google.com; s=arc-20160816; b=XeREfRhY8f7DvAebRIzM5kPLcJBF/eqP0sy6WyTv4VFJlUKTj4vDIdJQchPeX5ocpJ 3D1ErVV3RVwayuA5gGCUUATssaw4ZuR8OMsEnLxFpMlLVXn9XaaE6WxAP10IUnoA1a5i Svj613mDsNB+BMFxnaf5ZcddDxj7OMkOQ59lI+cWrLhlOrdeIJCdcu590uaYsTTFDjnG lj8oGYEV0XgT5MygmGNj9f4Kn1BqBXhO39wgDr/Mdr3VBQt1MpJEZ2+znU4AYtOaFK5a SCNZ5AYRCRYjlTmNFyX+r9jrnf7P8+1vgzI0TxbDYK13FZm2p9mU+3JRkaiGue7AQxab nD6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:feedback-id:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=soWeu6gkV3NEcYNRrfIYl154ZKDvANaWKtl+GG89qaE=; b=aU3Sn2iV76BWZ0jBIlreBwxh1HMBLZmxoa4IUteEhV8jR3OxqaB+r3RUHWqPIn31HR qSglC8xAbNZKz0VNFIsLndef0isYeQ52wEWHBisK0goDWiyiBGIvuwhJF8ej2JMqIiIW SV5kI57NlUOxkCE9zVu5hEglZ1gqxGA+XhpdR70Gxh6OswwSXoAdKFxOKdDFm1vIJSo1 GJqbaW3ScaJKCkzT1XXcz5iFipfZKIwc9pxLxFza5J5SH3qbWOWCtiK58aJR6NIbVZGX iv2FB5e/yi8+sM/2JCtyitABmeWtNBDOb6/+oKqk/psGxb+dVO5A1U7dD5mKoeYci/gY 2hmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@siemens.com header.s=fm1 header.b=Zoq+elDa; 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=siemens.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d29-20020a63735d000000b004e07c92165bsi3096296pgn.240.2023.02.03.06.58.06; Fri, 03 Feb 2023 06:58:18 -0800 (PST) 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=@siemens.com header.s=fm1 header.b=Zoq+elDa; 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=siemens.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233282AbjBCOux (ORCPT + 99 others); Fri, 3 Feb 2023 09:50:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232637AbjBCOus (ORCPT ); Fri, 3 Feb 2023 09:50:48 -0500 Received: from mta-65-225.siemens.flowmailer.net (mta-65-225.siemens.flowmailer.net [185.136.65.225]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4DBA573058 for ; Fri, 3 Feb 2023 06:50:45 -0800 (PST) Received: by mta-65-225.siemens.flowmailer.net with ESMTPSA id 20230203145043e8dbe453e4aaf29f1c for ; Fri, 03 Feb 2023 15:50:43 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=fm1; d=siemens.com; i=daniel.starke@siemens.com; h=Date:From:Subject:To:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:Cc:References:In-Reply-To; bh=soWeu6gkV3NEcYNRrfIYl154ZKDvANaWKtl+GG89qaE=; b=Zoq+elDa54uNPWIqcLTvhC6h8SEmYAp7+CC2tc+BukBRK8JfKgI6Lc6sKWeADUWMCy979s mK2dnRwPYk5zS953sx2RfMHa+lhFKXzeRrj/cbjY7ymzsk84F7gMo3+IejoLYtCOI1CJ/e/l k/v9BOA0ogvP2xpqH6oJyjLHgPsIs=; From: "D. Starke" To: linux-serial@vger.kernel.org, gregkh@linuxfoundation.org, jirislaby@kernel.org, ilpo.jarvinen@linux.intel.com Cc: linux-kernel@vger.kernel.org, Daniel Starke Subject: [PATCH v3 4/4] tty: n_gsm: add TIOCMIWAIT support Date: Fri, 3 Feb 2023 15:50:23 +0100 Message-Id: <20230203145023.6012-4-daniel.starke@siemens.com> In-Reply-To: <20230203145023.6012-1-daniel.starke@siemens.com> References: <20230203145023.6012-1-daniel.starke@siemens.com> MIME-Version: 1.0 X-Flowmailer-Platform: Siemens Feedback-ID: 519:519-314044:519-21489:flowmailer X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756822292243125379?= X-GMAIL-MSGID: =?utf-8?q?1756822292243125379?= From: Daniel Starke Add support for the TIOCMIWAIT ioctl on the virtual ttys. This enables the user to wait for virtual modem signals like RING. More work is needed to support also TIOCGICOUNT. Signed-off-by: Daniel Starke --- drivers/tty/n_gsm.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) v2 -> v3: Added appropriate cast of arg in gsm_wait_modem_change() call as remarked in the review. No other changes. Link: https://lore.kernel.org/all/Y9vZOsAuzKjBNArJ@kroah.com/ diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c index cf1ab7d619d9..aa3488280f1b 100644 --- a/drivers/tty/n_gsm.c +++ b/drivers/tty/n_gsm.c @@ -1542,6 +1542,7 @@ static void gsm_process_modem(struct tty_struct *tty, struct gsm_dlci *dlci, if (brk & 0x01) tty_insert_flip_char(&dlci->port, 0, TTY_BREAK); dlci->modem_rx = mlines; + wake_up_interruptible(&dlci->gsm->event); } /** @@ -2129,7 +2130,7 @@ static void gsm_dlci_close(struct gsm_dlci *dlci) /* A DLCI 0 close is a MUX termination so we need to kick that back to userspace somehow */ gsm_dlci_data_kick(dlci); - wake_up(&dlci->gsm->event); + wake_up_all(&dlci->gsm->event); } /** @@ -2339,6 +2340,7 @@ static void gsm_dlci_begin_close(struct gsm_dlci *dlci) dlci->state = DLCI_CLOSING; gsm_command(dlci->gsm, dlci->addr, DISC|PF); mod_timer(&dlci->t1, jiffies + gsm->t1 * HZ / 100); + wake_up_interruptible(&gsm->event); } /** @@ -3877,6 +3879,33 @@ static int gsm_modem_update(struct gsm_dlci *dlci, u8 brk) return -EPROTONOSUPPORT; } +/** + * gsm_wait_modem_change - wait for modem status line change + * @dlci: channel + * @mask: modem status line bits + * + * The function returns if: + * - any given modem status line bit changed + * - the wait event function got interrupted (e.g. by a signal) + * - the underlying DLCI was closed + * - the underlying ldisc device was removed + */ +static int gsm_wait_modem_change(struct gsm_dlci *dlci, u32 mask) +{ + struct gsm_mux *gsm = dlci->gsm; + u32 old = dlci->modem_rx; + int ret; + + ret = wait_event_interruptible(gsm->event, gsm->dead || + dlci->state != DLCI_OPEN || + (old ^ dlci->modem_rx) & mask); + if (gsm->dead) + return -ENODEV; + if (dlci->state != DLCI_OPEN) + return -EL2NSYNC; + return ret; +} + static bool gsm_carrier_raised(struct tty_port *port) { struct gsm_dlci *dlci = container_of(port, struct gsm_dlci, port); @@ -4136,6 +4165,8 @@ static int gsmtty_ioctl(struct tty_struct *tty, gsm_destroy_network(dlci); mutex_unlock(&dlci->mutex); return 0; + case TIOCMIWAIT: + return gsm_wait_modem_change(dlci, (u32)arg); default: return -ENOIOCTLCMD; }