Initial commit
[platform/upstream/ccid.git] / src / defs.h
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 #define max( a, b )   ( ( ( a ) > ( b ) ) ? ( a ) : ( b ) )
21
22 #include <pcsclite.h>
23
24 #include "openct/proto-t1.h"
25
26 typedef struct CCID_DESC
27 {
28         /*
29          * ATR
30          */
31         int nATRLength;
32         unsigned char pcATRBuffer[MAX_ATR_SIZE];
33
34         /*
35          * Card state
36          */
37         unsigned char bPowerFlags;
38
39         /*
40          * T=1 Protocol context
41          */
42         t1_state_t t1;
43
44         /* reader name passed to IFDHCreateChannelByName() */
45         char *readerName;
46 } CcidDesc;
47
48 typedef enum {
49         STATUS_NO_SUCH_DEVICE        = 0xF9,
50         STATUS_SUCCESS               = 0xFA,
51         STATUS_UNSUCCESSFUL          = 0xFB,
52         STATUS_COMM_ERROR            = 0xFC,
53         STATUS_DEVICE_PROTOCOL_ERROR = 0xFD,
54         STATUS_COMM_NAK              = 0xFE,
55         STATUS_SECONDARY_SLOT        = 0xFF
56 } status_t;
57
58 /* Powerflag (used to detect quick insertion removals unnoticed by the
59  * resource manager) */
60 /* Initial value */
61 #define POWERFLAGS_RAZ 0x00
62 /* Flag set when a power up has been requested */
63 #define MASK_POWERFLAGS_PUP 0x01
64 /* Flag set when a power down is requested */
65 #define MASK_POWERFLAGS_PDWN 0x02
66
67 /* Communication buffer size (max=adpu+Lc+data+Le)
68  * we use a 64kB for extended APDU on APDU mode readers */
69 #define CMD_BUF_SIZE (4 +3 +64*1024 +3)
70
71 /* Protocols */
72 #define T_0 0
73 #define T_1 1
74
75 /* Default communication read timeout in milliseconds */
76 #define DEFAULT_COM_READ_TIMEOUT (3*1000)
77
78 /* DWORD type formating */
79 #ifdef __APPLE__
80 /* Apple defines DWORD as uint32_t */
81 #define DWORD_X "%X"
82 #define DWORD_D "%d"
83 #else
84 /* pcsc-lite defines DWORD as unsigned long */
85 #define DWORD_X "%lX"
86 #define DWORD_D "%ld"
87 #endif
88
89 /*
90  * communication ports abstraction
91  */
92 #ifdef TWIN_SERIAL
93
94 #define OpenPortByName OpenSerialByName
95 #define OpenPort OpenSerial
96 #define ClosePort CloseSerial
97 #define ReadPort ReadSerial
98 #define WritePort WriteSerial
99 #include "ccid_serial.h"
100
101 #else
102
103 #define OpenPortByName OpenUSBByName
104 #define OpenPort OpenUSB
105 #define ClosePort CloseUSB
106 #define ReadPort ReadUSB
107 #define WritePort WriteUSB
108 #include "ccid_usb.h"
109
110 #endif
111