qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Alon Levy <alevy@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 08/20] libcacard/vscard_common.h update (v15->v16)
Date: Wed,  2 Feb 2011 22:28:08 +0200	[thread overview]
Message-ID: <1296678500-19497-9-git-send-email-alevy@redhat.com> (raw)
In-Reply-To: <1296678500-19497-1-git-send-email-alevy@redhat.com>

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

Signed-off-by: Alon Levy <alevy@redhat.com>
---
 libcacard/vscard_common.h |  103 ++++++++++++++++++++++++++++++--------------
 1 files changed, 70 insertions(+), 33 deletions(-)

diff --git a/libcacard/vscard_common.h b/libcacard/vscard_common.h
index 9ff1295..5cb6eb5 100644
--- a/libcacard/vscard_common.h
+++ b/libcacard/vscard_common.h
@@ -1,20 +1,25 @@
 /* Virtual Smart Card protocol definition
  *
- * This protocol is between a host implementing a group of virtual smart card
- * reader, and a client implementing a virtual smart card, or passthrough to
- * a real card.
+ * 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 and provide for error responses.
+ * removal of cards, negotiate the protocol via capabilities and provide
+ * for error responses.
  *
- * Copyright (c) 2010 Red Hat.
+ * Copyright (c) 2011 Red Hat.
  *
  * This code is licensed under the LGPL.
  */
 
-#ifndef _VSCARD_COMMON_H
-#define _VSCARD_COMMON_H
+#ifndef VSCARD_COMMON_H
+#define VSCARD_COMMON_H
 
 #include <stdint.h>
 
@@ -40,91 +45,123 @@
  * something that cannot be accomodated with the existing protocol.
  */
 
-#define VSCARD_VERSION MAKE_VERSION(0,0,1)
+#define VSCARD_VERSION MAKE_VERSION(0,0,2)
 
-typedef enum {
-    VSC_Init,
+typedef enum VSCMsgType {
+    VSC_Init = 1,
     VSC_Error,
     VSC_ReaderAdd,
-    VSC_ReaderAddResponse,
     VSC_ReaderRemove,
     VSC_ATR,
     VSC_CardRemove,
     VSC_APDU,
-    VSC_Reconnect
+    VSC_Flush,
+    VSC_FlushComplete
 } VSCMsgType;
 
-typedef enum {
+typedef enum VSCErrorCode {
+    VSC_SUCCESS=0,
     VSC_GENERAL_ERROR=1,
     VSC_CANNOT_ADD_MORE_READERS,
+    VSC_CARD_ALREAY_INSERTED,
 } VSCErrorCode;
 
-typedef uint32_t reader_id_t;
-#define VSCARD_UNDEFINED_READER_ID 0xffffffff
+#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 {
-    VSCMsgType type;
-    reader_id_t   reader_id;
+    uint32_t   type;
+    uint32_t   reader_id;
     uint32_t   length;
     uint8_t    data[0];
 } VSCMsgHeader;
 
 /* VSCMsgInit               Client <-> Host
- * Host replies with allocated reader id in ReaderAddResponse
+ * 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 ReaderAddResponse
- * name - name of the reader on client side.
+ * 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;
 
-/* VSCMsgReaderAddResponse  Host -> Client
- * Reply to ReaderAdd
- * */
-typedef struct VSCMsgReaderAddResponse {
-} VSCMsgReaderAddResponse;
-
 /* 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.
+ * 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;
 
-/* VSCMsgReconnect          Host -> Client
+/* VSCMsgFlush               Host -> Client
+ * Request client to send a FlushComplete message when it is done
+ * servicing all outstanding APDUs
  * */
-typedef struct VSCMsgReconnect {
-    uint32_t   ip;
-    uint16_t   port;
-} VSCMsgReconnect;
+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 */
 
-#endif
-- 
1.7.4

  parent reply	other threads:[~2011-02-02 20:28 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-02 20:28 [Qemu-devel] [PATCH 00/20] usb-ccid (v16) Alon Levy
2011-02-02 20:28 ` [Qemu-devel] [PATCH 01/20] qdev: add print_options callback Alon Levy
2011-02-03 16:39   ` Anthony Liguori
2011-02-03 20:54     ` Alon Levy
2011-02-02 20:28 ` [Qemu-devel] [PATCH 02/20] qdev: add data pointer to Property Alon Levy
2011-02-02 20:28 ` [Qemu-devel] [PATCH 03/20] qdev-properties: add PROP_TYPE_ENUM Alon Levy
2011-02-03 16:44   ` Anthony Liguori
2011-02-03 20:59     ` Alon Levy
2011-02-02 20:28 ` [Qemu-devel] [PATCH 04/20] qdev-properties: parse_enum: don't cast a void* Alon Levy
2011-02-02 20:28 ` [Qemu-devel] [PATCH 05/20] usb-ccid: add CCID bus Alon Levy
2011-02-03 16:46   ` Anthony Liguori
2011-02-03 18:53     ` Alon Levy
2011-02-03 19:29       ` Alon Levy
2011-02-02 20:28 ` [Qemu-devel] [PATCH 06/20] usb-ccid: review fixes (v15-v16) Alon Levy
2011-02-03 16:48   ` Anthony Liguori
2011-02-03 18:53     ` Alon Levy
2011-02-02 20:28 ` [Qemu-devel] [PATCH 07/20] introduce libcacard/vscard_common.h Alon Levy
2011-02-02 20:28 ` Alon Levy [this message]
2011-02-02 20:28 ` [Qemu-devel] [PATCH 09/20] ccid: add passthru card device Alon Levy
2011-02-02 20:28 ` [Qemu-devel] [PATCH 10/20] ccid-card-passthru: review fixes (v15->v16) Alon Levy
2011-02-02 20:28 ` [Qemu-devel] [PATCH 11/20] libcacard: initial commit after coding style fixes Alon Levy
2011-02-02 20:28 ` [Qemu-devel] [PATCH 12/20] libcacard: fixes from review (v15->v16) Alon Levy
2011-02-02 20:28 ` [Qemu-devel] [PATCH 13/20] ccid: add ccid-card-emulated device (v2) Alon Levy
2011-02-02 20:28 ` [Qemu-devel] [PATCH 14/20] ccid-card-emulated: use PROP_TYPE_ENUM for backend Alon Levy
2011-02-02 20:28 ` [Qemu-devel] [PATCH 15/20] ccid-card-emulated: review fixes (v15->v16) Alon Levy
2011-02-02 20:28 ` [Qemu-devel] [PATCH 16/20] ccid: add docs Alon Levy
2011-02-02 20:28 ` [Qemu-devel] [PATCH 17/20] ccid: configure: add --enable/disable and nss only disable Alon Levy
2011-02-02 20:28 ` [Qemu-devel] [PATCH 18/20] ccid: add qdev description strings Alon Levy
2011-02-02 20:28 ` [Qemu-devel] [PATCH 19/20] smartcard, configure: add --enable-smartcard-nss, report only nss Alon Levy
2011-02-02 20:28 ` [Qemu-devel] [PATCH 20/20] smartcard,configure: " Alon Levy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1296678500-19497-9-git-send-email-alevy@redhat.com \
    --to=alevy@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).