[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] usb-ccid: make ids and descriptor configurable
From: |
Ripke, Klaus |
Subject: |
[PATCH] usb-ccid: make ids and descriptor configurable |
Date: |
Tue, 10 Jan 2023 13:18:45 +0000 |
Signed-off-by: Klaus Ripke <klaus.ripke@secunet.com>
hw/usb/dev-smartcard-reader.c:
Set static values from env vars QEMU_CCID_VENDOR/PRODUCT_ID and
_DESCRIPTOR
---
hw/usb/dev-smartcard-reader.c | 27 ++++++++++++++++++++++++---
1 file changed, 24 insertions(+), 3 deletions(-)
diff --git a/hw/usb/dev-smartcard-reader.c b/hw/usb/dev-smartcard-
reader.c
index 28164d89be..0632ab44c6 100644
--- a/hw/usb/dev-smartcard-reader.c
+++ b/hw/usb/dev-smartcard-reader.c
@@ -323,7 +323,7 @@ struct USBCCIDState {
* 0dc3:1004 Athena Smartcard Solutions, Inc.
*/
-static const uint8_t qemu_ccid_descriptor[] = {
+static uint8_t qemu_ccid_descriptor[] = {
/* Smart Card Device Class Descriptor */
0x36, /* u8 bLength; */
0x21, /* u8 bDescriptorType; Functional */
@@ -472,7 +472,7 @@ static const USBDescDevice desc_device = {
},
};
-static const USBDesc desc_ccid = {
+static USBDesc desc_ccid = {
.id = {
.idVendor = CCID_VENDOR_ID,
.idProduct = CCID_PRODUCT_ID,
@@ -1437,12 +1437,33 @@ static Property ccid_properties[] = {
DEFINE_PROP_END_OF_LIST(),
};
+static void env_uint16(uint16_t *val, const char *env)
+{
+ const char *str = getenv(env);
+ if (str) {
+ *val = qemu_strtoul(str, NULL, 16);
+ }
+}
+
static void ccid_class_initfn(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(klass);
-
+ const char *dsc = getenv("QEMU_CCID_DESCRIPTOR");
+
+ if (dsc) {
+ unsigned int idx = 0;
+ unsigned int val = 0;
+ int off = 0;
+ for (; 2 == sscanf(dsc, "%u:%x%n", &idx, &val, &off); dsc +=
off) {
+ if (idx < sizeof qemu_ccid_descriptor) {
+ qemu_ccid_descriptor[idx] = val;
+ }
+ }
+ }
+ env_uint16(&desc_ccid.id.idVendor, "QEMU_CCID_VENDOR_ID");
+ env_uint16(&desc_ccid.id.idProduct, "QEMU_CCID_PRODUCT_ID");
uc->realize = ccid_realize;
uc->product_desc = "QEMU USB CCID";
uc->usb_desc = &desc_ccid;
--
2.34.1
--
Klaus Ripke
Senior Developer
Public Authorities Division
secunet Security Networks AG
Telefon: +49 201 5454-2982
- [PATCH] usb-ccid: make ids and descriptor configurable,
Ripke, Klaus <=