Initial commit
[platform/upstream/ccid.git] / src / ccid.h
1 /*
2     ccid.h: CCID structures
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 typedef struct
21 {
22         /*
23          * CCID Sequence number
24          */
25         unsigned char *pbSeq;
26         unsigned char real_bSeq;
27
28         /*
29          * VendorID << 16 + ProductID
30          */
31         int readerID;
32
33         /*
34          * Maximum message length
35          */
36         unsigned int dwMaxCCIDMessageLength;
37
38         /*
39          * Maximum IFSD
40          */
41         int dwMaxIFSD;
42
43         /*
44          * Features supported by the reader (directly from Class Descriptor)
45          */
46         int dwFeatures;
47
48         /*
49          * PIN support of the reader (directly from Class Descriptor)
50          */
51         char bPINSupport;
52
53         /*
54          * Display dimensions of the reader (directly from Class Descriptor)
55          */
56         unsigned int wLcdLayout;
57
58         /*
59          * Default Clock
60          */
61         int dwDefaultClock;
62
63         /*
64          * Max Data Rate
65          */
66         unsigned int dwMaxDataRate;
67
68         /*
69          * Number of available slots
70          */
71         char bMaxSlotIndex;
72
73         /*
74          * Slot in use
75          */
76         char bCurrentSlotIndex;
77
78         /*
79          * The array of data rates supported by the reader
80          */
81         unsigned int *arrayOfSupportedDataRates;
82
83         /*
84          * Read communication port timeout
85          * value is milliseconds
86          * this value can evolve dynamically if card request it (time processing).
87          */
88         unsigned int readTimeout;
89
90         /*
91          * Card protocol
92          */
93         int cardProtocol;
94
95         /*
96          * bInterfaceProtocol (CCID, ICCD-A, ICCD-B)
97          */
98         int bInterfaceProtocol;
99
100         /*
101          * bNumEndpoints
102          */
103         int bNumEndpoints;
104
105         /*
106          * GemCore SIM PRO slot status management
107          * The reader always reports a card present even if no card is inserted.
108          * If the Power Up fails the driver will report IFD_ICC_NOT_PRESENT instead
109          * of IFD_ICC_PRESENT
110          */
111         int dwSlotStatus;
112
113         /*
114          * bVoltageSupport (bit field)
115          * 1 = 5.0V
116          * 2 = 3.0V
117          * 4 = 1.8V
118          */
119         int bVoltageSupport;
120
121         /*
122          * USB serial number of the device (if any)
123          */
124         char *sIFD_serial_number;
125
126         /*
127          * USB iManufacturer string
128          */
129         char *sIFD_iManufacturer;
130
131         /*
132          * USB bcdDevice
133          */
134         int IFD_bcdDevice;
135
136         /*
137          * Gemalto extra features, if any
138          */
139         struct GEMALTO_FIRMWARE_FEATURES *gemalto_firmware_features;
140
141 #ifdef ENABLE_ZLP
142         /*
143          * Zero Length Packet fixup (boolean)
144          */
145         char zlp;
146 #endif
147 } _ccid_descriptor;
148
149 /* Features from dwFeatures */
150 #define CCID_CLASS_AUTO_CONF_ATR        0x00000002
151 #define CCID_CLASS_AUTO_ACTIVATION      0x00000004
152 #define CCID_CLASS_AUTO_VOLTAGE         0x00000008
153 #define CCID_CLASS_AUTO_BAUD            0x00000020
154 #define CCID_CLASS_AUTO_PPS_PROP        0x00000040
155 #define CCID_CLASS_AUTO_PPS_CUR         0x00000080
156 #define CCID_CLASS_AUTO_IFSD            0x00000400
157 #define CCID_CLASS_CHARACTER            0x00000000
158 #define CCID_CLASS_TPDU                         0x00010000
159 #define CCID_CLASS_SHORT_APDU           0x00020000
160 #define CCID_CLASS_EXTENDED_APDU        0x00040000
161 #define CCID_CLASS_EXCHANGE_MASK        0x00070000
162
163 /* Features from bPINSupport */
164 #define CCID_CLASS_PIN_VERIFY           0x01
165 #define CCID_CLASS_PIN_MODIFY           0x02
166
167 /* See CCID specs ch. 4.2.1 */
168 #define CCID_ICC_PRESENT_ACTIVE         0x00    /* 00 0000 00 */
169 #define CCID_ICC_PRESENT_INACTIVE       0x01    /* 00 0000 01 */
170 #define CCID_ICC_ABSENT                         0x02    /* 00 0000 10 */
171 #define CCID_ICC_STATUS_MASK            0x03    /* 00 0000 11 */
172
173 #define CCID_COMMAND_FAILED                     0x40    /* 01 0000 00 */
174 #define CCID_TIME_EXTENSION                     0x80    /* 10 0000 00 */
175
176 /* bInterfaceProtocol for ICCD */
177 #define PROTOCOL_CCID   0       /* plain CCID */
178 #define PROTOCOL_ICCD_A 1       /* ICCD Version A */
179 #define PROTOCOL_ICCD_B 2       /* ICCD Version B */
180
181 /* Product identification for special treatments */
182 #define GEMPC433        0x08E64433
183 #define GEMPCKEY        0x08E63438
184 #define GEMPCTWIN       0x08E63437
185 #define GEMPCPINPAD 0x08E63478
186 #define GEMCORESIMPRO 0x08E63480
187 #define GEMCORESIMPRO2 0x08E60000 /* Does NOT match a real VID/PID as new firmware release exposes same VID/PID */
188 #define GEMCOREPOSPRO 0x08E63479
189 #define GEMALTOPROXDU 0x08E65503
190 #define GEMALTOPROXSU 0x08E65504
191 #define GEMALTO_EZIO_CBP 0x08E634C3
192 #define CARDMAN3121     0x076B3021
193 #define LTC31           0x07830003
194 #define C3PO_LTC31_v2 0x07830006
195 #define SCR331DI        0x04E65111
196 #define SCR331DINTTCOM  0x04E65120
197 #define SDI010          0x04E65121
198 #define SEC1210 0x04241202
199 #define CHERRYXX33      0x046A0005
200 #define CHERRYST2000    0x046A003E
201 #define OZ776           0x0B977762
202 #define OZ776_7772      0x0B977772
203 #define SPR532          0x04E6E003
204 #define MYSMARTPAD      0x09BE0002
205 #define CHERRYXX44      0x046a0010
206 #define CL1356D         0x0B810200
207 #define REINER_SCT      0x0C4B0300
208 #define SEG                     0x08E68000
209 #define BLUDRIVEII_CCID 0x1B0E1078
210 #define DELLSCRK    0x413C2101
211 #define DELLSK      0x413C2100
212 #define KOBIL_TRIBANK   0x0D463010
213 #define KOBIL_MIDENTITY_VISUAL  0x0D464289
214 #define VEGAALPHA   0x09820008
215 #define HPSMARTCARDKEYBOARD 0x03F01024
216 #define HP_CCIDSMARTCARDKEYBOARD 0x03F00036
217 #define CHICONYHPSKYLABKEYBOARD 0x04F21469
218 #define KOBIL_IDTOKEN 0x0D46301D
219 #define FUJITSUSMARTKEYB 0x0BF81017
220 #define FEITIANR502DUAL 0x096E060D
221 #define MICROCHIP_SEC1100 0x04241104
222 #define CHERRY_KC1000SC 0x046A00A1
223 #define ElatecTWN4_CCID_CDC     0x09D80427
224 #define ElatecTWN4_CCID 0x09D80428
225 #define SCM_SCL011 0x04E65293
226 #define HID_AVIATOR     0x076B3A21
227 #define HID_OMNIKEY_5422 0x076B5422
228 #define HID_OMNIKEY_3X21 0x076B3031 /* OMNIKEY 3121 or 3021 or 1021 */
229 #define HID_OMNIKEY_3821 0x076B3821 /* OMNIKEY 3821 */
230 #define HID_OMNIKEY_6121 0x076B6632 /* OMNIKEY 6121 */
231 #define CHERRY_XX44     0x046A00A7 /* Cherry Smart Terminal xx44 */
232 #define FUJITSU_D323 0x0BF81024 /* Fujitsu Smartcard Reader D323 */
233 #define IDENTIV_uTrust3700F             0x04E65790
234 #define IDENTIV_uTrust3701F             0x04E65791
235 #define IDENTIV_uTrust4701F             0x04E65724
236
237 #define VENDOR_GEMALTO 0x08E6
238 #define GET_VENDOR(readerID) ((readerID >> 16) & 0xFFFF)
239
240 /*
241  * The O2Micro OZ776S reader has a wrong USB descriptor
242  * The extra[] field is associated with the last endpoint instead of the
243  * main USB descriptor
244  */
245 #define O2MICRO_OZ776_PATCH
246
247 /* Escape sequence codes */
248 #define ESC_GEMPC_SET_ISO_MODE          1
249 #define ESC_GEMPC_SET_APDU_MODE         2
250
251 /*
252  * Possible values :
253  * 3 -> 1.8V, 3V, 5V
254  * 2 -> 3V, 5V, 1.8V
255  * 1 -> 5V, 1.8V, 3V
256  * 0 -> automatic (selection made by the reader)
257  */
258 /*
259  * The default is to start at 5V
260  * otherwise we would have to parse the ATR and get the value of TAi (i>2) when
261  * in T=15
262  */
263 #define VOLTAGE_AUTO 0
264 #define VOLTAGE_5V 1
265 #define VOLTAGE_3V 2
266 #define VOLTAGE_1_8V 3
267
268 int ccid_open_hack_pre(unsigned int reader_index);
269 int ccid_open_hack_post(unsigned int reader_index);
270 void ccid_error(int log_level, int error, const char *file, int line,
271         const char *function);
272 _ccid_descriptor *get_ccid_descriptor(unsigned int reader_index);
273
274 /* convert a 4 byte integer in USB format into an int */
275 #define dw2i(a, x) (unsigned int)((((((a[x+3] << 8) + a[x+2]) << 8) + a[x+1]) << 8) + a[x])
276
277 /* all the data rates specified by ISO 7816-3 Fi/Di tables */
278 #define ISO_DATA_RATES 10753, 14337, 15625, 17204, \
279                 20833, 21505, 23438, 25806, 28674, \
280                 31250, 32258, 34409, 39063, 41667, \
281                 43011, 46875, 52083, 53763, 57348, \
282                 62500, 64516, 68817, 71685, 78125, \
283                 83333, 86022, 93750, 104167, 107527, \
284                 114695, 125000, 129032, 143369, 156250, \
285                 166667, 172043, 215054, 229391, 250000, \
286                 344086
287
288 /* data rates supported by the secondary slots on the GemCore Pos Pro & SIM Pro */
289 #define GEMPLUS_CUSTOM_DATA_RATES 10753, 21505, 43011, 125000
290
291 /* data rates for GemCore SIM Pro 2 */
292 #define SIMPRO2_ISO_DATA_RATES 8709, 10322, 12403, 12500, \
293                 12903, 17204, 18750, 20645, 24806, \
294                 25000, 25806, 28125, 30967, 34408, \
295                 37500, 41290, 46875, 49612, 50000, \
296                 51612, 56250, 62500, 64516, 68817, \
297                 74418, 75000, 82580, 86021, 93750, \
298                 99224, 100000, 103225, 112500, 124031, \
299                 125000, 137634, 150000, 154838, 165161, \
300                 172043, 187500, 198449, 200000, 206451, \
301                 258064, 275268, 300000, 396899, 400000, \
302                 412903, 550537, 600000, 825806
303
304 /* Structure returned by Gemalto readers for the CCID Escape command 0x6A */
305 struct GEMALTO_FIRMWARE_FEATURES
306 {
307         unsigned char   bLogicalLCDLineNumber;  /* Logical number of LCD lines */
308         unsigned char   bLogicalLCDRowNumber;   /* Logical number of characters per LCD line */
309         unsigned char   bLcdInfo;                               /* b0 indicates if scrolling is available */
310         unsigned char   bEntryValidationCondition;      /* See PIN_PROPERTIES */
311
312         /* Here come the PC/SC bit features to report */
313         unsigned char   VerifyPinStart:1;
314         unsigned char   VerifyPinFinish:1;
315         unsigned char   ModifyPinStart:1;
316         unsigned char   ModifyPinFinish:1;
317         unsigned char   GetKeyPressed:1;
318         unsigned char   VerifyPinDirect:1;
319         unsigned char   ModifyPinDirect:1;
320         unsigned char   Abort:1;
321
322         unsigned char   GetKey:1;
323         unsigned char   WriteDisplay:1;
324         unsigned char   SetSpeMessage:1;
325         unsigned char   RFUb1:5;
326
327         unsigned char   RFUb2[2];
328
329         /* Additional flags */
330         unsigned char   bTimeOut2:1;
331         unsigned char   bListSupportedLanguages:1;      /* Reader is able to indicate
332            the list of supported languages through CCID-ESC 0x6B */
333         unsigned char   bNumberMessageFix:1;    /* Reader handles correctly shifts
334                 made by bNumberMessage in PIN modification data structure */
335         unsigned char   bPPDUSupportOverXferBlock:1;    /* Reader supports PPDU over
336                 PC_to_RDR_XferBlock command */
337         unsigned char   bPPDUSupportOverEscape:1;       /* Reader supports PPDU over
338                 PC_to_RDR_Escape command with abData[0]=0xFF */
339         unsigned char   RFUb3:3;
340
341         unsigned char   RFUb4[3];
342
343         unsigned char   VersionNumber;  /* ?? */
344         unsigned char   MinimumPINSize; /* for Verify and Modify */
345         unsigned char   MaximumPINSize;
346
347         /* Miscellaneous reader features */
348         unsigned char   Firewall:1;
349         unsigned char   RFUb5:7;
350
351         /* The following fields, FirewalledCommand_SW1 and
352          * FirewalledCommand_SW2 are only valid if Firewall=1
353          * These fields give the SW1 SW2 value used by the reader to
354          * indicate a command has been firewalled */
355         unsigned char   FirewalledCommand_SW1;
356         unsigned char   FirewalledCommand_SW2;
357         unsigned char   RFUb6[3];
358 };
359