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" |
Kévin Redon | a1012b1 | 2018-07-01 18:11:01 +0200 | [diff] [blame] | 36 | #include "simtrace_usb.h" |
Harald Welte | 2fb5996 | 2016-02-28 12:34:26 +0100 | [diff] [blame] | 37 | #include "utils.h" |
Christina Quast | 968b974 | 2015-02-25 14:10:12 +0100 | [diff] [blame] | 38 | |
Christina Quast | db7b1ab | 2015-03-03 12:34:36 +0100 | [diff] [blame] | 39 | #include <cciddriverdescriptors.h> |
Harald Welte | 7ed6f3b | 2017-02-26 17:00:43 +0100 | [diff] [blame] | 40 | #include <usb/common/dfu/usb_dfu.h> |
| 41 | #include <usb/device/dfu/dfu.h> |
Christina Quast | db7b1ab | 2015-03-03 12:34:36 +0100 | [diff] [blame] | 42 | |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 43 | /*------------------------------------------------------------------------------ |
| 44 | * USB String descriptors |
| 45 | *------------------------------------------------------------------------------*/ |
Harald Welte | 2363fa0 | 2017-03-05 10:16:25 +0100 | [diff] [blame] | 46 | #include "usb_strings_generated.h" |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 47 | enum strDescNum { |
Harald Welte | 3b64695 | 2017-05-14 23:13:52 +0200 | [diff] [blame] | 48 | MANUF_STR = 1, |
| 49 | PRODUCT_STRING, |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 50 | SNIFFER_CONF_STR, |
| 51 | CCID_CONF_STR, |
| 52 | PHONE_CONF_STR, |
| 53 | MITM_CONF_STR, |
| 54 | CARDEM_USIM1_INTF_STR, |
| 55 | CARDEM_USIM2_INTF_STR, |
| 56 | STRING_DESC_CNT |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 57 | }; |
| 58 | |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 59 | /*------------------------------------------------------------------------------ |
| 60 | * USB Device descriptors |
| 61 | *------------------------------------------------------------------------------*/ |
| 62 | |
Harald Welte | 2fb5996 | 2016-02-28 12:34:26 +0100 | [diff] [blame] | 63 | #ifdef HAVE_SNIFFER |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 64 | typedef struct _SIMTraceDriverConfigurationDescriptorSniffer { |
| 65 | |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 66 | /** Standard configuration descriptor. */ |
| 67 | USBConfigurationDescriptor configuration; |
| 68 | USBInterfaceDescriptor sniffer; |
| 69 | USBEndpointDescriptor sniffer_dataOut; |
| 70 | USBEndpointDescriptor sniffer_dataIn; |
| 71 | USBEndpointDescriptor sniffer_interruptIn; |
Harald Welte | 7ed6f3b | 2017-02-26 17:00:43 +0100 | [diff] [blame] | 72 | DFURT_IF_DESCRIPTOR_STRUCT; |
Christina Quast | 01bbdc3 | 2015-02-24 17:38:45 +0100 | [diff] [blame] | 73 | } __attribute__ ((packed)) SIMTraceDriverConfigurationDescriptorSniffer; |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 74 | |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 75 | static const SIMTraceDriverConfigurationDescriptorSniffer |
| 76 | configurationDescriptorSniffer = { |
| 77 | /* Standard configuration descriptor */ |
Harald Welte | 495a67d | 2017-03-06 09:55:37 +0100 | [diff] [blame] | 78 | .configuration = { |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 79 | .bLength = sizeof(USBConfigurationDescriptor), |
| 80 | .bDescriptorType = USBGenericDescriptor_CONFIGURATION, |
| 81 | .wTotalLength = sizeof(SIMTraceDriverConfigurationDescriptorSniffer), |
Harald Welte | 7ed6f3b | 2017-02-26 17:00:43 +0100 | [diff] [blame] | 82 | .bNumInterfaces = 1+DFURT_NUM_IF, |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 83 | .bConfigurationValue = CFG_NUM_SNIFF, |
| 84 | .iConfiguration = SNIFFER_CONF_STR, |
| 85 | .bmAttributes = USBD_BMATTRIBUTES, |
| 86 | .bMaxPower = USBConfigurationDescriptor_POWER(100), |
| 87 | }, |
| 88 | /* Communication class interface standard descriptor */ |
Harald Welte | 495a67d | 2017-03-06 09:55:37 +0100 | [diff] [blame] | 89 | .sniffer = { |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 90 | .bLength = sizeof(USBInterfaceDescriptor), |
| 91 | .bDescriptorType = USBGenericDescriptor_INTERFACE, |
| 92 | .bInterfaceNumber = 0, |
| 93 | .bAlternateSetting = 0, |
| 94 | .bNumEndpoints = 3, |
Kévin Redon | a1012b1 | 2018-07-01 18:11:01 +0200 | [diff] [blame] | 95 | .bInterfaceClass = USB_CLASS_PROPRIETARY, |
| 96 | .bInterfaceSubClass = SIMTRACE_SNIFFER_USB_SUBCLASS, |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 97 | .bInterfaceProtocol = 0, |
| 98 | .iInterface = SNIFFER_CONF_STR, |
| 99 | }, |
| 100 | /* Bulk-OUT endpoint standard descriptor */ |
Harald Welte | 495a67d | 2017-03-06 09:55:37 +0100 | [diff] [blame] | 101 | .sniffer_dataOut = { |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 102 | .bLength = sizeof(USBEndpointDescriptor), |
| 103 | .bDescriptorType = USBGenericDescriptor_ENDPOINT, |
| 104 | .bEndpointAddress = USBEndpointDescriptor_ADDRESS( |
| 105 | USBEndpointDescriptor_OUT, |
Kévin Redon | a1012b1 | 2018-07-01 18:11:01 +0200 | [diff] [blame] | 106 | SIMTRACE_USB_EP_CARD_DATAOUT), |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 107 | .bmAttributes = USBEndpointDescriptor_BULK, |
Kévin Redon | a1012b1 | 2018-07-01 18:11:01 +0200 | [diff] [blame] | 108 | .wMaxPacketSize = USBEndpointDescriptor_MAXBULKSIZE_FS, |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 109 | .bInterval = 0, |
| 110 | }, |
| 111 | /* Bulk-IN endpoint descriptor */ |
Harald Welte | 495a67d | 2017-03-06 09:55:37 +0100 | [diff] [blame] | 112 | .sniffer_dataIn = { |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 113 | .bLength = sizeof(USBEndpointDescriptor), |
| 114 | .bDescriptorType = USBGenericDescriptor_ENDPOINT, |
| 115 | .bEndpointAddress = USBEndpointDescriptor_ADDRESS( |
| 116 | USBEndpointDescriptor_IN, |
Kévin Redon | a1012b1 | 2018-07-01 18:11:01 +0200 | [diff] [blame] | 117 | SIMTRACE_USB_EP_CARD_DATAIN), |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 118 | .bmAttributes = USBEndpointDescriptor_BULK, |
Kévin Redon | a1012b1 | 2018-07-01 18:11:01 +0200 | [diff] [blame] | 119 | .wMaxPacketSize = USBEndpointDescriptor_MAXBULKSIZE_FS, |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 120 | .bInterval = 0, |
| 121 | }, |
| 122 | // Notification endpoint descriptor |
Harald Welte | 495a67d | 2017-03-06 09:55:37 +0100 | [diff] [blame] | 123 | .sniffer_interruptIn = { |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 124 | .bLength = sizeof(USBEndpointDescriptor), |
| 125 | .bDescriptorType = USBGenericDescriptor_ENDPOINT, |
| 126 | .bEndpointAddress = USBEndpointDescriptor_ADDRESS( |
| 127 | USBEndpointDescriptor_IN, |
Kévin Redon | a1012b1 | 2018-07-01 18:11:01 +0200 | [diff] [blame] | 128 | SIMTRACE_USB_EP_CARD_INT), |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 129 | .bmAttributes = USBEndpointDescriptor_INTERRUPT, |
Kévin Redon | a1012b1 | 2018-07-01 18:11:01 +0200 | [diff] [blame] | 130 | .wMaxPacketSize = USBEndpointDescriptor_MAXINTERRUPTSIZE_FS, |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 131 | .bInterval = 0x10, |
Harald Welte | 7ed6f3b | 2017-02-26 17:00:43 +0100 | [diff] [blame] | 132 | }, |
| 133 | DFURT_IF_DESCRIPTOR(1, 0), |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 134 | }; |
Harald Welte | 2fb5996 | 2016-02-28 12:34:26 +0100 | [diff] [blame] | 135 | #endif /* HAVE_SNIFFER */ |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 136 | |
Harald Welte | 2fb5996 | 2016-02-28 12:34:26 +0100 | [diff] [blame] | 137 | #ifdef HAVE_CCID |
Harald Welte | ec4fe23 | 2015-11-07 18:41:25 +0100 | [diff] [blame] | 138 | static const CCIDDriverConfigurationDescriptors configurationDescriptorCCID = { |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 139 | // Standard USB configuration descriptor |
| 140 | { |
| 141 | .bLength = sizeof(USBConfigurationDescriptor), |
| 142 | .bDescriptorType = USBGenericDescriptor_CONFIGURATION, |
| 143 | .wTotalLength = sizeof(CCIDDriverConfigurationDescriptors), |
Harald Welte | 7ed6f3b | 2017-02-26 17:00:43 +0100 | [diff] [blame] | 144 | .bNumInterfaces = 1+DFURT_NUM_IF, |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 145 | .bConfigurationValue = CFG_NUM_CCID, |
| 146 | .iConfiguration = CCID_CONF_STR, |
| 147 | .bmAttributes = BOARD_USB_BMATTRIBUTES, |
| 148 | .bMaxPower = USBConfigurationDescriptor_POWER(100), |
| 149 | }, |
| 150 | // CCID interface descriptor |
| 151 | // Table 4.3-1 Interface Descriptor |
| 152 | // Interface descriptor |
| 153 | { |
| 154 | .bLength = sizeof(USBInterfaceDescriptor), |
| 155 | .bDescriptorType = USBGenericDescriptor_INTERFACE, |
| 156 | .bInterfaceNumber = 0, |
| 157 | .bAlternateSetting = 0, |
| 158 | .bNumEndpoints = 3, |
| 159 | .bInterfaceClass = SMART_CARD_DEVICE_CLASS, |
| 160 | .bInterfaceSubClass = 0, |
| 161 | .bInterfaceProtocol = 0, |
| 162 | .iInterface = CCID_CONF_STR, |
| 163 | }, |
| 164 | { |
| 165 | .bLength = sizeof(CCIDDescriptor), |
| 166 | .bDescriptorType = CCID_DECRIPTOR_TYPE, |
| 167 | .bcdCCID = CCID1_10, // CCID version |
| 168 | .bMaxSlotIndex = 0, // 1 slot |
| 169 | .bVoltageSupport = VOLTS_3_0, |
| 170 | .dwProtocols = (1 << PROTOCOL_TO), |
| 171 | .dwDefaultClock = 3580, |
| 172 | .dwMaximumClock = 3580, |
| 173 | .bNumClockSupported = 0, |
| 174 | .dwDataRate = 9600, |
| 175 | .dwMaxDataRate = 9600, |
| 176 | .bNumDataRatesSupported = 0, |
| 177 | .dwMaxIFSD = 0xfe, |
| 178 | .dwSynchProtocols = 0, |
| 179 | .dwMechanical = 0, |
| 180 | .dwFeatures = CCID_FEATURES_AUTO_CLOCK | CCID_FEATURES_AUTO_BAUD | |
| 181 | CCID_FEATURES_AUTO_PCONF | CCID_FEATURES_AUTO_PNEGO | |
| 182 | CCID_FEATURES_EXC_TPDU, |
| 183 | .dwMaxCCIDMessageLength = 271, /* For extended APDU |
| 184 | level the value shall |
| 185 | be between 261 + 10 */ |
| 186 | .bClassGetResponse = 0xFF, // Echoes the class of the APDU |
| 187 | .bClassEnvelope = 0xFF, // Echoes the class of the APDU |
| 188 | .wLcdLayout = 0, // wLcdLayout: no LCD |
| 189 | .bPINSupport = 0, // bPINSupport: No PIN |
| 190 | .bMaxCCIDBusySlots = 1, |
| 191 | }, |
| 192 | // Bulk-OUT endpoint descriptor |
| 193 | { |
| 194 | .bLength = sizeof(USBEndpointDescriptor), |
| 195 | .bDescriptorType = USBGenericDescriptor_ENDPOINT, |
| 196 | .bEndpointAddress = |
| 197 | USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_OUT, |
| 198 | CCID_EPT_DATA_OUT), |
| 199 | .bmAttributes = USBEndpointDescriptor_BULK, |
Kévin Redon | a1012b1 | 2018-07-01 18:11:01 +0200 | [diff] [blame] | 200 | .wMaxPacketSize = USBEndpointDescriptor_MAXBULKSIZE_FS, |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 201 | .bInterval = 0x00, |
| 202 | }, |
| 203 | // Bulk-IN endpoint descriptor |
| 204 | { |
| 205 | .bLength = sizeof(USBEndpointDescriptor), |
| 206 | .bDescriptorType = USBGenericDescriptor_ENDPOINT, |
| 207 | .bEndpointAddress = |
| 208 | USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN, |
| 209 | CCID_EPT_DATA_IN), |
| 210 | .bmAttributes = USBEndpointDescriptor_BULK, |
Kévin Redon | a1012b1 | 2018-07-01 18:11:01 +0200 | [diff] [blame] | 211 | .wMaxPacketSize = USBEndpointDescriptor_MAXBULKSIZE_FS), |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 212 | .bInterval = 0x00, |
| 213 | }, |
| 214 | // Notification endpoint descriptor |
| 215 | { |
| 216 | .bLength = sizeof(USBEndpointDescriptor), |
| 217 | .bDescriptorType = USBGenericDescriptor_ENDPOINT, |
| 218 | .bEndpointAddress = |
| 219 | USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN, |
| 220 | CCID_EPT_NOTIFICATION), |
| 221 | .bmAttributes = USBEndpointDescriptor_INTERRUPT, |
Kévin Redon | a1012b1 | 2018-07-01 18:11:01 +0200 | [diff] [blame] | 222 | .wMaxPacketSize = USBEndpointDescriptor_MAXINTERRUPTSIZE_FS, |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 223 | .bInterval = 0x10, |
| 224 | }, |
Harald Welte | 7ed6f3b | 2017-02-26 17:00:43 +0100 | [diff] [blame] | 225 | DFURT_IF_DESCRIPTOR(1, 0), |
Christina Quast | db7b1ab | 2015-03-03 12:34:36 +0100 | [diff] [blame] | 226 | }; |
Harald Welte | 2fb5996 | 2016-02-28 12:34:26 +0100 | [diff] [blame] | 227 | #endif /* HAVE_CCID */ |
Christina Quast | db7b1ab | 2015-03-03 12:34:36 +0100 | [diff] [blame] | 228 | |
Harald Welte | 2fb5996 | 2016-02-28 12:34:26 +0100 | [diff] [blame] | 229 | #ifdef HAVE_CARDEM |
Christina Quast | 01bbdc3 | 2015-02-24 17:38:45 +0100 | [diff] [blame] | 230 | /* SIM card emulator */ |
| 231 | typedef struct _SIMTraceDriverConfigurationDescriptorPhone { |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 232 | /* Standard configuration descriptor. */ |
| 233 | USBConfigurationDescriptor configuration; |
| 234 | USBInterfaceDescriptor phone; |
| 235 | USBEndpointDescriptor phone_dataOut; |
| 236 | USBEndpointDescriptor phone_dataIn; |
| 237 | USBEndpointDescriptor phone_interruptIn; |
Harald Welte | 57b3a25 | 2016-03-02 15:20:27 +0100 | [diff] [blame] | 238 | #ifdef CARDEMU_SECOND_UART |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 239 | USBInterfaceDescriptor usim2; |
| 240 | USBEndpointDescriptor usim2_dataOut; |
| 241 | USBEndpointDescriptor usim2_dataIn; |
| 242 | USBEndpointDescriptor usim2_interruptIn; |
Harald Welte | 57b3a25 | 2016-03-02 15:20:27 +0100 | [diff] [blame] | 243 | #endif |
Harald Welte | 7ed6f3b | 2017-02-26 17:00:43 +0100 | [diff] [blame] | 244 | DFURT_IF_DESCRIPTOR_STRUCT; |
Christina Quast | 01bbdc3 | 2015-02-24 17:38:45 +0100 | [diff] [blame] | 245 | } __attribute__ ((packed)) SIMTraceDriverConfigurationDescriptorPhone; |
| 246 | |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 247 | static const SIMTraceDriverConfigurationDescriptorPhone |
| 248 | configurationDescriptorPhone = { |
| 249 | /* Standard configuration descriptor */ |
Harald Welte | 495a67d | 2017-03-06 09:55:37 +0100 | [diff] [blame] | 250 | .configuration = { |
| 251 | .bLength = sizeof(USBConfigurationDescriptor), |
| 252 | .bDescriptorType = USBGenericDescriptor_CONFIGURATION, |
| 253 | .wTotalLength = sizeof(SIMTraceDriverConfigurationDescriptorPhone), |
Harald Welte | 57b3a25 | 2016-03-02 15:20:27 +0100 | [diff] [blame] | 254 | #ifdef CARDEMU_SECOND_UART |
Harald Welte | 495a67d | 2017-03-06 09:55:37 +0100 | [diff] [blame] | 255 | .bNumInterfaces = 2+DFURT_NUM_IF, |
Harald Welte | 57b3a25 | 2016-03-02 15:20:27 +0100 | [diff] [blame] | 256 | #else |
Harald Welte | f231541 | 2017-11-28 19:16:10 +0100 | [diff] [blame] | 257 | .bNumInterfaces = 1+DFURT_NUM_IF, |
Harald Welte | 57b3a25 | 2016-03-02 15:20:27 +0100 | [diff] [blame] | 258 | #endif |
Harald Welte | 495a67d | 2017-03-06 09:55:37 +0100 | [diff] [blame] | 259 | .bConfigurationValue = CFG_NUM_PHONE, |
| 260 | .iConfiguration = PHONE_CONF_STR, |
| 261 | .bmAttributes = USBD_BMATTRIBUTES, |
| 262 | .bMaxPower = USBConfigurationDescriptor_POWER(100) |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 263 | }, |
| 264 | /* Communication class interface standard descriptor */ |
Harald Welte | 495a67d | 2017-03-06 09:55:37 +0100 | [diff] [blame] | 265 | .phone = { |
| 266 | .bLength = sizeof(USBInterfaceDescriptor), |
| 267 | .bDescriptorType = USBGenericDescriptor_INTERFACE, |
| 268 | .bInterfaceNumber = 0, |
| 269 | .bAlternateSetting = 0, |
| 270 | .bNumEndpoints = 3, |
Kévin Redon | a1012b1 | 2018-07-01 18:11:01 +0200 | [diff] [blame] | 271 | .bInterfaceClass = USB_CLASS_PROPRIETARY, |
| 272 | .bInterfaceSubClass = SIMTRACE_CARDEM_USB_SUBCLASS, |
Harald Welte | 495a67d | 2017-03-06 09:55:37 +0100 | [diff] [blame] | 273 | .bInterfaceProtocol = 0, |
| 274 | .iInterface = CARDEM_USIM1_INTF_STR, |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 275 | }, |
| 276 | /* Bulk-OUT endpoint standard descriptor */ |
Harald Welte | 495a67d | 2017-03-06 09:55:37 +0100 | [diff] [blame] | 277 | .phone_dataOut = { |
| 278 | .bLength = sizeof(USBEndpointDescriptor), |
| 279 | .bDescriptorType = USBGenericDescriptor_ENDPOINT, |
| 280 | .bEndpointAddress = USBEndpointDescriptor_ADDRESS( |
| 281 | USBEndpointDescriptor_OUT, |
Kévin Redon | a1012b1 | 2018-07-01 18:11:01 +0200 | [diff] [blame] | 282 | SIMTRACE_CARDEM_USB_EP_USIM1_DATAOUT), |
Harald Welte | 495a67d | 2017-03-06 09:55:37 +0100 | [diff] [blame] | 283 | .bmAttributes = USBEndpointDescriptor_BULK, |
Kévin Redon | a1012b1 | 2018-07-01 18:11:01 +0200 | [diff] [blame] | 284 | .wMaxPacketSize = USBEndpointDescriptor_MAXBULKSIZE_FS, |
Harald Welte | 495a67d | 2017-03-06 09:55:37 +0100 | [diff] [blame] | 285 | .bInterval = 0 /* Must be 0 for full-speed bulk endpoints */ |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 286 | }, |
| 287 | /* Bulk-IN endpoint descriptor */ |
Harald Welte | 495a67d | 2017-03-06 09:55:37 +0100 | [diff] [blame] | 288 | .phone_dataIn = { |
| 289 | .bLength = sizeof(USBEndpointDescriptor), |
| 290 | .bDescriptorType = USBGenericDescriptor_ENDPOINT, |
| 291 | .bEndpointAddress = USBEndpointDescriptor_ADDRESS( |
| 292 | USBEndpointDescriptor_IN, |
Kévin Redon | a1012b1 | 2018-07-01 18:11:01 +0200 | [diff] [blame] | 293 | SIMTRACE_CARDEM_USB_EP_USIM1_DATAIN), |
Harald Welte | 495a67d | 2017-03-06 09:55:37 +0100 | [diff] [blame] | 294 | .bmAttributes = USBEndpointDescriptor_BULK, |
Kévin Redon | a1012b1 | 2018-07-01 18:11:01 +0200 | [diff] [blame] | 295 | .wMaxPacketSize = USBEndpointDescriptor_MAXBULKSIZE_FS, |
Harald Welte | 495a67d | 2017-03-06 09:55:37 +0100 | [diff] [blame] | 296 | .bInterval = 0 /* Must be 0 for full-speed bulk endpoints */ |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 297 | }, |
| 298 | /* Notification endpoint descriptor */ |
Harald Welte | 495a67d | 2017-03-06 09:55:37 +0100 | [diff] [blame] | 299 | .phone_interruptIn = { |
| 300 | .bLength = sizeof(USBEndpointDescriptor), |
| 301 | .bDescriptorType = USBGenericDescriptor_ENDPOINT, |
| 302 | .bEndpointAddress = USBEndpointDescriptor_ADDRESS( |
| 303 | USBEndpointDescriptor_IN, |
Kévin Redon | a1012b1 | 2018-07-01 18:11:01 +0200 | [diff] [blame] | 304 | SIMTRACE_CARDEM_USB_EP_USIM1_INT), |
Harald Welte | 495a67d | 2017-03-06 09:55:37 +0100 | [diff] [blame] | 305 | .bmAttributes = USBEndpointDescriptor_INTERRUPT, |
Kévin Redon | a1012b1 | 2018-07-01 18:11:01 +0200 | [diff] [blame] | 306 | .wMaxPacketSize = USBEndpointDescriptor_MAXINTERRUPTSIZE_FS, |
Harald Welte | 495a67d | 2017-03-06 09:55:37 +0100 | [diff] [blame] | 307 | .bInterval = 0x10 |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 308 | }, |
Harald Welte | 57b3a25 | 2016-03-02 15:20:27 +0100 | [diff] [blame] | 309 | #ifdef CARDEMU_SECOND_UART |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 310 | /* Communication class interface standard descriptor */ |
Harald Welte | 495a67d | 2017-03-06 09:55:37 +0100 | [diff] [blame] | 311 | .usim2 = { |
| 312 | .bLength = sizeof(USBInterfaceDescriptor), |
| 313 | .bDescriptorType = USBGenericDescriptor_INTERFACE, |
| 314 | .bInterfaceNumber = 1, |
| 315 | .bAlternateSetting = 0, |
| 316 | .bNumEndpoints = 3, |
Kévin Redon | a1012b1 | 2018-07-01 18:11:01 +0200 | [diff] [blame] | 317 | .bInterfaceClass = USB_CLASS_PROPRIETARY, |
| 318 | .bInterfaceSubClass = SIMTRACE_CARDEM_USB_SUBCLASS, |
Harald Welte | 495a67d | 2017-03-06 09:55:37 +0100 | [diff] [blame] | 319 | .bInterfaceProtocol = 0, |
| 320 | .iInterface = CARDEM_USIM2_INTF_STR, |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 321 | }, |
| 322 | /* Bulk-OUT endpoint standard descriptor */ |
Harald Welte | 495a67d | 2017-03-06 09:55:37 +0100 | [diff] [blame] | 323 | .usim2_dataOut = { |
| 324 | .bLength = sizeof(USBEndpointDescriptor), |
| 325 | .bDescriptorType = USBGenericDescriptor_ENDPOINT, |
| 326 | .bEndpointAddress = USBEndpointDescriptor_ADDRESS( |
| 327 | USBEndpointDescriptor_OUT, |
Kévin Redon | a1012b1 | 2018-07-01 18:11:01 +0200 | [diff] [blame] | 328 | SIMTRACE_CARDEM_USB_EP_USIM2_DATAOUT), |
Harald Welte | 495a67d | 2017-03-06 09:55:37 +0100 | [diff] [blame] | 329 | .bmAttributes = USBEndpointDescriptor_BULK, |
Kévin Redon | a1012b1 | 2018-07-01 18:11:01 +0200 | [diff] [blame] | 330 | .wMaxPacketSize = USBEndpointDescriptor_MAXBULKSIZE_FS, |
Harald Welte | 495a67d | 2017-03-06 09:55:37 +0100 | [diff] [blame] | 331 | .bInterval = 0 /* Must be 0 for full-speed bulk endpoints */ |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 332 | } |
| 333 | , |
| 334 | /* Bulk-IN endpoint descriptor */ |
Harald Welte | 495a67d | 2017-03-06 09:55:37 +0100 | [diff] [blame] | 335 | .usim2_dataIn = { |
| 336 | .bLength = sizeof(USBEndpointDescriptor), |
| 337 | .bDescriptorType = USBGenericDescriptor_ENDPOINT, |
| 338 | .bEndpointAddress = USBEndpointDescriptor_ADDRESS( |
| 339 | USBEndpointDescriptor_IN, |
Kévin Redon | a1012b1 | 2018-07-01 18:11:01 +0200 | [diff] [blame] | 340 | SIMTRACE_CARDEM_USB_EP_USIM2_DATAIN), |
Harald Welte | 495a67d | 2017-03-06 09:55:37 +0100 | [diff] [blame] | 341 | .bmAttributes = USBEndpointDescriptor_BULK, |
Kévin Redon | a1012b1 | 2018-07-01 18:11:01 +0200 | [diff] [blame] | 342 | .wMaxPacketSize = USBEndpointDescriptor_MAXBULKSIZE_FS, |
Harald Welte | 495a67d | 2017-03-06 09:55:37 +0100 | [diff] [blame] | 343 | .bInterval = 0 /* Must be 0 for full-speed bulk endpoints */ |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 344 | }, |
| 345 | /* Notification endpoint descriptor */ |
Harald Welte | 495a67d | 2017-03-06 09:55:37 +0100 | [diff] [blame] | 346 | .usim2_interruptIn = { |
| 347 | .bLength = sizeof(USBEndpointDescriptor), |
| 348 | .bDescriptorType = USBGenericDescriptor_ENDPOINT, |
| 349 | .bEndpointAddress = USBEndpointDescriptor_ADDRESS( |
| 350 | USBEndpointDescriptor_IN, |
Kévin Redon | a1012b1 | 2018-07-01 18:11:01 +0200 | [diff] [blame] | 351 | SIMTRACE_CARDEM_USB_EP_USIM2_INT), |
Harald Welte | 495a67d | 2017-03-06 09:55:37 +0100 | [diff] [blame] | 352 | .bmAttributes = USBEndpointDescriptor_INTERRUPT, |
Kévin Redon | a1012b1 | 2018-07-01 18:11:01 +0200 | [diff] [blame] | 353 | .wMaxPacketSize = USBEndpointDescriptor_MAXINTERRUPTSIZE_FS, |
Harald Welte | 495a67d | 2017-03-06 09:55:37 +0100 | [diff] [blame] | 354 | .bInterval = 0x10, |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 355 | }, |
Harald Welte | 7ed6f3b | 2017-02-26 17:00:43 +0100 | [diff] [blame] | 356 | DFURT_IF_DESCRIPTOR(2, 0), |
| 357 | #else |
| 358 | DFURT_IF_DESCRIPTOR(1, 0), |
Harald Welte | 57b3a25 | 2016-03-02 15:20:27 +0100 | [diff] [blame] | 359 | #endif |
Christina Quast | 01bbdc3 | 2015-02-24 17:38:45 +0100 | [diff] [blame] | 360 | }; |
Harald Welte | 2fb5996 | 2016-02-28 12:34:26 +0100 | [diff] [blame] | 361 | #endif /* HAVE_CARDEM */ |
Christina Quast | 01bbdc3 | 2015-02-24 17:38:45 +0100 | [diff] [blame] | 362 | |
Harald Welte | 2fb5996 | 2016-02-28 12:34:26 +0100 | [diff] [blame] | 363 | #ifdef HAVE_MITM |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 364 | typedef struct _SIMTraceDriverConfigurationDescriptorMITM { |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 365 | /* Standard configuration descriptor. */ |
| 366 | USBConfigurationDescriptor configuration; |
| 367 | USBInterfaceDescriptor simcard; |
| 368 | /// CCID descriptor |
| 369 | CCIDDescriptor ccid; |
| 370 | /// Bulk OUT endpoint descriptor |
| 371 | USBEndpointDescriptor simcard_dataOut; |
| 372 | /// Bulk IN endpoint descriptor |
| 373 | USBEndpointDescriptor simcard_dataIn; |
| 374 | /// Interrupt OUT endpoint descriptor |
| 375 | USBEndpointDescriptor simcard_interruptIn; |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 376 | |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 377 | USBInterfaceDescriptor phone; |
| 378 | USBEndpointDescriptor phone_dataOut; |
| 379 | USBEndpointDescriptor phone_dataIn; |
| 380 | USBEndpointDescriptor phone_interruptIn; |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 381 | |
Harald Welte | 7ed6f3b | 2017-02-26 17:00:43 +0100 | [diff] [blame] | 382 | DFURT_IF_DESCRIPTOR_STRUCT; |
| 383 | |
Christina Quast | 01bbdc3 | 2015-02-24 17:38:45 +0100 | [diff] [blame] | 384 | } __attribute__ ((packed)) SIMTraceDriverConfigurationDescriptorMITM; |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 385 | |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 386 | static const SIMTraceDriverConfigurationDescriptorMITM |
| 387 | configurationDescriptorMITM = { |
| 388 | /* Standard configuration descriptor */ |
Harald Welte | 495a67d | 2017-03-06 09:55:37 +0100 | [diff] [blame] | 389 | .configuration = { |
| 390 | .bLength = sizeof(USBConfigurationDescriptor), |
| 391 | .bDescriptorType = USBGenericDescriptor_CONFIGURATION, |
| 392 | .wTotalLength = sizeof(SIMTraceDriverConfigurationDescriptorMITM), |
| 393 | .bNumInterfaces = 2+DFURT_NUM_IF, |
| 394 | .bConfigurationValue = CFG_NUM_MITM, |
| 395 | .iConfiguration = MITM_CONF_STR, |
| 396 | .bmAttributes = USBD_BMATTRIBUTES, |
| 397 | .bMaxPower = USBConfigurationDescriptor_POWER(100), |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 398 | }, |
| 399 | // CCID interface descriptor |
| 400 | // Table 4.3-1 Interface Descriptor |
| 401 | // Interface descriptor |
Harald Welte | 495a67d | 2017-03-06 09:55:37 +0100 | [diff] [blame] | 402 | .simcard = { |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 403 | .bLength = sizeof(USBInterfaceDescriptor), |
| 404 | .bDescriptorType = USBGenericDescriptor_INTERFACE, |
| 405 | .bInterfaceNumber = 0, |
| 406 | .bAlternateSetting = 0, |
| 407 | .bNumEndpoints = 3, |
| 408 | .bInterfaceClass = SMART_CARD_DEVICE_CLASS, |
| 409 | .bInterfaceSubClass = 0, |
| 410 | .bInterfaceProtocol = 0, |
| 411 | .iInterface = CCID_CONF_STR, |
| 412 | }, |
Harald Welte | 495a67d | 2017-03-06 09:55:37 +0100 | [diff] [blame] | 413 | .ccid = { |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 414 | .bLength = sizeof(CCIDDescriptor), |
| 415 | .bDescriptorType = CCID_DECRIPTOR_TYPE, |
| 416 | .bcdCCID = CCID1_10, // CCID version |
| 417 | .bMaxSlotIndex = 0, // 1 slot |
| 418 | .bVoltageSupport = VOLTS_3_0, |
| 419 | .dwProtocols = (1 << PROTOCOL_TO), |
| 420 | .dwDefaultClock = 3580, |
| 421 | .dwMaximumClock = 3580, |
| 422 | .bNumClockSupported = 0, |
| 423 | .dwDataRate = 9600, |
| 424 | .dwMaxDataRate = 9600, |
| 425 | .bNumDataRatesSupported = 0, |
| 426 | .dwMaxIFSD = 0xfe, |
| 427 | .dwSynchProtocols = 0, |
| 428 | .dwMechanical = 0, |
| 429 | .dwFeatures = CCID_FEATURES_AUTO_CLOCK | CCID_FEATURES_AUTO_BAUD | |
| 430 | CCID_FEATURES_AUTO_PCONF | CCID_FEATURES_AUTO_PNEGO | |
| 431 | CCID_FEATURES_EXC_TPDU, |
| 432 | .dwMaxCCIDMessageLength = 271, /* For extended APDU |
| 433 | level the value shall |
| 434 | be between 261 + 10 */ |
| 435 | .bClassGetResponse = 0xFF, // Echoes the class of the APDU |
| 436 | .bClassEnvelope = 0xFF, // Echoes the class of the APDU |
| 437 | .wLcdLayout = 0, // wLcdLayout: no LCD |
| 438 | .bPINSupport = 0, // bPINSupport: No PIN |
| 439 | .bMaxCCIDBusySlots = 1, |
| 440 | }, |
| 441 | // Bulk-OUT endpoint descriptor |
Harald Welte | 495a67d | 2017-03-06 09:55:37 +0100 | [diff] [blame] | 442 | .simcard_dataOut = { |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 443 | .bLength = sizeof(USBEndpointDescriptor), |
| 444 | .bDescriptorType = USBGenericDescriptor_ENDPOINT, |
| 445 | .bEndpointAddress = |
| 446 | USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_OUT, |
| 447 | CCID_EPT_DATA_OUT), |
| 448 | .bmAttributes = USBEndpointDescriptor_BULK, |
Kévin Redon | a1012b1 | 2018-07-01 18:11:01 +0200 | [diff] [blame] | 449 | .wMaxPacketSize = USBEndpointDescriptor_MAXBULKSIZE_FS, |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 450 | .bInterval = 0x00, |
| 451 | }, |
| 452 | // Bulk-IN endpoint descriptor |
Harald Welte | 495a67d | 2017-03-06 09:55:37 +0100 | [diff] [blame] | 453 | .simcard_dataIn = { |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 454 | .bLength = sizeof(USBEndpointDescriptor), |
| 455 | .bDescriptorType = USBGenericDescriptor_ENDPOINT, |
| 456 | .bEndpointAddress = |
| 457 | USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN, |
| 458 | CCID_EPT_DATA_IN), |
| 459 | .bmAttributes = USBEndpointDescriptor_BULK, |
Kévin Redon | a1012b1 | 2018-07-01 18:11:01 +0200 | [diff] [blame] | 460 | .wMaxPacketSize = USBEndpointDescriptor_MAXBULKSIZE_FS, |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 461 | .bInterval = 0x00, |
| 462 | }, |
| 463 | // Notification endpoint descriptor |
Harald Welte | 495a67d | 2017-03-06 09:55:37 +0100 | [diff] [blame] | 464 | .simcard_interruptIn = { |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 465 | .bLength = sizeof(USBEndpointDescriptor), |
| 466 | .bDescriptorType = USBGenericDescriptor_ENDPOINT, |
| 467 | .bEndpointAddress = |
| 468 | USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN, |
| 469 | CCID_EPT_NOTIFICATION), |
| 470 | .bmAttributes = USBEndpointDescriptor_INTERRUPT, |
Kévin Redon | a1012b1 | 2018-07-01 18:11:01 +0200 | [diff] [blame] | 471 | .wMaxPacketSize = USBEndpointDescriptor_MAXINTERRUPTSIZE_FS, |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 472 | .bInterval = 0x10, |
| 473 | }, |
| 474 | |
| 475 | /* Communication class interface standard descriptor */ |
Harald Welte | 495a67d | 2017-03-06 09:55:37 +0100 | [diff] [blame] | 476 | .phone = { |
| 477 | .bLength = sizeof(USBInterfaceDescriptor), |
| 478 | .bDescriptorType = USBGenericDescriptor_INTERFACE, |
| 479 | .bInterfaceNumber = 1, |
| 480 | .bAlternateSetting = 0, |
| 481 | .bNumEndpoints = 3, |
| 482 | .bInterfaceClass = 0xff, |
Harald Welte | f231541 | 2017-11-28 19:16:10 +0100 | [diff] [blame] | 483 | .bInterfaceSubClass = SIMTRACE_SUBCLASS_CARDEM, |
Harald Welte | 495a67d | 2017-03-06 09:55:37 +0100 | [diff] [blame] | 484 | .bInterfaceProtocol = 0, |
| 485 | .iInterface = PHONE_CONF_STR, |
| 486 | }, |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 487 | /* Bulk-OUT endpoint standard descriptor */ |
Harald Welte | 495a67d | 2017-03-06 09:55:37 +0100 | [diff] [blame] | 488 | .phone_dataOut = { |
| 489 | .bLength = sizeof(USBEndpointDescriptor), |
| 490 | .bDescriptorType = USBGenericDescriptor_ENDPOINT, |
| 491 | .bEndpointAddress = USBEndpointDescriptor_ADDRESS( |
| 492 | USBEndpointDescriptor_OUT, |
Kévin Redon | a1012b1 | 2018-07-01 18:11:01 +0200 | [diff] [blame] | 493 | SIMTRACE_USB_EP_PHONE_DATAOUT), |
Harald Welte | 495a67d | 2017-03-06 09:55:37 +0100 | [diff] [blame] | 494 | .bmAttributes = USBEndpointDescriptor_BULK, |
Kévin Redon | a1012b1 | 2018-07-01 18:11:01 +0200 | [diff] [blame] | 495 | .wMaxPacketSize = USBEndpointDescriptor_MAXBULKSIZE_FS, |
Harald Welte | 495a67d | 2017-03-06 09:55:37 +0100 | [diff] [blame] | 496 | .bInterval = 0, /* Must be 0 for full-speed bulk endpoints */ |
| 497 | }, |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 498 | /* Bulk-IN endpoint descriptor */ |
Harald Welte | 495a67d | 2017-03-06 09:55:37 +0100 | [diff] [blame] | 499 | .phone_dataIn = { |
| 500 | .bLength = sizeof(USBEndpointDescriptor), |
| 501 | .bDescriptorType = USBGenericDescriptor_ENDPOINT, |
| 502 | .bEndpointAddress = USBEndpointDescriptor_ADDRESS( |
| 503 | USBEndpointDescriptor_IN, |
Kévin Redon | a1012b1 | 2018-07-01 18:11:01 +0200 | [diff] [blame] | 504 | SIMTRACE_USB_EP_PHONE_DATAIN), |
Harald Welte | 495a67d | 2017-03-06 09:55:37 +0100 | [diff] [blame] | 505 | .bmAttributes = USBEndpointDescriptor_BULK, |
Kévin Redon | a1012b1 | 2018-07-01 18:11:01 +0200 | [diff] [blame] | 506 | .wMaxPacketSize = USBEndpointDescriptor_MAXBULKSIZE_FS, |
Harald Welte | 495a67d | 2017-03-06 09:55:37 +0100 | [diff] [blame] | 507 | .bInterval = 0, /* Must be 0 for full-speed bulk endpoints */ |
| 508 | }, |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 509 | /* Notification endpoint descriptor */ |
| 510 | { |
Harald Welte | 495a67d | 2017-03-06 09:55:37 +0100 | [diff] [blame] | 511 | .bLength = sizeof(USBEndpointDescriptor), |
| 512 | .bDescriptorType = USBGenericDescriptor_ENDPOINT, |
| 513 | .bEndpointAddress = USBEndpointDescriptor_ADDRESS( |
| 514 | USBEndpointDescriptor_IN, |
Kévin Redon | a1012b1 | 2018-07-01 18:11:01 +0200 | [diff] [blame] | 515 | SIMTRACE_USB_EP_PHONE_INT), |
Harald Welte | 495a67d | 2017-03-06 09:55:37 +0100 | [diff] [blame] | 516 | .bmAttributes = USBEndpointDescriptor_INTERRUPT, |
Kévin Redon | a1012b1 | 2018-07-01 18:11:01 +0200 | [diff] [blame] | 517 | .wMaxPacketSize = USBEndpointDescriptor_MAXINTERRUPTSIZE_FS, |
Harald Welte | 495a67d | 2017-03-06 09:55:37 +0100 | [diff] [blame] | 518 | .bInterval = 0x10 |
| 519 | }, |
Harald Welte | 7ed6f3b | 2017-02-26 17:00:43 +0100 | [diff] [blame] | 520 | DFURT_IF_DESCRIPTOR(2, 0), |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 521 | }; |
Harald Welte | 2fb5996 | 2016-02-28 12:34:26 +0100 | [diff] [blame] | 522 | #endif /* HAVE_CARDEM */ |
| 523 | |
| 524 | const USBConfigurationDescriptor *configurationDescriptorsArr[] = { |
| 525 | #ifdef HAVE_SNIFFER |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 526 | &configurationDescriptorSniffer.configuration, |
Harald Welte | 2fb5996 | 2016-02-28 12:34:26 +0100 | [diff] [blame] | 527 | #endif |
| 528 | #ifdef HAVE_CCID |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 529 | &configurationDescriptorCCID.configuration, |
Harald Welte | 2fb5996 | 2016-02-28 12:34:26 +0100 | [diff] [blame] | 530 | #endif |
| 531 | #ifdef HAVE_CARDEM |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 532 | &configurationDescriptorPhone.configuration, |
Harald Welte | 2fb5996 | 2016-02-28 12:34:26 +0100 | [diff] [blame] | 533 | #endif |
| 534 | #ifdef HAVE_MITM |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 535 | &configurationDescriptorMITM.configuration, |
Harald Welte | 2fb5996 | 2016-02-28 12:34:26 +0100 | [diff] [blame] | 536 | #endif |
| 537 | }; |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 538 | |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 539 | /** Standard USB device descriptor for the CDC serial driver */ |
| 540 | const USBDeviceDescriptor deviceDescriptor = { |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 541 | .bLength = sizeof(USBDeviceDescriptor), |
| 542 | .bDescriptorType = USBGenericDescriptor_DEVICE, |
| 543 | .bcdUSB = USBDeviceDescriptor_USB2_00, |
Harald Welte | eab7e45 | 2017-03-06 10:04:56 +0100 | [diff] [blame] | 544 | .bDeviceClass = 0, |
| 545 | .bDeviceSubClass = 0, |
| 546 | .bDeviceProtocol = 0, |
Kévin Redon | a1012b1 | 2018-07-01 18:11:01 +0200 | [diff] [blame] | 547 | .bMaxPacketSize0 = 64, |
Harald Welte | c6e482d | 2017-03-05 16:24:29 +0100 | [diff] [blame] | 548 | .idVendor = BOARD_USB_VENDOR_ID, |
| 549 | .idProduct = BOARD_USB_PRODUCT_ID, |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 550 | .bcdDevice = 2, /* Release number */ |
| 551 | .iManufacturer = MANUF_STR, |
| 552 | .iProduct = PRODUCT_STRING, |
| 553 | .iSerialNumber = 0, |
| 554 | .bNumConfigurations = ARRAY_SIZE(configurationDescriptorsArr), |
Christina Quast | 01bbdc3 | 2015-02-24 17:38:45 +0100 | [diff] [blame] | 555 | }; |
| 556 | |
Christina Quast | bd5b8bd | 2015-05-14 17:25:41 +0200 | [diff] [blame] | 557 | /* AT91SAM3S only supports full speed, but not high speed USB */ |
Harald Welte | ec4fe23 | 2015-11-07 18:41:25 +0100 | [diff] [blame] | 558 | static const USBDDriverDescriptors driverDescriptors = { |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 559 | &deviceDescriptor, |
| 560 | (const USBConfigurationDescriptor **)&(configurationDescriptorsArr), /* first full-speed configuration descriptor */ |
| 561 | 0, /* No full-speed device qualifier descriptor */ |
| 562 | 0, /* No full-speed other speed configuration */ |
| 563 | 0, /* No high-speed device descriptor */ |
| 564 | 0, /* No high-speed configuration descriptor */ |
| 565 | 0, /* No high-speed device qualifier descriptor */ |
| 566 | 0, /* No high-speed other speed configuration descriptor */ |
Harald Welte | 2363fa0 | 2017-03-05 10:16:25 +0100 | [diff] [blame] | 567 | usb_strings, |
| 568 | ARRAY_SIZE(usb_strings),/* cnt string descriptors in list */ |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 569 | }; |
| 570 | |
Christina Quast | 0ae0314 | 2015-02-25 18:43:46 +0100 | [diff] [blame] | 571 | /*---------------------------------------------------------------------------- |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 572 | * Functions |
Christina Quast | 968b974 | 2015-02-25 14:10:12 +0100 | [diff] [blame] | 573 | *----------------------------------------------------------------------------*/ |
| 574 | |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 575 | void SIMtrace_USB_Initialize(void) |
Christina Quast | 968b974 | 2015-02-25 14:10:12 +0100 | [diff] [blame] | 576 | { |
Kévin Redon | f5869d4 | 2018-06-17 22:31:21 +0200 | [diff] [blame] | 577 | |
| 578 | /* Signal USB reset by disabling the pull-up on USB D+ for at least 10 ms */ |
| 579 | const Pin usb_dp_pullup = PIN_USB_PULLUP; |
| 580 | PIO_Configure(&usb_dp_pullup, 1); |
| 581 | PIO_Set(&usb_dp_pullup); |
| 582 | mdelay(15); |
| 583 | PIO_Clear(&usb_dp_pullup); |
| 584 | |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 585 | // Get std USB driver |
| 586 | USBDDriver *pUsbd = USBD_GetDriver(); |
Christina Quast | 968b974 | 2015-02-25 14:10:12 +0100 | [diff] [blame] | 587 | |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 588 | // Initialize standard USB driver |
| 589 | USBDDriver_Initialize(pUsbd, &driverDescriptors, 0); // Multiple interface settings not supported |
| 590 | USBD_Init(); |
| 591 | USBD_Connect(); |
Christina Quast | 968b974 | 2015-02-25 14:10:12 +0100 | [diff] [blame] | 592 | |
Harald Welte | 7dd3dfd | 2016-03-03 12:32:04 +0100 | [diff] [blame] | 593 | NVIC_EnableIRQ(UDP_IRQn); |
Christina Quast | 968b974 | 2015-02-25 14:10:12 +0100 | [diff] [blame] | 594 | } |