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 { |
| 97 | NONE = 1, PRODUCT_STRING, SNIFFER_CONF_STR, CCIDRDR_CONF_STR, PHONE_CONF_STR, MITM_CONF_STR, STRING_DESC_CNT |
| 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 | |
| 114 | |
| 115 | /*------------------------------------------------------------------------------ |
| 116 | * USB Device descriptors |
| 117 | *------------------------------------------------------------------------------*/ |
| 118 | |
| 119 | typedef struct _SIMTraceDriverConfigurationDescriptorSniffer { |
| 120 | |
| 121 | /** Standard configuration descriptor. */ |
| 122 | USBConfigurationDescriptor configuration; |
| 123 | USBInterfaceDescriptor sniffer; |
| 124 | USBEndpointDescriptor sniffer_dataOut; |
| 125 | USBEndpointDescriptor sniffer_dataIn; |
| 126 | |
| 127 | } __attribute__ ((packed)) SIMTraceDriverConfigurationDescriptor; |
| 128 | |
| 129 | const SIMTraceDriverConfigurationDescriptorSniffer configurationDescriptorSniffer = { |
| 130 | /* Standard configuration descriptor */ |
| 131 | { |
| 132 | sizeof(USBConfigurationDescriptor), |
| 133 | USBGenericDescriptor_CONFIGURATION, |
| 134 | sizeof(SIMTraceDriverConfigurationDescriptorSniffer), |
| 135 | 1, /* There is one interface in this configuration */ |
| 136 | 1, /* This is configuration #1 */ |
| 137 | SNIFFER_CONF_STR, /* string descriptor for this configuration */ |
| 138 | USBD_BMATTRIBUTES, |
| 139 | USBConfigurationDescriptor_POWER(100) |
| 140 | }, |
| 141 | /* Communication class interface standard descriptor */ |
| 142 | { |
| 143 | sizeof(USBInterfaceDescriptor), |
| 144 | USBGenericDescriptor_INTERFACE, |
| 145 | 0, /* This is interface #0 */ |
| 146 | 0, /* This is alternate setting #0 for this interface */ |
| 147 | 2, /* This interface uses 2 endpoints */ |
| 148 | 0xff, /* Descriptor Class: Vendor specific */ |
| 149 | 0, /* No subclass */ |
| 150 | 0, /* No l */ |
| 151 | SNIFFER_CONF_STR /* Third in string descriptor for this interface */ |
| 152 | }, |
| 153 | /* Bulk-OUT endpoint standard descriptor */ |
| 154 | #define DATAOUT 1 |
| 155 | { |
| 156 | sizeof(USBEndpointDescriptor), |
| 157 | USBGenericDescriptor_ENDPOINT, |
| 158 | USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_OUT, |
| 159 | DATAOUT), |
| 160 | USBEndpointDescriptor_BULK, |
| 161 | MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(DATAOUT), |
| 162 | USBEndpointDescriptor_MAXBULKSIZE_FS), |
| 163 | 0 /* Must be 0 for full-speed bulk endpoints */ |
| 164 | }, |
| 165 | /* Bulk-IN endpoint descriptor */ |
| 166 | #define DATAIN 2 |
| 167 | { |
| 168 | sizeof(USBEndpointDescriptor), |
| 169 | USBGenericDescriptor_ENDPOINT, |
| 170 | USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN, |
| 171 | DATAIN), |
| 172 | USBEndpointDescriptor_BULK, |
| 173 | MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(DATAIN), |
| 174 | USBEndpointDescriptor_MAXBULKSIZE_FS), |
| 175 | 0 /* Must be 0 for full-speed bulk endpoints */ |
| 176 | } |
| 177 | }; |
| 178 | |
| 179 | /* FIXME: CCID descriptor: External C file */ |
| 180 | |
| 181 | typedef struct _SIMTraceDriverConfigurationDescriptorMITM { |
| 182 | |
| 183 | /** Standard configuration descriptor. */ |
| 184 | USBConfigurationDescriptor configuration; |
| 185 | USBInterfaceDescriptor simcard; |
| 186 | USBEndpointDescriptor simcard_dataOut; |
| 187 | USBEndpointDescriptor simcard_dataIn; |
| 188 | USBInterfaceDescriptor phone; |
| 189 | USBEndpointDescriptor phone_dataOut; |
| 190 | USBEndpointDescriptor phone_dataIn; |
| 191 | |
| 192 | } __attribute__ ((packed)) SIMTraceDriverConfigurationDescriptor; |
| 193 | |
| 194 | const SIMTraceDriverConfigurationDescriptorMITM configurationDescriptorsMITM = { |
| 195 | /* Standard configuration descriptor */ |
| 196 | { |
| 197 | sizeof(USBConfigurationDescriptor), |
| 198 | USBGenericDescriptor_CONFIGURATION, |
| 199 | sizeof(SIMTraceDriverConfigurationDescriptor), |
| 200 | 2, /* There are two interfaces in this configuration */ |
| 201 | 4, /* This is configuration #4 */ |
| 202 | MITM_CONF_STR, /* string descriptor for this configuration */ |
| 203 | USBD_BMATTRIBUTES, |
| 204 | USBConfigurationDescriptor_POWER(100) |
| 205 | }, |
| 206 | /* Communication class interface standard descriptor */ |
| 207 | { |
| 208 | sizeof(USBInterfaceDescriptor), |
| 209 | USBGenericDescriptor_INTERFACE, |
| 210 | 0, /* This is interface #0 */ |
| 211 | 0, /* This is alternate setting #0 for this interface */ |
| 212 | 2, /* This interface uses 2 endpoints */ |
| 213 | //CDCCommunicationInterfaceDescriptor_CLASS, |
| 214 | 0xff, |
| 215 | // CDCCommunicationInterfaceDescriptor_ABSTRACTCONTROLMODEL, |
| 216 | 0, |
| 217 | // CDCCommunicationInterfaceDescriptor_NOPROTOCOL, |
| 218 | 0, |
| 219 | MITM_CONF_STR /* string descriptor for this interface */ |
| 220 | }, |
| 221 | /* Bulk-OUT endpoint standard descriptor */ |
| 222 | #define DATAOUT 1 |
| 223 | { |
| 224 | sizeof(USBEndpointDescriptor), |
| 225 | USBGenericDescriptor_ENDPOINT, |
| 226 | USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_OUT, |
| 227 | DATAOUT), |
| 228 | USBEndpointDescriptor_BULK, |
| 229 | MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(DATAOUT), |
| 230 | USBEndpointDescriptor_MAXBULKSIZE_FS), |
| 231 | 0 /* Must be 0 for full-speed bulk endpoints */ |
| 232 | }, |
| 233 | /* Bulk-IN endpoint descriptor */ |
| 234 | #define DATAIN 2 |
| 235 | { |
| 236 | sizeof(USBEndpointDescriptor), |
| 237 | USBGenericDescriptor_ENDPOINT, |
| 238 | USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN, |
| 239 | DATAIN), |
| 240 | USBEndpointDescriptor_BULK, |
| 241 | MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(DATAIN), |
| 242 | USBEndpointDescriptor_MAXBULKSIZE_FS), |
| 243 | 0 /* Must be 0 for full-speed bulk endpoints */ |
| 244 | } |
| 245 | }; |
| 246 | |
| 247 | |
| 248 | /** Standard USB device descriptor for the CDC serial driver */ |
| 249 | const USBDeviceDescriptor deviceDescriptor = { |
| 250 | |
| 251 | sizeof(USBDeviceDescriptor), |
| 252 | USBGenericDescriptor_DEVICE, |
| 253 | USBDeviceDescriptor_USB2_00, |
| 254 | 0xff, |
| 255 | // CDCDeviceDescriptor_CLASS, |
| 256 | 0xff, |
| 257 | // CDCDeviceDescriptor_SUBCLASS, |
| 258 | 0xff, |
| 259 | // CDCDeviceDescriptor_PROTOCOL, |
| 260 | BOARD_USB_ENDPOINTS_MAXPACKETSIZE(0), |
| 261 | ATMEL_VENDOR_ID, |
| 262 | SIMTRACE_PRODUCT_ID, |
| 263 | 1, /* Release number */ |
| 264 | 0, /* No string descriptor for manufacturer */ |
| 265 | PRODUCT_STRING, /* Index of product string descriptor */ |
| 266 | 0, /* No string descriptor for serial number */ |
| 267 | 4 /* Device has 4 possible configurations */ |
| 268 | }; |
| 269 | |
| 270 | /* AT91SAM3S does only support full speed, but not high speed USB */ |
| 271 | const USBDDriverDescriptors driverDescriptors = { |
| 272 | &deviceDescriptor, |
| 273 | (USBConfigurationDescriptor **) &(configurationDescriptorSniffer), /* first full-speed configuration descriptor */ |
| 274 | 0, /* No full-speed device qualifier descriptor */ |
| 275 | 0, /* No full-speed other speed configuration */ |
| 276 | 0, /* No high-speed device descriptor */ |
| 277 | 0, /* No high-speed configuration descriptor */ |
| 278 | 0, /* No high-speed device qualifier descriptor */ |
| 279 | 0, /* No high-speed other speed configuration descriptor */ |
| 280 | stringDescriptors, |
| 281 | STRING_DESC_CNT-1 /* cnt string descriptors in list */ |
| 282 | }; |
| 283 | |