diff options
author | Alon Levy <alevy@redhat.com> | 2010-08-15 18:11:10 +0300 |
---|---|---|
committer | Alon Levy <alevy@redhat.com> | 2010-08-15 18:11:10 +0300 |
commit | fb2ed4398ce45cbc4942d723f30fafb6cc855c64 (patch) | |
tree | e004fe7ed8ccbc97ec1333fb11172d64e18bd123 /vscard_common.h | |
parent | c4523f6d1a009ebcb93b4161c86e3ce02dfa9b4c (diff) |
updated protocol including version tracking, init message, reader addition/removal
Diffstat (limited to 'vscard_common.h')
-rw-r--r-- | vscard_common.h | 126 |
1 files changed, 114 insertions, 12 deletions
diff --git a/vscard_common.h b/vscard_common.h index 7e90a58..3a79eab 100644 --- a/vscard_common.h +++ b/vscard_common.h @@ -1,16 +1,118 @@ -#ifndef _SCARD_COMMON_H -#define _SCARD_COMMON_H +/* 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. + * + * 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. + * + * Copyright (c) 2010 Red Hat. + * + * This code is licensed under the LGPL. + */ + +#ifndef _VSCARD_COMMON_H +#define _VSCARD_COMMON_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,1) + +#define VSCARD_UNDEFINED_READER_ID -1 +#define VSCARD_MINIMAL_READER_ID 0 + +typedef enum { + VSC_Init, + VSC_Error, + VSC_ReaderAdd, + VSC_ReaderAddResponse, + VSC_ReaderRemove, + VSC_ATR, + VSC_CardRemove, + VSC_APDU +} VSCMsgType; typedef enum { - SCard_ATR, - SCard_APDU, - SCard_Remove, - SCard_Error -} MsgType; - -typedef struct SCRMsgHeader { - MsgType type; - unsigned int nLength; -} SCRMsgHeader; + VSC_GENERAL_ERROR=1, + VSC_CANNOT_ADD_MORE_READERS, +} VSCErrorCode; + +typedef struct VSCMsgHeader { + VSCMsgType type; + uint32_t reader_id; + uint32_t length; +} VSCMsgHeader; + +/* VSCMsgInit Client <-> Host + * Host replies with allocated reader id in ReaderAddResponse + * */ +typedef struct VSCMsgInit { + uint32_t version; +} VSCMsgInit; + +/* VSCMsgError Client <-> Host + * */ +typedef struct VSCMsgError { + VSCErrorCode code; +} VSCMsgError; + +/* VSCMsgReaderAdd Client -> Host + * Host replies with allocated reader id in ReaderAddResponse + * */ +typedef struct VSCMsgReaderAdd { + uint8_t name[0]; +} VSCMsgReaderAdd; + +/* VSCMsgReaderAddResponse Host -> Client + * Reply to ReaderAdd + * */ +typedef struct VSCMsgReaderAddResponse { +} VSCMsgReaderAddResponse; + +/* VSCMsgReaderRemove Client -> Host + * */ +typedef struct VSCMsgReaderRemove { +} VSCMsgReaderRemove; + +/* VSCMsgATR Client -> Host + * Answer to reset. Sent for card insertion or card reset. + * */ +typedef struct VSCMsgATR { + uint8_t atr[0]; +} VSCMsgATR; + +/* VSCMsgCardRemove Client -> Host + * */ +typedef struct VSCMsgCardRemove { +} VSCMsgCardRemove; + +/* VSCMsgAPDU Client <-> Host + * */ +typedef struct VSCMsgAPDU { + uint8_t data[0]; +} VSCMsgAPDU; #endif |