Christina Quast | 968b974 | 2015-02-25 14:10:12 +0100 | [diff] [blame] | 1 | /* ---------------------------------------------------------------------------- |
| 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 Quast | db7b1ab | 2015-03-03 12:34:36 +0100 | [diff] [blame] | 36 | #include <cciddriverdescriptors.h> |
| 37 | |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 38 | /*------------------------------------------------------------------------------ |
| 39 | * USB String descriptors |
| 40 | *------------------------------------------------------------------------------*/ |
| 41 | |
Christina Quast | 6032e79 | 2015-02-27 15:22:25 +0100 | [diff] [blame] | 42 | |
| 43 | static const unsigned char langDesc[] = { |
| 44 | |
| 45 | USBStringDescriptor_LENGTH(1), |
| 46 | USBGenericDescriptor_STRING, |
| 47 | USBStringDescriptor_ENGLISH_US |
| 48 | }; |
| 49 | |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 50 | const unsigned char productStringDescriptor[] = { |
| 51 | |
Harald Welte | beb7293 | 2015-11-07 18:35:41 +0100 | [diff] [blame] | 52 | USBStringDescriptor_LENGTH(10), |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 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'), |
Harald Welte | beb7293 | 2015-11-07 18:35:41 +0100 | [diff] [blame] | 62 | USBStringDescriptor_UNICODE(' '), |
| 63 | USBStringDescriptor_UNICODE('2'), |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 64 | }; |
| 65 | |
| 66 | const unsigned char snifferConfigStringDescriptor[] = { |
| 67 | |
Harald Welte | beb7293 | 2015-11-07 18:35:41 +0100 | [diff] [blame] | 68 | USBStringDescriptor_LENGTH(16), |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 69 | USBGenericDescriptor_STRING, |
| 70 | USBStringDescriptor_UNICODE('S'), |
| 71 | USBStringDescriptor_UNICODE('I'), |
| 72 | USBStringDescriptor_UNICODE('M'), |
| 73 | USBStringDescriptor_UNICODE('t'), |
| 74 | USBStringDescriptor_UNICODE('r'), |
| 75 | USBStringDescriptor_UNICODE('a'), |
| 76 | USBStringDescriptor_UNICODE('c'), |
| 77 | USBStringDescriptor_UNICODE('e'), |
Harald Welte | beb7293 | 2015-11-07 18:35:41 +0100 | [diff] [blame] | 78 | USBStringDescriptor_UNICODE(' '), |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 79 | USBStringDescriptor_UNICODE('S'), |
| 80 | USBStringDescriptor_UNICODE('n'), |
| 81 | USBStringDescriptor_UNICODE('i'), |
| 82 | USBStringDescriptor_UNICODE('f'), |
| 83 | USBStringDescriptor_UNICODE('f'), |
| 84 | USBStringDescriptor_UNICODE('e'), |
| 85 | USBStringDescriptor_UNICODE('r'), |
| 86 | }; |
| 87 | |
| 88 | const unsigned char CCIDConfigStringDescriptor[] = { |
| 89 | |
Harald Welte | beb7293 | 2015-11-07 18:35:41 +0100 | [diff] [blame] | 90 | USBStringDescriptor_LENGTH(13), |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 91 | USBGenericDescriptor_STRING, |
| 92 | USBStringDescriptor_UNICODE('S'), |
| 93 | USBStringDescriptor_UNICODE('I'), |
| 94 | USBStringDescriptor_UNICODE('M'), |
| 95 | USBStringDescriptor_UNICODE('t'), |
| 96 | USBStringDescriptor_UNICODE('r'), |
| 97 | USBStringDescriptor_UNICODE('a'), |
| 98 | USBStringDescriptor_UNICODE('c'), |
| 99 | USBStringDescriptor_UNICODE('e'), |
Harald Welte | beb7293 | 2015-11-07 18:35:41 +0100 | [diff] [blame] | 100 | USBStringDescriptor_UNICODE(' '), |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 101 | USBStringDescriptor_UNICODE('C'), |
| 102 | USBStringDescriptor_UNICODE('C'), |
| 103 | USBStringDescriptor_UNICODE('I'), |
| 104 | USBStringDescriptor_UNICODE('D'), |
| 105 | }; |
| 106 | |
| 107 | const unsigned char phoneConfigStringDescriptor[] = { |
| 108 | |
Harald Welte | beb7293 | 2015-11-07 18:35:41 +0100 | [diff] [blame] | 109 | USBStringDescriptor_LENGTH(14), |
| 110 | USBGenericDescriptor_STRING, |
| 111 | USBStringDescriptor_UNICODE('S'), |
| 112 | USBStringDescriptor_UNICODE('I'), |
| 113 | USBStringDescriptor_UNICODE('M'), |
| 114 | USBStringDescriptor_UNICODE('t'), |
| 115 | USBStringDescriptor_UNICODE('r'), |
| 116 | USBStringDescriptor_UNICODE('a'), |
| 117 | USBStringDescriptor_UNICODE('c'), |
| 118 | USBStringDescriptor_UNICODE('e'), |
| 119 | USBStringDescriptor_UNICODE(' '), |
| 120 | USBStringDescriptor_UNICODE('P'), |
| 121 | USBStringDescriptor_UNICODE('h'), |
| 122 | USBStringDescriptor_UNICODE('o'), |
| 123 | USBStringDescriptor_UNICODE('n'), |
| 124 | USBStringDescriptor_UNICODE('e'), |
| 125 | }; |
| 126 | |
| 127 | |
| 128 | const unsigned char MITMConfigStringDescriptor[] = { |
| 129 | |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 130 | USBStringDescriptor_LENGTH(13), |
| 131 | USBGenericDescriptor_STRING, |
| 132 | USBStringDescriptor_UNICODE('S'), |
| 133 | USBStringDescriptor_UNICODE('I'), |
| 134 | USBStringDescriptor_UNICODE('M'), |
| 135 | USBStringDescriptor_UNICODE('t'), |
| 136 | USBStringDescriptor_UNICODE('r'), |
| 137 | USBStringDescriptor_UNICODE('a'), |
| 138 | USBStringDescriptor_UNICODE('c'), |
| 139 | USBStringDescriptor_UNICODE('e'), |
Harald Welte | beb7293 | 2015-11-07 18:35:41 +0100 | [diff] [blame] | 140 | USBStringDescriptor_UNICODE(' '), |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 141 | USBStringDescriptor_UNICODE('M'), |
| 142 | USBStringDescriptor_UNICODE('I'), |
| 143 | USBStringDescriptor_UNICODE('T'), |
| 144 | USBStringDescriptor_UNICODE('M'), |
| 145 | }; |
| 146 | |
| 147 | enum strDescNum { |
Christina Quast | 54d0c1f | 2015-02-25 16:04:25 +0100 | [diff] [blame] | 148 | PRODUCT_STRING = 1, SNIFFER_CONF_STR, CCID_CONF_STR, PHONE_CONF_STR, MITM_CONF_STR, STRING_DESC_CNT |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 149 | }; |
| 150 | |
| 151 | /** List of string descriptors used by the device */ |
Harald Welte | ec4fe23 | 2015-11-07 18:41:25 +0100 | [diff] [blame^] | 152 | static const unsigned char *stringDescriptors[] = { |
Christina Quast | 6032e79 | 2015-02-27 15:22:25 +0100 | [diff] [blame] | 153 | langDesc, |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 154 | productStringDescriptor, |
| 155 | snifferConfigStringDescriptor, |
Christina Quast | 968b974 | 2015-02-25 14:10:12 +0100 | [diff] [blame] | 156 | CCIDConfigStringDescriptor, |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 157 | phoneConfigStringDescriptor, |
| 158 | MITMConfigStringDescriptor |
| 159 | }; |
| 160 | |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 161 | /*------------------------------------------------------------------------------ |
| 162 | * USB Device descriptors |
| 163 | *------------------------------------------------------------------------------*/ |
| 164 | |
| 165 | typedef struct _SIMTraceDriverConfigurationDescriptorSniffer { |
| 166 | |
| 167 | /** Standard configuration descriptor. */ |
Christina Quast | da373fd | 2015-02-27 15:25:22 +0100 | [diff] [blame] | 168 | USBConfigurationDescriptor configuration; |
| 169 | USBInterfaceDescriptor sniffer; |
| 170 | USBEndpointDescriptor sniffer_dataOut; |
| 171 | USBEndpointDescriptor sniffer_dataIn; |
| 172 | USBEndpointDescriptor sniffer_interruptIn; |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 173 | |
Christina Quast | 01bbdc3 | 2015-02-24 17:38:45 +0100 | [diff] [blame] | 174 | } __attribute__ ((packed)) SIMTraceDriverConfigurationDescriptorSniffer; |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 175 | |
Harald Welte | ec4fe23 | 2015-11-07 18:41:25 +0100 | [diff] [blame^] | 176 | static const SIMTraceDriverConfigurationDescriptorSniffer configurationDescriptorSniffer = { |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 177 | /* Standard configuration descriptor */ |
| 178 | { |
| 179 | sizeof(USBConfigurationDescriptor), |
| 180 | USBGenericDescriptor_CONFIGURATION, |
| 181 | sizeof(SIMTraceDriverConfigurationDescriptorSniffer), |
| 182 | 1, /* There is one interface in this configuration */ |
Christina Quast | 10b2e5a | 2015-02-25 18:40:15 +0100 | [diff] [blame] | 183 | CFG_NUM_SNIFF, /* configuration number */ |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 184 | SNIFFER_CONF_STR, /* string descriptor for this configuration */ |
| 185 | USBD_BMATTRIBUTES, |
| 186 | USBConfigurationDescriptor_POWER(100) |
| 187 | }, |
| 188 | /* Communication class interface standard descriptor */ |
| 189 | { |
| 190 | sizeof(USBInterfaceDescriptor), |
| 191 | USBGenericDescriptor_INTERFACE, |
| 192 | 0, /* This is interface #0 */ |
| 193 | 0, /* This is alternate setting #0 for this interface */ |
Christina Quast | 99d80ff | 2015-04-03 22:26:07 +0200 | [diff] [blame] | 194 | 3, /* Number of endpoints */ |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 195 | 0xff, /* Descriptor Class: Vendor specific */ |
| 196 | 0, /* No subclass */ |
| 197 | 0, /* No l */ |
| 198 | SNIFFER_CONF_STR /* Third in string descriptor for this interface */ |
| 199 | }, |
| 200 | /* Bulk-OUT endpoint standard descriptor */ |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 201 | { |
| 202 | sizeof(USBEndpointDescriptor), |
| 203 | USBGenericDescriptor_ENDPOINT, |
| 204 | USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_OUT, |
Christina Quast | 2b8a18b | 2015-04-12 09:31:36 +0200 | [diff] [blame] | 205 | PHONE_DATAOUT), |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 206 | USBEndpointDescriptor_BULK, |
Christina Quast | 2b8a18b | 2015-04-12 09:31:36 +0200 | [diff] [blame] | 207 | MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(PHONE_DATAOUT), |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 208 | USBEndpointDescriptor_MAXBULKSIZE_FS), |
| 209 | 0 /* Must be 0 for full-speed bulk endpoints */ |
| 210 | }, |
| 211 | /* Bulk-IN endpoint descriptor */ |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 212 | { |
| 213 | sizeof(USBEndpointDescriptor), |
| 214 | USBGenericDescriptor_ENDPOINT, |
| 215 | USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN, |
Christina Quast | 2b8a18b | 2015-04-12 09:31:36 +0200 | [diff] [blame] | 216 | PHONE_DATAIN), |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 217 | USBEndpointDescriptor_BULK, |
Christina Quast | 2b8a18b | 2015-04-12 09:31:36 +0200 | [diff] [blame] | 218 | MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(PHONE_DATAIN), |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 219 | USBEndpointDescriptor_MAXBULKSIZE_FS), |
| 220 | 0 /* Must be 0 for full-speed bulk endpoints */ |
Christina Quast | da373fd | 2015-02-27 15:25:22 +0100 | [diff] [blame] | 221 | }, |
| 222 | // Notification endpoint descriptor |
| 223 | { |
| 224 | sizeof(USBEndpointDescriptor), |
| 225 | USBGenericDescriptor_ENDPOINT, |
Christina Quast | 2b8a18b | 2015-04-12 09:31:36 +0200 | [diff] [blame] | 226 | USBEndpointDescriptor_ADDRESS( USBEndpointDescriptor_IN, PHONE_INT ), |
Christina Quast | da373fd | 2015-02-27 15:25:22 +0100 | [diff] [blame] | 227 | USBEndpointDescriptor_INTERRUPT, |
Christina Quast | 2b8a18b | 2015-04-12 09:31:36 +0200 | [diff] [blame] | 228 | MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(PHONE_INT), |
Christina Quast | da373fd | 2015-02-27 15:25:22 +0100 | [diff] [blame] | 229 | USBEndpointDescriptor_MAXINTERRUPTSIZE_FS), |
| 230 | 0x10 |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 231 | } |
| 232 | }; |
| 233 | |
Christina Quast | db7b1ab | 2015-03-03 12:34:36 +0100 | [diff] [blame] | 234 | /* |
| 235 | /// CCIDDriverConfiguration Descriptors |
| 236 | /// List of descriptors that make up the configuration descriptors of a |
| 237 | /// device using the CCID driver. |
Christina Quast | 01bbdc3 | 2015-02-24 17:38:45 +0100 | [diff] [blame] | 238 | typedef struct { |
| 239 | |
Christina Quast | db7b1ab | 2015-03-03 12:34:36 +0100 | [diff] [blame] | 240 | /// Configuration descriptor |
Christina Quast | 01bbdc3 | 2015-02-24 17:38:45 +0100 | [diff] [blame] | 241 | USBConfigurationDescriptor configuration; |
Christina Quast | db7b1ab | 2015-03-03 12:34:36 +0100 | [diff] [blame] | 242 | /// Interface descriptor |
Christina Quast | 01bbdc3 | 2015-02-24 17:38:45 +0100 | [diff] [blame] | 243 | USBInterfaceDescriptor interface; |
Christina Quast | db7b1ab | 2015-03-03 12:34:36 +0100 | [diff] [blame] | 244 | /// CCID descriptor |
Christina Quast | 01bbdc3 | 2015-02-24 17:38:45 +0100 | [diff] [blame] | 245 | CCIDDescriptor ccid; |
Christina Quast | db7b1ab | 2015-03-03 12:34:36 +0100 | [diff] [blame] | 246 | /// Bulk OUT endpoint descriptor |
Christina Quast | 01bbdc3 | 2015-02-24 17:38:45 +0100 | [diff] [blame] | 247 | USBEndpointDescriptor bulkOut; |
Christina Quast | db7b1ab | 2015-03-03 12:34:36 +0100 | [diff] [blame] | 248 | /// Bulk IN endpoint descriptor |
Christina Quast | 01bbdc3 | 2015-02-24 17:38:45 +0100 | [diff] [blame] | 249 | USBEndpointDescriptor bulkIn; |
Christina Quast | db7b1ab | 2015-03-03 12:34:36 +0100 | [diff] [blame] | 250 | /// Interrupt OUT endpoint descriptor |
Christina Quast | 01bbdc3 | 2015-02-24 17:38:45 +0100 | [diff] [blame] | 251 | USBEndpointDescriptor interruptIn; |
Christina Quast | db7b1ab | 2015-03-03 12:34:36 +0100 | [diff] [blame] | 252 | } __attribute__ ((packed)) CCIDDriverConfigurationDescriptors; |
| 253 | */ |
Christina Quast | 01bbdc3 | 2015-02-24 17:38:45 +0100 | [diff] [blame] | 254 | |
Harald Welte | ec4fe23 | 2015-11-07 18:41:25 +0100 | [diff] [blame^] | 255 | static const CCIDDriverConfigurationDescriptors configurationDescriptorCCID = { |
Christina Quast | db7b1ab | 2015-03-03 12:34:36 +0100 | [diff] [blame] | 256 | |
| 257 | // Standard USB configuration descriptor |
| 258 | { |
| 259 | sizeof(USBConfigurationDescriptor), |
| 260 | USBGenericDescriptor_CONFIGURATION, |
| 261 | sizeof(CCIDDriverConfigurationDescriptors), |
| 262 | 1, // One interface in this configuration |
| 263 | CFG_NUM_CCID, // This is configuration #1 |
| 264 | CCID_CONF_STR, // associated string descriptor |
| 265 | BOARD_USB_BMATTRIBUTES, |
| 266 | USBConfigurationDescriptor_POWER(100) |
| 267 | }, |
| 268 | // CCID interface descriptor |
| 269 | // Table 4.3-1 Interface Descriptor |
| 270 | // Interface descriptor |
| 271 | { |
| 272 | sizeof(USBInterfaceDescriptor), |
| 273 | USBGenericDescriptor_INTERFACE, |
| 274 | 0, // Interface 0 |
| 275 | 0, // No alternate settings |
| 276 | 3, // uses bulk-IN, bulk-OUT and interrupt IN |
| 277 | SMART_CARD_DEVICE_CLASS, |
| 278 | 0, // Subclass code |
| 279 | 0, // bulk transfers optional interrupt-IN |
| 280 | CCID_CONF_STR // associated string descriptor |
| 281 | }, |
| 282 | { |
| 283 | sizeof(CCIDDescriptor), // bLength: Size of this descriptor in bytes |
| 284 | CCID_DECRIPTOR_TYPE, // bDescriptorType:Functional descriptor type |
| 285 | CCID1_10, // bcdCCID: CCID version |
| 286 | 0, // bMaxSlotIndex: Value 0 indicates that one slot is supported |
| 287 | VOLTS_5_0, // bVoltageSupport |
| 288 | (1 << PROTOCOL_TO), // dwProtocols |
| 289 | 3580, // dwDefaultClock |
| 290 | 3580, // dwMaxClock |
| 291 | 0, // bNumClockSupported |
| 292 | 9600, // dwDataRate : 9600 bauds |
| 293 | 9600, // dwMaxDataRate : 9600 bauds |
| 294 | 0, // bNumDataRatesSupported |
| 295 | 0xfe, // dwMaxIFSD |
| 296 | 0, // dwSynchProtocols |
| 297 | 0, // dwMechanical |
| 298 | //0x00010042, // dwFeatures: Short APDU level exchanges |
| 299 | CCID_FEATURES_AUTO_CLOCK | CCID_FEATURES_AUTO_BAUD | |
| 300 | CCID_FEATURES_AUTO_PCONF | CCID_FEATURES_AUTO_PNEGO | CCID_FEATURES_EXC_TPDU, |
| 301 | 0x0000010F, // dwMaxCCIDMessageLength: For extended APDU level the value shall be between 261 + 10 |
| 302 | 0xFF, // bClassGetResponse: Echoes the class of the APDU |
| 303 | 0xFF, // bClassEnvelope: Echoes the class of the APDU |
| 304 | 0, // wLcdLayout: no LCD |
| 305 | 0, // bPINSupport: No PIN |
| 306 | 1 // bMaxCCIDBusySlot |
| 307 | }, |
| 308 | // Bulk-OUT endpoint descriptor |
| 309 | { |
| 310 | sizeof(USBEndpointDescriptor), |
| 311 | USBGenericDescriptor_ENDPOINT, |
| 312 | USBEndpointDescriptor_ADDRESS( USBEndpointDescriptor_OUT, CCID_EPT_DATA_OUT ), |
| 313 | USBEndpointDescriptor_BULK, |
| 314 | MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CCID_EPT_DATA_OUT), |
| 315 | USBEndpointDescriptor_MAXBULKSIZE_FS), |
| 316 | 0x00 // Does not apply to Bulk endpoints |
| 317 | }, |
| 318 | // Bulk-IN endpoint descriptor |
| 319 | { |
| 320 | sizeof(USBEndpointDescriptor), |
| 321 | USBGenericDescriptor_ENDPOINT, |
| 322 | USBEndpointDescriptor_ADDRESS( USBEndpointDescriptor_IN, CCID_EPT_DATA_IN ), |
| 323 | USBEndpointDescriptor_BULK, |
| 324 | MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CCID_EPT_DATA_IN), |
| 325 | USBEndpointDescriptor_MAXBULKSIZE_FS), |
| 326 | 0x00 // Does not apply to Bulk endpoints |
| 327 | }, |
| 328 | // Notification endpoint descriptor |
| 329 | { |
| 330 | sizeof(USBEndpointDescriptor), |
| 331 | USBGenericDescriptor_ENDPOINT, |
| 332 | USBEndpointDescriptor_ADDRESS( USBEndpointDescriptor_IN, CCID_EPT_NOTIFICATION ), |
| 333 | USBEndpointDescriptor_INTERRUPT, |
| 334 | MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CCID_EPT_NOTIFICATION), |
| 335 | USBEndpointDescriptor_MAXINTERRUPTSIZE_FS), |
| 336 | 0x10 |
| 337 | }, |
| 338 | }; |
| 339 | |
Christina Quast | 01bbdc3 | 2015-02-24 17:38:45 +0100 | [diff] [blame] | 340 | |
| 341 | /* SIM card emulator */ |
| 342 | typedef struct _SIMTraceDriverConfigurationDescriptorPhone { |
| 343 | |
| 344 | /** Standard configuration descriptor. */ |
Christina Quast | da373fd | 2015-02-27 15:25:22 +0100 | [diff] [blame] | 345 | USBConfigurationDescriptor configuration; |
| 346 | USBInterfaceDescriptor phone; |
| 347 | USBEndpointDescriptor phone_dataOut; |
| 348 | USBEndpointDescriptor phone_dataIn; |
| 349 | USBEndpointDescriptor phone_interruptIn; |
Christina Quast | 01bbdc3 | 2015-02-24 17:38:45 +0100 | [diff] [blame] | 350 | } __attribute__ ((packed)) SIMTraceDriverConfigurationDescriptorPhone; |
| 351 | |
Harald Welte | ec4fe23 | 2015-11-07 18:41:25 +0100 | [diff] [blame^] | 352 | static const SIMTraceDriverConfigurationDescriptorPhone configurationDescriptorPhone = { |
Christina Quast | 01bbdc3 | 2015-02-24 17:38:45 +0100 | [diff] [blame] | 353 | /* Standard configuration descriptor */ |
| 354 | { |
| 355 | sizeof(USBConfigurationDescriptor), |
| 356 | USBGenericDescriptor_CONFIGURATION, |
Christina Quast | 6d9dcfc | 2015-04-03 22:26:43 +0200 | [diff] [blame] | 357 | sizeof(SIMTraceDriverConfigurationDescriptorPhone), |
Christina Quast | 01bbdc3 | 2015-02-24 17:38:45 +0100 | [diff] [blame] | 358 | 1, /* There is one interface in this configuration */ |
Christina Quast | 10b2e5a | 2015-02-25 18:40:15 +0100 | [diff] [blame] | 359 | CFG_NUM_PHONE, /* configuration number */ |
Christina Quast | 01bbdc3 | 2015-02-24 17:38:45 +0100 | [diff] [blame] | 360 | PHONE_CONF_STR, /* string descriptor for this configuration */ |
| 361 | USBD_BMATTRIBUTES, |
| 362 | USBConfigurationDescriptor_POWER(100) |
| 363 | }, |
| 364 | /* Communication class interface standard descriptor */ |
| 365 | { |
| 366 | sizeof(USBInterfaceDescriptor), |
| 367 | USBGenericDescriptor_INTERFACE, |
| 368 | 0, /* This is interface #0 */ |
| 369 | 0, /* This is alternate setting #0 for this interface */ |
Christina Quast | b65b881 | 2015-04-04 10:51:37 +0200 | [diff] [blame] | 370 | 3, /* Number of endpoints */ |
Christina Quast | 01bbdc3 | 2015-02-24 17:38:45 +0100 | [diff] [blame] | 371 | 0xff, /* Descriptor Class: Vendor specific */ |
| 372 | 0, /* No subclass */ |
| 373 | 0, /* No l */ |
| 374 | PHONE_CONF_STR /* Third in string descriptor for this interface */ |
| 375 | }, |
| 376 | /* Bulk-OUT endpoint standard descriptor */ |
| 377 | { |
| 378 | sizeof(USBEndpointDescriptor), |
| 379 | USBGenericDescriptor_ENDPOINT, |
| 380 | USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_OUT, |
Christina Quast | 7123425 | 2015-04-03 11:35:59 +0200 | [diff] [blame] | 381 | PHONE_DATAOUT), |
Christina Quast | 01bbdc3 | 2015-02-24 17:38:45 +0100 | [diff] [blame] | 382 | USBEndpointDescriptor_BULK, |
Christina Quast | 7123425 | 2015-04-03 11:35:59 +0200 | [diff] [blame] | 383 | MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(PHONE_DATAOUT), |
Christina Quast | 01bbdc3 | 2015-02-24 17:38:45 +0100 | [diff] [blame] | 384 | USBEndpointDescriptor_MAXBULKSIZE_FS), |
| 385 | 0 /* Must be 0 for full-speed bulk endpoints */ |
| 386 | }, |
| 387 | /* Bulk-IN endpoint descriptor */ |
| 388 | { |
| 389 | sizeof(USBEndpointDescriptor), |
| 390 | USBGenericDescriptor_ENDPOINT, |
| 391 | USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN, |
Christina Quast | 7123425 | 2015-04-03 11:35:59 +0200 | [diff] [blame] | 392 | PHONE_DATAIN), |
Christina Quast | 01bbdc3 | 2015-02-24 17:38:45 +0100 | [diff] [blame] | 393 | USBEndpointDescriptor_BULK, |
Christina Quast | 7123425 | 2015-04-03 11:35:59 +0200 | [diff] [blame] | 394 | MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(PHONE_DATAIN), |
Christina Quast | 01bbdc3 | 2015-02-24 17:38:45 +0100 | [diff] [blame] | 395 | USBEndpointDescriptor_MAXBULKSIZE_FS), |
| 396 | 0 /* Must be 0 for full-speed bulk endpoints */ |
Christina Quast | da373fd | 2015-02-27 15:25:22 +0100 | [diff] [blame] | 397 | }, |
| 398 | /* Notification endpoint descriptor */ |
| 399 | { |
| 400 | sizeof(USBEndpointDescriptor), |
| 401 | USBGenericDescriptor_ENDPOINT, |
Christina Quast | 7123425 | 2015-04-03 11:35:59 +0200 | [diff] [blame] | 402 | USBEndpointDescriptor_ADDRESS( USBEndpointDescriptor_IN, PHONE_INT ), |
Christina Quast | da373fd | 2015-02-27 15:25:22 +0100 | [diff] [blame] | 403 | USBEndpointDescriptor_INTERRUPT, |
Christina Quast | 7123425 | 2015-04-03 11:35:59 +0200 | [diff] [blame] | 404 | MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(PHONE_INT), |
Christina Quast | da373fd | 2015-02-27 15:25:22 +0100 | [diff] [blame] | 405 | USBEndpointDescriptor_MAXINTERRUPTSIZE_FS), |
| 406 | 0x10 |
Christina Quast | 01bbdc3 | 2015-02-24 17:38:45 +0100 | [diff] [blame] | 407 | } |
| 408 | }; |
| 409 | |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 410 | |
| 411 | typedef struct _SIMTraceDriverConfigurationDescriptorMITM { |
| 412 | |
| 413 | /** Standard configuration descriptor. */ |
Christina Quast | da373fd | 2015-02-27 15:25:22 +0100 | [diff] [blame] | 414 | USBConfigurationDescriptor configuration; |
| 415 | USBInterfaceDescriptor simcard; |
Christina Quast | e01fb9a | 2015-04-04 19:56:23 +0200 | [diff] [blame] | 416 | /// CCID descriptor |
| 417 | CCIDDescriptor ccid; |
| 418 | /// Bulk OUT endpoint descriptor |
Christina Quast | da373fd | 2015-02-27 15:25:22 +0100 | [diff] [blame] | 419 | USBEndpointDescriptor simcard_dataOut; |
Christina Quast | e01fb9a | 2015-04-04 19:56:23 +0200 | [diff] [blame] | 420 | /// Bulk IN endpoint descriptor |
Christina Quast | da373fd | 2015-02-27 15:25:22 +0100 | [diff] [blame] | 421 | USBEndpointDescriptor simcard_dataIn; |
Christina Quast | e01fb9a | 2015-04-04 19:56:23 +0200 | [diff] [blame] | 422 | /// Interrupt OUT endpoint descriptor |
Christina Quast | da373fd | 2015-02-27 15:25:22 +0100 | [diff] [blame] | 423 | USBEndpointDescriptor simcard_interruptIn; |
Christina Quast | e01fb9a | 2015-04-04 19:56:23 +0200 | [diff] [blame] | 424 | |
Christina Quast | da373fd | 2015-02-27 15:25:22 +0100 | [diff] [blame] | 425 | USBInterfaceDescriptor phone; |
| 426 | USBEndpointDescriptor phone_dataOut; |
| 427 | USBEndpointDescriptor phone_dataIn; |
| 428 | USBEndpointDescriptor phone_interruptIn; |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 429 | |
Christina Quast | 01bbdc3 | 2015-02-24 17:38:45 +0100 | [diff] [blame] | 430 | } __attribute__ ((packed)) SIMTraceDriverConfigurationDescriptorMITM; |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 431 | |
Harald Welte | ec4fe23 | 2015-11-07 18:41:25 +0100 | [diff] [blame^] | 432 | static const SIMTraceDriverConfigurationDescriptorMITM configurationDescriptorMITM = { |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 433 | /* Standard configuration descriptor */ |
| 434 | { |
| 435 | sizeof(USBConfigurationDescriptor), |
| 436 | USBGenericDescriptor_CONFIGURATION, |
Christina Quast | 968b974 | 2015-02-25 14:10:12 +0100 | [diff] [blame] | 437 | sizeof(SIMTraceDriverConfigurationDescriptorMITM), |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 438 | 2, /* There are two interfaces in this configuration */ |
Christina Quast | 10b2e5a | 2015-02-25 18:40:15 +0100 | [diff] [blame] | 439 | CFG_NUM_MITM, /* configuration number */ |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 440 | MITM_CONF_STR, /* string descriptor for this configuration */ |
| 441 | USBD_BMATTRIBUTES, |
| 442 | USBConfigurationDescriptor_POWER(100) |
| 443 | }, |
Christina Quast | e01fb9a | 2015-04-04 19:56:23 +0200 | [diff] [blame] | 444 | // CCID interface descriptor |
| 445 | // Table 4.3-1 Interface Descriptor |
| 446 | // Interface descriptor |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 447 | { |
| 448 | sizeof(USBInterfaceDescriptor), |
| 449 | USBGenericDescriptor_INTERFACE, |
Christina Quast | e01fb9a | 2015-04-04 19:56:23 +0200 | [diff] [blame] | 450 | 0, // Interface 0 |
| 451 | 0, // No alternate settings |
| 452 | 3, // uses bulk-IN, bulk-OUT and interrupt IN |
| 453 | SMART_CARD_DEVICE_CLASS, |
| 454 | 0, // Subclass code |
| 455 | 0, // bulk transfers optional interrupt-IN |
| 456 | CCID_CONF_STR // associated string descriptor |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 457 | }, |
Christina Quast | e01fb9a | 2015-04-04 19:56:23 +0200 | [diff] [blame] | 458 | { |
| 459 | sizeof(CCIDDescriptor), // bLength: Size of this descriptor in bytes |
| 460 | CCID_DECRIPTOR_TYPE, // bDescriptorType:Functional descriptor type |
| 461 | CCID1_10, // bcdCCID: CCID version |
| 462 | 0, // bMaxSlotIndex: Value 0 indicates that one slot is supported |
| 463 | VOLTS_5_0, // bVoltageSupport |
| 464 | (1 << PROTOCOL_TO), // dwProtocols |
| 465 | 3580, // dwDefaultClock |
| 466 | 3580, // dwMaxClock |
| 467 | 0, // bNumClockSupported |
| 468 | 9600, // dwDataRate : 9600 bauds |
| 469 | 9600, // dwMaxDataRate : 9600 bauds |
| 470 | 0, // bNumDataRatesSupported |
| 471 | 0xfe, // dwMaxIFSD |
| 472 | 0, // dwSynchProtocols |
| 473 | 0, // dwMechanical |
| 474 | //0x00010042, // dwFeatures: Short APDU level exchanges |
| 475 | CCID_FEATURES_AUTO_CLOCK | CCID_FEATURES_AUTO_BAUD | |
| 476 | CCID_FEATURES_AUTO_PCONF | CCID_FEATURES_AUTO_PNEGO | CCID_FEATURES_EXC_TPDU, |
| 477 | 0x0000010F, // dwMaxCCIDMessageLength: For extended APDU level the value shall be between 261 + 10 |
| 478 | 0xFF, // bClassGetResponse: Echoes the class of the APDU |
| 479 | 0xFF, // bClassEnvelope: Echoes the class of the APDU |
| 480 | 0, // wLcdLayout: no LCD |
| 481 | 0, // bPINSupport: No PIN |
| 482 | 1 // bMaxCCIDBusySlot |
| 483 | }, |
| 484 | // Bulk-OUT endpoint descriptor |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 485 | { |
| 486 | sizeof(USBEndpointDescriptor), |
| 487 | USBGenericDescriptor_ENDPOINT, |
Christina Quast | e01fb9a | 2015-04-04 19:56:23 +0200 | [diff] [blame] | 488 | USBEndpointDescriptor_ADDRESS( USBEndpointDescriptor_OUT, CCID_EPT_DATA_OUT ), |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 489 | USBEndpointDescriptor_BULK, |
Christina Quast | e01fb9a | 2015-04-04 19:56:23 +0200 | [diff] [blame] | 490 | MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CCID_EPT_DATA_OUT), |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 491 | USBEndpointDescriptor_MAXBULKSIZE_FS), |
Christina Quast | e01fb9a | 2015-04-04 19:56:23 +0200 | [diff] [blame] | 492 | 0x00 // Does not apply to Bulk endpoints |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 493 | }, |
Christina Quast | e01fb9a | 2015-04-04 19:56:23 +0200 | [diff] [blame] | 494 | // Bulk-IN endpoint descriptor |
Christina Quast | 01bbdc3 | 2015-02-24 17:38:45 +0100 | [diff] [blame] | 495 | { |
| 496 | sizeof(USBEndpointDescriptor), |
| 497 | USBGenericDescriptor_ENDPOINT, |
Christina Quast | e01fb9a | 2015-04-04 19:56:23 +0200 | [diff] [blame] | 498 | USBEndpointDescriptor_ADDRESS( USBEndpointDescriptor_IN, CCID_EPT_DATA_IN ), |
Christina Quast | 01bbdc3 | 2015-02-24 17:38:45 +0100 | [diff] [blame] | 499 | USBEndpointDescriptor_BULK, |
Christina Quast | e01fb9a | 2015-04-04 19:56:23 +0200 | [diff] [blame] | 500 | MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CCID_EPT_DATA_IN), |
Christina Quast | 01bbdc3 | 2015-02-24 17:38:45 +0100 | [diff] [blame] | 501 | USBEndpointDescriptor_MAXBULKSIZE_FS), |
Christina Quast | e01fb9a | 2015-04-04 19:56:23 +0200 | [diff] [blame] | 502 | 0x00 // Does not apply to Bulk endpoints |
Christina Quast | 968b974 | 2015-02-25 14:10:12 +0100 | [diff] [blame] | 503 | }, |
Christina Quast | e01fb9a | 2015-04-04 19:56:23 +0200 | [diff] [blame] | 504 | // Notification endpoint descriptor |
Christina Quast | da373fd | 2015-02-27 15:25:22 +0100 | [diff] [blame] | 505 | { |
| 506 | sizeof(USBEndpointDescriptor), |
| 507 | USBGenericDescriptor_ENDPOINT, |
Christina Quast | e01fb9a | 2015-04-04 19:56:23 +0200 | [diff] [blame] | 508 | USBEndpointDescriptor_ADDRESS( USBEndpointDescriptor_IN, CCID_EPT_NOTIFICATION ), |
Christina Quast | da373fd | 2015-02-27 15:25:22 +0100 | [diff] [blame] | 509 | USBEndpointDescriptor_INTERRUPT, |
Christina Quast | e01fb9a | 2015-04-04 19:56:23 +0200 | [diff] [blame] | 510 | MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CCID_EPT_NOTIFICATION), |
Christina Quast | da373fd | 2015-02-27 15:25:22 +0100 | [diff] [blame] | 511 | USBEndpointDescriptor_MAXINTERRUPTSIZE_FS), |
| 512 | 0x10 |
| 513 | }, |
Christina Quast | 01bbdc3 | 2015-02-24 17:38:45 +0100 | [diff] [blame] | 514 | /* Communication class interface standard descriptor */ |
| 515 | { |
| 516 | sizeof(USBInterfaceDescriptor), |
| 517 | USBGenericDescriptor_INTERFACE, |
| 518 | 1, /* This is interface #1 */ |
| 519 | 0, /* This is alternate setting #0 for this interface */ |
Christina Quast | 99d80ff | 2015-04-03 22:26:07 +0200 | [diff] [blame] | 520 | 3, /* Number of endpoints */ |
Christina Quast | 01bbdc3 | 2015-02-24 17:38:45 +0100 | [diff] [blame] | 521 | 0xff, |
| 522 | 0, |
Christina Quast | bfd7354 | 2015-05-08 16:00:51 +0200 | [diff] [blame] | 523 | 0, |
| 524 | PHONE_CONF_STR, /* string descriptor for this interface */ |
Christina Quast | 01bbdc3 | 2015-02-24 17:38:45 +0100 | [diff] [blame] | 525 | }, |
| 526 | /* Bulk-OUT endpoint standard descriptor */ |
| 527 | { |
| 528 | sizeof(USBEndpointDescriptor), |
| 529 | USBGenericDescriptor_ENDPOINT, |
| 530 | USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_OUT, |
Christina Quast | 7123425 | 2015-04-03 11:35:59 +0200 | [diff] [blame] | 531 | PHONE_DATAOUT), |
Christina Quast | 01bbdc3 | 2015-02-24 17:38:45 +0100 | [diff] [blame] | 532 | USBEndpointDescriptor_BULK, |
Christina Quast | 7123425 | 2015-04-03 11:35:59 +0200 | [diff] [blame] | 533 | MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(PHONE_DATAOUT), |
Christina Quast | 01bbdc3 | 2015-02-24 17:38:45 +0100 | [diff] [blame] | 534 | USBEndpointDescriptor_MAXBULKSIZE_FS), |
| 535 | 0 /* Must be 0 for full-speed bulk endpoints */ |
| 536 | }, |
| 537 | /* Bulk-IN endpoint descriptor */ |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 538 | { |
| 539 | sizeof(USBEndpointDescriptor), |
| 540 | USBGenericDescriptor_ENDPOINT, |
| 541 | USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN, |
Christina Quast | 7123425 | 2015-04-03 11:35:59 +0200 | [diff] [blame] | 542 | PHONE_DATAIN), |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 543 | USBEndpointDescriptor_BULK, |
Christina Quast | 7123425 | 2015-04-03 11:35:59 +0200 | [diff] [blame] | 544 | MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(PHONE_DATAIN), |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 545 | USBEndpointDescriptor_MAXBULKSIZE_FS), |
| 546 | 0 /* Must be 0 for full-speed bulk endpoints */ |
Christina Quast | da373fd | 2015-02-27 15:25:22 +0100 | [diff] [blame] | 547 | }, |
| 548 | /* Notification endpoint descriptor */ |
| 549 | { |
| 550 | sizeof(USBEndpointDescriptor), |
| 551 | USBGenericDescriptor_ENDPOINT, |
Christina Quast | 7123425 | 2015-04-03 11:35:59 +0200 | [diff] [blame] | 552 | USBEndpointDescriptor_ADDRESS( USBEndpointDescriptor_IN, PHONE_INT ), |
Christina Quast | da373fd | 2015-02-27 15:25:22 +0100 | [diff] [blame] | 553 | USBEndpointDescriptor_INTERRUPT, |
Christina Quast | 7123425 | 2015-04-03 11:35:59 +0200 | [diff] [blame] | 554 | MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(PHONE_INT), |
Christina Quast | da373fd | 2015-02-27 15:25:22 +0100 | [diff] [blame] | 555 | USBEndpointDescriptor_MAXINTERRUPTSIZE_FS), |
| 556 | 0x10 |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 557 | } |
| 558 | }; |
| 559 | |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 560 | /** Standard USB device descriptor for the CDC serial driver */ |
| 561 | const USBDeviceDescriptor deviceDescriptor = { |
| 562 | |
| 563 | sizeof(USBDeviceDescriptor), |
| 564 | USBGenericDescriptor_DEVICE, |
| 565 | USBDeviceDescriptor_USB2_00, |
| 566 | 0xff, |
| 567 | // CDCDeviceDescriptor_CLASS, |
| 568 | 0xff, |
| 569 | // CDCDeviceDescriptor_SUBCLASS, |
| 570 | 0xff, |
| 571 | // CDCDeviceDescriptor_PROTOCOL, |
| 572 | BOARD_USB_ENDPOINTS_MAXPACKETSIZE(0), |
Christina Quast | 3735039 | 2015-05-08 16:47:26 +0200 | [diff] [blame] | 573 | SIMTRACE_VENDOR_ID, |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 574 | SIMTRACE_PRODUCT_ID, |
| 575 | 1, /* Release number */ |
| 576 | 0, /* No string descriptor for manufacturer */ |
| 577 | PRODUCT_STRING, /* Index of product string descriptor */ |
| 578 | 0, /* No string descriptor for serial number */ |
Christina Quast | db7b1ab | 2015-03-03 12:34:36 +0100 | [diff] [blame] | 579 | 4 /* Device has 4 possible configurations */ |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 580 | }; |
| 581 | |
Christina Quast | 968b974 | 2015-02-25 14:10:12 +0100 | [diff] [blame] | 582 | const USBConfigurationDescriptor *configurationDescriptorsArr[] = { |
Christina Quast | 0becc0c | 2015-04-04 13:04:06 +0200 | [diff] [blame] | 583 | &configurationDescriptorSniffer.configuration, |
| 584 | &configurationDescriptorCCID.configuration, |
| 585 | &configurationDescriptorPhone.configuration, |
| 586 | &configurationDescriptorMITM.configuration, |
Christina Quast | 01bbdc3 | 2015-02-24 17:38:45 +0100 | [diff] [blame] | 587 | }; |
| 588 | |
Christina Quast | bd5b8bd | 2015-05-14 17:25:41 +0200 | [diff] [blame] | 589 | /* AT91SAM3S only supports full speed, but not high speed USB */ |
Harald Welte | ec4fe23 | 2015-11-07 18:41:25 +0100 | [diff] [blame^] | 590 | static const USBDDriverDescriptors driverDescriptors = { |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 591 | &deviceDescriptor, |
Christina Quast | b06fc38 | 2015-04-06 23:30:21 +0200 | [diff] [blame] | 592 | (const USBConfigurationDescriptor **) &(configurationDescriptorsArr), /* first full-speed configuration descriptor */ |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 593 | 0, /* No full-speed device qualifier descriptor */ |
| 594 | 0, /* No full-speed other speed configuration */ |
| 595 | 0, /* No high-speed device descriptor */ |
| 596 | 0, /* No high-speed configuration descriptor */ |
| 597 | 0, /* No high-speed device qualifier descriptor */ |
| 598 | 0, /* No high-speed other speed configuration descriptor */ |
| 599 | stringDescriptors, |
Christina Quast | 54d0c1f | 2015-02-25 16:04:25 +0100 | [diff] [blame] | 600 | STRING_DESC_CNT /* cnt string descriptors in list */ |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 601 | }; |
| 602 | |
Christina Quast | 0ae0314 | 2015-02-25 18:43:46 +0100 | [diff] [blame] | 603 | |
| 604 | /*---------------------------------------------------------------------------- |
Christina Quast | 968b974 | 2015-02-25 14:10:12 +0100 | [diff] [blame] | 605 | * Functions |
| 606 | *----------------------------------------------------------------------------*/ |
| 607 | |
| 608 | /** |
| 609 | * \brief Configure 48MHz Clock for USB |
| 610 | */ |
| 611 | static void _ConfigureUsbClock(void) |
| 612 | { |
| 613 | /* Enable PLLB for USB */ |
Christina Quast | 968b974 | 2015-02-25 14:10:12 +0100 | [diff] [blame] | 614 | PMC->CKGR_PLLBR = CKGR_PLLBR_DIVB(5) |
| 615 | | CKGR_PLLBR_MULB(0xc) /* MULT+1=0xd*/ |
| 616 | | CKGR_PLLBR_PLLBCOUNT_Msk; |
| 617 | while((PMC->PMC_SR & PMC_SR_LOCKB) == 0); |
| 618 | /* USB Clock uses PLLB */ |
| 619 | PMC->PMC_USB = PMC_USB_USBDIV(0) /* /1 (no divider) */ |
| 620 | | PMC_USB_USBS; /* PLLB */ |
| 621 | } |
| 622 | |
| 623 | |
| 624 | void SIMtrace_USB_Initialize( void ) |
| 625 | { |
| 626 | _ConfigureUsbClock(); |
| 627 | // Get std USB driver |
| 628 | USBDDriver *pUsbd = USBD_GetDriver(); |
| 629 | |
| 630 | TRACE_DEBUG("."); |
| 631 | |
| 632 | // Initialize standard USB driver |
| 633 | USBDDriver_Initialize(pUsbd, |
| 634 | &driverDescriptors, |
Christina Quast | 968b974 | 2015-02-25 14:10:12 +0100 | [diff] [blame] | 635 | 0); // Multiple interface settings not supported |
Christina Quast | 968b974 | 2015-02-25 14:10:12 +0100 | [diff] [blame] | 636 | USBD_Init(); |
Christina Quast | 968b974 | 2015-02-25 14:10:12 +0100 | [diff] [blame] | 637 | USBD_Connect(); |
| 638 | |
| 639 | NVIC_EnableIRQ( UDP_IRQn ); |
| 640 | } |