blob: 46f0926d12739b6ef4e32d1ca5c4ed4e0e6317e3 [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"
35
Christina Quastdb7b1ab2015-03-03 12:34:36 +010036#include <cciddriverdescriptors.h>
37
Christina Quastf5549502015-02-24 14:27:08 +010038/*------------------------------------------------------------------------------
39 * USB String descriptors
40 *------------------------------------------------------------------------------*/
41
Christina Quast6032e792015-02-27 15:22:25 +010042
43static const unsigned char langDesc[] = {
44
45 USBStringDescriptor_LENGTH(1),
46 USBGenericDescriptor_STRING,
47 USBStringDescriptor_ENGLISH_US
48};
49
Christina Quastf5549502015-02-24 14:27:08 +010050const unsigned char productStringDescriptor[] = {
51
52 USBStringDescriptor_LENGTH(8),
53 USBGenericDescriptor_STRING,
54 USBStringDescriptor_UNICODE('S'),
55 USBStringDescriptor_UNICODE('I'),
56 USBStringDescriptor_UNICODE('M'),
57 USBStringDescriptor_UNICODE('t'),
58 USBStringDescriptor_UNICODE('r'),
59 USBStringDescriptor_UNICODE('a'),
60 USBStringDescriptor_UNICODE('c'),
61 USBStringDescriptor_UNICODE('e'),
62};
63
64const unsigned char snifferConfigStringDescriptor[] = {
65
66 USBStringDescriptor_LENGTH(15),
67 USBGenericDescriptor_STRING,
68 USBStringDescriptor_UNICODE('S'),
69 USBStringDescriptor_UNICODE('I'),
70 USBStringDescriptor_UNICODE('M'),
71 USBStringDescriptor_UNICODE('t'),
72 USBStringDescriptor_UNICODE('r'),
73 USBStringDescriptor_UNICODE('a'),
74 USBStringDescriptor_UNICODE('c'),
75 USBStringDescriptor_UNICODE('e'),
76 USBStringDescriptor_UNICODE('S'),
77 USBStringDescriptor_UNICODE('n'),
78 USBStringDescriptor_UNICODE('i'),
79 USBStringDescriptor_UNICODE('f'),
80 USBStringDescriptor_UNICODE('f'),
81 USBStringDescriptor_UNICODE('e'),
82 USBStringDescriptor_UNICODE('r'),
83};
84
85const unsigned char CCIDConfigStringDescriptor[] = {
86
87 USBStringDescriptor_LENGTH(12),
88 USBGenericDescriptor_STRING,
89 USBStringDescriptor_UNICODE('S'),
90 USBStringDescriptor_UNICODE('I'),
91 USBStringDescriptor_UNICODE('M'),
92 USBStringDescriptor_UNICODE('t'),
93 USBStringDescriptor_UNICODE('r'),
94 USBStringDescriptor_UNICODE('a'),
95 USBStringDescriptor_UNICODE('c'),
96 USBStringDescriptor_UNICODE('e'),
97 USBStringDescriptor_UNICODE('C'),
98 USBStringDescriptor_UNICODE('C'),
99 USBStringDescriptor_UNICODE('I'),
100 USBStringDescriptor_UNICODE('D'),
101};
102
103const unsigned char phoneConfigStringDescriptor[] = {
104
105 USBStringDescriptor_LENGTH(13),
106 USBGenericDescriptor_STRING,
107 USBStringDescriptor_UNICODE('S'),
108 USBStringDescriptor_UNICODE('I'),
109 USBStringDescriptor_UNICODE('M'),
110 USBStringDescriptor_UNICODE('t'),
111 USBStringDescriptor_UNICODE('r'),
112 USBStringDescriptor_UNICODE('a'),
113 USBStringDescriptor_UNICODE('c'),
114 USBStringDescriptor_UNICODE('e'),
115 USBStringDescriptor_UNICODE('P'),
116 USBStringDescriptor_UNICODE('h'),
117 USBStringDescriptor_UNICODE('o'),
118 USBStringDescriptor_UNICODE('n'),
119 USBStringDescriptor_UNICODE('e'),
120};
121
122
123const unsigned char MITMConfigStringDescriptor[] = {
124
125 USBStringDescriptor_LENGTH(12),
126 USBGenericDescriptor_STRING,
127 USBStringDescriptor_UNICODE('S'),
128 USBStringDescriptor_UNICODE('I'),
129 USBStringDescriptor_UNICODE('M'),
130 USBStringDescriptor_UNICODE('t'),
131 USBStringDescriptor_UNICODE('r'),
132 USBStringDescriptor_UNICODE('a'),
133 USBStringDescriptor_UNICODE('c'),
134 USBStringDescriptor_UNICODE('e'),
135 USBStringDescriptor_UNICODE('M'),
136 USBStringDescriptor_UNICODE('I'),
137 USBStringDescriptor_UNICODE('T'),
138 USBStringDescriptor_UNICODE('M'),
139};
140
141enum strDescNum {
Christina Quast54d0c1f2015-02-25 16:04:25 +0100142 PRODUCT_STRING = 1, SNIFFER_CONF_STR, CCID_CONF_STR, PHONE_CONF_STR, MITM_CONF_STR, STRING_DESC_CNT
Christina Quastf5549502015-02-24 14:27:08 +0100143};
144
145/** List of string descriptors used by the device */
146const unsigned char *stringDescriptors[] = {
147/* FIXME: Is it true that I can't use the string desc #0,
148 * because 0 also stands for "no string desc"?
149 * on the other hand, dmesg output:
150 * "string descriptor 0 malformed (err = -61), defaulting to 0x0409" */
Christina Quast6032e792015-02-27 15:22:25 +0100151 langDesc,
Christina Quastf5549502015-02-24 14:27:08 +0100152 productStringDescriptor,
153 snifferConfigStringDescriptor,
Christina Quast968b9742015-02-25 14:10:12 +0100154 CCIDConfigStringDescriptor,
Christina Quastf5549502015-02-24 14:27:08 +0100155 phoneConfigStringDescriptor,
156 MITMConfigStringDescriptor
157};
158
Christina Quastf5549502015-02-24 14:27:08 +0100159/*------------------------------------------------------------------------------
160 * USB Device descriptors
161 *------------------------------------------------------------------------------*/
162
163typedef struct _SIMTraceDriverConfigurationDescriptorSniffer {
164
165 /** Standard configuration descriptor. */
Christina Quastda373fd2015-02-27 15:25:22 +0100166 USBConfigurationDescriptor configuration;
167 USBInterfaceDescriptor sniffer;
168 USBEndpointDescriptor sniffer_dataOut;
169 USBEndpointDescriptor sniffer_dataIn;
170 USBEndpointDescriptor sniffer_interruptIn;
Christina Quastf5549502015-02-24 14:27:08 +0100171
Christina Quast01bbdc32015-02-24 17:38:45 +0100172} __attribute__ ((packed)) SIMTraceDriverConfigurationDescriptorSniffer;
Christina Quastf5549502015-02-24 14:27:08 +0100173
174const SIMTraceDriverConfigurationDescriptorSniffer configurationDescriptorSniffer = {
175 /* Standard configuration descriptor */
176 {
177 sizeof(USBConfigurationDescriptor),
178 USBGenericDescriptor_CONFIGURATION,
179 sizeof(SIMTraceDriverConfigurationDescriptorSniffer),
180 1, /* There is one interface in this configuration */
Christina Quast10b2e5a2015-02-25 18:40:15 +0100181 CFG_NUM_SNIFF, /* configuration number */
Christina Quastf5549502015-02-24 14:27:08 +0100182 SNIFFER_CONF_STR, /* string descriptor for this configuration */
183 USBD_BMATTRIBUTES,
184 USBConfigurationDescriptor_POWER(100)
185 },
186 /* Communication class interface standard descriptor */
187 {
188 sizeof(USBInterfaceDescriptor),
189 USBGenericDescriptor_INTERFACE,
190 0, /* This is interface #0 */
191 0, /* This is alternate setting #0 for this interface */
Christina Quastda373fd2015-02-27 15:25:22 +0100192 3, /* This interface uses 3 endpoints */
Christina Quastf5549502015-02-24 14:27:08 +0100193 0xff, /* Descriptor Class: Vendor specific */
194 0, /* No subclass */
195 0, /* No l */
196 SNIFFER_CONF_STR /* Third in string descriptor for this interface */
197 },
198 /* Bulk-OUT endpoint standard descriptor */
Christina Quastf5549502015-02-24 14:27:08 +0100199 {
200 sizeof(USBEndpointDescriptor),
201 USBGenericDescriptor_ENDPOINT,
202 USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_OUT,
203 DATAOUT),
204 USBEndpointDescriptor_BULK,
205 MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(DATAOUT),
206 USBEndpointDescriptor_MAXBULKSIZE_FS),
207 0 /* Must be 0 for full-speed bulk endpoints */
208 },
209 /* Bulk-IN endpoint descriptor */
Christina Quastf5549502015-02-24 14:27:08 +0100210 {
211 sizeof(USBEndpointDescriptor),
212 USBGenericDescriptor_ENDPOINT,
213 USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN,
214 DATAIN),
215 USBEndpointDescriptor_BULK,
216 MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(DATAIN),
217 USBEndpointDescriptor_MAXBULKSIZE_FS),
218 0 /* Must be 0 for full-speed bulk endpoints */
Christina Quastda373fd2015-02-27 15:25:22 +0100219 },
220 // Notification endpoint descriptor
221 {
222 sizeof(USBEndpointDescriptor),
223 USBGenericDescriptor_ENDPOINT,
224 USBEndpointDescriptor_ADDRESS( USBEndpointDescriptor_IN, INT ),
225 USBEndpointDescriptor_INTERRUPT,
226 MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(INT),
227 USBEndpointDescriptor_MAXINTERRUPTSIZE_FS),
228 0x10
Christina Quastf5549502015-02-24 14:27:08 +0100229 }
230};
231
Christina Quastdb7b1ab2015-03-03 12:34:36 +0100232/*
233/// CCIDDriverConfiguration Descriptors
234/// List of descriptors that make up the configuration descriptors of a
235/// device using the CCID driver.
Christina Quast01bbdc32015-02-24 17:38:45 +0100236typedef struct {
237
Christina Quastdb7b1ab2015-03-03 12:34:36 +0100238 /// Configuration descriptor
Christina Quast01bbdc32015-02-24 17:38:45 +0100239 USBConfigurationDescriptor configuration;
Christina Quastdb7b1ab2015-03-03 12:34:36 +0100240 /// Interface descriptor
Christina Quast01bbdc32015-02-24 17:38:45 +0100241 USBInterfaceDescriptor interface;
Christina Quastdb7b1ab2015-03-03 12:34:36 +0100242 /// CCID descriptor
Christina Quast01bbdc32015-02-24 17:38:45 +0100243 CCIDDescriptor ccid;
Christina Quastdb7b1ab2015-03-03 12:34:36 +0100244 /// Bulk OUT endpoint descriptor
Christina Quast01bbdc32015-02-24 17:38:45 +0100245 USBEndpointDescriptor bulkOut;
Christina Quastdb7b1ab2015-03-03 12:34:36 +0100246 /// Bulk IN endpoint descriptor
Christina Quast01bbdc32015-02-24 17:38:45 +0100247 USBEndpointDescriptor bulkIn;
Christina Quastdb7b1ab2015-03-03 12:34:36 +0100248 /// Interrupt OUT endpoint descriptor
Christina Quast01bbdc32015-02-24 17:38:45 +0100249 USBEndpointDescriptor interruptIn;
Christina Quastdb7b1ab2015-03-03 12:34:36 +0100250} __attribute__ ((packed)) CCIDDriverConfigurationDescriptors;
251*/
Christina Quast01bbdc32015-02-24 17:38:45 +0100252
Christina Quastdb7b1ab2015-03-03 12:34:36 +0100253const CCIDDriverConfigurationDescriptors configurationDescriptorCCID = {
254
255 // Standard USB configuration descriptor
256 {
257 sizeof(USBConfigurationDescriptor),
258 USBGenericDescriptor_CONFIGURATION,
259 sizeof(CCIDDriverConfigurationDescriptors),
260 1, // One interface in this configuration
261 CFG_NUM_CCID, // This is configuration #1
262 CCID_CONF_STR, // associated string descriptor
263 BOARD_USB_BMATTRIBUTES,
264 USBConfigurationDescriptor_POWER(100)
265 },
266 // CCID interface descriptor
267 // Table 4.3-1 Interface Descriptor
268 // Interface descriptor
269 {
270 sizeof(USBInterfaceDescriptor),
271 USBGenericDescriptor_INTERFACE,
272 0, // Interface 0
273 0, // No alternate settings
274 3, // uses bulk-IN, bulk-OUT and interrupt IN
275 SMART_CARD_DEVICE_CLASS,
276 0, // Subclass code
277 0, // bulk transfers optional interrupt-IN
278 CCID_CONF_STR // associated string descriptor
279 },
280 {
281 sizeof(CCIDDescriptor), // bLength: Size of this descriptor in bytes
282 CCID_DECRIPTOR_TYPE, // bDescriptorType:Functional descriptor type
283 CCID1_10, // bcdCCID: CCID version
284 0, // bMaxSlotIndex: Value 0 indicates that one slot is supported
285 VOLTS_5_0, // bVoltageSupport
286 (1 << PROTOCOL_TO), // dwProtocols
287 3580, // dwDefaultClock
288 3580, // dwMaxClock
289 0, // bNumClockSupported
290 9600, // dwDataRate : 9600 bauds
291 9600, // dwMaxDataRate : 9600 bauds
292 0, // bNumDataRatesSupported
293 0xfe, // dwMaxIFSD
294 0, // dwSynchProtocols
295 0, // dwMechanical
296 //0x00010042, // dwFeatures: Short APDU level exchanges
297 CCID_FEATURES_AUTO_CLOCK | CCID_FEATURES_AUTO_BAUD |
298 CCID_FEATURES_AUTO_PCONF | CCID_FEATURES_AUTO_PNEGO | CCID_FEATURES_EXC_TPDU,
299 0x0000010F, // dwMaxCCIDMessageLength: For extended APDU level the value shall be between 261 + 10
300 0xFF, // bClassGetResponse: Echoes the class of the APDU
301 0xFF, // bClassEnvelope: Echoes the class of the APDU
302 0, // wLcdLayout: no LCD
303 0, // bPINSupport: No PIN
304 1 // bMaxCCIDBusySlot
305 },
306 // Bulk-OUT endpoint descriptor
307 {
308 sizeof(USBEndpointDescriptor),
309 USBGenericDescriptor_ENDPOINT,
310 USBEndpointDescriptor_ADDRESS( USBEndpointDescriptor_OUT, CCID_EPT_DATA_OUT ),
311 USBEndpointDescriptor_BULK,
312 MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CCID_EPT_DATA_OUT),
313 USBEndpointDescriptor_MAXBULKSIZE_FS),
314 0x00 // Does not apply to Bulk endpoints
315 },
316 // Bulk-IN endpoint descriptor
317 {
318 sizeof(USBEndpointDescriptor),
319 USBGenericDescriptor_ENDPOINT,
320 USBEndpointDescriptor_ADDRESS( USBEndpointDescriptor_IN, CCID_EPT_DATA_IN ),
321 USBEndpointDescriptor_BULK,
322 MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CCID_EPT_DATA_IN),
323 USBEndpointDescriptor_MAXBULKSIZE_FS),
324 0x00 // Does not apply to Bulk endpoints
325 },
326 // Notification endpoint descriptor
327 {
328 sizeof(USBEndpointDescriptor),
329 USBGenericDescriptor_ENDPOINT,
330 USBEndpointDescriptor_ADDRESS( USBEndpointDescriptor_IN, CCID_EPT_NOTIFICATION ),
331 USBEndpointDescriptor_INTERRUPT,
332 MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CCID_EPT_NOTIFICATION),
333 USBEndpointDescriptor_MAXINTERRUPTSIZE_FS),
334 0x10
335 },
336};
337
Christina Quast01bbdc32015-02-24 17:38:45 +0100338
339/* SIM card emulator */
340typedef struct _SIMTraceDriverConfigurationDescriptorPhone {
341
342 /** Standard configuration descriptor. */
Christina Quastda373fd2015-02-27 15:25:22 +0100343 USBConfigurationDescriptor configuration;
344 USBInterfaceDescriptor phone;
345 USBEndpointDescriptor phone_dataOut;
346 USBEndpointDescriptor phone_dataIn;
347 USBEndpointDescriptor phone_interruptIn;
Christina Quast01bbdc32015-02-24 17:38:45 +0100348} __attribute__ ((packed)) SIMTraceDriverConfigurationDescriptorPhone;
349
350const SIMTraceDriverConfigurationDescriptorPhone configurationDescriptorPhone = {
351 /* Standard configuration descriptor */
352 {
353 sizeof(USBConfigurationDescriptor),
354 USBGenericDescriptor_CONFIGURATION,
355 sizeof(SIMTraceDriverConfigurationDescriptorSniffer),
356 1, /* There is one interface in this configuration */
Christina Quast10b2e5a2015-02-25 18:40:15 +0100357 CFG_NUM_PHONE, /* configuration number */
Christina Quast01bbdc32015-02-24 17:38:45 +0100358 PHONE_CONF_STR, /* string descriptor for this configuration */
359 USBD_BMATTRIBUTES,
360 USBConfigurationDescriptor_POWER(100)
361 },
362 /* Communication class interface standard descriptor */
363 {
364 sizeof(USBInterfaceDescriptor),
365 USBGenericDescriptor_INTERFACE,
366 0, /* This is interface #0 */
367 0, /* This is alternate setting #0 for this interface */
Christina Quastda373fd2015-02-27 15:25:22 +0100368 3, /* This interface uses 3 endpoints */
Christina Quast01bbdc32015-02-24 17:38:45 +0100369 0xff, /* Descriptor Class: Vendor specific */
370 0, /* No subclass */
371 0, /* No l */
372 PHONE_CONF_STR /* Third in string descriptor for this interface */
373 },
374 /* Bulk-OUT endpoint standard descriptor */
375 {
376 sizeof(USBEndpointDescriptor),
377 USBGenericDescriptor_ENDPOINT,
378 USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_OUT,
379 DATAOUT),
380 USBEndpointDescriptor_BULK,
381 MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(DATAOUT),
382 USBEndpointDescriptor_MAXBULKSIZE_FS),
383 0 /* Must be 0 for full-speed bulk endpoints */
384 },
385 /* Bulk-IN endpoint descriptor */
386 {
387 sizeof(USBEndpointDescriptor),
388 USBGenericDescriptor_ENDPOINT,
389 USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN,
390 DATAIN),
391 USBEndpointDescriptor_BULK,
392 MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(DATAIN),
393 USBEndpointDescriptor_MAXBULKSIZE_FS),
394 0 /* Must be 0 for full-speed bulk endpoints */
Christina Quastda373fd2015-02-27 15:25:22 +0100395 },
396 /* Notification endpoint descriptor */
397 {
398 sizeof(USBEndpointDescriptor),
399 USBGenericDescriptor_ENDPOINT,
400 USBEndpointDescriptor_ADDRESS( USBEndpointDescriptor_IN, INT ),
401 USBEndpointDescriptor_INTERRUPT,
402 MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(INT),
403 USBEndpointDescriptor_MAXINTERRUPTSIZE_FS),
404 0x10
Christina Quast01bbdc32015-02-24 17:38:45 +0100405 }
406};
407
Christina Quastf5549502015-02-24 14:27:08 +0100408
409typedef struct _SIMTraceDriverConfigurationDescriptorMITM {
410
411 /** Standard configuration descriptor. */
Christina Quastda373fd2015-02-27 15:25:22 +0100412 USBConfigurationDescriptor configuration;
413 USBInterfaceDescriptor simcard;
414 USBEndpointDescriptor simcard_dataOut;
415 USBEndpointDescriptor simcard_dataIn;
416 USBEndpointDescriptor simcard_interruptIn;
417 USBInterfaceDescriptor phone;
418 USBEndpointDescriptor phone_dataOut;
419 USBEndpointDescriptor phone_dataIn;
420 USBEndpointDescriptor phone_interruptIn;
Christina Quastf5549502015-02-24 14:27:08 +0100421
Christina Quast01bbdc32015-02-24 17:38:45 +0100422} __attribute__ ((packed)) SIMTraceDriverConfigurationDescriptorMITM;
Christina Quastf5549502015-02-24 14:27:08 +0100423
Christina Quast968b9742015-02-25 14:10:12 +0100424const SIMTraceDriverConfigurationDescriptorMITM configurationDescriptorMITM = {
Christina Quastf5549502015-02-24 14:27:08 +0100425 /* Standard configuration descriptor */
426 {
427 sizeof(USBConfigurationDescriptor),
428 USBGenericDescriptor_CONFIGURATION,
Christina Quast968b9742015-02-25 14:10:12 +0100429 sizeof(SIMTraceDriverConfigurationDescriptorMITM),
Christina Quastf5549502015-02-24 14:27:08 +0100430 2, /* There are two interfaces in this configuration */
Christina Quast10b2e5a2015-02-25 18:40:15 +0100431 CFG_NUM_MITM, /* configuration number */
Christina Quastf5549502015-02-24 14:27:08 +0100432 MITM_CONF_STR, /* string descriptor for this configuration */
433 USBD_BMATTRIBUTES,
434 USBConfigurationDescriptor_POWER(100)
435 },
436 /* Communication class interface standard descriptor */
437 {
438 sizeof(USBInterfaceDescriptor),
439 USBGenericDescriptor_INTERFACE,
440 0, /* This is interface #0 */
441 0, /* This is alternate setting #0 for this interface */
Christina Quastda373fd2015-02-27 15:25:22 +0100442 3, /* This interface uses 3 endpoints */
Christina Quastf5549502015-02-24 14:27:08 +0100443 //CDCCommunicationInterfaceDescriptor_CLASS,
444 0xff,
445// CDCCommunicationInterfaceDescriptor_ABSTRACTCONTROLMODEL,
446 0,
447// CDCCommunicationInterfaceDescriptor_NOPROTOCOL,
448 0,
449 MITM_CONF_STR /* string descriptor for this interface */
450 },
451 /* Bulk-OUT endpoint standard descriptor */
Christina Quastf5549502015-02-24 14:27:08 +0100452 {
453 sizeof(USBEndpointDescriptor),
454 USBGenericDescriptor_ENDPOINT,
455 USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_OUT,
456 DATAOUT),
457 USBEndpointDescriptor_BULK,
458 MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(DATAOUT),
459 USBEndpointDescriptor_MAXBULKSIZE_FS),
460 0 /* Must be 0 for full-speed bulk endpoints */
461 },
462 /* Bulk-IN endpoint descriptor */
Christina Quast01bbdc32015-02-24 17:38:45 +0100463 {
464 sizeof(USBEndpointDescriptor),
465 USBGenericDescriptor_ENDPOINT,
466 USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN,
467 DATAIN),
468 USBEndpointDescriptor_BULK,
469 MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(DATAIN),
470 USBEndpointDescriptor_MAXBULKSIZE_FS),
471 0 /* Must be 0 for full-speed bulk endpoints */
Christina Quast968b9742015-02-25 14:10:12 +0100472 },
Christina Quastda373fd2015-02-27 15:25:22 +0100473 /* Notification endpoint descriptor */
474 {
475 sizeof(USBEndpointDescriptor),
476 USBGenericDescriptor_ENDPOINT,
477 USBEndpointDescriptor_ADDRESS( USBEndpointDescriptor_IN, INT ),
478 USBEndpointDescriptor_INTERRUPT,
479 MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(INT),
480 USBEndpointDescriptor_MAXINTERRUPTSIZE_FS),
481 0x10
482 },
Christina Quast01bbdc32015-02-24 17:38:45 +0100483 /* Communication class interface standard descriptor */
484 {
485 sizeof(USBInterfaceDescriptor),
486 USBGenericDescriptor_INTERFACE,
487 1, /* This is interface #1 */
488 0, /* This is alternate setting #0 for this interface */
Christina Quastda373fd2015-02-27 15:25:22 +0100489 3, /* This interface uses 3 endpoints */
Christina Quast01bbdc32015-02-24 17:38:45 +0100490 0xff,
491 0,
492 0,
493 0, /* FIXME: string descriptor for this interface */
494 },
Christina Quast0166c6d2015-03-05 15:44:05 +0100495#define DATAOUT_2 DATAOUT+3
496#define DATAIN_2 DATAIN+3
497#define INT_2 INT+3
Christina Quast01bbdc32015-02-24 17:38:45 +0100498 /* Bulk-OUT endpoint standard descriptor */
499 {
500 sizeof(USBEndpointDescriptor),
501 USBGenericDescriptor_ENDPOINT,
502 USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_OUT,
Christina Quast0166c6d2015-03-05 15:44:05 +0100503 DATAOUT_2),
Christina Quast01bbdc32015-02-24 17:38:45 +0100504 USBEndpointDescriptor_BULK,
Christina Quast0166c6d2015-03-05 15:44:05 +0100505 MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(DATAOUT_2),
Christina Quast01bbdc32015-02-24 17:38:45 +0100506 USBEndpointDescriptor_MAXBULKSIZE_FS),
507 0 /* Must be 0 for full-speed bulk endpoints */
508 },
509 /* Bulk-IN endpoint descriptor */
Christina Quastf5549502015-02-24 14:27:08 +0100510 {
511 sizeof(USBEndpointDescriptor),
512 USBGenericDescriptor_ENDPOINT,
513 USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN,
Christina Quast0166c6d2015-03-05 15:44:05 +0100514 DATAIN_2),
Christina Quastf5549502015-02-24 14:27:08 +0100515 USBEndpointDescriptor_BULK,
Christina Quast0166c6d2015-03-05 15:44:05 +0100516 MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(DATAIN_2),
Christina Quastf5549502015-02-24 14:27:08 +0100517 USBEndpointDescriptor_MAXBULKSIZE_FS),
518 0 /* Must be 0 for full-speed bulk endpoints */
Christina Quastda373fd2015-02-27 15:25:22 +0100519 },
520 /* Notification endpoint descriptor */
521 {
522 sizeof(USBEndpointDescriptor),
523 USBGenericDescriptor_ENDPOINT,
Christina Quast0166c6d2015-03-05 15:44:05 +0100524 USBEndpointDescriptor_ADDRESS( USBEndpointDescriptor_IN, INT_2 ),
Christina Quastda373fd2015-02-27 15:25:22 +0100525 USBEndpointDescriptor_INTERRUPT,
Christina Quast0166c6d2015-03-05 15:44:05 +0100526 MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(INT_2),
Christina Quastda373fd2015-02-27 15:25:22 +0100527 USBEndpointDescriptor_MAXINTERRUPTSIZE_FS),
528 0x10
Christina Quastf5549502015-02-24 14:27:08 +0100529 }
530};
531
532
533/** Standard USB device descriptor for the CDC serial driver */
534const USBDeviceDescriptor deviceDescriptor = {
535
536 sizeof(USBDeviceDescriptor),
537 USBGenericDescriptor_DEVICE,
538 USBDeviceDescriptor_USB2_00,
539 0xff,
540// CDCDeviceDescriptor_CLASS,
541 0xff,
542// CDCDeviceDescriptor_SUBCLASS,
543 0xff,
544// CDCDeviceDescriptor_PROTOCOL,
545 BOARD_USB_ENDPOINTS_MAXPACKETSIZE(0),
546 ATMEL_VENDOR_ID,
547 SIMTRACE_PRODUCT_ID,
548 1, /* Release number */
549 0, /* No string descriptor for manufacturer */
550 PRODUCT_STRING, /* Index of product string descriptor */
551 0, /* No string descriptor for serial number */
Christina Quastdb7b1ab2015-03-03 12:34:36 +0100552 4 /* Device has 4 possible configurations */
Christina Quastf5549502015-02-24 14:27:08 +0100553};
554
Christina Quast968b9742015-02-25 14:10:12 +0100555const USBConfigurationDescriptor *configurationDescriptorsArr[] = {
Christina Quast01bbdc32015-02-24 17:38:45 +0100556 &configurationDescriptorSniffer,
Christina Quastdb7b1ab2015-03-03 12:34:36 +0100557 &configurationDescriptorCCID,
Christina Quast01bbdc32015-02-24 17:38:45 +0100558 &configurationDescriptorPhone,
559 &configurationDescriptorMITM,
560};
561
Christina Quastdb7b1ab2015-03-03 12:34:36 +0100562USBConfigurationDescriptor *getConfigDesc(uint8_t idx) {
563 return configurationDescriptorsArr[idx];
564}
Christina Quast01bbdc32015-02-24 17:38:45 +0100565
Christina Quastf5549502015-02-24 14:27:08 +0100566/* AT91SAM3S does only support full speed, but not high speed USB */
567const USBDDriverDescriptors driverDescriptors = {
568 &deviceDescriptor,
Christina Quast01bbdc32015-02-24 17:38:45 +0100569 (USBConfigurationDescriptor **) &(configurationDescriptorsArr), /* first full-speed configuration descriptor */
Christina Quastf5549502015-02-24 14:27:08 +0100570 0, /* No full-speed device qualifier descriptor */
571 0, /* No full-speed other speed configuration */
572 0, /* No high-speed device descriptor */
573 0, /* No high-speed configuration descriptor */
574 0, /* No high-speed device qualifier descriptor */
575 0, /* No high-speed other speed configuration descriptor */
576 stringDescriptors,
Christina Quast54d0c1f2015-02-25 16:04:25 +0100577 STRING_DESC_CNT /* cnt string descriptors in list */
Christina Quastf5549502015-02-24 14:27:08 +0100578};
579
Christina Quast0ae03142015-02-25 18:43:46 +0100580
581/*----------------------------------------------------------------------------
582 * Callbacks
583 *----------------------------------------------------------------------------*/
584extern uint8_t conf_changed;
585extern uint8_t simtrace_config;
586
587void USBDDriverCallbacks_ConfigurationChanged(uint8_t cfgnum)
588{
589 TRACE_INFO_WP("cfgChanged%d ", cfgnum);
590 conf_changed =1;
591 simtrace_config = cfgnum;
592}
593
594
Christina Quast968b9742015-02-25 14:10:12 +0100595/*----------------------------------------------------------------------------
596 * Functions
597 *----------------------------------------------------------------------------*/
598
599/**
600 * \brief Configure 48MHz Clock for USB
601 */
602static void _ConfigureUsbClock(void)
603{
604 /* Enable PLLB for USB */
605// FIXME: are these the dividers I actually need?
606// FIXME: I could just use PLLA, since it has a frequ of 48Mhz anyways?
607 PMC->CKGR_PLLBR = CKGR_PLLBR_DIVB(5)
608 | CKGR_PLLBR_MULB(0xc) /* MULT+1=0xd*/
609 | CKGR_PLLBR_PLLBCOUNT_Msk;
610 while((PMC->PMC_SR & PMC_SR_LOCKB) == 0);
611 /* USB Clock uses PLLB */
612 PMC->PMC_USB = PMC_USB_USBDIV(0) /* /1 (no divider) */
613 | PMC_USB_USBS; /* PLLB */
614}
615
616
617void SIMtrace_USB_Initialize( void )
618{
619 _ConfigureUsbClock();
620 // Get std USB driver
621 USBDDriver *pUsbd = USBD_GetDriver();
622
623 TRACE_DEBUG(".");
624
625 // Initialize standard USB driver
626 USBDDriver_Initialize(pUsbd,
627 &driverDescriptors,
628// FIXME: 2 interface settings supported in MITM mode
629 0); // Multiple interface settings not supported
630
631 USBD_Init();
632
633 USBD_Connect();
634
635 NVIC_EnableIRQ( UDP_IRQn );
636}