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" |
Harald Welte | 1605564 | 2016-03-03 11:02:45 +0100 | [diff] [blame] | 35 | #include "simtrace.h" |
Harald Welte | 2fb5996 | 2016-02-28 12:34:26 +0100 | [diff] [blame] | 36 | #include "utils.h" |
Christina Quast | 968b974 | 2015-02-25 14:10:12 +0100 | [diff] [blame] | 37 | |
Christina Quast | db7b1ab | 2015-03-03 12:34:36 +0100 | [diff] [blame] | 38 | #include <cciddriverdescriptors.h> |
Harald Welte | 7ed6f3b | 2017-02-26 17:00:43 +0100 | [diff] [blame] | 39 | #include <usb/common/dfu/usb_dfu.h> |
| 40 | #include <usb/device/dfu/dfu.h> |
Christina Quast | db7b1ab | 2015-03-03 12:34:36 +0100 | [diff] [blame] | 41 | |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 42 | /*------------------------------------------------------------------------------ |
| 43 | * USB String descriptors |
| 44 | *------------------------------------------------------------------------------*/ |
| 45 | |
Christina Quast | 6032e79 | 2015-02-27 15:22:25 +0100 | [diff] [blame] | 46 | static const unsigned char langDesc[] = { |
| 47 | |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 48 | USBStringDescriptor_LENGTH(1), |
| 49 | USBGenericDescriptor_STRING, |
| 50 | USBStringDescriptor_ENGLISH_US |
Christina Quast | 6032e79 | 2015-02-27 15:22:25 +0100 | [diff] [blame] | 51 | }; |
| 52 | |
Harald Welte | 6d44c1f | 2015-11-07 19:01:30 +0100 | [diff] [blame] | 53 | const unsigned char manufStringDescriptor[] = { |
| 54 | |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 55 | USBStringDescriptor_LENGTH(24), |
| 56 | USBGenericDescriptor_STRING, |
| 57 | USBStringDescriptor_UNICODE('s'), |
| 58 | USBStringDescriptor_UNICODE('y'), |
| 59 | USBStringDescriptor_UNICODE('s'), |
| 60 | USBStringDescriptor_UNICODE('m'), |
| 61 | USBStringDescriptor_UNICODE('o'), |
| 62 | USBStringDescriptor_UNICODE('c'), |
| 63 | USBStringDescriptor_UNICODE('o'), |
| 64 | USBStringDescriptor_UNICODE('m'), |
| 65 | USBStringDescriptor_UNICODE(' '), |
| 66 | USBStringDescriptor_UNICODE('-'), |
| 67 | USBStringDescriptor_UNICODE(' '), |
| 68 | USBStringDescriptor_UNICODE('s'), |
| 69 | USBStringDescriptor_UNICODE('.'), |
| 70 | USBStringDescriptor_UNICODE('f'), |
| 71 | USBStringDescriptor_UNICODE('.'), |
| 72 | USBStringDescriptor_UNICODE('m'), |
| 73 | USBStringDescriptor_UNICODE('.'), |
| 74 | USBStringDescriptor_UNICODE('c'), |
| 75 | USBStringDescriptor_UNICODE('.'), |
| 76 | USBStringDescriptor_UNICODE(' '), |
| 77 | USBStringDescriptor_UNICODE('G'), |
| 78 | USBStringDescriptor_UNICODE('m'), |
| 79 | USBStringDescriptor_UNICODE('b'), |
| 80 | USBStringDescriptor_UNICODE('H'), |
Harald Welte | 6d44c1f | 2015-11-07 19:01:30 +0100 | [diff] [blame] | 81 | }; |
| 82 | |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 83 | const unsigned char productStringDescriptor[] = { |
| 84 | |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 85 | USBStringDescriptor_LENGTH(10), |
| 86 | USBGenericDescriptor_STRING, |
| 87 | USBStringDescriptor_UNICODE('S'), |
| 88 | USBStringDescriptor_UNICODE('I'), |
| 89 | USBStringDescriptor_UNICODE('M'), |
| 90 | USBStringDescriptor_UNICODE('t'), |
| 91 | USBStringDescriptor_UNICODE('r'), |
| 92 | USBStringDescriptor_UNICODE('a'), |
| 93 | USBStringDescriptor_UNICODE('c'), |
| 94 | USBStringDescriptor_UNICODE('e'), |
| 95 | USBStringDescriptor_UNICODE(' '), |
| 96 | USBStringDescriptor_UNICODE('2'), |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 97 | }; |
| 98 | |
| 99 | const unsigned char snifferConfigStringDescriptor[] = { |
| 100 | |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 101 | USBStringDescriptor_LENGTH(16), |
| 102 | USBGenericDescriptor_STRING, |
| 103 | USBStringDescriptor_UNICODE('S'), |
| 104 | USBStringDescriptor_UNICODE('I'), |
| 105 | USBStringDescriptor_UNICODE('M'), |
| 106 | USBStringDescriptor_UNICODE('t'), |
| 107 | USBStringDescriptor_UNICODE('r'), |
| 108 | USBStringDescriptor_UNICODE('a'), |
| 109 | USBStringDescriptor_UNICODE('c'), |
| 110 | USBStringDescriptor_UNICODE('e'), |
| 111 | USBStringDescriptor_UNICODE(' '), |
| 112 | USBStringDescriptor_UNICODE('S'), |
| 113 | USBStringDescriptor_UNICODE('n'), |
| 114 | USBStringDescriptor_UNICODE('i'), |
| 115 | USBStringDescriptor_UNICODE('f'), |
| 116 | USBStringDescriptor_UNICODE('f'), |
| 117 | USBStringDescriptor_UNICODE('e'), |
| 118 | USBStringDescriptor_UNICODE('r'), |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 119 | }; |
| 120 | |
| 121 | const unsigned char CCIDConfigStringDescriptor[] = { |
| 122 | |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 123 | USBStringDescriptor_LENGTH(13), |
| 124 | USBGenericDescriptor_STRING, |
| 125 | USBStringDescriptor_UNICODE('S'), |
| 126 | USBStringDescriptor_UNICODE('I'), |
| 127 | USBStringDescriptor_UNICODE('M'), |
| 128 | USBStringDescriptor_UNICODE('t'), |
| 129 | USBStringDescriptor_UNICODE('r'), |
| 130 | USBStringDescriptor_UNICODE('a'), |
| 131 | USBStringDescriptor_UNICODE('c'), |
| 132 | USBStringDescriptor_UNICODE('e'), |
| 133 | USBStringDescriptor_UNICODE(' '), |
| 134 | USBStringDescriptor_UNICODE('C'), |
| 135 | USBStringDescriptor_UNICODE('C'), |
| 136 | USBStringDescriptor_UNICODE('I'), |
| 137 | USBStringDescriptor_UNICODE('D'), |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 138 | }; |
| 139 | |
| 140 | const unsigned char phoneConfigStringDescriptor[] = { |
| 141 | |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 142 | USBStringDescriptor_LENGTH(14), |
| 143 | USBGenericDescriptor_STRING, |
| 144 | USBStringDescriptor_UNICODE('S'), |
| 145 | USBStringDescriptor_UNICODE('I'), |
| 146 | USBStringDescriptor_UNICODE('M'), |
| 147 | USBStringDescriptor_UNICODE('t'), |
| 148 | USBStringDescriptor_UNICODE('r'), |
| 149 | USBStringDescriptor_UNICODE('a'), |
| 150 | USBStringDescriptor_UNICODE('c'), |
| 151 | USBStringDescriptor_UNICODE('e'), |
| 152 | USBStringDescriptor_UNICODE(' '), |
| 153 | USBStringDescriptor_UNICODE('P'), |
| 154 | USBStringDescriptor_UNICODE('h'), |
| 155 | USBStringDescriptor_UNICODE('o'), |
| 156 | USBStringDescriptor_UNICODE('n'), |
| 157 | USBStringDescriptor_UNICODE('e'), |
Harald Welte | beb7293 | 2015-11-07 18:35:41 +0100 | [diff] [blame] | 158 | }; |
| 159 | |
Harald Welte | beb7293 | 2015-11-07 18:35:41 +0100 | [diff] [blame] | 160 | const unsigned char MITMConfigStringDescriptor[] = { |
| 161 | |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 162 | USBStringDescriptor_LENGTH(13), |
| 163 | USBGenericDescriptor_STRING, |
| 164 | USBStringDescriptor_UNICODE('S'), |
| 165 | USBStringDescriptor_UNICODE('I'), |
| 166 | USBStringDescriptor_UNICODE('M'), |
| 167 | USBStringDescriptor_UNICODE('t'), |
| 168 | USBStringDescriptor_UNICODE('r'), |
| 169 | USBStringDescriptor_UNICODE('a'), |
| 170 | USBStringDescriptor_UNICODE('c'), |
| 171 | USBStringDescriptor_UNICODE('e'), |
| 172 | USBStringDescriptor_UNICODE(' '), |
| 173 | USBStringDescriptor_UNICODE('M'), |
| 174 | USBStringDescriptor_UNICODE('I'), |
| 175 | USBStringDescriptor_UNICODE('T'), |
| 176 | USBStringDescriptor_UNICODE('M'), |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 177 | }; |
| 178 | |
Harald Welte | 57b3a25 | 2016-03-02 15:20:27 +0100 | [diff] [blame] | 179 | const unsigned char cardem_usim1_intf_str[] = { |
| 180 | |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 181 | USBStringDescriptor_LENGTH(18), |
| 182 | USBGenericDescriptor_STRING, |
| 183 | USBStringDescriptor_UNICODE('C'), |
| 184 | USBStringDescriptor_UNICODE('a'), |
| 185 | USBStringDescriptor_UNICODE('r'), |
| 186 | USBStringDescriptor_UNICODE('d'), |
| 187 | USBStringDescriptor_UNICODE('E'), |
| 188 | USBStringDescriptor_UNICODE('m'), |
| 189 | USBStringDescriptor_UNICODE('u'), |
| 190 | USBStringDescriptor_UNICODE('l'), |
| 191 | USBStringDescriptor_UNICODE('a'), |
| 192 | USBStringDescriptor_UNICODE('t'), |
| 193 | USBStringDescriptor_UNICODE('o'), |
| 194 | USBStringDescriptor_UNICODE('r'), |
| 195 | USBStringDescriptor_UNICODE(' '), |
| 196 | USBStringDescriptor_UNICODE('U'), |
| 197 | USBStringDescriptor_UNICODE('S'), |
| 198 | USBStringDescriptor_UNICODE('I'), |
| 199 | USBStringDescriptor_UNICODE('M'), |
| 200 | USBStringDescriptor_UNICODE('1'), |
Harald Welte | 57b3a25 | 2016-03-02 15:20:27 +0100 | [diff] [blame] | 201 | }; |
| 202 | |
| 203 | const unsigned char cardem_usim2_intf_str[] = { |
| 204 | |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 205 | USBStringDescriptor_LENGTH(18), |
| 206 | USBGenericDescriptor_STRING, |
| 207 | USBStringDescriptor_UNICODE('C'), |
| 208 | USBStringDescriptor_UNICODE('a'), |
| 209 | USBStringDescriptor_UNICODE('r'), |
| 210 | USBStringDescriptor_UNICODE('d'), |
| 211 | USBStringDescriptor_UNICODE('E'), |
| 212 | USBStringDescriptor_UNICODE('m'), |
| 213 | USBStringDescriptor_UNICODE('u'), |
| 214 | USBStringDescriptor_UNICODE('l'), |
| 215 | USBStringDescriptor_UNICODE('a'), |
| 216 | USBStringDescriptor_UNICODE('t'), |
| 217 | USBStringDescriptor_UNICODE('o'), |
| 218 | USBStringDescriptor_UNICODE('r'), |
| 219 | USBStringDescriptor_UNICODE(' '), |
| 220 | USBStringDescriptor_UNICODE('U'), |
| 221 | USBStringDescriptor_UNICODE('S'), |
| 222 | USBStringDescriptor_UNICODE('I'), |
| 223 | USBStringDescriptor_UNICODE('M'), |
| 224 | USBStringDescriptor_UNICODE('2'), |
Harald Welte | 57b3a25 | 2016-03-02 15:20:27 +0100 | [diff] [blame] | 225 | }; |
| 226 | |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 227 | enum strDescNum { |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 228 | PRODUCT_STRING = 1, |
| 229 | MANUF_STR, |
| 230 | SNIFFER_CONF_STR, |
| 231 | CCID_CONF_STR, |
| 232 | PHONE_CONF_STR, |
| 233 | MITM_CONF_STR, |
| 234 | CARDEM_USIM1_INTF_STR, |
| 235 | CARDEM_USIM2_INTF_STR, |
| 236 | STRING_DESC_CNT |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 237 | }; |
| 238 | |
| 239 | /** List of string descriptors used by the device */ |
Harald Welte | ec4fe23 | 2015-11-07 18:41:25 +0100 | [diff] [blame] | 240 | static const unsigned char *stringDescriptors[] = { |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 241 | langDesc, |
| 242 | [PRODUCT_STRING] = productStringDescriptor, |
| 243 | [MANUF_STR] = manufStringDescriptor, |
| 244 | [SNIFFER_CONF_STR] = snifferConfigStringDescriptor, |
| 245 | [CCID_CONF_STR] = CCIDConfigStringDescriptor, |
| 246 | [PHONE_CONF_STR] = phoneConfigStringDescriptor, |
| 247 | [MITM_CONF_STR] = MITMConfigStringDescriptor, |
| 248 | [CARDEM_USIM1_INTF_STR] = cardem_usim1_intf_str, |
| 249 | [CARDEM_USIM2_INTF_STR] = cardem_usim2_intf_str, |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 250 | }; |
| 251 | |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 252 | /*------------------------------------------------------------------------------ |
| 253 | * USB Device descriptors |
| 254 | *------------------------------------------------------------------------------*/ |
| 255 | |
Harald Welte | 2fb5996 | 2016-02-28 12:34:26 +0100 | [diff] [blame] | 256 | #ifdef HAVE_SNIFFER |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 257 | typedef struct _SIMTraceDriverConfigurationDescriptorSniffer { |
| 258 | |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 259 | /** Standard configuration descriptor. */ |
| 260 | USBConfigurationDescriptor configuration; |
| 261 | USBInterfaceDescriptor sniffer; |
| 262 | USBEndpointDescriptor sniffer_dataOut; |
| 263 | USBEndpointDescriptor sniffer_dataIn; |
| 264 | USBEndpointDescriptor sniffer_interruptIn; |
Harald Welte | 7ed6f3b | 2017-02-26 17:00:43 +0100 | [diff] [blame] | 265 | DFURT_IF_DESCRIPTOR_STRUCT; |
Christina Quast | 01bbdc3 | 2015-02-24 17:38:45 +0100 | [diff] [blame] | 266 | } __attribute__ ((packed)) SIMTraceDriverConfigurationDescriptorSniffer; |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 267 | |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 268 | static const SIMTraceDriverConfigurationDescriptorSniffer |
| 269 | configurationDescriptorSniffer = { |
| 270 | /* Standard configuration descriptor */ |
| 271 | { |
| 272 | .bLength = sizeof(USBConfigurationDescriptor), |
| 273 | .bDescriptorType = USBGenericDescriptor_CONFIGURATION, |
| 274 | .wTotalLength = sizeof(SIMTraceDriverConfigurationDescriptorSniffer), |
Harald Welte | 7ed6f3b | 2017-02-26 17:00:43 +0100 | [diff] [blame] | 275 | .bNumInterfaces = 1+DFURT_NUM_IF, |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 276 | .bConfigurationValue = CFG_NUM_SNIFF, |
| 277 | .iConfiguration = SNIFFER_CONF_STR, |
| 278 | .bmAttributes = USBD_BMATTRIBUTES, |
| 279 | .bMaxPower = USBConfigurationDescriptor_POWER(100), |
| 280 | }, |
| 281 | /* Communication class interface standard descriptor */ |
| 282 | { |
| 283 | .bLength = sizeof(USBInterfaceDescriptor), |
| 284 | .bDescriptorType = USBGenericDescriptor_INTERFACE, |
| 285 | .bInterfaceNumber = 0, |
| 286 | .bAlternateSetting = 0, |
| 287 | .bNumEndpoints = 3, |
| 288 | .bInterfaceClass = 0xff, |
| 289 | .bInterfaceSubClass = 0, |
| 290 | .bInterfaceProtocol = 0, |
| 291 | .iInterface = SNIFFER_CONF_STR, |
| 292 | }, |
| 293 | /* Bulk-OUT endpoint standard descriptor */ |
| 294 | { |
| 295 | .bLength = sizeof(USBEndpointDescriptor), |
| 296 | .bDescriptorType = USBGenericDescriptor_ENDPOINT, |
| 297 | .bEndpointAddress = USBEndpointDescriptor_ADDRESS( |
| 298 | USBEndpointDescriptor_OUT, |
| 299 | PHONE_DATAOUT), |
| 300 | .bmAttributes = USBEndpointDescriptor_BULK, |
| 301 | .wMaxPacketSize = MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE( |
| 302 | PHONE_DATAOUT), |
| 303 | USBEndpointDescriptor_MAXBULKSIZE_FS), |
| 304 | .bInterval = 0, |
| 305 | }, |
| 306 | /* Bulk-IN endpoint descriptor */ |
| 307 | { |
| 308 | .bLength = sizeof(USBEndpointDescriptor), |
| 309 | .bDescriptorType = USBGenericDescriptor_ENDPOINT, |
| 310 | .bEndpointAddress = USBEndpointDescriptor_ADDRESS( |
| 311 | USBEndpointDescriptor_IN, |
| 312 | PHONE_DATAIN), |
| 313 | .bmAttributes = USBEndpointDescriptor_BULK, |
| 314 | .wMaxPacketSize = MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE( |
| 315 | PHONE_DATAIN), |
| 316 | USBEndpointDescriptor_MAXBULKSIZE_FS), |
| 317 | .bInterval = 0, |
| 318 | }, |
| 319 | // Notification endpoint descriptor |
| 320 | { |
| 321 | .bLength = sizeof(USBEndpointDescriptor), |
| 322 | .bDescriptorType = USBGenericDescriptor_ENDPOINT, |
| 323 | .bEndpointAddress = USBEndpointDescriptor_ADDRESS( |
| 324 | USBEndpointDescriptor_IN, |
| 325 | PHONE_INT), |
| 326 | .bmAttributes = USBEndpointDescriptor_INTERRUPT, |
| 327 | .wMaxPacketSize = MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE( |
| 328 | PHONE_INT), |
| 329 | USBEndpointDescriptor_MAXINTERRUPTSIZE_FS), |
| 330 | .bInterval = 0x10, |
Harald Welte | 7ed6f3b | 2017-02-26 17:00:43 +0100 | [diff] [blame] | 331 | }, |
| 332 | DFURT_IF_DESCRIPTOR(1, 0), |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 333 | }; |
Harald Welte | 2fb5996 | 2016-02-28 12:34:26 +0100 | [diff] [blame] | 334 | #endif /* HAVE_SNIFFER */ |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 335 | |
Harald Welte | 2fb5996 | 2016-02-28 12:34:26 +0100 | [diff] [blame] | 336 | #ifdef HAVE_CCID |
Harald Welte | ec4fe23 | 2015-11-07 18:41:25 +0100 | [diff] [blame] | 337 | static const CCIDDriverConfigurationDescriptors configurationDescriptorCCID = { |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 338 | // Standard USB configuration descriptor |
| 339 | { |
| 340 | .bLength = sizeof(USBConfigurationDescriptor), |
| 341 | .bDescriptorType = USBGenericDescriptor_CONFIGURATION, |
| 342 | .wTotalLength = sizeof(CCIDDriverConfigurationDescriptors), |
Harald Welte | 7ed6f3b | 2017-02-26 17:00:43 +0100 | [diff] [blame] | 343 | .bNumInterfaces = 1+DFURT_NUM_IF, |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 344 | .bConfigurationValue = CFG_NUM_CCID, |
| 345 | .iConfiguration = CCID_CONF_STR, |
| 346 | .bmAttributes = BOARD_USB_BMATTRIBUTES, |
| 347 | .bMaxPower = USBConfigurationDescriptor_POWER(100), |
| 348 | }, |
| 349 | // CCID interface descriptor |
| 350 | // Table 4.3-1 Interface Descriptor |
| 351 | // Interface descriptor |
| 352 | { |
| 353 | .bLength = sizeof(USBInterfaceDescriptor), |
| 354 | .bDescriptorType = USBGenericDescriptor_INTERFACE, |
| 355 | .bInterfaceNumber = 0, |
| 356 | .bAlternateSetting = 0, |
| 357 | .bNumEndpoints = 3, |
| 358 | .bInterfaceClass = SMART_CARD_DEVICE_CLASS, |
| 359 | .bInterfaceSubClass = 0, |
| 360 | .bInterfaceProtocol = 0, |
| 361 | .iInterface = CCID_CONF_STR, |
| 362 | }, |
| 363 | { |
| 364 | .bLength = sizeof(CCIDDescriptor), |
| 365 | .bDescriptorType = CCID_DECRIPTOR_TYPE, |
| 366 | .bcdCCID = CCID1_10, // CCID version |
| 367 | .bMaxSlotIndex = 0, // 1 slot |
| 368 | .bVoltageSupport = VOLTS_3_0, |
| 369 | .dwProtocols = (1 << PROTOCOL_TO), |
| 370 | .dwDefaultClock = 3580, |
| 371 | .dwMaximumClock = 3580, |
| 372 | .bNumClockSupported = 0, |
| 373 | .dwDataRate = 9600, |
| 374 | .dwMaxDataRate = 9600, |
| 375 | .bNumDataRatesSupported = 0, |
| 376 | .dwMaxIFSD = 0xfe, |
| 377 | .dwSynchProtocols = 0, |
| 378 | .dwMechanical = 0, |
| 379 | .dwFeatures = CCID_FEATURES_AUTO_CLOCK | CCID_FEATURES_AUTO_BAUD | |
| 380 | CCID_FEATURES_AUTO_PCONF | CCID_FEATURES_AUTO_PNEGO | |
| 381 | CCID_FEATURES_EXC_TPDU, |
| 382 | .dwMaxCCIDMessageLength = 271, /* For extended APDU |
| 383 | level the value shall |
| 384 | be between 261 + 10 */ |
| 385 | .bClassGetResponse = 0xFF, // Echoes the class of the APDU |
| 386 | .bClassEnvelope = 0xFF, // Echoes the class of the APDU |
| 387 | .wLcdLayout = 0, // wLcdLayout: no LCD |
| 388 | .bPINSupport = 0, // bPINSupport: No PIN |
| 389 | .bMaxCCIDBusySlots = 1, |
| 390 | }, |
| 391 | // Bulk-OUT endpoint descriptor |
| 392 | { |
| 393 | .bLength = sizeof(USBEndpointDescriptor), |
| 394 | .bDescriptorType = USBGenericDescriptor_ENDPOINT, |
| 395 | .bEndpointAddress = |
| 396 | USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_OUT, |
| 397 | CCID_EPT_DATA_OUT), |
| 398 | .bmAttributes = USBEndpointDescriptor_BULK, |
| 399 | .wMaxPacketSize = MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE( |
| 400 | CCID_EPT_DATA_OUT), |
| 401 | USBEndpointDescriptor_MAXBULKSIZE_FS), |
| 402 | .bInterval = 0x00, |
| 403 | }, |
| 404 | // Bulk-IN endpoint descriptor |
| 405 | { |
| 406 | .bLength = sizeof(USBEndpointDescriptor), |
| 407 | .bDescriptorType = USBGenericDescriptor_ENDPOINT, |
| 408 | .bEndpointAddress = |
| 409 | USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN, |
| 410 | CCID_EPT_DATA_IN), |
| 411 | .bmAttributes = USBEndpointDescriptor_BULK, |
| 412 | .wMaxPacketSize = MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE( |
| 413 | CCID_EPT_DATA_IN), |
| 414 | USBEndpointDescriptor_MAXBULKSIZE_FS), |
| 415 | .bInterval = 0x00, |
| 416 | }, |
| 417 | // Notification endpoint descriptor |
| 418 | { |
| 419 | .bLength = sizeof(USBEndpointDescriptor), |
| 420 | .bDescriptorType = USBGenericDescriptor_ENDPOINT, |
| 421 | .bEndpointAddress = |
| 422 | USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN, |
| 423 | CCID_EPT_NOTIFICATION), |
| 424 | .bmAttributes = USBEndpointDescriptor_INTERRUPT, |
| 425 | .wMaxPacketSize = MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE( |
| 426 | CCID_EPT_NOTIFICATION), |
| 427 | USBEndpointDescriptor_MAXINTERRUPTSIZE_FS), |
| 428 | .bInterval = 0x10, |
| 429 | }, |
Harald Welte | 7ed6f3b | 2017-02-26 17:00:43 +0100 | [diff] [blame] | 430 | DFURT_IF_DESCRIPTOR(1, 0), |
Christina Quast | db7b1ab | 2015-03-03 12:34:36 +0100 | [diff] [blame] | 431 | }; |
Harald Welte | 2fb5996 | 2016-02-28 12:34:26 +0100 | [diff] [blame] | 432 | #endif /* HAVE_CCID */ |
Christina Quast | db7b1ab | 2015-03-03 12:34:36 +0100 | [diff] [blame] | 433 | |
Harald Welte | 2fb5996 | 2016-02-28 12:34:26 +0100 | [diff] [blame] | 434 | #ifdef HAVE_CARDEM |
Christina Quast | 01bbdc3 | 2015-02-24 17:38:45 +0100 | [diff] [blame] | 435 | /* SIM card emulator */ |
| 436 | typedef struct _SIMTraceDriverConfigurationDescriptorPhone { |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 437 | /* Standard configuration descriptor. */ |
| 438 | USBConfigurationDescriptor configuration; |
| 439 | USBInterfaceDescriptor phone; |
| 440 | USBEndpointDescriptor phone_dataOut; |
| 441 | USBEndpointDescriptor phone_dataIn; |
| 442 | USBEndpointDescriptor phone_interruptIn; |
Harald Welte | 57b3a25 | 2016-03-02 15:20:27 +0100 | [diff] [blame] | 443 | #ifdef CARDEMU_SECOND_UART |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 444 | USBInterfaceDescriptor usim2; |
| 445 | USBEndpointDescriptor usim2_dataOut; |
| 446 | USBEndpointDescriptor usim2_dataIn; |
| 447 | USBEndpointDescriptor usim2_interruptIn; |
Harald Welte | 57b3a25 | 2016-03-02 15:20:27 +0100 | [diff] [blame] | 448 | #endif |
Harald Welte | 7ed6f3b | 2017-02-26 17:00:43 +0100 | [diff] [blame] | 449 | DFURT_IF_DESCRIPTOR_STRUCT; |
Christina Quast | 01bbdc3 | 2015-02-24 17:38:45 +0100 | [diff] [blame] | 450 | } __attribute__ ((packed)) SIMTraceDriverConfigurationDescriptorPhone; |
| 451 | |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 452 | static const SIMTraceDriverConfigurationDescriptorPhone |
| 453 | configurationDescriptorPhone = { |
| 454 | /* Standard configuration descriptor */ |
| 455 | { |
| 456 | sizeof(USBConfigurationDescriptor), |
| 457 | USBGenericDescriptor_CONFIGURATION, |
| 458 | sizeof(SIMTraceDriverConfigurationDescriptorPhone), |
Harald Welte | 57b3a25 | 2016-03-02 15:20:27 +0100 | [diff] [blame] | 459 | #ifdef CARDEMU_SECOND_UART |
Harald Welte | 7ed6f3b | 2017-02-26 17:00:43 +0100 | [diff] [blame] | 460 | 2+DFURT_NUM_IF, |
Harald Welte | 57b3a25 | 2016-03-02 15:20:27 +0100 | [diff] [blame] | 461 | #else |
Harald Welte | 7ed6f3b | 2017-02-26 17:00:43 +0100 | [diff] [blame] | 462 | 1+DFURT_NUM_IF, /* There is one interface in this configuration */ |
Harald Welte | 57b3a25 | 2016-03-02 15:20:27 +0100 | [diff] [blame] | 463 | #endif |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 464 | CFG_NUM_PHONE, /* configuration number */ |
| 465 | PHONE_CONF_STR, /* string descriptor for this configuration */ |
| 466 | USBD_BMATTRIBUTES, |
| 467 | USBConfigurationDescriptor_POWER(100) |
| 468 | }, |
| 469 | /* Communication class interface standard descriptor */ |
| 470 | { |
| 471 | sizeof(USBInterfaceDescriptor), |
| 472 | USBGenericDescriptor_INTERFACE, |
| 473 | 0, /* This is interface #0 */ |
| 474 | 0, /* This is alternate setting #0 for this interface */ |
| 475 | 3, /* Number of endpoints */ |
| 476 | 0xff, /* Descriptor Class: Vendor specific */ |
| 477 | 0, /* No subclass */ |
| 478 | 0, /* No l */ |
| 479 | CARDEM_USIM1_INTF_STR |
| 480 | }, |
| 481 | /* Bulk-OUT endpoint standard descriptor */ |
| 482 | { |
| 483 | sizeof(USBEndpointDescriptor), |
| 484 | USBGenericDescriptor_ENDPOINT, |
| 485 | USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_OUT, |
| 486 | PHONE_DATAOUT), |
| 487 | USBEndpointDescriptor_BULK, |
| 488 | MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(PHONE_DATAOUT), |
| 489 | USBEndpointDescriptor_MAXBULKSIZE_FS), |
| 490 | 0 /* Must be 0 for full-speed bulk endpoints */ |
| 491 | }, |
| 492 | /* Bulk-IN endpoint descriptor */ |
| 493 | { |
| 494 | sizeof(USBEndpointDescriptor), |
| 495 | USBGenericDescriptor_ENDPOINT, |
| 496 | USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN, |
| 497 | PHONE_DATAIN), |
| 498 | USBEndpointDescriptor_BULK, |
| 499 | MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(PHONE_DATAIN), |
| 500 | USBEndpointDescriptor_MAXBULKSIZE_FS), |
| 501 | 0 /* Must be 0 for full-speed bulk endpoints */ |
| 502 | }, |
| 503 | /* Notification endpoint descriptor */ |
| 504 | { |
| 505 | sizeof(USBEndpointDescriptor), |
| 506 | USBGenericDescriptor_ENDPOINT, |
| 507 | USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN, |
| 508 | PHONE_INT), |
| 509 | USBEndpointDescriptor_INTERRUPT, |
| 510 | MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(PHONE_INT), |
| 511 | USBEndpointDescriptor_MAXINTERRUPTSIZE_FS), |
| 512 | 0x10 |
| 513 | }, |
Harald Welte | 57b3a25 | 2016-03-02 15:20:27 +0100 | [diff] [blame] | 514 | #ifdef CARDEMU_SECOND_UART |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 515 | /* Communication class interface standard descriptor */ |
| 516 | { |
| 517 | sizeof(USBInterfaceDescriptor), |
| 518 | USBGenericDescriptor_INTERFACE, |
Harald Welte | 6dcacf3 | 2016-03-19 14:01:31 +0100 | [diff] [blame] | 519 | 1, /* This is interface #1 */ |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 520 | 0, /* This is alternate setting #0 for this interface */ |
| 521 | 3, /* Number of endpoints */ |
| 522 | 0xff, /* Descriptor Class: Vendor specific */ |
| 523 | 0, /* No subclass */ |
| 524 | 0, /* No l */ |
| 525 | CARDEM_USIM2_INTF_STR |
| 526 | }, |
| 527 | /* Bulk-OUT endpoint standard descriptor */ |
| 528 | { |
| 529 | sizeof(USBEndpointDescriptor), |
| 530 | USBGenericDescriptor_ENDPOINT, |
| 531 | USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_OUT, |
| 532 | CARDEM_USIM2_DATAOUT), |
| 533 | USBEndpointDescriptor_BULK, |
| 534 | MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CARDEM_USIM2_DATAOUT), |
| 535 | USBEndpointDescriptor_MAXBULKSIZE_FS), |
| 536 | 0 /* Must be 0 for full-speed bulk endpoints */ |
| 537 | } |
| 538 | , |
| 539 | /* Bulk-IN endpoint descriptor */ |
| 540 | { |
| 541 | sizeof(USBEndpointDescriptor), |
| 542 | USBGenericDescriptor_ENDPOINT, |
| 543 | USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN, |
| 544 | CARDEM_USIM2_DATAIN), |
| 545 | USBEndpointDescriptor_BULK, |
| 546 | MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CARDEM_USIM2_DATAIN), |
| 547 | USBEndpointDescriptor_MAXBULKSIZE_FS), |
| 548 | 0 /* Must be 0 for full-speed bulk endpoints */ |
| 549 | }, |
| 550 | /* Notification endpoint descriptor */ |
| 551 | { |
| 552 | sizeof(USBEndpointDescriptor), |
| 553 | USBGenericDescriptor_ENDPOINT, |
| 554 | USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN, |
| 555 | CARDEM_USIM2_INT), |
| 556 | USBEndpointDescriptor_INTERRUPT, |
| 557 | MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CARDEM_USIM2_INT), |
| 558 | USBEndpointDescriptor_MAXINTERRUPTSIZE_FS), |
| 559 | 0x10 |
| 560 | }, |
Harald Welte | 7ed6f3b | 2017-02-26 17:00:43 +0100 | [diff] [blame] | 561 | DFURT_IF_DESCRIPTOR(2, 0), |
| 562 | #else |
| 563 | DFURT_IF_DESCRIPTOR(1, 0), |
Harald Welte | 57b3a25 | 2016-03-02 15:20:27 +0100 | [diff] [blame] | 564 | #endif |
Christina Quast | 01bbdc3 | 2015-02-24 17:38:45 +0100 | [diff] [blame] | 565 | }; |
Harald Welte | 2fb5996 | 2016-02-28 12:34:26 +0100 | [diff] [blame] | 566 | #endif /* HAVE_CARDEM */ |
Christina Quast | 01bbdc3 | 2015-02-24 17:38:45 +0100 | [diff] [blame] | 567 | |
Harald Welte | 2fb5996 | 2016-02-28 12:34:26 +0100 | [diff] [blame] | 568 | #ifdef HAVE_MITM |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 569 | typedef struct _SIMTraceDriverConfigurationDescriptorMITM { |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 570 | /* Standard configuration descriptor. */ |
| 571 | USBConfigurationDescriptor configuration; |
| 572 | USBInterfaceDescriptor simcard; |
| 573 | /// CCID descriptor |
| 574 | CCIDDescriptor ccid; |
| 575 | /// Bulk OUT endpoint descriptor |
| 576 | USBEndpointDescriptor simcard_dataOut; |
| 577 | /// Bulk IN endpoint descriptor |
| 578 | USBEndpointDescriptor simcard_dataIn; |
| 579 | /// Interrupt OUT endpoint descriptor |
| 580 | USBEndpointDescriptor simcard_interruptIn; |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 581 | |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 582 | USBInterfaceDescriptor phone; |
| 583 | USBEndpointDescriptor phone_dataOut; |
| 584 | USBEndpointDescriptor phone_dataIn; |
| 585 | USBEndpointDescriptor phone_interruptIn; |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 586 | |
Harald Welte | 7ed6f3b | 2017-02-26 17:00:43 +0100 | [diff] [blame] | 587 | DFURT_IF_DESCRIPTOR_STRUCT; |
| 588 | |
Christina Quast | 01bbdc3 | 2015-02-24 17:38:45 +0100 | [diff] [blame] | 589 | } __attribute__ ((packed)) SIMTraceDriverConfigurationDescriptorMITM; |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 590 | |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 591 | static const SIMTraceDriverConfigurationDescriptorMITM |
| 592 | configurationDescriptorMITM = { |
| 593 | /* Standard configuration descriptor */ |
| 594 | { |
| 595 | sizeof(USBConfigurationDescriptor), |
| 596 | USBGenericDescriptor_CONFIGURATION, |
| 597 | sizeof(SIMTraceDriverConfigurationDescriptorMITM), |
Harald Welte | 7ed6f3b | 2017-02-26 17:00:43 +0100 | [diff] [blame] | 598 | 2+DFURT_NUM_IF, /* There are two interfaces in this configuration */ |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 599 | CFG_NUM_MITM, /* configuration number */ |
| 600 | MITM_CONF_STR, /* string descriptor for this configuration */ |
| 601 | USBD_BMATTRIBUTES, |
| 602 | USBConfigurationDescriptor_POWER(100) |
| 603 | }, |
| 604 | // CCID interface descriptor |
| 605 | // Table 4.3-1 Interface Descriptor |
| 606 | // Interface descriptor |
| 607 | { |
| 608 | .bLength = sizeof(USBInterfaceDescriptor), |
| 609 | .bDescriptorType = USBGenericDescriptor_INTERFACE, |
| 610 | .bInterfaceNumber = 0, |
| 611 | .bAlternateSetting = 0, |
| 612 | .bNumEndpoints = 3, |
| 613 | .bInterfaceClass = SMART_CARD_DEVICE_CLASS, |
| 614 | .bInterfaceSubClass = 0, |
| 615 | .bInterfaceProtocol = 0, |
| 616 | .iInterface = CCID_CONF_STR, |
| 617 | }, |
| 618 | { |
| 619 | .bLength = sizeof(CCIDDescriptor), |
| 620 | .bDescriptorType = CCID_DECRIPTOR_TYPE, |
| 621 | .bcdCCID = CCID1_10, // CCID version |
| 622 | .bMaxSlotIndex = 0, // 1 slot |
| 623 | .bVoltageSupport = VOLTS_3_0, |
| 624 | .dwProtocols = (1 << PROTOCOL_TO), |
| 625 | .dwDefaultClock = 3580, |
| 626 | .dwMaximumClock = 3580, |
| 627 | .bNumClockSupported = 0, |
| 628 | .dwDataRate = 9600, |
| 629 | .dwMaxDataRate = 9600, |
| 630 | .bNumDataRatesSupported = 0, |
| 631 | .dwMaxIFSD = 0xfe, |
| 632 | .dwSynchProtocols = 0, |
| 633 | .dwMechanical = 0, |
| 634 | .dwFeatures = CCID_FEATURES_AUTO_CLOCK | CCID_FEATURES_AUTO_BAUD | |
| 635 | CCID_FEATURES_AUTO_PCONF | CCID_FEATURES_AUTO_PNEGO | |
| 636 | CCID_FEATURES_EXC_TPDU, |
| 637 | .dwMaxCCIDMessageLength = 271, /* For extended APDU |
| 638 | level the value shall |
| 639 | be between 261 + 10 */ |
| 640 | .bClassGetResponse = 0xFF, // Echoes the class of the APDU |
| 641 | .bClassEnvelope = 0xFF, // Echoes the class of the APDU |
| 642 | .wLcdLayout = 0, // wLcdLayout: no LCD |
| 643 | .bPINSupport = 0, // bPINSupport: No PIN |
| 644 | .bMaxCCIDBusySlots = 1, |
| 645 | }, |
| 646 | // Bulk-OUT endpoint descriptor |
| 647 | { |
| 648 | .bLength = sizeof(USBEndpointDescriptor), |
| 649 | .bDescriptorType = USBGenericDescriptor_ENDPOINT, |
| 650 | .bEndpointAddress = |
| 651 | USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_OUT, |
| 652 | CCID_EPT_DATA_OUT), |
| 653 | .bmAttributes = USBEndpointDescriptor_BULK, |
| 654 | .wMaxPacketSize = MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE( |
| 655 | CCID_EPT_DATA_OUT), |
| 656 | USBEndpointDescriptor_MAXBULKSIZE_FS), |
| 657 | .bInterval = 0x00, |
| 658 | }, |
| 659 | // Bulk-IN endpoint descriptor |
| 660 | { |
| 661 | .bLength = sizeof(USBEndpointDescriptor), |
| 662 | .bDescriptorType = USBGenericDescriptor_ENDPOINT, |
| 663 | .bEndpointAddress = |
| 664 | USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN, |
| 665 | CCID_EPT_DATA_IN), |
| 666 | .bmAttributes = USBEndpointDescriptor_BULK, |
| 667 | .wMaxPacketSize = MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE( |
| 668 | CCID_EPT_DATA_IN), |
| 669 | USBEndpointDescriptor_MAXBULKSIZE_FS), |
| 670 | .bInterval = 0x00, |
| 671 | }, |
| 672 | // Notification endpoint descriptor |
| 673 | { |
| 674 | .bLength = sizeof(USBEndpointDescriptor), |
| 675 | .bDescriptorType = USBGenericDescriptor_ENDPOINT, |
| 676 | .bEndpointAddress = |
| 677 | USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN, |
| 678 | CCID_EPT_NOTIFICATION), |
| 679 | .bmAttributes = USBEndpointDescriptor_INTERRUPT, |
| 680 | .wMaxPacketSize = MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE( |
| 681 | CCID_EPT_NOTIFICATION), |
| 682 | USBEndpointDescriptor_MAXINTERRUPTSIZE_FS), |
| 683 | .bInterval = 0x10, |
| 684 | }, |
| 685 | |
| 686 | /* Communication class interface standard descriptor */ |
| 687 | { |
| 688 | sizeof(USBInterfaceDescriptor), |
| 689 | USBGenericDescriptor_INTERFACE, |
| 690 | 1, /* This is interface #1 */ |
| 691 | 0, /* This is alternate setting #0 for this interface */ |
| 692 | 3, /* Number of endpoints */ |
| 693 | 0xff, |
| 694 | 0, |
| 695 | 0, |
| 696 | PHONE_CONF_STR, /* string descriptor for this interface */ |
| 697 | } |
| 698 | , |
| 699 | /* Bulk-OUT endpoint standard descriptor */ |
| 700 | { |
| 701 | sizeof(USBEndpointDescriptor), |
| 702 | USBGenericDescriptor_ENDPOINT, |
| 703 | USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_OUT, |
| 704 | PHONE_DATAOUT), |
| 705 | USBEndpointDescriptor_BULK, |
| 706 | MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(PHONE_DATAOUT), |
| 707 | USBEndpointDescriptor_MAXBULKSIZE_FS), |
| 708 | 0 /* Must be 0 for full-speed bulk endpoints */ |
| 709 | } |
| 710 | , |
| 711 | /* Bulk-IN endpoint descriptor */ |
| 712 | { |
| 713 | sizeof(USBEndpointDescriptor), |
| 714 | USBGenericDescriptor_ENDPOINT, |
| 715 | USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN, |
| 716 | PHONE_DATAIN), |
| 717 | USBEndpointDescriptor_BULK, |
| 718 | MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(PHONE_DATAIN), |
| 719 | USBEndpointDescriptor_MAXBULKSIZE_FS), |
| 720 | 0 /* Must be 0 for full-speed bulk endpoints */ |
| 721 | } |
| 722 | , |
| 723 | /* Notification endpoint descriptor */ |
| 724 | { |
| 725 | sizeof(USBEndpointDescriptor), |
| 726 | USBGenericDescriptor_ENDPOINT, |
| 727 | USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN, PHONE_INT), |
| 728 | USBEndpointDescriptor_INTERRUPT, |
| 729 | MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(PHONE_INT), |
| 730 | USBEndpointDescriptor_MAXINTERRUPTSIZE_FS), |
Harald Welte | 7ed6f3b | 2017-02-26 17:00:43 +0100 | [diff] [blame] | 731 | 0x10}, |
| 732 | DFURT_IF_DESCRIPTOR(2, 0), |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 733 | }; |
Harald Welte | 2fb5996 | 2016-02-28 12:34:26 +0100 | [diff] [blame] | 734 | #endif /* HAVE_CARDEM */ |
| 735 | |
| 736 | const USBConfigurationDescriptor *configurationDescriptorsArr[] = { |
| 737 | #ifdef HAVE_SNIFFER |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 738 | &configurationDescriptorSniffer.configuration, |
Harald Welte | 2fb5996 | 2016-02-28 12:34:26 +0100 | [diff] [blame] | 739 | #endif |
| 740 | #ifdef HAVE_CCID |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 741 | &configurationDescriptorCCID.configuration, |
Harald Welte | 2fb5996 | 2016-02-28 12:34:26 +0100 | [diff] [blame] | 742 | #endif |
| 743 | #ifdef HAVE_CARDEM |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 744 | &configurationDescriptorPhone.configuration, |
Harald Welte | 2fb5996 | 2016-02-28 12:34:26 +0100 | [diff] [blame] | 745 | #endif |
| 746 | #ifdef HAVE_MITM |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 747 | &configurationDescriptorMITM.configuration, |
Harald Welte | 2fb5996 | 2016-02-28 12:34:26 +0100 | [diff] [blame] | 748 | #endif |
| 749 | }; |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 750 | |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 751 | /** Standard USB device descriptor for the CDC serial driver */ |
| 752 | const USBDeviceDescriptor deviceDescriptor = { |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 753 | .bLength = sizeof(USBDeviceDescriptor), |
| 754 | .bDescriptorType = USBGenericDescriptor_DEVICE, |
| 755 | .bcdUSB = USBDeviceDescriptor_USB2_00, |
| 756 | .bDeviceClass = 0xff, |
| 757 | .bDeviceSubClass = 0xff, |
| 758 | .bDeviceProtocol = 0xff, |
| 759 | .bMaxPacketSize0 = BOARD_USB_ENDPOINTS_MAXPACKETSIZE(0), |
| 760 | .idVendor = SIMTRACE_VENDOR_ID, |
| 761 | .idProduct = SIMTRACE_PRODUCT_ID, |
| 762 | .bcdDevice = 2, /* Release number */ |
| 763 | .iManufacturer = MANUF_STR, |
| 764 | .iProduct = PRODUCT_STRING, |
| 765 | .iSerialNumber = 0, |
| 766 | .bNumConfigurations = ARRAY_SIZE(configurationDescriptorsArr), |
Christina Quast | 01bbdc3 | 2015-02-24 17:38:45 +0100 | [diff] [blame] | 767 | }; |
| 768 | |
Christina Quast | bd5b8bd | 2015-05-14 17:25:41 +0200 | [diff] [blame] | 769 | /* AT91SAM3S only supports full speed, but not high speed USB */ |
Harald Welte | ec4fe23 | 2015-11-07 18:41:25 +0100 | [diff] [blame] | 770 | static const USBDDriverDescriptors driverDescriptors = { |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 771 | &deviceDescriptor, |
| 772 | (const USBConfigurationDescriptor **)&(configurationDescriptorsArr), /* first full-speed configuration descriptor */ |
| 773 | 0, /* No full-speed device qualifier descriptor */ |
| 774 | 0, /* No full-speed other speed configuration */ |
| 775 | 0, /* No high-speed device descriptor */ |
| 776 | 0, /* No high-speed configuration descriptor */ |
| 777 | 0, /* No high-speed device qualifier descriptor */ |
| 778 | 0, /* No high-speed other speed configuration descriptor */ |
| 779 | stringDescriptors, |
| 780 | STRING_DESC_CNT /* cnt string descriptors in list */ |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 781 | }; |
| 782 | |
Harald Welte | 84ad985 | 2017-01-12 18:06:57 +0100 | [diff] [blame] | 783 | #if (BOARD_MAINOSC == 12000000) |
| 784 | #define PLLB_CFG (CKGR_PLLBR_DIVB(2)|CKGR_PLLBR_MULB(8-1)|CKGR_PLLBR_PLLBCOUNT_Msk) |
| 785 | #elif (BOARD_MAINOSC == 18432000) |
| 786 | #define PLLB_CFG (CKGR_PLLBR_DIVB(5)|CKGR_PLLBR_MULB(13-1)|CKGR_PLLBR_PLLBCOUNT_Msk) |
| 787 | #else |
| 788 | #error "Please configure PLLB for your MAINOSC freq" |
| 789 | #endif |
| 790 | |
Christina Quast | 0ae0314 | 2015-02-25 18:43:46 +0100 | [diff] [blame] | 791 | /*---------------------------------------------------------------------------- |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 792 | * Functions |
Christina Quast | 968b974 | 2015-02-25 14:10:12 +0100 | [diff] [blame] | 793 | *----------------------------------------------------------------------------*/ |
| 794 | |
| 795 | /** |
| 796 | * \brief Configure 48MHz Clock for USB |
| 797 | */ |
| 798 | static void _ConfigureUsbClock(void) |
| 799 | { |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 800 | /* Enable PLLB for USB */ |
Harald Welte | 84ad985 | 2017-01-12 18:06:57 +0100 | [diff] [blame] | 801 | PMC->CKGR_PLLBR = PLLB_CFG; |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 802 | while ((PMC->PMC_SR & PMC_SR_LOCKB) == 0) ; |
| 803 | |
| 804 | /* USB Clock uses PLLB */ |
| 805 | PMC->PMC_USB = PMC_USB_USBDIV(0) /* /1 (no divider) */ |
| 806 | | PMC_USB_USBS; /* PLLB */ |
Christina Quast | 968b974 | 2015-02-25 14:10:12 +0100 | [diff] [blame] | 807 | } |
| 808 | |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 809 | void SIMtrace_USB_Initialize(void) |
Christina Quast | 968b974 | 2015-02-25 14:10:12 +0100 | [diff] [blame] | 810 | { |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 811 | _ConfigureUsbClock(); |
| 812 | // Get std USB driver |
| 813 | USBDDriver *pUsbd = USBD_GetDriver(); |
Christina Quast | 968b974 | 2015-02-25 14:10:12 +0100 | [diff] [blame] | 814 | |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 815 | TRACE_DEBUG("."); |
Christina Quast | 968b974 | 2015-02-25 14:10:12 +0100 | [diff] [blame] | 816 | |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 817 | // Initialize standard USB driver |
| 818 | USBDDriver_Initialize(pUsbd, &driverDescriptors, 0); // Multiple interface settings not supported |
| 819 | USBD_Init(); |
| 820 | USBD_Connect(); |
Christina Quast | 968b974 | 2015-02-25 14:10:12 +0100 | [diff] [blame] | 821 | |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 822 | NVIC_EnableIRQ(UDP_IRQn); |
Christina Quast | 968b974 | 2015-02-25 14:10:12 +0100 | [diff] [blame] | 823 | } |