2008-03-06 16:06:59 +00:00
|
|
|
#ifndef __INTERNAL_WINSCARD_H
|
|
|
|
#define __INTERNAL_WINSCARD_H
|
|
|
|
|
|
|
|
/* Mostly copied from pcsc-lite, this is the minimum required */
|
|
|
|
|
|
|
|
#if defined(HAVE_INTTYPES_H)
|
|
|
|
#include <inttypes.h>
|
|
|
|
#elif defined(HAVE_STDINT_H)
|
|
|
|
#include <stdint.h>
|
|
|
|
#elif defined(_MSC_VER)
|
|
|
|
typedef unsigned __int32 uint32_t;
|
|
|
|
typedef unsigned __int16 uint16_t;
|
|
|
|
typedef unsigned __int8 uint8_t;
|
|
|
|
#else
|
|
|
|
#warning no uint32_t type available, please contact opensc-devel@opensc-project.org
|
|
|
|
#endif
|
|
|
|
|
2008-10-27 19:16:28 +00:00
|
|
|
#ifdef HAVE_WINSCARD_H
|
|
|
|
#include <winscard.h>
|
2008-12-11 09:18:09 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
#include <wintypes.h>
|
|
|
|
#endif
|
2008-10-27 19:16:28 +00:00
|
|
|
#else
|
|
|
|
/* mingw32 does not have winscard.h */
|
|
|
|
|
2008-03-06 16:06:59 +00:00
|
|
|
#define MAX_ATR_SIZE 33 /**< Maximum ATR size */
|
|
|
|
|
|
|
|
#define SCARD_PROTOCOL_T0 0x0001 /**< T=0 active protocol. */
|
|
|
|
#define SCARD_PROTOCOL_T1 0x0002 /**< T=1 active protocol. */
|
|
|
|
#define SCARD_PROTOCOL_RAW 0x0004 /**< Raw active protocol. */
|
|
|
|
|
|
|
|
#define SCARD_STATE_UNAWARE 0x0000 /**< App wants status */
|
|
|
|
#define SCARD_STATE_IGNORE 0x0001 /**< Ignore this reader */
|
|
|
|
#define SCARD_STATE_CHANGED 0x0002 /**< State has changed */
|
2010-01-24 15:25:08 +00:00
|
|
|
#define SCARD_STATE_UNKNOWN 0x0004 /**< Reader unknown */
|
2008-03-06 16:06:59 +00:00
|
|
|
#define SCARD_STATE_EMPTY 0x0010 /**< Card removed */
|
|
|
|
#define SCARD_STATE_PRESENT 0x0020 /**< Card inserted */
|
|
|
|
|
|
|
|
#define SCARD_SHARE_EXCLUSIVE 0x0001 /**< Exclusive mode only */
|
|
|
|
#define SCARD_SHARE_SHARED 0x0002 /**< Shared mode only */
|
2009-09-14 09:48:56 +00:00
|
|
|
#define SCARD_SHARE_DIRECT 0x0003 /**< Raw mode only */
|
2008-03-06 16:06:59 +00:00
|
|
|
|
|
|
|
#define SCARD_LEAVE_CARD 0x0000 /**< Do nothing on close */
|
|
|
|
#define SCARD_RESET_CARD 0x0001 /**< Reset on close */
|
|
|
|
#define SCARD_UNPOWER_CARD 0x0002 /**< Power down on close */
|
|
|
|
|
|
|
|
#define SCARD_SCOPE_USER 0x0000 /**< Scope in user space */
|
|
|
|
|
2008-10-26 14:48:47 +00:00
|
|
|
#ifndef SCARD_S_SUCCESS /* conflict in mingw-w64 */
|
2008-03-06 16:06:59 +00:00
|
|
|
#define SCARD_S_SUCCESS 0x00000000 /**< No error was encountered. */
|
2010-01-10 18:44:02 +00:00
|
|
|
#define SCARD_E_CANCELLED 0x80100002 /**< The action was cancelled by an SCardCancel request. */
|
2008-04-29 17:01:19 +00:00
|
|
|
#define SCARD_E_INVALID_HANDLE 0x80100003 /**< The supplied handle was invalid. */
|
2008-03-06 16:06:59 +00:00
|
|
|
#define SCARD_E_TIMEOUT 0x8010000A /**< The user-specified timeout value has expired. */
|
|
|
|
#define SCARD_E_SHARING_VIOLATION 0x8010000B /**< The smart card cannot be accessed because of other connections outstanding. */
|
2009-09-14 09:03:33 +00:00
|
|
|
#define SCARD_E_NO_SMARTCARD 0x8010000C /**< The operation requires a smart card, but no smart card is currently in the device. */
|
|
|
|
#define SCARD_E_PROTO_MISMATCH 0x8010000F /**< The requested protocols are incompatible with the protocol currently in use with the smart card. */
|
2008-03-06 16:06:59 +00:00
|
|
|
#define SCARD_E_NOT_TRANSACTED 0x80100016 /**< An attempt was made to end a non-existent transaction. */
|
2008-04-29 17:01:19 +00:00
|
|
|
#define SCARD_E_READER_UNAVAILABLE 0x80100017 /**< The specified reader is not currently available for use. */
|
2009-01-20 08:45:12 +00:00
|
|
|
#define SCARD_E_NO_SERVICE 0x8010001D /**< The Smart card resource manager is not running. */
|
2008-03-06 16:06:59 +00:00
|
|
|
#define SCARD_E_NO_READERS_AVAILABLE 0x8010002E /**< Cannot find a smart card reader. */
|
|
|
|
#define SCARD_W_UNRESPONSIVE_CARD 0x80100066 /**< The smart card is not responding to a reset. */
|
|
|
|
#define SCARD_W_UNPOWERED_CARD 0x80100067 /**< Power has been removed from the smart card, so that further communication is not possible. */
|
|
|
|
#define SCARD_W_RESET_CARD 0x80100068 /**< The smart card has been reset, so any shared state information is invalid. */
|
|
|
|
#define SCARD_W_REMOVED_CARD 0x80100069 /**< The smart card has been removed, so further communication is not possible. */
|
2008-10-26 14:48:47 +00:00
|
|
|
#endif
|
2008-03-06 16:06:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
typedef const BYTE *LPCBYTE;
|
|
|
|
typedef long SCARDCONTEXT; /**< \p hContext returned by SCardEstablishContext() */
|
|
|
|
typedef SCARDCONTEXT *PSCARDCONTEXT;
|
|
|
|
typedef SCARDCONTEXT *LPSCARDCONTEXT;
|
|
|
|
typedef long SCARDHANDLE; /**< \p hCard returned by SCardConnect() */
|
|
|
|
typedef SCARDHANDLE *PSCARDHANDLE;
|
|
|
|
typedef SCARDHANDLE *LPSCARDHANDLE;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
const char *szReader;
|
|
|
|
void *pvUserData;
|
|
|
|
unsigned long dwCurrentState;
|
|
|
|
unsigned long dwEventState;
|
|
|
|
unsigned long cbAtr;
|
|
|
|
unsigned char rgbAtr[MAX_ATR_SIZE];
|
|
|
|
}
|
|
|
|
SCARD_READERSTATE_A;
|
|
|
|
|
|
|
|
typedef struct _SCARD_IO_REQUEST
|
|
|
|
{
|
|
|
|
unsigned long dwProtocol; /* Protocol identifier */
|
|
|
|
unsigned long cbPciLength; /* Protocol Control Inf Length */
|
|
|
|
}
|
|
|
|
SCARD_IO_REQUEST, *PSCARD_IO_REQUEST, *LPSCARD_IO_REQUEST;
|
|
|
|
|
2008-10-27 19:16:28 +00:00
|
|
|
typedef const SCARD_IO_REQUEST *LPCSCARD_IO_REQUEST;
|
|
|
|
typedef SCARD_READERSTATE_A SCARD_READERSTATE, *PSCARD_READERSTATE_A,
|
|
|
|
*LPSCARD_READERSTATE_A;
|
|
|
|
|
|
|
|
#endif /* HAVE_SCARD_H */
|
2008-04-04 16:46:50 +00:00
|
|
|
|
|
|
|
#if defined(_WIN32)
|
|
|
|
#define PCSC_API WINAPI
|
|
|
|
#elif defined(USE_CYGWIN)
|
|
|
|
#define PCSC_API __stdcall
|
|
|
|
#else
|
|
|
|
#define PCSC_API
|
|
|
|
#endif
|
|
|
|
|
2008-04-04 06:05:38 +00:00
|
|
|
typedef LONG (PCSC_API *SCardEstablishContext_t)(DWORD dwScope, LPCVOID pvReserved1,
|
2008-03-06 16:06:59 +00:00
|
|
|
LPCVOID pvReserved2, LPSCARDCONTEXT phContext);
|
2008-04-04 06:05:38 +00:00
|
|
|
typedef LONG (PCSC_API *SCardReleaseContext_t)(SCARDCONTEXT hContext);
|
|
|
|
typedef LONG (PCSC_API *SCardConnect_t)(SCARDCONTEXT hContext, LPCSTR szReader, DWORD dwShareMode,
|
2008-03-06 16:06:59 +00:00
|
|
|
DWORD dwPreferredProtocols, LPSCARDHANDLE phCard, LPDWORD pdwActiveProtocol);
|
2008-04-04 06:05:38 +00:00
|
|
|
typedef LONG (PCSC_API *SCardReconnect_t)(SCARDHANDLE hCard, DWORD dwShareMode, DWORD dwPreferredProtocols,
|
2008-03-06 16:06:59 +00:00
|
|
|
DWORD dwInitialization, LPDWORD pdwActiveProtocol);
|
2008-04-04 06:05:38 +00:00
|
|
|
typedef LONG (PCSC_API *SCardDisconnect_t)(SCARDHANDLE hCard, DWORD dwDisposition);
|
|
|
|
typedef LONG (PCSC_API *SCardBeginTransaction_t)(SCARDHANDLE hCard);
|
|
|
|
typedef LONG (PCSC_API *SCardEndTransaction_t)(SCARDHANDLE hCard, DWORD dwDisposition);
|
|
|
|
typedef LONG (PCSC_API *SCardStatus_t)(SCARDHANDLE hCard, LPSTR mszReaderNames, LPDWORD pcchReaderLen,
|
2008-03-06 16:06:59 +00:00
|
|
|
LPDWORD pdwState, LPDWORD pdwProtocol, LPBYTE pbAtr, LPDWORD pcbAtrLen);
|
2008-04-04 06:05:38 +00:00
|
|
|
typedef LONG (PCSC_API *SCardGetStatusChange_t)(SCARDCONTEXT hContext, DWORD dwTimeout,
|
2008-03-06 16:06:59 +00:00
|
|
|
LPSCARD_READERSTATE_A rgReaderStates, DWORD cReaders);
|
2010-01-10 18:44:02 +00:00
|
|
|
typedef LONG (PCSC_API *SCardCancel_t)(SCARDCONTEXT hContext);
|
2008-04-04 06:05:38 +00:00
|
|
|
typedef LONG (PCSC_API *SCardControlOLD_t)(SCARDHANDLE hCard, LPCVOID pbSendBuffer, DWORD cbSendLength,
|
2008-03-06 16:06:59 +00:00
|
|
|
LPVOID pbRecvBuffer, LPDWORD lpBytesReturned);
|
2008-04-04 06:05:38 +00:00
|
|
|
typedef LONG (PCSC_API *SCardControl_t)(SCARDHANDLE hCard, DWORD dwControlCode, LPCVOID pbSendBuffer,
|
2008-03-06 16:06:59 +00:00
|
|
|
DWORD cbSendLength, LPVOID pbRecvBuffer, DWORD cbRecvLength,
|
|
|
|
LPDWORD lpBytesReturned);
|
2008-04-04 06:05:38 +00:00
|
|
|
typedef LONG (PCSC_API *SCardTransmit_t)(SCARDHANDLE hCard, LPCSCARD_IO_REQUEST pioSendPci,
|
2008-03-06 16:06:59 +00:00
|
|
|
LPCBYTE pbSendBuffer, DWORD cbSendLength, LPSCARD_IO_REQUEST pioRecvPci,
|
|
|
|
LPBYTE pbRecvBuffer, LPDWORD pcbRecvLength);
|
2008-04-04 06:05:38 +00:00
|
|
|
typedef LONG (PCSC_API *SCardListReaders_t)(SCARDCONTEXT hContext, LPCSTR mszGroups,
|
2008-03-06 16:06:59 +00:00
|
|
|
LPSTR mszReaders, LPDWORD pcchReaders);
|
2010-02-05 13:05:25 +00:00
|
|
|
typedef LONG (PCSC_API *SCardGetAttrib_t)(SCARDHANDLE hCard, DWORD dwAttrId,\
|
|
|
|
LPBYTE pbAttr, LPDWORD pcbAttrLen);
|
2008-03-06 16:06:59 +00:00
|
|
|
|
|
|
|
/* Copied from pcsc-lite reader.h */
|
|
|
|
|
2008-10-27 19:16:28 +00:00
|
|
|
#ifndef SCARD_CTL_CODE
|
2009-03-07 21:55:40 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
#include <winioctl.h>
|
|
|
|
#define SCARD_CTL_CODE(code) CTL_CODE(FILE_DEVICE_SMARTCARD,(code),METHOD_BUFFERED,FILE_ANY_ACCESS)
|
|
|
|
#else
|
2008-10-27 19:16:28 +00:00
|
|
|
#define SCARD_CTL_CODE(code) (0x42000000 + (code))
|
|
|
|
#endif
|
2009-03-07 21:55:40 +00:00
|
|
|
#endif
|
2008-10-27 19:16:28 +00:00
|
|
|
|
2008-03-06 16:06:59 +00:00
|
|
|
/**
|
2009-03-21 11:09:12 +00:00
|
|
|
* PC/SC v2.02.05 part 10 reader tags
|
2008-03-06 16:06:59 +00:00
|
|
|
*/
|
|
|
|
#define CM_IOCTL_GET_FEATURE_REQUEST SCARD_CTL_CODE(3400)
|
|
|
|
|
2009-03-21 11:09:12 +00:00
|
|
|
#define FEATURE_VERIFY_PIN_START 0x01
|
|
|
|
#define FEATURE_VERIFY_PIN_FINISH 0x02
|
|
|
|
#define FEATURE_MODIFY_PIN_START 0x03
|
|
|
|
#define FEATURE_MODIFY_PIN_FINISH 0x04
|
|
|
|
#define FEATURE_GET_KEY_PRESSED 0x05
|
|
|
|
#define FEATURE_VERIFY_PIN_DIRECT 0x06
|
|
|
|
#define FEATURE_MODIFY_PIN_DIRECT 0x07
|
|
|
|
#define FEATURE_MCT_READERDIRECT 0x08
|
|
|
|
#define FEATURE_MCT_UNIVERSAL 0x09
|
|
|
|
#define FEATURE_IFD_PIN_PROPERTIES 0x0A
|
|
|
|
#define FEATURE_ABORT 0x0B
|
|
|
|
#define FEATURE_SET_SPE_MESSAGE 0x0C
|
|
|
|
#define FEATURE_VERIFY_PIN_DIRECT_APP_ID 0x0D
|
|
|
|
#define FEATURE_MODIFY_PIN_DIRECT_APP_ID 0x0E
|
|
|
|
#define FEATURE_WRITE_DISPLAY 0x0F
|
|
|
|
#define FEATURE_GET_KEY 0x10
|
|
|
|
#define FEATURE_IFD_DISPLAY_PROPERTIES 0x11
|
2008-03-06 16:06:59 +00:00
|
|
|
|
|
|
|
/* structures used (but not defined) in PCSC Part 10 revision 2.01.02:
|
|
|
|
* "IFDs with Secure Pin Entry Capabilities" */
|
|
|
|
|
|
|
|
/* Set structure elements aligment on bytes
|
|
|
|
* http://gcc.gnu.org/onlinedocs/gcc/Structure_002dPacking-Pragmas.html */
|
|
|
|
#ifdef __APPLE__
|
|
|
|
#pragma pack(1)
|
|
|
|
#else
|
|
|
|
#pragma pack(push, 1)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/** the structure must be 6-bytes long */
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
uint8_t tag;
|
|
|
|
uint8_t length;
|
|
|
|
uint32_t value; /**< This value is always in BIG ENDIAN format as documented in PCSC v2 part 10 ch 2.2 page 2. You can use ntohl() for example */
|
|
|
|
} PCSC_TLV_STRUCTURE;
|
|
|
|
|
|
|
|
/** the wLangId and wPINMaxExtraDigit are 16-bits long so are subject to byte
|
|
|
|
* ordering */
|
|
|
|
#define HOST_TO_CCID_16(x) (x)
|
|
|
|
#define HOST_TO_CCID_32(x) (x)
|
|
|
|
|
|
|
|
/** structure used with \ref FEATURE_VERIFY_PIN_DIRECT */
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
uint8_t bTimerOut; /**< timeout is seconds (00 means use default timeout) */
|
|
|
|
uint8_t bTimerOut2; /**< timeout in seconds after first key stroke */
|
|
|
|
uint8_t bmFormatString; /**< formatting options */
|
|
|
|
uint8_t bmPINBlockString; /**< bits 7-4 bit size of PIN length in APDU,
|
|
|
|
* bits 3-0 PIN block size in bytes after
|
|
|
|
* justification and formatting */
|
|
|
|
uint8_t bmPINLengthFormat; /**< bits 7-5 RFU,
|
|
|
|
* bit 4 set if system units are bytes, clear if
|
|
|
|
* system units are bits,
|
|
|
|
* bits 3-0 PIN length position in system units */
|
|
|
|
uint16_t wPINMaxExtraDigit; /**< 0xXXYY where XX is minimum PIN size in digits,
|
|
|
|
and YY is maximum PIN size in digits */
|
|
|
|
uint8_t bEntryValidationCondition; /**< Conditions under which PIN entry should
|
|
|
|
* be considered complete */
|
|
|
|
uint8_t bNumberMessage; /**< Number of messages to display for PIN verification */
|
|
|
|
uint16_t wLangId; /**< Language for messages */
|
|
|
|
uint8_t bMsgIndex; /**< Message index (should be 00) */
|
|
|
|
uint8_t bTeoPrologue[3]; /**< T=1 block prologue field to use (fill with 00) */
|
|
|
|
uint32_t ulDataLength; /**< length of Data to be sent to the ICC */
|
|
|
|
uint8_t abData[1]; /**< Data to send to the ICC */
|
|
|
|
} PIN_VERIFY_STRUCTURE;
|
|
|
|
|
|
|
|
/** structure used with \ref FEATURE_MODIFY_PIN_DIRECT */
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
uint8_t bTimerOut; /**< timeout is seconds (00 means use default timeout) */
|
|
|
|
uint8_t bTimerOut2; /**< timeout in seconds after first key stroke */
|
|
|
|
uint8_t bmFormatString; /**< formatting options */
|
|
|
|
uint8_t bmPINBlockString; /**< bits 7-4 bit size of PIN length in APDU,
|
|
|
|
* bits 3-0 PIN block size in bytes after
|
|
|
|
* justification and formatting */
|
|
|
|
uint8_t bmPINLengthFormat; /**< bits 7-5 RFU,
|
|
|
|
* bit 4 set if system units are bytes, clear if
|
|
|
|
* system units are bits,
|
|
|
|
* bits 3-0 PIN length position in system units */
|
|
|
|
uint8_t bInsertionOffsetOld; /**< Insertion position offset in bytes for
|
|
|
|
the current PIN */
|
|
|
|
uint8_t bInsertionOffsetNew; /**< Insertion position offset in bytes for
|
|
|
|
the new PIN */
|
|
|
|
uint16_t wPINMaxExtraDigit;
|
|
|
|
/**< 0xXXYY where XX is minimum PIN size in digits,
|
|
|
|
and YY is maximum PIN size in digits */
|
|
|
|
uint8_t bConfirmPIN; /**< Flags governing need for confirmation of new PIN */
|
|
|
|
uint8_t bEntryValidationCondition; /**< Conditions under which PIN entry should
|
|
|
|
* be considered complete */
|
|
|
|
uint8_t bNumberMessage; /**< Number of messages to display for PIN verification*/
|
|
|
|
uint16_t wLangId; /**< Language for messages */
|
|
|
|
uint8_t bMsgIndex1; /**< index of 1st prompting message */
|
|
|
|
uint8_t bMsgIndex2; /**< index of 2d prompting message */
|
|
|
|
uint8_t bMsgIndex3; /**< index of 3d prompting message */
|
|
|
|
uint8_t bTeoPrologue[3]; /**< T=1 block prologue field to use (fill with 00) */
|
|
|
|
uint32_t ulDataLength; /**< length of Data to be sent to the ICC */
|
|
|
|
uint8_t abData[1]; /**< Data to send to the ICC */
|
|
|
|
} PIN_MODIFY_STRUCTURE;
|
|
|
|
|
2009-03-21 11:09:12 +00:00
|
|
|
typedef struct {
|
|
|
|
uint16_t wLcdLayout; /**< display characteristics */
|
|
|
|
uint16_t wLcdMaxCharacters;
|
|
|
|
uint16_t wLcdMaxLines;
|
|
|
|
uint8_t bEntryValidationCondition;
|
|
|
|
uint8_t bTimeOut2;
|
|
|
|
} PIN_PROPERTIES_STRUCTURE;
|
|
|
|
|
2008-03-06 16:06:59 +00:00
|
|
|
/* restore default structure elements alignment */
|
|
|
|
#ifdef __APPLE__
|
|
|
|
#pragma pack()
|
|
|
|
#else
|
|
|
|
#pragma pack(pop)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|