Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp160094pxb; Thu, 17 Feb 2022 00:51:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJwiNWHdkolysW74dk8iBtKFPSZ3V9PhaeD19UGYjeLePqBiE5mXPby523ebSklNBU2UpH6D X-Received: by 2002:a17:906:86c7:b0:6a8:49fa:a3f5 with SMTP id j7-20020a17090686c700b006a849faa3f5mr1497959ejy.421.1645087865038; Thu, 17 Feb 2022 00:51:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645087865; cv=none; d=google.com; s=arc-20160816; b=ul4znf9al/lEYSaIpe+uCx9CTinPM7z2sfKWLvebj3TYlU776noQwJp5Tnua/IRpil rONlnPOYmxfJfAHPwr38HJwBW1/dkaE3pPMPK+rT/m0ayoL6rNgYvweY4AaDhAp/4dbY FLBHi5ZAyAT0qgEsD2GlffMO89kHBvAE884Mds6yFqYgpJlllHjuWk76ZGwBf0KHOoqx fzko5ge+o7Nf/yzrwVXdq1kA+LSxUFPwjtix7oC2ifRA4t1/fhFlSdYQ4ATcWjlqq9Z/ Ce7+WpKOaAh0nXFTrkSXHh/sOVZmeVrllf2GnfH0TSvSMNqMsUpqDaVnyeU/nGm/JVq/ x7UA== 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=F+BlRq60XbUp67HLkZ4sGGjzRXyVOCRM3ka7rW5wSAU=; b=ivoGR2clKSpj59P9ow+uMTmwdiDALDAyv33ES+2dKr616MzCqHp8BsppYkEXayxtEL gyIyptVHe0zjeUI1Z6tHmu4EjFZyAyeJgH/z99wTSWo0SUW57qntmcc95/khkA9lnGzk yCRkjzh1E8QUJjd4iUpH1QTcbUpBbpZpEfcNyWG9c53UlGgneDaym9ADk9HU4WGnBI1e Xs2SuqTtaDwFTxI5Pa3m/jgRMqSFFVlgz2b3wDyOv9xtxSIks65zPrJZUON6V8U1L8r4 SZdx6Fjntfphnmb4BP7O+YuDvBmeFlvPgUXw0NhT77ogLCRdrtFueymdsSKmLBo28Kzl N6BA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@siemens.com header.s=fm1 header.b=ZO10HjJo; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ca3si2487678edb.135.2022.02.17.00.50.41; Thu, 17 Feb 2022 00:51:05 -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=ZO10HjJo; 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 S237117AbiBQIHX (ORCPT + 99 others); Thu, 17 Feb 2022 03:07:23 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:45256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236433AbiBQIHQ (ORCPT ); Thu, 17 Feb 2022 03:07:16 -0500 X-Greylist: delayed 62 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Thu, 17 Feb 2022 00:07:02 PST Received: from mta-65-228.siemens.flowmailer.net (mta-65-228.siemens.flowmailer.net [185.136.65.228]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B464527DF3C for ; Thu, 17 Feb 2022 00:07:02 -0800 (PST) Received: by mta-65-228.siemens.flowmailer.net with ESMTPSA id 20220217080557ca41ad077441f459a7 for ; Thu, 17 Feb 2022 09:05:58 +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=F+BlRq60XbUp67HLkZ4sGGjzRXyVOCRM3ka7rW5wSAU=; b=ZO10HjJooR03WNL9aiBSwYoD9qjYk2bhZXBogRMnsduAAJ3bW45nbx4rpxGL9Z3Fhb1YkG 0OCelm4G77UzZYfWshGi9QEavc6NXelCutn0dErL70V+bM0SSyabCz2pW9JOJtyKHuZvHFEL KP1mLqUAxYViyp1iA7+aiguF7L+ok=; From: daniel.starke@siemens.com To: linux-serial@vger.kernel.org, gregkh@linuxfoundation.org, jirislaby@kernel.org Cc: linux-kernel@vger.kernel.org, Daniel Starke Subject: [PATCH 1/1] tty: n_gsm: fix encoding of command/response bit Date: Thu, 17 Feb 2022 00:05:50 -0800 Message-Id: <20220217080555.5387-2-daniel.starke@siemens.com> In-Reply-To: <20220217080555.5387-1-daniel.starke@siemens.com> References: <20220217080555.5387-1-daniel.starke@siemens.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Flowmailer-Platform: Siemens Feedback-ID: 519:519-7517:519-21489:flowmailer X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS, 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 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 --- drivers/tty/n_gsm.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c index 0b1808e3a912..c012733e0402 100644 --- a/drivers/tty/n_gsm.c +++ b/drivers/tty/n_gsm.c @@ -448,7 +448,7 @@ static u8 gsm_encode_modem(const struct gsm_dlci *dlci) * 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 *input, u8 *output, int len) * 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 addr, int cr, int control) 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, int addr, int cr, int control) 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, int addr, int cr, int control) 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 *gsm) 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) { -- 2.25.1