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