Contiki 2.5
usb_descriptors.h
Go to the documentation of this file.
1 /* This file has been prepared for Doxygen automatic documentation generation.*/
2 /*! \file usb_descriptors.h ***************************************************
3  *
4  * \brief
5  * This file contains the usb parameters that uniquely identify the
6  * application through descriptor tables.
7  *
8  * \addtogroup usbstick
9  *
10  * \author
11  * Atmel Corporation: http://www.atmel.com
12  * \author
13  * Colin O'Flynn <coflynn@newae.com>
14  *
15  ******************************************************************************/
16 /* Copyright (c) 2008 ATMEL Corporation
17  Copyright (c) 2008 Colin O'Flynn
18  All rights reserved.
19 
20  Redistribution and use in source and binary forms, with or without
21  modification, are permitted provided that the following conditions are met:
22 
23  * Redistributions of source code must retain the above copyright
24  notice, this list of conditions and the following disclaimer.
25  * Redistributions in binary form must reproduce the above copyright
26  notice, this list of conditions and the following disclaimer in
27  the documentation and/or other materials provided with the
28  distribution.
29  * Neither the name of the copyright holders nor the names of
30  contributors may be used to endorse or promote products derived
31  from this software without specific prior written permission.
32 
33  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
34  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
35  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
36  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
37  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
38  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
39  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
40  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
41  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
42  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
43  POSSIBILITY OF SUCH DAMAGE.
44 */
45 
46 /**
47  \addtogroup usbconf
48  @{
49  */
50 
51 #ifndef _USB_USERCONFIG_H_
52 #define _USB_USERCONFIG_H_
53 
54 //_____ I N C L U D E S ____________________________________________________
55 
56 #include "config.h"
57 #include "usb_standard_request.h"
58 #include "conf_usb.h"
59 #include <avr/pgmspace.h>
60 
61 //_____ M A C R O S ________________________________________________________
62 
63 
64 //_____ U S B D E F I N E _______________________________________________
65 
66  // USB Device descriptor
67 #define USB_SPECIFICATION 0x0200
68 #if USB_CONF_MACINTOSH
69 #define COMPOSITE_DEVICE_CLASS 0x02 // Misc
70 #define COMPOSITE_DEVICE_SUB_CLASS 0x00 // Common
71 #define COMPOSITE_DEVICE_PROTOCOL 0x00 // IAD
72 #else //Windows wants these for composite device
73 //Above seems to work for Vista and Win7 but XP and Ubuntu 904 might need the old values
74 #define COMPOSITE_DEVICE_CLASS 0xEF // Misc
75 #define COMPOSITE_DEVICE_SUB_CLASS 0x02 // Common
76 #define COMPOSITE_DEVICE_PROTOCOL 0x01 // IAD
77 #endif
78 
79 #define NETWORK_DEVICE_CLASS 0x02 // CDC ACM
80 #define NETWORK_DEVICE_SUB_CLASS 0x02 //
81 #define NETWORK_DEVICE_PROTOCOL 0xFF // Vendor-specific
82 
83 #define MASS_DEVICE_CLASS 0x00 //
84 #define MASS_DEVICE_SUB_CLASS 0x00 //
85 #define MASS_DEVICE_PROTOCOL 0x00 //
86 
87 #define EEM_DEVICE_CLASS 0x02 // CDC
88 #define EEM_DEVICE_SUB_CLASS 0x0C // EEM
89 #define EEM_DEVICE_PROTOCOL 0x07 // EEM
90 
91 #define EP_CONTROL_LENGTH 64
92 #define VENDOR_ID 0x03EB // Atmel vendor ID = 03EBh
93 
94 #if USB_CONF_MACINTOSH
95 //A different product ID avoids instant windows corruption when it tries to use the cached drivers
96 //TODO:Get some valid ID's from Atmel
97 #define COMPOSITE_PRODUCT_ID 0x9921 //Product ID for composite device
98 #define NETWORK_PRODUCT_ID 0x9919 //Product ID for just CDC-ECM device
99 #else
100 #define COMPOSITE_PRODUCT_ID 0x2021 //Product ID for composite device
101 #define NETWORK_PRODUCT_ID 0x2019 //Product ID for just RNDIS device
102 #endif
103 
104 #define MASS_PRODUCT_ID 0x202F //Product ID for mass storage
105 #define RELEASE_NUMBER 0x1000
106 
107 enum {
108  USB_STRING_NONE = 0,
109  USB_STRING_MAN = 1,
110  USB_STRING_PRODUCT,
111  USB_STRING_SERIAL,
112  USB_STRING_MAC_ADDRESS,
113  USB_STRING_CONFIG_COMPOSITE,
114  USB_STRING_CONFIG_RNDIS,
115  USB_STRING_CONFIG_EEM,
116  USB_STRING_CONFIG_ECM,
117  USB_STRING_CONFIG_ECM_DEBUG,
118  USB_STRING_CONFIG_MS,
119  USB_STRING_INTERFACE_RNDIS,
120  USB_STRING_INTERFACE_EEM,
121  USB_STRING_INTERFACE_ECM,
122  USB_STRING_INTERFACE_ECM_ATTACHED,
123  USB_STRING_INTERFACE_ECM_DETACHED,
124  USB_STRING_INTERFACE_SERIAL,
125  USB_STRING_INTERFACE_MS,
126 
127 };
128 
129 enum {
130  USB_CONFIG_UNCONFIGURED = 0,
131 
132  USB_CONFIG_RNDIS = 1,
133  USB_CONFIG_RNDIS_DEBUG = 1+(1<<7),
134 
135  USB_CONFIG_ECM = 2,
136  USB_CONFIG_ECM_DEBUG = 2+(1<<7),
137 
138  USB_CONFIG_EEM = 3,
139 
140 #if USB_CONF_STORAGE
141  USB_CONFIG_MS = 4,
142 #endif
143 };
144 
145 #define USB_CONFIG_HAS_DEBUG_PORT(x) ((x==USB_CONFIG_ECM_DEBUG)||(x==USB_CONFIG_RNDIS_DEBUG))
146 
147 //#define USB_CONFIG_COUNT (USB_CONFIG_COUNT_PLUS_ONE-1)
148 //#define NB_CONFIGURATION USB_CONFIG_COUNT
149 
150 #define NETWORK_NB_INTERFACE 2
151 #define COMPOSITE_NB_INTERFACE 4
152 #define MASS_NB_INTERFACE 1
153 #define EEM_NB_INTERFACE 1
154 #define CONF_NB 1
155 #define CONF_INDEX 0
156 #define CONF_ATTRIBUTES USB_CONFIG_BUSPOWERED
157 #define MAX_POWER 50 // 100 mA
158 
159 /*** CDC RNDIS CONFIGURATION CONFIGURATION ***/
160 
161 // Interface 0 descriptor
162 #define INTERFACE0_NB 0
163 #define ALTERNATE0 0
164 #define NB_ENDPOINT0 1
165 #define INTERFACE0_CLASS 0x02 // CDC ACM Com
166 #define INTERFACE0_SUB_CLASS 0x02
167 #define INTERFACE0_PROTOCOL 0xFF // Vendor specific
168 #define INTERFACE0_INDEX 0
169 
170 // Interface 1 descriptor
171 #define INTERFACE1_NB 1
172 #define ALTERNATE1 0
173 #define NB_ENDPOINT1 2
174 #define INTERFACE1_CLASS 0x0A // CDC ACM Data
175 #define INTERFACE1_SUB_CLASS 0
176 #define INTERFACE1_PROTOCOL 0
177 #define INTERFACE1_INDEX 0
178 
179  // USB Endpoint 1 descriptor
180  // Interrupt IN
181 #define ENDPOINT_NB_1 0x80 | INT_EP
182 #define EP_ATTRIBUTES_1 0x03 // BULK = 0x02, INTERUPT = 0x03
183 #define EP_SIZE_1 0x08
184 #define EP_INTERVAL_1 0x01 //ms interrupt pooling from host
185 
186  // USB Endpoint 1 descriptor
187  // Bulk IN
188 #define ENDPOINT_NB_2 0x80 | TX_EP
189 #define EP_ATTRIBUTES_2 0x02 // BULK = 0x02, INTERUPT = 0x03
190 #define EP_SIZE_2 0x40 //64 byte max size
191 #define EP_INTERVAL_2 0x01
192 
193  // USB Endpoint 2 descriptor
194  //Bulk OUT RX endpoint
195 #define ENDPOINT_NB_3 RX_EP
196 #define EP_ATTRIBUTES_3 0x02 // BULK = 0x02, INTERUPT = 0x03
197 #define EP_SIZE_3 0x40 //64 byte max size
198 #define EP_INTERVAL_3 0x01
199 
200 /*** CDC Virtual Serial Port ***/
201 
202  // Interface 2 descriptor
203 #define INTERFACE2_NB 2
204 #define ALTERNATE2 0
205 #define NB_ENDPOINT2 1
206 #define INTERFACE2_CLASS 0x02 // CDC ACM Com
207 #define INTERFACE2_SUB_CLASS 0x02
208 #define INTERFACE2_PROTOCOL 0x01
209 #define INTERFACE2_INDEX 0
210 
211  // Interface 3 descriptor
212 #define INTERFACE3_NB 3
213 #define ALTERNATE3 0
214 #define NB_ENDPOINT3 2
215 #define INTERFACE3_CLASS 0x0A // CDC ACM Data
216 #define INTERFACE3_SUB_CLASS 0
217 #define INTERFACE3_PROTOCOL 0
218 #define INTERFACE3_INDEX 0
219 
220  // USB Endpoint 4 descriptor
221  // Interrupt IN
222 #define TX_EP_SIZE 0x20
223 #define ENDPOINT_NB_4 0x80 | VCP_INT_EP
224 #define EP_ATTRIBUTES_4 0x03 // BULK = 0x02, INTERUPT = 0x03
225 #define EP_SIZE_4 TX_EP_SIZE
226 #define EP_INTERVAL_4 0xFF //ms interrupt pooling from host
227 
228  // USB Endpoint 5 descriptor
229  // Bulk IN
230 #define ENDPOINT_NB_5 0x80 | VCP_TX_EP
231 #define EP_ATTRIBUTES_5 0x02 // BULK = 0x02, INTERUPT = 0x03
232 #define EP_SIZE_5 0x20
233 #define EP_INTERVAL_5 0x01
234 
235  // USB Endpoint 6 descriptor
236  // Bulk OUT
237 #define ENDPOINT_NB_6 VCP_RX_EP
238 #define EP_ATTRIBUTES_6 0x02 // BULK = 0x02, INTERUPT = 0x03
239 #define EP_SIZE_6 0x20
240 #define EP_INTERVAL_6 0x01
241 
242 /*** Mass Storage ***/
243 
244 #define MS_INTERFACE_NB 0
245 #define MS_ALTERNATE 0
246 #define MS_NB_ENDPOINT 2
247 #define MS_INTERFACE_CLASS 0x08 // Mass Storage Class
248 #define MS_INTERFACE_SUB_CLASS 0x06 // SCSI transparent Command Set
249 #define MS_INTERFACE_PROTOCOL 0x50 // Bulk-Only Transport
250 #define MS_INTERFACE_INDEX 0
251 
252 // USB Endpoint 1 descriptor FS
253 #define MS_ENDPOINT_NB_1 (MS_IN_EP | 0x80)
254 #define MS_EP_ATTRIBUTES_1 0x02 // BULK = 0x02, INTERUPT = 0x03
255 #define MS_EP_IN_LENGTH 64
256 #define MS_EP_SIZE_1 MS_EP_IN_LENGTH
257 #define MS_EP_INTERVAL_1 0x00
258 
259 
260 // USB Endpoint 2 descriptor FS
261 #define MS_ENDPOINT_NB_2 MS_OUT_EP
262 #define MS_EP_ATTRIBUTES_2 0x02 // BULK = 0x02, INTERUPT = 0x03
263 #define MS_EP_IN_LENGTH 64
264 #define MS_EP_SIZE_2 MS_EP_IN_LENGTH
265 #define MS_EP_INTERVAL_2 0x00
266 
267 /******* EEM Configuration *******/
268 
269 // Interface 0 descriptor
270 #define EEM_INTERFACE0_NB 0
271 #define EEM_ALTERNATE0 0
272 #define EEM_NB_ENDPOINT0 2
273 #define EEM_INTERFACE0_CLASS 0x02 // CDC ACM Com
274 #define EEM_INTERFACE0_SUB_CLASS 0x0C // EEM
275 #define EEM_INTERFACE0_PROTOCOL 0x07 // EEM
276 #define EEM_INTERFACE0_INDEX 0
277 
278  // USB Endpoint 1 descriptor
279  // Bulk IN
280 #define EEM_ENDPOINT_NB_1 0x80 | TX_EP
281 #define EEM_EP_ATTRIBUTES_1 0x02 // BULK = 0x02, INTERUPT = 0x03
282 #define EEM_EP_SIZE_1 0x40 //64 byte max size
283 #define EEM_EP_INTERVAL_1 0x01
284 
285  // USB Endpoint 2 descriptor
286  // Bulk OUT
287 #define EEM_ENDPOINT_NB_2 RX_EP
288 #define EEM_EP_ATTRIBUTES_2 0x02 // BULK = 0x02, INTERUPT = 0x03
289 #define EEM_EP_SIZE_2 0x40 //64 byte max size
290 #define EEM_EP_INTERVAL_2 0x01
291 
292 /******* ECM Configuration *******/
293 
294 // Interface 0 descriptor
295 #define ECM_INTERFACE0_NB 0
296 #define ECM_ALTERNATE0 0
297 #define ECM_NB_ENDPOINT0 2
298 #define ECM_INTERFACE0_CLASS 0x02 // CDC ACM Com
299 #define ECM_INTERFACE0_SUB_CLASS 0x06 // ECM
300 #define ECM_INTERFACE0_PROTOCOL 0x00 // Empty
301 #define ECM_INTERFACE0_INDEX 0
302 
303 
304 
305 #define DEVICE_STATUS 0x00 // TBD
306 #define INTERFACE_STATUS 0x00 // TBD
307 
308 #define LANG_ID 0x00
309 
310 #define LANGUAGE_ID 0x0409
311 
312  //! Usb Request
313 typedef struct
314 {
315  U8 bmRequestType; //!< Characteristics of the request
316  U8 bRequest; //!< Specific request
317  U16 wValue; //!< field that varies according to request
318  U16 wIndex; //!< field that varies according to request
319  U16 wLength; //!< Number of bytes to transfer if Data
320 } S_UsbRequest;
321 
322  //! Usb Device Descriptor
323 typedef struct {
324  U8 bLength; //!< Size of this descriptor in bytes
325  U8 bDescriptorType; //!< DEVICE descriptor type
326  U16 bscUSB; //!< Binay Coded Decimal Spec. release
327  U8 bDeviceClass; //!< Class code assigned by the USB
328  U8 bDeviceSubClass; //!< Sub-class code assigned by the USB
329  U8 bDeviceProtocol; //!< Protocol code assigned by the USB
330  U8 bMaxPacketSize0; //!< Max packet size for EP0
331  U16 idVendor; //!< Vendor ID. ATMEL = 0x03EB
332  U16 idProduct; //!< Product ID assigned by the manufacturer
333  U16 bcdDevice; //!< Device release number
334  U8 iManufacturer; //!< Index of manu. string descriptor
335  U8 iProduct; //!< Index of prod. string descriptor
336  U8 iSerialNumber; //!< Index of S.N. string descriptor
337  U8 bNumConfigurations; //!< Number of possible configurations
339 
340 
341  //! Usb Configuration Descriptor
342 typedef struct {
343  U8 bLength; //!< size of this descriptor in bytes
344  U8 bDescriptorType; //!< CONFIGURATION descriptor type
345  U16 wTotalLength; //!< total length of data returned
346  U8 bNumInterfaces; //!< number of interfaces for this conf.
347  U8 bConfigurationValue; //!< value for SetConfiguration resquest
348  U8 iConfiguration; //!< index of string descriptor
349  U8 bmAttibutes; //!< Configuration characteristics
350  U8 MaxPower; //!< maximum power consumption
352 
353 
354  //! Usb Interface Descriptor
355 typedef struct {
356  U8 bLength; //!< size of this descriptor in bytes
357  U8 bDescriptorType; //!< INTERFACE descriptor type
358  U8 bInterfaceNumber; //!< Number of interface
359  U8 bAlternateSetting; //!< value to select alternate setting
360  U8 bNumEndpoints; //!< Number of EP except EP 0
361  U8 bInterfaceClass; //!< Class code assigned by the USB
362  U8 bInterfaceSubClass; //!< Sub-class code assigned by the USB
363  U8 bInterfaceProtocol; //!< Protocol code assigned by the USB
364  U8 iInterface; //!< Index of string descriptor
366 
367 
368  //! Usb Endpoint Descriptor
369 typedef struct {
370  U8 bLength; //!< Size of this descriptor in bytes
371  U8 bDescriptorType; //!< ENDPOINT descriptor type
372  U8 bEndpointAddress; //!< Address of the endpoint
373  U8 bmAttributes; //!< Endpoint's attributes
374  U16 wMaxPacketSize; //!< Maximum packet size for this EP
375  U8 bInterval; //!< Interval for polling EP in ms
377 
378 
379  //! Usb Device Qualifier Descriptor
380 typedef struct {
381  U8 bLength; //!< Size of this descriptor in bytes
382  U8 bDescriptorType; //!< Device Qualifier descriptor type
383  U16 bscUSB; //!< Binay Coded Decimal Spec. release
384  U8 bDeviceClass; //!< Class code assigned by the USB
385  U8 bDeviceSubClass; //!< Sub-class code assigned by the USB
386  U8 bDeviceProtocol; //!< Protocol code assigned by the USB
387  U8 bMaxPacketSize0; //!< Max packet size for EP0
388  U8 bNumConfigurations; //!< Number of possible configurations
389  U8 bReserved; //!< Reserved for future use, must be zero
391 
392 
393  //! Usb Language Descriptor
394 typedef struct {
395  U8 bLength; //!< size of this descriptor in bytes
396  U8 bDescriptorType; //!< STRING descriptor type
397  U16 wlangid; //!< language id
399 
400 
401 /*_____ U S B I A D _______________________________________________________*/
402 
403 #define DSC_TYPE_IAD 11
404 
405 typedef struct
406 {
407  U8 bLength;
408  U8 bDescriptorType;
409  U8 bFirstInterface;
410  U8 bInterfaceCount;
411  U8 bFunctionClass;
412  U8 bFunctionSubClass;
413  U8 bFunctionProtocol;
414  U8 iInterface;
415 } S_usb_interface_association_descriptor;
416 
417 /*_____ U S B D E S C R I P T O R __________________________________*/
418 
419 /* RNDIS + Serial Port */
420 typedef struct
421 {
423 
424  S_usb_interface_association_descriptor iad0;
426  U8 CS1_INTERFACE[19];
431 
432  S_usb_interface_association_descriptor iad1;
434  U8 CS2_INTERFACE[19];
439 
440 } S_usb_user_configuration_descriptor_composite;
441 
442 /* Just RNDIS */
443 typedef struct
444 {
447  U8 CS1_INTERFACE[19];
452 
453 } S_usb_user_configuration_descriptor_network;
454 
455 /* EEM */
456 typedef struct
457 {
462 } S_usb_user_configuration_descriptor_eem;
463 
464 
465 
466 
467 typedef struct
468 {
469  U8 bLength;
470  U8 bDescriptorType;
471  U8 bDescriptorSubtype;
472  U8 iMACAddress;
473  U32 bmEthernetStatistics;
474  U16 wMaxSegmentSize;
475  U16 wNumberMCFilters;
476  U8 bNumberPowerFilters;
477 } S_usb_ethernet_networking_functional_descriptor;
478 
479 
480 /* ECM */
481 typedef struct
482 {
485  U8 CS1_INTERFACE[5+5];
486  S_usb_ethernet_networking_functional_descriptor fd0;
487 #if CDC_ECM_USES_INTERRUPT_ENDPOINT
489 #endif
490 #if 0
492 #endif
496 } S_usb_user_configuration_descriptor_ecm;
497 
498 
499 /* ECM + Serial Port */
500 typedef struct
501 {
503  S_usb_interface_association_descriptor iad0;
505  U8 CS1_INTERFACE[5+5];
506  S_usb_ethernet_networking_functional_descriptor fd0;
507 #if CDC_ECM_USES_INTERRUPT_ENDPOINT
509 #endif
510 #if 0
512 #endif
516 
517  S_usb_interface_association_descriptor iad1;
519  U8 CS2_INTERFACE[19];
524 
525 } S_usb_user_configuration_descriptor_ecm_debug;
526 
527 
528 /* Mass Storage */
529 
530 typedef struct
531 {
536 
537 } S_usb_user_configuration_descriptor_mass;
538 
539 
540 
541 PGM_VOID_P Usb_get_dev_desc_pointer(void);
542 U8 Usb_get_dev_desc_length(void);
543 PGM_VOID_P Usb_get_conf_desc_pointer(U8 index) ;
544 U8 Usb_get_conf_desc_length(U8 index);
545 
546 #endif // _USB_USERCONFIG_H_
547 
548 /** @} */