/[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 269 - (show annotations) (download)
Tue Aug 12 12:40:23 2003 UTC (9 years, 9 months ago) by rousseau
File MIME type: text/plain
File size: 6747 byte(s)
Initial revision
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 usb_get_string_simple(handle, dev->descriptor.iManufacturer,
93 buffer, sizeof(buffer));
94 printf(" iManufacturer: %s\n", buffer);
95
96 usb_get_string_simple(handle, dev->descriptor.iProduct,
97 buffer, sizeof(buffer));
98 printf(" iProduct: %s\n", buffer);
99
100 usb_interface = dev->config->interface->altsetting;
101
102 printf(" bLength: %d\n", usb_interface->bLength);
103
104 printf(" bDescriptorType: %d\n", usb_interface->bDescriptorType);
105
106 printf(" bInterfaceNumber: %d\n", usb_interface->bInterfaceNumber);
107
108 printf(" bAlternateSetting: %d\n", usb_interface->bAlternateSetting);
109
110 printf(" bNumEndpoints: %d\n", usb_interface->bNumEndpoints);
111
112 printf(" bInterfaceClass: 0x%02X", usb_interface->bInterfaceClass);
113 if (usb_interface->bInterfaceClass == 0x0b)
114 printf(" [Chip Card Interface Device Class (CCID)]\n");
115 else
116 {
117 printf("NOT A CCID DEVICE\n");
118 return TRUE;
119 }
120
121 printf(" bInterfaceSubClass: %d\n", usb_interface->bInterfaceSubClass);
122 if (usb_interface->bInterfaceSubClass)
123 {
124 printf(" UNSUPPORTED SubClass\n");
125 return TRUE;
126 }
127
128 printf(" bInterfaceProtocol: %d\n", usb_interface->bInterfaceProtocol);
129 if (usb_interface->bInterfaceProtocol)
130 {
131 printf(" UNSUPPORTED InterfaceProtocol\n");
132 return TRUE;
133 }
134
135 printf(" iInterface: %d\n", usb_interface->iInterface);
136
137 /*
138 * CCID Class Descriptor
139 */
140 printf(" CCID Class Descriptor\n");
141 extra = usb_interface->extra;
142
143 printf(" bLength: 0x%02X\n", extra[0]);
144 if (extra[0] != 0x36)
145 {
146 printf(" UNSUPPORTED bLength\n");
147 return TRUE;
148 }
149
150 printf(" bDescriptorType: 0x%02X\n", extra[1]);
151 if (extra[1] != 0x21)
152 {
153 printf(" UNSUPPORTED bDescriptorType\n");
154 return TRUE;
155 }
156
157 printf(" bcdCCID: %X.%02X\n", extra[3], extra[2]);
158 printf(" bMaxSlotIndex: 0x%02X\n", extra[4]);
159 printf(" bVoltageSupport: 0x%02X -", extra[5]);
160 if (extra[5] & 0x01)
161 printf(" 5.0V");
162 if (extra[5] & 0x02)
163 printf(" 3.0V");
164 if (extra[5] & 0x04)
165 printf(" 1.8V");
166 printf("\n");
167
168 printf(" dwProtocols: 0x%02X%02X 0x%02X%02X -", extra[9], extra[8], extra[7],extra[6]);
169 if (extra[6] & 0x01)
170 printf(" T=0");
171 if (extra[6] & 0x02)
172 printf(" T=1");
173 printf("\n");
174
175 printf(" dwDefaultClock: %.3f MHz\n", dw2i(extra, 10)/1000.0);
176 printf(" dwMaximumClock: %.3f MHz\n", dw2i(extra, 14)/1000.0);
177
178 printf(" bNumClockSupported: 0x%02X\n", extra[18]);
179 printf(" dwDataRate: %d bps\n", dw2i(extra, 19));
180 printf(" dwMaxDataRate: %d bps\n", dw2i(extra, 23));
181 printf(" bNumDataRatesSupported: %d\n", extra[27]);
182 printf(" dwMaxIFSD: %d\n", dw2i(extra, 28));
183 printf(" dwSynchProtocols: 0x%08X\n", dw2i(extra, 32));
184
185 printf(" dwMechanical: 0x%08X -", dw2i(extra, 36));
186 if (extra[36] == 0)
187 printf(" No special characteristics");
188 if (extra[36] & 0x01)
189 printf(" Card accept mechanism");
190 if (extra[36] & 0x02)
191 printf(" Card ejection mechanism");
192 if (extra[36] & 0x04)
193 printf(" Card capture mechanism");
194 if (extra[36] & 0x08)
195 printf(" Card lock/unlock mechanism");
196 printf("\n");
197
198 printf(" dwFeatures: 0x%08X -", dw2i(extra, 40));
199 if (extra[40] == 0)
200 printf(" No special characteristics");
201 if (extra[40] & 0x02)
202 printf(" Automatic parameter configuration based on ATR data,");
203 if (extra[40] & 0x04)
204 printf(" Automatic activation of ICC on inserting,");
205 if (extra[40] & 0x08)
206 printf(" Automatic ICC voltage selection,");
207 if (extra[40] & 0x10)
208 printf(" Automatic ICC clock frequency change according to parameters,");
209 if (extra[40] & 0x20)
210 printf(" Automatic baud rate change according to frequency and Fi, Di parameters,");
211 if (extra[40] & 0x40)
212 printf(" Automatic parameters negotiation made by the ICC,");
213 if (extra[40] & 0x80)
214 printf(" Automatic PPS made by the ICC,");
215 if (extra[41] & 0x01)
216 printf(" CCID can set ICC in clock stop mode,");
217 if (extra[41] & 0x02)
218 printf(" NAD value other than 00 accepted (T=1),");
219 if (extra[41] & 0x04)
220 printf(" Automatic IFSD exchange as first exchange (T=1),");
221 if (extra[42] & 0x01)
222 printf(" TPDU level exchange,");
223 if (extra[42] & 0x02)
224 printf(" Short APDU level exchange,");
225 if (extra[42] & 0x04)
226 printf(" Short and Extended APDU level exchange,");
227 printf("\n");
228
229 printf(" dwMaxCCIDMessageLength: %d bytes\n", dw2i(extra, 44));
230 printf(" bClassGetResponse: %d\n", extra[48]);
231 printf(" bClassEnveloppe: %d\n", extra[49]);
232 printf(" wLcdLayout: 0x%04X\n", (extra[51] << 8)+extra[50]);
233 printf(" bPINSupport: 0x%02X\n", extra[52]);
234 printf(" bMaxCCIDBusySlots: %d\n", extra[53]);
235
236 return FALSE;
237 } /* ccid_parse_interface_descriptor */
238

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.5