From nobody Sat May 18 20:15:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1678755623484269.5696534128431; Mon, 13 Mar 2023 18:00:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pbt15-0007am-Ew; Mon, 13 Mar 2023 20:59:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pbt11-0007ZZ-1b for qemu-devel@nongnu.org; Mon, 13 Mar 2023 20:59:47 -0400 Received: from a.mx.secunet.com ([62.96.220.36]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pbt0y-0006OG-Pl for qemu-devel@nongnu.org; Mon, 13 Mar 2023 20:59:46 -0400 Received: from localhost (localhost [127.0.0.1]) by a.mx.secunet.com (Postfix) with ESMTP id AFA75204D9; Tue, 14 Mar 2023 01:59:29 +0100 (CET) Received: from a.mx.secunet.com ([127.0.0.1]) by localhost (a.mx.secunet.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id bwXshtAfn3FC; Tue, 14 Mar 2023 01:59:29 +0100 (CET) Received: from mailout1.secunet.com (mailout1.secunet.com [62.96.220.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by a.mx.secunet.com (Postfix) with ESMTPS id 0ADB6201E5; Tue, 14 Mar 2023 01:59:29 +0100 (CET) Received: from cas-essen-01.secunet.de (unknown [10.53.40.201]) by mailout1.secunet.com (Postfix) with ESMTP id EE0F080004A; Tue, 14 Mar 2023 01:59:28 +0100 (CET) Received: from mbx-dresden-01.secunet.de (10.53.40.199) by cas-essen-01.secunet.de (10.53.40.201) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.17; Tue, 14 Mar 2023 01:59:13 +0100 Received: from mbx-essen-01.secunet.de (10.53.40.197) by mbx-dresden-01.secunet.de (10.53.40.199) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.17; Tue, 14 Mar 2023 01:59:12 +0100 Received: from mbx-essen-01.secunet.de ([fe80::1522:bd4f:78cd:ce75]) by mbx-essen-01.secunet.de ([fe80::1522:bd4f:78cd:ce75%6]) with mapi id 15.01.2507.017; Tue, 14 Mar 2023 01:59:12 +0100 X-Virus-Scanned: by secunet From: "Ripke, Klaus" To: "qemu-devel@nongnu.org" CC: "marcandre.lureau@gmail.com" Subject: [PATCH] add option for a multislot usb ccid device Thread-Topic: [PATCH] add option for a multislot usb ccid device Thread-Index: AQHZVhAwgQmWQS0+GkKFtMf4gc7B6g== Date: Tue, 14 Mar 2023 00:59:12 +0000 Message-ID: Accept-Language: de-DE, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: Content-Type: text/plain; charset="utf-8" Content-ID: <4848381555A3304DB25C547659838480@secunet.com> Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: 2c86f778-e09b-4440-8b15-867914633a10 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=62.96.220.36; envelope-from=klaus.ripke@secunet.com; helo=a.mx.secunet.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1678755625612100003 Signed-off-by: Klaus Ripke hw/usb/dev-smartcard-reader.c: add multi option for a multislot smartcard reader, similar to audio multi --- hw/usb/dev-smartcard-reader.c | 106 +++++++++++++++++++++++++++++++++- 1 file changed, 103 insertions(+), 3 deletions(-) diff --git a/hw/usb/dev-smartcard-reader.c b/hw/usb/dev-smartcard- reader.c index be0a4fc3bc..b0063b669e 100644 --- a/hw/usb/dev-smartcard-reader.c +++ b/hw/usb/dev-smartcard-reader.c @@ -90,10 +90,13 @@ OBJECT_DECLARE_SIMPLE_TYPE(USBCCIDState, USB_CCID_DEV) * usbccid.sys (winxp, others untested) is a class driver so it doesn't care. * linux has a number of class drivers, but openct filters based on * vendor/product (/etc/openct.conf under fedora), hence Gemplus. + * Use a Omnikey/HID 3121 with multislot for distinction. */ #define CCID_VENDOR_ID 0x08e6 #define CCID_PRODUCT_ID 0x4433 #define CCID_DEVICE_VERSION 0x0000 +#define CCID_VENDOR_ID_MULTI 0x076b +#define CCID_PRODUCT_ID_MULTI 0x3021 =20 /* * BULK_OUT messages from PC to Reader @@ -312,7 +315,9 @@ struct USBCCIDState { uint8_t bmSlotICCState; uint8_t powered; uint8_t notify_slot_change; + /* properties */ uint8_t debug; + bool multi; }; =20 /* @@ -411,6 +416,34 @@ static const uint8_t qemu_ccid_descriptor[] =3D { 0x01, /* u8 bMaxCCIDBusySlots; */ }; =20 +static const uint8_t qemu_ccid_descriptor_multi[] =3D { + /* Smart Card Device Class Descriptor */ + 0x36, /* u8 bLength; */ + 0x21, /* u8 bDescriptorType; Functional */ + 0x10, 0x01, /* u16 bcdCCID; CCID Specification Release Number. */ + 0x0e, /* u8 bMaxSlotIndex; 14, as 16 slots can cause trouble. */ + 0x07, /* u8 bVoltageSupport; 01h - 5.0v, 02h - 3.0, 03 - 1.8 */ + + 0x01, 0x00, /* u32 dwProtocols; RRRR PPPP. RRRR =3D 0000h.*/ + 0x00, 0x00, /* PPPP: see above */ + 0xa0, 0x0f, 0x00, 0x00, /* u32 dwMaximumClock; */ + 0x00, 0x00, 0x01, 0x00, + 0x00, /* u8 bNumClockSupported; see above */ + 0x80, 0x25, 0x00, 0x00, /* u32 dwMaxDataRate ; see above */ + 0x00, 0xC2, 0x01, 0x00, + 0x00, /* u8 bNumDataRatesSupported; see above */ + 0xfe, 0x00, 0x00, 0x00, /* u32 dwMaxIFSD; see above */ + 0x00, 0x00, 0x00, 0x00, /* u32 dwSyncProtocols; see above */ + 0x00, 0x00, 0x00, 0x00, /* u32 dwMechanical; see above */ + 0xfe, 0x04, 0x04, 0x00, /* u32 dwFeatures; 400 for better compat. */ + 0x12, 0x00, 0x01, 0x00, /* u32 dwMaxCCIDMessageLength; see above */ + 0xFF, /* u8 bClassGetResponse; see above */ + 0xFF, /* u8 bClassEnvelope; see above */ + 0x00, 0x00, /* u16 wLcdLayout; see above */ + 0x01, /* u8 bPINSupport; see above */ + 0x0f, /* u8 bMaxCCIDBusySlots; modified from 1 */ +}; + enum { STR_MANUFACTURER =3D 1, STR_PRODUCT, @@ -457,6 +490,38 @@ static const USBDescIface desc_iface0 =3D { } }; =20 +static const USBDescIface desc_iface0_multi =3D { + .bInterfaceNumber =3D 0, + .bNumEndpoints =3D 3, + .bInterfaceClass =3D USB_CLASS_CSCID, + .bInterfaceSubClass =3D USB_SUBCLASS_UNDEFINED, + .bInterfaceProtocol =3D 0x00, + .iInterface =3D STR_INTERFACE, + .ndesc =3D 1, + .descs =3D (USBDescOther[]) { + { + /* smartcard descriptor */ + .data =3D qemu_ccid_descriptor_multi, + }, + }, + .eps =3D (USBDescEndpoint[]) { + { + .bEndpointAddress =3D USB_DIR_IN | CCID_INT_IN_EP, + .bmAttributes =3D USB_ENDPOINT_XFER_INT, + .bInterval =3D 255, + .wMaxPacketSize =3D 64, + },{ + .bEndpointAddress =3D USB_DIR_IN | CCID_BULK_IN_EP, + .bmAttributes =3D USB_ENDPOINT_XFER_BULK, + .wMaxPacketSize =3D 64, + },{ + .bEndpointAddress =3D USB_DIR_OUT | CCID_BULK_OUT_EP, + .bmAttributes =3D USB_ENDPOINT_XFER_BULK, + .wMaxPacketSize =3D 64, + }, + } +}; + static const USBDescDevice desc_device =3D { .bcdUSB =3D 0x0110, .bMaxPacketSize0 =3D 64, @@ -474,6 +539,23 @@ static const USBDescDevice desc_device =3D { }, }; =20 +static const USBDescDevice desc_device_multi =3D { + .bcdUSB =3D 0x0110, + .bMaxPacketSize0 =3D 64, + .bNumConfigurations =3D 1, + .confs =3D (USBDescConfig[]) { + { + .bNumInterfaces =3D 1, + .bConfigurationValue =3D 1, + .bmAttributes =3D USB_CFG_ATT_ONE | USB_CFG_ATT_SELFPOWER | + USB_CFG_ATT_WAKEUP, + .bMaxPower =3D 50, + .nif =3D 1, + .ifs =3D &desc_iface0_multi, + }, + }, +}; + static const USBDesc desc_ccid =3D { .id =3D { .idVendor =3D CCID_VENDOR_ID, @@ -487,6 +569,19 @@ static const USBDesc desc_ccid =3D { .str =3D desc_strings, }; =20 +static const USBDesc desc_ccid_multi =3D { + .id =3D { + .idVendor =3D CCID_VENDOR_ID_MULTI, + .idProduct =3D CCID_PRODUCT_ID_MULTI, + .bcdDevice =3D CCID_DEVICE_VERSION, + .iManufacturer =3D STR_MANUFACTURER, + .iProduct =3D STR_PRODUCT, + .iSerialNumber =3D STR_SERIALNUMBER, + }, + .full =3D &desc_device_multi, + .str =3D desc_strings, +}; + static const uint8_t *ccid_card_get_atr(CCIDCardState *card, uint32_t *len) { CCIDCardClass *cc =3D CCID_CARD_GET_CLASS(card); @@ -1293,10 +1388,12 @@ static void ccid_card_realize(DeviceState *qdev, Error **errp) USBDevice *dev =3D USB_DEVICE(qdev->parent_bus->parent); USBCCIDState *s =3D USB_CCID_DEV(dev); Error *local_err =3D NULL; + const USBDesc *desc =3D usb_device_get_usb_desc(dev); + uint8_t bMaxSlotIndex =3D desc->full->confs[0].ifs- >descs[0].data[4]; =20 - if (card->slot !=3D 0) { - error_setg(errp, "usb-ccid supports one slot, can't add %d", - card->slot); + if (card->slot > bMaxSlotIndex) { + error_setg(errp, "usb-ccid supports %d slots, can't add %d", + bMaxSlotIndex+1, card->slot); return; } if (s->card !=3D NULL) { @@ -1317,6 +1414,8 @@ static void ccid_realize(USBDevice *dev, Error **errp) { USBCCIDState *s =3D USB_CCID_DEV(dev); =20 + dev->usb_desc =3D s->multi ? &desc_ccid_multi : &desc_ccid; + usb_desc_create_serial(dev); usb_desc_init(dev); qbus_init(&s->bus, sizeof(s->bus), TYPE_CCID_BUS, DEVICE(dev), NULL); @@ -1433,6 +1532,7 @@ static const VMStateDescription ccid_vmstate =3D { =20 static Property ccid_properties[] =3D { DEFINE_PROP_UINT8("debug", USBCCIDState, debug, 0), + DEFINE_PROP_BOOL("multi", USBCCIDState, multi, false), DEFINE_PROP_END_OF_LIST(), }; =20 --=20 2.34.1