root/trunk/src/libopensc/internal-winscard.h

Revision 3590, 10.4 KB (checked in by alonbl, 5 weeks ago)

Re-add pcsc-lite compile-time dependency

Win64 changed the SCARDCONTEXT from LONG to ULONG_PTR,
pcsc-lite did not follow this on 64bit platforms.
This breaks the pcsc module.

To solve this we use installed winscard.h in order to get proper
declerations.

As mingw32 does not have winscard.h we keep current types. mingw64 and
pcsc-lite system have winscard.h.

Line 
1#ifndef __INTERNAL_WINSCARD_H
2#define __INTERNAL_WINSCARD_H
3
4/* Mostly copied from pcsc-lite, this is the minimum required */
5
6#if defined(HAVE_INTTYPES_H)
7#include <inttypes.h>
8#elif defined(HAVE_STDINT_H)
9#include <stdint.h>
10#elif defined(_MSC_VER)
11typedef unsigned __int32 uint32_t;
12typedef unsigned __int16 uint16_t;
13typedef unsigned __int8 uint8_t;
14#else
15#warning no uint32_t type available, please contact opensc-devel@opensc-project.org
16#endif
17
18#ifdef HAVE_WINSCARD_H
19#include <winscard.h>
20#else
21/* mingw32 does not have winscard.h */
22
23#define MAX_ATR_SIZE                    33      /**< Maximum ATR size */
24
25#define SCARD_PROTOCOL_T0               0x0001  /**< T=0 active protocol. */
26#define SCARD_PROTOCOL_T1               0x0002  /**< T=1 active protocol. */
27#define SCARD_PROTOCOL_RAW              0x0004  /**< Raw active protocol. */
28
29#define SCARD_STATE_UNAWARE             0x0000  /**< App wants status */
30#define SCARD_STATE_IGNORE              0x0001  /**< Ignore this reader */
31#define SCARD_STATE_CHANGED             0x0002  /**< State has changed */
32#define SCARD_STATE_EMPTY               0x0010  /**< Card removed */
33#define SCARD_STATE_PRESENT             0x0020  /**< Card inserted */
34
35#define SCARD_SHARE_EXCLUSIVE           0x0001  /**< Exclusive mode only */
36#define SCARD_SHARE_SHARED              0x0002  /**< Shared mode only */
37
38#define SCARD_LEAVE_CARD                0x0000  /**< Do nothing on close */
39#define SCARD_RESET_CARD                0x0001  /**< Reset on close */
40#define SCARD_UNPOWER_CARD              0x0002  /**< Power down on close */
41
42#define SCARD_SCOPE_USER                0x0000  /**< Scope in user space */
43
44#ifndef SCARD_S_SUCCESS /* conflict in mingw-w64 */
45#define SCARD_S_SUCCESS                 0x00000000 /**< No error was encountered. */
46#define SCARD_E_INVALID_HANDLE          0x80100003 /**< The supplied handle was invalid. */
47#define SCARD_E_TIMEOUT                 0x8010000A /**< The user-specified timeout value has expired. */
48#define SCARD_E_SHARING_VIOLATION       0x8010000B /**< The smart card cannot be accessed because of other connections outstanding. */
49#define SCARD_E_NOT_TRANSACTED          0x80100016 /**< An attempt was made to end a non-existent transaction. */
50#define SCARD_E_READER_UNAVAILABLE      0x80100017 /**< The specified reader is not currently available for use. */
51#define SCARD_E_NO_READERS_AVAILABLE    0x8010002E /**< Cannot find a smart card reader. */
52#define SCARD_W_UNRESPONSIVE_CARD       0x80100066 /**< The smart card is not responding to a reset. */
53#define SCARD_W_UNPOWERED_CARD          0x80100067 /**< Power has been removed from the smart card, so that further communication is not possible. */
54#define SCARD_W_RESET_CARD              0x80100068 /**< The smart card has been reset, so any shared state information is invalid. */
55#define SCARD_W_REMOVED_CARD            0x80100069 /**< The smart card has been removed, so further communication is not possible. */
56#endif
57
58
59typedef const BYTE *LPCBYTE;
60typedef long SCARDCONTEXT; /**< \p hContext returned by SCardEstablishContext() */
61typedef SCARDCONTEXT *PSCARDCONTEXT;
62typedef SCARDCONTEXT *LPSCARDCONTEXT;
63typedef long SCARDHANDLE; /**< \p hCard returned by SCardConnect() */
64typedef SCARDHANDLE *PSCARDHANDLE;
65typedef SCARDHANDLE *LPSCARDHANDLE;
66
67typedef struct
68{
69        const char *szReader;
70        void *pvUserData;
71        unsigned long dwCurrentState;
72        unsigned long dwEventState;
73        unsigned long cbAtr;
74        unsigned char rgbAtr[MAX_ATR_SIZE];
75}
76SCARD_READERSTATE_A;
77
78typedef struct _SCARD_IO_REQUEST
79{
80        unsigned long dwProtocol;       /* Protocol identifier */
81        unsigned long cbPciLength;      /* Protocol Control Inf Length */
82}
83SCARD_IO_REQUEST, *PSCARD_IO_REQUEST, *LPSCARD_IO_REQUEST;
84
85typedef const SCARD_IO_REQUEST *LPCSCARD_IO_REQUEST;
86typedef SCARD_READERSTATE_A SCARD_READERSTATE, *PSCARD_READERSTATE_A,
87        *LPSCARD_READERSTATE_A;
88
89#endif  /* HAVE_SCARD_H */
90
91#if defined(_WIN32)
92#define PCSC_API WINAPI
93#elif defined(USE_CYGWIN)
94#define PCSC_API __stdcall
95#else
96#define PCSC_API
97#endif
98
99typedef LONG (PCSC_API *SCardEstablishContext_t)(DWORD dwScope, LPCVOID pvReserved1,
100        LPCVOID pvReserved2, LPSCARDCONTEXT phContext);
101typedef LONG (PCSC_API *SCardReleaseContext_t)(SCARDCONTEXT hContext);
102typedef LONG (PCSC_API *SCardConnect_t)(SCARDCONTEXT hContext, LPCSTR szReader, DWORD dwShareMode,
103        DWORD dwPreferredProtocols, LPSCARDHANDLE phCard, LPDWORD pdwActiveProtocol);
104typedef LONG (PCSC_API *SCardReconnect_t)(SCARDHANDLE hCard, DWORD dwShareMode, DWORD dwPreferredProtocols,
105        DWORD dwInitialization, LPDWORD pdwActiveProtocol);
106typedef LONG (PCSC_API *SCardDisconnect_t)(SCARDHANDLE hCard, DWORD dwDisposition);
107typedef LONG (PCSC_API *SCardBeginTransaction_t)(SCARDHANDLE hCard);
108typedef LONG (PCSC_API *SCardEndTransaction_t)(SCARDHANDLE hCard, DWORD dwDisposition);
109typedef LONG (PCSC_API *SCardStatus_t)(SCARDHANDLE hCard, LPSTR mszReaderNames, LPDWORD pcchReaderLen,
110        LPDWORD pdwState, LPDWORD pdwProtocol, LPBYTE pbAtr, LPDWORD pcbAtrLen);
111typedef LONG (PCSC_API *SCardGetStatusChange_t)(SCARDCONTEXT hContext, DWORD dwTimeout,
112        LPSCARD_READERSTATE_A rgReaderStates, DWORD cReaders);
113typedef LONG (PCSC_API *SCardControlOLD_t)(SCARDHANDLE hCard, LPCVOID pbSendBuffer, DWORD cbSendLength,
114        LPVOID pbRecvBuffer, LPDWORD lpBytesReturned);
115typedef LONG (PCSC_API *SCardControl_t)(SCARDHANDLE hCard, DWORD dwControlCode, LPCVOID pbSendBuffer,
116        DWORD cbSendLength, LPVOID pbRecvBuffer, DWORD cbRecvLength,
117        LPDWORD lpBytesReturned);
118typedef LONG (PCSC_API *SCardTransmit_t)(SCARDHANDLE hCard, LPCSCARD_IO_REQUEST pioSendPci,
119        LPCBYTE pbSendBuffer, DWORD cbSendLength, LPSCARD_IO_REQUEST pioRecvPci,
120        LPBYTE pbRecvBuffer, LPDWORD pcbRecvLength);
121typedef LONG (PCSC_API *SCardListReaders_t)(SCARDCONTEXT hContext, LPCSTR mszGroups,
122        LPSTR mszReaders, LPDWORD pcchReaders);
123
124/* Copied from pcsc-lite reader.h */
125
126#ifndef SCARD_CTL_CODE
127#define SCARD_CTL_CODE(code) (0x42000000 + (code))
128#endif
129
130/**
131 * TeleTrust Class 2 reader tags
132 */
133#define CM_IOCTL_GET_FEATURE_REQUEST SCARD_CTL_CODE(3400)
134
135#define FEATURE_VERIFY_PIN_START  0x01 /**< OMNIKEY Proposal */
136#define FEATURE_VERIFY_PIN_FINISH 0x02 /**< OMNIKEY Proposal */
137#define FEATURE_MODIFY_PIN_START  0x03 /**< OMNIKEY Proposal */
138#define FEATURE_MODIFY_PIN_FINISH 0x04 /**< OMNIKEY Proposal */
139#define FEATURE_GET_KEY_PRESSED   0x05 /**< OMNIKEY Proposal */
140#define FEATURE_VERIFY_PIN_DIRECT 0x06 /**< USB CCID PIN Verify */
141#define FEATURE_MODIFY_PIN_DIRECT 0x07 /**< USB CCID PIN Modify */
142#define FEATURE_MCT_READERDIRECT  0x08 /**< KOBIL Proposal */
143#define FEATURE_MCT_UNIVERSAL     0x09 /**< KOBIL Proposal */
144#define FEATURE_IFD_PIN_PROP      0x0A /**< Gemplus Proposal */
145#define FEATURE_ABORT             0x0B /**< SCM Proposal */
146
147/* structures used (but not defined) in PCSC Part 10 revision 2.01.02:
148 * "IFDs with Secure Pin Entry Capabilities" */
149
150/* Set structure elements aligment on bytes
151 * http://gcc.gnu.org/onlinedocs/gcc/Structure_002dPacking-Pragmas.html */
152#ifdef __APPLE__
153#pragma pack(1)
154#else
155#pragma pack(push, 1)
156#endif
157
158/** the structure must be 6-bytes long */
159typedef struct
160{
161        uint8_t tag;
162        uint8_t length;
163        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 */
164} PCSC_TLV_STRUCTURE;
165
166/** the wLangId and wPINMaxExtraDigit are 16-bits long so are subject to byte
167 * ordering */
168#define HOST_TO_CCID_16(x) (x)
169#define HOST_TO_CCID_32(x) (x)
170
171/** structure used with \ref FEATURE_VERIFY_PIN_DIRECT */
172typedef struct
173{
174        uint8_t bTimerOut;      /**< timeout is seconds (00 means use default timeout) */
175        uint8_t bTimerOut2; /**< timeout in seconds after first key stroke */
176        uint8_t bmFormatString; /**< formatting options */
177        uint8_t bmPINBlockString; /**< bits 7-4 bit size of PIN length in APDU,
178                                * bits 3-0 PIN block size in bytes after
179                                * justification and formatting */
180        uint8_t bmPINLengthFormat; /**< bits 7-5 RFU,
181                                 * bit 4 set if system units are bytes, clear if
182                                 * system units are bits,
183                                 * bits 3-0 PIN length position in system units */
184        uint16_t wPINMaxExtraDigit; /**< 0xXXYY where XX is minimum PIN size in digits,
185                                    and YY is maximum PIN size in digits */
186        uint8_t bEntryValidationCondition; /**< Conditions under which PIN entry should
187                                         * be considered complete */
188        uint8_t bNumberMessage; /**< Number of messages to display for PIN verification */
189        uint16_t wLangId; /**< Language for messages */
190        uint8_t bMsgIndex; /**< Message index (should be 00) */
191        uint8_t bTeoPrologue[3]; /**< T=1 block prologue field to use (fill with 00) */
192        uint32_t ulDataLength; /**< length of Data to be sent to the ICC */
193        uint8_t abData[1]; /**< Data to send to the ICC */
194} PIN_VERIFY_STRUCTURE;
195
196/** structure used with \ref FEATURE_MODIFY_PIN_DIRECT */
197typedef struct
198{
199        uint8_t bTimerOut;      /**< timeout is seconds (00 means use default timeout) */
200        uint8_t bTimerOut2; /**< timeout in seconds after first key stroke */
201        uint8_t bmFormatString; /**< formatting options */
202        uint8_t bmPINBlockString; /**< bits 7-4 bit size of PIN length in APDU,
203                                * bits 3-0 PIN block size in bytes after
204                                * justification and formatting */
205        uint8_t bmPINLengthFormat; /**< bits 7-5 RFU,
206                                 * bit 4 set if system units are bytes, clear if
207                                 * system units are bits,
208                                 * bits 3-0 PIN length position in system units */
209        uint8_t bInsertionOffsetOld; /**< Insertion position offset in bytes for
210                                     the current PIN */
211        uint8_t bInsertionOffsetNew; /**< Insertion position offset in bytes for
212                                     the new PIN */
213        uint16_t wPINMaxExtraDigit;
214                                 /**< 0xXXYY where XX is minimum PIN size in digits,
215                                    and YY is maximum PIN size in digits */
216        uint8_t bConfirmPIN; /**< Flags governing need for confirmation of new PIN */
217        uint8_t bEntryValidationCondition; /**< Conditions under which PIN entry should
218                                         * be considered complete */
219        uint8_t bNumberMessage; /**< Number of messages to display for PIN verification*/
220        uint16_t wLangId; /**< Language for messages */
221        uint8_t bMsgIndex1; /**< index of 1st prompting message */
222        uint8_t bMsgIndex2; /**< index of 2d prompting message */
223        uint8_t bMsgIndex3; /**< index of 3d prompting message */
224        uint8_t bTeoPrologue[3]; /**< T=1 block prologue field to use (fill with 00) */
225        uint32_t ulDataLength; /**< length of Data to be sent to the ICC */
226        uint8_t abData[1]; /**< Data to send to the ICC */
227} PIN_MODIFY_STRUCTURE;
228
229/* restore default structure elements alignment */
230#ifdef __APPLE__
231#pragma pack()
232#else
233#pragma pack(pop)
234#endif
235
236#endif
Note: See TracBrowser for help on using the browser.