usbdescriptors.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  1. /*
  2. * (C) Copyright 2003
  3. * Gerry Hamel, geh@ti.com, Texas Instruments
  4. *
  5. * Based on
  6. * linux/drivers/usbd/usb-function.h - USB Function
  7. *
  8. * Copyright (c) 2000, 2001, 2002 Lineo
  9. * Copyright (c) 2001 Hewlett Packard
  10. *
  11. * By:
  12. * Stuart Lynne <sl@lineo.com>,
  13. * Tom Rushworth <tbr@lineo.com>,
  14. * Bruce Balden <balden@lineo.com>
  15. *
  16. * SPDX-License-Identifier: GPL-2.0+
  17. */
  18. /* USB Descriptors - Create a complete description of all of the
  19. * function driver capabilities. These map directly to the USB descriptors.
  20. *
  21. * This heirarchy is created by the functions drivers and is passed to the
  22. * usb-device driver when the function driver is registered.
  23. *
  24. * device
  25. * configuration
  26. * interface
  27. * alternate
  28. * class
  29. * class
  30. * alternate
  31. * endpoint
  32. * endpoint
  33. * interface
  34. * alternate
  35. * endpoint
  36. * endpoint
  37. * configuration
  38. * interface
  39. * alternate
  40. * endpoint
  41. * endpoint
  42. *
  43. *
  44. * The configuration structures refer to the USB Configurations that will be
  45. * made available to a USB HOST during the enumeration process.
  46. *
  47. * The USB HOST will select a configuration and optionally an interface with
  48. * the usb set configuration and set interface commands.
  49. *
  50. * The selected interface (or the default interface if not specifically
  51. * selected) will define the list of endpoints that will be used.
  52. *
  53. * The configuration and interfaces are stored in an array that is indexed
  54. * by the specified configuratin or interface number minus one.
  55. *
  56. * A configuration number of zero is used to specify a return to the unconfigured
  57. * state.
  58. *
  59. */
  60. #ifndef __USBDESCRIPTORS_H__
  61. #define __USBDESCRIPTORS_H__
  62. #include <asm/types.h>
  63. /*
  64. * communications class types
  65. *
  66. * c.f. CDC USB Class Definitions for Communications Devices
  67. * c.f. WMCD USB CDC Subclass Specification for Wireless Mobile Communications Devices
  68. *
  69. */
  70. #define CLASS_BCD_VERSION 0x0110
  71. /* c.f. CDC 4.1 Table 14 */
  72. #define COMMUNICATIONS_DEVICE_CLASS 0x02
  73. /* c.f. CDC 4.2 Table 15 */
  74. #define COMMUNICATIONS_INTERFACE_CLASS_CONTROL 0x02
  75. #define COMMUNICATIONS_INTERFACE_CLASS_DATA 0x0A
  76. #define COMMUNICATIONS_INTERFACE_CLASS_VENDOR 0x0FF
  77. /* c.f. CDC 4.3 Table 16 */
  78. #define COMMUNICATIONS_NO_SUBCLASS 0x00
  79. #define COMMUNICATIONS_DLCM_SUBCLASS 0x01
  80. #define COMMUNICATIONS_ACM_SUBCLASS 0x02
  81. #define COMMUNICATIONS_TCM_SUBCLASS 0x03
  82. #define COMMUNICATIONS_MCCM_SUBCLASS 0x04
  83. #define COMMUNICATIONS_CCM_SUBCLASS 0x05
  84. #define COMMUNICATIONS_ENCM_SUBCLASS 0x06
  85. #define COMMUNICATIONS_ANCM_SUBCLASS 0x07
  86. /* c.f. WMCD 5.1 */
  87. #define COMMUNICATIONS_WHCM_SUBCLASS 0x08
  88. #define COMMUNICATIONS_DMM_SUBCLASS 0x09
  89. #define COMMUNICATIONS_MDLM_SUBCLASS 0x0a
  90. #define COMMUNICATIONS_OBEX_SUBCLASS 0x0b
  91. /* c.f. CDC 4.4 Table 17 */
  92. #define COMMUNICATIONS_NO_PROTOCOL 0x00
  93. #define COMMUNICATIONS_V25TER_PROTOCOL 0x01 /*Common AT Hayes compatible*/
  94. /* c.f. CDC 4.5 Table 18 */
  95. #define DATA_INTERFACE_CLASS 0x0a
  96. /* c.f. CDC 4.6 No Table */
  97. #define DATA_INTERFACE_SUBCLASS_NONE 0x00 /* No subclass pertinent */
  98. /* c.f. CDC 4.7 Table 19 */
  99. #define DATA_INTERFACE_PROTOCOL_NONE 0x00 /* No class protcol required */
  100. /* c.f. CDC 5.2.3 Table 24 */
  101. #define CS_INTERFACE 0x24
  102. #define CS_ENDPOINT 0x25
  103. /*
  104. * bDescriptorSubtypes
  105. *
  106. * c.f. CDC 5.2.3 Table 25
  107. * c.f. WMCD 5.3 Table 5.3
  108. */
  109. #define USB_ST_HEADER 0x00
  110. #define USB_ST_CMF 0x01
  111. #define USB_ST_ACMF 0x02
  112. #define USB_ST_DLMF 0x03
  113. #define USB_ST_TRF 0x04
  114. #define USB_ST_TCLF 0x05
  115. #define USB_ST_UF 0x06
  116. #define USB_ST_CSF 0x07
  117. #define USB_ST_TOMF 0x08
  118. #define USB_ST_USBTF 0x09
  119. #define USB_ST_NCT 0x0a
  120. #define USB_ST_PUF 0x0b
  121. #define USB_ST_EUF 0x0c
  122. #define USB_ST_MCMF 0x0d
  123. #define USB_ST_CCMF 0x0e
  124. #define USB_ST_ENF 0x0f
  125. #define USB_ST_ATMNF 0x10
  126. #define USB_ST_WHCM 0x11
  127. #define USB_ST_MDLM 0x12
  128. #define USB_ST_MDLMD 0x13
  129. #define USB_ST_DMM 0x14
  130. #define USB_ST_OBEX 0x15
  131. #define USB_ST_CS 0x16
  132. #define USB_ST_CSD 0x17
  133. #define USB_ST_TCM 0x18
  134. /* endpoint modifiers
  135. * static struct usb_endpoint_description function_default_A_1[] = {
  136. *
  137. * {this_endpoint: 0, attributes: CONTROL, max_size: 8, polling_interval: 0 },
  138. * {this_endpoint: 1, attributes: BULK, max_size: 64, polling_interval: 0, direction: IN},
  139. * {this_endpoint: 2, attributes: BULK, max_size: 64, polling_interval: 0, direction: OUT},
  140. * {this_endpoint: 3, attributes: INTERRUPT, max_size: 8, polling_interval: 0},
  141. *
  142. *
  143. */
  144. #define OUT 0x00
  145. #define IN 0x80
  146. #define CONTROL 0x00
  147. #define ISOCHRONOUS 0x01
  148. #define BULK 0x02
  149. #define INTERRUPT 0x03
  150. /* configuration modifiers
  151. */
  152. #define BMATTRIBUTE_RESERVED 0x80
  153. #define BMATTRIBUTE_SELF_POWERED 0x40
  154. /*
  155. * standard usb descriptor structures
  156. */
  157. struct usb_endpoint_descriptor {
  158. u8 bLength;
  159. u8 bDescriptorType; /* 0x5 */
  160. u8 bEndpointAddress;
  161. u8 bmAttributes;
  162. u16 wMaxPacketSize;
  163. u8 bInterval;
  164. } __attribute__ ((packed));
  165. struct usb_interface_descriptor {
  166. u8 bLength;
  167. u8 bDescriptorType; /* 0x04 */
  168. u8 bInterfaceNumber;
  169. u8 bAlternateSetting;
  170. u8 bNumEndpoints;
  171. u8 bInterfaceClass;
  172. u8 bInterfaceSubClass;
  173. u8 bInterfaceProtocol;
  174. u8 iInterface;
  175. } __attribute__ ((packed));
  176. struct usb_configuration_descriptor {
  177. u8 bLength;
  178. u8 bDescriptorType; /* 0x2 */
  179. u16 wTotalLength;
  180. u8 bNumInterfaces;
  181. u8 bConfigurationValue;
  182. u8 iConfiguration;
  183. u8 bmAttributes;
  184. u8 bMaxPower;
  185. } __attribute__ ((packed));
  186. struct usb_device_descriptor {
  187. u8 bLength;
  188. u8 bDescriptorType; /* 0x01 */
  189. u16 bcdUSB;
  190. u8 bDeviceClass;
  191. u8 bDeviceSubClass;
  192. u8 bDeviceProtocol;
  193. u8 bMaxPacketSize0;
  194. u16 idVendor;
  195. u16 idProduct;
  196. u16 bcdDevice;
  197. u8 iManufacturer;
  198. u8 iProduct;
  199. u8 iSerialNumber;
  200. u8 bNumConfigurations;
  201. } __attribute__ ((packed));
  202. #if defined(CONFIG_USBD_HS)
  203. struct usb_qualifier_descriptor {
  204. u8 bLength;
  205. u8 bDescriptorType;
  206. u16 bcdUSB;
  207. u8 bDeviceClass;
  208. u8 bDeviceSubClass;
  209. u8 bDeviceProtocol;
  210. u8 bMaxPacketSize0;
  211. u8 bNumConfigurations;
  212. u8 breserved;
  213. } __attribute__ ((packed));
  214. #endif
  215. struct usb_string_descriptor {
  216. u8 bLength;
  217. u8 bDescriptorType; /* 0x03 */
  218. u16 wData[0];
  219. } __attribute__ ((packed));
  220. struct usb_generic_descriptor {
  221. u8 bLength;
  222. u8 bDescriptorType;
  223. u8 bDescriptorSubtype;
  224. } __attribute__ ((packed));
  225. /*
  226. * communications class descriptor structures
  227. *
  228. * c.f. CDC 5.2 Table 25c
  229. */
  230. struct usb_class_function_descriptor {
  231. u8 bFunctionLength;
  232. u8 bDescriptorType;
  233. u8 bDescriptorSubtype;
  234. } __attribute__ ((packed));
  235. struct usb_class_function_descriptor_generic {
  236. u8 bFunctionLength;
  237. u8 bDescriptorType;
  238. u8 bDescriptorSubtype;
  239. u8 bmCapabilities;
  240. } __attribute__ ((packed));
  241. struct usb_class_header_function_descriptor {
  242. u8 bFunctionLength;
  243. u8 bDescriptorType;
  244. u8 bDescriptorSubtype; /* 0x00 */
  245. u16 bcdCDC;
  246. } __attribute__ ((packed));
  247. struct usb_class_call_management_descriptor {
  248. u8 bFunctionLength;
  249. u8 bDescriptorType;
  250. u8 bDescriptorSubtype; /* 0x01 */
  251. u8 bmCapabilities;
  252. u8 bDataInterface;
  253. } __attribute__ ((packed));
  254. struct usb_class_abstract_control_descriptor {
  255. u8 bFunctionLength;
  256. u8 bDescriptorType;
  257. u8 bDescriptorSubtype; /* 0x02 */
  258. u8 bmCapabilities;
  259. } __attribute__ ((packed));
  260. struct usb_class_direct_line_descriptor {
  261. u8 bFunctionLength;
  262. u8 bDescriptorType;
  263. u8 bDescriptorSubtype; /* 0x03 */
  264. } __attribute__ ((packed));
  265. struct usb_class_telephone_ringer_descriptor {
  266. u8 bFunctionLength;
  267. u8 bDescriptorType;
  268. u8 bDescriptorSubtype; /* 0x04 */
  269. u8 bRingerVolSeps;
  270. u8 bNumRingerPatterns;
  271. } __attribute__ ((packed));
  272. struct usb_class_telephone_call_descriptor {
  273. u8 bFunctionLength;
  274. u8 bDescriptorType;
  275. u8 bDescriptorSubtype; /* 0x05 */
  276. u8 bmCapabilities;
  277. } __attribute__ ((packed));
  278. struct usb_class_union_function_descriptor {
  279. u8 bFunctionLength;
  280. u8 bDescriptorType;
  281. u8 bDescriptorSubtype; /* 0x06 */
  282. u8 bMasterInterface;
  283. /* u8 bSlaveInterface0[0]; */
  284. u8 bSlaveInterface0;
  285. } __attribute__ ((packed));
  286. struct usb_class_country_selection_descriptor {
  287. u8 bFunctionLength;
  288. u8 bDescriptorType;
  289. u8 bDescriptorSubtype; /* 0x07 */
  290. u8 iCountryCodeRelDate;
  291. u16 wCountryCode0[0];
  292. } __attribute__ ((packed));
  293. struct usb_class_telephone_operational_descriptor {
  294. u8 bFunctionLength;
  295. u8 bDescriptorType;
  296. u8 bDescriptorSubtype; /* 0x08 */
  297. u8 bmCapabilities;
  298. } __attribute__ ((packed));
  299. struct usb_class_usb_terminal_descriptor {
  300. u8 bFunctionLength;
  301. u8 bDescriptorType;
  302. u8 bDescriptorSubtype; /* 0x09 */
  303. u8 bEntityId;
  304. u8 bInterfaceNo;
  305. u8 bOutInterfaceNo;
  306. u8 bmOptions;
  307. u8 bChild0[0];
  308. } __attribute__ ((packed));
  309. struct usb_class_network_channel_descriptor {
  310. u8 bFunctionLength;
  311. u8 bDescriptorType;
  312. u8 bDescriptorSubtype; /* 0x0a */
  313. u8 bEntityId;
  314. u8 iName;
  315. u8 bChannelIndex;
  316. u8 bPhysicalInterface;
  317. } __attribute__ ((packed));
  318. struct usb_class_protocol_unit_function_descriptor {
  319. u8 bFunctionLength;
  320. u8 bDescriptorType;
  321. u8 bDescriptorSubtype; /* 0x0b */
  322. u8 bEntityId;
  323. u8 bProtocol;
  324. u8 bChild0[0];
  325. } __attribute__ ((packed));
  326. struct usb_class_extension_unit_descriptor {
  327. u8 bFunctionLength;
  328. u8 bDescriptorType;
  329. u8 bDescriptorSubtype; /* 0x0c */
  330. u8 bEntityId;
  331. u8 bExtensionCode;
  332. u8 iName;
  333. u8 bChild0[0];
  334. } __attribute__ ((packed));
  335. struct usb_class_multi_channel_descriptor {
  336. u8 bFunctionLength;
  337. u8 bDescriptorType;
  338. u8 bDescriptorSubtype; /* 0x0d */
  339. u8 bmCapabilities;
  340. } __attribute__ ((packed));
  341. struct usb_class_capi_control_descriptor {
  342. u8 bFunctionLength;
  343. u8 bDescriptorType;
  344. u8 bDescriptorSubtype; /* 0x0e */
  345. u8 bmCapabilities;
  346. } __attribute__ ((packed));
  347. struct usb_class_ethernet_networking_descriptor {
  348. u8 bFunctionLength;
  349. u8 bDescriptorType;
  350. u8 bDescriptorSubtype; /* 0x0f */
  351. u8 iMACAddress;
  352. u32 bmEthernetStatistics;
  353. u16 wMaxSegmentSize;
  354. u16 wNumberMCFilters;
  355. u8 bNumberPowerFilters;
  356. } __attribute__ ((packed));
  357. struct usb_class_atm_networking_descriptor {
  358. u8 bFunctionLength;
  359. u8 bDescriptorType;
  360. u8 bDescriptorSubtype; /* 0x10 */
  361. u8 iEndSystermIdentifier;
  362. u8 bmDataCapabilities;
  363. u8 bmATMDeviceStatistics;
  364. u16 wType2MaxSegmentSize;
  365. u16 wType3MaxSegmentSize;
  366. u16 wMaxVC;
  367. } __attribute__ ((packed));
  368. struct usb_class_mdlm_descriptor {
  369. u8 bFunctionLength;
  370. u8 bDescriptorType;
  371. u8 bDescriptorSubtype; /* 0x12 */
  372. u16 bcdVersion;
  373. u8 bGUID[16];
  374. } __attribute__ ((packed));
  375. struct usb_class_mdlmd_descriptor {
  376. u8 bFunctionLength;
  377. u8 bDescriptorType;
  378. u8 bDescriptorSubtype; /* 0x13 */
  379. u8 bGuidDescriptorType;
  380. u8 bDetailData[0];
  381. } __attribute__ ((packed));
  382. /*
  383. * HID class descriptor structures
  384. *
  385. * c.f. HID 6.2.1
  386. */
  387. struct usb_class_hid_descriptor {
  388. u8 bLength;
  389. u8 bDescriptorType;
  390. u16 bcdCDC;
  391. u8 bCountryCode;
  392. u8 bNumDescriptors; /* 0x01 */
  393. u8 bDescriptorType0;
  394. u16 wDescriptorLength0;
  395. /* optional descriptors are not supported. */
  396. } __attribute__((packed));
  397. struct usb_class_report_descriptor {
  398. u8 bLength; /* dummy */
  399. u8 bDescriptorType;
  400. u16 wLength;
  401. u8 bData[0];
  402. } __attribute__((packed));
  403. /*
  404. * descriptor union structures
  405. */
  406. struct usb_descriptor {
  407. union {
  408. struct usb_generic_descriptor generic;
  409. struct usb_endpoint_descriptor endpoint;
  410. struct usb_interface_descriptor interface;
  411. struct usb_configuration_descriptor configuration;
  412. struct usb_device_descriptor device;
  413. struct usb_string_descriptor string;
  414. } descriptor;
  415. } __attribute__ ((packed));
  416. struct usb_class_descriptor {
  417. union {
  418. struct usb_class_function_descriptor function;
  419. struct usb_class_function_descriptor_generic generic;
  420. struct usb_class_header_function_descriptor header_function;
  421. struct usb_class_call_management_descriptor call_management;
  422. struct usb_class_abstract_control_descriptor abstract_control;
  423. struct usb_class_direct_line_descriptor direct_line;
  424. struct usb_class_telephone_ringer_descriptor telephone_ringer;
  425. struct usb_class_telephone_operational_descriptor telephone_operational;
  426. struct usb_class_telephone_call_descriptor telephone_call;
  427. struct usb_class_union_function_descriptor union_function;
  428. struct usb_class_country_selection_descriptor country_selection;
  429. struct usb_class_usb_terminal_descriptor usb_terminal;
  430. struct usb_class_network_channel_descriptor network_channel;
  431. struct usb_class_extension_unit_descriptor extension_unit;
  432. struct usb_class_multi_channel_descriptor multi_channel;
  433. struct usb_class_capi_control_descriptor capi_control;
  434. struct usb_class_ethernet_networking_descriptor ethernet_networking;
  435. struct usb_class_atm_networking_descriptor atm_networking;
  436. struct usb_class_mdlm_descriptor mobile_direct;
  437. struct usb_class_mdlmd_descriptor mobile_direct_detail;
  438. struct usb_class_hid_descriptor hid;
  439. } descriptor;
  440. } __attribute__ ((packed));
  441. #ifdef DEBUG
  442. static inline void print_device_descriptor(struct usb_device_descriptor *d)
  443. {
  444. serial_printf("usb device descriptor \n");
  445. serial_printf("\tbLength %2.2x\n", d->bLength);
  446. serial_printf("\tbDescriptorType %2.2x\n", d->bDescriptorType);
  447. serial_printf("\tbcdUSB %4.4x\n", d->bcdUSB);
  448. serial_printf("\tbDeviceClass %2.2x\n", d->bDeviceClass);
  449. serial_printf("\tbDeviceSubClass %2.2x\n", d->bDeviceSubClass);
  450. serial_printf("\tbDeviceProtocol %2.2x\n", d->bDeviceProtocol);
  451. serial_printf("\tbMaxPacketSize0 %2.2x\n", d->bMaxPacketSize0);
  452. serial_printf("\tidVendor %4.4x\n", d->idVendor);
  453. serial_printf("\tidProduct %4.4x\n", d->idProduct);
  454. serial_printf("\tbcdDevice %4.4x\n", d->bcdDevice);
  455. serial_printf("\tiManufacturer %2.2x\n", d->iManufacturer);
  456. serial_printf("\tiProduct %2.2x\n", d->iProduct);
  457. serial_printf("\tiSerialNumber %2.2x\n", d->iSerialNumber);
  458. serial_printf("\tbNumConfigurations %2.2x\n", d->bNumConfigurations);
  459. }
  460. #else
  461. /* stubs */
  462. #define print_device_descriptor(d)
  463. #endif /* DEBUG */
  464. #endif