/[pcsclite]/trunk/Drivers/ccid/src/ccid.c
ViewVC logotype

Contents of /trunk/Drivers/ccid/src/ccid.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1093 - (show annotations) (download)
Wed Jul 21 09:01:11 2004 UTC (8 years, 10 months ago) by rousseau
File MIME type: text/plain
File size: 5098 byte(s)
ccid_open_hack(): detect and activate the contactless interface of the
SCR331-DI
1 /*
2 ccid.c: CCID common code
3 Copyright (C) 2003 Ludovic Rousseau
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program 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
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20 /*
21 * $Id$
22 */
23
24 #include <stdio.h>
25 #include <PCSC/pcsclite.h>
26 #include <PCSC/ifdhandler.h>
27
28 #include "config.h"
29 #include "debug.h"
30 #include "ccid.h"
31 #include "defs.h"
32 #include "ccid_ifdhandler.h"
33 #include "commands.h"
34
35 /*****************************************************************************
36 *
37 * ccid_open_hack
38 *
39 ****************************************************************************/
40 int ccid_open_hack(unsigned int lun)
41 {
42 _ccid_descriptor *ccid_descriptor = get_ccid_descriptor(lun);
43
44 switch (ccid_descriptor->readerID)
45 {
46 case CARDMAN3121+1:
47 /* Reader announces APDU but is in fact TPDU */
48 ccid_descriptor->dwFeatures &= ~CCID_CLASS_EXCHANGE_MASK;
49 ccid_descriptor->dwFeatures |= CCID_CLASS_TPDU;
50 break;
51
52 /*
53 * Do not switch to APDU mode since it also swicth in EMV mode and
54 * may not work with non EMV cards
55 */
56 case GEMPCKEY:
57 case GEMPCTWIN:
58 /* Reader announces TPDU but can do APDU */
59 if (DriverOptions & DRIVER_OPTION_GEMPC_TWIN_KEY_APDU)
60 {
61 unsigned char cmd[] = "\xA0\x02";
62 unsigned char res[10];
63 unsigned int length_res = sizeof(res);
64
65 if (CmdEscape(lun, cmd, sizeof(cmd)-1, res, &length_res) == IFD_SUCCESS)
66 {
67 ccid_descriptor->dwFeatures &= ~CCID_CLASS_EXCHANGE_MASK;
68 ccid_descriptor->dwFeatures |= CCID_CLASS_SHORT_APDU;
69 }
70 }
71 break;
72
73 /* SCM SCR331-DI contactless */
74 case SCR331DI:
75 /* the contactless reader is in the second slot */
76 if (ccid_descriptor->bMaxSlotIndex > 0)
77 {
78 unsigned char cmd1[] = { 0x00 };
79 /* command: 00 ??
80 * response: 06 10 03 03 00 00 00 01 FE FF FF FE 01 ?? */
81 unsigned char cmd2[] = { 0x02 };
82 /* command: 02 ??
83 * response: 00 ?? */
84
85 unsigned char res[20];
86 unsigned int length_res = sizeof(res);
87
88 if ((IFD_SUCCESS == CmdEscape(lun, cmd1, sizeof(cmd1), res, &length_res))
89 && (IFD_SUCCESS == CmdEscape(lun, cmd2, sizeof(cmd2), res, &length_res)))
90 {
91 DEBUG_COMM("SCM SCR331-DI contactless detected");
92 }
93 else
94 {
95 DEBUG_COMM("SCM SCR331-DI contactless init failed");
96
97 /* inhibit the contactless reader */
98 ccid_descriptor->bMaxSlotIndex = 0;
99 }
100 }
101 break;
102 }
103
104 return 0;
105 } /* ccid_open_hack */
106
107 /*****************************************************************************
108 *
109 * ccid_error
110 *
111 ****************************************************************************/
112 void ccid_error(int error, char *file, int line, char *function)
113 {
114 char *text;
115 char var_text[20];
116
117 switch (error)
118 {
119 case 0x00:
120 text = "Command not supported or not allowed";
121 break;
122
123 case 0x01:
124 text = "Wrong command length";
125 break;
126
127 case 0x05:
128 text = "Invalid slot number";
129 break;
130
131 case 0xA2:
132 text = "Card short-circuiting. Card powered off";
133 break;
134
135 case 0xA3:
136 text = "ATR too long (> 33)";
137 break;
138
139 case 0xAB:
140 text = "No data exchanged";
141 break;
142
143 case 0xB0:
144 text = "Reader in EMV mode and T=1 message too long";
145 break;
146
147 case 0xBB:
148 text = "Protocol error in EMV mode";
149 break;
150
151 case 0xBD:
152 text = "Card error during T=1 exchange";
153 break;
154
155 case 0xBE:
156 text = "Wrong APDU command length";
157 break;
158
159 case 0xE0:
160 text = "Slot busy";
161 break;
162
163 case 0xEF:
164 text = "PIN cancelled";
165 break;
166
167 case 0xF0:
168 text = "PIN timeout";
169 break;
170
171 case 0xF2:
172 text = "Busy with autosequence";
173 break;
174
175 case 0xF3:
176 text = "Deactivated protocol";
177 break;
178
179 case 0xF4:
180 text = "Procedure byte conflict";
181 break;
182
183 case 0xF5:
184 text = "Class not supported";
185 break;
186
187 case 0xF6:
188 text = "Protocol not supported";
189 break;
190
191 case 0xF7:
192 text = "Invalid ATR checksum byte (TCK)";
193 break;
194
195 case 0xF8:
196 text = "Invalid ATR first byte";
197 break;
198
199 case 0xFB:
200 text = "Hardware error";
201 break;
202
203 case 0xFC:
204 text = "Overrun error";
205 break;
206
207 case 0xFD:
208 text = "Parity error during exchange";
209 break;
210
211 case 0xFE:
212 text = "Card absent or mute";
213 break;
214
215 case 0xFF:
216 text = "Activity aborted by Host";
217 break;
218
219 default:
220 if ((error >= 1) && (error <= 127))
221 {
222 sprintf(var_text, "error on byte %d", error);
223 text = var_text;
224 }
225 else
226 text = "Unknown CCID error";
227 break;
228 }
229 debug_msg("%s:%d:%s %s", file, line, function, text);
230
231 } /* ccid_error */
232

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.5