From patchwork Mon Mar 20 15:23:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Ripke, Klaus" X-Patchwork-Id: 1759093 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PgJSL3q8lz247d for ; Tue, 21 Mar 2023 02:24:34 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1peHMq-0004BB-OT; Mon, 20 Mar 2023 11:24:12 -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 1peHMl-00049T-MK; Mon, 20 Mar 2023 11:24:07 -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 1peHMh-0005ng-Gd; Mon, 20 Mar 2023 11:24:07 -0400 Received: from localhost (localhost [127.0.0.1]) by a.mx.secunet.com (Postfix) with ESMTP id 2A14F200A3; Mon, 20 Mar 2023 16:23:57 +0100 (CET) X-Virus-Scanned: by secunet 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 KD9popSaMhtN; Mon, 20 Mar 2023 16:23:56 +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 615C32007F; Mon, 20 Mar 2023 16:23:56 +0100 (CET) Received: from cas-essen-01.secunet.de (unknown [10.53.40.201]) by mailout1.secunet.com (Postfix) with ESMTP id 5288980004A; Mon, 20 Mar 2023 16:23:56 +0100 (CET) Received: from mbx-essen-01.secunet.de (10.53.40.197) 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; Mon, 20 Mar 2023 16:23:56 +0100 Received: from mbx-essen-01.secunet.de (10.53.40.197) by mbx-essen-01.secunet.de (10.53.40.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.17; Mon, 20 Mar 2023 16:23:55 +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; Mon, 20 Mar 2023 16:23:55 +0100 From: "Ripke, Klaus" To: "qemu-devel@nongnu.org" CC: "kraxel@redhat.com" , "qemu-trivial@nongnu.org" , "marcandre.lureau@gmail.com" Subject: [PATCH v2] add option for a multislot usb ccid device Thread-Topic: [PATCH v2] add option for a multislot usb ccid device Thread-Index: AQHZWz/8wBBg4+O45E2yb5rRaBpvVg== Date: Mon, 20 Mar 2023 15:23:55 +0000 Message-ID: <7f321e2fc335be07f44db3b539ee172dbdc4ed2d.camel@secunet.com> Accept-Language: de-DE, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: Content-ID: <3D0A4B9C6650C14EA566454CEDAA136B@secunet.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: 2c86f778-e09b-4440-8b15-867914633a10 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Klaus Ripke hw/usb/dev-smartcard-reader.c: add option for a multislot usb ccid device, similar to audio multi. (v2 with slight formatting fix on " + ") ---  hw/usb/dev-smartcard-reader.c | 106 +++++++++++++++++++++++++++++++++-  1 file changed, 103 insertions(+), 3 deletions(-)  /*   * 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;  };    /* @@ -411,6 +416,34 @@ static const uint8_t qemu_ccid_descriptor[] = {          0x01,       /* u8  bMaxCCIDBusySlots; */  };   +static const uint8_t qemu_ccid_descriptor_multi[] = { +        /* 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 = 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 = 1,      STR_PRODUCT, @@ -457,6 +490,38 @@ static const USBDescIface desc_iface0 = {      }  };   +static const USBDescIface desc_iface0_multi = { +    .bInterfaceNumber              = 0, +    .bNumEndpoints                 = 3, +    .bInterfaceClass               = USB_CLASS_CSCID, +    .bInterfaceSubClass            = USB_SUBCLASS_UNDEFINED, +    .bInterfaceProtocol            = 0x00, +    .iInterface                    = STR_INTERFACE, +    .ndesc                         = 1, +    .descs = (USBDescOther[]) { +        { +            /* smartcard descriptor */ +            .data = qemu_ccid_descriptor_multi, +        }, +    }, +    .eps = (USBDescEndpoint[]) { +        { +            .bEndpointAddress      = USB_DIR_IN | CCID_INT_IN_EP, +            .bmAttributes          = USB_ENDPOINT_XFER_INT, +            .bInterval             = 255, +            .wMaxPacketSize        = 64, +        },{ +            .bEndpointAddress      = USB_DIR_IN | CCID_BULK_IN_EP, +            .bmAttributes          = USB_ENDPOINT_XFER_BULK, +            .wMaxPacketSize        = 64, +        },{ +            .bEndpointAddress      = USB_DIR_OUT | CCID_BULK_OUT_EP, +            .bmAttributes          = USB_ENDPOINT_XFER_BULK, +            .wMaxPacketSize        = 64, +        }, +    } +}; +  static const USBDescDevice desc_device = {      .bcdUSB                        = 0x0110,      .bMaxPacketSize0               = 64, @@ -474,6 +539,23 @@ static const USBDescDevice desc_device = {      },  };   +static const USBDescDevice desc_device_multi = { +    .bcdUSB                        = 0x0110, +    .bMaxPacketSize0               = 64, +    .bNumConfigurations            = 1, +    .confs = (USBDescConfig[]) { +        { +            .bNumInterfaces        = 1, +            .bConfigurationValue   = 1, +            .bmAttributes          = USB_CFG_ATT_ONE | USB_CFG_ATT_SELFPOWER | +                                     USB_CFG_ATT_WAKEUP, +            .bMaxPower             = 50, +            .nif = 1, +            .ifs = &desc_iface0_multi, +        }, +    }, +}; +  static const USBDesc desc_ccid = {      .id = {          .idVendor          = CCID_VENDOR_ID, @@ -487,6 +569,19 @@ static const USBDesc desc_ccid = {      .str  = desc_strings,  };   +static const USBDesc desc_ccid_multi = { +    .id = { +        .idVendor          = CCID_VENDOR_ID_MULTI, +        .idProduct         = CCID_PRODUCT_ID_MULTI, +        .bcdDevice         = CCID_DEVICE_VERSION, +        .iManufacturer     = STR_MANUFACTURER, +        .iProduct          = STR_PRODUCT, +        .iSerialNumber     = STR_SERIALNUMBER, +    }, +    .full = &desc_device_multi, +    .str  = desc_strings, +}; +  static const uint8_t *ccid_card_get_atr(CCIDCardState *card, uint32_t *len)  {      CCIDCardClass *cc = CCID_CARD_GET_CLASS(card); @@ -1293,10 +1388,12 @@ static void ccid_card_realize(DeviceState *qdev, Error **errp)      USBDevice *dev = USB_DEVICE(qdev->parent_bus->parent);      USBCCIDState *s = USB_CCID_DEV(dev);      Error *local_err = NULL; +    const USBDesc *desc = usb_device_get_usb_desc(dev); +    uint8_t bMaxSlotIndex = desc->full->confs[0].ifs- >descs[0].data[4];   -    if (card->slot != 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 != NULL) { @@ -1317,6 +1414,8 @@ static void ccid_realize(USBDevice *dev, Error **errp)  {      USBCCIDState *s = USB_CCID_DEV(dev);   +    dev->usb_desc = 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 = {    static Property ccid_properties[] = {      DEFINE_PROP_UINT8("debug", USBCCIDState, debug, 0), +    DEFINE_PROP_BOOL("multi", USBCCIDState, multi, false),      DEFINE_PROP_END_OF_LIST(),  }; diff --git a/hw/usb/dev-smartcard-reader.c b/hw/usb/dev-smartcard- reader.c index be0a4fc3bc..30d8892b4e 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