1/*
2    defs.h:
3    Copyright (C) 2003-2010   Ludovic Rousseau
4
5    This library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License as published by the Free Software Foundation; either
8    version 2.1 of the License, or (at your option) any later version.
9
10    This library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Lesser General Public License for more details.
14
15	You should have received a copy of the GNU Lesser General Public License
16	along with this library; if not, write to the Free Software Foundation,
17	Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18*/
19
20/*
21 * $Id: defs.h 6305 2012-05-19 08:10:08Z rousseau $
22 */
23
24#include <pcsclite.h>
25
26#include "openct/proto-t1.h"
27
28typedef struct CCID_DESC
29{
30	/*
31	 * ATR
32	 */
33	int nATRLength;
34	UCHAR pcATRBuffer[MAX_ATR_SIZE];
35
36	/*
37	 * Card state
38	 */
39	UCHAR bPowerFlags;
40
41	/*
42	 * T=1 Protocol context
43	 */
44	t1_state_t t1;
45
46	/* reader name passed to IFDHCreateChannelByName() */
47	char *readerName;
48} CcidDesc;
49
50typedef enum {
51	STATUS_NO_SUCH_DEVICE        = 0xF9,
52	STATUS_SUCCESS               = 0xFA,
53	STATUS_UNSUCCESSFUL          = 0xFB,
54	STATUS_COMM_ERROR            = 0xFC,
55	STATUS_DEVICE_PROTOCOL_ERROR = 0xFD,
56	STATUS_COMM_NAK              = 0xFE,
57	STATUS_SECONDARY_SLOT        = 0xFF
58} status_t;
59
60/* Powerflag (used to detect quick insertion removals unnoticed by the
61 * resource manager) */
62/* Initial value */
63#define POWERFLAGS_RAZ 0x00
64/* Flag set when a power up has been requested */
65#define MASK_POWERFLAGS_PUP 0x01
66/* Flag set when a power down is requested */
67#define MASK_POWERFLAGS_PDWN 0x02
68
69/* Communication buffer size (max=adpu+Lc+data+Le)
70 * we use a 64kB for extended APDU on APDU mode readers */
71#define CMD_BUF_SIZE (4 +3 +64*1024 +3)
72
73/* Protocols */
74#define T_0 0
75#define T_1 1
76
77/* Default communication read timeout in milliseconds */
78#define DEFAULT_COM_READ_TIMEOUT (3*1000)
79
80/* DWORD type formating */
81#ifdef __APPLE__
82/* Apple defines DWORD as uint32_t */
83#define DWORD_X "%X"
84#define DWORD_D "%d"
85#else
86/* pcsc-lite defines DWORD as unsigned long */
87#define DWORD_X "%lX"
88#define DWORD_D "%ld"
89#endif
90
91/*
92 * communication ports abstraction
93 */
94#ifdef TWIN_SERIAL
95
96#define OpenPortByName OpenSerialByName
97#define OpenPort OpenSerial
98#define ClosePort CloseSerial
99#define ReadPort ReadSerial
100#define WritePort WriteSerial
101#include "ccid_serial.h"
102
103#else
104
105#define OpenPortByName OpenUSBByName
106#define OpenPort OpenUSB
107#define ClosePort CloseUSB
108#define ReadPort ReadUSB
109#define WritePort WriteUSB
110#include "ccid_usb.h"
111
112#endif
113
114