Contiki 2.5
usb_descriptors.c
Go to the documentation of this file.
1 /* This file has been prepared for Doxygen automatic documentation generation.*/
2 /*! \file usb_descriptors.c *****************************************************
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 \n
12  * Support email: avr@atmel.com
13  * \author
14  * Colin O'Flynn <coflynn@newae.com>
15  *
16  ******************************************************************************/
17 /* Copyright (c) 2008 ATMEL Corporation
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 //_____ I N C L U D E S ____________________________________________________
52 
53 #include "config.h"
54 
55 #include "usb_drv.h"
56 #include "usb_descriptors.h"
57 #include "usb_specific_request.h"
58 #include "rndis/rndis_task.h"
59 
60 
61 //_____ M A C R O S ________________________________________________________
62 
63 
64 #define USB_ETH_NET_FUNC_DESC(MACAddrString,etherStat,maxSegmentSize,nMCFilters,nPowerFilters) \
65  { sizeof(S_usb_ethernet_networking_functional_descriptor) \
66  , 0x24, 0x0F \
67 , MACAddrString \
68 , etherStat \
69 , Usb_write_word_enum_struc(maxSegmentSize) \
70 , Usb_write_word_enum_struc(nMCFilters) \
71 , nPowerFilters \
72 }
73 
74 
75 
76 #define USB_CONFIG_DESC(totalsize,interfaceCount,value,stringIndex,attr,power) \
77  { sizeof(S_usb_configuration_descriptor) \
78  , CONFIGURATION_DESCRIPTOR \
79  , Usb_write_word_enum_struc(totalsize) \
80  , interfaceCount \
81  , value \
82  , stringIndex \
83  , attr \
84  , power \
85  }
86 
87 #define USB_ENDPOINT(nb,attr,maxpktsize,interval) \
88 { sizeof(S_usb_endpoint_descriptor) \
89  , ENDPOINT_DESCRIPTOR \
90  , nb \
91  , attr \
92  , Usb_write_word_enum_struc(maxpktsize) \
93  , interval \
94  }
95 
96 #define USB_IAD(firstinterface,interfacecount,funcClass,funcSubClass,funcProto,stringIndex) \
97  { \
98  sizeof(S_usb_interface_association_descriptor), \
99  DSC_TYPE_IAD, \
100  firstinterface, \
101  interfacecount, \
102  funcClass, \
103  funcSubClass, \
104  funcProto, \
105  stringIndex \
106  }
107 
108 #define USB_INTERFACEDESC(nb,altsetting,endpointCount,interfaceClass,interfaceSubClass,interfaceProto,stringIndex) \
109  { sizeof(S_usb_interface_descriptor) \
110  , INTERFACE_DESCRIPTOR \
111  , nb \
112  , altsetting \
113  , endpointCount \
114  , interfaceClass \
115  , interfaceSubClass \
116  , interfaceProto \
117  , stringIndex \
118  }
119 
120 
121 #define FUNC_DESC_HEADER \
122 0x05, /* bFunctionLength, Descriptor size in bytes*/ \
123 0x24, /* bDescriptorType, CS_INTERFACE */ \
124 0x00, /* bDescriptorSubtype, Header Functional Descriptor */ \
125 0x10,0x01 /* bcdCDC, CDC specification release number in BCD format (1,1) */
126 
127 #define FUNC_DESC_CALL_MANAGEMENT(caps,dataInterface) \
128 0x05, /* bFunctionLength, Descriptor size in bytes */ \
129 0x24, /* bDescriptorType, CS_INTERFACE */ \
130 0x01, /* bDescriptorSubtype, Call Management Functional Descriptor */ \
131 caps, /* bmCapabilities */ \
132 dataInterface /* bDataInterface, Interface used for call management */
133 
134 /* Abstract Control Management Functional Descriptor */
135 #define FUNC_DESC_ABSTRACT_CONTROL_MANAGEMENT(caps) \
136 0x04, /* bFunctionLength, Descriptor size in bytes */ \
137 0x24, /* bDescriptorType, CS_INTERFACE */ \
138 0x02, /* bDescriptorSubtype, Call Management Functional Descriptor */ \
139 caps /* bmCapabilities */
140 
141 /* Union Functional Descriptor */ \
142 #define FUNC_DESC_UNION(masterInterface,slaveInterface) \
143 0x05, /* bFunctionLength, Descriptor size in bytes */ \
144 0x24, /* bDescriptorType, CS_INTERFACE */ \
145 0x06, /* bDescriptorSubtype, Union Functional Descriptor */ \
146 masterInterface, /* bMasterInterface, The controlling interface for the union (bInterfaceNumber of a Communication or Data Class interface in this configuration) */ \
147 slaveInterface /* bSlaveInterface0, The controlled interace in the union (bInterfaceNumber of an interface in this configuration) */ \
148 
149 #define RNDIS_INTERFACES \
150 USB_INTERFACEDESC( \
151  INTERFACE0_NB, \
152  ALTERNATE0, \
153  NB_ENDPOINT0, \
154  INTERFACE0_CLASS, \
155  INTERFACE0_SUB_CLASS, \
156  INTERFACE0_PROTOCOL, \
157  USB_STRING_INTERFACE_RNDIS \
158 ), \
159  { \
160  FUNC_DESC_HEADER, \
161  FUNC_DESC_CALL_MANAGEMENT(0x00/*caps*/,0x00/*dataInterface*/), \
162  FUNC_DESC_ABSTRACT_CONTROL_MANAGEMENT(0x00), \
163  FUNC_DESC_UNION(0x00,0x01), \
164  }, \
165  USB_ENDPOINT(ENDPOINT_NB_1,EP_ATTRIBUTES_1,EP_SIZE_1,EP_INTERVAL_1), \
166 \
167 USB_INTERFACEDESC( \
168  INTERFACE1_NB, \
169  ALTERNATE1, \
170  NB_ENDPOINT1, \
171  INTERFACE1_CLASS, \
172  INTERFACE1_SUB_CLASS, \
173  INTERFACE1_PROTOCOL, \
174  USB_STRING_NONE \
175 ), \
176  USB_ENDPOINT(ENDPOINT_NB_2,EP_ATTRIBUTES_2,EP_SIZE_2,EP_INTERVAL_2), \
177  USB_ENDPOINT(ENDPOINT_NB_3,EP_ATTRIBUTES_3,EP_SIZE_3,EP_INTERVAL_3)
178 
179 #define CDC_SERIAL_INTERFACES \
180 USB_INTERFACEDESC( \
181  INTERFACE2_NB, \
182  ALTERNATE2, \
183  NB_ENDPOINT2, \
184  INTERFACE2_CLASS, \
185  INTERFACE2_SUB_CLASS, \
186  INTERFACE2_PROTOCOL, \
187  USB_STRING_INTERFACE_SERIAL \
188 ), \
189 { \
190  FUNC_DESC_HEADER, \
191  FUNC_DESC_CALL_MANAGEMENT(0x03/*caps*/,0x03/*dataInterface*/), \
192  FUNC_DESC_ABSTRACT_CONTROL_MANAGEMENT(0x02), \
193  FUNC_DESC_UNION(0x02,0x03), \
194 }, \
195 USB_ENDPOINT(ENDPOINT_NB_4,EP_ATTRIBUTES_4,EP_SIZE_4,EP_INTERVAL_4), \
196 USB_INTERFACEDESC( \
197  INTERFACE3_NB, \
198  ALTERNATE3, \
199  NB_ENDPOINT3, \
200  INTERFACE3_CLASS, \
201  INTERFACE3_SUB_CLASS, \
202  INTERFACE3_PROTOCOL, \
203  USB_STRING_NONE \
204 ), \
205 USB_ENDPOINT(ENDPOINT_NB_5,EP_ATTRIBUTES_5,EP_SIZE_5,EP_INTERVAL_5), \
206 USB_ENDPOINT(ENDPOINT_NB_6,EP_ATTRIBUTES_6,EP_SIZE_6,EP_INTERVAL_6)
207 
208 #define CDC_EEM_INTERFACES \
209 USB_INTERFACEDESC( \
210  EEM_INTERFACE0_NB, \
211  EEM_ALTERNATE0, \
212  EEM_NB_ENDPOINT0, \
213  EEM_INTERFACE0_CLASS, \
214  EEM_INTERFACE0_SUB_CLASS, \
215  EEM_INTERFACE0_PROTOCOL, \
216  USB_STRING_INTERFACE_EEM \
217 ), \
218  USB_ENDPOINT(ENDPOINT_NB_1,EP_ATTRIBUTES_1,EP_SIZE_1,EP_INTERVAL_1), \
219  USB_ENDPOINT(ENDPOINT_NB_2,EP_ATTRIBUTES_2,EP_SIZE_2,EP_INTERVAL_2)
220 
221 
222 
223 
224 #if CDC_ECM_USES_INTERRUPT_ENDPOINT
225 #define CDC_ECM_CONTROL_ENDPOINT_COUNT 1
226 #define CDC_ECM_CONTROL_ENDPOINT USB_ENDPOINT(ENDPOINT_NB_1,EP_ATTRIBUTES_1,EP_SIZE_1,EP_INTERVAL_1),
227 #else
228 #define CDC_ECM_CONTROL_ENDPOINT_COUNT 0
229 #define CDC_ECM_CONTROL_ENDPOINT
230 #endif
231 
232 
233 #define CDC_ECM_INTERFACES \
234 USB_INTERFACEDESC( \
235  ECM_INTERFACE0_NB, \
236  ECM_ALTERNATE0, \
237  CDC_ECM_CONTROL_ENDPOINT_COUNT, \
238  ECM_INTERFACE0_CLASS, \
239  ECM_INTERFACE0_SUB_CLASS, \
240  ECM_INTERFACE0_PROTOCOL, \
241  USB_STRING_INTERFACE_ECM \
242 ), \
243 { \
244  FUNC_DESC_HEADER, \
245  FUNC_DESC_UNION(0x00,0x01), \
246 }, \
247  USB_ETH_NET_FUNC_DESC( \
248  USB_STRING_MAC_ADDRESS, \
249  0, /* Support no stats for now */ \
250  USB_ETH_MTU, /* maxSegmentSize */ \
251  0, /* nMCFilters*/ \
252  0 /*nPowerFilters*/ \
253  ), \
254  CDC_ECM_CONTROL_ENDPOINT \
255 USB_INTERFACEDESC( \
256  ECM_INTERFACE0_NB+1, \
257  0, \
258  2, \
259  10, \
260  0, \
261  0, \
262  USB_STRING_NONE \
263 ), \
264  USB_ENDPOINT(ENDPOINT_NB_2,EP_ATTRIBUTES_2,EP_SIZE_2,EP_INTERVAL_2), \
265  USB_ENDPOINT(ENDPOINT_NB_3,EP_ATTRIBUTES_3,EP_SIZE_3,EP_INTERVAL_3)
266 
267 /*
268 USB_INTERFACEDESC( \
269  ECM_INTERFACE0_NB+1, \
270  0, \
271  0, \
272  10, \
273  0, \
274  0, \
275  USB_STRING_NONE \
276 ), \
277 */
278 
279 
280 
281 //_____ D E F I N I T I O N ________________________________________________
282 
283 /************* COMPOSITE DEVICE DESCRIPTORS (using IAD) **********/
284 //TODO:Serial port enumeration will prevent falling through to the
285 //supported network on Mac or Windows. Linux will take either.
286 //Once Windows loads the RNDIS driver it will use it on a subsequent
287 //Mac enumeration, and the device will fail to start.
288 //This doesn't seem to hurt anything but beware, system corruption is
289 //a possibility.
290 #if USB_CONF_MACINTOSH
291 /* Prefer CDC-ECM network enumeration (Macintosh, linux) */
292 FLASH uint8_t usb_dev_config_order[] = {
293  USB_CONFIG_RNDIS, //windows gets networking only (if not here gets serial only)
294 #if USB_CONF_SERIAL
295  USB_CONFIG_ECM_DEBUG, //mac, linux get networking and serial port
296 #endif
297  USB_CONFIG_ECM,
298 #if USB_CONF_SERIAL
299  USB_CONFIG_RNDIS_DEBUG,
300 #endif
301 // USB_CONFIG_RNDIS,
302  USB_CONFIG_EEM,
303 #if USB_CONF_STORAGE
304  USB_CONFIG_MS,
305 #endif
306 };
307 #else
308 /* Prefer RNDIS network enumeration (Windows, linux) */
309 FLASH uint8_t usb_dev_config_order[] = {
310 
311 // USB_CONFIG_ECM, //windows doesnt like this here, will not go on to RNDIS
312 #if USB_CONF_SERIAL
313  USB_CONFIG_RNDIS_DEBUG,
314 #else
315  USB_CONFIG_RNDIS,
316 #endif
317 #if 0 //XP may have a problem with these extra configurations
318  USB_CONFIG_RNDIS,
319 #if USB_CONF_SERIAL
320  USB_CONFIG_ECM_DEBUG,
321 #endif
322  USB_CONFIG_ECM,
323  USB_CONFIG_EEM,
324 #if USB_CONF_STORAGE
325  USB_CONFIG_MS,
326 #endif
327 #endif
328 };
329 #endif /* USB_CONF_MACINTOSH */
330 
331 // usb_user_device_descriptor
332 FLASH S_usb_device_descriptor usb_dev_desc_composite =
333 {
334  sizeof(usb_dev_desc_composite)
335 , DEVICE_DESCRIPTOR
336 , Usb_write_word_enum_struc(USB_SPECIFICATION)
337 , COMPOSITE_DEVICE_CLASS
338 , COMPOSITE_DEVICE_SUB_CLASS
339 , COMPOSITE_DEVICE_PROTOCOL
340 , EP_CONTROL_LENGTH
341 , Usb_write_word_enum_struc(VENDOR_ID)
342 , Usb_write_word_enum_struc(COMPOSITE_PRODUCT_ID)
343 , Usb_write_word_enum_struc(RELEASE_NUMBER)
344 , USB_STRING_MAN
345 , USB_STRING_PRODUCT
346 , USB_STRING_SERIAL
347 , (sizeof(usb_dev_config_order)/sizeof(*usb_dev_config_order)) //sizeof(*) is sizeof first element
348 };
349 
350 
351 // usb_user_configuration_descriptor FS
352 FLASH S_usb_user_configuration_descriptor_composite usb_conf_desc_composite = {
353  USB_CONFIG_DESC(
354  sizeof(usb_conf_desc_composite),
355  COMPOSITE_NB_INTERFACE,
356  USB_CONFIG_RNDIS_DEBUG,
357  USB_STRING_CONFIG_COMPOSITE,
358  CONF_ATTRIBUTES,
359  MAX_POWER
360  ),
361 
362  USB_IAD(
363  0x00, // First interface
364  0x02, // Interface count
365  0x02, // Function Class
366  0x02, // Function Subclass
367  0xFF, // Function Protocol
368  USB_STRING_INTERFACE_RNDIS
369  ),RNDIS_INTERFACES,
370 
371  USB_IAD(
372  0x02, // First interface
373  0x02, // Interface count
374  0x02, // Function Class
375  0x02, // Function Subclass
376  0x01, // Function Protocol
377  USB_STRING_INTERFACE_SERIAL
378  ),CDC_SERIAL_INTERFACES
379 };
380 
381 /****************** NETWORK-ONLY DEVICE DESCRIPTORS **************************/
382 
383 /*
384 FLASH S_usb_device_descriptor usb_dev_desc_network =
385 {
386  sizeof(usb_dev_desc_network)
387 , DEVICE_DESCRIPTOR
388 , Usb_write_word_enum_struc(USB_SPECIFICATION)
389 , NETWORK_DEVICE_CLASS
390 , NETWORK_DEVICE_SUB_CLASS
391 , NETWORK_DEVICE_PROTOCOL
392 , EP_CONTROL_LENGTH
393 , Usb_write_word_enum_struc(VENDOR_ID)
394 , Usb_write_word_enum_struc(NETWORK_PRODUCT_ID)
395 , Usb_write_word_enum_struc(RELEASE_NUMBER)
396 , USB_STRING_MAN
397 , USB_STRING_PRODUCT
398 , USB_STRING_SERIAL
399 , NB_CONFIGURATION
400 };
401 */
402 
403 // usb_user_configuration_descriptor FS
404 FLASH S_usb_user_configuration_descriptor_network usb_conf_desc_network = {
405  USB_CONFIG_DESC(
406  sizeof(usb_conf_desc_network),
407  NETWORK_NB_INTERFACE,
408  CONF_NB, // value
409  USB_STRING_CONFIG_RNDIS,
410  CONF_ATTRIBUTES,
411  MAX_POWER
412  ),
413  RNDIS_INTERFACES
414 };
415 
416 
417 
418 /************* EEM-ONLY ***************/
419 
420 // usb_user_device_descriptor
421 /*
422 FLASH S_usb_device_descriptor usb_dev_desc_eem =
423 {
424  sizeof(usb_dev_desc_composite)
425 , DEVICE_DESCRIPTOR
426 , Usb_write_word_enum_struc(USB_SPECIFICATION)
427 , EEM_DEVICE_CLASS
428 , EEM_DEVICE_SUB_CLASS
429 , EEM_DEVICE_PROTOCOL
430 , EP_CONTROL_LENGTH
431 , Usb_write_word_enum_struc(VENDOR_ID)
432 , Usb_write_word_enum_struc(COMPOSITE_PRODUCT_ID)
433 , Usb_write_word_enum_struc(RELEASE_NUMBER)
434 , USB_STRING_MAN
435 , USB_STRING_PRODUCT
436 , USB_STRING_SERIAL
437 , NB_CONFIGURATION
438 };
439 */
440 
441 
442 // usb_user_configuration_descriptor FS
443 FLASH S_usb_user_configuration_descriptor_eem usb_conf_desc_eem = {
444  USB_CONFIG_DESC(
445  sizeof(usb_conf_desc_eem),
446  EEM_NB_INTERFACE,
447  USB_CONFIG_EEM, // value
448  USB_STRING_CONFIG_EEM,
449  CONF_ATTRIBUTES,
450  MAX_POWER
451  ),
452  CDC_EEM_INTERFACES
453 };
454 
455 
456 FLASH S_usb_user_configuration_descriptor_ecm usb_conf_desc_ecm = {
457  USB_CONFIG_DESC(
458  sizeof(usb_conf_desc_ecm),
459  2, // Interface Count
460  USB_CONFIG_ECM, // value
461  USB_STRING_CONFIG_ECM,
462  CONF_ATTRIBUTES,
463  MAX_POWER
464  ),
465  CDC_ECM_INTERFACES
466 };
467 
468 FLASH S_usb_user_configuration_descriptor_ecm_debug usb_conf_desc_ecm_debug = {
469  USB_CONFIG_DESC(
470  sizeof(usb_conf_desc_ecm_debug),
471  4, // Interface Count
472  USB_CONFIG_ECM_DEBUG, // value
473  USB_STRING_CONFIG_ECM_DEBUG,
474  CONF_ATTRIBUTES,
475  MAX_POWER
476  ),
477 
478  USB_IAD(
479  0x00, // First interface
480  0x02, // Interface count
481  0x02, // Function Class
482  0x06, // Function Subclass
483  0x00, // Function Protocol
484  USB_STRING_INTERFACE_ECM
485  ),CDC_ECM_INTERFACES,
486 
487  USB_IAD(
488  0x02, // First interface
489  0x02, // Interface count
490  0x02, // Function Class
491  0x02, // Function Subclass
492  0x01, // Function Protocol
493  USB_STRING_INTERFACE_SERIAL
494  ),CDC_SERIAL_INTERFACES
495 
496 
497 
498 };
499 
500 
501 
502 /****************** MASS-STORAGE DEVICE DESCRIPTORS **************************/
503 
504 /*
505 FLASH S_usb_device_descriptor usb_dev_desc_mass =
506 {
507  sizeof(usb_dev_desc_mass)
508 , DEVICE_DESCRIPTOR
509 , Usb_write_word_enum_struc(USB_SPECIFICATION)
510 , MASS_DEVICE_CLASS
511 , MASS_DEVICE_SUB_CLASS
512 , MASS_DEVICE_PROTOCOL
513 , EP_CONTROL_LENGTH
514 , Usb_write_word_enum_struc(VENDOR_ID)
515 , Usb_write_word_enum_struc(MASS_PRODUCT_ID)
516 , Usb_write_word_enum_struc(RELEASE_NUMBER)
517 , USB_STRING_MAN
518 , USB_STRING_PRODUCT
519 , USB_STRING_SERIAL
520 , NB_CONFIGURATION
521 };
522 */
523 #if USB_CONF_STORAGE
524 
525 // usb_user_configuration_descriptor FS
526 FLASH S_usb_user_configuration_descriptor_mass usb_conf_desc_mass = {
528  , CONFIGURATION_DESCRIPTOR
529  , Usb_write_word_enum_struc(sizeof(S_usb_user_configuration_descriptor_mass))
530  , MASS_NB_INTERFACE
531  , CONF_NB
532  , USB_STRING_CONFIG_MS
533  , CONF_ATTRIBUTES
534  , MAX_POWER
535  },//9
536 
537  /// Mass storage
539  , INTERFACE_DESCRIPTOR
540  , MS_INTERFACE_NB
541  , MS_ALTERNATE
542  , MS_NB_ENDPOINT
543  , MS_INTERFACE_CLASS
544  , MS_INTERFACE_SUB_CLASS
545  , MS_INTERFACE_PROTOCOL
546  , USB_STRING_INTERFACE_MS
547  } //9
548 ,
550  , ENDPOINT_DESCRIPTOR
551  , MS_ENDPOINT_NB_1
552  , MS_EP_ATTRIBUTES_1
553  , Usb_write_word_enum_struc(MS_EP_SIZE_1)
554  , MS_EP_INTERVAL_1
555  } //7
556  ,
557  { sizeof(S_usb_endpoint_descriptor)
558  , ENDPOINT_DESCRIPTOR
559  , MS_ENDPOINT_NB_2
560  , MS_EP_ATTRIBUTES_2
561  , Usb_write_word_enum_struc(MS_EP_SIZE_2)
562  , MS_EP_INTERVAL_2
563  }
564 };
565 
566 #endif
567 
568 /************* COMMON *****************/
569 
570 
571 
572  // usb_user_language_id
573 
574 FLASH S_usb_language_id usb_user_language_id = {
575  sizeof(usb_user_language_id)
576 , STRING_DESCRIPTOR
577 , Usb_write_word_enum_struc(LANGUAGE_ID)
578 };
579 
580 
581 
582 
583 
584 PGM_VOID_P Usb_get_dev_desc_pointer(void)
585 {
586 #if 1
587  return &(usb_dev_desc_composite.bLength);
588 #else //these are all the same length
589  if (usb_mode == rndis_only)
590  return &(usb_dev_desc_network.bLength);
591 
592  if (usb_mode == rndis_debug)
593  return &(usb_dev_desc_composite.bLength);
594 
595  if (usb_mode == eem)
596  return &(usb_dev_desc_eem.bLength);
597 
598  return &(usb_dev_desc_mass.bLength);
599 #endif
600 }
601 
602 
603 U8 Usb_get_dev_desc_length(void)
604 {
605 #if 1
606  return sizeof(usb_dev_desc_composite);
607 #else //these are all the same size
608  if (usb_mode == rndis_only)
609  return sizeof(usb_dev_desc_network);
610 
611  if (usb_mode == rndis_debug)
612  return sizeof(usb_dev_desc_composite);
613 
614  if (usb_mode == eem)
615  return sizeof(usb_dev_desc_eem);
616 
617  return sizeof(usb_dev_desc_mass);
618 #endif
619 }
620 
621 
622 PGM_VOID_P Usb_get_conf_desc_pointer(U8 index)
623 {
624 
625  switch(pgm_read_byte_near(&usb_dev_config_order[index])) {
626  case USB_CONFIG_ECM:
627  return &(usb_conf_desc_ecm.cfg.bLength);
628  case USB_CONFIG_ECM_DEBUG:
629  return &(usb_conf_desc_ecm_debug.cfg.bLength);
630  case USB_CONFIG_RNDIS_DEBUG:
631  return &(usb_conf_desc_composite.cfg.bLength);
632  case USB_CONFIG_RNDIS:
633  return &(usb_conf_desc_network.cfg.bLength);
634  case USB_CONFIG_EEM:
635  return &(usb_conf_desc_eem.cfg.bLength);
636 #if USB_CONF_STORAGE
637  case USB_CONFIG_MS:
638  return &(usb_conf_desc_mass.cfg.bLength);
639 #endif
640  default:
641  return 0;
642  }
643 }
644 
645 
646 U8 Usb_get_conf_desc_length(U8 index)
647 {
648  switch(pgm_read_byte_near(&usb_dev_config_order[index])) {
649  case USB_CONFIG_ECM:
650  return sizeof(usb_conf_desc_ecm);
651  case USB_CONFIG_ECM_DEBUG:
652  return sizeof(usb_conf_desc_ecm_debug);
653  case USB_CONFIG_RNDIS_DEBUG:
654  return sizeof(usb_conf_desc_composite);
655  case USB_CONFIG_RNDIS:
656  return sizeof (usb_conf_desc_network);
657  case USB_CONFIG_EEM:
658  return sizeof(usb_conf_desc_eem);
659 #if USB_CONF_STORAGE
660  case USB_CONFIG_MS:
661  return sizeof(usb_conf_desc_mass);
662 #endif
663  default:
664  return 0;
665  }
666 }
667 
668 /** @} */