Re: [Qemu-devel] [PATCH v23 03/11] usb-ccid: add CCID bus

2011-03-28 Thread Jes Sorensen
On 03/23/11 14:19, 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 Levy al...@redhat.com

This looks ok to me now - I noticed that the comments in the header file
refers to u8/u16/u32 for types, even though the code uses
uint{8,16,32}_t, but I don't think that warrants a fix.

If the comment goes in, please fix the spelling of my name.

Reviewed-by: Jes Sorensen jes.soren...@redhat.com




Re: [Qemu-devel] [PATCH v23 03/11] usb-ccid: add CCID bus

2011-03-28 Thread Alon Levy
On Mon, Mar 28, 2011 at 02:01:01PM +0200, Jes Sorensen wrote:
 On 03/23/11 14:19, 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 Levy al...@redhat.com
 
 This looks ok to me now - I noticed that the comments in the header file
 refers to u8/u16/u32 for types, even though the code uses
 uint{8,16,32}_t, but I don't think that warrants a fix.
 
 If the comment goes in, please fix the spelling of my name.

Gah, I'm terribly sorry, I usually try to be correct on that point.

 
 Reviewed-by: Jes Sorensen jes.soren...@redhat.com
 



Re: [Qemu-devel] [PATCH v23 03/11] usb-ccid: add CCID bus

2011-03-28 Thread Alon Levy
On Mon, Mar 28, 2011 at 02:01:01PM +0200, Jes Sorensen wrote:
 On 03/23/11 14:19, 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 Levy al...@redhat.com
 
 This looks ok to me now - I noticed that the comments in the header file
 refers to u8/u16/u32 for types, even though the code uses
 uint{8,16,32}_t, but I don't think that warrants a fix.

You mean the comments in hw/usb-ccid.c in the descriptor? that's just shorter.

 
 If the comment goes in, please fix the spelling of my name.
 
 Reviewed-by: Jes Sorensen jes.soren...@redhat.com
 



Re: [Qemu-devel] [PATCH v23 03/11] usb-ccid: add CCID bus

2011-03-28 Thread Jes Sorensen
On 03/28/11 16:28, Alon Levy wrote:
 On Mon, Mar 28, 2011 at 02:01:01PM +0200, Jes Sorensen wrote:
  On 03/23/11 14:19, 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 Levy al...@redhat.com
  
  This looks ok to me now - I noticed that the comments in the header file
  refers to u8/u16/u32 for types, even though the code uses
  uint{8,16,32}_t, but I don't think that warrants a fix.
 You mean the comments in hw/usb-ccid.c in the descriptor? that's just shorter.

I wasn't sure if it was a leftover from some of the headers being used
in the kernel. However I am fine with it - no need to change it, and it
makes it shorter as you say.

Cheers,
Jes



Re: [Qemu-devel] [PATCH v23 03/11] usb-ccid: add CCID bus

2011-03-28 Thread Blue Swirl
On Mon, Mar 28, 2011 at 5:31 PM, Jes Sorensen jes.soren...@redhat.com wrote:
 On 03/28/11 16:28, Alon Levy wrote:
 On Mon, Mar 28, 2011 at 02:01:01PM +0200, Jes Sorensen wrote:
  On 03/23/11 14:19, 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 Levy al...@redhat.com
 
  This looks ok to me now - I noticed that the comments in the header file
  refers to u8/u16/u32 for types, even though the code uses
  uint{8,16,32}_t, but I don't think that warrants a fix.
 You mean the comments in hw/usb-ccid.c in the descriptor? that's just 
 shorter.

 I wasn't sure if it was a leftover from some of the headers being used
 in the kernel. However I am fine with it - no need to change it, and it
 makes it shorter as you say.

No, u8/u16 etc are only available for Linux. Please use standard
uint8_t etc. See also HACKING 2.1.



Re: [Qemu-devel] [PATCH v23 03/11] usb-ccid: add CCID bus

2011-03-28 Thread Alon Levy
On Mon, Mar 28, 2011 at 08:44:59PM +0300, Blue Swirl wrote:
 On Mon, Mar 28, 2011 at 5:31 PM, Jes Sorensen jes.soren...@redhat.com wrote:
  On 03/28/11 16:28, Alon Levy wrote:
  On Mon, Mar 28, 2011 at 02:01:01PM +0200, Jes Sorensen wrote:
   On 03/23/11 14:19, 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 Levy al...@redhat.com
  
   This looks ok to me now - I noticed that the comments in the header file
   refers to u8/u16/u32 for types, even though the code uses
   uint{8,16,32}_t, but I don't think that warrants a fix.
  You mean the comments in hw/usb-ccid.c in the descriptor? that's just 
  shorter.
 
  I wasn't sure if it was a leftover from some of the headers being used
  in the kernel. However I am fine with it - no need to change it, and it
  makes it shorter as you say.
 
 No, u8/u16 etc are only available for Linux. Please use standard
 uint8_t etc. See also HACKING 2.1.

