From nobody Tue Feb 10 10:19:01 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500541556875955.007733501862; Thu, 20 Jul 2017 02:05:56 -0700 (PDT) Received: from localhost ([::1]:36786 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dY7P8-00080E-7O for importer@patchew.org; Thu, 20 Jul 2017 05:05:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44368) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dY7N9-0006Me-Gi for qemu-devel@nongnu.org; Thu, 20 Jul 2017 05:03:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dY7N8-0004Pn-KM for qemu-devel@nongnu.org; Thu, 20 Jul 2017 05:03:51 -0400 Received: from manul.sfritsch.de ([2a01:4f8:172:195f:112::2]:36996) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dY7N8-0004PI-F1 for qemu-devel@nongnu.org; Thu, 20 Jul 2017 05:03:50 -0400 From: Stefan Fritsch To: Gerd Hoffmann , qemu-devel@nongnu.org Date: Thu, 20 Jul 2017 11:02:45 +0200 Message-Id: <1500541371-24788-3-git-send-email-sf@sfritsch.de> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1500541371-24788-1-git-send-email-sf@sfritsch.de> References: <1500541371-24788-1-git-send-email-sf@sfritsch.de> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a01:4f8:172:195f:112::2 Subject: [Qemu-devel] [PATCH v2 2/8] usb-ccid: Fix USB packet generation for 64-Bytes sized packets. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Stefan Fritsch An USB transfer must be terminated by a packet that is shorter than the maximum USB packet size (usually 64Byte) reported by the device in its descriptor(s). Thus if the last packet of a transfer is exactly 64-Bytes long, we must send an additional zero length packet. Fix this for bulk in transfers. For bulk out transfers this is already ok, for interrupt transfers this is not a problem as the pipe has a maximum packet size of 8 and transfers are only two bytes long. Signed-off-by: Stefan Fritsch Signed-off-by: Christian Ehrhardt --- hw/usb/dev-smartcard-reader.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/hw/usb/dev-smartcard-reader.c b/hw/usb/dev-smartcard-reader.c index 624dc2c447..49791492ea 100644 --- a/hw/usb/dev-smartcard-reader.c +++ b/hw/usb/dev-smartcard-reader.c @@ -1124,7 +1124,13 @@ static void ccid_bulk_in_copy_to_guest(USBCCIDState = *s, USBPacket *p) s->current_bulk_in->data + s->current_bulk_in->pos, len); s->current_bulk_in->pos +=3D len; - if (s->current_bulk_in->pos =3D=3D s->current_bulk_in->len) { + /* + * The caller assumes that the packet continues if we fill the + * entire iov and the iov length matches the max packet size. + * Add an empty USB packet in this case. + */ + if (s->current_bulk_in->pos =3D=3D s->current_bulk_in->len + && (len < p->iov.size || p->iov.size < CCID_MAX_PACKET_SIZE)) { ccid_bulk_in_release(s); } } else { --=20 2.11.0