blob: 6b57b1b5d979ce27483b91c57be48d9cdc2f639d [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 Welte2fb59962016-02-28 12:34:26 +010035#include "utils.h"
Christina Quast968b9742015-02-25 14:10:12 +010036
Christina Quastdb7b1ab2015-03-03 12:34:36 +010037#include <cciddriverdescriptors.h>
38
Christina Quastf5549502015-02-24 14:27:08 +010039/*------------------------------------------------------------------------------
40 * USB String descriptors
41 *------------------------------------------------------------------------------*/
42
Christina Quast6032e792015-02-27 15:22:25 +010043
44static const unsigned char langDesc[] = {
45
46 USBStringDescriptor_LENGTH(1),
47 USBGenericDescriptor_STRING,
48 USBStringDescriptor_ENGLISH_US
49};
50
Harald Welte6d44c1f2015-11-07 19:01:30 +010051const unsigned char manufStringDescriptor[] = {
52
53 USBStringDescriptor_LENGTH(24),
54 USBGenericDescriptor_STRING,
55 USBStringDescriptor_UNICODE('s'),
56 USBStringDescriptor_UNICODE('y'),
57 USBStringDescriptor_UNICODE('s'),
58 USBStringDescriptor_UNICODE('m'),
59 USBStringDescriptor_UNICODE('o'),
60 USBStringDescriptor_UNICODE('c'),
61 USBStringDescriptor_UNICODE('o'),
62 USBStringDescriptor_UNICODE('m'),
63 USBStringDescriptor_UNICODE(' '),
64 USBStringDescriptor_UNICODE('-'),
65 USBStringDescriptor_UNICODE(' '),
66 USBStringDescriptor_UNICODE('s'),
67 USBStringDescriptor_UNICODE('.'),
68 USBStringDescriptor_UNICODE('f'),
69 USBStringDescriptor_UNICODE('.'),
70 USBStringDescriptor_UNICODE('m'),
71 USBStringDescriptor_UNICODE('.'),
72 USBStringDescriptor_UNICODE('c'),
73 USBStringDescriptor_UNICODE('.'),
74 USBStringDescriptor_UNICODE(' '),
75 USBStringDescriptor_UNICODE('G'),
76 USBStringDescriptor_UNICODE('m'),
77 USBStringDescriptor_UNICODE('b'),
78 USBStringDescriptor_UNICODE('H'),
79};
80
Christina Quastf5549502015-02-24 14:27:08 +010081const unsigned char productStringDescriptor[] = {
82
Harald Weltebeb72932015-11-07 18:35:41 +010083 USBStringDescriptor_LENGTH(10),
Christina Quastf5549502015-02-24 14:27:08 +010084 USBGenericDescriptor_STRING,
85 USBStringDescriptor_UNICODE('S'),
86 USBStringDescriptor_UNICODE('I'),
87 USBStringDescriptor_UNICODE('M'),
88 USBStringDescriptor_UNICODE('t'),
89 USBStringDescriptor_UNICODE('r'),
90 USBStringDescriptor_UNICODE('a'),
91 USBStringDescriptor_UNICODE('c'),
92 USBStringDescriptor_UNICODE('e'),
Harald Weltebeb72932015-11-07 18:35:41 +010093 USBStringDescriptor_UNICODE(' '),
94 USBStringDescriptor_UNICODE('2'),
Christina Quastf5549502015-02-24 14:27:08 +010095};
96
97const unsigned char snifferConfigStringDescriptor[] = {
98
Harald Weltebeb72932015-11-07 18:35:41 +010099 USBStringDescriptor_LENGTH(16),
Christina Quastf5549502015-02-24 14:27:08 +0100100 USBGenericDescriptor_STRING,
101 USBStringDescriptor_UNICODE('S'),
102 USBStringDescriptor_UNICODE('I'),
103 USBStringDescriptor_UNICODE('M'),
104 USBStringDescriptor_UNICODE('t'),
105 USBStringDescriptor_UNICODE('r'),
106 USBStringDescriptor_UNICODE('a'),
107 USBStringDescriptor_UNICODE('c'),
108 USBStringDescriptor_UNICODE('e'),
Harald Weltebeb72932015-11-07 18:35:41 +0100109 USBStringDescriptor_UNICODE(' '),
Christina Quastf5549502015-02-24 14:27:08 +0100110 USBStringDescriptor_UNICODE('S'),
111 USBStringDescriptor_UNICODE('n'),
112 USBStringDescriptor_UNICODE('i'),
113 USBStringDescriptor_UNICODE('f'),
114 USBStringDescriptor_UNICODE('f'),
115 USBStringDescriptor_UNICODE('e'),
116 USBStringDescriptor_UNICODE('r'),
117};
118
119const unsigned char CCIDConfigStringDescriptor[] = {
120
Harald Weltebeb72932015-11-07 18:35:41 +0100121 USBStringDescriptor_LENGTH(13),
Christina Quastf5549502015-02-24 14:27:08 +0100122 USBGenericDescriptor_STRING,
123 USBStringDescriptor_UNICODE('S'),
124 USBStringDescriptor_UNICODE('I'),
125 USBStringDescriptor_UNICODE('M'),
126 USBStringDescriptor_UNICODE('t'),
127 USBStringDescriptor_UNICODE('r'),
128 USBStringDescriptor_UNICODE('a'),
129 USBStringDescriptor_UNICODE('c'),
130 USBStringDescriptor_UNICODE('e'),
Harald Weltebeb72932015-11-07 18:35:41 +0100131 USBStringDescriptor_UNICODE(' '),
Christina Quastf5549502015-02-24 14:27:08 +0100132 USBStringDescriptor_UNICODE('C'),
133 USBStringDescriptor_UNICODE('C'),
134 USBStringDescriptor_UNICODE('I'),
135 USBStringDescriptor_UNICODE('D'),
136};
137
138const unsigned char phoneConfigStringDescriptor[] = {
139
Harald Weltebeb72932015-11-07 18:35:41 +0100140 USBStringDescriptor_LENGTH(14),
141 USBGenericDescriptor_STRING,
142 USBStringDescriptor_UNICODE('S'),
143 USBStringDescriptor_UNICODE('I'),
144 USBStringDescriptor_UNICODE('M'),
145 USBStringDescriptor_UNICODE('t'),
146 USBStringDescriptor_UNICODE('r'),
147 USBStringDescriptor_UNICODE('a'),
148 USBStringDescriptor_UNICODE('c'),
149 USBStringDescriptor_UNICODE('e'),
150 USBStringDescriptor_UNICODE(' '),
151 USBStringDescriptor_UNICODE('P'),
152 USBStringDescriptor_UNICODE('h'),
153 USBStringDescriptor_UNICODE('o'),
154 USBStringDescriptor_UNICODE('n'),
155 USBStringDescriptor_UNICODE('e'),
156};
157
158
159const unsigned char MITMConfigStringDescriptor[] = {
160
Christina Quastf5549502015-02-24 14:27:08 +0100161 USBStringDescriptor_LENGTH(13),
162 USBGenericDescriptor_STRING,
163 USBStringDescriptor_UNICODE('S'),
164 USBStringDescriptor_UNICODE('I'),
165 USBStringDescriptor_UNICODE('M'),
166 USBStringDescriptor_UNICODE('t'),
167 USBStringDescriptor_UNICODE('r'),
168 USBStringDescriptor_UNICODE('a'),
169 USBStringDescriptor_UNICODE('c'),
170 USBStringDescriptor_UNICODE('e'),
Harald Weltebeb72932015-11-07 18:35:41 +0100171 USBStringDescriptor_UNICODE(' '),
Christina Quastf5549502015-02-24 14:27:08 +0100172 USBStringDescriptor_UNICODE('M'),
173 USBStringDescriptor_UNICODE('I'),
174 USBStringDescriptor_UNICODE('T'),
175 USBStringDescriptor_UNICODE('M'),
176};
177
Harald Welte57b3a252016-03-02 15:20:27 +0100178const unsigned char cardem_usim1_intf_str[] = {
179
180 USBStringDescriptor_LENGTH(18),
181 USBGenericDescriptor_STRING,
182 USBStringDescriptor_UNICODE('C'),
183 USBStringDescriptor_UNICODE('a'),
184 USBStringDescriptor_UNICODE('r'),
185 USBStringDescriptor_UNICODE('d'),
186 USBStringDescriptor_UNICODE('E'),
187 USBStringDescriptor_UNICODE('m'),
188 USBStringDescriptor_UNICODE('u'),
189 USBStringDescriptor_UNICODE('l'),
190 USBStringDescriptor_UNICODE('a'),
191 USBStringDescriptor_UNICODE('t'),
192 USBStringDescriptor_UNICODE('o'),
193 USBStringDescriptor_UNICODE('r'),
194 USBStringDescriptor_UNICODE(' '),
195 USBStringDescriptor_UNICODE('U'),
196 USBStringDescriptor_UNICODE('S'),
197 USBStringDescriptor_UNICODE('I'),
198 USBStringDescriptor_UNICODE('M'),
199 USBStringDescriptor_UNICODE('1'),
200};
201
202const unsigned char cardem_usim2_intf_str[] = {
203
204 USBStringDescriptor_LENGTH(18),
205 USBGenericDescriptor_STRING,
206 USBStringDescriptor_UNICODE('C'),
207 USBStringDescriptor_UNICODE('a'),
208 USBStringDescriptor_UNICODE('r'),
209 USBStringDescriptor_UNICODE('d'),
210 USBStringDescriptor_UNICODE('E'),
211 USBStringDescriptor_UNICODE('m'),
212 USBStringDescriptor_UNICODE('u'),
213 USBStringDescriptor_UNICODE('l'),
214 USBStringDescriptor_UNICODE('a'),
215 USBStringDescriptor_UNICODE('t'),
216 USBStringDescriptor_UNICODE('o'),
217 USBStringDescriptor_UNICODE('r'),
218 USBStringDescriptor_UNICODE(' '),
219 USBStringDescriptor_UNICODE('U'),
220 USBStringDescriptor_UNICODE('S'),
221 USBStringDescriptor_UNICODE('I'),
222 USBStringDescriptor_UNICODE('M'),
223 USBStringDescriptor_UNICODE('2'),
224};
225
Christina Quastf5549502015-02-24 14:27:08 +0100226enum strDescNum {
Harald Welte57b3a252016-03-02 15:20:27 +0100227 PRODUCT_STRING = 1, MANUF_STR, SNIFFER_CONF_STR, CCID_CONF_STR, PHONE_CONF_STR, MITM_CONF_STR,
228 CARDEM_USIM1_INTF_STR, CARDEM_USIM2_INTF_STR, STRING_DESC_CNT
Christina Quastf5549502015-02-24 14:27:08 +0100229};
230
231/** List of string descriptors used by the device */
Harald Welteec4fe232015-11-07 18:41:25 +0100232static const unsigned char *stringDescriptors[] = {
Christina Quast6032e792015-02-27 15:22:25 +0100233 langDesc,
Harald Welte6d44c1f2015-11-07 19:01:30 +0100234 [PRODUCT_STRING] = productStringDescriptor,
235 [MANUF_STR] = manufStringDescriptor,
236 [SNIFFER_CONF_STR] = snifferConfigStringDescriptor,
237 [CCID_CONF_STR] = CCIDConfigStringDescriptor,
238 [PHONE_CONF_STR] = phoneConfigStringDescriptor,
Harald Welte57b3a252016-03-02 15:20:27 +0100239 [MITM_CONF_STR] = MITMConfigStringDescriptor,
240 [CARDEM_USIM1_INTF_STR] = cardem_usim1_intf_str,
241 [CARDEM_USIM2_INTF_STR] = cardem_usim2_intf_str,
Christina Quastf5549502015-02-24 14:27:08 +0100242};
243
Christina Quastf5549502015-02-24 14:27:08 +0100244/*------------------------------------------------------------------------------
245 * USB Device descriptors
246 *------------------------------------------------------------------------------*/
247
Harald Welte2fb59962016-02-28 12:34:26 +0100248#ifdef HAVE_SNIFFER
Christina Quastf5549502015-02-24 14:27:08 +0100249typedef struct _SIMTraceDriverConfigurationDescriptorSniffer {
250
251 /** Standard configuration descriptor. */
Christina Quastda373fd2015-02-27 15:25:22 +0100252 USBConfigurationDescriptor configuration;
253 USBInterfaceDescriptor sniffer;
254 USBEndpointDescriptor sniffer_dataOut;
255 USBEndpointDescriptor sniffer_dataIn;
256 USBEndpointDescriptor sniffer_interruptIn;
Christina Quastf5549502015-02-24 14:27:08 +0100257
Christina Quast01bbdc32015-02-24 17:38:45 +0100258} __attribute__ ((packed)) SIMTraceDriverConfigurationDescriptorSniffer;
Christina Quastf5549502015-02-24 14:27:08 +0100259
Harald Welteec4fe232015-11-07 18:41:25 +0100260static const SIMTraceDriverConfigurationDescriptorSniffer configurationDescriptorSniffer = {
Christina Quastf5549502015-02-24 14:27:08 +0100261 /* Standard configuration descriptor */
262 {
263 sizeof(USBConfigurationDescriptor),
264 USBGenericDescriptor_CONFIGURATION,
265 sizeof(SIMTraceDriverConfigurationDescriptorSniffer),
266 1, /* There is one interface in this configuration */
Christina Quast10b2e5a2015-02-25 18:40:15 +0100267 CFG_NUM_SNIFF, /* configuration number */
Christina Quastf5549502015-02-24 14:27:08 +0100268 SNIFFER_CONF_STR, /* string descriptor for this configuration */
269 USBD_BMATTRIBUTES,
270 USBConfigurationDescriptor_POWER(100)
271 },
272 /* Communication class interface standard descriptor */
273 {
274 sizeof(USBInterfaceDescriptor),
275 USBGenericDescriptor_INTERFACE,
276 0, /* This is interface #0 */
277 0, /* This is alternate setting #0 for this interface */
Christina Quast99d80ff2015-04-03 22:26:07 +0200278 3, /* Number of endpoints */
Christina Quastf5549502015-02-24 14:27:08 +0100279 0xff, /* Descriptor Class: Vendor specific */
280 0, /* No subclass */
281 0, /* No l */
282 SNIFFER_CONF_STR /* Third in string descriptor for this interface */
283 },
284 /* Bulk-OUT endpoint standard descriptor */
Christina Quastf5549502015-02-24 14:27:08 +0100285 {
286 sizeof(USBEndpointDescriptor),
287 USBGenericDescriptor_ENDPOINT,
288 USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_OUT,
Christina Quast2b8a18b2015-04-12 09:31:36 +0200289 PHONE_DATAOUT),
Christina Quastf5549502015-02-24 14:27:08 +0100290 USBEndpointDescriptor_BULK,
Christina Quast2b8a18b2015-04-12 09:31:36 +0200291 MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(PHONE_DATAOUT),
Christina Quastf5549502015-02-24 14:27:08 +0100292 USBEndpointDescriptor_MAXBULKSIZE_FS),
293 0 /* Must be 0 for full-speed bulk endpoints */
294 },
295 /* Bulk-IN endpoint descriptor */
Christina Quastf5549502015-02-24 14:27:08 +0100296 {
297 sizeof(USBEndpointDescriptor),
298 USBGenericDescriptor_ENDPOINT,
299 USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN,
Christina Quast2b8a18b2015-04-12 09:31:36 +0200300 PHONE_DATAIN),
Christina Quastf5549502015-02-24 14:27:08 +0100301 USBEndpointDescriptor_BULK,
Christina Quast2b8a18b2015-04-12 09:31:36 +0200302 MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(PHONE_DATAIN),
Christina Quastf5549502015-02-24 14:27:08 +0100303 USBEndpointDescriptor_MAXBULKSIZE_FS),
304 0 /* Must be 0 for full-speed bulk endpoints */
Christina Quastda373fd2015-02-27 15:25:22 +0100305 },
306 // Notification endpoint descriptor
307 {
308 sizeof(USBEndpointDescriptor),
309 USBGenericDescriptor_ENDPOINT,
Christina Quast2b8a18b2015-04-12 09:31:36 +0200310 USBEndpointDescriptor_ADDRESS( USBEndpointDescriptor_IN, PHONE_INT ),
Christina Quastda373fd2015-02-27 15:25:22 +0100311 USBEndpointDescriptor_INTERRUPT,
Christina Quast2b8a18b2015-04-12 09:31:36 +0200312 MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(PHONE_INT),
Christina Quastda373fd2015-02-27 15:25:22 +0100313 USBEndpointDescriptor_MAXINTERRUPTSIZE_FS),
314 0x10
Christina Quastf5549502015-02-24 14:27:08 +0100315 }
316};
Harald Welte2fb59962016-02-28 12:34:26 +0100317#endif /* HAVE_SNIFFER */
Christina Quastf5549502015-02-24 14:27:08 +0100318
Harald Welte2fb59962016-02-28 12:34:26 +0100319
320#ifdef HAVE_CCID
Christina Quastdb7b1ab2015-03-03 12:34:36 +0100321/*
322/// CCIDDriverConfiguration Descriptors
323/// List of descriptors that make up the configuration descriptors of a
324/// device using the CCID driver.
Christina Quast01bbdc32015-02-24 17:38:45 +0100325typedef struct {
326
Christina Quastdb7b1ab2015-03-03 12:34:36 +0100327 /// Configuration descriptor
Christina Quast01bbdc32015-02-24 17:38:45 +0100328 USBConfigurationDescriptor configuration;
Christina Quastdb7b1ab2015-03-03 12:34:36 +0100329 /// Interface descriptor
Christina Quast01bbdc32015-02-24 17:38:45 +0100330 USBInterfaceDescriptor interface;
Christina Quastdb7b1ab2015-03-03 12:34:36 +0100331 /// CCID descriptor
Christina Quast01bbdc32015-02-24 17:38:45 +0100332 CCIDDescriptor ccid;
Christina Quastdb7b1ab2015-03-03 12:34:36 +0100333 /// Bulk OUT endpoint descriptor
Christina Quast01bbdc32015-02-24 17:38:45 +0100334 USBEndpointDescriptor bulkOut;
Christina Quastdb7b1ab2015-03-03 12:34:36 +0100335 /// Bulk IN endpoint descriptor
Christina Quast01bbdc32015-02-24 17:38:45 +0100336 USBEndpointDescriptor bulkIn;
Christina Quastdb7b1ab2015-03-03 12:34:36 +0100337 /// Interrupt OUT endpoint descriptor
Christina Quast01bbdc32015-02-24 17:38:45 +0100338 USBEndpointDescriptor interruptIn;
Christina Quastdb7b1ab2015-03-03 12:34:36 +0100339} __attribute__ ((packed)) CCIDDriverConfigurationDescriptors;
340*/
Christina Quast01bbdc32015-02-24 17:38:45 +0100341
Harald Welteec4fe232015-11-07 18:41:25 +0100342static const CCIDDriverConfigurationDescriptors configurationDescriptorCCID = {
Christina Quastdb7b1ab2015-03-03 12:34:36 +0100343
344 // Standard USB configuration descriptor
345 {
346 sizeof(USBConfigurationDescriptor),
347 USBGenericDescriptor_CONFIGURATION,
348 sizeof(CCIDDriverConfigurationDescriptors),
349 1, // One interface in this configuration
350 CFG_NUM_CCID, // This is configuration #1
351 CCID_CONF_STR, // associated string descriptor
352 BOARD_USB_BMATTRIBUTES,
353 USBConfigurationDescriptor_POWER(100)
354 },
355 // CCID interface descriptor
356 // Table 4.3-1 Interface Descriptor
357 // Interface descriptor
358 {
359 sizeof(USBInterfaceDescriptor),
360 USBGenericDescriptor_INTERFACE,
361 0, // Interface 0
362 0, // No alternate settings
363 3, // uses bulk-IN, bulk-OUT and interrupt IN
364 SMART_CARD_DEVICE_CLASS,
365 0, // Subclass code
366 0, // bulk transfers optional interrupt-IN
367 CCID_CONF_STR // associated string descriptor
368 },
369 {
370 sizeof(CCIDDescriptor), // bLength: Size of this descriptor in bytes
371 CCID_DECRIPTOR_TYPE, // bDescriptorType:Functional descriptor type
372 CCID1_10, // bcdCCID: CCID version
373 0, // bMaxSlotIndex: Value 0 indicates that one slot is supported
Harald Welte8a5b5802015-11-07 18:52:52 +0100374 VOLTS_3_0, // bVoltageSupport
Christina Quastdb7b1ab2015-03-03 12:34:36 +0100375 (1 << PROTOCOL_TO), // dwProtocols
376 3580, // dwDefaultClock
377 3580, // dwMaxClock
378 0, // bNumClockSupported
379 9600, // dwDataRate : 9600 bauds
380 9600, // dwMaxDataRate : 9600 bauds
381 0, // bNumDataRatesSupported
382 0xfe, // dwMaxIFSD
383 0, // dwSynchProtocols
384 0, // dwMechanical
385 //0x00010042, // dwFeatures: Short APDU level exchanges
386 CCID_FEATURES_AUTO_CLOCK | CCID_FEATURES_AUTO_BAUD |
387 CCID_FEATURES_AUTO_PCONF | CCID_FEATURES_AUTO_PNEGO | CCID_FEATURES_EXC_TPDU,
388 0x0000010F, // dwMaxCCIDMessageLength: For extended APDU level the value shall be between 261 + 10
389 0xFF, // bClassGetResponse: Echoes the class of the APDU
390 0xFF, // bClassEnvelope: Echoes the class of the APDU
391 0, // wLcdLayout: no LCD
392 0, // bPINSupport: No PIN
393 1 // bMaxCCIDBusySlot
394 },
395 // Bulk-OUT endpoint descriptor
396 {
397 sizeof(USBEndpointDescriptor),
398 USBGenericDescriptor_ENDPOINT,
399 USBEndpointDescriptor_ADDRESS( USBEndpointDescriptor_OUT, CCID_EPT_DATA_OUT ),
400 USBEndpointDescriptor_BULK,
401 MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CCID_EPT_DATA_OUT),
402 USBEndpointDescriptor_MAXBULKSIZE_FS),
403 0x00 // Does not apply to Bulk endpoints
404 },
405 // Bulk-IN endpoint descriptor
406 {
407 sizeof(USBEndpointDescriptor),
408 USBGenericDescriptor_ENDPOINT,
409 USBEndpointDescriptor_ADDRESS( USBEndpointDescriptor_IN, CCID_EPT_DATA_IN ),
410 USBEndpointDescriptor_BULK,
411 MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CCID_EPT_DATA_IN),
412 USBEndpointDescriptor_MAXBULKSIZE_FS),
413 0x00 // Does not apply to Bulk endpoints
414 },
415 // Notification endpoint descriptor
416 {
417 sizeof(USBEndpointDescriptor),
418 USBGenericDescriptor_ENDPOINT,
419 USBEndpointDescriptor_ADDRESS( USBEndpointDescriptor_IN, CCID_EPT_NOTIFICATION ),
420 USBEndpointDescriptor_INTERRUPT,
421 MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CCID_EPT_NOTIFICATION),
422 USBEndpointDescriptor_MAXINTERRUPTSIZE_FS),
423 0x10
424 },
425};
Harald Welte2fb59962016-02-28 12:34:26 +0100426#endif /* HAVE_CCID */
Christina Quastdb7b1ab2015-03-03 12:34:36 +0100427
Christina Quast01bbdc32015-02-24 17:38:45 +0100428
Harald Welte2fb59962016-02-28 12:34:26 +0100429#ifdef HAVE_CARDEM
Christina Quast01bbdc32015-02-24 17:38:45 +0100430/* SIM card emulator */
431typedef struct _SIMTraceDriverConfigurationDescriptorPhone {
432
433 /** Standard configuration descriptor. */
Christina Quastda373fd2015-02-27 15:25:22 +0100434 USBConfigurationDescriptor configuration;
435 USBInterfaceDescriptor phone;
436 USBEndpointDescriptor phone_dataOut;
437 USBEndpointDescriptor phone_dataIn;
438 USBEndpointDescriptor phone_interruptIn;
Harald Welte57b3a252016-03-02 15:20:27 +0100439#ifdef CARDEMU_SECOND_UART
440 USBInterfaceDescriptor usim2;
441 USBEndpointDescriptor usim2_dataOut;
442 USBEndpointDescriptor usim2_dataIn;
443 USBEndpointDescriptor usim2_interruptIn;
444#endif
Christina Quast01bbdc32015-02-24 17:38:45 +0100445} __attribute__ ((packed)) SIMTraceDriverConfigurationDescriptorPhone;
446
Harald Welteec4fe232015-11-07 18:41:25 +0100447static const SIMTraceDriverConfigurationDescriptorPhone configurationDescriptorPhone = {
Christina Quast01bbdc32015-02-24 17:38:45 +0100448 /* Standard configuration descriptor */
449 {
450 sizeof(USBConfigurationDescriptor),
451 USBGenericDescriptor_CONFIGURATION,
Christina Quast6d9dcfc2015-04-03 22:26:43 +0200452 sizeof(SIMTraceDriverConfigurationDescriptorPhone),
Harald Welte57b3a252016-03-02 15:20:27 +0100453#ifdef CARDEMU_SECOND_UART
454 2,
455#else
Christina Quast01bbdc32015-02-24 17:38:45 +0100456 1, /* There is one interface in this configuration */
Harald Welte57b3a252016-03-02 15:20:27 +0100457#endif
Christina Quast10b2e5a2015-02-25 18:40:15 +0100458 CFG_NUM_PHONE, /* configuration number */
Christina Quast01bbdc32015-02-24 17:38:45 +0100459 PHONE_CONF_STR, /* string descriptor for this configuration */
460 USBD_BMATTRIBUTES,
461 USBConfigurationDescriptor_POWER(100)
462 },
463 /* Communication class interface standard descriptor */
464 {
465 sizeof(USBInterfaceDescriptor),
466 USBGenericDescriptor_INTERFACE,
467 0, /* This is interface #0 */
468 0, /* This is alternate setting #0 for this interface */
Christina Quastb65b8812015-04-04 10:51:37 +0200469 3, /* Number of endpoints */
Christina Quast01bbdc32015-02-24 17:38:45 +0100470 0xff, /* Descriptor Class: Vendor specific */
471 0, /* No subclass */
472 0, /* No l */
Harald Welte57b3a252016-03-02 15:20:27 +0100473 CARDEM_USIM1_INTF_STR
Christina Quast01bbdc32015-02-24 17:38:45 +0100474 },
475 /* Bulk-OUT endpoint standard descriptor */
476 {
477 sizeof(USBEndpointDescriptor),
478 USBGenericDescriptor_ENDPOINT,
479 USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_OUT,
Christina Quast71234252015-04-03 11:35:59 +0200480 PHONE_DATAOUT),
Christina Quast01bbdc32015-02-24 17:38:45 +0100481 USBEndpointDescriptor_BULK,
Christina Quast71234252015-04-03 11:35:59 +0200482 MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(PHONE_DATAOUT),
Christina Quast01bbdc32015-02-24 17:38:45 +0100483 USBEndpointDescriptor_MAXBULKSIZE_FS),
484 0 /* Must be 0 for full-speed bulk endpoints */
485 },
486 /* Bulk-IN endpoint descriptor */
487 {
488 sizeof(USBEndpointDescriptor),
489 USBGenericDescriptor_ENDPOINT,
490 USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN,
Christina Quast71234252015-04-03 11:35:59 +0200491 PHONE_DATAIN),
Christina Quast01bbdc32015-02-24 17:38:45 +0100492 USBEndpointDescriptor_BULK,
Christina Quast71234252015-04-03 11:35:59 +0200493 MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(PHONE_DATAIN),
Christina Quast01bbdc32015-02-24 17:38:45 +0100494 USBEndpointDescriptor_MAXBULKSIZE_FS),
495 0 /* Must be 0 for full-speed bulk endpoints */
Christina Quastda373fd2015-02-27 15:25:22 +0100496 },
497 /* Notification endpoint descriptor */
498 {
499 sizeof(USBEndpointDescriptor),
500 USBGenericDescriptor_ENDPOINT,
Christina Quast71234252015-04-03 11:35:59 +0200501 USBEndpointDescriptor_ADDRESS( USBEndpointDescriptor_IN, PHONE_INT ),
Christina Quastda373fd2015-02-27 15:25:22 +0100502 USBEndpointDescriptor_INTERRUPT,
Christina Quast71234252015-04-03 11:35:59 +0200503 MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(PHONE_INT),
Christina Quastda373fd2015-02-27 15:25:22 +0100504 USBEndpointDescriptor_MAXINTERRUPTSIZE_FS),
505 0x10
Harald Welte57b3a252016-03-02 15:20:27 +0100506 },
507#ifdef CARDEMU_SECOND_UART
508 /* Communication class interface standard descriptor */
509 {
510 sizeof(USBInterfaceDescriptor),
511 USBGenericDescriptor_INTERFACE,
512 1, /* This is interface #0 */
513 0, /* This is alternate setting #0 for this interface */
514 3, /* Number of endpoints */
515 0xff, /* Descriptor Class: Vendor specific */
516 0, /* No subclass */
517 0, /* No l */
518 CARDEM_USIM2_INTF_STR
519 },
520 /* Bulk-OUT endpoint standard descriptor */
521 {
522 sizeof(USBEndpointDescriptor),
523 USBGenericDescriptor_ENDPOINT,
524 USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_OUT,
525 CARDEM_USIM2_DATAOUT),
526 USBEndpointDescriptor_BULK,
527 MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CARDEM_USIM2_DATAOUT),
528 USBEndpointDescriptor_MAXBULKSIZE_FS),
529 0 /* Must be 0 for full-speed bulk endpoints */
530 },
531 /* Bulk-IN endpoint descriptor */
532 {
533 sizeof(USBEndpointDescriptor),
534 USBGenericDescriptor_ENDPOINT,
535 USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN,
536 CARDEM_USIM2_DATAIN),
537 USBEndpointDescriptor_BULK,
538 MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CARDEM_USIM2_DATAIN),
539 USBEndpointDescriptor_MAXBULKSIZE_FS),
540 0 /* Must be 0 for full-speed bulk endpoints */
541 },
542 /* Notification endpoint descriptor */
543 {
544 sizeof(USBEndpointDescriptor),
545 USBGenericDescriptor_ENDPOINT,
546 USBEndpointDescriptor_ADDRESS( USBEndpointDescriptor_IN, CARDEM_USIM2_INT ),
547 USBEndpointDescriptor_INTERRUPT,
548 MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CARDEM_USIM2_INT),
549 USBEndpointDescriptor_MAXINTERRUPTSIZE_FS),
550 0x10
Christina Quast01bbdc32015-02-24 17:38:45 +0100551 }
Harald Welte57b3a252016-03-02 15:20:27 +0100552#endif
Christina Quast01bbdc32015-02-24 17:38:45 +0100553};
Harald Welte2fb59962016-02-28 12:34:26 +0100554#endif /* HAVE_CARDEM */
Christina Quast01bbdc32015-02-24 17:38:45 +0100555
Harald Welte2fb59962016-02-28 12:34:26 +0100556#ifdef HAVE_MITM
Christina Quastf5549502015-02-24 14:27:08 +0100557typedef struct _SIMTraceDriverConfigurationDescriptorMITM {
558
559 /** Standard configuration descriptor. */
Christina Quastda373fd2015-02-27 15:25:22 +0100560 USBConfigurationDescriptor configuration;
561 USBInterfaceDescriptor simcard;
Christina Quaste01fb9a2015-04-04 19:56:23 +0200562 /// CCID descriptor
563 CCIDDescriptor ccid;
564 /// Bulk OUT endpoint descriptor
Christina Quastda373fd2015-02-27 15:25:22 +0100565 USBEndpointDescriptor simcard_dataOut;
Christina Quaste01fb9a2015-04-04 19:56:23 +0200566 /// Bulk IN endpoint descriptor
Christina Quastda373fd2015-02-27 15:25:22 +0100567 USBEndpointDescriptor simcard_dataIn;
Christina Quaste01fb9a2015-04-04 19:56:23 +0200568 /// Interrupt OUT endpoint descriptor
Christina Quastda373fd2015-02-27 15:25:22 +0100569 USBEndpointDescriptor simcard_interruptIn;
Christina Quaste01fb9a2015-04-04 19:56:23 +0200570
Christina Quastda373fd2015-02-27 15:25:22 +0100571 USBInterfaceDescriptor phone;
572 USBEndpointDescriptor phone_dataOut;
573 USBEndpointDescriptor phone_dataIn;
574 USBEndpointDescriptor phone_interruptIn;
Christina Quastf5549502015-02-24 14:27:08 +0100575
Christina Quast01bbdc32015-02-24 17:38:45 +0100576} __attribute__ ((packed)) SIMTraceDriverConfigurationDescriptorMITM;
Christina Quastf5549502015-02-24 14:27:08 +0100577
Harald Welteec4fe232015-11-07 18:41:25 +0100578static const SIMTraceDriverConfigurationDescriptorMITM configurationDescriptorMITM = {
Christina Quastf5549502015-02-24 14:27:08 +0100579 /* Standard configuration descriptor */
580 {
581 sizeof(USBConfigurationDescriptor),
582 USBGenericDescriptor_CONFIGURATION,
Christina Quast968b9742015-02-25 14:10:12 +0100583 sizeof(SIMTraceDriverConfigurationDescriptorMITM),
Christina Quastf5549502015-02-24 14:27:08 +0100584 2, /* There are two interfaces in this configuration */
Christina Quast10b2e5a2015-02-25 18:40:15 +0100585 CFG_NUM_MITM, /* configuration number */
Christina Quastf5549502015-02-24 14:27:08 +0100586 MITM_CONF_STR, /* string descriptor for this configuration */
587 USBD_BMATTRIBUTES,
588 USBConfigurationDescriptor_POWER(100)
589 },
Christina Quaste01fb9a2015-04-04 19:56:23 +0200590 // CCID interface descriptor
591 // Table 4.3-1 Interface Descriptor
592 // Interface descriptor
Christina Quastf5549502015-02-24 14:27:08 +0100593 {
594 sizeof(USBInterfaceDescriptor),
595 USBGenericDescriptor_INTERFACE,
Christina Quaste01fb9a2015-04-04 19:56:23 +0200596 0, // Interface 0
597 0, // No alternate settings
598 3, // uses bulk-IN, bulk-OUT and interrupt IN
599 SMART_CARD_DEVICE_CLASS,
600 0, // Subclass code
601 0, // bulk transfers optional interrupt-IN
602 CCID_CONF_STR // associated string descriptor
Christina Quastf5549502015-02-24 14:27:08 +0100603 },
Christina Quaste01fb9a2015-04-04 19:56:23 +0200604 {
605 sizeof(CCIDDescriptor), // bLength: Size of this descriptor in bytes
606 CCID_DECRIPTOR_TYPE, // bDescriptorType:Functional descriptor type
607 CCID1_10, // bcdCCID: CCID version
608 0, // bMaxSlotIndex: Value 0 indicates that one slot is supported
Harald Welte8a5b5802015-11-07 18:52:52 +0100609 VOLTS_3_0, // bVoltageSupport
Christina Quaste01fb9a2015-04-04 19:56:23 +0200610 (1 << PROTOCOL_TO), // dwProtocols
611 3580, // dwDefaultClock
612 3580, // dwMaxClock
613 0, // bNumClockSupported
614 9600, // dwDataRate : 9600 bauds
615 9600, // dwMaxDataRate : 9600 bauds
616 0, // bNumDataRatesSupported
617 0xfe, // dwMaxIFSD
618 0, // dwSynchProtocols
619 0, // dwMechanical
620 //0x00010042, // dwFeatures: Short APDU level exchanges
621 CCID_FEATURES_AUTO_CLOCK | CCID_FEATURES_AUTO_BAUD |
622 CCID_FEATURES_AUTO_PCONF | CCID_FEATURES_AUTO_PNEGO | CCID_FEATURES_EXC_TPDU,
623 0x0000010F, // dwMaxCCIDMessageLength: For extended APDU level the value shall be between 261 + 10
624 0xFF, // bClassGetResponse: Echoes the class of the APDU
625 0xFF, // bClassEnvelope: Echoes the class of the APDU
626 0, // wLcdLayout: no LCD
627 0, // bPINSupport: No PIN
628 1 // bMaxCCIDBusySlot
629 },
630 // Bulk-OUT endpoint descriptor
Christina Quastf5549502015-02-24 14:27:08 +0100631 {
632 sizeof(USBEndpointDescriptor),
633 USBGenericDescriptor_ENDPOINT,
Christina Quaste01fb9a2015-04-04 19:56:23 +0200634 USBEndpointDescriptor_ADDRESS( USBEndpointDescriptor_OUT, CCID_EPT_DATA_OUT ),
Christina Quastf5549502015-02-24 14:27:08 +0100635 USBEndpointDescriptor_BULK,
Christina Quaste01fb9a2015-04-04 19:56:23 +0200636 MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CCID_EPT_DATA_OUT),
Christina Quastf5549502015-02-24 14:27:08 +0100637 USBEndpointDescriptor_MAXBULKSIZE_FS),
Christina Quaste01fb9a2015-04-04 19:56:23 +0200638 0x00 // Does not apply to Bulk endpoints
Christina Quastf5549502015-02-24 14:27:08 +0100639 },
Christina Quaste01fb9a2015-04-04 19:56:23 +0200640 // Bulk-IN endpoint descriptor
Christina Quast01bbdc32015-02-24 17:38:45 +0100641 {
642 sizeof(USBEndpointDescriptor),
643 USBGenericDescriptor_ENDPOINT,
Christina Quaste01fb9a2015-04-04 19:56:23 +0200644 USBEndpointDescriptor_ADDRESS( USBEndpointDescriptor_IN, CCID_EPT_DATA_IN ),
Christina Quast01bbdc32015-02-24 17:38:45 +0100645 USBEndpointDescriptor_BULK,
Christina Quaste01fb9a2015-04-04 19:56:23 +0200646 MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CCID_EPT_DATA_IN),
Christina Quast01bbdc32015-02-24 17:38:45 +0100647 USBEndpointDescriptor_MAXBULKSIZE_FS),
Christina Quaste01fb9a2015-04-04 19:56:23 +0200648 0x00 // Does not apply to Bulk endpoints
Christina Quast968b9742015-02-25 14:10:12 +0100649 },
Christina Quaste01fb9a2015-04-04 19:56:23 +0200650 // Notification endpoint descriptor
Christina Quastda373fd2015-02-27 15:25:22 +0100651 {
652 sizeof(USBEndpointDescriptor),
653 USBGenericDescriptor_ENDPOINT,
Christina Quaste01fb9a2015-04-04 19:56:23 +0200654 USBEndpointDescriptor_ADDRESS( USBEndpointDescriptor_IN, CCID_EPT_NOTIFICATION ),
Christina Quastda373fd2015-02-27 15:25:22 +0100655 USBEndpointDescriptor_INTERRUPT,
Christina Quaste01fb9a2015-04-04 19:56:23 +0200656 MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CCID_EPT_NOTIFICATION),
Christina Quastda373fd2015-02-27 15:25:22 +0100657 USBEndpointDescriptor_MAXINTERRUPTSIZE_FS),
658 0x10
659 },
Christina Quast01bbdc32015-02-24 17:38:45 +0100660 /* Communication class interface standard descriptor */
661 {
662 sizeof(USBInterfaceDescriptor),
663 USBGenericDescriptor_INTERFACE,
664 1, /* This is interface #1 */
665 0, /* This is alternate setting #0 for this interface */
Christina Quast99d80ff2015-04-03 22:26:07 +0200666 3, /* Number of endpoints */
Christina Quast01bbdc32015-02-24 17:38:45 +0100667 0xff,
668 0,
Christina Quastbfd73542015-05-08 16:00:51 +0200669 0,
670 PHONE_CONF_STR, /* string descriptor for this interface */
Christina Quast01bbdc32015-02-24 17:38:45 +0100671 },
672 /* Bulk-OUT endpoint standard descriptor */
673 {
674 sizeof(USBEndpointDescriptor),
675 USBGenericDescriptor_ENDPOINT,
676 USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_OUT,
Christina Quast71234252015-04-03 11:35:59 +0200677 PHONE_DATAOUT),
Christina Quast01bbdc32015-02-24 17:38:45 +0100678 USBEndpointDescriptor_BULK,
Christina Quast71234252015-04-03 11:35:59 +0200679 MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(PHONE_DATAOUT),
Christina Quast01bbdc32015-02-24 17:38:45 +0100680 USBEndpointDescriptor_MAXBULKSIZE_FS),
681 0 /* Must be 0 for full-speed bulk endpoints */
682 },
683 /* Bulk-IN endpoint descriptor */
Christina Quastf5549502015-02-24 14:27:08 +0100684 {
685 sizeof(USBEndpointDescriptor),
686 USBGenericDescriptor_ENDPOINT,
687 USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN,
Christina Quast71234252015-04-03 11:35:59 +0200688 PHONE_DATAIN),
Christina Quastf5549502015-02-24 14:27:08 +0100689 USBEndpointDescriptor_BULK,
Christina Quast71234252015-04-03 11:35:59 +0200690 MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(PHONE_DATAIN),
Christina Quastf5549502015-02-24 14:27:08 +0100691 USBEndpointDescriptor_MAXBULKSIZE_FS),
692 0 /* Must be 0 for full-speed bulk endpoints */
Christina Quastda373fd2015-02-27 15:25:22 +0100693 },
694 /* Notification endpoint descriptor */
695 {
696 sizeof(USBEndpointDescriptor),
697 USBGenericDescriptor_ENDPOINT,
Christina Quast71234252015-04-03 11:35:59 +0200698 USBEndpointDescriptor_ADDRESS( USBEndpointDescriptor_IN, PHONE_INT ),
Christina Quastda373fd2015-02-27 15:25:22 +0100699 USBEndpointDescriptor_INTERRUPT,
Christina Quast71234252015-04-03 11:35:59 +0200700 MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(PHONE_INT),
Christina Quastda373fd2015-02-27 15:25:22 +0100701 USBEndpointDescriptor_MAXINTERRUPTSIZE_FS),
702 0x10
Christina Quastf5549502015-02-24 14:27:08 +0100703 }
704};
Harald Welte2fb59962016-02-28 12:34:26 +0100705#endif /* HAVE_CARDEM */
706
707const USBConfigurationDescriptor *configurationDescriptorsArr[] = {
708#ifdef HAVE_SNIFFER
709 &configurationDescriptorSniffer.configuration,
710#endif
711#ifdef HAVE_CCID
712 &configurationDescriptorCCID.configuration,
713#endif
714#ifdef HAVE_CARDEM
715 &configurationDescriptorPhone.configuration,
716#endif
717#ifdef HAVE_MITM
718 &configurationDescriptorMITM.configuration,
719#endif
720};
Christina Quastf5549502015-02-24 14:27:08 +0100721
Christina Quastf5549502015-02-24 14:27:08 +0100722/** Standard USB device descriptor for the CDC serial driver */
723const USBDeviceDescriptor deviceDescriptor = {
724
725 sizeof(USBDeviceDescriptor),
726 USBGenericDescriptor_DEVICE,
727 USBDeviceDescriptor_USB2_00,
728 0xff,
729// CDCDeviceDescriptor_CLASS,
730 0xff,
731// CDCDeviceDescriptor_SUBCLASS,
732 0xff,
733// CDCDeviceDescriptor_PROTOCOL,
734 BOARD_USB_ENDPOINTS_MAXPACKETSIZE(0),
Christina Quast37350392015-05-08 16:47:26 +0200735 SIMTRACE_VENDOR_ID,
Christina Quastf5549502015-02-24 14:27:08 +0100736 SIMTRACE_PRODUCT_ID,
737 1, /* Release number */
Harald Welte6d44c1f2015-11-07 19:01:30 +0100738 MANUF_STR, /* Indesx of manufacturer string descriptor */
Christina Quastf5549502015-02-24 14:27:08 +0100739 PRODUCT_STRING, /* Index of product string descriptor */
740 0, /* No string descriptor for serial number */
Harald Welte2fb59962016-02-28 12:34:26 +0100741 ARRAY_SIZE(configurationDescriptorsArr) /* Device has N possible configs */
Christina Quast01bbdc32015-02-24 17:38:45 +0100742};
743
Christina Quastbd5b8bd2015-05-14 17:25:41 +0200744/* AT91SAM3S only supports full speed, but not high speed USB */
Harald Welteec4fe232015-11-07 18:41:25 +0100745static const USBDDriverDescriptors driverDescriptors = {
Christina Quastf5549502015-02-24 14:27:08 +0100746 &deviceDescriptor,
Christina Quastb06fc382015-04-06 23:30:21 +0200747 (const USBConfigurationDescriptor **) &(configurationDescriptorsArr), /* first full-speed configuration descriptor */
Christina Quastf5549502015-02-24 14:27:08 +0100748 0, /* No full-speed device qualifier descriptor */
749 0, /* No full-speed other speed configuration */
750 0, /* No high-speed device descriptor */
751 0, /* No high-speed configuration descriptor */
752 0, /* No high-speed device qualifier descriptor */
753 0, /* No high-speed other speed configuration descriptor */
754 stringDescriptors,
Christina Quast54d0c1f2015-02-25 16:04:25 +0100755 STRING_DESC_CNT /* cnt string descriptors in list */
Christina Quastf5549502015-02-24 14:27:08 +0100756};
757
Christina Quast0ae03142015-02-25 18:43:46 +0100758
759/*----------------------------------------------------------------------------
Christina Quast968b9742015-02-25 14:10:12 +0100760 * Functions
761 *----------------------------------------------------------------------------*/
762
763/**
764 * \brief Configure 48MHz Clock for USB
765 */
766static void _ConfigureUsbClock(void)
767{
768 /* Enable PLLB for USB */
Christina Quast968b9742015-02-25 14:10:12 +0100769 PMC->CKGR_PLLBR = CKGR_PLLBR_DIVB(5)
770 | CKGR_PLLBR_MULB(0xc) /* MULT+1=0xd*/
771 | CKGR_PLLBR_PLLBCOUNT_Msk;
772 while((PMC->PMC_SR & PMC_SR_LOCKB) == 0);
773 /* USB Clock uses PLLB */
774 PMC->PMC_USB = PMC_USB_USBDIV(0) /* /1 (no divider) */
775 | PMC_USB_USBS; /* PLLB */
776}
777
778
779void SIMtrace_USB_Initialize( void )
780{
781 _ConfigureUsbClock();
782 // Get std USB driver
783 USBDDriver *pUsbd = USBD_GetDriver();
784
785 TRACE_DEBUG(".");
786
787 // Initialize standard USB driver
788 USBDDriver_Initialize(pUsbd,
789 &driverDescriptors,
Christina Quast968b9742015-02-25 14:10:12 +0100790 0); // Multiple interface settings not supported
Christina Quast968b9742015-02-25 14:10:12 +0100791 USBD_Init();
Christina Quast968b9742015-02-25 14:10:12 +0100792 USBD_Connect();
793
794 NVIC_EnableIRQ( UDP_IRQn );
795}