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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.5