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 <alevy@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).
This commit is contained in:
Alon Levy 2010-10-17 11:40:07 +02:00 committed by Anthony Liguori
parent 65097429ae
commit 367071447e
4 changed files with 1490 additions and 0 deletions

View File

@ -200,6 +200,7 @@ hw-obj-$(CONFIG_APM) += pm_smbus.o apm.o
hw-obj-$(CONFIG_DMA) += dma.o hw-obj-$(CONFIG_DMA) += dma.o
hw-obj-$(CONFIG_HPET) += hpet.o hw-obj-$(CONFIG_HPET) += hpet.o
hw-obj-$(CONFIG_APPLESMC) += applesmc.o hw-obj-$(CONFIG_APPLESMC) += applesmc.o
hw-obj-$(CONFIG_SMARTCARD) += usb-ccid.o
# PPC devices # PPC devices
hw-obj-$(CONFIG_OPENPIC) += openpic.o hw-obj-$(CONFIG_OPENPIC) += openpic.o

11
configure vendored
View File

@ -175,6 +175,7 @@ trace_backend="nop"
trace_file="trace" trace_file="trace"
spice="" spice=""
rbd="" rbd=""
smartcard=""
# parse CC options first # parse CC options first
for opt do for opt do
@ -724,6 +725,10 @@ for opt do
;; ;;
--enable-rbd) rbd="yes" --enable-rbd) rbd="yes"
;; ;;
--disable-smartcard) smartcard="no"
;;
--enable-smartcard) smartcard="yes"
;;
*) echo "ERROR: unknown option $opt"; show_help="yes" *) echo "ERROR: unknown option $opt"; show_help="yes"
;; ;;
esac esac
@ -921,6 +926,8 @@ echo " Default:trace-<pid>"
echo " --disable-spice disable spice" echo " --disable-spice disable spice"
echo " --enable-spice enable spice" echo " --enable-spice enable spice"
echo " --enable-rbd enable building the rados block device (rbd)" echo " --enable-rbd enable building the rados block device (rbd)"
echo " --disable-smartcard disable smartcard support"
echo " --enable-smartcard enable smartcard support"
echo "" echo ""
echo "NOTE: The object files are built at the place where configure is launched" echo "NOTE: The object files are built at the place where configure is launched"
exit 1 exit 1
@ -2824,6 +2831,10 @@ if test "$spice" = "yes" ; then
echo "CONFIG_SPICE=y" >> $config_host_mak echo "CONFIG_SPICE=y" >> $config_host_mak
fi fi
if test "$smartcard" = "yes" ; then
echo "CONFIG_SMARTCARD=y" >> $config_host_mak
fi
# XXX: suppress that # XXX: suppress that
if [ "$bsd" = "yes" ] ; then if [ "$bsd" = "yes" ] ; then
echo "CONFIG_BSD=y" >> $config_host_mak echo "CONFIG_BSD=y" >> $config_host_mak

59
hw/ccid.h Normal file
View File

@ -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_t slot; /* 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 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 */

1419
hw/usb-ccid.c Normal file

File diff suppressed because it is too large Load Diff