Re: [Qemu-devel] [PATCH 05/20] usb-ccid: add CCID bus
On 02/02/2011 02:28 PM, Alon Levy wrote: 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 Levyal...@redhat.com --- Makefile.objs |1 + configure |6 + hw/ccid.h | 35 ++ hw/usb-ccid.c | 1355 + 4 files changed, 1397 insertions(+), 0 deletions(-) create mode 100644 hw/ccid.h create mode 100644 hw/usb-ccid.c diff --git a/Makefile.objs b/Makefile.objs index f1c7bfe..a1f3853 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -195,6 +195,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 diff --git a/configure b/configure index 598e8e1..14a035a 100755 --- a/configure +++ b/configure @@ -174,6 +174,7 @@ trace_backend=nop trace_file=trace spice= rbd= +smartcard=yes # parse CC options first for opt do @@ -2472,6 +2473,7 @@ echo Trace output file $trace_file-pid echo spice support $spice echo rbd support $rbd echo xfsctl support$xfs +echo smartcard support $smartcard if test $sdl_too_old = yes; then echo - Your SDL version is too old - please upgrade to have SDL support @@ -2744,6 +2746,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 diff --git a/hw/ccid.h b/hw/ccid.h new file mode 100644 index 000..af59070 --- /dev/null +++ b/hw/ccid.h @@ -0,0 +1,35 @@ +#ifndef __CCID_H__ +#define __CCID_H__ Missing copyright, plus identifiers can't start with __. + +#include qdev.h + +typedef struct CCIDCardState CCIDCardState; +typedef struct CCIDCardInfo CCIDCardInfo; + +struct CCIDCardState { +DeviceState qdev; +uint32_tslot; // For future use with multiple slot reader. +}; Please stick to C89 comments. + +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__ + diff --git a/hw/usb-ccid.c b/hw/usb-ccid.c new file mode 100644 index 000..58f69a6 --- /dev/null +++ b/hw/usb-ccid.c @@ -0,0 +1,1355 @@ +/* + * CCID Device emulation + * + * Based on usb-serial.c: + * Copyright (c) 2006 CodeSourcery. + * Copyright (c) 2008 Samuel Thibaultsamuel.thiba...@ens-lyon.org + * Written by Paul Brook, reused for FTDI by Samuel Thibault, + * Reused for CCID by Alon Levy. + * Contributed to by Robert Relyea + * Copyright (c) 2010 Red Hat. + * + * This code is licenced under the LGPL. + */ + +/* References: + * + * CCID Specification Revision 1.1 April 22nd 2005 + * Universal Serial Bus, Device Class: Smart Card + * Specification for Integrated Circuit(s) Cards Interface Devices + * + * Endianess note: from the spec (1.3) + * Fields that are larger than a byte are stored in little endian + * + * KNOWN BUGS + * 1. remove/insert can sometimes result in removed state instead of inserted. + * This is a result of the following: + * symptom: dmesg shows ERMOTEIO (-121), pcscd shows -99. This happens + * when we send a too short packet, seen in uhci-usb.c, resulting from + * a urb requesting SPD and us returning a smaller packet. + * Not sure which messages trigger this. + * + * Migration note: + * + * All the VMStateDescription's are left here for future use, but + * not enabled right now since there is no support for USB migration. + * + * To enable define ENABLE_MIGRATION + */ + +#include qemu-common.h +#include qemu-error.h +#include usb.h +#include monitor.h + +#include hw/ccid.h + +//#define DEBUG_CCID + +#define DPRINTF(s, lvl, fmt, ...) \ +do { if (lvl= s-debug) { printf(usb-ccid: fmt , ## __VA_ARGS__); } } while (0) + +#define
Re: [Qemu-devel] [PATCH 05/20] usb-ccid: add CCID bus
On Thu, Feb 03, 2011 at 10:46:59AM -0600, Anthony Liguori wrote: On 02/02/2011 02:28 PM, Alon Levy wrote: 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 Levyal...@redhat.com --- Makefile.objs |1 + configure |6 + hw/ccid.h | 35 ++ hw/usb-ccid.c | 1355 + 4 files changed, 1397 insertions(+), 0 deletions(-) create mode 100644 hw/ccid.h create mode 100644 hw/usb-ccid.c diff --git a/Makefile.objs b/Makefile.objs index f1c7bfe..a1f3853 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -195,6 +195,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 diff --git a/configure b/configure index 598e8e1..14a035a 100755 --- a/configure +++ b/configure @@ -174,6 +174,7 @@ trace_backend=nop trace_file=trace spice= rbd= +smartcard=yes # parse CC options first for opt do @@ -2472,6 +2473,7 @@ echo Trace output file $trace_file-pid echo spice support $spice echo rbd support $rbd echo xfsctl support$xfs +echo smartcard support $smartcard if test $sdl_too_old = yes; then echo - Your SDL version is too old - please upgrade to have SDL support @@ -2744,6 +2746,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 diff --git a/hw/ccid.h b/hw/ccid.h new file mode 100644 index 000..af59070 --- /dev/null +++ b/hw/ccid.h @@ -0,0 +1,35 @@ +#ifndef __CCID_H__ +#define __CCID_H__ Missing copyright, plus identifiers can't start with __. Will fix. Again. + +#include qdev.h + +typedef struct CCIDCardState CCIDCardState; +typedef struct CCIDCardInfo CCIDCardInfo; + +struct CCIDCardState { +DeviceState qdev; +uint32_tslot; // For future use with multiple slot reader. +}; Please stick to C89 comments. Another oops. + +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__ + diff --git a/hw/usb-ccid.c b/hw/usb-ccid.c new file mode 100644 index 000..58f69a6 --- /dev/null +++ b/hw/usb-ccid.c @@ -0,0 +1,1355 @@ +/* + * CCID Device emulation + * + * Based on usb-serial.c: + * Copyright (c) 2006 CodeSourcery. + * Copyright (c) 2008 Samuel Thibaultsamuel.thiba...@ens-lyon.org + * Written by Paul Brook, reused for FTDI by Samuel Thibault, + * Reused for CCID by Alon Levy. + * Contributed to by Robert Relyea + * Copyright (c) 2010 Red Hat. + * + * This code is licenced under the LGPL. + */ + +/* References: + * + * CCID Specification Revision 1.1 April 22nd 2005 + * Universal Serial Bus, Device Class: Smart Card + * Specification for Integrated Circuit(s) Cards Interface Devices + * + * Endianess note: from the spec (1.3) + * Fields that are larger than a byte are stored in little endian + * + * KNOWN BUGS + * 1. remove/insert can sometimes result in removed state instead of inserted. + * This is a result of the following: + * symptom: dmesg shows ERMOTEIO (-121), pcscd shows -99. This happens + * when we send a too short packet, seen in uhci-usb.c, resulting from + * a urb requesting SPD and us returning a smaller packet. + * Not sure which messages trigger this. + * + * Migration note: + * + * All the VMStateDescription's are left here for future use, but + * not enabled right now since there is no support for USB migration. + * + * To enable define ENABLE_MIGRATION + */ + +#include
Re: [Qemu-devel] [PATCH 05/20] usb-ccid: add CCID bus
On Thu, Feb 03, 2011 at 08:53:07PM +0200, Alon Levy wrote: On Thu, Feb 03, 2011 at 10:46:59AM -0600, Anthony Liguori wrote: On 02/02/2011 02:28 PM, Alon Levy wrote: 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 Levyal...@redhat.com --- Makefile.objs |1 + configure |6 + hw/ccid.h | 35 ++ hw/usb-ccid.c | 1355 + 4 files changed, 1397 insertions(+), 0 deletions(-) create mode 100644 hw/ccid.h create mode 100644 hw/usb-ccid.c diff --git a/Makefile.objs b/Makefile.objs index f1c7bfe..a1f3853 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -195,6 +195,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 diff --git a/configure b/configure index 598e8e1..14a035a 100755 --- a/configure +++ b/configure @@ -174,6 +174,7 @@ trace_backend=nop trace_file=trace spice= rbd= +smartcard=yes # parse CC options first for opt do @@ -2472,6 +2473,7 @@ echo Trace output file $trace_file-pid echo spice support $spice echo rbd support $rbd echo xfsctl support$xfs +echo smartcard support $smartcard if test $sdl_too_old = yes; then echo - Your SDL version is too old - please upgrade to have SDL support @@ -2744,6 +2746,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 diff --git a/hw/ccid.h b/hw/ccid.h new file mode 100644 index 000..af59070 --- /dev/null +++ b/hw/ccid.h @@ -0,0 +1,35 @@ +#ifndef __CCID_H__ +#define __CCID_H__ Missing copyright, plus identifiers can't start with __. Will fix. Again. + +#include qdev.h + +typedef struct CCIDCardState CCIDCardState; +typedef struct CCIDCardInfo CCIDCardInfo; + +struct CCIDCardState { +DeviceState qdev; +uint32_tslot; // For future use with multiple slot reader. +}; Please stick to C89 comments. Another oops. + +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__ + diff --git a/hw/usb-ccid.c b/hw/usb-ccid.c new file mode 100644 index 000..58f69a6 --- /dev/null +++ b/hw/usb-ccid.c @@ -0,0 +1,1355 @@ +/* + * CCID Device emulation + * + * Based on usb-serial.c: + * Copyright (c) 2006 CodeSourcery. + * Copyright (c) 2008 Samuel Thibaultsamuel.thiba...@ens-lyon.org + * Written by Paul Brook, reused for FTDI by Samuel Thibault, + * Reused for CCID by Alon Levy. + * Contributed to by Robert Relyea + * Copyright (c) 2010 Red Hat. + * + * This code is licenced under the LGPL. + */ + +/* References: + * + * CCID Specification Revision 1.1 April 22nd 2005 + * Universal Serial Bus, Device Class: Smart Card + * Specification for Integrated Circuit(s) Cards Interface Devices + * + * Endianess note: from the spec (1.3) + * Fields that are larger than a byte are stored in little endian + * + * KNOWN BUGS + * 1. remove/insert can sometimes result in removed state instead of inserted. + * This is a result of the following: + * symptom: dmesg shows ERMOTEIO (-121), pcscd shows -99. This happens + * when we send a too short packet, seen in uhci-usb.c, resulting from + * a urb requesting SPD and us returning a smaller packet. + * Not sure which messages trigger this. + * + *
[Qemu-devel] [PATCH 05/20] 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. Signed-off-by: Alon Levy al...@redhat.com --- Makefile.objs |1 + configure |6 + hw/ccid.h | 35 ++ hw/usb-ccid.c | 1355 + 4 files changed, 1397 insertions(+), 0 deletions(-) create mode 100644 hw/ccid.h create mode 100644 hw/usb-ccid.c diff --git a/Makefile.objs b/Makefile.objs index f1c7bfe..a1f3853 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -195,6 +195,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 diff --git a/configure b/configure index 598e8e1..14a035a 100755 --- a/configure +++ b/configure @@ -174,6 +174,7 @@ trace_backend=nop trace_file=trace spice= rbd= +smartcard=yes # parse CC options first for opt do @@ -2472,6 +2473,7 @@ echo Trace output file $trace_file-pid echo spice support $spice echo rbd support $rbd echo xfsctl support$xfs +echo smartcard support $smartcard if test $sdl_too_old = yes; then echo - Your SDL version is too old - please upgrade to have SDL support @@ -2744,6 +2746,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 diff --git a/hw/ccid.h b/hw/ccid.h new file mode 100644 index 000..af59070 --- /dev/null +++ b/hw/ccid.h @@ -0,0 +1,35 @@ +#ifndef __CCID_H__ +#define __CCID_H__ + +#include qdev.h + +typedef struct CCIDCardState CCIDCardState; +typedef struct CCIDCardInfo CCIDCardInfo; + +struct CCIDCardState { +DeviceState qdev; +uint32_tslot; // For future use with multiple slot reader. +}; + +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__ + diff --git a/hw/usb-ccid.c b/hw/usb-ccid.c new file mode 100644 index 000..58f69a6 --- /dev/null +++ b/hw/usb-ccid.c @@ -0,0 +1,1355 @@ +/* + * CCID Device emulation + * + * Based on usb-serial.c: + * Copyright (c) 2006 CodeSourcery. + * Copyright (c) 2008 Samuel Thibault samuel.thiba...@ens-lyon.org + * Written by Paul Brook, reused for FTDI by Samuel Thibault, + * Reused for CCID by Alon Levy. + * Contributed to by Robert Relyea + * Copyright (c) 2010 Red Hat. + * + * This code is licenced under the LGPL. + */ + +/* References: + * + * CCID Specification Revision 1.1 April 22nd 2005 + * Universal Serial Bus, Device Class: Smart Card + * Specification for Integrated Circuit(s) Cards Interface Devices + * + * Endianess note: from the spec (1.3) + * Fields that are larger than a byte are stored in little endian + * + * KNOWN BUGS + * 1. remove/insert can sometimes result in removed state instead of inserted. + * This is a result of the following: + * symptom: dmesg shows ERMOTEIO (-121), pcscd shows -99. This happens + * when we send a too short packet, seen in uhci-usb.c, resulting from + * a urb requesting SPD and us returning a smaller packet. + * Not sure which messages trigger this. + * + * Migration note: + * + * All the VMStateDescription's are left here for future use, but + * not enabled right now since there is no support for USB migration. + * + * To enable define ENABLE_MIGRATION + */ + +#include qemu-common.h +#include qemu-error.h +#include usb.h +#include monitor.h + +#include hw/ccid.h + +//#define DEBUG_CCID + +#define DPRINTF(s, lvl, fmt, ...) \ +do { if (lvl = s-debug) { printf(usb-ccid: fmt , ## __VA_ARGS__); } } while (0) + +#define CCID_DEV_NAME usb-ccid + +/* The two options for variable sized buffers: + * make them constant size, for large enough constant, + * or handle the migration complexity -