usb-ccid (v18)
PATCH 1/16 qdev: add print_options callback
In reply to Alon Levyanother callback added to PropertyInfo, for later use by PROP_TYPE_ENUM. Allows printing of runtime computed options when doing:
qemu -device foo,?
--- hw/qdev.c | 10 +++++++++- hw/qdev.h | 1 + 2 files changed, 10 insertions(+), 1 deletions(-)
hw/qdev.c +9 -1
@@ -187,7 +187,15 @@ int qdev_device_help(QemuOpts *opts)if (!prop->info->parse) {continue ;/* no way to set it, don't show */ } -error_printf ("%s.%s=%s\n" , info->name, prop->name, prop->info->name); +if (prop->info->print_options) { +char buf[256 ]; +int ret; + ret = prop->info->print_options (info, prop, buf,sizeof (buf) -3 ); +error_printf ("%s.%s=%s%s\n" , info->name, prop->name, buf, + ret ==sizeof (buf) -3 ?"..." :"" ); + }else { +error_printf ("%s.%s=%s\n" , info->name, prop->name, prop->info->name); + } }return 1 ; }
hw/qdev.h +1 -0
@@ -109,6 +109,7 @@ struct PropertyInfo {enum PropertyType type;int (*parse)(DeviceState *dev,Property *prop,const char *str);int (*print)(DeviceState *dev,Property *prop,char *dest,size_t len); +int (*print_options)(DeviceInfo *info,Property *prop,char *dest,size_t len);void (*free)(DeviceState *dev,Property *prop); };
Signature · 1 line
1.7.4
cover usb-ccid (v18)
This patchset adds three new devices, usb-ccid, ccid-card-passthru and ccid-card-emulated, providing a CCID bus, a simple passthru protocol implementing card requiring a client, and a standalone emulated card.
It also introduces a new directory libcaccard with CAC card emulation, CAC is a type of ISO 7816 smart card.
Tree for pull: git://anongit.freedesktop.org/~alon/qemu usb_ccid.v18
v17-v18 changes:
* merge vscard_common.h patches.
* actually provide a tree to pull.
v16-v17 changes:
* merged all the "v15->v16" patches
* merged some more wherever it was easy (all same file commits).
* added signed off by to first four patches
* ccid.h: added copyright, removed underscore in defines, and replaced non C89 comments
v15-v16 changes:
* split vscard_common introducing patch for ease of review
* sum of commit logs for the v15-v16 commits: (whitespace fixes
removed for space, see original commit messages in later patches)
* usb-ccid:
* 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)
* vscard_common.h protocol change:
* VSCMsgInit capabilities and magic
* removed ReaderResponse, will use Error instead with code==VSC_SUCCESS.
* added Flush and FlushComplete, remove Reconnect.
* define VSCARD_MAGIC
* added error code VSC_SUCCESS.
* ccid-card-passthru
* return correct size
* return error instead of assert if client sent too large ATR
* don't assert if client sent too large a size, but add asserts for indices to buffer
* reset vscard_in indices on chardev disconnect
* handle init from client
* error if no chardev supplied
* use ntoh, hton
* eradicate reader_id_t
* remove Reconnect usage (removed from VSCARD protocol)
* send VSC_SUCCESS on card insert/remove and reader add/remove
* ccid-card-emulated
* fix error reporting in initfn
v14-v15 changes:
* add patch with --enable-smartcard and --disable-smartcard and only disable ccid-card-emulated if nss not found.
* add patch with description strings
* s/libcaccard/libcacard/ in docs/ccid.txt
v13-v14 changes:
- support device_del/device_add on ccid-card-* and usb-ccid
* usb-ccid:
* lose card reference when card device deleted
* check slot number and deny adding a slot if one is already added.
* ccid-card-*: use qdev_simple_unplug_cb in both emulated and passthru ccid cards, the exitfn already takes care of triggering card removal in the usb dev.
* libcacard:
* remove double include of config-host.mak
* add replay of card events to libcacard to support second and more emulation
* don't initialize more then once (doesn't support it right now, so one thread, NSS thread, is left when device_del is done)
* add VCARD_EMUL_INIT_ALREADY_INITED
* ccid-card-emulated:
* take correct mutexes on signaling to fix deadlocks on device_del
* allow card insertion/removal event without proper reader insertion event
v12-v13 changes:
* libcacard:
* fix Makefile clean to remove vscclient
* fix double include of config-host in Makefile
* usb-ccid: remove attach/detach logic, usb is always attached. Guest doesn't care if there is a reader attached with no card anyway.
* ccid-card-passthru: don't close chr_dev on removal, makes it possible to use device_del/device_add to create remove/insertion for debugging.
v11-v12 changes:
* fix out of tree build
v10-v11 changes:
* fix last patch that removed one of the doc files.
* updated flow table in docs/ccid.txt
v8-v10 changes:
* usb-ccid:
* add slot for future use (Gerd)
* ifdef ENABLE_MIGRATION for migration support on account of usb migration not being ready in general. (Gerd)
* verbosified commit messages. (Gerd)
* put libcacard docs in libcacard commit. (Gerd)
v8-v9 changes:
* Blue Swirl comments:
* white space fixes
* enabled by default, disabled only if missing nss
* forgotten fix from v8 (don't build libcacard.so)
* added a note about device being little endian
* library renamed from libcaccard to libcacard
* squashed both of libcacard patches, they touched different files anyway.
v7-v8 changes:
* Blue Swirl comments:
* usb-ccid: deannonymize some structs
* usb-ccid: coding style change - answer_t and bulk_in_t fixed
* usb-ccid: handle endianess conversion between guest and host
* usb-ccid: s/ccid_bulk_in_copy_out/ccid_bulk_in_copy_to_guest/
* ccid-card-emulated: fix segfault if backend not specified
* ccid-card-emulated: let last reader inserted win
* libcaccard: remove double vscard_common.h
v6->v7 changes:
* external libcaccard became internal directory libcaccard
* statically link object files into qemu
* produce libcaccard.so for usage by external projects
* applied coding style to new code (please check me)
- did not use the qemu options parsing for libcaccard, since it seems to draw large amounts of qemu code (monitor for instance).
v5->v6 changes:
* really remove static debug (I apologize for claiming to have done so before)
v4->v5 changes:
* rebased to latest
* remove static debug in card devices
* fix --enable-smartcard to link
* stall instead of assert when exceeding BULK_OUT_DATA_SIZE
* make ccid_reserve_recv_buf for too large len discard message, not exit
* make ccid_reserve_recv_buf return void*
* fix typo
* remove commented code in VMState
v3->v4:
* remove ccid field in CCIDBus
* remove static debug in bus
* add back docs
v2->v3:
* split into bus (usb-ccid.c, uses ccid.h) and card (ccid-card-passthru.c).
* removed documentation (being revised).
v1->v2:
* 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 (15):
qdev: add print_options callback
qdev: add data pointer to Property
qdev-properties: add PROP_TYPE_ENUM
qdev-properties: parse_enum: don't cast a void*
usb-ccid: add CCID bus
introduce libcacard/vscard_common.h
ccid: add passthru card device
ccid: add ccid-card-emulated device (v2)
ccid: add docs
ccid: configure: add --enable/disable and nss only disable
ccid: add qdev description strings
smartcard,configure: add --enable-smartcard-nss, report only nss smartcard,configure: report only nss
ccid-card-emulated: don't link with NSS if --disable-smartcard-nss ccid.h: add copyright, fix define and remove non C89 comments
Robert Relyea (1):
libcacard: initial commit
Makefile | 6 +- Makefile.objs | 7 + Makefile.target | 2 + configure | 60 ++ docs/ccid.txt | 135 +++++ docs/libcacard.txt | 483 +++++++++++++++ hw/ccid-card-emulated.c | 551 ++++++++++++++++++ hw/ccid-card-passthru.c | 329 +++++++++++ hw/ccid.h | 51 ++ hw/qdev-properties.c | 60 ++ hw/qdev.c | 10 +- hw/qdev.h | 17 + hw/usb-ccid.c | 1353 +++++++++++++++++++++++++++++++++++++++++++ libcacard/Makefile | 14 + libcacard/cac.c | 411 +++++++++++++ libcacard/cac.h | 20 + libcacard/card_7816.c | 780 +++++++++++++++++++++++++ libcacard/card_7816.h | 60 ++ libcacard/card_7816t.h | 163 ++++++ libcacard/event.c | 112 ++++ libcacard/eventt.h | 28 + libcacard/link_test.c | 20 + libcacard/mutex.h | 59 ++ libcacard/passthru.c | 612 +++++++++++++++++++ libcacard/passthru.h | 50 ++ libcacard/vcard.c | 350 +++++++++++ libcacard/vcard.h | 85 +++ libcacard/vcard_emul.h | 62 ++ libcacard/vcard_emul_nss.c | 1192 +++++++++++++++++++++++++++++++++++++ libcacard/vcard_emul_type.c | 60 ++ libcacard/vcard_emul_type.h | 29 + libcacard/vcardt.h | 66 +++ libcacard/vevent.h | 26 + libcacard/vreader.c | 526 +++++++++++++++++ libcacard/vreader.h | 54 ++ libcacard/vreadert.h | 23 + libcacard/vscard_common.h | 167 ++++++ libcacard/vscclient.c | 743 ++++++++++++++++++++++++ 38 files changed, 8773 insertions(+), 3 deletions(-) create mode 100644 docs/ccid.txt create mode 100644 docs/libcacard.txt create mode 100644 hw/ccid-card-emulated.c create mode 100644 hw/ccid-card-passthru.c create mode 100644 hw/ccid.h create mode 100644 hw/usb-ccid.c create mode 100644 libcacard/Makefile create mode 100644 libcacard/cac.c create mode 100644 libcacard/cac.h create mode 100644 libcacard/card_7816.c create mode 100644 libcacard/card_7816.h create mode 100644 libcacard/card_7816t.h create mode 100644 libcacard/event.c create mode 100644 libcacard/eventt.h create mode 100644 libcacard/link_test.c create mode 100644 libcacard/mutex.h create mode 100644 libcacard/passthru.c create mode 100644 libcacard/passthru.h create mode 100644 libcacard/vcard.c create mode 100644 libcacard/vcard.h create mode 100644 libcacard/vcard_emul.h create mode 100644 libcacard/vcard_emul_nss.c create mode 100644 libcacard/vcard_emul_type.c create mode 100644 libcacard/vcard_emul_type.h create mode 100644 libcacard/vcardt.h create mode 100644 libcacard/vevent.h create mode 100644 libcacard/vreader.c create mode 100644 libcacard/vreader.h create mode 100644 libcacard/vreadert.h create mode 100644 libcacard/vscard_common.h create mode 100644 libcacard/vscclient.c
Signature · 1 line
1.7.4
PATCH 2/16 qdev: add data pointer to Property
For later use by PROP_TYPE_ENUM, will store enumeration name/value table there.
--- hw/qdev.h | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
hw/qdev.h +1 -0
@@ -83,6 +83,7 @@ struct Property {int offset;int bitnr;void *defval; +void *data; };enum PropertyType {
Signature · 1 line
1.7.4
PATCH 3/16 qdev-properties: add PROP_TYPE_ENUM
In reply to Alon LevyExample usage:
EnumTable foo_enum_table[] = {
{"bar", 1},
{"buz", 2},
{NULL, 0},
};DEFINE_PROP_ENUM("foo", State, foo, 1, foo_enum_table)
When using qemu -device foodev,? it will appear as:
foodev.foo=bar/buz
--- hw/qdev-properties.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++ hw/qdev.h | 15 ++++++++++++ 2 files changed, 75 insertions(+), 0 deletions(-)
hw/qdev-properties.c +60 -0
@@ -63,6 +63,66 @@ PropertyInfo qdev_prop_bit = { .print = print_bit, }; +/* --- Enumeration --- */ +/* Example usage: +EnumTable foo_enum_table[] = { +{"bar", 1}, +{"buz", 2}, +{NULL, 0}, +}; +DEFINE_PROP_ENUM("foo", State, foo, 1, foo_enum_table), +*/ +static int parse_enum (DeviceState *dev,Property *prop,const char *str) +{ +uint8_t *ptr =qdev_get_prop_ptr (dev, prop); +EnumTable *option = (EnumTable *)prop->data; + +while (option->name !=NULL ) { +if (!strncmp (str, option->name,strlen (option->name))) { + *ptr = option->value; +return 0 ; + } + option++; + } +return -EINVAL ; +} + +static int print_enum (DeviceState *dev,Property *prop,char *dest,size_t len) +{ +uint32_t *p =qdev_get_prop_ptr (dev, prop); +EnumTable *option = (EnumTable *)prop->data; +while (option->name !=NULL ) { +if (*p == option->value) { +return snprintf (dest, len,"%s" , option->name); + } + option++; + } +return 0 ; +} + +static int print_enum_options (DeviceInfo *info,Property *prop,char *dest,size_t len) +{ +int ret =0 ; +EnumTable *option = (EnumTable *)prop->data; +while (option->name !=NULL ) { + ret +=snprintf (dest + ret, len - ret,"%s" , option->name); +if (option[1 ].name !=NULL ) { + ret +=snprintf (dest + ret, len - ret,"/" ); + } + option++; + } +return ret; +} + +PropertyInfo qdev_prop_enum = { + .name ="enum" , + .type =PROP_TYPE_ENUM , + .size =sizeof (uint32_t ), + .parse = parse_enum, + .print = print_enum, + .print_options = print_enum_options, +}; +/* --- 8bit integer --- */ static int parse_uint8 (DeviceState *dev,Property *prop,const char *str)
hw/qdev.h +15 -0
@@ -102,6 +102,7 @@ enum PropertyType {PROP_TYPE_VLAN ,PROP_TYPE_PTR ,PROP_TYPE_BIT , + PROP_TYPE_ENUM, }; struct PropertyInfo {
@@ -121,6 +122,11 @@ typedef struct GlobalProperty {QTAILQ_ENTRY (GlobalProperty) next; } GlobalProperty; +typedef struct EnumTable { +const char *name; +uint32_t value; +}EnumTable ; +/*** Board API. This should go away once we have a machine config file. ***/ DeviceState *qdev_create (BusState *bus,const char *name);
@@ -235,6 +241,7 @@ extern PropertyInfo qdev_prop_drive;extern PropertyInfo qdev_prop_netdev;extern PropertyInfo qdev_prop_vlan;extern PropertyInfo qdev_prop_pci_devfn; +extern PropertyInfo qdev_prop_enum;#define DEFINE_PROP (_name, _state, _field, _prop, _type) { \ .name = (_name), \
@@ -257,6 +264,14 @@ extern PropertyInfo qdev_prop_pci_devfn; + type_check(uint32_t,typeof_field(_state, _field)), \ .defval = (bool[]) { (_defval) }, \ } +#define DEFINE_PROP_ENUM (_name, _state, _field, _defval, _options) { \ + .name = (_name), \ + .info = &(qdev_prop_enum), \ + .offset = offsetof(_state, _field) \ + + type_check(uint32_t,typeof_field(_state, _field)), \ + .defval = (uint32_t[]) { (_defval) }, \ + .data = (void*)(_options), \ + }#define DEFINE_PROP_UINT8 (_n, _s, _f, _d) \ DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint8, uint8_t)
Signature · 1 line
1.7.4
PATCH 4/16 qdev-properties: parse_enum: don't cast a void*
In reply to Alon Levy--- hw/qdev-properties.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
hw/qdev-properties.c +1 -1
@@ -75,7 +75,7 @@ DEFINE_PROP_ENUM("foo", State, foo, 1, foo_enum_table),static int parse_enum (DeviceState *dev,Property *prop,const char *str) {uint8_t *ptr =qdev_get_prop_ptr (dev, prop); -EnumTable *option = (EnumTable *)prop->data; +EnumTable *option = prop->data;while (option->name !=NULL ) {if (!strncmp (str, option->name,strlen (option->name))) {
Signature · 1 line
1.7.4
PATCH 6/16 introduce libcacard/vscard_common.h
In reply to Alon Levy---
v15->v16 changes:
Protocol change:
* VSCMsgInit capabilities and magic
* removed ReaderResponse, will use Error instead with code==VSC_SUCCESS.
* adaded Flush and FlushComplete, remove Reconnect.
* define VSCARD_MAGIC
* added error code VSC_SUCCESS.
Fixes:
* update VSCMsgInit comment
* fix message type enum
* remove underscore from wrapping define
* update copyright
* updated comments.
* Header comment updated
* remove C++ style comment
* fix comment for VSCMsgError
* give names to enums in typedefs
--- libcacard/vscard_common.h | 167 +++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 167 insertions(+), 0 deletions(-) create mode 100644 libcacard/vscard_common.h
libcacard/vscard_common.h new file +167 -0
@@ -0,0 +1,167 @@ +/* Virtual Smart Card protocol definition +* +* This protocol is between a host using virtual smart card readers, +* and a client providing the smart cards, perhaps by emulating them or by +* access to real cards. +* +* Definitions for this protocol: +* Host - user of the card +* Client - owner of the card +* +* The current implementation passes the raw APDU's from 7816 and additionally +* contains messages to setup and teardown readers, handle insertion and +* removal of cards, negotiate the protocol via capabilities and provide +* for error responses. +* +* Copyright (c) 2011 Red Hat. +* +* This code is licensed under the LGPL. +*/ + +#ifndef VSCARD_COMMON_H +#define VSCARD_COMMON_H + +#include <stdint.h> + +#define VERSION_MAJOR_BITS 11 +#define VERSION_MIDDLE_BITS 11 +#define VERSION_MINOR_BITS 10 + +#define MAKE_VERSION (major, middle, minor) \ + ( (major << (VERSION_MINOR_BITS + VERSION_MIDDLE_BITS)) \ + | (middle << VERSION_MINOR_BITS) \ + | (minor) ) + +/** IMPORTANT NOTE on VERSION +* +* The version below MUST be changed whenever a change in this file is made. +* +* The last digit, the minor, is for bug fix changes only. +* +* The middle digit is for backward / forward compatible changes, updates +* to the existing messages, addition of fields. +* +* The major digit is for a breaking change of protocol, presumably +* something that cannot be accomodated with the existing protocol. +*/ + +#define VSCARD_VERSION MAKE_VERSION(0,0,2) + +typedef enum VSCMsgType { + VSC_Init =1 , + VSC_Error, + VSC_ReaderAdd, + VSC_ReaderRemove, +VSC_ATR , + VSC_CardRemove, +VSC_APDU , + VSC_Flush, + VSC_FlushComplete +}VSCMsgType ; + +typedef enum VSCErrorCode { +VSC_SUCCESS =0 , +VSC_GENERAL_ERROR =1 , +VSC_CANNOT_ADD_MORE_READERS , +VSC_CARD_ALREAY_INSERTED , +}VSCErrorCode ; + +#define VSCARD_UNDEFINED_READER_ID 0xffffffff +#define VSCARD_MINIMAL_READER_ID 0 + +#define VSCARD_MAGIC (*(uint32_t*)"VSCD") + +/* Header +* Each message starts with the header. +* type - message type +* reader_id - used by messages that are reader specific +* length - length of payload (not including header, i.e. zero for +* messages containing empty payloads) +*/ +typedef struct VSCMsgHeader { +uint32_t type; +uint32_t reader_id; +uint32_t length; +uint8_t data[0 ]; +}VSCMsgHeader ; + +/* VSCMsgInit Client <-> Host +* Client sends it on connection, with its own capabilities. +* Host replies with VSCMsgInit filling in its capabilities. +* +* It is not meant to be used for negotiation, i.e. sending more then +* once from any side, but could be used for that in the future. +* */ +typedef struct VSCMsgInit { +uint32_t magic; +uint32_t version; +uint32_t capabilities[1 ];/* receiver must check length, +array may grow in the future*/ +}VSCMsgInit ; + +/* VSCMsgError Client <-> Host +* This message is a response to any of: +* Reader Add +* Reader Remove +* Card Remove +* If the operation was successful then VSC_SUCCESS +* is returned, other wise a specific error code. +* */ +typedef struct VSCMsgError { +uint32_t code; +}VSCMsgError ; + +/* VSCMsgReaderAdd Client -> Host +* Host replies with allocated reader id in VSCMsgError with code==SUCCESS. +* +* name - name of the reader on client side, UTF-8 encoded. Only used +* for client presentation (may be translated to the device presented to the +* guest), protocol wise only reader_id is important. +* */ +typedef struct VSCMsgReaderAdd { +uint8_t name[0 ]; +}VSCMsgReaderAdd ; + +/* VSCMsgReaderRemove Client -> Host +* The client's reader has been removed. +* */ +typedef struct VSCMsgReaderRemove { +}VSCMsgReaderRemove ; + +/* VSCMsgATR Client -> Host +* Answer to reset. Sent for card insertion or card reset. The reset/insertion +* happens on the client side, they do not require any action from the host. +* */ +typedef struct VSCMsgATR { +uint8_t atr[0 ]; +}VSCMsgATR ; + +/* VSCMsgCardRemove Client -> Host +* The client card has been removed. +* */ +typedef struct VSCMsgCardRemove { +}VSCMsgCardRemove ; + +/* VSCMsgAPDU Client <-> Host +* Main reason of existance. Transfer a single APDU in either direction. +* */ +typedef struct VSCMsgAPDU { +uint8_t data[0 ]; +}VSCMsgAPDU ; + +/* VSCMsgFlush Host -> Client +* Request client to send a FlushComplete message when it is done +* servicing all outstanding APDUs +* */ +typedef struct VSCMsgFlush { +}VSCMsgFlush ; + +/* VSCMsgFlush Client -> Host +* Client response to Flush after all APDUs have been processed and +* responses sent. +* */ +typedef struct VSCMsgFlushComplete { +}VSCMsgFlushComplete ; + +#endif /* VSCARD_COMMON_H */ +
Signature · 1 line
1.7.4
PATCH 5/16 usb-ccid: add CCID bus
In reply to Alon LevyA 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.
---
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 | 6 + hw/ccid.h | 42 ++ hw/usb-ccid.c | 1352 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 1401 insertions(+), 0 deletions(-) create mode 100644 hw/ccid.h create mode 100644 hw/usb-ccid.c
Makefile.objs +1 -0
@@ -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
configure +6 -0
@@ -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
hw/ccid.h new file +42 -0
42 lines not on this page · raw message
hw/usb-ccid.c new file +1352 -0
1,352 lines not on this page · raw message
Signature · 1 line
1.7.4
PATCH 7/16 ccid: add passthru card device
In reply to Alon LevyThe passthru ccid card is a device sitting on the usb-ccid bus and using a chardevice to communicate with a remote device using the VSCard protocol defined in libcacard/vscard_common.h
Usage docs available in following patch in docs/ccid.txt
---
Changes from v16->v17:
* fix wrong cast when receiving VSC_Error
* ccid-card-passthru: force chardev user wakeup by sending Init see lengthy comment below.
Changes from v15->v16:
Behavioral changes:
* return correct size
* return error instead of assert if client sent too large ATR
* don't assert if client sent too large a size, but add asserts for indices to buffer
* reset vscard_in indices on chardev disconnect
* handle init from client
* error if no chardev supplied
* use ntoh, hton
* eradicate reader_id_t
* remove Reconnect usage (removed from VSCARD protocol)
* send VSC_SUCCESS on card insert/remove and reader add/remove
Style fixes:
* width of line fix
* update copyright
* remove old TODO's
* update file header comment
* use macros for debug levels
* c++ style comment replacement
* update copyright license
* fix ATR size comment
* fix whitespace in struct def
* fix DPRINTF prefix
* line width fix
ccid-card-passthru: force chardev user wakeup by sending Init
The problem: how to wakeup the user of the smartcard when the smartcard device is initialized?
Long term solution: have a callback interface. This was done via the deprecated so called chardev ioctl interface.
Short term solution: do a write. Specifically we write an Init message. And we change the client to send it's own Init message regardless of receiving this one. Additional Init messages will be regarded as acceptable, the first one received after connection establishment is the determining one wrt capabilities.
--- Makefile.objs | 2 +- hw/ccid-card-passthru.c | 329 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 330 insertions(+), 1 deletions(-) create mode 100644 hw/ccid-card-passthru.c
Makefile.objs +1 -1
@@ -195,7 +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 +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 +329 -0
329 lines not on this page · raw message
Signature · 1 line
1.7.4
PATCH 9/16 ccid: add ccid-card-emulated device (v2)
In reply to Alon LevyThis devices uses libcacard (internal) to emulate a smartcard conforming to the CAC standard. It attaches to the usb-ccid bus. Usage instructions (example command lines) are in the following patch in docs/ccid.txt. It uses libcacard which uses nss, so it can work with both hw cards and certificates (files).
---
changes from v16->v17:
* use PROP_TYPE_ENUM for backend
changes from v15->v16:
* fix error reporting in initfn
* bump copyright year
* update copyright license
changes from v1:
* remove stale comments, use only c-style comments
* bugfix, forgot to set recv_len
* change reader name to 'Virtual Reader'
--- Makefile.objs | 2 +- hw/ccid-card-emulated.c | 550 +++++++++++++++++++++++++++++++++++++++++++++++ hw/ccid-card-passthru.c | 1 - 3 files changed, 551 insertions(+), 2 deletions(-) create mode 100644 hw/ccid-card-emulated.c
Makefile.objs +1 -1
@@ -195,7 +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 ccid-card-passthru.o +hw-obj-$(CONFIG_SMARTCARD) += usb-ccid.o ccid-card-passthru.o ccid-card-emulated.o # PPC devices hw-obj-$(CONFIG_OPENPIC) += openpic.o
hw/ccid-card-emulated.c new file +550 -0
550 lines not on this page · raw message
hw/ccid-card-passthru.c +0 -1
@@ -313,7 +313,6 @@ static CCIDCardInfo passthru_card_info = { .exitfn = passthru_exitfn, .get_atr = passthru_get_atr, .apdu_from_guest = passthru_apdu_from_guest, - .qdev.unplug = qdev_simple_unplug_cb, .qdev.props = (Property []) {DEFINE_PROP_CHR ("chardev" , PassthruState, cs),DEFINE_PROP_UINT8 ("debug" , PassthruState, debug,0 ),
Signature · 1 line
1.7.4
PATCH 10/16 ccid: add docs
In reply to Alon LevyAdd documentation for the usb-ccid device and accompanying two card devices, ccid-card-emulated and ccid-card-passthru.
--- docs/ccid.txt | 135 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 135 insertions(+), 0 deletions(-) create mode 100644 docs/ccid.txt
docs/ccid.txt new file +135 -0
@@ -0,0 +1,135 @@ +Qemu CCID Device Documentation. + +Contents +1. USB CCID device +2. Building +3. Using ccid-card-emulated with hardware +4. Using ccid-card-emulated with certificates +5. Using ccid-card-passthru with client side hardware +6. Using ccid-card-passthru with client side certificates +7. Passthrough protocol scenario +8. libcacard + +1. USB CCID device + +The USB CCID device is a USB device implementing the CCID specification, which +lets one connect smart card readers that implement the same spec. For more +information see the specification: + + Universal Serial Bus + Device Class: Smart Card + CCID + Specification for + Integrated Circuit(s) Cards Interface Devices + Revision 1.1 + April 22rd, 2005 + +Smartcard are used for authentication, single sign on, decryption in +public/private schemes and digital signatures. A smartcard reader on the client +cannot be used on a guest with simple usb passthrough since it will then not be +available on the client, possibly locking the computer when it is "removed". On +the other hand this device can let you use the smartcard on both the client and +the guest machine. It is also possible to have a completely virtual smart card +reader and smart card (i.e. not backed by a physical device) using this device. + +2. Building + +The cryptographic functions and access to the physical card is done via NSS. + +Installing NSS: + +In redhat/fedora: + yum install nss-devel +In ubuntu/debian: + apt-get install libnss3-dev + (not tested on ubuntu) + +Configuring and building: + ./configure --enable-smartcard && make + +3. Using ccid-card-emulated with hardware + +Assuming you have a working smartcard on the host with the current +user, using NSS, qemu acts as another NSS client using ccid-card-emulated: + + qemu -usb -device usb-ccid -device ccid-card-emualated + +4. Using ccid-card-emulated with certificates + +You must create the certificates. This is a one time process. We use NSS +certificates: + + certutil -d /etc/pki/nssdb -x -t "CT,CT,CT" -S -s "CN=cert1" -n cert1 + +Note: you must have exactly three certificates. + +Assuming the current user can access the certificates (use certutil -L to +verify), you can use the emulated card type with the certificates backend: + + qemu -usb -device usb-ccid -device ccid-card-emulated,backend=certificates,cert1=cert1,cert2=cert2,cert3=cert3 + +5. Using ccid-card-passthru with client side hardware + +on the host specify the ccid-card-passthru device with a suitable chardev: + + qemu -chardev socket,server,host=0.0.0.0,port=2001,id=ccid,nowait -usb -device usb-ccid -device ccid-card-passthru,chardev=ccid + +on the client run vscclient, built when you built the libcacard library: + libcacard/vscclient <qemu-host> 2001 + +6. Using ccid-card-passthru with client side certificates + +Run qemu as per #5, and run vscclient as follows: +(Note: vscclient command line interface is in a state of change) + + libcacard/vscclient -e "db=\"/etc/pki/nssdb\" use_hw=no soft=(,Test,CAC,,cert1,cert2,cert3)" <qemu-host> 2001 + +7. Passthrough protocol scenario + +This is a typical interchange of messages when using the passthru card device. +usb-ccid is a usb device. It defaults to an unattached usb device on startup. +usb-ccid expects a chardev and expects the protocol defined in +cac_card/vscard_common.h to be passed over that. +The usb-ccid device can be in one of three modes: + * detached + * attached with no card + * attached with card + +A typical interchange is: (the arrow shows who started each exchange, it can be client +originated or guest originated) + +client event | vscclient | passthru | usb-ccid | guest event +---------------------------------------------------------------------------------------------- + | VSC_Init | | | + | VSC_ReaderAdd | | attach | + | | | | sees new usb device. +card inserted -> | | | | + | VSC_ATR | insert | insert | see new card + | | | | + | VSC_APDU | VSC_APDU | | <- guest sends APDU +client<->physical | | | | +card APDU exchange| | | | +client response ->| VSC_APDU | VSC_APDU | | receive APDU response + ... + [APDU<->APDU repeats several times] + ... +card removed -> | | | | + | VSC_CardRemove | remove | remove | card removed + ... + [(card insert, apdu's, card remove) repeat] + ... +kill/quit | | | | + vscclient | | | | + | VSC_ReaderRemove | | detach | + | | | | usb device removed. + + +8. libcacard + +ccid-card-passthru and vscclient use libcacard as the card emulator. +libcacard implements a completely virtual CAC (DoD standard for smart cards) +compliant card and uses NSS to actually retrive certificates and do any +encryption using the backend (real reader + card or file backed certificates). + +For documentation of cac_card see README in libcacard subdirectory. +
Signature · 1 line
1.7.4
PATCH 12/16 ccid: add qdev description strings
In reply to Alon Levy--- hw/ccid-card-emulated.c | 1 + hw/ccid-card-passthru.c | 1 + hw/usb-ccid.c | 1 + 3 files changed, 3 insertions(+), 0 deletions(-)
hw/ccid-card-emulated.c +1 -0
@@ -525,6 +525,7 @@ EnumTable backend_enum_table[] = {static CCIDCardInfo emulated_card_info = { .qdev.name =EMULATED_DEV_NAME , + .qdev.desc ="emulated smartcard" , .qdev.size =sizeof (EmulatedState), .initfn = emulated_initfn, .exitfn = emulated_exitfn,
hw/ccid-card-passthru.c +1 -0
@@ -307,6 +307,7 @@ static VMStateDescription passthru_vmstate = {static CCIDCardInfo passthru_card_info = { .qdev.name =PASSTHRU_DEV_NAME , + .qdev.desc ="passthrough smartcard" , .qdev.size =sizeof (PassthruState), .qdev.vmsd = &passthru_vmstate, .initfn = passthru_initfn,
hw/usb-ccid.c +1 -0
@@ -1330,6 +1330,7 @@ static VMStateDescription ccid_vmstate = {static struct USBDeviceInfo ccid_info = { .product_desc ="QEMU USB CCID" , .qdev.name =CCID_DEV_NAME , + .qdev.desc ="CCID Rev 1.1 smartcard reader" , .qdev.size =sizeof (USBCCIDState), .init = ccid_initfn, .handle_packet = usb_generic_handle_packet,
Signature · 1 line
1.7.4
PATCH 13/16 smartcard, configure: add --enable-smartcard-nss, report only nss
In reply to Alon Levy--- configure | 28 ++++++++++++++++++++-------- 1 files changed, 20 insertions(+), 8 deletions(-)
configure +20 -8
@@ -174,8 +174,8 @@ trace_backend="nop" trace_file="trace" spice="" rbd="" -smartcard="yes" -smartcard_nss="yes" +smartcard="" +smartcard_nss="" # parse CC options first for opt do
@@ -725,6 +725,10 @@ for opt do ;; --enable-smartcard) smartcard="yes" ;; + --disable-smartcard-nss) smartcard_nss="no" + ;; + --enable-smartcard-nss) smartcard_nss="yes" + ;; *) echo "ERROR: unknown option $opt"; show_help="yes" ;; esac
@@ -922,6 +926,8 @@ 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 " --disable-smartcard-nss disable smartcard nss support" +echo " --enable-smartcard-nss enable smartcard nss support" echo "" echo "NOTE: The object files are built at the place where configure is launched" exit 1
@@ -2249,16 +2255,22 @@ fi # check for libcacard for smartcard support if test "$smartcard" != "no" ; then + smartcard="yes" smartcard_cflags="-I\$(SRC_PATH)/libcacard" libcacard_libs=$($pkg_config --libs nss 2>/dev/null) libcacard_cflags=$($pkg_config --cflags nss 2>/dev/null) # TODO - what's the minimal nss version we support? - if $pkg_config --atleast-version=3.12.8 nss >/dev/null 2>&1 ; then - smartcard_nss="yes" - QEMU_CFLAGS="$QEMU_CFLAGS $smartcard_cflags $libcacard_cflags" - LIBS="$libcacard_libs $LIBS" - else - smartcard_nss="no" + if test "$smartcard_nss" != "no"; then + if $pkg_config --atleast-version=3.12.8 nss >/dev/null 2>&1 ; then + smartcard_nss="yes" + QEMU_CFLAGS="$QEMU_CFLAGS $smartcard_cflags $libcacard_cflags" + LIBS="$libcacard_libs $LIBS" + else + if test "$smartcard_nss" == "yes"; then + feature_not_found "nss" + fi + smartcard_nss="no" + fi fi fi if test "$smartcard" == "no" ; then
Signature · 1 line
1.7.4
PATCH 14/16 smartcard,configure: report only nss
In reply to Alon Levy--- configure | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-)
configure +1 -2
@@ -2510,8 +2510,7 @@ echo "Trace output file $trace_file-<pid>" echo "spice support $spice" echo "rbd support $rbd" echo "xfsctl support $xfs" -echo "smartcard support $smartcard" -echo " \_ nss support $smartcard_nss" +echo "nss used $smartcard_nss" if test $sdl_too_old = "yes"; then echo "-> Your SDL version is too old - please upgrade to have SDL support"
Signature · 1 line
1.7.4
PATCH 15/16 ccid-card-emulated: don't link with NSS if --disable-smartcard-nss
In reply to Alon Levy--- configure | 7 ++++--- 1 files changed, 4 insertions(+), 3 deletions(-)
configure +4 -3
@@ -2256,13 +2256,14 @@ fi # check for libcacard for smartcard support if test "$smartcard" != "no" ; then smartcard="yes" - smartcard_cflags="-I\$(SRC_PATH)/libcacard" - libcacard_libs=$($pkg_config --libs nss 2>/dev/null) - libcacard_cflags=$($pkg_config --cflags nss 2>/dev/null) + smartcard_cflags="" # TODO - what's the minimal nss version we support? if test "$smartcard_nss" != "no"; then if $pkg_config --atleast-version=3.12.8 nss >/dev/null 2>&1 ; then smartcard_nss="yes" + smartcard_cflags="-I\$(SRC_PATH)/libcacard" + libcacard_libs=$($pkg_config --libs nss 2>/dev/null) + libcacard_cflags=$($pkg_config --cflags nss 2>/dev/null) QEMU_CFLAGS="$QEMU_CFLAGS $smartcard_cflags $libcacard_cflags" LIBS="$libcacard_libs $LIBS" else
Signature · 1 line
1.7.4
PATCH 16/16 ccid.h: add copyright, fix define and remove non C89 comments
In reply to Alon Levy--- hw/ccid.h | 17 +++++++++++++---- 1 files changed, 13 insertions(+), 4 deletions(-)
hw/ccid.h +13 -4
@@ -1,5 +1,14 @@ -#ifndef __CCID_H__ -#define __CCID_H__ +/* +* 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"
@@ -10,7 +19,7 @@ typedef struct CCIDCardInfo CCIDCardInfo;*/ struct CCIDCardState {DeviceState qdev; -uint32_t slot;// For future use with multiple slot reader. +uint32_t slot;/* For future use with multiple slot reader. */ };/* callbacks to be used by the CCID device (hw/usb-ccid.c) to call
@@ -38,5 +47,5 @@ void ccid_card_qdev_register(CCIDCardInfo *card);int ccid_card_ccid_attach (CCIDCardState *card);void ccid_card_ccid_detach (CCIDCardState *card); -#endif // __CCID_H__ +#endif /* CCID_H */
Signature · 1 line
1.7.4
PATCH 11/16 ccid: configure: add --enable/disable and nss only disable
In reply to Alon Levyadd --enable-smartcard and --disable-smartcard flags, and let the nss check only disable building the ccid-card-emulated device, since both the usb-ccid and ccid-card-passthru don't depend on it.
--- Makefile.objs | 3 ++- Makefile.target | 2 +- configure | 41 +++++++++++++++++++++++++++++------------ 3 files changed, 32 insertions(+), 14 deletions(-)
Makefile.objs +2 -1
@@ -195,7 +195,8 @@ 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 ccid-card-passthru.o ccid-card-emulated.o +hw-obj-$(CONFIG_SMARTCARD) += usb-ccid.o ccid-card-passthru.o +hw-obj-$(CONFIG_SMARTCARD_NSS) += ccid-card-emulated.o # PPC devices hw-obj-$(CONFIG_OPENPIC) += openpic.o
Makefile.target +1 -1
@@ -340,7 +340,7 @@ obj-y += $(addprefix $(HWDIR)/, $(hw-obj-y)) endif # CONFIG_SOFTMMU -obj-y += $(addprefix ../libcacard/, $(libcacard-$(CONFIG_SMARTCARD))) +obj-y += $(addprefix ../libcacard/, $(libcacard-$(CONFIG_SMARTCARD_NSS))) obj-y += $(addprefix ../, $(trace-obj-y)) obj-$(CONFIG_GDBSTUB_XML) += gdbstub-xml.o
configure +29 -12
89 lines not on this page · raw message
Signature · 1 line
1.7.4
PATCH 8/16 libcacard: initial commit
In reply to Alon LevyFrom: Robert Relyea <[email protected]>
libcacard emulates a Common Access Card (CAC) which is a standard for smartcards. It is used by the emulated ccid card introduced in a following patch. Docs are available in docs/libcacard.txt
---
changes from v15->v16:
Build:
* don't erase self with distclean
* fix make clean after make distclean
* Makefile: make vscclient link quiet
Behavioral:
* vcard_emul_nss: load coolkey in more situations
* vscclient:
* use hton,ntoh
* send init on connect, only start vevent thread on response
* read payload after header check, before type switch
* remove Reconnect
* update for vscard_common changes, empty Flush implementation
Style/Whitespace:
* fix wrong variable usage
* remove unused variable
* use only C style comments
* add copyright header
* fix tabulation
--- Makefile | 6 +- Makefile.objs | 5 + Makefile.target | 2 + configure | 25 + docs/libcacard.txt | 483 +++++++++++++++++ libcacard/Makefile | 14 + libcacard/cac.c | 411 +++++++++++++++ libcacard/cac.h | 20 + libcacard/card_7816.c | 780 ++++++++++++++++++++++++++++ libcacard/card_7816.h | 60 +++ libcacard/card_7816t.h | 163 ++++++ libcacard/event.c | 112 ++++ libcacard/eventt.h | 28 + libcacard/link_test.c | 20 + libcacard/mutex.h | 59 +++ libcacard/passthru.c | 612 ++++++++++++++++++++++ libcacard/passthru.h | 50 ++ libcacard/vcard.c | 350 +++++++++++++ libcacard/vcard.h | 85 +++ libcacard/vcard_emul.h | 62 +++ libcacard/vcard_emul_nss.c | 1192 +++++++++++++++++++++++++++++++++++++++++++ libcacard/vcard_emul_type.c | 60 +++ libcacard/vcard_emul_type.h | 29 + libcacard/vcardt.h | 66 +++ libcacard/vevent.h | 26 + libcacard/vreader.c | 526 +++++++++++++++++++ libcacard/vreader.h | 54 ++ libcacard/vreadert.h | 23 + libcacard/vscclient.c | 743 +++++++++++++++++++++++++++ 29 files changed, 6064 insertions(+), 2 deletions(-) create mode 100644 docs/libcacard.txt create mode 100644 libcacard/Makefile create mode 100644 libcacard/cac.c create mode 100644 libcacard/cac.h create mode 100644 libcacard/card_7816.c create mode 100644 libcacard/card_7816.h create mode 100644 libcacard/card_7816t.h create mode 100644 libcacard/event.c create mode 100644 libcacard/eventt.h create mode 100644 libcacard/link_test.c create mode 100644 libcacard/mutex.h create mode 100644 libcacard/passthru.c create mode 100644 libcacard/passthru.h create mode 100644 libcacard/vcard.c create mode 100644 libcacard/vcard.h create mode 100644 libcacard/vcard_emul.h create mode 100644 libcacard/vcard_emul_nss.c create mode 100644 libcacard/vcard_emul_type.c create mode 100644 libcacard/vcard_emul_type.h create mode 100644 libcacard/vcardt.h create mode 100644 libcacard/vevent.h create mode 100644 libcacard/vreader.c create mode 100644 libcacard/vreader.h create mode 100644 libcacard/vreadert.h create mode 100644 libcacard/vscclient.c
Makefile +4 -2
@@ -173,6 +173,8 @@ check-qlist: check-qlist.o qlist.o qint.o $(CHECK_PROG_DEPS) check-qfloat: check-qfloat.o qfloat.o $(CHECK_PROG_DEPS) check-qjson: check-qjson.o qfloat.o qint.o qdict.o qstring.o qlist.o qbool.o qjson.o json-streamer.o json-lexer.o json-parser.o $(CHECK_PROG_DEPS) +QEMULIBS=libhw32 libhw64 libuser libdis libdis-user + clean: # avoid old build problems by removing potentially incorrect old files rm -f config.mak op-i386.h opc-i386.h gen-op-i386.h op-arm.h opc-arm.h gen-op-arm.h
@@ -184,7 +186,7 @@ clean: rm -f trace-dtrace.dtrace trace-dtrace.dtrace-timestamp rm -f trace-dtrace.h trace-dtrace.h-timestamp $(MAKE) -C tests clean - for d in $(ALL_SUBDIRS) libhw32 libhw64 libuser libdis libdis-user; do \ + for d in $(ALL_SUBDIRS) $(QEMULIBS) libcacard; do \ if test -d $$d; then $(MAKE) -C $$d $@ || exit 1; fi; \ rm -f $$d/qemu-options.def; \ done
@@ -195,7 +197,7 @@ distclean: clean rm -f roms/seabios/config.mak roms/vgabios/config.mak rm -f qemu-doc.info qemu-doc.aux qemu-doc.cp qemu-doc.dvi qemu-doc.fn qemu-doc.info qemu-doc.ky qemu-doc.log qemu-doc.pdf qemu-doc.pg qemu-doc.toc qemu-doc.tp qemu-doc.vr rm -f qemu-tech.info qemu-tech.aux qemu-tech.cp qemu-tech.dvi qemu-tech.fn qemu-tech.info qemu-tech.ky qemu-tech.log qemu-tech.pdf qemu-tech.pg qemu-tech.toc qemu-tech.tp qemu-tech.vr - for d in $(TARGET_DIRS) libhw32 libhw64 libuser libdis libdis-user; do \ + for d in $(TARGET_DIRS) $(QEMULIBS); do \ rm -rf $$d || exit 1 ; \ done
Makefile.objs +5 -0
@@ -313,6 +313,11 @@ user-obj-y += qemu-timer-common.o endif endif +###################################################################### +# smartcard + +libcacard-y = cac.o event.o passthru.o vcard.o vreader.o vcard_emul_nss.o vcard_emul_type.o card_7816.o + vl.o: QEMU_CFLAGS+=$(GPROF_CFLAGS) vl.o: QEMU_CFLAGS+=$(SDL_CFLAGS)
Makefile.target +2 -0
@@ -340,6 +340,8 @@ obj-y += $(addprefix $(HWDIR)/, $(hw-obj-y)) endif # CONFIG_SOFTMMU +obj-y += $(addprefix ../libcacard/, $(libcacard-$(CONFIG_SMARTCARD))) + obj-y += $(addprefix ../, $(trace-obj-y)) obj-$(CONFIG_GDBSTUB_XML) += gdbstub-xml.o
configure +25 -0
@@ -2240,6 +2240,19 @@ EOF fi fi +# check for libcacard for smartcard support +smartcard_cflags="-I\$(SRC_PATH)/libcacard" +libcacard_libs=$($pkgconfig --libs nss 2>/dev/null) +libcacard_cflags=$($pkgconfig --cflags nss) +# TODO - what's the minimal nss version we support? +if $pkgconfig --atleast-version=3.12.8 nss; then + smartcard="yes" + QEMU_CFLAGS="$QEMU_CFLAGS $smartcard_cflags $libcacard_cflags" + LIBS="$libcacard_libs $LIBS" +else + smartcard="no" +fi + ########################################## ##########################################
@@ -3075,6 +3088,11 @@ fi if test "$target_darwin_user" = "yes" ; then echo "CONFIG_DARWIN_USER=y" >> $config_target_mak fi +if test "$smartcard" = "yes" ; then + echo "subdir-$target: subdir-libcacard" >> $config_host_mak + echo "libcacard_libs=$libcacard_libs" >> $config_host_mak + echo "libcacard_cflags=$libcacard_cflags" >> $config_host_mak +fi list="" if test ! -z "$gdb_xml_files" ; then for x in $gdb_xml_files; do
@@ -3288,6 +3306,13 @@ for hwlib in 32 64; do echo "QEMU_CFLAGS+=-DTARGET_PHYS_ADDR_BITS=$hwlib" > $d/config.mak done +if [ $source_path != $workdir ]; then + # out of tree build + mkdir -p libcacard + rm -f libcacard/Makefile + ln -s $source_path/libcacard/Makefile libcacard/Makefile +fi + d=libuser mkdir -p $d symlink $source_path/Makefile.user $d/Makefile
docs/libcacard.txt new file +483 -0
483 lines not on this page · raw message
libcacard/Makefile new file +14 -0
@@ -0,0 +1,14 @@ +-include ../config-host.mak +-include $(SRC_PATH)/Makefile.objs +-include $(SRC_PATH)/rules.mak + +$(call set-vpath, $(SRC_PATH):$(SRC_PATH)/libcacard) + +vscclient: $(libcacard-y) vscclient.o + $(call quiet-command,$(CC) $(libcacard_libs) -o $@ $^," LINK $(TARGET_DIR)$@") + +all: vscclient + +clean: + rm -f *.o */*.o *.d */*.d *.a */*.a *~ */*~ vscclient +
libcacard/cac.c new file +411 -0
411 lines not on this page · raw message
libcacard/cac.h new file +20 -0
@@ -0,0 +1,20 @@ +/* +* defines the entry point for the cac card. Only used by cac.c anc +* vcard_emul_type.c +*/ +#ifndef CAC_H +#define CAC_H 1 +#include "vcard.h" +#include "vreader.h" +/* +* Initialize the cac card. This is the only public function in this file. All +* the rest are connected through function pointers. +*/ +VCardStatus cac_card_init (VReader *reader,VCard *card,const char *params, +unsigned char *const *cert,int cert_len[], +VCardKey *key[]/* adopt the keys*/ , +int cert_count); + +/* not yet implemented */ +VCardStatus cac_is_cac_card (VReader *reader); +#endif
libcacard/card_7816.c new file +780 -0
780 lines not on this page · raw message
libcacard/card_7816.h new file +60 -0
60 lines not on this page · raw message
libcacard/card_7816t.h new file +163 -0
163 lines not on this page · raw message
libcacard/event.c new file +112 -0
112 lines not on this page · raw message
libcacard/eventt.h new file +28 -0
@@ -0,0 +1,28 @@ +/* +* +*/ + +#ifndef EVENTT_H +#define EVENTT_H 1 +#include "vreadert.h" +#include "vcardt.h" + +typedef struct VEventStruct VEvent ; + +typedef enum { +VEVENT_READER_INSERT , +VEVENT_READER_REMOVE , +VEVENT_CARD_INSERT , +VEVENT_CARD_REMOVE , +VEVENT_LAST , +}VEventType ; + +struct VEventStruct { +VEvent *next; +VEventType type; +VReader *reader; +VCard *card; +}; +#endif + +
libcacard/link_test.c new file +20 -0
@@ -0,0 +1,20 @@ +/* +* +*/ +#include <stdio.h> +#include "vcard.h" + +VCardStatus cac_card_init (const char *flags,VCard *card, +const unsigned char *cert[], +int cert_len[],VCardKey *key[]/* adopt the keys*/ , +int cert_count); +/* +* this will crash... just test the linkage right now +*/ + +main(int argc, char **argv) +{ + VCard *card; /* no constructor yet */ +cac_card_init ("" , card,NULL ,0 ,NULL ,0 ); +} +
libcacard/mutex.h new file +59 -0
59 lines not on this page · raw message
libcacard/passthru.c new file +612 -0
612 lines not on this page · raw message
libcacard/passthru.h new file +50 -0
50 lines not on this page · raw message
libcacard/vcard.c new file +350 -0
102 lines not on this page · raw message
libcacard/vcard.h new file +85 -0
85 lines not on this page · raw message
libcacard/vcard_emul.h new file +62 -0
62 lines not on this page · raw message
libcacard/vcard_emul_nss.c new file +1192 -0
1,192 lines not on this page · raw message
libcacard/vcard_emul_type.c new file +60 -0
60 lines not on this page · raw message
libcacard/vcardt.h new file +66 -0
66 lines not on this page · raw message
libcacard/vreader.c new file +526 -0
526 lines not on this page · raw message
libcacard/vreader.h new file +54 -0
54 lines not on this page · raw message
libcacard/vscclient.c new file +743 -0
743 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.7.4
Part of the diff is not shown here. View the raw message.
Re: [Qemu-devel] [PATCH 03/16] qdev-properties: add PROP_TYPE_ENUM
In reply to Alon LevyI haven't been able to follow the evolution of this series, my apologies if I'm missing things already discussed.
Quoted 29 lines · Alon Levy
Example usage:
EnumTable foo_enum_table[] = { {"bar", 1}, {"buz", 2}, {NULL, 0}, };
DEFINE_PROP_ENUM("foo", State, foo, 1, foo_enum_table)When using qemu -device foodev,? it will appear as:
foodev.foo=bar/buzSigned-off-by Alon Levy <[email protected]>--- hw/qdev-properties.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++ hw/qdev.h | 15 ++++++++++++ 2 files changed, 75 insertions(+), 0 deletions(-)hw/qdev-properties.c +2
-0@@ -63,6 +63,66 @@ PropertyInfo qdev_prop_bit = { .print = print_bit, }; +/* --- Enumeration --- */ +/* Example usage:
hw/qdev-properties.c PropertyInfo qdev_prop_bit = { · line 77
Quoted 10 lines
hw/qdev-properties.c +10
-0+EnumTable foo_enum_table[] = { +{"bar", 1}, +{"buz", 2}, +{NULL, 0}, +}; +DEFINE_PROP_ENUM("foo", State, foo, 1, foo_enum_table), +*/ +static int parse_enum (DeviceState *dev,Property *prop,const char *str) +{ +uint8_t *ptr =qdev_get_prop_ptr (dev, prop);
uint8_t is inconsistent with print_enum() and DEFINE_PROP_ENUM(), which both use uint32_t.
hw/qdev-properties.c PropertyInfo qdev_prop_bit = { · line 78
Quoted 1 line
hw/qdev-properties.c +1
-0+EnumTable *option = (EnumTable *)prop->data;
Please don't cast from void * to pointer type (this isn't C++).
Not thrilled about the "void *data", to be honest. Smells like premature generality to me.
hw/qdev-properties.c PropertyInfo qdev_prop_bit = { · line 81
Quoted 3 lines
hw/qdev-properties.c +3
-0+ +while (option->name !=NULL ) { +if (!strncmp (str, option->name,strlen (option->name))) {
Why strncmp() and not straight strcmp()?
Quoted 9 lines
hw/qdev-properties.c +9
-0+ *ptr = option->value; +return 0 ; + } + option++; + } +return -EINVAL ; +} + +static int print_enum (DeviceState *dev,Property *prop,char *dest,size_t len)
hw/qdev-properties.c PropertyInfo qdev_prop_bit = { · line 100
Quoted 10 lines
hw/qdev-properties.c +10
-0+{ +uint32_t *p =qdev_get_prop_ptr (dev, prop); +EnumTable *option = (EnumTable *)prop->data; +while (option->name !=NULL ) { +if (*p == option->value) { +return snprintf (dest, len,"%s" , option->name); + } + option++; + } +return 0 ;
Bug: must dest[0] = 0 when returning 0.
hw/qdev-properties.c PropertyInfo qdev_prop_bit = { · line 106
Quoted 6 lines
hw/qdev-properties.c +6
-0+} + +static int print_enum_options (DeviceInfo *info,Property *prop,char *dest,size_t len) +{ +int ret =0 ; +EnumTable *option = (EnumTable *)prop->data;
Please don't cast from void * to pointer type (this isn't C++).
Quoted 55 lines
hw/qdev-properties.c +19
-0+while (option->name !=NULL ) { + ret +=snprintf (dest + ret, len - ret,"%s" , option->name); +if (option[1 ].name !=NULL ) { + ret +=snprintf (dest + ret, len - ret,"/" ); + } + option++; + } +return ret; +} + +PropertyInfo qdev_prop_enum = { + .name ="enum" , + .type =PROP_TYPE_ENUM , + .size =sizeof (uint32_t ), + .parse = parse_enum, + .print = print_enum, + .print_options = print_enum_options, +}; +/* --- 8bit integer --- */ static int parse_uint8 (DeviceState *dev,Property *prop,const char *str)hw/qdev.h +7
-0@@ -102,6 +102,7 @@ enum PropertyType {PROP_TYPE_VLAN ,PROP_TYPE_PTR ,PROP_TYPE_BIT , + PROP_TYPE_ENUM, }; struct PropertyInfo {@@ -121,6 +122,11 @@ typedef struct GlobalProperty {QTAILQ_ENTRY (GlobalProperty) next; } GlobalProperty; +typedef struct EnumTable { +const char *name; +uint32_t value; +}EnumTable ; +/*** Board API. This should go away once we have a machine config file. ***/ DeviceState *qdev_create (BusState *bus,const char *name);@@ -235,6 +241,7 @@ extern PropertyInfo qdev_prop_drive;extern PropertyInfo qdev_prop_netdev;extern PropertyInfo qdev_prop_vlan;extern PropertyInfo qdev_prop_pci_devfn; +extern PropertyInfo qdev_prop_enum;#define DEFINE_PROP (_name, _state, _field, _prop, _type) { \ .name = (_name), \
hw/qdev.h extern PropertyInfo qdev_prop_pci_devfn; · line 273
Quoted 10 lines
hw/qdev.h +7
-0@@ -257,6 +264,14 @@ extern PropertyInfo qdev_prop_pci_devfn; + type_check(uint32_t,typeof_field(_state, _field)), \ .defval = (bool[]) { (_defval) }, \ } +#define DEFINE_PROP_ENUM (_name, _state, _field, _defval, _options) { \ + .name = (_name), \ + .info = &(qdev_prop_enum), \ + .offset = offsetof(_state, _field) \ + + type_check(uint32_t,typeof_field(_state, _field)), \ + .defval = (uint32_t[]) { (_defval) }, \ + .data = (void*)(_options), \
Please don't cast from pointer type to void * (this isn't C++). If someone accidentally passes an integral argument for _options (forgotten operator &), the cast suppresses the warning.
hw/qdev.h extern PropertyInfo qdev_prop_pci_devfn; · line 277
Quoted 4 lines
hw/qdev.h +1
-0+ }#define DEFINE_PROP_UINT8 (_n, _s, _f, _d) \ DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint8, uint8_t)
Okay, let's examine how your enumeration properties work.
An enumeration property describes a uint32_t field of the state object. Differences to ordinary properties defined with DEFINE_PROP_UINT32:
* info is qdev_prop_enum instead of qdev_prop_uint32. Differences between the two:
- parse, print: symbolic names vs. numbers
- name, print_options: only for -device DRIVER,\? (and name's use there isn't particularly helpful)
* data points to an EnumTable, which is a map string <-> number. Thus, the actual enumeration is attached to the property declaration, not the property type (in programming languages, we commonly attach it to the type, not the variable declaration). Since it's a table it can be used for multiple properties with minimal fuss. Works for me.
What if we want to enumerate values of fields with types other than uint32_t?
C enumeration types, in particular. Tricky, because width and signedness of enum types is implementation-defined, and different enum types may differ there.
Perhaps what we really need is a way to define arbitrary integer type properties with an EnumTable attached.
Re: [Qemu-devel] [PATCH 03/16] qdev-properties: add PROP_TYPE_ENUM
Quoted 32 lines · Markus Armbruster
I haven't been able to follow the evolution of this series, my apologies if I'm missing things already discussed.
Quoted 27 lines · Alon Levy
Example usage:
EnumTable foo_enum_table[] = { {"bar", 1}, {"buz", 2}, {NULL, 0}, };
DEFINE_PROP_ENUM("foo", State, foo, 1, foo_enum_table)When using qemu -device foodev,? it will appear as:
foodev.foo=bar/buzSigned-off-by Alon Levy <[email protected]>--- hw/qdev-properties.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++ hw/qdev.h | 15 ++++++++++++ 2 files changed, 75 insertions(+), 0 deletions(-)hw/qdev-properties.c +0
-0@@ -63,6 +63,66 @@ PropertyInfo qdev_prop_bit = { .print = print_bit, };
Quoted 15 lines
hw/qdev-properties.c PropertyInfo qdev_prop_bit = { · line 77
Quoted 12 lines
hw/qdev-properties.c +12
-0+/* --- Enumeration --- */ +/* Example usage: +EnumTable foo_enum_table[] = { +{"bar", 1}, +{"buz", 2}, +{NULL, 0}, +}; +DEFINE_PROP_ENUM("foo", State, foo, 1, foo_enum_table), +*/ +static int parse_enum (DeviceState *dev,Property *prop,const char *str) +{ +uint8_t *ptr =qdev_get_prop_ptr (dev, prop);
uint8_tis inconsistent withprint_enum()andDEFINE_PROP_ENUM(), which both useuint32_t.
Thanks, fixing.
Quoted 5 lines
hw/qdev-properties.c PropertyInfo qdev_prop_bit = { · line 78
Quoted 2 lines
hw/qdev-properties.c +1
-0+EnumTable *option = (EnumTable *)prop->data;Please don't cast from void * to pointer type (this isn't C++).
Will fix for all references.
Quoted 3 lines
Not thrilled about the "void *data", to be honest. Smells like premature generality to me.
I did put it in there because I didn't think a "EnumTable *enum" variable would have been acceptable (added baggage just used by a single property type), and I didn't find any other place to add it. I guess I should just do a:
typedef struct EnumProperty {
Property base;
EnumTable *table;
} EnumProperty;But then because we define the properties in a Property[] array this won't work. Maybe turn that into a Property* array?
In summary I guess data is a terrible name, but it was least amount of change. Happy to take suggestions.
Quoted 6 lines
hw/qdev-properties.c PropertyInfo qdev_prop_bit = { · line 81
Quoted 3 lines
hw/qdev-properties.c +3
-0+ +while (option->name !=NULL ) { +if (!strncmp (str, option->name,strlen (option->name))) {Why
strncmp()and not straightstrcmp()?
I guess no reason except "strncmp is more secure" but irrelevant here since option->name is from the source, I'll fix.
Quoted 13 lines
Quoted 13 lines
hw/qdev-properties.c +13
-0+ *ptr = option->value; +return 0 ; + } + option++; + } +return -EINVAL ; +} + +static int print_enum (DeviceState *dev,Property *prop,char *dest,size_t len) +{ +uint32_t *p =qdev_get_prop_ptr (dev, prop); +EnumTable *option = (EnumTable *)prop->data; +while (option->name !=NULL ) {
Quoted 9 lines
hw/qdev-properties.c PropertyInfo qdev_prop_bit = { · line 100
Quoted 6 lines
hw/qdev-properties.c +6
-0+if (*p == option->value) { +return snprintf (dest, len,"%s" , option->name); + } + option++; + } +return 0 ;Bug: must dest[0] = 0 when returning 0.
will just return snprintf(dest, len, "<enum %d>", option->value)
Quoted 9 lines
hw/qdev-properties.c PropertyInfo qdev_prop_bit = { · line 106
Quoted 6 lines
hw/qdev-properties.c +6
-0+} + +static int print_enum_options (DeviceInfo *info,Property *prop,char *dest,size_t len) +{ +int ret =0 ; +EnumTable *option = (EnumTable *)prop->data;Please don't cast from void * to pointer type (this isn't C++).
fixing.
Quoted 61 lines
Quoted 61 lines
hw/qdev-properties.c +19
-0+while (option->name !=NULL ) { + ret +=snprintf (dest + ret, len - ret,"%s" , option->name); +if (option[1 ].name !=NULL ) { + ret +=snprintf (dest + ret, len - ret,"/" ); + } + option++; + } +return ret; +} + +PropertyInfo qdev_prop_enum = { + .name ="enum" , + .type =PROP_TYPE_ENUM , + .size =sizeof (uint32_t ), + .parse = parse_enum, + .print = print_enum, + .print_options = print_enum_options, +}; +/* --- 8bit integer --- */ static int parse_uint8 (DeviceState *dev,Property *prop,const char *str)hw/qdev.h +10
-0@@ -102,6 +102,7 @@ enum PropertyType {PROP_TYPE_VLAN ,PROP_TYPE_PTR ,PROP_TYPE_BIT , + PROP_TYPE_ENUM, }; struct PropertyInfo {@@ -121,6 +122,11 @@ typedef struct GlobalProperty {QTAILQ_ENTRY (GlobalProperty) next; } GlobalProperty; +typedef struct EnumTable { +const char *name; +uint32_t value; +}EnumTable ; +/*** Board API. This should go away once we have a machine config file. ***/ DeviceState *qdev_create (BusState *bus,const char *name);@@ -235,6 +241,7 @@ extern PropertyInfo qdev_prop_drive;extern PropertyInfo qdev_prop_netdev;extern PropertyInfo qdev_prop_vlan;extern PropertyInfo qdev_prop_pci_devfn; +extern PropertyInfo qdev_prop_enum;#define DEFINE_PROP (_name, _state, _field, _prop, _type) { \ .name = (_name), \@@ -257,6 +264,14 @@ extern PropertyInfo qdev_prop_pci_devfn; + type_check(uint32_t,typeof_field(_state, _field)), \ .defval = (bool[]) { (_defval) }, \ } +#define DEFINE_PROP_ENUM (_name, _state, _field, _defval, _options) { \ + .name = (_name), \ + .info = &(qdev_prop_enum), \
Quoted 9 lines
hw/qdev.h extern PropertyInfo qdev_prop_pci_devfn; · line 273
Quoted 4 lines
hw/qdev.h +4
-0+ .offset = offsetof(_state, _field) \ + + type_check(uint32_t,typeof_field(_state, _field)), \ + .defval = (uint32_t[]) { (_defval) }, \ + .data = (void*)(_options), \Please don't cast from pointer type to void * (this isn't C++). If someone accidentally passes an integral argument for
_options(forgotten operator &), the cast suppresses the warning.
fixing.
Quoted 10 lines
hw/qdev.h extern PropertyInfo qdev_prop_pci_devfn; · line 277
Quoted 4 lines
hw/qdev.h +1
-0+ }#define DEFINE_PROP_UINT8 (_n, _s, _f, _d) \ DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint8, uint8_t)Okay, let's examine how your enumeration properties work.
An enumeration property describes a
uint32_tfield of the state object. Differences to ordinary properties defined withDEFINE_PROP_UINT32:
Quoted 7 lines
* info is
qdev_prop_enuminstead ofqdev_prop_uint32. Differences between the two:- parse, print: symbolic names vs. numbers
- name,
print_options: only for -device DRIVER,\? (and name's use there isn't particularly helpful)
Why do you say that? this is being used by libvirt to get the names of the supported backends for the ccid-card-emulated device.
Quoted 7 lines
* data points to an EnumTable, which is a map string <-> number. Thus, the actual enumeration is attached to the property declaration, not the property type (in programming languages, we commonly attach it to the type, not the variable declaration). Since it's a table it can be used for multiple properties with minimal fuss. Works for me.
Quoted 7 lines
What if we want to enumerate values of fields with types other than
uint32_t?C enumeration types, in particular. Tricky, because width and signedness of enum types is implementation-defined, and different enum types may differ there.
I specifically used uint32_t expecting it to work for many uses. It would be better to allow an arbitrary type, or just not require specifying the type but getting it from the enum itself (using typeof?). But then you can't have a single EnumTable because it's type is now dependent on the enumeration type (of course I could resort to macros, but I don't want to go there).
Quoted 3 lines
Perhaps what we really need is a way to define arbitrary integer type properties with an EnumTable attached.
This sounds more promising. So you would have an EnumTableU32 etc and DEFINE_PROP_{UINT8,..}_ENUM which takes an extra EnumTable of the correct type, to be defined inline maybe so user doesn't actually declare it (like no one declares Property thanks to the DEFINE_PROP_ macros).
Hi,
I have a v19 waiting to be sent, but it's basically the same just
with patches folded were appropriate, and the fixes Markus pointed out for the Enumeration property type.
I guess I'll wait a little longer for more feedback? Should I split
the enum property separately? it's only used by ccid-card-emualted atm.
Alon
Quoted 251 lines · Alon Levy
This patchset adds three new devices, usb-ccid, ccid-card-passthru and ccid-card-emulated, providing a CCID bus, a simple passthru protocol implementing card requiring a client, and a standalone emulated card.
It also introduces a new directory libcaccard with CAC card emulation, CAC is a type of ISO 7816 smart card.
Tree for pull:
git://anongit.freedesktop.org/~alon/qemuusb_ccid.v18v17-v18 changes:
* mergevscard_common.hpatches.
* actually provide a tree to pull.v16-v17 changes:
* merged all the "v15->v16" patches
* merged some more wherever it was easy (all same file commits).
* added signed off by to first four patches
*ccid.h: added copyright, removed underscore in defines, and replaced non C89 commentsv15-v16 changes:
* splitvscard_commonintroducing patch for ease of review
* sum of commit logs for the v15-v16 commits: (whitespace fixes
removed for space, see original commit messages in later patches)
* usb-ccid:
* 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 inccid_set_parameters
* add missing abRFU in SetParameters (no affect on linux guest)
*vscard_common.hprotocol change:
* VSCMsgInit capabilities and magic
* removed ReaderResponse, will use Error instead with code==VSC_SUCCESS.
* added Flush and FlushComplete, remove Reconnect.
* defineVSCARD_MAGIC
* added error codeVSC_SUCCESS.
* ccid-card-passthru
* return correct size
* return error instead of assert if client sent too large ATR
* don't assert if client sent too large a size, but add asserts for indices to buffer
* resetvscard_inindices on chardev disconnect
* handle init from client
* error if no chardev supplied
* use ntoh, hton
* eradicatereader_id_t
* remove Reconnect usage (removed from VSCARD protocol)
* sendVSC_SUCCESSon card insert/remove and reader add/remove
* ccid-card-emulated
* fix error reporting in initfnv14-v15 changes:
* add patch with --enable-smartcard and --disable-smartcard and only disable ccid-card-emulated if nss not found.
* add patch with description strings
* s/libcaccard/libcacard/ indocs/ccid.txtv13-v14 changes:
- support device_del/device_add on ccid-card-* and usb-ccid
* usb-ccid:
* lose card reference when card device deleted
* check slot number and deny adding a slot if one is already added.
* ccid-card-*: useqdev_simple_unplug_cbin both emulated and passthru ccid cards, the exitfn already takes care of triggering card removal in the usb dev.
* libcacard:
* remove double include of config-host.mak
* add replay of card events to libcacard to support second and more emulation
* don't initialize more then once (doesn't support it right now, so one thread, NSS thread, is left whendevice_delis done)
* addVCARD_EMUL_INIT_ALREADY_INITED
* ccid-card-emulated:
* take correct mutexes on signaling to fix deadlocks ondevice_del
* allow card insertion/removal event without proper reader insertion eventv12-v13 changes:
* libcacard:
* fixMakefileclean to remove vscclient
* fix double include of config-host inMakefile
* usb-ccid: remove attach/detach logic, usb is always attached. Guest doesn't care if there is a reader attached with no card anyway.
* ccid-card-passthru: don't closechr_devon removal, makes it possible to use device_del/device_add to create remove/insertion for debugging.v11-v12 changes:
* fix out of tree buildv10-v11 changes:
* fix last patch that removed one of the doc files.
* updated flow table indocs/ccid.txtv8-v10 changes:
* usb-ccid:
* add slot for future use (Gerd)
* ifdefENABLE_MIGRATIONfor migration support on account of usb migration not being ready in general. (Gerd)
* verbosified commit messages. (Gerd)
* put libcacard docs in libcacard commit. (Gerd)v8-v9 changes:
* Blue Swirl comments:
* white space fixes
* enabled by default, disabled only if missing nss
* forgotten fix from v8 (don't build libcacard.so)
* added a note about device being little endian
* library renamed from libcaccard to libcacard
* squashed both of libcacard patches, they touched different files anyway.v7-v8 changes:
* Blue Swirl comments:
* usb-ccid: deannonymize some structs
* usb-ccid: coding style change -answer_tandbulk_in_tfixed
* usb-ccid: handle endianess conversion between guest and host
* usb-ccid: s/ccid_bulk_in_copy_out/ccid_bulk_in_copy_to_guest/
* ccid-card-emulated: fix segfault if backend not specified
* ccid-card-emulated: let last reader inserted win
* libcaccard: remove doublevscard_common.h
v6->v7changes:
* external libcaccard became internal directory libcaccard
* statically link object files into qemu
* produce libcaccard.so for usage by external projects
* applied coding style to new code (please check me)
- did not use the qemu options parsing for libcaccard, since it seems to draw large amounts of qemu code (monitor for instance).
v5->v6changes:
* really remove static debug (I apologize for claiming to have done so before)
v4->v5changes:
* rebased to latest
* remove static debug in card devices
* fix --enable-smartcard to link
* stall instead of assert when exceedingBULK_OUT_DATA_SIZE
* makeccid_reserve_recv_buffor too large len discard message, not exit
* makeccid_reserve_recv_bufreturn void*
* fix typo
* remove commented code in VMState
v3->v4:
* remove ccid field in CCIDBus
* remove static debug in bus
* add back docs
v2->v3:
* split into bus (usb-ccid.c, usesccid.h) and card (ccid-card-passthru.c).
* removed documentation (being revised).
v1->v2:
* 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 (15):
qdev: addprint_optionscallback
qdev: add data pointer to Property
qdev-properties: addPROP_TYPE_ENUM
qdev-properties:parse_enum: don't cast a void*
usb-ccid: add CCID bus
introducelibcacard/vscard_common.h
ccid: add passthru card device
ccid: add ccid-card-emulated device (v2)
ccid: add docs
ccid: configure: add --enable/disable and nss only disable
ccid: add qdev description strings
smartcard,configure: add --enable-smartcard-nss, report only nss smartcard,configure: report only nss
ccid-card-emulated: don't link with NSS if --disable-smartcard-nssccid.h: add copyright, fix define and remove non C89 commentsRobert Relyea (1):
libcacard: initial commitMakefile | 6 +- Makefile.objs | 7 + Makefile.target | 2 + configure | 60 ++ docs/ccid.txt | 135 +++++ docs/libcacard.txt | 483 +++++++++++++++ hw/ccid-card-emulated.c | 551 ++++++++++++++++++ hw/ccid-card-passthru.c | 329 +++++++++++ hw/ccid.h | 51 ++ hw/qdev-properties.c | 60 ++ hw/qdev.c | 10 +- hw/qdev.h | 17 + hw/usb-ccid.c | 1353 +++++++++++++++++++++++++++++++++++++++++++ libcacard/Makefile | 14 + libcacard/cac.c | 411 +++++++++++++ libcacard/cac.h | 20 + libcacard/card_7816.c | 780 +++++++++++++++++++++++++ libcacard/card_7816.h | 60 ++ libcacard/card_7816t.h | 163 ++++++ libcacard/event.c | 112 ++++ libcacard/eventt.h | 28 + libcacard/link_test.c | 20 + libcacard/mutex.h | 59 ++ libcacard/passthru.c | 612 +++++++++++++++++++ libcacard/passthru.h | 50 ++ libcacard/vcard.c | 350 +++++++++++ libcacard/vcard.h | 85 +++ libcacard/vcard_emul.h | 62 ++ libcacard/vcard_emul_nss.c | 1192 +++++++++++++++++++++++++++++++++++++ libcacard/vcard_emul_type.c | 60 ++ libcacard/vcard_emul_type.h | 29 + libcacard/vcardt.h | 66 +++ libcacard/vevent.h | 26 + libcacard/vreader.c | 526 +++++++++++++++++ libcacard/vreader.h | 54 ++ libcacard/vreadert.h | 23 + libcacard/vscard_common.h | 167 ++++++ libcacard/vscclient.c | 743 ++++++++++++++++++++++++ 38 files changed, 8773 insertions(+), 3 deletions(-) create mode 100644 docs/ccid.txt create mode 100644 docs/libcacard.txt create mode 100644 hw/ccid-card-emulated.c create mode 100644 hw/ccid-card-passthru.c create mode 100644 hw/ccid.h create mode 100644 hw/usb-ccid.c create mode 100644 libcacard/Makefile create mode 100644 libcacard/cac.c create mode 100644 libcacard/cac.h create mode 100644 libcacard/card_7816.c create mode 100644 libcacard/card_7816.h create mode 100644 libcacard/card_7816t.h create mode 100644 libcacard/event.c create mode 100644 libcacard/eventt.h create mode 100644 libcacard/link_test.c create mode 100644 libcacard/mutex.h create mode 100644 libcacard/passthru.c create mode 100644 libcacard/passthru.h create mode 100644 libcacard/vcard.c create mode 100644 libcacard/vcard.h create mode 100644 libcacard/vcard_emul.h create mode 100644 libcacard/vcard_emul_nss.c create mode 100644 libcacard/vcard_emul_type.c create mode 100644 libcacard/vcard_emul_type.h create mode 100644 libcacard/vcardt.h create mode 100644 libcacard/vevent.h create mode 100644 libcacard/vreader.c create mode 100644 libcacard/vreader.h create mode 100644 libcacard/vreadert.h create mode 100644 libcacard/vscard_common.h create mode 100644 libcacard/vscclient.cSignature · 1 line
1.7.4
Re: [Qemu-devel] [PATCH 03/16] qdev-properties: add PROP_TYPE_ENUM
In reply to Alon LevyQuoted 220 lines · Alon Levy
Quoted 33 lines · Markus Armbruster
I haven't been able to follow the evolution of this series, my apologies if I'm missing things already discussed.
Quoted 27 lines · Alon Levy
Example usage:
EnumTable foo_enum_table[] = { {"bar", 1}, {"buz", 2}, {NULL, 0}, };
DEFINE_PROP_ENUM("foo", State, foo, 1, foo_enum_table)When using qemu -device foodev,? it will appear as:
foodev.foo=bar/buzSigned-off-by Alon Levy<[email protected]>--- hw/qdev-properties.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++ hw/qdev.h | 15 ++++++++++++ 2 files changed, 75 insertions(+), 0 deletions(-)hw/qdev-properties.c +0
-0@@ -63,6 +63,66 @@ PropertyInfo qdev_prop_bit = { .print = print_bit, };Quoted 16 lines
hw/qdev-properties.c PropertyInfo qdev_prop_bit = { · line 127
Quoted 13 lines
hw/qdev-properties.c +12
-0+/* --- Enumeration --- */ +/* Example usage: +EnumTable foo_enum_table[] = { +{"bar", 1}, +{"buz", 2}, +{NULL, 0}, +}; +DEFINE_PROP_ENUM("foo", State, foo, 1, foo_enum_table), +*/ +static int parse_enum (DeviceState *dev,Property *prop,const char *str) +{ +uint8_t *ptr =qdev_get_prop_ptr (dev, prop);
uint8_tis inconsistent withprint_enum()andDEFINE_PROP_ENUM(), which both useuint32_t.Thanks, fixing.
Quoted 6 lines
hw/qdev-properties.c PropertyInfo qdev_prop_bit = { · line 80
Quoted 3 lines
hw/qdev-properties.c +1
-0+EnumTable *option = (EnumTable *)prop->data;Please don't cast from void * to pointer type (this isn't C++).
Will fix for all references.
Quoted 4 lines
Not thrilled about the "void *data", to be honest. Smells like premature generality to me.
I did put it in there because I didn't think a "EnumTable *enum" variable would have been acceptable (added baggage just used by a single property type), and I didn't find any other place to add it. I guess I should just do a:
typedef struct EnumProperty { Property base; EnumTable *table; } EnumProperty;But then because we define the properties in a Property[] array this won't work. Maybe turn that into a Property* array?
In summary I guess data is a terrible name, but it was least amount of change. Happy to take suggestions.
Quoted 7 lines
hw/qdev-properties.c PropertyInfo qdev_prop_bit = { · line 127
Quoted 4 lines
hw/qdev-properties.c +3
-0+ +while (option->name !=NULL ) { +if (!strncmp (str, option->name,strlen (option->name))) {Why
strncmp()and not straightstrcmp()?I guess no reason except "strncmp is more secure" but irrelevant here since
option->nameis from the source, I'll fix.Quoted 13 lines
Quoted 13 lines
hw/qdev-properties.c +13
-0+ *ptr = option->value; +return 0 ; + } + option++; + } +return -EINVAL ; +} + +static int print_enum (DeviceState *dev,Property *prop,char *dest,size_t len) +{ +uint32_t *p =qdev_get_prop_ptr (dev, prop); +EnumTable *option = (EnumTable *)prop->data; +while (option->name !=NULL ) {Quoted 10 lines
hw/qdev-properties.c PropertyInfo qdev_prop_bit = { · line 100
Quoted 7 lines
hw/qdev-properties.c +6
-0+if (*p == option->value) { +return snprintf (dest, len,"%s" , option->name); + } + option++; + } +return 0 ;Bug: must dest[0] = 0 when returning 0.
will just return
snprintf(dest, len, "<enum %d>", option->value)Quoted 10 lines
hw/qdev-properties.c PropertyInfo qdev_prop_bit = { · line 106
Quoted 7 lines
hw/qdev-properties.c +6
-0+} + +static int print_enum_options (DeviceInfo *info,Property *prop,char *dest,size_t len) +{ +int ret =0 ; +EnumTable *option = (EnumTable *)prop->data;Please don't cast from void * to pointer type (this isn't C++).
fixing.
Quoted 61 lines
Quoted 61 lines
hw/qdev-properties.c +19
-0+while (option->name !=NULL ) { + ret +=snprintf (dest + ret, len - ret,"%s" , option->name); +if (option[1 ].name !=NULL ) { + ret +=snprintf (dest + ret, len - ret,"/" ); + } + option++; + } +return ret; +} + +PropertyInfo qdev_prop_enum = { + .name ="enum" , + .type =PROP_TYPE_ENUM , + .size =sizeof (uint32_t ), + .parse = parse_enum, + .print = print_enum, + .print_options = print_enum_options, +}; +/* --- 8bit integer --- */
static int
parse_uint8(DeviceState *dev, Property *prop, const char *str)hw/qdev.h +10
-0@@ -102,6 +102,7 @@ enum PropertyType {PROP_TYPE_VLAN ,PROP_TYPE_PTR ,PROP_TYPE_BIT , + PROP_TYPE_ENUM, }; struct PropertyInfo {@@ -121,6 +122,11 @@ typedef struct GlobalProperty {QTAILQ_ENTRY (GlobalProperty) next; } GlobalProperty; +typedef struct EnumTable { +const char *name; +uint32_t value; +}EnumTable ; +/*** Board API. This should go away once we have a machine config file. ***/ DeviceState *qdev_create (BusState *bus,const char *name);@@ -235,6 +241,7 @@ extern PropertyInfo qdev_prop_drive;extern PropertyInfo qdev_prop_netdev;extern PropertyInfo qdev_prop_vlan;extern PropertyInfo qdev_prop_pci_devfn; +extern PropertyInfo qdev_prop_enum;#define DEFINE_PROP (_name, _state, _field, _prop, _type) { \ .name = (_name), \@@ -257,6 +264,14 @@ extern PropertyInfo qdev_prop_pci_devfn; + type_check(uint32_t,typeof_field(_state, _field)), \ .defval = (bool[]) { (_defval) }, \ } +#define DEFINE_PROP_ENUM (_name, _state, _field, _defval, _options) { \ + .name = (_name), \ + .info =&(qdev_prop_enum), \Quoted 10 lines
hw/qdev.h extern PropertyInfo qdev_prop_pci_devfn; · line 275
Quoted 5 lines
hw/qdev.h +4
-0+ .offset = offsetof(_state, _field) \ + + type_check(uint32_t,typeof_field(_state, _field)), \ + .defval = (uint32_t[]) { (_defval) }, \ + .data = (void*)(_options), \Please don't cast from pointer type to void * (this isn't C++). If someone accidentally passes an integral argument for
_options(forgotten operator&), the cast suppresses the warning.fixing.
Quoted 13 lines
Quoted 5 lines
hw/qdev.h +1
-0+ }#define DEFINE_PROP_UINT8 (_n, _s, _f, _d) \DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint8, uint8_t)Okay, let's examine how your enumeration properties work.
An enumeration property describes a
uint32_tfield of the state object. Differences to ordinary properties defined withDEFINE_PROP_UINT32:* info is
qdev_prop_enuminstead ofqdev_prop_uint32. Differences between the two:
Quoted 8 lines
Quoted 5 lines
- parse, print: symbolic names vs. numbers
- name,
print_options: only for -device DRIVER,\? (and name's use there isn't particularly helpful)Why do you say that? this is being used by libvirt to get the names of the supported backends for the ccid-card-emulated device.
This is wrong.
Libvirt should query this information through QMP. This is my main concern with enums. If there isn't a useful introspection interface, libvirt is going to do dumb things like query help output.
This has been a nightmare historically and I'm not inclined to repeat it.
Regards,
Anthony Liguori
Quoted 9 lines · Alon Levy
Hi,
I have a v19 waiting to be sent, but it's basically the same just
with patches folded were appropriate, and the fixes Markus pointed out for the Enumeration property type.I guess I'll wait a little longer for more feedback? Should I split
the enum property separately? it's only used by ccid-card-emualted atm.
The only non-cosmetic concern I have about your series is the enum property so I would strongly suggest splitting it. If you did that for v19, it will be pretty close to merge ready.
Regards,
Anthony Liguori
Quoted 257 lines
Alon
Quoted 252 lines · Alon Levy
This patchset adds three new devices, usb-ccid, ccid-card-passthru and ccid-card-emulated, providing a CCID bus, a simple passthru protocol implementing card requiring a client, and a standalone emulated card.
It also introduces a new directory libcaccard with CAC card emulation, CAC is a type of ISO 7816 smart card.
Tree for pull:
git://anongit.freedesktop.org/~alon/qemuusb_ccid.v18v17-v18 changes:
* mergevscard_common.hpatches.
* actually provide a tree to pull.v16-v17 changes:
* merged all the "v15->v16" patches
* merged some more wherever it was easy (all same file commits).
* added signed off by to first four patches
*ccid.h: added copyright, removed underscore in defines, and replaced non C89 commentsv15-v16 changes:
* splitvscard_commonintroducing patch for ease of review
* sum of commit logs for the v15-v16 commits: (whitespace fixes
removed for space, see original commit messages in later patches)
* usb-ccid:
* 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 inccid_set_parameters
* add missing abRFU in SetParameters (no affect on linux guest)
*vscard_common.hprotocol change:
* VSCMsgInit capabilities and magic
* removed ReaderResponse, will use Error instead with code==VSC_SUCCESS.
* added Flush and FlushComplete, remove Reconnect.
* defineVSCARD_MAGIC
* added error codeVSC_SUCCESS.
* ccid-card-passthru
* return correct size
* return error instead of assert if client sent too large ATR
* don't assert if client sent too large a size, but add asserts for indices to buffer
* resetvscard_inindices on chardev disconnect
* handle init from client
* error if no chardev supplied
* use ntoh, hton
* eradicatereader_id_t
* remove Reconnect usage (removed from VSCARD protocol)
* sendVSC_SUCCESSon card insert/remove and reader add/remove
* ccid-card-emulated
* fix error reporting in initfnv14-v15 changes:
* add patch with --enable-smartcard and --disable-smartcard and only disable ccid-card-emulated if nss not found.
* add patch with description strings
* s/libcaccard/libcacard/ indocs/ccid.txtv13-v14 changes:
- support device_del/device_add on ccid-card-* and usb-ccid
* usb-ccid:
* lose card reference when card device deleted
* check slot number and deny adding a slot if one is already added.
* ccid-card-*: useqdev_simple_unplug_cbin both emulated and passthru ccid cards, the exitfn already takes care of triggering card removal in the usb dev.
* libcacard:
* remove double include of config-host.mak
* add replay of card events to libcacard to support second and more emulation
* don't initialize more then once (doesn't support it right now, so one thread, NSS thread, is left whendevice_delis done)
* addVCARD_EMUL_INIT_ALREADY_INITED
* ccid-card-emulated:
* take correct mutexes on signaling to fix deadlocks ondevice_del
* allow card insertion/removal event without proper reader insertion eventv12-v13 changes:
* libcacard:
* fixMakefileclean to remove vscclient
* fix double include of config-host inMakefile
* usb-ccid: remove attach/detach logic, usb is always attached. Guest doesn't care if there is a reader attached with no card anyway.
* ccid-card-passthru: don't closechr_devon removal, makes it possible to use device_del/device_add to create remove/insertion for debugging.v11-v12 changes:
* fix out of tree buildv10-v11 changes:
* fix last patch that removed one of the doc files.
* updated flow table indocs/ccid.txtv8-v10 changes:
* usb-ccid:
* add slot for future use (Gerd)
* ifdefENABLE_MIGRATIONfor migration support on account of usb migration not being ready in general. (Gerd)
* verbosified commit messages. (Gerd)
* put libcacard docs in libcacard commit. (Gerd)v8-v9 changes:
* Blue Swirl comments:
* white space fixes
* enabled by default, disabled only if missing nss
* forgotten fix from v8 (don't build libcacard.so)
* added a note about device being little endian
* library renamed from libcaccard to libcacard
* squashed both of libcacard patches, they touched different files anyway.v7-v8 changes:
* Blue Swirl comments:
* usb-ccid: deannonymize some structs
* usb-ccid: coding style change -answer_tandbulk_in_tfixed
* usb-ccid: handle endianess conversion between guest and host
* usb-ccid: s/ccid_bulk_in_copy_out/ccid_bulk_in_copy_to_guest/
* ccid-card-emulated: fix segfault if backend not specified
* ccid-card-emulated: let last reader inserted win
* libcaccard: remove doublevscard_common.h
v6->v7changes:
* external libcaccard became internal directory libcaccard
* statically link object files into qemu
* produce libcaccard.so for usage by external projects
* applied coding style to new code (please check me)
- did not use the qemu options parsing for libcaccard, since it seems to draw large amounts of qemu code (monitor for instance).
v5->v6changes:
* really remove static debug (I apologize for claiming to have done so before)
v4->v5changes:
* rebased to latest
* remove static debug in card devices
* fix --enable-smartcard to link
* stall instead of assert when exceedingBULK_OUT_DATA_SIZE
* makeccid_reserve_recv_buffor too large len discard message, not exit
* makeccid_reserve_recv_bufreturn void*
* fix typo
* remove commented code in VMState
v3->v4:
* remove ccid field in CCIDBus
* remove static debug in bus
* add back docs
v2->v3:
* split into bus (usb-ccid.c, usesccid.h) and card (ccid-card-passthru.c).
* removed documentation (being revised).
v1->v2:
* 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 (15):
qdev: addprint_optionscallback
qdev: add data pointer to Property
qdev-properties: addPROP_TYPE_ENUM
qdev-properties:parse_enum: don't cast a void*
usb-ccid: add CCID bus
introducelibcacard/vscard_common.h
ccid: add passthru card device
ccid: add ccid-card-emulated device (v2)
ccid: add docs
ccid: configure: add --enable/disable and nss only disable
ccid: add qdev description strings
smartcard,configure: add --enable-smartcard-nss, report only nss smartcard,configure: report only nss
ccid-card-emulated: don't link with NSS if --disable-smartcard-nssccid.h: add copyright, fix define and remove non C89 commentsRobert Relyea (1):
libcacard: initial commitMakefile | 6 +- Makefile.objs | 7 + Makefile.target | 2 + configure | 60 ++ docs/ccid.txt | 135 +++++ docs/libcacard.txt | 483 +++++++++++++++ hw/ccid-card-emulated.c | 551 ++++++++++++++++++ hw/ccid-card-passthru.c | 329 +++++++++++ hw/ccid.h | 51 ++ hw/qdev-properties.c | 60 ++ hw/qdev.c | 10 +- hw/qdev.h | 17 + hw/usb-ccid.c | 1353 +++++++++++++++++++++++++++++++++++++++++++ libcacard/Makefile | 14 + libcacard/cac.c | 411 +++++++++++++ libcacard/cac.h | 20 + libcacard/card_7816.c | 780 +++++++++++++++++++++++++ libcacard/card_7816.h | 60 ++ libcacard/card_7816t.h | 163 ++++++ libcacard/event.c | 112 ++++ libcacard/eventt.h | 28 + libcacard/link_test.c | 20 + libcacard/mutex.h | 59 ++ libcacard/passthru.c | 612 +++++++++++++++++++ libcacard/passthru.h | 50 ++ libcacard/vcard.c | 350 +++++++++++ libcacard/vcard.h | 85 +++ libcacard/vcard_emul.h | 62 ++ libcacard/vcard_emul_nss.c | 1192 +++++++++++++++++++++++++++++++++++++ libcacard/vcard_emul_type.c | 60 ++ libcacard/vcard_emul_type.h | 29 + libcacard/vcardt.h | 66 +++ libcacard/vevent.h | 26 + libcacard/vreader.c | 526 +++++++++++++++++ libcacard/vreader.h | 54 ++ libcacard/vreadert.h | 23 + libcacard/vscard_common.h | 167 ++++++ libcacard/vscclient.c | 743 ++++++++++++++++++++++++ 38 files changed, 8773 insertions(+), 3 deletions(-)create mode 100644
docs/ccid.txt
create mode 100644docs/libcacard.txt
create mode 100644hw/ccid-card-emulated.c
create mode 100644hw/ccid-card-passthru.c
create mode 100644hw/ccid.h
create mode 100644hw/usb-ccid.c
create mode 100644 libcacard/Makefile
create mode 100644libcacard/cac.c
create mode 100644libcacard/cac.h
create mode 100644libcacard/card_7816.c
create mode 100644libcacard/card_7816.h
create mode 100644libcacard/card_7816t.h
create mode 100644libcacard/event.c
create mode 100644libcacard/eventt.h
create mode 100644libcacard/link_test.c
create mode 100644libcacard/mutex.h
create mode 100644libcacard/passthru.c
create mode 100644libcacard/passthru.h
create mode 100644libcacard/vcard.c
create mode 100644libcacard/vcard.h
create mode 100644libcacard/vcard_emul.h
create mode 100644libcacard/vcard_emul_nss.c
create mode 100644libcacard/vcard_emul_type.c
create mode 100644libcacard/vcard_emul_type.h
create mode 100644libcacard/vcardt.h
create mode 100644libcacard/vevent.h
create mode 100644libcacard/vreader.c
create mode 100644libcacard/vreader.h
create mode 100644libcacard/vreadert.h
create mode 100644libcacard/vscard_common.h
create mode 100644libcacard/vscclient.cSignature · 1 line
1.7.4
Re: [Qemu-devel] [PATCH 03/16] qdev-properties: add PROP_TYPE_ENUM
In reply to Markus ArmbrusterQuoted 196 lines · Markus Armbruster
I haven't been able to follow the evolution of this series, my apologies if I'm missing things already discussed.
Quoted 30 lines · Alon Levy
Example usage:
EnumTable foo_enum_table[] = { {"bar", 1}, {"buz", 2}, {NULL, 0}, };
DEFINE_PROP_ENUM("foo", State, foo, 1, foo_enum_table)When using qemu -device foodev,? it will appear as:
foodev.foo=bar/buzSigned-off-by Alon Levy<[email protected]>--- hw/qdev-properties.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++ hw/qdev.h | 15 ++++++++++++ 2 files changed, 75 insertions(+), 0 deletions(-)hw/qdev-properties.c +3
-0@@ -63,6 +63,66 @@ PropertyInfo qdev_prop_bit = { .print = print_bit, }; +/* --- Enumeration --- */ +/* Example usage: +EnumTable foo_enum_table[] = { hw/qdev-properties.c PropertyInfo qdev_prop_bit = { · line 78
Quoted 10 lines
hw/qdev-properties.c +9
-0+{"bar", 1}, +{"buz", 2}, +{NULL, 0}, +}; +DEFINE_PROP_ENUM("foo", State, foo, 1, foo_enum_table), +*/ +static int parse_enum (DeviceState *dev,Property *prop,const char *str) +{ +uint8_t *ptr =qdev_get_prop_ptr (dev, prop);
uint8_tis inconsistent withprint_enum()andDEFINE_PROP_ENUM(), which both useuint32_t.hw/qdev-properties.c PropertyInfo qdev_prop_bit = { · line 80
Quoted 2 lines
hw/qdev-properties.c +1
-0+EnumTable *option = (EnumTable *)prop->data;Please don't cast from void * to pointer type (this isn't C++).
Not thrilled about the "void *data", to be honest. Smells like premature generality to me.
hw/qdev-properties.c PropertyInfo qdev_prop_bit = { · line 127
Quoted 4 lines
hw/qdev-properties.c +3
-0+ +while (option->name !=NULL ) { +if (!strncmp (str, option->name,strlen (option->name))) {Why
strncmp()and not straightstrcmp()?Quoted 10 lines
hw/qdev-properties.c +9
-0+ *ptr = option->value; +return 0 ; + } + option++; + } +return -EINVAL ; +} + +static int print_enum (DeviceState *dev,Property *prop,char *dest,size_t len)hw/qdev-properties.c PropertyInfo qdev_prop_bit = { · line 100
Quoted 10 lines
hw/qdev-properties.c +10
-0+{ +uint32_t *p =qdev_get_prop_ptr (dev, prop); +EnumTable *option = (EnumTable *)prop->data; +while (option->name !=NULL ) { +if (*p == option->value) { +return snprintf (dest, len,"%s" , option->name); + } + option++; + } +return 0 ;Bug: must dest[0] = 0 when returning 0.
hw/qdev-properties.c PropertyInfo qdev_prop_bit = { · line 106
Quoted 7 lines
hw/qdev-properties.c +6
-0+} + +static int print_enum_options (DeviceInfo *info,Property *prop,char *dest,size_t len) +{ +int ret =0 ; +EnumTable *option = (EnumTable *)prop->data;Please don't cast from void * to pointer type (this isn't C++).
Quoted 56 lines
hw/qdev-properties.c +19
-0+while (option->name !=NULL ) { + ret +=snprintf (dest + ret, len - ret,"%s" , option->name); +if (option[1 ].name !=NULL ) { + ret +=snprintf (dest + ret, len - ret,"/" ); + } + option++; + } +return ret; +} + +PropertyInfo qdev_prop_enum = { + .name ="enum" , + .type =PROP_TYPE_ENUM , + .size =sizeof (uint32_t ), + .parse = parse_enum, + .print = print_enum, + .print_options = print_enum_options, +}; +/* --- 8bit integer --- */
static int
parse_uint8(DeviceState *dev, Property *prop, const char *str)hw/qdev.h +7
-0@@ -102,6 +102,7 @@ enum PropertyType {PROP_TYPE_VLAN ,PROP_TYPE_PTR ,PROP_TYPE_BIT , + PROP_TYPE_ENUM, }; struct PropertyInfo {@@ -121,6 +122,11 @@ typedef struct GlobalProperty {QTAILQ_ENTRY (GlobalProperty) next; } GlobalProperty; +typedef struct EnumTable { +const char *name; +uint32_t value; +}EnumTable ; +/*** Board API. This should go away once we have a machine config file. ***/ DeviceState *qdev_create (BusState *bus,const char *name);@@ -235,6 +241,7 @@ extern PropertyInfo qdev_prop_drive;extern PropertyInfo qdev_prop_netdev;extern PropertyInfo qdev_prop_vlan;extern PropertyInfo qdev_prop_pci_devfn; +extern PropertyInfo qdev_prop_enum;#define DEFINE_PROP (_name, _state, _field, _prop, _type) { \ .name = (_name), \@@ -257,6 +264,14 @@ extern PropertyInfo qdev_prop_pci_devfn; + type_check(uint32_t,typeof_field(_state, _field)), \hw/qdev.h extern PropertyInfo qdev_prop_pci_devfn; · line 274
Quoted 10 lines
hw/qdev.h +7
-0.defval = (bool[]) { (_defval) }, \ } +#define DEFINE_PROP_ENUM (_name, _state, _field, _defval, _options) { \ + .name = (_name), \ + .info =&(qdev_prop_enum), \ + .offset = offsetof(_state, _field) \ + + type_check(uint32_t,typeof_field(_state, _field)), \ + .defval = (uint32_t[]) { (_defval) }, \ + .data = (void*)(_options), \Please don't cast from pointer type to void * (this isn't C++). If someone accidentally passes an integral argument for
_options(forgotten operator&), the cast suppresses the warning.Quoted 5 lines
hw/qdev.h +1
-0+ }#define DEFINE_PROP_UINT8 (_n, _s, _f, _d) \DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint8, uint8_t)Okay, let's examine how your enumeration properties work.
An enumeration property describes a
uint32_tfield of the state object. Differences to ordinary properties defined withDEFINE_PROP_UINT32:* info is
qdev_prop_enuminstead ofqdev_prop_uint32. Differences between the two:- parse, print: symbolic names vs. numbers
- name,
print_options: only for -device DRIVER,\? (and name's use there isn't particularly helpful)* data points to an EnumTable, which is a map string<-> number. Thus, the actual enumeration is attached to the property declaration, not the property type (in programming languages, we commonly attach it to the type, not the variable declaration). Since it's a table it can be used for multiple properties with minimal fuss. Works for me.
What if we want to enumerate values of fields with types other than
uint32_t?
Quoted 7 lines
C enumeration types, in particular. Tricky, because width and signedness of enum types is implementation-defined, and different enum types may differ there.
Perhaps what we really need is a way to define arbitrary integer type properties with an EnumTable attached.
Given the massive QMP overhaul for 0.15, I don't want to add any more complexity to device properties because without unifying the device properties with QMP.
The bridge to QMP for qdev via device_add is quite scary. We have strong typing in QMP, and then marshal those strong types to strings such that they can be demarshaled via device properties. This is a real shame.
As I mentioned earlier, this patch breaks that in a subtle way.
If we want to add enums (and we really do), we should add it first to QMP in a structured way and then map that to device properties.
Regards,
Anthony Liguori
Regards,
Anthony Liguori
Re: [Qemu-devel] [PATCH 03/16] qdev-properties: add PROP_TYPE_ENUM
In reply to Alon LevyQuoted 67 lines · Alon Levy
Quoted 32 lines · Markus Armbruster
I haven't been able to follow the evolution of this series, my apologies if I'm missing things already discussed.
Quoted 27 lines · Alon Levy
Example usage:
EnumTable foo_enum_table[] = { {"bar", 1}, {"buz", 2}, {NULL, 0}, };
DEFINE_PROP_ENUM("foo", State, foo, 1, foo_enum_table)When using qemu -device foodev,? it will appear as:
foodev.foo=bar/buzSigned-off-by Alon Levy <[email protected]>--- hw/qdev-properties.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++ hw/qdev.h | 15 ++++++++++++ 2 files changed, 75 insertions(+), 0 deletions(-)hw/qdev-properties.c +0
-0@@ -63,6 +63,66 @@ PropertyInfo qdev_prop_bit = { .print = print_bit, };Quoted 15 lines
hw/qdev-properties.c PropertyInfo qdev_prop_bit = { · line 77
Quoted 12 lines
hw/qdev-properties.c +12
-0+/* --- Enumeration --- */ +/* Example usage: +EnumTable foo_enum_table[] = { +{"bar", 1}, +{"buz", 2}, +{NULL, 0}, +}; +DEFINE_PROP_ENUM("foo", State, foo, 1, foo_enum_table), +*/ +static int parse_enum (DeviceState *dev,Property *prop,const char *str) +{ +uint8_t *ptr =qdev_get_prop_ptr (dev, prop);
uint8_tis inconsistent withprint_enum()andDEFINE_PROP_ENUM(), which both useuint32_t.Thanks, fixing.
Quoted 5 lines
hw/qdev-properties.c PropertyInfo qdev_prop_bit = { · line 78
Quoted 2 lines
hw/qdev-properties.c +1
-0+EnumTable *option = (EnumTable *)prop->data;Please don't cast from void * to pointer type (this isn't C++).
Will fix for all references.
Quoted 3 lines
Not thrilled about the "void *data", to be honest. Smells like premature generality to me.
I did put it in there because I didn't think a "EnumTable *enum" variable would have been acceptable (added baggage just used by a single property type), and I didn't find any other place to add it. I guess I should just do a:
Quoted 7 lines
typedef struct EnumProperty { Property base; EnumTable *table; } EnumProperty;But then because we define the properties in a Property[] array this won't work. Maybe turn that into a Property* array?
Doubt the additional complexity just for keeping EnumTable out of Property is worth it.
Quoted 2 lines
In summary I guess data is a terrible name, but it was least amount of change. Happy to take suggestions.
Further down, we discuss the idea of supporting an EnumTable with arbitrary integer type properties. Would you find an EnumTable member of Property more palatable then?
Quoted 33 lines
Quoted 6 lines
hw/qdev-properties.c PropertyInfo qdev_prop_bit = { · line 81
Quoted 3 lines
hw/qdev-properties.c +3
-0+ +while (option->name !=NULL ) { +if (!strncmp (str, option->name,strlen (option->name))) {Why
strncmp()and not straightstrcmp()?I guess no reason except "strncmp is more secure" but irrelevant here since
option->nameis from the source, I'll fix.Quoted 13 lines
Quoted 13 lines
hw/qdev-properties.c +13
-0+ *ptr = option->value; +return 0 ; + } + option++; + } +return -EINVAL ; +} + +static int print_enum (DeviceState *dev,Property *prop,char *dest,size_t len) +{ +uint32_t *p =qdev_get_prop_ptr (dev, prop); +EnumTable *option = (EnumTable *)prop->data; +while (option->name !=NULL ) {Quoted 9 lines
hw/qdev-properties.c PropertyInfo qdev_prop_bit = { · line 100
Quoted 6 lines
hw/qdev-properties.c +6
-0+if (*p == option->value) { +return snprintf (dest, len,"%s" , option->name); + } + option++; + } +return 0 ;Bug: must dest[0] = 0 when returning 0.
Quoted 1 line
will just return
snprintf(dest, len, "<enum %d>", option->value)
Print something useful is a good idea. I guess I'd print an unadorned "%d".
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
hw/qdev-properties.c +2
-0+} +
[...]
Quoted 13 lines
Quoted 13 lines
Quoted 4 lines
+ }
#define DEFINE_PROP_UINT8(_n, _s, _f, _d) \ DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint8, uint8_t)Okay, let's examine how your enumeration properties work.
An enumeration property describes a
uint32_tfield of the state object. Differences to ordinary properties defined withDEFINE_PROP_UINT32:* info is
qdev_prop_enuminstead ofqdev_prop_uint32. Differences between the two:
Quoted 7 lines
Quoted 4 lines
- parse, print: symbolic names vs. numbers
- name,
print_options: only for -device DRIVER,\? (and name's use there isn't particularly helpful)Why do you say that? this is being used by libvirt to get the names of the supported backends for the ccid-card-emulated device.
Too terse, let me try again :)
- name, print_options: differences not important here, because these members are they are only for -device DRIVER,\?
By the way, I don't find help output like
e1000.mac=macaddr
e1000.vlan=vlan
e1000.netdev=netdev
particularly helpful. Not your fault, outside the scope of this patch.
Quoted 15 lines
Quoted 7 lines
* data points to an EnumTable, which is a map string <-> number. Thus, the actual enumeration is attached to the property declaration, not the property type (in programming languages, we commonly attach it to the type, not the variable declaration). Since it's a table it can be used for multiple properties with minimal fuss. Works for me.
Quoted 7 lines
What if we want to enumerate values of fields with types other than
uint32_t?C enumeration types, in particular. Tricky, because width and signedness of enum types is implementation-defined, and different enum types may differ there.
Quoted 6 lines
I specifically used
uint32_texpecting it to work for many uses. It would be better to allow an arbitrary type, or just not require specifying the type but getting it from the enum itself (using typeof?). But then you can't have a single EnumTable because it's type is now dependent on the enumeration type (of course I could resort to macros, but I don't want to go there).
That's what I meant when I called it "tricky".
Still, having an enum property that cannot be used with enumeration types is kind of sad, isn't it?
Quoted 8 lines
Quoted 3 lines
Perhaps what we really need is a way to define arbitrary integer type properties with an EnumTable attached.
This sounds more promising. So you would have an EnumTableU32 etc and DEFINE_PROP_{UINT8,..}_ENUM which takes an extra EnumTable of the correct type, to be defined inline maybe so user doesn't actually declare it (like no one declares Property thanks to the
DEFINE_PROP_macros).
Sounds like what I have in mind. Care to explore it?
One EnumTable should do, just make its member value wide enough.
Note to maintainer: we don't have to get enum properties 100% right and polished before we can commit this series.
Re: [Qemu-devel] [PATCH 03/16] qdev-properties: add PROP_TYPE_ENUM
In reply to Anthony LiguoriQuoted 2 lines · Anthony Liguori
Quoted 1 line · Alon Levy
On Mon, Feb 07, 2011 at 09:53:44AM +0100, Markus Armbruster wrote:
[...]
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Okay, let's examine how your enumeration properties work.
An enumeration property describes a
uint32_tfield of the state object. Differences to ordinary properties defined withDEFINE_PROP_UINT32:* info is
qdev_prop_enuminstead ofqdev_prop_uint32. Differences between the two:- parse, print: symbolic names vs. numbers
- name,
print_options: only for -device DRIVER,\? (and name's use there isn't particularly helpful)
Quoted 7 lines
Quoted 3 lines
Why do you say that? this is being used by libvirt to get the names of the supported backends for the ccid-card-emulated device.
This is wrong.
Libvirt should query this information through QMP.
"We should make this information readily available through QMP", you want to say ;)
Quoted 3 lines
This is my main
concern with enums. If there isn't a useful introspection interface, libvirt is going to do dumb things like query help output.
Beggars can't be choosers.
Quoted 1 line
This has been a nightmare historically and I'm not inclined to repeat it.
No argument, but we can hardly expect poor Alon to finish the QMP job just to get his usb-ccid device in.
What would making him drop enum properties from his series accomplish? We'd get the same device with an inferior -device interface, which we then have to maintain compatibly.
Re: [Qemu-devel] [PATCH 03/16] qdev-properties: add PROP_TYPE_ENUM
In reply to Anthony LiguoriQuoted 204 lines · Anthony Liguori
Quoted 196 lines · Alon Levy
Quoted 32 lines · Markus Armbruster
I haven't been able to follow the evolution of this series, my apologies if I'm missing things already discussed.
Quoted 27 lines · Alon Levy
Example usage:
EnumTable foo_enum_table[] = { {"bar", 1}, {"buz", 2}, {NULL, 0}, };
DEFINE_PROP_ENUM("foo", State, foo, 1, foo_enum_table)When using qemu -device foodev,? it will appear as:
foodev.foo=bar/buzSigned-off-by Alon Levy<[email protected]>--- hw/qdev-properties.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++ hw/qdev.h | 15 ++++++++++++ 2 files changed, 75 insertions(+), 0 deletions(-)hw/qdev-properties.c +0
-0@@ -63,6 +63,66 @@ PropertyInfo qdev_prop_bit = { .print = print_bit, };Quoted 14 lines
hw/qdev-properties.c PropertyInfo qdev_prop_bit = { · line 77
Quoted 12 lines
hw/qdev-properties.c +12
-0+/* --- Enumeration --- */ +/* Example usage: +EnumTable foo_enum_table[] = { +{"bar", 1}, +{"buz", 2}, +{NULL, 0}, +}; +DEFINE_PROP_ENUM("foo", State, foo, 1, foo_enum_table), +*/ +static int parse_enum (DeviceState *dev,Property *prop,const char *str) +{ +uint8_t *ptr =qdev_get_prop_ptr (dev, prop);
uint8_tis inconsistent withprint_enum()andDEFINE_PROP_ENUM(), which both useuint32_t.Thanks, fixing.
Quoted 3 lines
hw/qdev-properties.c PropertyInfo qdev_prop_bit = { · line 78
Quoted 1 line
hw/qdev-properties.c +1
-0+EnumTable *option = (EnumTable *)prop->data;Please don't cast from void * to pointer type (this isn't C++).
Will fix for all references.
Quoted 3 lines
Not thrilled about the "void *data", to be honest. Smells like premature generality to me.
I did put it in there because I didn't think a "EnumTable *enum" variable would have been acceptable (added baggage just used by a single property type), and I didn't find any other place to add it. I guess I should just do a:
typedef struct EnumProperty { Property base; EnumTable *table; } EnumProperty;But then because we define the properties in a Property[] array this won't work. Maybe turn that into a Property* array?
In summary I guess data is a terrible name, but it was least amount of change. Happy to take suggestions.
Quoted 5 lines
hw/qdev-properties.c PropertyInfo qdev_prop_bit = { · line 81
Quoted 3 lines
hw/qdev-properties.c +3
-0+ +while (option->name !=NULL ) { +if (!strncmp (str, option->name,strlen (option->name))) {Why
strncmp()and not straightstrcmp()?I guess no reason except "strncmp is more secure" but irrelevant here since
option->nameis from the source, I'll fix.Quoted 12 lines
Quoted 12 lines
hw/qdev-properties.c +12
-0+ *ptr = option->value; +return 0 ; + } + option++; + } +return -EINVAL ; +} + +static int print_enum (DeviceState *dev,Property *prop,char *dest,size_t len) +{ +uint32_t *p =qdev_get_prop_ptr (dev, prop); +EnumTable *option = (EnumTable *)prop->data;Quoted 9 lines
hw/qdev-properties.c PropertyInfo qdev_prop_bit = { · line 100
Quoted 7 lines
hw/qdev-properties.c +7
-0+while (option->name !=NULL ) { +if (*p == option->value) { +return snprintf (dest, len,"%s" , option->name); + } + option++; + } +return 0 ;Bug: must dest[0] = 0 when returning 0.
will just return
snprintf(dest, len, "<enum %d>", option->value)Quoted 8 lines
hw/qdev-properties.c PropertyInfo qdev_prop_bit = { · line 106
Quoted 6 lines
hw/qdev-properties.c +6
-0+} + +static int print_enum_options (DeviceInfo *info,Property *prop,char *dest,size_t len) +{ +int ret =0 ; +EnumTable *option = (EnumTable *)prop->data;Please don't cast from void * to pointer type (this isn't C++).
fixing.
Quoted 52 lines
Quoted 52 lines
hw/qdev-properties.c +19
-0+while (option->name !=NULL ) { + ret +=snprintf (dest + ret, len - ret,"%s" , option->name); +if (option[1 ].name !=NULL ) { + ret +=snprintf (dest + ret, len - ret,"/" ); + } + option++; + } +return ret; +} + +PropertyInfo qdev_prop_enum = { + .name ="enum" , + .type =PROP_TYPE_ENUM , + .size =sizeof (uint32_t ), + .parse = parse_enum, + .print = print_enum, + .print_options = print_enum_options, +}; +/* --- 8bit integer --- */ static int parse_uint8 (DeviceState *dev,Property *prop,const char *str)hw/qdev.h +7
-0@@ -102,6 +102,7 @@ enum PropertyType {PROP_TYPE_VLAN ,PROP_TYPE_PTR ,PROP_TYPE_BIT , + PROP_TYPE_ENUM, }; struct PropertyInfo {@@ -121,6 +122,11 @@ typedef struct GlobalProperty {QTAILQ_ENTRY (GlobalProperty) next; } GlobalProperty; +typedef struct EnumTable { +const char *name; +uint32_t value; +}EnumTable ; +/*** Board API. This should go away once we have a machine config file. ***/ DeviceState *qdev_create (BusState *bus,const char *name);@@ -235,6 +241,7 @@ extern PropertyInfo qdev_prop_drive;extern PropertyInfo qdev_prop_netdev;extern PropertyInfo qdev_prop_vlan;extern PropertyInfo qdev_prop_pci_devfn; +extern PropertyInfo qdev_prop_enum;Quoted 17 lines
hw/qdev.h extern PropertyInfo qdev_prop_pci_devfn; · line 273
Quoted 13 lines
hw/qdev.h +7
-0#define DEFINE_PROP (_name, _state, _field, _prop, _type) { \ .name = (_name), \@@ -257,6 +264,14 @@ extern PropertyInfo qdev_prop_pci_devfn; + type_check(uint32_t,typeof_field(_state, _field)), \ .defval = (bool[]) { (_defval) }, \ } +#define DEFINE_PROP_ENUM (_name, _state, _field, _defval, _options) { \ + .name = (_name), \ + .info =&(qdev_prop_enum), \ + .offset = offsetof(_state, _field) \ + + type_check(uint32_t,typeof_field(_state, _field)), \ + .defval = (uint32_t[]) { (_defval) }, \ + .data = (void*)(_options), \Please don't cast from pointer type to void * (this isn't C++). If someone accidentally passes an integral argument for
_options(forgotten operator&), the cast suppresses the warning.fixing.
Quoted 12 lines
hw/qdev.h extern PropertyInfo qdev_prop_pci_devfn; · line 277
Quoted 4 lines
hw/qdev.h +1
-0+ }#define DEFINE_PROP_UINT8 (_n, _s, _f, _d) \ DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint8, uint8_t)Okay, let's examine how your enumeration properties work.
An enumeration property describes a
uint32_tfield of the state object. Differences to ordinary properties defined withDEFINE_PROP_UINT32:* info is
qdev_prop_enuminstead ofqdev_prop_uint32. Differences between the two:Quoted 6 lines
Quoted 4 lines
- parse, print: symbolic names vs. numbers
- name,
print_options: only for -device DRIVER,\? (and name's use there isn't particularly helpful)Why do you say that? this is being used by libvirt to get the names of the supported backends for the ccid-card-emulated device.
Quoted 9 lines
This is wrong.
Libvirt should query this information through QMP. This is my main concern with enums. If there isn't a useful introspection interface, libvirt is going to do dumb things like query help output.
This has been a nightmare historically and I'm not inclined to repeat it.
Fair enough, so a patch that added enumeration through QMP would be acceptable? I'm not even sure that makes sense, would you mind outlining how you see this implemented?
Quoted 5 lines
Regards,
Anthony Liguori
Re: [Qemu-devel] [PATCH 03/16] qdev-properties: add PROP_TYPE_ENUM
In reply to Markus ArmbrusterQuoted 35 lines · Markus Armbruster
Quoted 4 lines · Anthony Liguori
Quoted 2 lines · Alon Levy
On Mon, Feb 07, 2011 at 09:53:44AM +0100, Markus Armbruster wrote:
[...]
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Okay, let's examine how your enumeration properties work.
An enumeration property describes a
uint32_tfield of the state object. Differences to ordinary properties defined withDEFINE_PROP_UINT32:* info is
qdev_prop_enuminstead ofqdev_prop_uint32. Differences between the two:- parse, print: symbolic names vs. numbers
- name,
print_options: only for -device DRIVER,\? (and name's use there isn't particularly helpful)Quoted 8 lines
Quoted 4 lines
Why do you say that? this is being used by libvirt to get the names of the supported backends for the ccid-card-emulated device.
This is wrong.
Libvirt should query this information through QMP.
"We should make this information readily available through QMP", you want to say ;)
Quoted 6 lines
Quoted 4 lines
This is my main
concern with enums. If there isn't a useful introspection interface, libvirt is going to do dumb things like query help output.Beggars can't be choosers.
I'm making steady progress. I just finished device_add/device_del on a plane. I expect to have QMP fully converted in a couple weeks.
There is a lot more than I anticipated that is not available in QMP vs. the HMP so that's going to take a bit more time.
Quoted 5 lines
Quoted 2 lines
This has been a nightmare historically and I'm not inclined to repeat it.
No argument, but we can hardly expect poor Alon to finish the QMP job just to get his usb-ccid device in.
Hint: enum shouldn't block usb-ccid. An enum is equivalent to a string property to convert as far as the current command line interface so just use a string property with a well documented set of inputs, and let's do enums properly.
That's what I was suggesting in my previous replies to this series.
Quoted 2 lines
What would making him drop enum properties from his series accomplish?
We (or maybe just I) have to take QMP more seriously. I don't want to further make device properties incompatible with QMP which is what an enum property would do.
Quoted 3 lines
We'd get the same device with an inferior -device interface, which we then have to maintain compatibly.
We can retroactively make the command line interface take a symbolic value of an enum when it previously took a string with no compatibility problem.
But a QMP enum interface may not operate in strings. If it sends integer constants instead of strings, then we'll create a compatibility issue.
Regards,
Anthony Liguori
Re: [Qemu-devel] [PATCH 03/16] qdev-properties: add PROP_TYPE_ENUM
In reply to Markus ArmbrusterQuoted 80 lines · Markus Armbruster
Quoted 67 lines · Alon Levy
Quoted 32 lines · Markus Armbruster
I haven't been able to follow the evolution of this series, my apologies if I'm missing things already discussed.
Quoted 27 lines · Alon Levy
Example usage:
EnumTable foo_enum_table[] = { {"bar", 1}, {"buz", 2}, {NULL, 0}, };
DEFINE_PROP_ENUM("foo", State, foo, 1, foo_enum_table)When using qemu -device foodev,? it will appear as:
foodev.foo=bar/buzSigned-off-by Alon Levy <[email protected]>--- hw/qdev-properties.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++ hw/qdev.h | 15 ++++++++++++ 2 files changed, 75 insertions(+), 0 deletions(-)hw/qdev-properties.c +0
-0@@ -63,6 +63,66 @@ PropertyInfo qdev_prop_bit = { .print = print_bit, };Quoted 15 lines
hw/qdev-properties.c PropertyInfo qdev_prop_bit = { · line 77
Quoted 12 lines
hw/qdev-properties.c +12
-0+/* --- Enumeration --- */ +/* Example usage: +EnumTable foo_enum_table[] = { +{"bar", 1}, +{"buz", 2}, +{NULL, 0}, +}; +DEFINE_PROP_ENUM("foo", State, foo, 1, foo_enum_table), +*/ +static int parse_enum (DeviceState *dev,Property *prop,const char *str) +{ +uint8_t *ptr =qdev_get_prop_ptr (dev, prop);
uint8_tis inconsistent withprint_enum()andDEFINE_PROP_ENUM(), which both useuint32_t.Thanks, fixing.
Quoted 5 lines
hw/qdev-properties.c PropertyInfo qdev_prop_bit = { · line 78
Quoted 2 lines
hw/qdev-properties.c +1
-0+EnumTable *option = (EnumTable *)prop->data;Please don't cast from void * to pointer type (this isn't C++).
Will fix for all references.
Quoted 3 lines
Not thrilled about the "void *data", to be honest. Smells like premature generality to me.
I did put it in there because I didn't think a "EnumTable *enum" variable would have been acceptable (added baggage just used by a single property type), and I didn't find any other place to add it. I guess I should just do a:
Quoted 7 lines
typedef struct EnumProperty { Property base; EnumTable *table; } EnumProperty;But then because we define the properties in a Property[] array this won't work. Maybe turn that into a Property* array?
Doubt the additional complexity just for keeping EnumTable out of Property is worth it.
Quoted 7 lines
Quoted 2 lines
In summary I guess data is a terrible name, but it was least amount of change. Happy to take suggestions.
Further down, we discuss the idea of supporting an EnumTable with arbitrary integer type properties. Would you find an EnumTable member of Property more palatable then?
I would.
Quoted 33 lines
Quoted 33 lines
Quoted 6 lines
hw/qdev-properties.c PropertyInfo qdev_prop_bit = { · line 81
Quoted 3 lines
hw/qdev-properties.c +3
-0+ +while (option->name !=NULL ) { +if (!strncmp (str, option->name,strlen (option->name))) {Why
strncmp()and not straightstrcmp()?I guess no reason except "strncmp is more secure" but irrelevant here since
option->nameis from the source, I'll fix.Quoted 22 lines
Quoted 9 lines
hw/qdev-properties.c +9
-0+ *ptr = option->value; +return 0 ; + } + option++; + } +return -EINVAL ; +} + +static int print_enum (DeviceState *dev,Property *prop,char *dest,size_t len)hw/qdev-properties.c PropertyInfo qdev_prop_bit = { · line 100
Quoted 10 lines
hw/qdev-properties.c +10
-0+{ +uint32_t *p =qdev_get_prop_ptr (dev, prop); +EnumTable *option = (EnumTable *)prop->data; +while (option->name !=NULL ) { +if (*p == option->value) { +return snprintf (dest, len,"%s" , option->name); + } + option++; + } +return 0 ;Bug: must dest[0] = 0 when returning 0.
Quoted 5 lines
Quoted 1 line
will just return
snprintf(dest, len, "<enum %d>", option->value)Print something useful is a good idea. I guess I'd print an unadorned "%d".
Agreed.
Quoted 29 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
hw/qdev-properties.c +2
-0+} +[...]
Quoted 13 lines
Quoted 13 lines
Quoted 4 lines
+ }
#define DEFINE_PROP_UINT8(_n, _s, _f, _d) \ DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint8, uint8_t)Okay, let's examine how your enumeration properties work.
An enumeration property describes a
uint32_tfield of the state object. Differences to ordinary properties defined withDEFINE_PROP_UINT32:* info is
qdev_prop_enuminstead ofqdev_prop_uint32. Differences between the two:Quoted 7 lines
Quoted 4 lines
- parse, print: symbolic names vs. numbers
- name,
print_options: only for -device DRIVER,\? (and name's use there isn't particularly helpful)Why do you say that? this is being used by libvirt to get the names of the supported backends for the ccid-card-emulated device.
Too terse, let me try again :)
- name,
print_options: differences not important here, because these members are they are only for -device DRIVER,\?
Quoted 9 lines
By the way, I don't find help output like
e1000.mac=macaddr
e1000.vlan=vlan
e1000.netdev=netdevparticularly helpful. Not your fault, outside the scope of this patch.
Right, you get strange "X=X" output most of the time, but with print_options for enum types you actually get this:
$ x86_64-softmmu/qemu-system-x86_64 -device ccid-card-emulated,? ccid-card-emulated.backend=nss-emulated/certificates
That's actually parsable. Of course I agree with Anthony that having a json (QMP) interface with properly quoted strings (here I don't take care of backslashes in the EnumTable names for instance) would be much better.
Quoted 31 lines
Quoted 15 lines
Quoted 7 lines
* data points to an EnumTable, which is a map string <-> number. Thus, the actual enumeration is attached to the property declaration, not the property type (in programming languages, we commonly attach it to the type, not the variable declaration). Since it's a table it can be used for multiple properties with minimal fuss. Works for me.
Quoted 7 lines
What if we want to enumerate values of fields with types other than
uint32_t?C enumeration types, in particular. Tricky, because width and signedness of enum types is implementation-defined, and different enum types may differ there.
Quoted 6 lines
I specifically used
uint32_texpecting it to work for many uses. It would be better to allow an arbitrary type, or just not require specifying the type but getting it from the enum itself (using typeof?). But then you can't have a single EnumTable because it's type is now dependent on the enumeration type (of course I could resort to macros, but I don't want to go there).That's what I meant when I called it "tricky".
Still, having an enum property that cannot be used with enumeration types is kind of sad, isn't it?
Quoted 4 lines
Quoted 3 lines
Perhaps what we really need is a way to define arbitrary integer type properties with an EnumTable attached.
Quoted 9 lines
Quoted 4 lines
This sounds more promising. So you would have an EnumTableU32 etc and DEFINE_PROP_{UINT8,..}_ENUM which takes an extra EnumTable of the correct type, to be defined inline maybe so user doesn't actually declare it (like no one declares Property thanks to the
DEFINE_PROP_macros).Sounds like what I have in mind. Care to explore it?
One EnumTable should do, just make its member value wide enough.
Ok, I can try that. Sounds like it should work.
Quoted 3 lines
Note to maintainer: we don't have to get enum properties 100% right and polished before we can commit this series.
Re: [Qemu-devel] [PATCH 03/16] qdev-properties: add PROP_TYPE_ENUM
In reply to Alon LevyQuoted 4 lines · Alon Levy
Fair enough, so a patch that added enumeration through QMP would be acceptable? I'm not even sure that makes sense, would you mind outlining how you see this implemented?
Before we write any code, we need to figure out what an enum is, how we want to transport it via QMP, and how we will support introspection on it.
In terms of the protocol format, I'm inclined to suggest that we transmit enums as integers as it maps better to C. That way, we can write a first class enumeration type and build our interfaces on top of that.
I'm working on a QMP rewrite using a schema located at http://repo.or.cz/w/qemu/aliguori.git/shortlog/refs/heads/glib
The schema has the notion of defining types along side with defining interfaces. Adding a syntax to define an enum would be pretty straight forward. Probably something like:
{ 'DriftCompensationPolicy': [{'gradual': 'int'}, {'fast': 'int'}, {'none': 'int'}] }
This would in turn generate:
typedef enum DriftCompensationPolicy {
DRIFT_COMPENSATION_POLICY_GRADUAL = 0,
DRIFT_COMPENSATION_POLICY_FAST,
DRIFT_COMPENSATION_POLICY_NONE
} DriftCompensationPolicy;
From a QMP side, the value would be marshalled as an integer but the schema would contain the type 'DriftCompensationPolicy' as the type.
For -device, this would mean that enums would be treated as integer properties, and we'd need some boiler plate code to register the enum with symbolic names.
From a qdev perspective, I think it would be easier to generate a unique property type for every specific enum type. That means the qdev side ends up looking like:
PropertyInfo qdev_prop_drift_compensation_policy = {
.name = "DriftCompensationPolicy",
.type = PROP_TYPE_INT32,
.size = sizeof(DriftCompensationPolicy), .parse = parse_drift_compensation_policy,
.print = print_drift_compensation_policy,
};
struct MyDevice {
DriftCompensationPolicy drift_policy;
};DEFINE_PROP_DRIFT_COMPENSATION_POLICY("drift_policy", MyDevice, drift_policy,
DRIFT_COMPENSATION_POLICY_NONE);
We could autogenerate all of this code from the QMP schema too. It's possible to do a one-off forwards compatible enum type for qdev but I'd strongly prefer to get the QMP infrastructure in place first.
But the advantage of this approach is pretty significant IMHO. We get to work in native C enumeration types both in QEMU and libqmp. That's a big win for type safety.
BTW, if we treat QMP introspection as just returning the QMP schema that we use for code generation (it's valid JSON afterall), then we get enumeration introspection for free.
I think this efficiently gives us what danpb's earlier series was going for with his introspection patch set.
Regards,
Anthony Liguori
Quoted 7 lines
Quoted 6 lines
Regards,
Anthony Liguori
Re: [Qemu-devel] [PATCH 03/16] qdev-properties: add PROP_TYPE_ENUM
Quoted 7 lines · Anthony Liguori
Quoted 3 lines · Alon Levy
Fair enough, so a patch that added enumeration through QMP would be acceptable? I'm not even sure that makes sense, would you mind outlining how you see this implemented?
Before we write any code, we need to figure out what an enum is, how we want to transport it via QMP, and how we will support introspection on it.
Quoted 7 lines
In terms of the protocol format, I'm inclined to suggest that we transmit enums as integers as it maps better to C. That way, we can write a first class enumeration type and build our interfaces on top of that.
I'm working on a QMP rewrite using a schema located at http://repo.or.cz/w/qemu/aliguori.git/shortlog/refs/heads/glib
The schema has the notion of defining types along side with defining interfaces. Adding a syntax to define an enum would be pretty straight forward. Probably something like:
{ 'DriftCompensationPolicy': [{'gradual': 'int'}, {'fast': 'int'}, {'none': 'int'}] }
http://repo.or.cz/w/qemu/aliguori.git/commit/50375b29f512c18d03cec8b1f9fea47ffdb6b232
Is a start at what I'm talking about here. Adding the qdev type bits should be pretty straight forward.
Regards,
Anthony Liguori
Quoted 50 lines
This would in turn generate:
typedef enum DriftCompensationPolicy {
DRIFT_COMPENSATION_POLICY_GRADUAL= 0,
DRIFT_COMPENSATION_POLICY_FAST,
DRIFT_COMPENSATION_POLICY_NONE
} DriftCompensationPolicy;From a QMP side, the value would be marshalled as an integer but the schema would contain the type 'DriftCompensationPolicy' as the type.
For -device, this would mean that enums would be treated as integer properties, and we'd need some boiler plate code to register the enum with symbolic names.
From a qdev perspective, I think it would be easier to generate a unique property type for every specific enum type. That means the qdev side ends up looking like:
PropertyInfo
qdev_prop_drift_compensation_policy= {.name = "DriftCompensationPolicy", .type = PROP_TYPE_INT32, .size = sizeof(DriftCompensationPolicy),.parse =
parse_drift_compensation_policy,
.print =print_drift_compensation_policy,
};struct MyDevice { DriftCompensationPolicy drift_policy; };DEFINE_PROP_DRIFT_COMPENSATION_POLICY("drift_policy", MyDevice,
drift_policy,
DRIFT_COMPENSATION_POLICY_NONE);We could autogenerate all of this code from the QMP schema too. It's possible to do a one-off forwards compatible enum type for qdev but I'd strongly prefer to get the QMP infrastructure in place first.
But the advantage of this approach is pretty significant IMHO. We get to work in native C enumeration types both in QEMU and libqmp. That's a big win for type safety.
BTW, if we treat QMP introspection as just returning the QMP schema that we use for code generation (it's valid JSON afterall), then we get enumeration introspection for free.
I think this efficiently gives us what danpb's earlier series was going for with his introspection patch set.
Regards,
Anthony Liguori
Quoted 5 lines
Quoted 5 lines
Regards,
Anthony Liguori
Quoted 7 lines · Anthony Liguori
Quoted 6 lines · Alon Levy
Hi,
I have a v19 waiting to be sent, but it's basically the same just
with patches folded were appropriate, and the fixes Markus pointed out for the Enumeration property type.
Quoted 7 lines
Quoted 2 lines
I guess I'll wait a little longer for more feedback? Should I split
the enum property separately? it's only used by ccid-card-emualted atm.The only non-cosmetic concern I have about your series is the enum property so I would strongly suggest splitting it. If you did that for v19, it will be pretty close to merge ready.
Eric,
How does this affect libvirt? could you assume a default set of backends
if "-device ccid-card-emulated,?" returns "backend=string" instead of "backend=A/B" ?
Alon
Quoted 260 lines
Regards,
Anthony Liguori
Quoted 254 lines
Alon
Quoted 251 lines · Alon Levy
This patchset adds three new devices, usb-ccid, ccid-card-passthru and ccid-card-emulated, providing a CCID bus, a simple passthru protocol implementing card requiring a client, and a standalone emulated card.
It also introduces a new directory libcaccard with CAC card emulation, CAC is a type of ISO 7816 smart card.
Tree for pull:
git://anongit.freedesktop.org/~alon/qemuusb_ccid.v18v17-v18 changes:
* mergevscard_common.hpatches.
* actually provide a tree to pull.v16-v17 changes:
* merged all the "v15->v16" patches
* merged some more wherever it was easy (all same file commits).
* added signed off by to first four patches
*ccid.h: added copyright, removed underscore in defines, and replaced non C89 commentsv15-v16 changes:
* splitvscard_commonintroducing patch for ease of review
* sum of commit logs for the v15-v16 commits: (whitespace fixes
removed for space, see original commit messages in later patches)
* usb-ccid:
* 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 inccid_set_parameters
* add missing abRFU in SetParameters (no affect on linux guest)
*vscard_common.hprotocol change:
* VSCMsgInit capabilities and magic
* removed ReaderResponse, will use Error instead with code==VSC_SUCCESS.
* added Flush and FlushComplete, remove Reconnect.
* defineVSCARD_MAGIC
* added error codeVSC_SUCCESS.
* ccid-card-passthru
* return correct size
* return error instead of assert if client sent too large ATR
* don't assert if client sent too large a size, but add asserts for indices to buffer
* resetvscard_inindices on chardev disconnect
* handle init from client
* error if no chardev supplied
* use ntoh, hton
* eradicatereader_id_t
* remove Reconnect usage (removed from VSCARD protocol)
* sendVSC_SUCCESSon card insert/remove and reader add/remove
* ccid-card-emulated
* fix error reporting in initfnv14-v15 changes:
* add patch with --enable-smartcard and --disable-smartcard and only disable ccid-card-emulated if nss not found.
* add patch with description strings
* s/libcaccard/libcacard/ indocs/ccid.txtv13-v14 changes:
- support device_del/device_add on ccid-card-* and usb-ccid
* usb-ccid:
* lose card reference when card device deleted
* check slot number and deny adding a slot if one is already added.
* ccid-card-*: useqdev_simple_unplug_cbin both emulated and passthru ccid cards, the exitfn already takes care of triggering card removal in the usb dev.
* libcacard:
* remove double include of config-host.mak
* add replay of card events to libcacard to support second and more emulation
* don't initialize more then once (doesn't support it right now, so one thread, NSS thread, is left whendevice_delis done)
* addVCARD_EMUL_INIT_ALREADY_INITED
* ccid-card-emulated:
* take correct mutexes on signaling to fix deadlocks ondevice_del
* allow card insertion/removal event without proper reader insertion eventv12-v13 changes:
* libcacard:
* fixMakefileclean to remove vscclient
* fix double include of config-host inMakefile
* usb-ccid: remove attach/detach logic, usb is always attached. Guest doesn't care if there is a reader attached with no card anyway.
* ccid-card-passthru: don't closechr_devon removal, makes it possible to use device_del/device_add to create remove/insertion for debugging.v11-v12 changes:
* fix out of tree buildv10-v11 changes:
* fix last patch that removed one of the doc files.
* updated flow table indocs/ccid.txtv8-v10 changes:
* usb-ccid:
* add slot for future use (Gerd)
* ifdefENABLE_MIGRATIONfor migration support on account of usb migration not being ready in general. (Gerd)
* verbosified commit messages. (Gerd)
* put libcacard docs in libcacard commit. (Gerd)v8-v9 changes:
* Blue Swirl comments:
* white space fixes
* enabled by default, disabled only if missing nss
* forgotten fix from v8 (don't build libcacard.so)
* added a note about device being little endian
* library renamed from libcaccard to libcacard
* squashed both of libcacard patches, they touched different files anyway.v7-v8 changes:
* Blue Swirl comments:
* usb-ccid: deannonymize some structs
* usb-ccid: coding style change -answer_tandbulk_in_tfixed
* usb-ccid: handle endianess conversion between guest and host
* usb-ccid: s/ccid_bulk_in_copy_out/ccid_bulk_in_copy_to_guest/
* ccid-card-emulated: fix segfault if backend not specified
* ccid-card-emulated: let last reader inserted win
* libcaccard: remove doublevscard_common.h
v6->v7changes:
* external libcaccard became internal directory libcaccard
* statically link object files into qemu
* produce libcaccard.so for usage by external projects
* applied coding style to new code (please check me)
- did not use the qemu options parsing for libcaccard, since it seems to draw large amounts of qemu code (monitor for instance).
v5->v6changes:
* really remove static debug (I apologize for claiming to have done so before)
v4->v5changes:
* rebased to latest
* remove static debug in card devices
* fix --enable-smartcard to link
* stall instead of assert when exceedingBULK_OUT_DATA_SIZE
* makeccid_reserve_recv_buffor too large len discard message, not exit
* makeccid_reserve_recv_bufreturn void*
* fix typo
* remove commented code in VMState
v3->v4:
* remove ccid field in CCIDBus
* remove static debug in bus
* add back docs
v2->v3:
* split into bus (usb-ccid.c, usesccid.h) and card (ccid-card-passthru.c).
* removed documentation (being revised).
v1->v2:
* 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 (15):
qdev: addprint_optionscallback
qdev: add data pointer to Property
qdev-properties: addPROP_TYPE_ENUM
qdev-properties:parse_enum: don't cast a void*
usb-ccid: add CCID bus
introducelibcacard/vscard_common.h
ccid: add passthru card device
ccid: add ccid-card-emulated device (v2)
ccid: add docs
ccid: configure: add --enable/disable and nss only disable
ccid: add qdev description strings
smartcard,configure: add --enable-smartcard-nss, report only nss smartcard,configure: report only nss
ccid-card-emulated: don't link with NSS if --disable-smartcard-nssccid.h: add copyright, fix define and remove non C89 commentsRobert Relyea (1):
libcacard: initial commitMakefile | 6 +- Makefile.objs | 7 + Makefile.target | 2 + configure | 60 ++ docs/ccid.txt | 135 +++++ docs/libcacard.txt | 483 +++++++++++++++ hw/ccid-card-emulated.c | 551 ++++++++++++++++++ hw/ccid-card-passthru.c | 329 +++++++++++ hw/ccid.h | 51 ++ hw/qdev-properties.c | 60 ++ hw/qdev.c | 10 +- hw/qdev.h | 17 + hw/usb-ccid.c | 1353 +++++++++++++++++++++++++++++++++++++++++++ libcacard/Makefile | 14 + libcacard/cac.c | 411 +++++++++++++ libcacard/cac.h | 20 + libcacard/card_7816.c | 780 +++++++++++++++++++++++++ libcacard/card_7816.h | 60 ++ libcacard/card_7816t.h | 163 ++++++ libcacard/event.c | 112 ++++ libcacard/eventt.h | 28 + libcacard/link_test.c | 20 + libcacard/mutex.h | 59 ++ libcacard/passthru.c | 612 +++++++++++++++++++ libcacard/passthru.h | 50 ++ libcacard/vcard.c | 350 +++++++++++ libcacard/vcard.h | 85 +++ libcacard/vcard_emul.h | 62 ++ libcacard/vcard_emul_nss.c | 1192 +++++++++++++++++++++++++++++++++++++ libcacard/vcard_emul_type.c | 60 ++ libcacard/vcard_emul_type.h | 29 + libcacard/vcardt.h | 66 +++ libcacard/vevent.h | 26 + libcacard/vreader.c | 526 +++++++++++++++++ libcacard/vreader.h | 54 ++ libcacard/vreadert.h | 23 + libcacard/vscard_common.h | 167 ++++++ libcacard/vscclient.c | 743 ++++++++++++++++++++++++ 38 files changed, 8773 insertions(+), 3 deletions(-) create mode 100644 docs/ccid.txt create mode 100644 docs/libcacard.txt create mode 100644 hw/ccid-card-emulated.c create mode 100644 hw/ccid-card-passthru.c create mode 100644 hw/ccid.h create mode 100644 hw/usb-ccid.c create mode 100644 libcacard/Makefile create mode 100644 libcacard/cac.c create mode 100644 libcacard/cac.h create mode 100644 libcacard/card_7816.c create mode 100644 libcacard/card_7816.h create mode 100644 libcacard/card_7816t.h create mode 100644 libcacard/event.c create mode 100644 libcacard/eventt.h create mode 100644 libcacard/link_test.c create mode 100644 libcacard/mutex.h create mode 100644 libcacard/passthru.c create mode 100644 libcacard/passthru.h create mode 100644 libcacard/vcard.c create mode 100644 libcacard/vcard.h create mode 100644 libcacard/vcard_emul.h create mode 100644 libcacard/vcard_emul_nss.c create mode 100644 libcacard/vcard_emul_type.c create mode 100644 libcacard/vcard_emul_type.h create mode 100644 libcacard/vcardt.h create mode 100644 libcacard/vevent.h create mode 100644 libcacard/vreader.c create mode 100644 libcacard/vreader.h create mode 100644 libcacard/vreadert.h create mode 100644 libcacard/vscard_common.h create mode 100644 libcacard/vscclient.cSignature · 1 line
1.7.4
[adding libvir-list as well]
Quoted 8 lines · Alon Levy
Quoted 7 lines
Quoted 2 lines
I guess I'll wait a little longer for more feedback? Should I split
the enum property separately? it's only used by ccid-card-emualted atm.The only non-cosmetic concern I have about your series is the enum property so I would strongly suggest splitting it. If you did that for v19, it will be pretty close to merge ready.
Quoted 5 lines
Eric,
How does this affect libvirt? could you assume a default set of backends
if "-device ccid-card-emulated,?" returns "backend=string" instead of "backend=A/B" ?
Hmm. At the moment, libvirt only looks for "ccid-card-emulated" in the -device ? list, and hasn't yet tried inspecting -device ccid-card-emulated,? output. In short, libvirt assumes that the presence of ccid-card-emulated implies that both modes are available (libvirt's <smartcard mode='host'/> => backend=nss-emulated; <smartcard mode='host-certificates' => backend=certificates). Is it possible for qemu to have support for one, but not both, of those modes? If that's the case, then supporting "backend=nss-emulated/certificates" in -device ccid-card-emulated,? would be handy for libvirt (for example, it would be just "backend=certificates" if nss-emulated is not available). But if it's an all-or-none approach (all backends are available if ccid-card-emulated is present), then libvirt's current code won't be impacted by changing the string to the simpler "backend=string".
Signature · 2 lines
Eric Blake [email protected] +1-801-349-2682 Libvirt virtualization library http://libvirt.org
Quoted 18 lines · Eric Blake
[adding libvir-list as well]
Quoted 8 lines · Alon Levy
Quoted 8 lines
Quoted 3 lines
I guess I'll wait a little longer for more feedback? Should I split
the enum property separately? it's only used by ccid-card-emualted atm.The only non-cosmetic concern I have about your series is the enum property so I would strongly suggest splitting it. If you did that for v19, it will be pretty close to merge ready.
Quoted 6 lines
Eric,
How does this affect libvirt? could you assume a default set of backends
if "-device ccid-card-emulated,?" returns "backend=string" instead of "backend=A/B" ?
Quoted 6 lines
Hmm. At the moment, libvirt only looks for "ccid-card-emulated" in the -device ? list, and hasn't yet tried inspecting -device ccid-card-emulated,? output. In short, libvirt assumes that the presence of ccid-card-emulated implies that both modes are available (libvirt's<smartcard mode='host'/> => backend=nss-emulated;<smartcard mode='host-certificates' => backend=certificates).
Why is libvirt assuming anything about a feature that isn't in upstream QEMU?
Regards,
Anthony Liguori
Quoted 10 lines
Is it possible for
qemu to have support for one, but not both, of those modes? If that's the case, then supporting "backend=nss-emulated/certificates" in -device ccid-card-emulated,? would be handy for libvirt (for example, it would be just "backend=certificates" if nss-emulated is not available). But if it's an all-or-none approach (all backends are available if ccid-card-emulated is present), then libvirt's current code won't be impacted by changing the string to the simpler "backend=string".
Quoted 17 lines · Eric Blake
[adding libvir-list as well]
Quoted 8 lines · Alon Levy
Quoted 7 lines
Quoted 2 lines
I guess I'll wait a little longer for more feedback? Should I split
the enum property separately? it's only used by ccid-card-emualted atm.The only non-cosmetic concern I have about your series is the enum property so I would strongly suggest splitting it. If you did that for v19, it will be pretty close to merge ready.
Quoted 5 lines
Eric,
How does this affect libvirt? could you assume a default set of backends
if "-device ccid-card-emulated,?" returns "backend=string" instead of "backend=A/B" ?
Quoted 14 lines
Hmm. At the moment, libvirt only looks for "ccid-card-emulated" in the -device ? list, and hasn't yet tried inspecting -device ccid-card-emulated,? output. In short, libvirt assumes that the presence of ccid-card-emulated implies that both modes are available (libvirt's <smartcard mode='host'/> => backend=nss-emulated; <smartcard mode='host-certificates' => backend=certificates). Is it possible for qemu to have support for one, but not both, of those modes? If that's the case, then supporting "backend=nss-emulated/certificates" in -device ccid-card-emulated,? would be handy for libvirt (for example, it would be just "backend=certificates" if nss-emulated is not available). But if it's an all-or-none approach (all backends are available if ccid-card-emulated is present), then libvirt's current code won't be impacted by changing the string to the simpler "backend=string".
So turns out this was not actually required (except as a measure to spart a discussion on enums). Since right now it is all or nothing as you say, there is no immediate need for this, so I'll just drop it, and when a QMP solution materialized I can use it.
Quoted 4 lines
Signature · 2 lines
Eric Blake [email protected] +1-801-349-2682 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 03/16] qdev-properties: add PROP_TYPE_ENUM
In reply to Alon LevyQuoted 217 lines · Alon Levy
Quoted 80 lines · Markus Armbruster
Quoted 67 lines · Alon Levy
Quoted 32 lines · Markus Armbruster
I haven't been able to follow the evolution of this series, my apologies if I'm missing things already discussed.
Quoted 27 lines · Alon Levy
Example usage:
EnumTable foo_enum_table[] = { {"bar", 1}, {"buz", 2}, {NULL, 0}, };
DEFINE_PROP_ENUM("foo", State, foo, 1, foo_enum_table)When using qemu -device foodev,? it will appear as:
foodev.foo=bar/buzSigned-off-by Alon Levy <[email protected]>--- hw/qdev-properties.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++ hw/qdev.h | 15 ++++++++++++ 2 files changed, 75 insertions(+), 0 deletions(-)hw/qdev-properties.c +0
-0@@ -63,6 +63,66 @@ PropertyInfo qdev_prop_bit = { .print = print_bit, };Quoted 15 lines
hw/qdev-properties.c PropertyInfo qdev_prop_bit = { · line 77
Quoted 12 lines
hw/qdev-properties.c +12
-0+/* --- Enumeration --- */ +/* Example usage: +EnumTable foo_enum_table[] = { +{"bar", 1}, +{"buz", 2}, +{NULL, 0}, +}; +DEFINE_PROP_ENUM("foo", State, foo, 1, foo_enum_table), +*/ +static int parse_enum (DeviceState *dev,Property *prop,const char *str) +{ +uint8_t *ptr =qdev_get_prop_ptr (dev, prop);
uint8_tis inconsistent withprint_enum()andDEFINE_PROP_ENUM(), which both useuint32_t.Thanks, fixing.
Quoted 5 lines
hw/qdev-properties.c PropertyInfo qdev_prop_bit = { · line 78
Quoted 2 lines
hw/qdev-properties.c +1
-0+EnumTable *option = (EnumTable *)prop->data;Please don't cast from void * to pointer type (this isn't C++).
Will fix for all references.
Quoted 3 lines
Not thrilled about the "void *data", to be honest. Smells like premature generality to me.
I did put it in there because I didn't think a "EnumTable *enum" variable would have been acceptable (added baggage just used by a single property type), and I didn't find any other place to add it. I guess I should just do a:
Quoted 7 lines
typedef struct EnumProperty { Property base; EnumTable *table; } EnumProperty;But then because we define the properties in a Property[] array this won't work. Maybe turn that into a Property* array?
Doubt the additional complexity just for keeping EnumTable out of Property is worth it.
Quoted 7 lines
Quoted 2 lines
In summary I guess data is a terrible name, but it was least amount of change. Happy to take suggestions.
Further down, we discuss the idea of supporting an EnumTable with arbitrary integer type properties. Would you find an EnumTable member of Property more palatable then?
I would.
Quoted 33 lines
Quoted 33 lines
Quoted 6 lines
hw/qdev-properties.c PropertyInfo qdev_prop_bit = { · line 81
Quoted 3 lines
hw/qdev-properties.c +3
-0+ +while (option->name !=NULL ) { +if (!strncmp (str, option->name,strlen (option->name))) {Why
strncmp()and not straightstrcmp()?I guess no reason except "strncmp is more secure" but irrelevant here since
option->nameis from the source, I'll fix.Quoted 22 lines
Quoted 9 lines
hw/qdev-properties.c +9
-0+ *ptr = option->value; +return 0 ; + } + option++; + } +return -EINVAL ; +} + +static int print_enum (DeviceState *dev,Property *prop,char *dest,size_t len)hw/qdev-properties.c PropertyInfo qdev_prop_bit = { · line 100
Quoted 10 lines
hw/qdev-properties.c +10
-0+{ +uint32_t *p =qdev_get_prop_ptr (dev, prop); +EnumTable *option = (EnumTable *)prop->data; +while (option->name !=NULL ) { +if (*p == option->value) { +return snprintf (dest, len,"%s" , option->name); + } + option++; + } +return 0 ;Bug: must dest[0] = 0 when returning 0.
Quoted 5 lines
Quoted 1 line
will just return
snprintf(dest, len, "<enum %d>", option->value)Print something useful is a good idea. I guess I'd print an unadorned "%d".
Agreed.
Quoted 29 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
hw/qdev-properties.c +2
-0+} +[...]
Quoted 13 lines
Quoted 13 lines
Quoted 4 lines
+ }
#define DEFINE_PROP_UINT8(_n, _s, _f, _d) \ DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint8, uint8_t)Okay, let's examine how your enumeration properties work.
An enumeration property describes a
uint32_tfield of the state object. Differences to ordinary properties defined withDEFINE_PROP_UINT32:* info is
qdev_prop_enuminstead ofqdev_prop_uint32. Differences between the two:Quoted 7 lines
Quoted 4 lines
- parse, print: symbolic names vs. numbers
- name,
print_options: only for -device DRIVER,\? (and name's use there isn't particularly helpful)Why do you say that? this is being used by libvirt to get the names of the supported backends for the ccid-card-emulated device.
Too terse, let me try again :)
- name,
print_options: differences not important here, because these members are they are only for -device DRIVER,\?Quoted 9 lines
By the way, I don't find help output like
e1000.mac=macaddr
e1000.vlan=vlan
e1000.netdev=netdevparticularly helpful. Not your fault, outside the scope of this patch.
Right, you get strange "X=X" output most of the time, but with
print_optionsfor enum types you actually get this:$ x86_64-softmmu/qemu-system-x86_64 -device ccid-card-emulated,? ccid-card-emulated.backend=nss-emulated/certificatesThat's actually parsable. Of course I agree with Anthony that having a json (QMP) interface with properly quoted strings (here I don't take care of backslashes in the EnumTable names for instance) would be much better.
Quoted 36 lines
Quoted 15 lines
Quoted 7 lines
* data points to an EnumTable, which is a map string <-> number. Thus, the actual enumeration is attached to the property declaration, not the property type (in programming languages, we commonly attach it to the type, not the variable declaration). Since it's a table it can be used for multiple properties with minimal fuss. Works for me.
Quoted 7 lines
What if we want to enumerate values of fields with types other than
uint32_t?C enumeration types, in particular. Tricky, because width and signedness of enum types is implementation-defined, and different enum types may differ there.
Quoted 6 lines
I specifically used
uint32_texpecting it to work for many uses. It would be better to allow an arbitrary type, or just not require specifying the type but getting it from the enum itself (using typeof?). But then you can't have a single EnumTable because it's type is now dependent on the enumeration type (of course I could resort to macros, but I don't want to go there).That's what I meant when I called it "tricky".
Still, having an enum property that cannot be used with enumeration types is kind of sad, isn't it?
Quoted 8 lines
Quoted 3 lines
Perhaps what we really need is a way to define arbitrary integer type properties with an EnumTable attached.
This sounds more promising. So you would have an EnumTableU32 etc and DEFINE_PROP_{UINT8,..}_ENUM which takes an extra EnumTable of the correct type, to be defined inline maybe so user doesn't actually declare it (like no one declares Property thanks to the
DEFINE_PROP_macros).
Quoted 7 lines
Quoted 4 lines
Sounds like what I have in mind. Care to explore it?
One EnumTable should do, just make its member value wide enough.
Ok, I can try that. Sounds like it should work.
Changed my mind - Since libvirt is happy with a string, and this is not something I really have time to pursue, and Anthony is making a better solution IIUC, I'm dropping this.
Quoted 4 lines
Quoted 3 lines
Note to maintainer: we don't have to get enum properties 100% right and polished before we can commit this series.
Re: [Qemu-devel] [PATCH 03/16] qdev-properties: add PROP_TYPE_ENUM
Quoted 2 lines · Alon Levy
Quoted 1 line · Alon Levy
On Mon, Feb 07, 2011 at 03:00:25PM +0100, Markus Armbruster wrote:
[...]
Quoted 11 lines
Quoted 7 lines
Quoted 4 lines
Sounds like what I have in mind. Care to explore it?
One EnumTable should do, just make its member value wide enough.
Ok, I can try that. Sounds like it should work.
Changed my mind - Since libvirt is happy with a string, and this is not something I really have time to pursue, and Anthony is making a better solution IIUC, I'm dropping this.
That's okay.