usbdescriptors.h 13 KB

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