Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp3115128pxm; Mon, 28 Feb 2022 12:19:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJx+vkyeGgwkQYG1V9C0GzbU9wWcVhdpva09B2sW07ne6JqXfHouvsNzqjkJzofeaymkinEH X-Received: by 2002:a17:902:8ec9:b0:14f:11f7:db77 with SMTP id x9-20020a1709028ec900b0014f11f7db77mr21792787plo.136.1646079597833; Mon, 28 Feb 2022 12:19:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646079597; cv=none; d=google.com; s=arc-20160816; b=pOYQmIHLOQBXN/qMCOgjywHYK2L3AR0+SpIuMIP7FGErhK4Cb0AxfgustsxmanBL0Z X4VwXvvC5qAYeJGCdhDkU4JwWCadnejSH7VheSYHzwt1UgdbSSFYHgnn66/FI5Z6aA+n 1oNkgwGti9RCqv9PzoGUWUCbH1OxrjENrykfkn8LyPDP2VfiSGd/7bCHywyEIbXuEC7z Mbjjfat0tI/mHmylBc/m68elRS5St//RH5q4LrAcf8ldSA64FbrWTvb76Ao385uduaoT HQxql5H7OXwhbrU/UfZZtqoazBBZ1gVEzSQJkNIOvx06gOpbqZeKwHl1xJVjO3dZhr47 LRjA== 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=j4mTPC21PJP9Ae1kBuTO9/6reOE4BF8wHhAxkuHMj9E=; b=w5TZPxXifbMAIMTallxNzebSt06ZYLTvezurA3fxDljeBHp+q8ZpQh3N9HJYdtG8Ob XrABlrajASggYda5B1MWCVpx2k9goYhCIWJANI6C8uUia+MuAS/qYyQumJ+zf1DEjnkM SRKbsCvtY9sKk2+nCSBIExAQ08HFXDjm4hcxsTVkTGqWGMSuOLcH9Kcjj9GrChFGoe27 sCefpKS+Vvup9EtWFD3Ss/UBul9hsgnvrNeVd29tk8bWSqwCiB2utbCk+O5hP36FHFem Y4BAJsSIWxcPWHqUS0MkIB1gmlwyJzfiAuSOC2QyokbZXriDWOaFZtLaHA48NCrTbS6e +R9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=jqSs40a0; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id g22-20020a632016000000b003759840bbc3si10267561pgg.67.2022.02.28.12.19.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Feb 2022 12:19:57 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=jqSs40a0; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 36C6F6C1FD; Mon, 28 Feb 2022 11:39:26 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240224AbiB1SNV (ORCPT + 99 others); Mon, 28 Feb 2022 13:13:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241075AbiB1SJ2 (ORCPT ); Mon, 28 Feb 2022 13:09:28 -0500 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67DC3654A5; Mon, 28 Feb 2022 09:49:29 -0800 (PST) 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 sin.source.kernel.org (Postfix) with ESMTPS id 98BF7CE17C5; Mon, 28 Feb 2022 17:49:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 99E89C340E7; Mon, 28 Feb 2022 17:49:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1646070562; bh=bJSGxrSyQRTjpkVIFjYm5UpZ5rWG34BAus4iU+AtDNc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jqSs40a0gcx/PpD6Cp1ugZNqn32WkVYMUv1r6hhbWqDfrDL4nVSja8bWxePyoPwq6 r1ldYHwJlqcLwIpw0y44UVDx55sIy/q4Du6CCJIkis/ZRjB3iojnvG2Yw/hxroeuOk Cmwnb8f7zkt7fw6UL4QgkyaR0M7t5jMT7h1OkoJc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Daniel Starke Subject: [PATCH 5.16 155/164] tty: n_gsm: fix encoding of command/response bit Date: Mon, 28 Feb 2022 18:25:17 +0100 Message-Id: <20220228172413.797509155@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220228172359.567256961@linuxfoundation.org> References: <20220228172359.567256961@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=-2.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE 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 From: daniel.starke@siemens.com commit 57435c42400ec147a527b2313188b649e81e449e 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.2.1.2 describes the encoding of the C/R (command/response) bit. Table 1 shows that the actual encoding of the C/R bit is inverted if the associated frame is sent by the responder. The referenced commit fixed here further broke the internal meaning of this bit in the outgoing path by always setting the C/R bit regardless of the frame type. This patch fixes both by setting the C/R bit always consistently for command (1) and response (0) frames and inverting it later for the responder where necessary. The meaning of this bit in the debug output is being preserved and shows the bit as if it was encoded by the initiator. This reflects only the frame type rather than the encoded combination of communication side and frame type. Fixes: cc0f42122a7e ("tty: n_gsm: Modify CR,PF bit when config requester") Cc: stable@vger.kernel.org Signed-off-by: Daniel Starke Link: https://lore.kernel.org/r/20220218073123.2121-2-daniel.starke@siemens.com Signed-off-by: Greg Kroah-Hartman --- drivers/tty/n_gsm.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) --- a/drivers/tty/n_gsm.c +++ b/drivers/tty/n_gsm.c @@ -448,7 +448,7 @@ static u8 gsm_encode_modem(const struct * gsm_print_packet - display a frame for debug * @hdr: header to print before decode * @addr: address EA from the frame - * @cr: C/R bit from the frame + * @cr: C/R bit seen as initiator * @control: control including PF bit * @data: following data bytes * @dlen: length of data @@ -548,7 +548,7 @@ static int gsm_stuff_frame(const u8 *inp * gsm_send - send a control frame * @gsm: our GSM mux * @addr: address for control frame - * @cr: command/response bit + * @cr: command/response bit seen as initiator * @control: control byte including PF bit * * Format up and transmit a control frame. These do not go via the @@ -563,11 +563,15 @@ static void gsm_send(struct gsm_mux *gsm int len; u8 cbuf[10]; u8 ibuf[3]; + int ocr; + + /* toggle C/R coding if not initiator */ + ocr = cr ^ (gsm->initiator ? 0 : 1); switch (gsm->encoding) { case 0: cbuf[0] = GSM0_SOF; - cbuf[1] = (addr << 2) | (cr << 1) | EA; + cbuf[1] = (addr << 2) | (ocr << 1) | EA; cbuf[2] = control; cbuf[3] = EA; /* Length of data = 0 */ cbuf[4] = 0xFF - gsm_fcs_add_block(INIT_FCS, cbuf + 1, 3); @@ -577,7 +581,7 @@ static void gsm_send(struct gsm_mux *gsm case 1: case 2: /* Control frame + packing (but not frame stuffing) in mode 1 */ - ibuf[0] = (addr << 2) | (cr << 1) | EA; + ibuf[0] = (addr << 2) | (ocr << 1) | EA; ibuf[1] = control; ibuf[2] = 0xFF - gsm_fcs_add_block(INIT_FCS, ibuf, 2); /* Stuffing may double the size worst case */ @@ -611,7 +615,7 @@ static void gsm_send(struct gsm_mux *gsm static inline void gsm_response(struct gsm_mux *gsm, int addr, int control) { - gsm_send(gsm, addr, 1, control); + gsm_send(gsm, addr, 0, control); } /** @@ -1800,10 +1804,10 @@ static void gsm_queue(struct gsm_mux *gs goto invalid; cr = gsm->address & 1; /* C/R bit */ + cr ^= gsm->initiator ? 0 : 1; /* Flip so 1 always means command */ gsm_print_packet("<--", address, cr, gsm->control, gsm->buf, gsm->len); - cr ^= 1 - gsm->initiator; /* Flip so 1 always means command */ dlci = gsm->dlci[address]; switch (gsm->control) {