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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1160 - (show annotations) (download)
Fri Aug 6 13:29:00 2004 UTC (8 years, 9 months ago) by rousseau
File MIME type: text/plain
File size: 7648 byte(s)
try to IFDHCloseChannel() only if we opened at least one reader
1 /*
2 parse.c: parse CCID structure
3 Copyright (C) 2003-2004 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 <string.h>
26 # ifdef S_SPLINT_S
27 # include <sys/types.h>
28 # endif
29 #include <usb.h>
30
31 #include <ifdhandler.h>
32 #include "defs.h"
33 #include "ccid_ifdhandler.h"
34 #include "ccid.h"
35
36 #ifndef TRUE
37 #define TRUE 1
38 #define FALSE 0
39 #endif
40
41 static int ccid_parse_interface_descriptor(usb_dev_handle *handle,
42 struct usb_device *dev);
43
44
45 /*****************************************************************************
46 *
47 * main
48 *
49 ****************************************************************************/
50 int main(/*@unused@*/ int argc, /*@unused@*/ char *argv[])
51 {
52 status_t res;
53 unsigned int channel;
54
55 for (channel=0; channel<CCID_DRIVER_MAX_READERS; channel++)
56 {
57 res = IFDHCreateChannel(channel<<16, channel);
58 if (res != IFD_SUCCESS)
59 {
60 fprintf(stderr, "ccid_OpenUSB: %d\n", res);
61 break;
62 }
63 else
64 {
65 usb_dev_handle *handle;
66 struct usb_device *dev;
67
68 get_desc(channel, &handle, &dev);
69 res = ccid_parse_interface_descriptor(handle, dev);
70 }
71 }
72
73 if (channel == 0)
74 printf("No known CCID reader found\n");
75 else
76 for (channel--; channel!=0; channel--)
77 (void)IFDHCloseChannel(channel<<16);
78
79 return 0;
80 } /* main */
81
82
83 /*****************************************************************************
84 *
85 * Parse a CCID USB Descriptor
86 *
87 ****************************************************************************/
88 static int ccid_parse_interface_descriptor(usb_dev_handle *handle,
89 struct usb_device *dev)
90 {
91 struct usb_interface_descriptor *usb_interface;
92 unsigned char *extra;
93 char buffer[255];
94
95 /*
96 * Interface Descriptor
97 */
98 printf("Parsing Interface Descriptor for device: %s/%s\n",
99 dev->bus->dirname, dev->filename);
100
101 /*
102 * Vendor/model name
103 */
104 if (usb_get_string_simple(handle, dev->descriptor.iManufacturer,
105 buffer, sizeof(buffer)) < 0)
106 printf(" Can't get iManufacturer string\n");
107 else
108 printf(" iManufacturer: %s\n", buffer);
109
110 if (usb_get_string_simple(handle, dev->descriptor.iProduct,
111 buffer, sizeof(buffer)) < 0)
112 printf(" Can't get iProduct string\n");
113 else
114 printf(" iProduct: %s\n", buffer);
115
116 usb_interface = get_ccid_usb_interface(dev)->altsetting;
117
118 printf(" bLength: %d\n", usb_interface->bLength);
119
120 printf(" bDescriptorType: %d\n", usb_interface->bDescriptorType);
121
122 printf(" bInterfaceNumber: %d\n", usb_interface->bInterfaceNumber);
123
124 printf(" bAlternateSetting: %d\n", usb_interface->bAlternateSetting);
125
126 printf(" bNumEndpoints: %d\n", usb_interface->bNumEndpoints);
127
128 printf(" bInterfaceClass: 0x%02X", usb_interface->bInterfaceClass);
129 if (usb_interface->bInterfaceClass == 0x0b)
130 printf(" [Chip Card Interface Device Class (CCID)]\n");
131 else
132 {
133 printf("\n NOT A CCID DEVICE\n");
134 if (usb_interface->bInterfaceClass != 0xFF)
135 return TRUE;
136 else
137 printf(" Class is 0xFF (proprietary)\n");
138 }
139
140 printf(" bInterfaceSubClass: %d\n", usb_interface->bInterfaceSubClass);
141 if (usb_interface->bInterfaceSubClass)
142 printf(" UNSUPPORTED SubClass\n");
143
144 printf(" bInterfaceProtocol: %d\n", usb_interface->bInterfaceProtocol);
145 if (usb_interface->bInterfaceProtocol)
146 printf(" UNSUPPORTED InterfaceProtocol\n");
147
148 printf(" iInterface: %d\n", usb_interface->iInterface);
149
150 if (usb_interface->extralen < 54)
151 {
152 printf("USB extra length is too short: %d\n", usb_interface->extralen);
153 printf("\n NOT A CCID DEVICE\n");
154 return TRUE;
155 }
156
157 /*
158 * CCID Class Descriptor
159 */
160 printf(" CCID Class Descriptor\n");
161 extra = usb_interface->extra;
162
163 printf(" bLength: 0x%02X\n", extra[0]);
164 if (extra[0] != 0x36)
165 {
166 printf(" UNSUPPORTED bLength\n");
167 return TRUE;
168 }
169
170 printf(" bDescriptorType: 0x%02X\n", extra[1]);
171 if (extra[1] != 0x21)
172 {
173 if (0xFF == extra[1])
174 printf(" PROPRIETARY bDescriptorType\n");
175 else
176 {
177 printf(" UNSUPPORTED bDescriptorType\n");
178 return TRUE;
179 }
180 }
181
182 printf(" bcdCCID: %X.%02X\n", extra[3], extra[2]);
183 printf(" bMaxSlotIndex: 0x%02X\n", extra[4]);
184 printf(" bVoltageSupport: 0x%02X\n", extra[5]);
185 if (extra[5] & 0x01)
186 printf(" 5.0V\n");
187 if (extra[5] & 0x02)
188 printf(" 3.0V\n");
189 if (extra[5] & 0x04)
190 printf(" 1.8V\n");
191
192 printf(" dwProtocols: 0x%02X%02X 0x%02X%02X\n", extra[9], extra[8],
193 extra[7],extra[6]);
194 if (extra[6] & 0x01)
195 printf(" T=0\n");
196 if (extra[6] & 0x02)
197 printf(" T=1\n");
198
199 printf(" dwDefaultClock: %.3f MHz\n", dw2i(extra, 10)/1000.0);
200 printf(" dwMaximumClock: %.3f MHz\n", dw2i(extra, 14)/1000.0);
201
202 printf(" bNumClockSupported: 0x%02X\n", extra[18]);
203 printf(" dwDataRate: %d bps\n", dw2i(extra, 19));
204 printf(" dwMaxDataRate: %d bps\n", dw2i(extra, 23));
205 printf(" bNumDataRatesSupported: %d\n", extra[27]);
206 printf(" dwMaxIFSD: %d\n", dw2i(extra, 28));
207 printf(" dwSynchProtocols: 0x%08X\n", dw2i(extra, 32));
208
209 printf(" dwMechanical: 0x%08X\n", dw2i(extra, 36));
210 if (extra[36] == 0)
211 printf(" No special characteristics\n");
212 if (extra[36] & 0x01)
213 printf(" Card accept mechanism\n");
214 if (extra[36] & 0x02)
215 printf(" Card ejection mechanism\n");
216 if (extra[36] & 0x04)
217 printf(" Card capture mechanism\n");
218 if (extra[36] & 0x08)
219 printf(" Card lock/unlock mechanism\n");
220
221 printf(" dwFeatures: 0x%08X\n", dw2i(extra, 40));
222 if (extra[40] == 0)
223 printf(" No special characteristics\n");
224 if (extra[40] & 0x02)
225 printf(" Automatic parameter configuration based on ATR data\n");
226 if (extra[40] & 0x04)
227 printf(" Automatic activation of ICC on inserting\n");
228 if (extra[40] & 0x08)
229 printf(" Automatic ICC voltage selection\n");
230 if (extra[40] & 0x10)
231 printf(" Automatic ICC clock frequency change according to parameters\n");
232 if (extra[40] & 0x20)
233 printf(" Automatic baud rate change according to frequency and Fi, Di parameters\n");
234 if (extra[40] & 0x40)
235 printf(" Automatic parameters negotiation made by the ICC\n");
236 if (extra[40] & 0x80)
237 printf(" Automatic PPS made by the ICC\n");
238 if (extra[41] & 0x01)
239 printf(" CCID can set ICC in clock stop mode\n");
240 if (extra[41] & 0x02)
241 printf(" NAD value other than 00 accepted (T=1)\n");
242 if (extra[41] & 0x04)
243 printf(" Automatic IFSD exchange as first exchange (T=1)\n");
244 if (extra[42] & 0x01)
245 printf(" TPDU level exchange\n");
246 if (extra[42] & 0x02)
247 printf(" Short APDU level exchange\n");
248 if (extra[42] & 0x04)
249 printf(" Short and Extended APDU level exchange\n");
250
251 printf(" dwMaxCCIDMessageLength: %d bytes\n", dw2i(extra, 44));
252 printf(" bClassGetResponse: %d\n", extra[48]);
253 printf(" bClassEnveloppe: %d\n", extra[49]);
254 printf(" wLcdLayout: 0x%04X\n", (extra[51] << 8)+extra[50]);
255 printf(" bPINSupport: 0x%02X\n", extra[52]);
256 if (extra[52] & 0x01)
257 printf(" PIN Verification supported\n");
258 if (extra[52] & 0x02)
259 printf(" PIN Modification supported\n");
260 printf(" bMaxCCIDBusySlots: %d\n", extra[53]);
261
262 return FALSE;
263 } /* ccid_parse_interface_descriptor */
264

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.5