They are just in the comments, like I said above. Just did a git grep to verify,
here is the output (snipped because there are many comments):
U playa:qemu alon (usb_ccid.v24)$ git grep \u8\ hw/ccid.h
U playa:qemu alon (usb_ccid.v24)$ git grep \u16\ hw/ccid.h
U playa:qemu alon (usb_ccid.v24)$ git grep \u16\ hw/usb-ccid.c
hw/usb-ccid.c:0x10, 0x01, /*  u16 bcdUSB; v1.1 */
hw/usb-ccid.c:/*  u16 idVendor  */
hw/usb-ccid.c:/*  u16 idProduct */
hw/usb-ccid.c:/*  u16 bcdDevice */
hw/usb-ccid.c:0x5d, 0x00, /* u16 wTotalLength; 9+9+54+7+7+7 */
hw/usb-ccid.c:0x10, 0x01, /* u16 bcdCCID; CCID Specification Release 
Number. 
hw/usb-ccid.c: * u16 wLcdLayout; XXYY Number of lines (XX) 
and ch
hw/usb-ccid.c:/* u16 ep_wMaxPacketSize; */
hw/usb-ccid.c:0x40, 0x00, /* u16 ep_wMaxPacketSize; */
hw/usb-ccid.c:0x40, 0x00, /* u16 ep_wMaxPacketSize; */
U playa:qemu alon (usb_ccid.v24)$ git grep \u8\ hw/usb-ccid.c
hw/usb-ccid.c:0x12,   /*  u8 bLength; */
hw/usb-ccid.c:USB_DT_DEVICE, /*  u8 bDescriptorType; Device */
hw/usb-ccid.c:0x00,   /*  u8  bDeviceClass; */
hw/usb-ccid.c:0x00,   /*  u8  bDeviceSubClass; */
hw/usb-ccid.c:0x00,   /*  u8  bDeviceProtocol; [ low/full speeds 
only ] *
[snip 46 more lines with comments]




Re: [Qemu-devel] [PATCH v23 03/11] usb-ccid: add CCID bus

2011-03-28 Thread Blue Swirl
On Mon, Mar 28, 2011 at 9:00 PM, Alon Levy al...@redhat.com wrote:
 On Mon, Mar 28, 2011 at 08:44:59PM +0300, Blue Swirl wrote:
 On Mon, Mar 28, 2011 at 5:31 PM, Jes Sorensen jes.soren...@redhat.com 
 wrote:
  On 03/28/11 16:28, Alon Levy wrote:
  On Mon, Mar 28, 2011 at 02:01:01PM +0200, Jes Sorensen wrote:
   On 03/23/11 14:19, 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 Levy al...@redhat.com
  
   This looks ok to me now - I noticed that the comments in the header 
   file
   refers to u8/u16/u32 for types, even though the code uses
   uint{8,16,32}_t, but I don't think that warrants a fix.
  You mean the comments in hw/usb-ccid.c in the descriptor? that's just 
  shorter.
 
  I wasn't sure if it was a leftover from some of the headers being used
  in the kernel. However I am fine with it - no need to change it, and it
  makes it shorter as you say.

 No, u8/u16 etc are only available for Linux. Please use standard
 uint8_t etc. See also HACKING 2.1.

 They are just in the comments, like I said above. Just did a git grep to 
 verify,
 here is the output (snipped because there are many comments):
 U playa:qemu alon (usb_ccid.v24)$ git grep \u8\ hw/ccid.h
 U playa:qemu alon (usb_ccid.v24)$ git grep \u16\ hw/ccid.h
 U playa:qemu alon (usb_ccid.v24)$ git grep \u16\ hw/usb-ccid.c
 hw/usb-ccid.c:        0x10, 0x01, /*  u16 bcdUSB; v1.1 */
 hw/usb-ccid.c:                    /*  u16 idVendor  */
 hw/usb-ccid.c:                    /*  u16 idProduct */
 hw/usb-ccid.c:                    /*  u16 bcdDevice */
 hw/usb-ccid.c:        0x5d, 0x00, /* u16 wTotalLength; 9+9+54+7+7+7 */
 hw/usb-ccid.c:        0x10, 0x01, /* u16 bcdCCID; CCID Specification Release 
 Number.
 hw/usb-ccid.c:                     * u16 wLcdLayout; XXYY Number of lines 
 (XX) and ch
 hw/usb-ccid.c:                    /* u16 ep_wMaxPacketSize; */
 hw/usb-ccid.c:        0x40, 0x00, /* u16 ep_wMaxPacketSize; */
 hw/usb-ccid.c:        0x40, 0x00, /* u16 ep_wMaxPacketSize; */
 U playa:qemu alon (usb_ccid.v24)$ git grep \u8\ hw/usb-ccid.c
 hw/usb-ccid.c:        0x12,       /*  u8 bLength; */
 hw/usb-ccid.c:        USB_DT_DEVICE, /*  u8 bDescriptorType; Device */
 hw/usb-ccid.c:        0x00,       /*  u8  bDeviceClass; */
 hw/usb-ccid.c:        0x00,       /*  u8  bDeviceSubClass; */
 hw/usb-ccid.c:        0x00,       /*  u8  bDeviceProtocol; [ low/full speeds 
 only ] *
 [snip 46 more lines with comments]

Sorry for the noise.



[Qemu-devel] [PATCH v23 03/11] usb-ccid: add CCID bus

2011-03-23 Thread 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 al...@redhat.com

---

changes from v20-v21: (Jes Sorenson review)
 * cosmetic changes - fix multi line comments.
 * reorder fields in USBCCIDState
 * add reference to COPYING
 * add --enable-smartcard and --disable-smartcard here (moved
 from last patch)

changes from v19-v20:
 * checkpatch.pl

changes from v18-v19:
 * merged: ccid.h: add copyright, fix define and remove non C89 comments
 * add qdev.desc

changes from v15-v16:

Behavioral changes:
 * fix abort on client answer after card remove
 * enable migration
 * remove side affect code from asserts
 * return consistent self-powered state
 * mask out reserved bits in ccid_set_parameters
 * add missing abRFU in SetParameters (no affect on linux guest)

whitefixes / comments / consts defines:
 * remove stale comment
 * remove ccid_print_pending_answers if no DEBUG_CCID
 * replace printf's with DPRINTF, remove DEBUG_CCID, add verbosity defines
 * use error_report
 * update copyright (most of the code is not original)
 * reword known bug comment
 * add missing closing quote in comment
 * add missing whitespace on one line
 * s/CCID_SetParameter/CCID_SetParameters/
 * add comments
 * use define for max packet size

Comment for return consistent self-powered state:

the Configuration Descriptor bmAttributes claims we are self powered,
but we were returning not self powered to USB_REQ_GET_STATUS control message.

In practice, this message is not sent by a linux 2.6.35.10-74.fc14.x86_64
guest (not tested on other guests), unless you issue lsusb -v as root (for
example).
---
 Makefile.objs |1 +
 configure |   11 +
 hw/ccid.h |   59 +++
 hw/usb-ccid.c | 1419 +
 4 files changed, 1490 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 1fa7a29..489a46b 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -200,6 +200,7 @@ hw-obj-$(CONFIG_APM) += pm_smbus.o apm.o
 hw-obj-$(CONFIG_DMA) += dma.o
 hw-obj-$(CONFIG_HPET) += hpet.o
 hw-obj-$(CONFIG_APPLESMC) += applesmc.o
+hw-obj-$(CONFIG_SMARTCARD) += usb-ccid.o
 
 # PPC devices
 hw-obj-$(CONFIG_OPENPIC) += openpic.o
diff --git a/configure b/configure
index 5a5827f..159549d 100755
--- a/configure
+++ b/configure
@@ -175,6 +175,7 @@ trace_backend=nop
 trace_file=trace
 spice=
 rbd=
+smartcard=
 
 # parse CC options first
 for opt do
@@ -724,6 +725,10 @@ for opt do
   ;;
   --enable-rbd) rbd=yes
   ;;
+  --disable-smartcard) smartcard=no
+  ;;
+  --enable-smartcard) smartcard=yes
+  ;;
   *) echo ERROR: unknown option $opt; show_help=yes
   ;;
   esac
@@ -921,6 +926,8 @@ echoDefault:trace-pid
 echo   --disable-spice  disable spice
 echo   --enable-spice   enable spice
 echo   --enable-rbd enable building the rados block device (rbd)
+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
@@ -2822,6 +2829,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..dbfc13c
--- /dev/null
+++ b/hw/ccid.h
@@ -0,0 +1,59 @@
+/*
+ * CCID Passthru Card Device emulation
+ *
+ * Copyright (c) 2011 Red Hat.
+ * Written by Alon Levy.
+ *
+ * This code is licenced under the GNU LGPL, version 2 or later.
+ */
+
+#ifndef CCID_H
+#define CCID_H
+
+#include qdev.h
+
+typedef struct CCIDCardState CCIDCardState;
+typedef struct CCIDCardInfo CCIDCardInfo;
+
+/*
+ * state of the CCID Card device (i.e. hw/ccid-card-*.c)
+ */
+struct CCIDCardState {
+DeviceState qdev;
+uint32_tslot; /* For future use with multiple slot reader. */
+};
+
+/*
+ * callbacks to be used by the CCID device (hw/usb-ccid.c) to call
+ * into the smartcard device (hw/ccid-card-*.c)
+ */
+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);
+};
+
+/*
+ * API for smartcard calling the CCID device (used by hw/ccid-card-*.c)
+ */
+void