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