usb-ccid (v3)
cover usb-ccid (v3)
This patchset adds two new devices, usb-ccid and ccid-card-passthru, providing a CCID implementation as a bus and a simple passthru protocol implementing card requiring a client.
Next patches will add a fully emulated card that can be used standalone to use a local (host side) card reader, and documentation (being revised for the new bus and multiple cards change)
v3 changes:
* split into bus (usb-ccid.c, uses ccid.h) and card (ccid-card-passthru.c).
* removed documentation (being revised).
v2 changed:
* all QSIMPLEQ turned into fixed sized rings
* all allocated buffers turned into fixed size buffers
* added migration support
* added a message to tell client qemu has migrated to ip:port
* for lack of monitor commands ip:port are 0:0, which causes the updated vscclient to connect to one port higher on the same host. will add monitor commands in a separate patch. tested with current setup.
Alon Levy (2):
usb-ccid: add CCID bus
ccid: add passthru card device
Makefile.objs | 1 + configure | 12 + hw/ccid-card-passthru.c | 284 ++++++++++ hw/ccid.h | 34 ++ hw/usb-ccid.c | 1349 +++++++++++++++++++++++++++++++++++++++++++++++ hw/vscard_common.h | 130 +++++ 6 files changed, 1810 insertions(+), 0 deletions(-) create mode 100644 hw/ccid-card-passthru.c create mode 100644 hw/ccid.h create mode 100644 hw/usb-ccid.c create mode 100644 hw/vscard_common.h
Signature · 1 line
1.7.3.1
PATCH 1/2 usb-ccid: add CCID bus
A CCID device is a smart card reader. It is a USB device, defined at [1]. This patch introduces the usb-ccid device that is a ccid bus. Next patches will introduce two card types to use it, a passthru card and an emulated card.
[1] http://www.usb.org/developers/devclass_docs/DWG_Smart-Card_CCID_Rev110.
--- Makefile.objs | 1 + configure | 12 + hw/ccid.h | 34 ++ hw/usb-ccid.c | 1349 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 1396 insertions(+), 0 deletions(-) create mode 100644 hw/ccid.h create mode 100644 hw/usb-ccid.c
Makefile.objs +1 -0
@@ -173,6 +173,7 @@ hw-obj-$(CONFIG_FDC) += fdc.o hw-obj-$(CONFIG_ACPI) += acpi.o acpi_piix4.o hw-obj-$(CONFIG_APM) += pm_smbus.o apm.o hw-obj-$(CONFIG_DMA) += dma.o +hw-obj-$(CONFIG_SMARTCARD) += usb-ccid.o # PPC devices hw-obj-$(CONFIG_OPENPIC) += openpic.o
configure +12 -0
@@ -331,6 +331,7 @@ zero_malloc="" trace_backend="nop" trace_file="trace" spice="" +smartcard="no" # OS specific if check_define __linux__ ; then
@@ -738,6 +739,10 @@ for opt do ;; --enable-vhost-net) vhost_net="yes" ;; + --disable-smartcard) smartcard="no" + ;; + --enable-smartcard) smartcard="yes" + ;; --*dir) ;; *) echo "ERROR: unknown option $opt"; show_help="yes"
@@ -931,6 +936,8 @@ echo " --trace-file=NAME Full PATH,NAME of file to store traces" echo " Default:trace-<pid>" echo " --disable-spice disable spice" echo " --enable-spice enable spice" +echo " --disable-smartcard disable smartcard support" +echo " --enable-smartcard enable smartcard support" echo "" echo "NOTE: The object files are built at the place where configure is launched" exit 1
@@ -2319,6 +2326,7 @@ echo "vhost-net support $vhost_net" echo "Trace backend $trace_backend" echo "Trace output file $trace_file-<pid>" echo "spice support $spice" +echo "smartcard support $smartcard" if test $sdl_too_old = "yes"; then echo "-> Your SDL version is too old - please upgrade to have SDL support"
@@ -2578,6 +2586,10 @@ if test "$spice" = "yes" ; then echo "CONFIG_SPICE=y" >> $config_host_mak fi +if test "$smartcard" = "yes" ; then + echo "CONFIG_SMARTCARD=y" >> $config_host_mak +fi + # XXX: suppress that if [ "$bsd" = "yes" ] ; then echo "CONFIG_BSD=y" >> $config_host_mak
hw/ccid.h new file +34 -0
@@ -0,0 +1,34 @@ +#ifndef __CCID_H__ +#define __CCID_H__ + +#include "qdev.h" + +typedef struct CCIDCardState CCIDCardState ; +typedef struct CCIDCardInfo CCIDCardInfo ; + +struct CCIDCardState { +DeviceState qdev; +}; + +struct CCIDCardInfo { +DeviceInfo qdev; +void (*print)(Monitor *mon,CCIDCardState *card,int indent); +const uint8_t *(*get_atr)(CCIDCardState *card,uint32_t *len); +void (*apdu_from_guest)(CCIDCardState *card,const uint8_t *apdu,uint32_t len); +int (*exitfn)(CCIDCardState *card); +int (*initfn)(CCIDCardState *card); +}; + +void ccid_card_send_apdu_to_guest (CCIDCardState *card,uint8_t * apdu,uint32_t len); +void ccid_card_card_removed (CCIDCardState *card); +void ccid_card_card_inserted (CCIDCardState *card); +void ccid_card_card_error (CCIDCardState *card,uint64_t error); +void ccid_card_qdev_register (CCIDCardInfo *card); + +/* support guest visible insertion/removal of ccid devices based on actual +* devices connected/removed. Called by card implementation (passthru, local) */ +int ccid_card_ccid_attach (CCIDCardState *card); +void ccid_card_ccid_detach (CCIDCardState *card); + +#endif // __CCID_H__ +
hw/usb-ccid.c new file +1349 -0
1,349 lines not on this page · raw message
Signature · 1 line
1.7.3.1
Re: [Qemu-devel] [PATCH 1/2] usb-ccid: add CCID bus
Quoted 15 lines · Alon Levy
A CCID device is a smart card reader. It is a USB device, defined at [1]. This patch introduces the usb-ccid device that is a ccid bus. Next patches will introduce two card types to use it, a passthru card and an emulated card.
[1] http://www.usb.org/developers/devclass_docs/DWG_Smart-Card_CCID_Rev110.
Signed-off-by Alon Levy <[email protected]>--- Makefile.objs | 1 + configure | 12 + hw/ccid.h | 34 ++ hw/usb-ccid.c | 1349 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 1396 insertions(+), 0 deletions(-) create mode 100644 hw/ccid.h create mode 100644 hw/usb-ccid.c
[...]
Quoted 6 lines
hw/usb-ccid.c new file +0
-0@@ -0,0 +1,1349 @@
[...]
hw/usb-ccid.c line 1057
Quoted 3 lines
hw/usb-ccid.c new file +3
-0+struct CCIDBus { +BusState qbus; +USBCCIDState *ccid;
Where does ccid point to?
Quoted 1 line
+};
[...]
hw/usb-ccid.c line 1197
Quoted 8 lines
hw/usb-ccid.c new file +8
-0+static int ccid_initfn (USBDevice *dev) +{ +USBCCIDState *s =DO_UPCAST (USBCCIDState, dev, dev); + + s->bus =ccid_bus_new (&dev->qdev); + s->card =NULL ; + s->cardinfo =NULL ; + s->bus->ccid = s;
Looks like it points back to the device providing the bus. Why not use bus->qbus->parent ?
hw/usb-ccid.c line 1200
Quoted 3 lines
hw/usb-ccid.c new file +3
-0+ s->migration_state =MIGRATION_NONE ; + dev->auto_attach = s->auto_attach; + debug = s->debug;
Wait a sec! Each CCID device has its own property "debug" (defined below), but they all copy to the same static debug on initialization. In other words, the device initialized last wins. Ugh.
Quoted 16 lines
hw/usb-ccid.c new file +16
-0+ s->migration_target_ip =0 ; + s->migration_target_port =0 ; + s->dev.speed =USB_SPEED_FULL ; + s->notify_slot_change = false; + s->powered = true; + s->pending_answers_num =0 ; + s->last_answer_error =0 ; + s->bulk_in_pending_start =0 ; + s->bulk_in_pending_end =0 ; + s->current_bulk_in =NULL ; +ccid_reset_error_status (s); + s->bulk_out_pos =0 ; +ccid_reset_parameters (s); +ccid_reset (s); +return 0 ; +}
[...]
Quoted 25 lines
hw/usb-ccid.c new file +25
-0+static struct USBDeviceInfo ccid_info = { + .product_desc ="QEMU USB CCID" , + .qdev.name =CCID_DEV_NAME , + .qdev.size =sizeof (USBCCIDState), + .qdev.vmsd = &ccid_vmstate, + .init = ccid_initfn, + .handle_packet = usb_generic_handle_packet, + .handle_reset = ccid_handle_reset, + .handle_control = ccid_handle_control, + .handle_data = ccid_handle_data, + .handle_destroy = ccid_handle_destroy, + .usbdevice_name ="ccid" , + .qdev.props = (Property []) { +DEFINE_PROP_UINT8 ("auto_attach" , USBCCIDState, auto_attach,0 ), +DEFINE_PROP_UINT8 ("debug" , USBCCIDState, debug,0 ), +DEFINE_PROP_END_OF_LIST (), + }, +}; + + +static void ccid_register_devices (void ) +{ +usb_qdev_register (&ccid_info); +} +device_init (ccid_register_devices)
Re: [Qemu-devel] [PATCH 1/2] usb-ccid: add CCID bus
Quoted 33 lines · Markus Armbruster
Quoted 15 lines · Alon Levy
A CCID device is a smart card reader. It is a USB device, defined at [1]. This patch introduces the usb-ccid device that is a ccid bus. Next patches will introduce two card types to use it, a passthru card and an emulated card.
[1] http://www.usb.org/developers/devclass_docs/DWG_Smart-Card_CCID_Rev110.
Signed-off-by Alon Levy <[email protected]>--- Makefile.objs | 1 + configure | 12 + hw/ccid.h | 34 ++ hw/usb-ccid.c | 1349 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 1396 insertions(+), 0 deletions(-) create mode 100644 hw/ccid.h create mode 100644 hw/usb-ccid.c[...]
Quoted 6 lines
hw/usb-ccid.c new file +0
-0@@ -0,0 +1,1349 @@[...]
hw/usb-ccid.c line 1057
Quoted 3 lines
hw/usb-ccid.c new file +3
-0+struct CCIDBus { +BusState qbus; +USBCCIDState *ccid;Where does ccid point to?
Quoted 1 line
+};
[...]
Quoted 12 lines
hw/usb-ccid.c line 1197
Quoted 8 lines
hw/usb-ccid.c new file +8
-0+static int ccid_initfn (USBDevice *dev) +{ +USBCCIDState *s =DO_UPCAST (USBCCIDState, dev, dev); + + s->bus =ccid_bus_new (&dev->qdev); + s->card =NULL ; + s->cardinfo =NULL ; + s->bus->ccid = s;Looks like it points back to the device providing the bus. Why not use
bus->qbus->parent?
Thanks, will fix.
Quoted 8 lines
hw/usb-ccid.c line 1200
Quoted 3 lines
hw/usb-ccid.c new file +3
-0+ s->migration_state =MIGRATION_NONE ; + dev->auto_attach = s->auto_attach; + debug = s->debug;Wait a sec! Each CCID device has its own property "debug" (defined below), but they all copy to the same static debug on initialization. In other words, the device initialized last wins. Ugh.
Thanks again. I'll change the DPRINTF to use the device instance (I think I have it wherever I use DPRINTF), that will eliminate the static.
Quoted 42 lines
Quoted 16 lines
hw/usb-ccid.c new file +16
-0+ s->migration_target_ip =0 ; + s->migration_target_port =0 ; + s->dev.speed =USB_SPEED_FULL ; + s->notify_slot_change = false; + s->powered = true; + s->pending_answers_num =0 ; + s->last_answer_error =0 ; + s->bulk_in_pending_start =0 ; + s->bulk_in_pending_end =0 ; + s->current_bulk_in =NULL ; +ccid_reset_error_status (s); + s->bulk_out_pos =0 ; +ccid_reset_parameters (s); +ccid_reset (s); +return 0 ; +}[...]
Quoted 25 lines
hw/usb-ccid.c new file +25
-0+static struct USBDeviceInfo ccid_info = { + .product_desc ="QEMU USB CCID" , + .qdev.name =CCID_DEV_NAME , + .qdev.size =sizeof (USBCCIDState), + .qdev.vmsd = &ccid_vmstate, + .init = ccid_initfn, + .handle_packet = usb_generic_handle_packet, + .handle_reset = ccid_handle_reset, + .handle_control = ccid_handle_control, + .handle_data = ccid_handle_data, + .handle_destroy = ccid_handle_destroy, + .usbdevice_name ="ccid" , + .qdev.props = (Property []) { +DEFINE_PROP_UINT8 ("auto_attach" , USBCCIDState, auto_attach,0 ), +DEFINE_PROP_UINT8 ("debug" , USBCCIDState, debug,0 ), +DEFINE_PROP_END_OF_LIST (), + }, +}; + + +static void ccid_register_devices (void ) +{ +usb_qdev_register (&ccid_info); +} +device_init (ccid_register_devices)
PATCH 2/2 ccid: add passthru card device
In reply to Alon LevyFor the client side utility vscclient, see libcac_card:
libcac_card http://cgit.freedesktop.org/~alon/cac_card (temporary home) written by Robert Relyea <[email protected]>
--- Makefile.objs | 2 +- hw/ccid-card-passthru.c | 284 +++++++++++++++++++++++++++++++++++++++++++++++ hw/vscard_common.h | 130 +++++++++++++++++++++ 3 files changed, 415 insertions(+), 1 deletions(-) create mode 100644 hw/ccid-card-passthru.c create mode 100644 hw/vscard_common.h
Makefile.objs +1 -1
@@ -173,7 +173,7 @@ hw-obj-$(CONFIG_FDC) += fdc.o hw-obj-$(CONFIG_ACPI) += acpi.o acpi_piix4.o hw-obj-$(CONFIG_APM) += pm_smbus.o apm.o hw-obj-$(CONFIG_DMA) += dma.o -hw-obj-$(CONFIG_SMARTCARD) += usb-ccid.o +hw-obj-$(CONFIG_SMARTCARD) += usb-ccid.o ccid-card-passthru.o # PPC devices hw-obj-$(CONFIG_OPENPIC) += openpic.o
hw/ccid-card-passthru.c new file +284 -0
284 lines not on this page · raw message
hw/vscard_common.h new file +130 -0
130 lines not on this page · raw message
Signature · 1 line
1.7.3.1