usb-ccid: make ids and descriptor configurable
PATCH 1/1 usb-ccid: make ids and descriptor configurable
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(-)
hw/usb/dev-smartcard- renamed from hw/usb/dev-smartcard-reader.c +0 -0
reader.c
index 28164d89be..0632ab44c6 100644
hw/usb/dev-smartcard-reader.c +0 -0
@@ -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;
Signature · 11 lines
2.34.1 -- Klaus Ripke Senior Developer Public Authorities Division secunet Security Networks AG Telefon: +49 201 5454-2982
Hi Klaus
Quoted 6 lines · Klaus
Signed-off-by Klaus Ripke <[email protected]>
hw/usb/dev-smartcard-reader.c:
Set static values from env vars QEMU_CCID_VENDOR/PRODUCT_ID and_DESCRIPTOR
We don't use environment variables to configure devices. Please add properties to ccid_properties[] instead.
thanks
Quoted 76 lines
--- hw/usb/dev-smartcard-reader.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-)hw/usb/dev-smartcard- renamed from hw/usb/dev-smartcard-reader.c +0
-0
reader.c
index28164d89be..0632ab44c6100644hw/usb/dev-smartcard-reader.c +24
-3@@ -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 AGTelefon: +49 201 5454-2982
Signature · 1 line
Marc-André Lureau