Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 1 | /*------------------------------------------------------------------------------ |
| 2 | * USB String descriptors |
| 3 | *------------------------------------------------------------------------------*/ |
| 4 | |
| 5 | const unsigned char productStringDescriptor[] = { |
| 6 | |
| 7 | USBStringDescriptor_LENGTH(8), |
| 8 | USBGenericDescriptor_STRING, |
| 9 | USBStringDescriptor_UNICODE('S'), |
| 10 | USBStringDescriptor_UNICODE('I'), |
| 11 | USBStringDescriptor_UNICODE('M'), |
| 12 | USBStringDescriptor_UNICODE('t'), |
| 13 | USBStringDescriptor_UNICODE('r'), |
| 14 | USBStringDescriptor_UNICODE('a'), |
| 15 | USBStringDescriptor_UNICODE('c'), |
| 16 | USBStringDescriptor_UNICODE('e'), |
| 17 | }; |
| 18 | |
| 19 | const unsigned char snifferConfigStringDescriptor[] = { |
| 20 | |
| 21 | USBStringDescriptor_LENGTH(15), |
| 22 | USBGenericDescriptor_STRING, |
| 23 | USBStringDescriptor_UNICODE('S'), |
| 24 | USBStringDescriptor_UNICODE('I'), |
| 25 | USBStringDescriptor_UNICODE('M'), |
| 26 | USBStringDescriptor_UNICODE('t'), |
| 27 | USBStringDescriptor_UNICODE('r'), |
| 28 | USBStringDescriptor_UNICODE('a'), |
| 29 | USBStringDescriptor_UNICODE('c'), |
| 30 | USBStringDescriptor_UNICODE('e'), |
| 31 | USBStringDescriptor_UNICODE('S'), |
| 32 | USBStringDescriptor_UNICODE('n'), |
| 33 | USBStringDescriptor_UNICODE('i'), |
| 34 | USBStringDescriptor_UNICODE('f'), |
| 35 | USBStringDescriptor_UNICODE('f'), |
| 36 | USBStringDescriptor_UNICODE('e'), |
| 37 | USBStringDescriptor_UNICODE('r'), |
| 38 | }; |
| 39 | |
| 40 | const unsigned char CCIDConfigStringDescriptor[] = { |
| 41 | |
| 42 | USBStringDescriptor_LENGTH(12), |
| 43 | USBGenericDescriptor_STRING, |
| 44 | USBStringDescriptor_UNICODE('S'), |
| 45 | USBStringDescriptor_UNICODE('I'), |
| 46 | USBStringDescriptor_UNICODE('M'), |
| 47 | USBStringDescriptor_UNICODE('t'), |
| 48 | USBStringDescriptor_UNICODE('r'), |
| 49 | USBStringDescriptor_UNICODE('a'), |
| 50 | USBStringDescriptor_UNICODE('c'), |
| 51 | USBStringDescriptor_UNICODE('e'), |
| 52 | USBStringDescriptor_UNICODE('C'), |
| 53 | USBStringDescriptor_UNICODE('C'), |
| 54 | USBStringDescriptor_UNICODE('I'), |
| 55 | USBStringDescriptor_UNICODE('D'), |
| 56 | }; |
| 57 | |
| 58 | const unsigned char phoneConfigStringDescriptor[] = { |
| 59 | |
| 60 | USBStringDescriptor_LENGTH(13), |
| 61 | USBGenericDescriptor_STRING, |
| 62 | USBStringDescriptor_UNICODE('S'), |
| 63 | USBStringDescriptor_UNICODE('I'), |
| 64 | USBStringDescriptor_UNICODE('M'), |
| 65 | USBStringDescriptor_UNICODE('t'), |
| 66 | USBStringDescriptor_UNICODE('r'), |
| 67 | USBStringDescriptor_UNICODE('a'), |
| 68 | USBStringDescriptor_UNICODE('c'), |
| 69 | USBStringDescriptor_UNICODE('e'), |
| 70 | USBStringDescriptor_UNICODE('P'), |
| 71 | USBStringDescriptor_UNICODE('h'), |
| 72 | USBStringDescriptor_UNICODE('o'), |
| 73 | USBStringDescriptor_UNICODE('n'), |
| 74 | USBStringDescriptor_UNICODE('e'), |
| 75 | }; |
| 76 | |
| 77 | |
| 78 | const unsigned char MITMConfigStringDescriptor[] = { |
| 79 | |
| 80 | USBStringDescriptor_LENGTH(12), |
| 81 | USBGenericDescriptor_STRING, |
| 82 | USBStringDescriptor_UNICODE('S'), |
| 83 | USBStringDescriptor_UNICODE('I'), |
| 84 | USBStringDescriptor_UNICODE('M'), |
| 85 | USBStringDescriptor_UNICODE('t'), |
| 86 | USBStringDescriptor_UNICODE('r'), |
| 87 | USBStringDescriptor_UNICODE('a'), |
| 88 | USBStringDescriptor_UNICODE('c'), |
| 89 | USBStringDescriptor_UNICODE('e'), |
| 90 | USBStringDescriptor_UNICODE('M'), |
| 91 | USBStringDescriptor_UNICODE('I'), |
| 92 | USBStringDescriptor_UNICODE('T'), |
| 93 | USBStringDescriptor_UNICODE('M'), |
| 94 | }; |
| 95 | |
| 96 | enum strDescNum { |
Christina Quast | 01bbdc3 | 2015-02-24 17:38:45 +0100 | [diff] [blame^] | 97 | NONE = 1, PRODUCT_STRING, SNIFFER_CONF_STR, CCID_CONF_STR, PHONE_CONF_STR, MITM_CONF_STR, STRING_DESC_CNT |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 98 | }; |
| 99 | |
| 100 | /** List of string descriptors used by the device */ |
| 101 | const unsigned char *stringDescriptors[] = { |
| 102 | /* FIXME: Is it true that I can't use the string desc #0, |
| 103 | * because 0 also stands for "no string desc"? |
| 104 | * on the other hand, dmesg output: |
| 105 | * "string descriptor 0 malformed (err = -61), defaulting to 0x0409" */ |
| 106 | 0, |
| 107 | productStringDescriptor, |
| 108 | snifferConfigStringDescriptor, |
| 109 | CCIDreaderConfigStringDescriptor, |
| 110 | phoneConfigStringDescriptor, |
| 111 | MITMConfigStringDescriptor |
| 112 | }; |
| 113 | |
Christina Quast | 01bbdc3 | 2015-02-24 17:38:45 +0100 | [diff] [blame^] | 114 | /* Endpoint numbers */ |
| 115 | #define DATAOUT 1 |
| 116 | #define DATAIN 2 |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 117 | |
| 118 | /*------------------------------------------------------------------------------ |
| 119 | * USB Device descriptors |
| 120 | *------------------------------------------------------------------------------*/ |
| 121 | |
| 122 | typedef struct _SIMTraceDriverConfigurationDescriptorSniffer { |
| 123 | |
| 124 | /** Standard configuration descriptor. */ |
| 125 | USBConfigurationDescriptor configuration; |
| 126 | USBInterfaceDescriptor sniffer; |
| 127 | USBEndpointDescriptor sniffer_dataOut; |
| 128 | USBEndpointDescriptor sniffer_dataIn; |
| 129 | |
Christina Quast | 01bbdc3 | 2015-02-24 17:38:45 +0100 | [diff] [blame^] | 130 | } __attribute__ ((packed)) SIMTraceDriverConfigurationDescriptorSniffer; |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 131 | |
| 132 | const SIMTraceDriverConfigurationDescriptorSniffer configurationDescriptorSniffer = { |
| 133 | /* Standard configuration descriptor */ |
| 134 | { |
| 135 | sizeof(USBConfigurationDescriptor), |
| 136 | USBGenericDescriptor_CONFIGURATION, |
| 137 | sizeof(SIMTraceDriverConfigurationDescriptorSniffer), |
| 138 | 1, /* There is one interface in this configuration */ |
| 139 | 1, /* This is configuration #1 */ |
| 140 | SNIFFER_CONF_STR, /* string descriptor for this configuration */ |
| 141 | USBD_BMATTRIBUTES, |
| 142 | USBConfigurationDescriptor_POWER(100) |
| 143 | }, |
| 144 | /* Communication class interface standard descriptor */ |
| 145 | { |
| 146 | sizeof(USBInterfaceDescriptor), |
| 147 | USBGenericDescriptor_INTERFACE, |
| 148 | 0, /* This is interface #0 */ |
| 149 | 0, /* This is alternate setting #0 for this interface */ |
| 150 | 2, /* This interface uses 2 endpoints */ |
| 151 | 0xff, /* Descriptor Class: Vendor specific */ |
| 152 | 0, /* No subclass */ |
| 153 | 0, /* No l */ |
| 154 | SNIFFER_CONF_STR /* Third in string descriptor for this interface */ |
| 155 | }, |
| 156 | /* Bulk-OUT endpoint standard descriptor */ |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 157 | { |
| 158 | sizeof(USBEndpointDescriptor), |
| 159 | USBGenericDescriptor_ENDPOINT, |
| 160 | USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_OUT, |
| 161 | DATAOUT), |
| 162 | USBEndpointDescriptor_BULK, |
| 163 | MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(DATAOUT), |
| 164 | USBEndpointDescriptor_MAXBULKSIZE_FS), |
| 165 | 0 /* Must be 0 for full-speed bulk endpoints */ |
| 166 | }, |
| 167 | /* Bulk-IN endpoint descriptor */ |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 168 | { |
| 169 | sizeof(USBEndpointDescriptor), |
| 170 | USBGenericDescriptor_ENDPOINT, |
| 171 | USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN, |
| 172 | DATAIN), |
| 173 | USBEndpointDescriptor_BULK, |
| 174 | MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(DATAIN), |
| 175 | USBEndpointDescriptor_MAXBULKSIZE_FS), |
| 176 | 0 /* Must be 0 for full-speed bulk endpoints */ |
| 177 | } |
| 178 | }; |
| 179 | |
| 180 | /* FIXME: CCID descriptor: External C file */ |
Christina Quast | 01bbdc3 | 2015-02-24 17:38:45 +0100 | [diff] [blame^] | 181 | typedef struct { |
| 182 | |
| 183 | USBConfigurationDescriptor configuration; |
| 184 | USBInterfaceDescriptor interface; |
| 185 | CCIDDescriptor ccid; |
| 186 | USBEndpointDescriptor bulkOut; |
| 187 | USBEndpointDescriptor bulkIn; |
| 188 | USBEndpointDescriptor interruptIn; |
| 189 | } __attribute__ ((packed)) CCIDDriverConfigurationDescriptorsCCID; |
| 190 | |
| 191 | const CCIDDriverConfigurationDescriptorsCCID configurationDescriptorCCID = { 0 }; |
| 192 | |
| 193 | /* SIM card emulator */ |
| 194 | typedef struct _SIMTraceDriverConfigurationDescriptorPhone { |
| 195 | |
| 196 | /** Standard configuration descriptor. */ |
| 197 | USBConfigurationDescriptor configuration; |
| 198 | USBInterfaceDescriptor sniffer; |
| 199 | USBEndpointDescriptor sniffer_dataOut; |
| 200 | USBEndpointDescriptor sniffer_dataIn; |
| 201 | |
| 202 | } __attribute__ ((packed)) SIMTraceDriverConfigurationDescriptorPhone; |
| 203 | |
| 204 | const SIMTraceDriverConfigurationDescriptorPhone configurationDescriptorPhone = { |
| 205 | /* Standard configuration descriptor */ |
| 206 | { |
| 207 | sizeof(USBConfigurationDescriptor), |
| 208 | USBGenericDescriptor_CONFIGURATION, |
| 209 | sizeof(SIMTraceDriverConfigurationDescriptorSniffer), |
| 210 | 1, /* There is one interface in this configuration */ |
| 211 | 1, /* This is configuration #1 */ |
| 212 | PHONE_CONF_STR, /* string descriptor for this configuration */ |
| 213 | USBD_BMATTRIBUTES, |
| 214 | USBConfigurationDescriptor_POWER(100) |
| 215 | }, |
| 216 | /* Communication class interface standard descriptor */ |
| 217 | { |
| 218 | sizeof(USBInterfaceDescriptor), |
| 219 | USBGenericDescriptor_INTERFACE, |
| 220 | 0, /* This is interface #0 */ |
| 221 | 0, /* This is alternate setting #0 for this interface */ |
| 222 | 2, /* This interface uses 2 endpoints */ |
| 223 | 0xff, /* Descriptor Class: Vendor specific */ |
| 224 | 0, /* No subclass */ |
| 225 | 0, /* No l */ |
| 226 | PHONE_CONF_STR /* Third in string descriptor for this interface */ |
| 227 | }, |
| 228 | /* Bulk-OUT endpoint standard descriptor */ |
| 229 | { |
| 230 | sizeof(USBEndpointDescriptor), |
| 231 | USBGenericDescriptor_ENDPOINT, |
| 232 | USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_OUT, |
| 233 | DATAOUT), |
| 234 | USBEndpointDescriptor_BULK, |
| 235 | MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(DATAOUT), |
| 236 | USBEndpointDescriptor_MAXBULKSIZE_FS), |
| 237 | 0 /* Must be 0 for full-speed bulk endpoints */ |
| 238 | }, |
| 239 | /* Bulk-IN endpoint descriptor */ |
| 240 | { |
| 241 | sizeof(USBEndpointDescriptor), |
| 242 | USBGenericDescriptor_ENDPOINT, |
| 243 | USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN, |
| 244 | DATAIN), |
| 245 | USBEndpointDescriptor_BULK, |
| 246 | MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(DATAIN), |
| 247 | USBEndpointDescriptor_MAXBULKSIZE_FS), |
| 248 | 0 /* Must be 0 for full-speed bulk endpoints */ |
| 249 | } |
| 250 | }; |
| 251 | |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 252 | |
| 253 | typedef struct _SIMTraceDriverConfigurationDescriptorMITM { |
| 254 | |
| 255 | /** Standard configuration descriptor. */ |
| 256 | USBConfigurationDescriptor configuration; |
| 257 | USBInterfaceDescriptor simcard; |
| 258 | USBEndpointDescriptor simcard_dataOut; |
| 259 | USBEndpointDescriptor simcard_dataIn; |
| 260 | USBInterfaceDescriptor phone; |
| 261 | USBEndpointDescriptor phone_dataOut; |
| 262 | USBEndpointDescriptor phone_dataIn; |
| 263 | |
Christina Quast | 01bbdc3 | 2015-02-24 17:38:45 +0100 | [diff] [blame^] | 264 | } __attribute__ ((packed)) SIMTraceDriverConfigurationDescriptorMITM; |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 265 | |
| 266 | const SIMTraceDriverConfigurationDescriptorMITM configurationDescriptorsMITM = { |
| 267 | /* Standard configuration descriptor */ |
| 268 | { |
| 269 | sizeof(USBConfigurationDescriptor), |
| 270 | USBGenericDescriptor_CONFIGURATION, |
| 271 | sizeof(SIMTraceDriverConfigurationDescriptor), |
| 272 | 2, /* There are two interfaces in this configuration */ |
| 273 | 4, /* This is configuration #4 */ |
| 274 | MITM_CONF_STR, /* string descriptor for this configuration */ |
| 275 | USBD_BMATTRIBUTES, |
| 276 | USBConfigurationDescriptor_POWER(100) |
| 277 | }, |
| 278 | /* Communication class interface standard descriptor */ |
| 279 | { |
| 280 | sizeof(USBInterfaceDescriptor), |
| 281 | USBGenericDescriptor_INTERFACE, |
| 282 | 0, /* This is interface #0 */ |
| 283 | 0, /* This is alternate setting #0 for this interface */ |
| 284 | 2, /* This interface uses 2 endpoints */ |
| 285 | //CDCCommunicationInterfaceDescriptor_CLASS, |
| 286 | 0xff, |
| 287 | // CDCCommunicationInterfaceDescriptor_ABSTRACTCONTROLMODEL, |
| 288 | 0, |
| 289 | // CDCCommunicationInterfaceDescriptor_NOPROTOCOL, |
| 290 | 0, |
| 291 | MITM_CONF_STR /* string descriptor for this interface */ |
| 292 | }, |
| 293 | /* Bulk-OUT endpoint standard descriptor */ |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 294 | { |
| 295 | sizeof(USBEndpointDescriptor), |
| 296 | USBGenericDescriptor_ENDPOINT, |
| 297 | USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_OUT, |
| 298 | DATAOUT), |
| 299 | USBEndpointDescriptor_BULK, |
| 300 | MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(DATAOUT), |
| 301 | USBEndpointDescriptor_MAXBULKSIZE_FS), |
| 302 | 0 /* Must be 0 for full-speed bulk endpoints */ |
| 303 | }, |
| 304 | /* Bulk-IN endpoint descriptor */ |
Christina Quast | 01bbdc3 | 2015-02-24 17:38:45 +0100 | [diff] [blame^] | 305 | { |
| 306 | sizeof(USBEndpointDescriptor), |
| 307 | USBGenericDescriptor_ENDPOINT, |
| 308 | USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN, |
| 309 | DATAIN), |
| 310 | USBEndpointDescriptor_BULK, |
| 311 | MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(DATAIN), |
| 312 | USBEndpointDescriptor_MAXBULKSIZE_FS), |
| 313 | 0 /* Must be 0 for full-speed bulk endpoints */ |
| 314 | } |
| 315 | /* Communication class interface standard descriptor */ |
| 316 | { |
| 317 | sizeof(USBInterfaceDescriptor), |
| 318 | USBGenericDescriptor_INTERFACE, |
| 319 | 1, /* This is interface #1 */ |
| 320 | 0, /* This is alternate setting #0 for this interface */ |
| 321 | 2, /* This interface uses 2 endpoints */ |
| 322 | 0xff, |
| 323 | 0, |
| 324 | 0, |
| 325 | 0, /* FIXME: string descriptor for this interface */ |
| 326 | }, |
| 327 | /* Bulk-OUT endpoint standard descriptor */ |
| 328 | { |
| 329 | sizeof(USBEndpointDescriptor), |
| 330 | USBGenericDescriptor_ENDPOINT, |
| 331 | USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_OUT, |
| 332 | DATAOUT), |
| 333 | USBEndpointDescriptor_BULK, |
| 334 | MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(DATAOUT), |
| 335 | USBEndpointDescriptor_MAXBULKSIZE_FS), |
| 336 | 0 /* Must be 0 for full-speed bulk endpoints */ |
| 337 | }, |
| 338 | /* Bulk-IN endpoint descriptor */ |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 339 | { |
| 340 | sizeof(USBEndpointDescriptor), |
| 341 | USBGenericDescriptor_ENDPOINT, |
| 342 | USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN, |
| 343 | DATAIN), |
| 344 | USBEndpointDescriptor_BULK, |
| 345 | MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(DATAIN), |
| 346 | USBEndpointDescriptor_MAXBULKSIZE_FS), |
| 347 | 0 /* Must be 0 for full-speed bulk endpoints */ |
| 348 | } |
| 349 | }; |
| 350 | |
| 351 | |
| 352 | /** Standard USB device descriptor for the CDC serial driver */ |
| 353 | const USBDeviceDescriptor deviceDescriptor = { |
| 354 | |
| 355 | sizeof(USBDeviceDescriptor), |
| 356 | USBGenericDescriptor_DEVICE, |
| 357 | USBDeviceDescriptor_USB2_00, |
| 358 | 0xff, |
| 359 | // CDCDeviceDescriptor_CLASS, |
| 360 | 0xff, |
| 361 | // CDCDeviceDescriptor_SUBCLASS, |
| 362 | 0xff, |
| 363 | // CDCDeviceDescriptor_PROTOCOL, |
| 364 | BOARD_USB_ENDPOINTS_MAXPACKETSIZE(0), |
| 365 | ATMEL_VENDOR_ID, |
| 366 | SIMTRACE_PRODUCT_ID, |
| 367 | 1, /* Release number */ |
| 368 | 0, /* No string descriptor for manufacturer */ |
| 369 | PRODUCT_STRING, /* Index of product string descriptor */ |
| 370 | 0, /* No string descriptor for serial number */ |
| 371 | 4 /* Device has 4 possible configurations */ |
| 372 | }; |
| 373 | |
Christina Quast | 01bbdc3 | 2015-02-24 17:38:45 +0100 | [diff] [blame^] | 374 | const SIMTraceDriverConfigurationDescriptor *configurationDescriptorsArr[] = { |
| 375 | &configurationDescriptorSniffer, |
| 376 | &configurationDescriptorCCID, |
| 377 | &configurationDescriptorPhone, |
| 378 | &configurationDescriptorMITM, |
| 379 | }; |
| 380 | |
| 381 | |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 382 | /* AT91SAM3S does only support full speed, but not high speed USB */ |
| 383 | const USBDDriverDescriptors driverDescriptors = { |
| 384 | &deviceDescriptor, |
Christina Quast | 01bbdc3 | 2015-02-24 17:38:45 +0100 | [diff] [blame^] | 385 | (USBConfigurationDescriptor **) &(configurationDescriptorsArr), /* first full-speed configuration descriptor */ |
Christina Quast | f554950 | 2015-02-24 14:27:08 +0100 | [diff] [blame] | 386 | 0, /* No full-speed device qualifier descriptor */ |
| 387 | 0, /* No full-speed other speed configuration */ |
| 388 | 0, /* No high-speed device descriptor */ |
| 389 | 0, /* No high-speed configuration descriptor */ |
| 390 | 0, /* No high-speed device qualifier descriptor */ |
| 391 | 0, /* No high-speed other speed configuration descriptor */ |
| 392 | stringDescriptors, |
| 393 | STRING_DESC_CNT-1 /* cnt string descriptors in list */ |
| 394 | }; |
| 395 | |