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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.5