blob: c1effec0fe7078deeed57cda7d069cf1e778a2e5 [file] [log] [blame]
Christina Quast968b9742015-02-25 14:10:12 +01001/* ----------------------------------------------------------------------------
2 * ATMEL Microcontroller Software Support
3 * ----------------------------------------------------------------------------
4 * Copyright (c) 2009, Atmel Corporation
5 *
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
10 *
11 * - Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the disclaimer below.
13 *
14 * Atmel's name may not be used to endorse or promote products derived from
15 * this software without specific prior written permission.
16 *
17 * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
20 * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
23 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 * ----------------------------------------------------------------------------
28 */
29
30/*----------------------------------------------------------------------------
31 * Headers
32 *----------------------------------------------------------------------------*/
33
34#include "board.h"
Harald Welte16055642016-03-03 11:02:45 +010035#include "simtrace.h"
Harald Welte2fb59962016-02-28 12:34:26 +010036#include "utils.h"
Christina Quast968b9742015-02-25 14:10:12 +010037
Christina Quastdb7b1ab2015-03-03 12:34:36 +010038#include <cciddriverdescriptors.h>
Harald Welte7ed6f3b2017-02-26 17:00:43 +010039#include <usb/common/dfu/usb_dfu.h>
40#include <usb/device/dfu/dfu.h>
Christina Quastdb7b1ab2015-03-03 12:34:36 +010041
Christina Quastf5549502015-02-24 14:27:08 +010042/*------------------------------------------------------------------------------
43 * USB String descriptors
44 *------------------------------------------------------------------------------*/
Harald Welte2363fa02017-03-05 10:16:25 +010045#include "usb_strings_generated.h"
Christina Quastf5549502015-02-24 14:27:08 +010046enum strDescNum {
Harald Welte7dd3dfd2016-03-03 12:32:04 +010047 PRODUCT_STRING = 1,
48 MANUF_STR,
49 SNIFFER_CONF_STR,
50 CCID_CONF_STR,
51 PHONE_CONF_STR,
52 MITM_CONF_STR,
53 CARDEM_USIM1_INTF_STR,
54 CARDEM_USIM2_INTF_STR,
55 STRING_DESC_CNT
Christina Quastf5549502015-02-24 14:27:08 +010056};
57
Christina Quastf5549502015-02-24 14:27:08 +010058/*------------------------------------------------------------------------------
59 * USB Device descriptors
60 *------------------------------------------------------------------------------*/
61
Harald Welte2fb59962016-02-28 12:34:26 +010062#ifdef HAVE_SNIFFER
Christina Quastf5549502015-02-24 14:27:08 +010063typedef struct _SIMTraceDriverConfigurationDescriptorSniffer {
64
Harald Welte7dd3dfd2016-03-03 12:32:04 +010065 /** Standard configuration descriptor. */
66 USBConfigurationDescriptor configuration;
67 USBInterfaceDescriptor sniffer;
68 USBEndpointDescriptor sniffer_dataOut;
69 USBEndpointDescriptor sniffer_dataIn;
70 USBEndpointDescriptor sniffer_interruptIn;
Harald Welte7ed6f3b2017-02-26 17:00:43 +010071 DFURT_IF_DESCRIPTOR_STRUCT;
Christina Quast01bbdc32015-02-24 17:38:45 +010072} __attribute__ ((packed)) SIMTraceDriverConfigurationDescriptorSniffer;
Christina Quastf5549502015-02-24 14:27:08 +010073
Harald Welte7dd3dfd2016-03-03 12:32:04 +010074static const SIMTraceDriverConfigurationDescriptorSniffer
75 configurationDescriptorSniffer = {
76 /* Standard configuration descriptor */
77 {
78 .bLength = sizeof(USBConfigurationDescriptor),
79 .bDescriptorType = USBGenericDescriptor_CONFIGURATION,
80 .wTotalLength = sizeof(SIMTraceDriverConfigurationDescriptorSniffer),
Harald Welte7ed6f3b2017-02-26 17:00:43 +010081 .bNumInterfaces = 1+DFURT_NUM_IF,
Harald Welte7dd3dfd2016-03-03 12:32:04 +010082 .bConfigurationValue = CFG_NUM_SNIFF,
83 .iConfiguration = SNIFFER_CONF_STR,
84 .bmAttributes = USBD_BMATTRIBUTES,
85 .bMaxPower = USBConfigurationDescriptor_POWER(100),
86 },
87 /* Communication class interface standard descriptor */
88 {
89 .bLength = sizeof(USBInterfaceDescriptor),
90 .bDescriptorType = USBGenericDescriptor_INTERFACE,
91 .bInterfaceNumber = 0,
92 .bAlternateSetting = 0,
93 .bNumEndpoints = 3,
94 .bInterfaceClass = 0xff,
95 .bInterfaceSubClass = 0,
96 .bInterfaceProtocol = 0,
97 .iInterface = SNIFFER_CONF_STR,
98 },
99 /* Bulk-OUT endpoint standard descriptor */
100 {
101 .bLength = sizeof(USBEndpointDescriptor),
102 .bDescriptorType = USBGenericDescriptor_ENDPOINT,
103 .bEndpointAddress = USBEndpointDescriptor_ADDRESS(
104 USBEndpointDescriptor_OUT,
105 PHONE_DATAOUT),
106 .bmAttributes = USBEndpointDescriptor_BULK,
107 .wMaxPacketSize = MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(
108 PHONE_DATAOUT),
109 USBEndpointDescriptor_MAXBULKSIZE_FS),
110 .bInterval = 0,
111 },
112 /* Bulk-IN endpoint descriptor */
113 {
114 .bLength = sizeof(USBEndpointDescriptor),
115 .bDescriptorType = USBGenericDescriptor_ENDPOINT,
116 .bEndpointAddress = USBEndpointDescriptor_ADDRESS(
117 USBEndpointDescriptor_IN,
118 PHONE_DATAIN),
119 .bmAttributes = USBEndpointDescriptor_BULK,
120 .wMaxPacketSize = MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(
121 PHONE_DATAIN),
122 USBEndpointDescriptor_MAXBULKSIZE_FS),
123 .bInterval = 0,
124 },
125 // Notification endpoint descriptor
126 {
127 .bLength = sizeof(USBEndpointDescriptor),
128 .bDescriptorType = USBGenericDescriptor_ENDPOINT,
129 .bEndpointAddress = USBEndpointDescriptor_ADDRESS(
130 USBEndpointDescriptor_IN,
131 PHONE_INT),
132 .bmAttributes = USBEndpointDescriptor_INTERRUPT,
133 .wMaxPacketSize = MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(
134 PHONE_INT),
135 USBEndpointDescriptor_MAXINTERRUPTSIZE_FS),
136 .bInterval = 0x10,
Harald Welte7ed6f3b2017-02-26 17:00:43 +0100137 },
138 DFURT_IF_DESCRIPTOR(1, 0),
Christina Quastf5549502015-02-24 14:27:08 +0100139};
Harald Welte2fb59962016-02-28 12:34:26 +0100140#endif /* HAVE_SNIFFER */
Christina Quastf5549502015-02-24 14:27:08 +0100141
Harald Welte2fb59962016-02-28 12:34:26 +0100142#ifdef HAVE_CCID
Harald Welteec4fe232015-11-07 18:41:25 +0100143static const CCIDDriverConfigurationDescriptors configurationDescriptorCCID = {
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100144 // Standard USB configuration descriptor
145 {
146 .bLength = sizeof(USBConfigurationDescriptor),
147 .bDescriptorType = USBGenericDescriptor_CONFIGURATION,
148 .wTotalLength = sizeof(CCIDDriverConfigurationDescriptors),
Harald Welte7ed6f3b2017-02-26 17:00:43 +0100149 .bNumInterfaces = 1+DFURT_NUM_IF,
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100150 .bConfigurationValue = CFG_NUM_CCID,
151 .iConfiguration = CCID_CONF_STR,
152 .bmAttributes = BOARD_USB_BMATTRIBUTES,
153 .bMaxPower = USBConfigurationDescriptor_POWER(100),
154 },
155 // CCID interface descriptor
156 // Table 4.3-1 Interface Descriptor
157 // Interface descriptor
158 {
159 .bLength = sizeof(USBInterfaceDescriptor),
160 .bDescriptorType = USBGenericDescriptor_INTERFACE,
161 .bInterfaceNumber = 0,
162 .bAlternateSetting = 0,
163 .bNumEndpoints = 3,
164 .bInterfaceClass = SMART_CARD_DEVICE_CLASS,
165 .bInterfaceSubClass = 0,
166 .bInterfaceProtocol = 0,
167 .iInterface = CCID_CONF_STR,
168 },
169 {
170 .bLength = sizeof(CCIDDescriptor),
171 .bDescriptorType = CCID_DECRIPTOR_TYPE,
172 .bcdCCID = CCID1_10, // CCID version
173 .bMaxSlotIndex = 0, // 1 slot
174 .bVoltageSupport = VOLTS_3_0,
175 .dwProtocols = (1 << PROTOCOL_TO),
176 .dwDefaultClock = 3580,
177 .dwMaximumClock = 3580,
178 .bNumClockSupported = 0,
179 .dwDataRate = 9600,
180 .dwMaxDataRate = 9600,
181 .bNumDataRatesSupported = 0,
182 .dwMaxIFSD = 0xfe,
183 .dwSynchProtocols = 0,
184 .dwMechanical = 0,
185 .dwFeatures = CCID_FEATURES_AUTO_CLOCK | CCID_FEATURES_AUTO_BAUD |
186 CCID_FEATURES_AUTO_PCONF | CCID_FEATURES_AUTO_PNEGO |
187 CCID_FEATURES_EXC_TPDU,
188 .dwMaxCCIDMessageLength = 271, /* For extended APDU
189 level the value shall
190 be between 261 + 10 */
191 .bClassGetResponse = 0xFF, // Echoes the class of the APDU
192 .bClassEnvelope = 0xFF, // Echoes the class of the APDU
193 .wLcdLayout = 0, // wLcdLayout: no LCD
194 .bPINSupport = 0, // bPINSupport: No PIN
195 .bMaxCCIDBusySlots = 1,
196 },
197 // Bulk-OUT endpoint descriptor
198 {
199 .bLength = sizeof(USBEndpointDescriptor),
200 .bDescriptorType = USBGenericDescriptor_ENDPOINT,
201 .bEndpointAddress =
202 USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_OUT,
203 CCID_EPT_DATA_OUT),
204 .bmAttributes = USBEndpointDescriptor_BULK,
205 .wMaxPacketSize = MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(
206 CCID_EPT_DATA_OUT),
207 USBEndpointDescriptor_MAXBULKSIZE_FS),
208 .bInterval = 0x00,
209 },
210 // Bulk-IN endpoint descriptor
211 {
212 .bLength = sizeof(USBEndpointDescriptor),
213 .bDescriptorType = USBGenericDescriptor_ENDPOINT,
214 .bEndpointAddress =
215 USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN,
216 CCID_EPT_DATA_IN),
217 .bmAttributes = USBEndpointDescriptor_BULK,
218 .wMaxPacketSize = MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(
219 CCID_EPT_DATA_IN),
220 USBEndpointDescriptor_MAXBULKSIZE_FS),
221 .bInterval = 0x00,
222 },
223 // Notification endpoint descriptor
224 {
225 .bLength = sizeof(USBEndpointDescriptor),
226 .bDescriptorType = USBGenericDescriptor_ENDPOINT,
227 .bEndpointAddress =
228 USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN,
229 CCID_EPT_NOTIFICATION),
230 .bmAttributes = USBEndpointDescriptor_INTERRUPT,
231 .wMaxPacketSize = MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(
232 CCID_EPT_NOTIFICATION),
233 USBEndpointDescriptor_MAXINTERRUPTSIZE_FS),
234 .bInterval = 0x10,
235 },
Harald Welte7ed6f3b2017-02-26 17:00:43 +0100236 DFURT_IF_DESCRIPTOR(1, 0),
Christina Quastdb7b1ab2015-03-03 12:34:36 +0100237};
Harald Welte2fb59962016-02-28 12:34:26 +0100238#endif /* HAVE_CCID */
Christina Quastdb7b1ab2015-03-03 12:34:36 +0100239
Harald Welte2fb59962016-02-28 12:34:26 +0100240#ifdef HAVE_CARDEM
Christina Quast01bbdc32015-02-24 17:38:45 +0100241/* SIM card emulator */
242typedef struct _SIMTraceDriverConfigurationDescriptorPhone {
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100243 /* Standard configuration descriptor. */
244 USBConfigurationDescriptor configuration;
245 USBInterfaceDescriptor phone;
246 USBEndpointDescriptor phone_dataOut;
247 USBEndpointDescriptor phone_dataIn;
248 USBEndpointDescriptor phone_interruptIn;
Harald Welte57b3a252016-03-02 15:20:27 +0100249#ifdef CARDEMU_SECOND_UART
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100250 USBInterfaceDescriptor usim2;
251 USBEndpointDescriptor usim2_dataOut;
252 USBEndpointDescriptor usim2_dataIn;
253 USBEndpointDescriptor usim2_interruptIn;
Harald Welte57b3a252016-03-02 15:20:27 +0100254#endif
Harald Welte7ed6f3b2017-02-26 17:00:43 +0100255 DFURT_IF_DESCRIPTOR_STRUCT;
Christina Quast01bbdc32015-02-24 17:38:45 +0100256} __attribute__ ((packed)) SIMTraceDriverConfigurationDescriptorPhone;
257
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100258static const SIMTraceDriverConfigurationDescriptorPhone
259 configurationDescriptorPhone = {
260 /* Standard configuration descriptor */
261 {
262 sizeof(USBConfigurationDescriptor),
263 USBGenericDescriptor_CONFIGURATION,
264 sizeof(SIMTraceDriverConfigurationDescriptorPhone),
Harald Welte57b3a252016-03-02 15:20:27 +0100265#ifdef CARDEMU_SECOND_UART
Harald Welte7ed6f3b2017-02-26 17:00:43 +0100266 2+DFURT_NUM_IF,
Harald Welte57b3a252016-03-02 15:20:27 +0100267#else
Harald Welte7ed6f3b2017-02-26 17:00:43 +0100268 1+DFURT_NUM_IF, /* There is one interface in this configuration */
Harald Welte57b3a252016-03-02 15:20:27 +0100269#endif
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100270 CFG_NUM_PHONE, /* configuration number */
271 PHONE_CONF_STR, /* string descriptor for this configuration */
272 USBD_BMATTRIBUTES,
273 USBConfigurationDescriptor_POWER(100)
274 },
275 /* Communication class interface standard descriptor */
276 {
277 sizeof(USBInterfaceDescriptor),
278 USBGenericDescriptor_INTERFACE,
279 0, /* This is interface #0 */
280 0, /* This is alternate setting #0 for this interface */
281 3, /* Number of endpoints */
282 0xff, /* Descriptor Class: Vendor specific */
283 0, /* No subclass */
284 0, /* No l */
285 CARDEM_USIM1_INTF_STR
286 },
287 /* Bulk-OUT endpoint standard descriptor */
288 {
289 sizeof(USBEndpointDescriptor),
290 USBGenericDescriptor_ENDPOINT,
291 USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_OUT,
292 PHONE_DATAOUT),
293 USBEndpointDescriptor_BULK,
294 MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(PHONE_DATAOUT),
295 USBEndpointDescriptor_MAXBULKSIZE_FS),
296 0 /* Must be 0 for full-speed bulk endpoints */
297 },
298 /* Bulk-IN endpoint descriptor */
299 {
300 sizeof(USBEndpointDescriptor),
301 USBGenericDescriptor_ENDPOINT,
302 USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN,
303 PHONE_DATAIN),
304 USBEndpointDescriptor_BULK,
305 MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(PHONE_DATAIN),
306 USBEndpointDescriptor_MAXBULKSIZE_FS),
307 0 /* Must be 0 for full-speed bulk endpoints */
308 },
309 /* Notification endpoint descriptor */
310 {
311 sizeof(USBEndpointDescriptor),
312 USBGenericDescriptor_ENDPOINT,
313 USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN,
314 PHONE_INT),
315 USBEndpointDescriptor_INTERRUPT,
316 MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(PHONE_INT),
317 USBEndpointDescriptor_MAXINTERRUPTSIZE_FS),
318 0x10
319 },
Harald Welte57b3a252016-03-02 15:20:27 +0100320#ifdef CARDEMU_SECOND_UART
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100321 /* Communication class interface standard descriptor */
322 {
323 sizeof(USBInterfaceDescriptor),
324 USBGenericDescriptor_INTERFACE,
Harald Welte6dcacf32016-03-19 14:01:31 +0100325 1, /* This is interface #1 */
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100326 0, /* This is alternate setting #0 for this interface */
327 3, /* Number of endpoints */
328 0xff, /* Descriptor Class: Vendor specific */
329 0, /* No subclass */
330 0, /* No l */
331 CARDEM_USIM2_INTF_STR
332 },
333 /* Bulk-OUT endpoint standard descriptor */
334 {
335 sizeof(USBEndpointDescriptor),
336 USBGenericDescriptor_ENDPOINT,
337 USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_OUT,
338 CARDEM_USIM2_DATAOUT),
339 USBEndpointDescriptor_BULK,
340 MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CARDEM_USIM2_DATAOUT),
341 USBEndpointDescriptor_MAXBULKSIZE_FS),
342 0 /* Must be 0 for full-speed bulk endpoints */
343 }
344 ,
345 /* Bulk-IN endpoint descriptor */
346 {
347 sizeof(USBEndpointDescriptor),
348 USBGenericDescriptor_ENDPOINT,
349 USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN,
350 CARDEM_USIM2_DATAIN),
351 USBEndpointDescriptor_BULK,
352 MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CARDEM_USIM2_DATAIN),
353 USBEndpointDescriptor_MAXBULKSIZE_FS),
354 0 /* Must be 0 for full-speed bulk endpoints */
355 },
356 /* Notification endpoint descriptor */
357 {
358 sizeof(USBEndpointDescriptor),
359 USBGenericDescriptor_ENDPOINT,
360 USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN,
361 CARDEM_USIM2_INT),
362 USBEndpointDescriptor_INTERRUPT,
363 MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CARDEM_USIM2_INT),
364 USBEndpointDescriptor_MAXINTERRUPTSIZE_FS),
365 0x10
366 },
Harald Welte7ed6f3b2017-02-26 17:00:43 +0100367 DFURT_IF_DESCRIPTOR(2, 0),
368#else
369 DFURT_IF_DESCRIPTOR(1, 0),
Harald Welte57b3a252016-03-02 15:20:27 +0100370#endif
Christina Quast01bbdc32015-02-24 17:38:45 +0100371};
Harald Welte2fb59962016-02-28 12:34:26 +0100372#endif /* HAVE_CARDEM */
Christina Quast01bbdc32015-02-24 17:38:45 +0100373
Harald Welte2fb59962016-02-28 12:34:26 +0100374#ifdef HAVE_MITM
Christina Quastf5549502015-02-24 14:27:08 +0100375typedef struct _SIMTraceDriverConfigurationDescriptorMITM {
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100376 /* Standard configuration descriptor. */
377 USBConfigurationDescriptor configuration;
378 USBInterfaceDescriptor simcard;
379 /// CCID descriptor
380 CCIDDescriptor ccid;
381 /// Bulk OUT endpoint descriptor
382 USBEndpointDescriptor simcard_dataOut;
383 /// Bulk IN endpoint descriptor
384 USBEndpointDescriptor simcard_dataIn;
385 /// Interrupt OUT endpoint descriptor
386 USBEndpointDescriptor simcard_interruptIn;
Christina Quastf5549502015-02-24 14:27:08 +0100387
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100388 USBInterfaceDescriptor phone;
389 USBEndpointDescriptor phone_dataOut;
390 USBEndpointDescriptor phone_dataIn;
391 USBEndpointDescriptor phone_interruptIn;
Christina Quastf5549502015-02-24 14:27:08 +0100392
Harald Welte7ed6f3b2017-02-26 17:00:43 +0100393 DFURT_IF_DESCRIPTOR_STRUCT;
394
Christina Quast01bbdc32015-02-24 17:38:45 +0100395} __attribute__ ((packed)) SIMTraceDriverConfigurationDescriptorMITM;
Christina Quastf5549502015-02-24 14:27:08 +0100396
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100397static const SIMTraceDriverConfigurationDescriptorMITM
398 configurationDescriptorMITM = {
399 /* Standard configuration descriptor */
400 {
401 sizeof(USBConfigurationDescriptor),
402 USBGenericDescriptor_CONFIGURATION,
403 sizeof(SIMTraceDriverConfigurationDescriptorMITM),
Harald Welte7ed6f3b2017-02-26 17:00:43 +0100404 2+DFURT_NUM_IF, /* There are two interfaces in this configuration */
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100405 CFG_NUM_MITM, /* configuration number */
406 MITM_CONF_STR, /* string descriptor for this configuration */
407 USBD_BMATTRIBUTES,
408 USBConfigurationDescriptor_POWER(100)
409 },
410 // CCID interface descriptor
411 // Table 4.3-1 Interface Descriptor
412 // Interface descriptor
413 {
414 .bLength = sizeof(USBInterfaceDescriptor),
415 .bDescriptorType = USBGenericDescriptor_INTERFACE,
416 .bInterfaceNumber = 0,
417 .bAlternateSetting = 0,
418 .bNumEndpoints = 3,
419 .bInterfaceClass = SMART_CARD_DEVICE_CLASS,
420 .bInterfaceSubClass = 0,
421 .bInterfaceProtocol = 0,
422 .iInterface = CCID_CONF_STR,
423 },
424 {
425 .bLength = sizeof(CCIDDescriptor),
426 .bDescriptorType = CCID_DECRIPTOR_TYPE,
427 .bcdCCID = CCID1_10, // CCID version
428 .bMaxSlotIndex = 0, // 1 slot
429 .bVoltageSupport = VOLTS_3_0,
430 .dwProtocols = (1 << PROTOCOL_TO),
431 .dwDefaultClock = 3580,
432 .dwMaximumClock = 3580,
433 .bNumClockSupported = 0,
434 .dwDataRate = 9600,
435 .dwMaxDataRate = 9600,
436 .bNumDataRatesSupported = 0,
437 .dwMaxIFSD = 0xfe,
438 .dwSynchProtocols = 0,
439 .dwMechanical = 0,
440 .dwFeatures = CCID_FEATURES_AUTO_CLOCK | CCID_FEATURES_AUTO_BAUD |
441 CCID_FEATURES_AUTO_PCONF | CCID_FEATURES_AUTO_PNEGO |
442 CCID_FEATURES_EXC_TPDU,
443 .dwMaxCCIDMessageLength = 271, /* For extended APDU
444 level the value shall
445 be between 261 + 10 */
446 .bClassGetResponse = 0xFF, // Echoes the class of the APDU
447 .bClassEnvelope = 0xFF, // Echoes the class of the APDU
448 .wLcdLayout = 0, // wLcdLayout: no LCD
449 .bPINSupport = 0, // bPINSupport: No PIN
450 .bMaxCCIDBusySlots = 1,
451 },
452 // Bulk-OUT endpoint descriptor
453 {
454 .bLength = sizeof(USBEndpointDescriptor),
455 .bDescriptorType = USBGenericDescriptor_ENDPOINT,
456 .bEndpointAddress =
457 USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_OUT,
458 CCID_EPT_DATA_OUT),
459 .bmAttributes = USBEndpointDescriptor_BULK,
460 .wMaxPacketSize = MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(
461 CCID_EPT_DATA_OUT),
462 USBEndpointDescriptor_MAXBULKSIZE_FS),
463 .bInterval = 0x00,
464 },
465 // Bulk-IN endpoint descriptor
466 {
467 .bLength = sizeof(USBEndpointDescriptor),
468 .bDescriptorType = USBGenericDescriptor_ENDPOINT,
469 .bEndpointAddress =
470 USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN,
471 CCID_EPT_DATA_IN),
472 .bmAttributes = USBEndpointDescriptor_BULK,
473 .wMaxPacketSize = MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(
474 CCID_EPT_DATA_IN),
475 USBEndpointDescriptor_MAXBULKSIZE_FS),
476 .bInterval = 0x00,
477 },
478 // Notification endpoint descriptor
479 {
480 .bLength = sizeof(USBEndpointDescriptor),
481 .bDescriptorType = USBGenericDescriptor_ENDPOINT,
482 .bEndpointAddress =
483 USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN,
484 CCID_EPT_NOTIFICATION),
485 .bmAttributes = USBEndpointDescriptor_INTERRUPT,
486 .wMaxPacketSize = MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(
487 CCID_EPT_NOTIFICATION),
488 USBEndpointDescriptor_MAXINTERRUPTSIZE_FS),
489 .bInterval = 0x10,
490 },
491
492 /* Communication class interface standard descriptor */
493 {
494 sizeof(USBInterfaceDescriptor),
495 USBGenericDescriptor_INTERFACE,
496 1, /* This is interface #1 */
497 0, /* This is alternate setting #0 for this interface */
498 3, /* Number of endpoints */
499 0xff,
500 0,
501 0,
502 PHONE_CONF_STR, /* string descriptor for this interface */
503 }
504 ,
505 /* Bulk-OUT endpoint standard descriptor */
506 {
507 sizeof(USBEndpointDescriptor),
508 USBGenericDescriptor_ENDPOINT,
509 USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_OUT,
510 PHONE_DATAOUT),
511 USBEndpointDescriptor_BULK,
512 MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(PHONE_DATAOUT),
513 USBEndpointDescriptor_MAXBULKSIZE_FS),
514 0 /* Must be 0 for full-speed bulk endpoints */
515 }
516 ,
517 /* Bulk-IN endpoint descriptor */
518 {
519 sizeof(USBEndpointDescriptor),
520 USBGenericDescriptor_ENDPOINT,
521 USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN,
522 PHONE_DATAIN),
523 USBEndpointDescriptor_BULK,
524 MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(PHONE_DATAIN),
525 USBEndpointDescriptor_MAXBULKSIZE_FS),
526 0 /* Must be 0 for full-speed bulk endpoints */
527 }
528 ,
529 /* Notification endpoint descriptor */
530 {
531 sizeof(USBEndpointDescriptor),
532 USBGenericDescriptor_ENDPOINT,
533 USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN, PHONE_INT),
534 USBEndpointDescriptor_INTERRUPT,
535 MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(PHONE_INT),
536 USBEndpointDescriptor_MAXINTERRUPTSIZE_FS),
Harald Welte7ed6f3b2017-02-26 17:00:43 +0100537 0x10},
538 DFURT_IF_DESCRIPTOR(2, 0),
Christina Quastf5549502015-02-24 14:27:08 +0100539};
Harald Welte2fb59962016-02-28 12:34:26 +0100540#endif /* HAVE_CARDEM */
541
542const USBConfigurationDescriptor *configurationDescriptorsArr[] = {
543#ifdef HAVE_SNIFFER
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100544 &configurationDescriptorSniffer.configuration,
Harald Welte2fb59962016-02-28 12:34:26 +0100545#endif
546#ifdef HAVE_CCID
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100547 &configurationDescriptorCCID.configuration,
Harald Welte2fb59962016-02-28 12:34:26 +0100548#endif
549#ifdef HAVE_CARDEM
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100550 &configurationDescriptorPhone.configuration,
Harald Welte2fb59962016-02-28 12:34:26 +0100551#endif
552#ifdef HAVE_MITM
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100553 &configurationDescriptorMITM.configuration,
Harald Welte2fb59962016-02-28 12:34:26 +0100554#endif
555};
Christina Quastf5549502015-02-24 14:27:08 +0100556
Christina Quastf5549502015-02-24 14:27:08 +0100557/** Standard USB device descriptor for the CDC serial driver */
558const USBDeviceDescriptor deviceDescriptor = {
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100559 .bLength = sizeof(USBDeviceDescriptor),
560 .bDescriptorType = USBGenericDescriptor_DEVICE,
561 .bcdUSB = USBDeviceDescriptor_USB2_00,
562 .bDeviceClass = 0xff,
563 .bDeviceSubClass = 0xff,
564 .bDeviceProtocol = 0xff,
565 .bMaxPacketSize0 = BOARD_USB_ENDPOINTS_MAXPACKETSIZE(0),
566 .idVendor = SIMTRACE_VENDOR_ID,
567 .idProduct = SIMTRACE_PRODUCT_ID,
568 .bcdDevice = 2, /* Release number */
569 .iManufacturer = MANUF_STR,
570 .iProduct = PRODUCT_STRING,
571 .iSerialNumber = 0,
572 .bNumConfigurations = ARRAY_SIZE(configurationDescriptorsArr),
Christina Quast01bbdc32015-02-24 17:38:45 +0100573};
574
Christina Quastbd5b8bd2015-05-14 17:25:41 +0200575/* AT91SAM3S only supports full speed, but not high speed USB */
Harald Welteec4fe232015-11-07 18:41:25 +0100576static const USBDDriverDescriptors driverDescriptors = {
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100577 &deviceDescriptor,
578 (const USBConfigurationDescriptor **)&(configurationDescriptorsArr), /* first full-speed configuration descriptor */
579 0, /* No full-speed device qualifier descriptor */
580 0, /* No full-speed other speed configuration */
581 0, /* No high-speed device descriptor */
582 0, /* No high-speed configuration descriptor */
583 0, /* No high-speed device qualifier descriptor */
584 0, /* No high-speed other speed configuration descriptor */
Harald Welte2363fa02017-03-05 10:16:25 +0100585 usb_strings,
586 ARRAY_SIZE(usb_strings),/* cnt string descriptors in list */
Christina Quastf5549502015-02-24 14:27:08 +0100587};
588
Christina Quast0ae03142015-02-25 18:43:46 +0100589/*----------------------------------------------------------------------------
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100590 * Functions
Christina Quast968b9742015-02-25 14:10:12 +0100591 *----------------------------------------------------------------------------*/
592
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100593void SIMtrace_USB_Initialize(void)
Christina Quast968b9742015-02-25 14:10:12 +0100594{
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100595 // Get std USB driver
596 USBDDriver *pUsbd = USBD_GetDriver();
Christina Quast968b9742015-02-25 14:10:12 +0100597
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100598 TRACE_DEBUG(".");
Christina Quast968b9742015-02-25 14:10:12 +0100599
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100600 // Initialize standard USB driver
601 USBDDriver_Initialize(pUsbd, &driverDescriptors, 0); // Multiple interface settings not supported
602 USBD_Init();
603 USBD_Connect();
Christina Quast968b9742015-02-25 14:10:12 +0100604
Harald Welte7dd3dfd2016-03-03 12:32:04 +0100605 NVIC_EnableIRQ(UDP_IRQn);
Christina Quast968b9742015-02-25 14:10:12 +0100606}