1 /* Virtual Smart Card protocol definition
3 * This protocol is between a host using virtual smart card readers,
4 * and a client providing the smart cards, perhaps by emulating them or by
5 * access to real cards.
7 * Definitions for this protocol:
8 * Host - user of the card
9 * Client - owner of the card
11 * The current implementation passes the raw APDU's from 7816 and additionally
12 * contains messages to setup and teardown readers, handle insertion and
13 * removal of cards, negotiate the protocol via capabilities and provide
14 * for error responses.
16 * Copyright (c) 2011 Red Hat.
18 * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
19 * See the COPYING.LIB file in the top-level directory.
22 #ifndef VSCARD_COMMON_H
23 #define VSCARD_COMMON_H
27 #define VERSION_MAJOR_BITS 11
28 #define VERSION_MIDDLE_BITS 11
29 #define VERSION_MINOR_BITS 10
31 #define MAKE_VERSION(major, middle, minor) \
32 ((major << (VERSION_MINOR_BITS + VERSION_MIDDLE_BITS)) \
33 | (middle << VERSION_MINOR_BITS) \
37 * IMPORTANT NOTE on VERSION
39 * The version below MUST be changed whenever a change in this file is made.
41 * The last digit, the minor, is for bug fix changes only.
43 * The middle digit is for backward / forward compatible changes, updates
44 * to the existing messages, addition of fields.
46 * The major digit is for a breaking change of protocol, presumably
47 * something that cannot be accommodated with the existing protocol.
50 #define VSCARD_VERSION MAKE_VERSION(0, 0, 2)
52 typedef enum VSCMsgType
{
64 typedef enum VSCErrorCode
{
66 VSC_GENERAL_ERROR
= 1,
67 VSC_CANNOT_ADD_MORE_READERS
,
68 VSC_CARD_ALREAY_INSERTED
,
71 #define VSCARD_UNDEFINED_READER_ID 0xffffffff
72 #define VSCARD_MINIMAL_READER_ID 0
74 #define VSCARD_MAGIC (*(uint32_t *)"VSCD")
78 * Each message starts with the header.
80 * reader_id - used by messages that are reader specific
81 * length - length of payload (not including header, i.e. zero for
82 * messages containing empty payloads)
84 typedef struct VSCMsgHeader
{
92 * VSCMsgInit Client <-> Host
93 * Client sends it on connection, with its own capabilities.
94 * Host replies with VSCMsgInit filling in its capabilities.
96 * It is not meant to be used for negotiation, i.e. sending more then
97 * once from any side, but could be used for that in the future.
99 typedef struct VSCMsgInit
{
102 uint32_t capabilities
[1]; /* receiver must check length,
103 array may grow in the future*/
107 * VSCMsgError Client <-> Host
108 * This message is a response to any of:
112 * If the operation was successful then VSC_SUCCESS
113 * is returned, other wise a specific error code.
115 typedef struct VSCMsgError
{
120 * VSCMsgReaderAdd Client -> Host
121 * Host replies with allocated reader id in VSCMsgError with code==SUCCESS.
123 * name - name of the reader on client side, UTF-8 encoded. Only used
124 * for client presentation (may be translated to the device presented to the
125 * guest), protocol wise only reader_id is important.
127 typedef struct VSCMsgReaderAdd
{
132 * VSCMsgReaderRemove Client -> Host
133 * The client's reader has been removed.
135 typedef struct VSCMsgReaderRemove
{
136 } VSCMsgReaderRemove
;
139 * VSCMsgATR Client -> Host
140 * Answer to reset. Sent for card insertion or card reset. The reset/insertion
141 * happens on the client side, they do not require any action from the host.
143 typedef struct VSCMsgATR
{
148 * VSCMsgCardRemove Client -> Host
149 * The client card has been removed.
151 typedef struct VSCMsgCardRemove
{
155 * VSCMsgAPDU Client <-> Host
156 * Main reason of existence. Transfer a single APDU in either direction.
158 typedef struct VSCMsgAPDU
{
163 * VSCMsgFlush Host -> Client
164 * Request client to send a FlushComplete message when it is done
165 * servicing all outstanding APDUs
167 typedef struct VSCMsgFlush
{
171 * VSCMsgFlush Client -> Host
172 * Client response to Flush after all APDUs have been processed and
175 typedef struct VSCMsgFlushComplete
{
176 } VSCMsgFlushComplete
;
178 #endif /* VSCARD_COMMON_H */