pcsc-lite 2.3.0
pcsclite.h
Go to the documentation of this file.
1/*
2 * MUSCLE SmartCard Development ( https://pcsclite.apdu.fr/ )
3 *
4 * Copyright (C) 1999-2004
5 * David Corcoran <corcoran@musclecard.com>
6 * Copyright (C) 2002-2024
7 * Ludovic Rousseau <ludovic.rousseau@free.fr>
8 * Copyright (C) 2005
9 * Martin Paljak <martin@paljak.pri.ee>
10 *
11Redistribution and use in source and binary forms, with or without
12modification, are permitted provided that the following conditions
13are met:
14
151. Redistributions of source code must retain the above copyright
16 notice, this list of conditions and the following disclaimer.
172. Redistributions in binary form must reproduce the above copyright
18 notice, this list of conditions and the following disclaimer in the
19 documentation and/or other materials provided with the distribution.
203. The name of the author may not be used to endorse or promote products
21 derived from this software without specific prior written permission.
22
23THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
42#ifndef __pcsclite_h__
43#define __pcsclite_h__
44
45#include <wintypes.h>
46
47#ifdef __cplusplus
48extern "C"
49{
50#endif
51
52typedef LONG SCARDCONTEXT;
53typedef SCARDCONTEXT *PSCARDCONTEXT;
54typedef SCARDCONTEXT *LPSCARDCONTEXT;
55typedef LONG SCARDHANDLE;
56typedef SCARDHANDLE *PSCARDHANDLE;
57typedef SCARDHANDLE *LPSCARDHANDLE;
58
59#define MAX_ATR_SIZE 33
61/* Set structure elements alignment on bytes
62 * http://gcc.gnu.org/onlinedocs/gcc/Structure_002dPacking-Pragmas.html */
63#ifdef __APPLE__
64#pragma pack(1)
65#endif
66
67typedef struct
68{
69 const char *szReader;
70 void *pvUserData;
71 DWORD dwCurrentState;
72 DWORD dwEventState;
73 DWORD cbAtr;
74 unsigned char rgbAtr[MAX_ATR_SIZE];
75}
77
79typedef struct
80{
81 unsigned long dwProtocol;
82 unsigned long cbPciLength;
83}
85
87
89
90/* restore default structure elements alignment */
91#ifdef __APPLE__
92#pragma pack()
93#endif
94
95#define SCARD_PCI_T0 (&g_rgSCardT0Pci)
96#define SCARD_PCI_T1 (&g_rgSCardT1Pci)
97#define SCARD_PCI_RAW (&g_rgSCardRawPci)
107#define SCARD_S_SUCCESS ((LONG)0x00000000)
109#define SCARD_F_INTERNAL_ERROR ((LONG)0x80100001)
111#define SCARD_E_CANCELLED ((LONG)0x80100002)
113#define SCARD_E_INVALID_HANDLE ((LONG)0x80100003)
115#define SCARD_E_INVALID_PARAMETER ((LONG)0x80100004)
117#define SCARD_E_INVALID_TARGET ((LONG)0x80100005)
119#define SCARD_E_NO_MEMORY ((LONG)0x80100006)
121#define SCARD_F_WAITED_TOO_LONG ((LONG)0x80100007)
123#define SCARD_E_INSUFFICIENT_BUFFER ((LONG)0x80100008)
125#define SCARD_E_UNKNOWN_READER ((LONG)0x80100009)
127#define SCARD_E_TIMEOUT ((LONG)0x8010000A)
129#define SCARD_E_SHARING_VIOLATION ((LONG)0x8010000B)
131#define SCARD_E_NO_SMARTCARD ((LONG)0x8010000C)
133#define SCARD_E_UNKNOWN_CARD ((LONG)0x8010000D)
135#define SCARD_E_CANT_DISPOSE ((LONG)0x8010000E)
137#define SCARD_E_PROTO_MISMATCH ((LONG)0x8010000F)
139#define SCARD_E_NOT_READY ((LONG)0x80100010)
141#define SCARD_E_INVALID_VALUE ((LONG)0x80100011)
143#define SCARD_E_SYSTEM_CANCELLED ((LONG)0x80100012)
145#define SCARD_F_COMM_ERROR ((LONG)0x80100013)
147#define SCARD_F_UNKNOWN_ERROR ((LONG)0x80100014)
149#define SCARD_E_INVALID_ATR ((LONG)0x80100015)
151#define SCARD_E_NOT_TRANSACTED ((LONG)0x80100016)
153#define SCARD_E_READER_UNAVAILABLE ((LONG)0x80100017)
155#define SCARD_P_SHUTDOWN ((LONG)0x80100018)
157#define SCARD_E_PCI_TOO_SMALL ((LONG)0x80100019)
159#define SCARD_E_READER_UNSUPPORTED ((LONG)0x8010001A)
161#define SCARD_E_DUPLICATE_READER ((LONG)0x8010001B)
163#define SCARD_E_CARD_UNSUPPORTED ((LONG)0x8010001C)
165#define SCARD_E_NO_SERVICE ((LONG)0x8010001D)
167#define SCARD_E_SERVICE_STOPPED ((LONG)0x8010001E)
169#define SCARD_E_UNEXPECTED ((LONG)0x8010001F)
171#define SCARD_E_UNSUPPORTED_FEATURE ((LONG)0x8010001F)
173#define SCARD_E_ICC_INSTALLATION ((LONG)0x80100020)
175#define SCARD_E_ICC_CREATEORDER ((LONG)0x80100021)
177/* #define SCARD_E_UNSUPPORTED_FEATURE ((LONG)0x80100022) / **< This smart card does not support the requested feature. */
179#define SCARD_E_DIR_NOT_FOUND ((LONG)0x80100023)
181#define SCARD_E_FILE_NOT_FOUND ((LONG)0x80100024)
183#define SCARD_E_NO_DIR ((LONG)0x80100025)
185#define SCARD_E_NO_FILE ((LONG)0x80100026)
187#define SCARD_E_NO_ACCESS ((LONG)0x80100027)
189#define SCARD_E_WRITE_TOO_MANY ((LONG)0x80100028)
191#define SCARD_E_BAD_SEEK ((LONG)0x80100029)
193#define SCARD_E_INVALID_CHV ((LONG)0x8010002A)
195#define SCARD_E_UNKNOWN_RES_MSG ((LONG)0x8010002B)
196#define SCARD_E_UNKNOWN_RES_MNG SCARD_E_UNKNOWN_RES_MSG
198#define SCARD_E_NO_SUCH_CERTIFICATE ((LONG)0x8010002C)
200#define SCARD_E_CERTIFICATE_UNAVAILABLE ((LONG)0x8010002D)
202#define SCARD_E_NO_READERS_AVAILABLE ((LONG)0x8010002E)
204#define SCARD_E_COMM_DATA_LOST ((LONG)0x8010002F)
206#define SCARD_E_NO_KEY_CONTAINER ((LONG)0x80100030)
208#define SCARD_E_SERVER_TOO_BUSY ((LONG)0x80100031)
211#define SCARD_W_UNSUPPORTED_CARD ((LONG)0x80100065)
213#define SCARD_W_UNRESPONSIVE_CARD ((LONG)0x80100066)
215#define SCARD_W_UNPOWERED_CARD ((LONG)0x80100067)
217#define SCARD_W_RESET_CARD ((LONG)0x80100068)
219#define SCARD_W_REMOVED_CARD ((LONG)0x80100069)
222#define SCARD_W_SECURITY_VIOLATION ((LONG)0x8010006A)
224#define SCARD_W_WRONG_CHV ((LONG)0x8010006B)
226#define SCARD_W_CHV_BLOCKED ((LONG)0x8010006C)
228#define SCARD_W_EOF ((LONG)0x8010006D)
230#define SCARD_W_CANCELLED_BY_USER ((LONG)0x8010006E)
232#define SCARD_W_CARD_NOT_AUTHENTICATED ((LONG)0x8010006F)
234#define SCARD_AUTOALLOCATE (DWORD)(-1)
235#define SCARD_SCOPE_USER 0x0000
236#define SCARD_SCOPE_TERMINAL 0x0001
237#define SCARD_SCOPE_SYSTEM 0x0002
238#define SCARD_SCOPE_GLOBAL 0x0003
240#define SCARD_PROTOCOL_UNDEFINED 0x0000
241#define SCARD_PROTOCOL_UNSET SCARD_PROTOCOL_UNDEFINED /* backward compat */
242#define SCARD_PROTOCOL_T0 0x0001
243#define SCARD_PROTOCOL_T1 0x0002
244#define SCARD_PROTOCOL_RAW 0x0004
245#define SCARD_PROTOCOL_T15 0x0008
247#define SCARD_PROTOCOL_ANY (SCARD_PROTOCOL_T0|SCARD_PROTOCOL_T1)
249#define SCARD_SHARE_EXCLUSIVE 0x0001
250#define SCARD_SHARE_SHARED 0x0002
251#define SCARD_SHARE_DIRECT 0x0003
253#define SCARD_LEAVE_CARD 0x0000
254#define SCARD_RESET_CARD 0x0001
255#define SCARD_UNPOWER_CARD 0x0002
256#define SCARD_EJECT_CARD 0x0003
258#define SCARD_UNKNOWN 0x0001
259#define SCARD_ABSENT 0x0002
260#define SCARD_PRESENT 0x0004
261#define SCARD_SWALLOWED 0x0008
262#define SCARD_POWERED 0x0010
263#define SCARD_NEGOTIABLE 0x0020
264#define SCARD_SPECIFIC 0x0040
266#define SCARD_STATE_UNAWARE 0x0000
267#define SCARD_STATE_IGNORE 0x0001
268#define SCARD_STATE_CHANGED 0x0002
269#define SCARD_STATE_UNKNOWN 0x0004
270#define SCARD_STATE_UNAVAILABLE 0x0008
271#define SCARD_STATE_EMPTY 0x0010
272#define SCARD_STATE_PRESENT 0x0020
273#define SCARD_STATE_ATRMATCH 0x0040
274#define SCARD_STATE_EXCLUSIVE 0x0080
275#define SCARD_STATE_INUSE 0x0100
276#define SCARD_STATE_MUTE 0x0200
277#define SCARD_STATE_UNPOWERED 0x0400
279#ifndef INFINITE
280#define INFINITE 0xFFFFFFFF
281#endif
282
283#define PCSCLITE_VERSION_NUMBER "2.3.0"
285#define PCSCLITE_MAX_READERS_CONTEXTS 16
286
287#define MAX_READERNAME 128
288
289#ifndef SCARD_ATR_LENGTH
290#define SCARD_ATR_LENGTH MAX_ATR_SIZE
291#endif
292
293/*
294 * The message and buffer sizes must be multiples of 16.
295 * The max message size must be at least large enough
296 * to accommodate the transmit_struct
297 */
298#define MAX_BUFFER_SIZE 264
299#define MAX_BUFFER_SIZE_EXTENDED (4 + 3 + (1<<16) + 3 + 2)
301/*
302 * Gets a stringified error response
303 */
304const char *pcsc_stringify_error(const LONG);
305
306#ifdef __cplusplus
307}
308#endif
309
310#endif
const char * pcsc_stringify_error(const LONG)
Returns a human readable text for the given PC/SC error code.
Definition error.c:82
PCSC_API const SCARD_IO_REQUEST g_rgSCardRawPci
Protocol Control Information for raw access.
PCSC_API const SCARD_IO_REQUEST g_rgSCardT1Pci
Protocol Control Information for T=1.
LONG SCARDCONTEXT
hContext returned by SCardEstablishContext()
Definition pcsclite.h:52
#define MAX_ATR_SIZE
Maximum ATR size.
Definition pcsclite.h:59
LONG SCARDHANDLE
hCard returned by SCardConnect()
Definition pcsclite.h:55
const SCARD_IO_REQUEST g_rgSCardT0Pci
Protocol Control Information for T=0.
Protocol Control Information (PCI)
Definition pcsclite.h:80
unsigned long dwProtocol
Protocol identifier.
Definition pcsclite.h:81
unsigned long cbPciLength
Protocol Control Inf Length.
Definition pcsclite.h:82
This keeps a list of Windows(R) types.