usb_ch9.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830
  1. /* $FreeBSD$ */
  2. /*-
  3. * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
  4. * Copyright (c) 1998 The NetBSD Foundation, Inc. All rights reserved.
  5. * Copyright (c) 1998 Lennart Augustsson. All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  17. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  18. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  19. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  20. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  21. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  22. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  23. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  24. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  25. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  26. * SUCH DAMAGE.
  27. */
  28. /*
  29. * This file contains standard definitions for the following USB
  30. * protocol versions:
  31. *
  32. * USB v1.0
  33. * USB v1.1
  34. * USB v2.0
  35. * USB v3.0
  36. */
  37. #ifndef _USB_STANDARD_H_
  38. #define _USB_STANDARD_H_
  39. #include <stdint.h>
  40. typedef uint8_t uByte;
  41. typedef uint16_t uWord;
  42. typedef uint32_t uDWord;
  43. #define USB_STACK_VERSION 2000 /* 2.0 */
  44. /* Definition of some hardcoded USB constants. */
  45. #define USB_MAX_IPACKET 8 /* initial USB packet size */
  46. #define USB_EP_MAX (2*16) /* hardcoded */
  47. #define USB_ROOT_HUB_ADDR 1 /* index */
  48. #define USB_MIN_DEVICES 2 /* unused + root HUB */
  49. #define USB_UNCONFIG_INDEX 0xFF /* internal use only */
  50. #define USB_IFACE_INDEX_ANY 0xFF /* internal use only */
  51. #define USB_START_ADDR 0 /* default USB device BUS address
  52. * after USB bus reset */
  53. #define USB_CONTROL_ENDPOINT 0 /* default control endpoint */
  54. #define USB_FRAMES_PER_SECOND_FS 1000 /* full speed */
  55. #define USB_FRAMES_PER_SECOND_HS 8000 /* high speed */
  56. #define USB_FS_BYTES_PER_HS_UFRAME 188 /* bytes */
  57. #define USB_HS_MICRO_FRAMES_MAX 8 /* units */
  58. #define USB_ISOC_TIME_MAX 128 /* ms */
  59. /*
  60. * Minimum time a device needs to be powered down to go through a
  61. * power cycle. These values are not in the USB specification.
  62. */
  63. #define USB_POWER_DOWN_TIME 200 /* ms */
  64. #define USB_PORT_POWER_DOWN_TIME 100 /* ms */
  65. /* Definition of software USB power modes */
  66. #define USB_POWER_MODE_OFF 0 /* turn off device */
  67. #define USB_POWER_MODE_ON 1 /* always on */
  68. #define USB_POWER_MODE_SAVE 2 /* automatic suspend and resume */
  69. #define USB_POWER_MODE_SUSPEND 3 /* force suspend */
  70. #define USB_POWER_MODE_RESUME 4 /* force resume */
  71. /* These are the values from the USB specification. */
  72. #define USB_PORT_RESET_DELAY_SPEC 10 /* ms */
  73. #define USB_PORT_ROOT_RESET_DELAY_SPEC 50 /* ms */
  74. #define USB_PORT_RESET_RECOVERY_SPEC 10 /* ms */
  75. #define USB_PORT_POWERUP_DELAY_SPEC 100 /* ms */
  76. #define USB_PORT_RESUME_DELAY_SPEC 20 /* ms */
  77. #define USB_SET_ADDRESS_SETTLE_SPEC 2 /* ms */
  78. #define USB_RESUME_DELAY_SPEC (20*5) /* ms */
  79. #define USB_RESUME_WAIT_SPEC 10 /* ms */
  80. #define USB_RESUME_RECOVERY_SPEC 10 /* ms */
  81. #define USB_EXTRA_POWER_UP_TIME_SPEC 0 /* ms */
  82. /* Allow for marginal and non-conforming devices. */
  83. #define USB_PORT_RESET_DELAY 50 /* ms */
  84. #define USB_PORT_ROOT_RESET_DELAY 200 /* ms */
  85. #define USB_PORT_RESET_RECOVERY 250 /* ms */
  86. #define USB_PORT_POWERUP_DELAY 300 /* ms */
  87. #define USB_PORT_RESUME_DELAY (20*2) /* ms */
  88. #define USB_SET_ADDRESS_SETTLE 10 /* ms */
  89. #define USB_RESUME_DELAY (50*5) /* ms */
  90. #define USB_RESUME_WAIT 50 /* ms */
  91. #define USB_RESUME_RECOVERY 50 /* ms */
  92. #define USB_EXTRA_POWER_UP_TIME 20 /* ms */
  93. #define USB_MIN_POWER 100 /* mA */
  94. #define USB_MAX_POWER 500 /* mA */
  95. #define USB_BUS_RESET_DELAY 100 /* ms */
  96. /*
  97. * USB record layout in memory:
  98. *
  99. * - USB config 0
  100. * - USB interfaces
  101. * - USB alternative interfaces
  102. * - USB endpoints
  103. *
  104. * - USB config 1
  105. * - USB interfaces
  106. * - USB alternative interfaces
  107. * - USB endpoints
  108. */
  109. /* Declaration of USB records */
  110. struct usb_device_request {
  111. uByte bmRequestType;
  112. uByte bRequest;
  113. uWord wValue;
  114. uWord wIndex;
  115. uWord wLength;
  116. } __attribute__((packed));
  117. typedef struct usb_device_request usb_device_request_t;
  118. /* bmRequestType */
  119. #define UT_GET_DIR(a) ((a) & 0x80)
  120. #define UT_DIR_OUT 0x00 /* host => device */
  121. #define UT_DIR_IN 0x80 /* device => host */
  122. #define UT_WRITE UT_DIR_OUT /* host write */
  123. #define UT_READ UT_DIR_IN /* host read */
  124. #define UT_MASK (0x3 << 5)
  125. #define UT_STANDARD 0x00
  126. #define UT_CLASS 0x20
  127. #define UT_VENDOR 0x40
  128. #define UT_RESERVED 0x60
  129. #define UT_RECIP_MASK 0x1f
  130. #define UT_RECIP_DEVICE 0x00
  131. #define UT_RECIP_INTERFACE 0x01
  132. #define UT_RECIP_ENDPOINT 0x02
  133. #define UT_RECIP_OTHER 0x03
  134. #define UT_RECIP_PORT 0x04
  135. #define UT_RECIP_RPIPE 0x05
  136. #define UT_READ_DEVICE (UT_READ | UT_STANDARD | UT_RECIP_DEVICE)
  137. #define UT_READ_INTERFACE (UT_READ | UT_STANDARD | UT_INTERFACE)
  138. #define UT_READ_ENDPOINT (UT_READ | UT_STANDARD | UT_ENDPOINT)
  139. #define UT_WRITE_DEVICE (UT_WRITE | UT_STANDARD | UT_RECIP_DEVICE)
  140. #define UT_WRITE_INTERFACE (UT_WRITE | UT_STANDARD | UT_INTERFACE)
  141. #define UT_WRITE_ENDPOINT (UT_WRITE | UT_STANDARD | UT_ENDPOINT)
  142. #define UT_READ_CLASS_DEVICE (UT_READ | UT_CLASS | UT_RECIP_DEVICE)
  143. #define UT_READ_CLASS_INTERFACE (UT_READ | UT_CLASS | UT_INTERFACE)
  144. #define UT_READ_CLASS_OTHER (UT_READ | UT_CLASS | UT_OTHER)
  145. #define UT_READ_CLASS_ENDPOINT (UT_READ | UT_CLASS | UT_ENDPOINT)
  146. #define UT_WRITE_CLASS_DEVICE (UT_WRITE | UT_CLASS | UT_RECIP_DEVICE)
  147. #define UT_WRITE_CLASS_INTERFACE (UT_WRITE | UT_CLASS | UT_INTERFACE)
  148. #define UT_WRITE_CLASS_OTHER (UT_WRITE | UT_CLASS | UT_OTHER)
  149. #define UT_WRITE_CLASS_ENDPOINT (UT_WRITE | UT_CLASS | UT_ENDPOINT)
  150. #define UT_READ_VENDOR_DEVICE (UT_READ | UT_VENDOR | UT_RECIP_DEVICE)
  151. #define UT_READ_VENDOR_INTERFACE (UT_READ | UT_VENDOR | UT_INTERFACE)
  152. #define UT_READ_VENDOR_OTHER (UT_READ | UT_VENDOR | UT_OTHER)
  153. #define UT_READ_VENDOR_ENDPOINT (UT_READ | UT_VENDOR | UT_ENDPOINT)
  154. #define UT_WRITE_VENDOR_DEVICE (UT_WRITE | UT_VENDOR | UT_RECIP_DEVICE)
  155. #define UT_WRITE_VENDOR_INTERFACE (UT_WRITE | UT_VENDOR | UT_INTERFACE)
  156. #define UT_WRITE_VENDOR_OTHER (UT_WRITE | UT_VENDOR | UT_OTHER)
  157. #define UT_WRITE_VENDOR_ENDPOINT (UT_WRITE | UT_VENDOR | UT_ENDPOINT)
  158. /* Requests */
  159. #define UR_GET_STATUS 0x00
  160. #define UR_CLEAR_FEATURE 0x01
  161. #define UR_SET_FEATURE 0x03
  162. #define UR_SET_ADDRESS 0x05
  163. #define UR_GET_DESCRIPTOR 0x06
  164. #define UR_SET_DESCRIPTOR 0x07
  165. #define UR_GET_CONFIG 0x08
  166. #define UR_SET_CONFIG 0x09
  167. #define UR_GET_INTERFACE 0x0a
  168. #define UR_SET_INTERFACE 0x0b
  169. #define UR_SYNCH_FRAME 0x0c
  170. #define UR_SET_SEL 0x30
  171. #define UR_ISOCH_DELAY 0x31
  172. /* Descriptor types ... USB 2.0 spec table 9.5 */
  173. #define UDESC_DEVICE 0x01
  174. #define UDESC_CONFIG 0x02
  175. #define UDESC_STRING 0x03
  176. #define USB_LANGUAGE_TABLE 0x00 /* language ID string index */
  177. #define UDESC_INTERFACE 0x04
  178. #define UDESC_ENDPOINT 0x05
  179. #define UDESC_DEVICE_QUALIFIER 0x06
  180. #define UDESC_OTHER_SPEED_CONFIGURATION 0x07
  181. #define UDESC_INTERFACE_POWER 0x08
  182. #define UDESC_OTG 0x09
  183. #define UDESC_DEBUG 0x0A
  184. #define UDESC_IFACE_ASSOC 0x0B /* interface association */
  185. #define UDESC_BOS 0x0F /* binary object store */
  186. #define UDESC_DEVICE_CAPABILITY 0x10
  187. #define UDESC_CS_DEVICE 0x21 /* class specific */
  188. #define UDESC_CS_CONFIG 0x22 /* UDESC_CONFIG | UT_CLASS */
  189. #define UDESC_CS_STRING 0x23 /* UDESC_STRING | UT_CLASS */
  190. #define UDESC_CS_INTERFACE 0x24 /* UDESC_INTERFACE | UT_CLASS */
  191. #define UDESC_CS_ENDPOINT 0x25 /* UDESC_ENDPOINT | UT_CLASS */
  192. #define UDESC_HUB 0x29
  193. #define UDESC_SS_HUB 0x2A /* super speed */
  194. #define UDESC_ENDPOINT_SS_COMP 0x30 /* super speed */
  195. /* HUB specific request */
  196. #define UR_GET_BUS_STATE 0x02
  197. #define UR_CLEAR_TT_BUFFER 0x08
  198. #define UR_RESET_TT 0x09
  199. #define UR_GET_TT_STATE 0x0a
  200. #define UR_STOP_TT 0x0b
  201. #define UR_SET_AND_TEST 0x0c /* USB 2.0 only */
  202. #define UR_SET_HUB_DEPTH 0x0c /* USB 3.0 only */
  203. #define USB_SS_HUB_DEPTH_MAX 5
  204. #define UR_GET_PORT_ERR_COUNT 0x0d
  205. /* Feature numbers */
  206. #define UF_ENDPOINT_HALT 0
  207. #define UF_DEVICE_REMOTE_WAKEUP 1
  208. #define UF_TEST_MODE 2
  209. #define UF_U1_ENABLE 0x30
  210. #define UF_U2_ENABLE 0x31
  211. #define UF_LTM_ENABLE 0x32
  212. /* HUB specific features */
  213. #define UHF_C_HUB_LOCAL_POWER 0
  214. #define UHF_C_HUB_OVER_CURRENT 1
  215. #define UHF_PORT_CONNECTION 0
  216. #define UHF_PORT_ENABLE 1
  217. #define UHF_PORT_SUSPEND 2
  218. #define UHF_PORT_OVER_CURRENT 3
  219. #define UHF_PORT_RESET 4
  220. #define UHF_PORT_LINK_STATE 5
  221. #define UHF_PORT_POWER 8
  222. #define UHF_PORT_LOW_SPEED 9
  223. #define UHF_PORT_L1 10
  224. #define UHF_C_PORT_CONNECTION 16
  225. #define UHF_C_PORT_ENABLE 17
  226. #define UHF_C_PORT_SUSPEND 18
  227. #define UHF_C_PORT_OVER_CURRENT 19
  228. #define UHF_C_PORT_RESET 20
  229. #define UHF_PORT_TEST 21
  230. #define UHF_PORT_INDICATOR 22
  231. #define UHF_C_PORT_L1 23
  232. /* SuperSpeed HUB specific features */
  233. #define UHF_PORT_U1_TIMEOUT 23
  234. #define UHF_PORT_U2_TIMEOUT 24
  235. #define UHF_C_PORT_LINK_STATE 25
  236. #define UHF_C_PORT_CONFIG_ERROR 26
  237. #define UHF_PORT_REMOTE_WAKE_MASK 27
  238. #define UHF_BH_PORT_RESET 28
  239. #define UHF_C_BH_PORT_RESET 29
  240. #define UHF_FORCE_LINKPM_ACCEPT 30
  241. struct usb_descriptor {
  242. uByte bLength;
  243. uByte bDescriptorType;
  244. // uByte bDescriptorSubtype;
  245. } __attribute__((packed));
  246. typedef struct usb_descriptor usb_descriptor_t;
  247. #define USB_DT_DEVICE_SIZE 18
  248. struct usb_device_descriptor {
  249. uByte bLength;
  250. uByte bDescriptorType;
  251. uWord bcdUSB;
  252. #define UD_USB_2_0 0x0200
  253. #define UD_USB_3_0 0x0300
  254. #define UD_IS_USB2(d) ((d)->bcdUSB[1] == 0x02)
  255. #define UD_IS_USB3(d) ((d)->bcdUSB[1] == 0x03)
  256. uByte bDeviceClass;
  257. uByte bDeviceSubClass;
  258. uByte bDeviceProtocol;
  259. uByte bMaxPacketSize;
  260. /* The fields below are not part of the initial descriptor. */
  261. uWord idVendor;
  262. uWord idProduct;
  263. uWord bcdDevice;
  264. uByte iManufacturer;
  265. uByte iProduct;
  266. uByte iSerialNumber;
  267. uByte bNumConfigurations;
  268. } __attribute__((packed));
  269. typedef struct usb_device_descriptor usb_device_descriptor_t;
  270. /* Binary Device Object Store (BOS) */
  271. struct usb_bos_descriptor {
  272. uByte bLength;
  273. uByte bDescriptorType;
  274. uWord wTotalLength;
  275. uByte bNumDeviceCaps;
  276. } __attribute__((packed));
  277. typedef struct usb_bos_descriptor usb_bos_descriptor_t;
  278. /* Binary Device Object Store Capability */
  279. struct usb_bos_cap_descriptor {
  280. uByte bLength;
  281. uByte bDescriptorType;
  282. uByte bDevCapabilityType;
  283. #define USB_DEVCAP_RESERVED 0x00
  284. #define USB_DEVCAP_WUSB 0x01
  285. #define USB_DEVCAP_USB2EXT 0x02
  286. #define USB_DEVCAP_SUPER_SPEED 0x03
  287. #define USB_DEVCAP_CONTAINER_ID 0x04
  288. /* data ... */
  289. } __attribute__((packed));
  290. typedef struct usb_bos_cap_descriptor usb_bos_cap_descriptor_t;
  291. struct usb_devcap_usb2ext_descriptor {
  292. uByte bLength;
  293. uByte bDescriptorType;
  294. uByte bDevCapabilityType;
  295. uDWord bmAttributes;
  296. #define USB_V2EXT_LPM (1U << 1)
  297. #define USB_V2EXT_BESL_SUPPORTED (1U << 2)
  298. #define USB_V2EXT_BESL_BASELINE_VALID (1U << 3)
  299. #define USB_V2EXT_BESL_DEEP_VALID (1U << 4)
  300. #define USB_V2EXT_BESL_BASELINE_GET(x) (((x) >> 8) & 0xF)
  301. #define USB_V2EXT_BESL_DEEP_GET(x) (((x) >> 12) & 0xF)
  302. } __attribute__((packed));
  303. typedef struct usb_devcap_usb2ext_descriptor usb_devcap_usb2ext_descriptor_t;
  304. struct usb_devcap_ss_descriptor {
  305. uByte bLength;
  306. uByte bDescriptorType;
  307. uByte bDevCapabilityType;
  308. uByte bmAttributes;
  309. uWord wSpeedsSupported;
  310. uByte bFunctionalitySupport;
  311. uByte bU1DevExitLat;
  312. uWord wU2DevExitLat;
  313. } __attribute__((packed));
  314. typedef struct usb_devcap_ss_descriptor usb_devcap_ss_descriptor_t;
  315. struct usb_devcap_container_id_descriptor {
  316. uByte bLength;
  317. uByte bDescriptorType;
  318. uByte bDevCapabilityType;
  319. uByte bReserved;
  320. uByte bContainerID;
  321. } __attribute__((packed));
  322. typedef struct usb_devcap_container_id_descriptor
  323. usb_devcap_container_id_descriptor_t;
  324. /* Device class codes */
  325. #define UDCLASS_IN_INTERFACE 0x00
  326. #define UDCLASS_AUDIO 0x01
  327. #define UDCLASS_COMM 0x02
  328. #define UDCLASS_HID 0x03
  329. #define UDCLASS_MASS_STORAGE 0x08
  330. #define UDCLASS_HUB 0x09
  331. #define UDCLASS_CDC_DATA 0x0a
  332. #define UDCLASS_CCID 0x0b
  333. #define UDCLASS_MTP 0x06
  334. #define UDCLASS_DIAGNOSTIC 0xdc
  335. #define UDCLASS_VIDEO 0xe0
  336. #define UDCLASS_WIRELESS 0xe0
  337. #define UDCLASS_MISC 0xef
  338. #define UDCLASS_APP_SPEC 0xfe
  339. #define UDCLASS_VENDOR 0xff
  340. /* Device subclass */
  341. #define UDSUBCLASS_HUB 0x00
  342. #define UDSUBCLASS_RF 0x01
  343. #define UDSUBCLASS_MTP 0x01
  344. /* Device protocol */
  345. #define UDPROTO_FSHUB 0x00
  346. #define UDPROTO_HSHUBSTT 0x01
  347. #define UDPROTO_HSHUBMTT 0x02
  348. #define UDPROTO_SSHUB 0x03
  349. #define UDPROTO_BLUETOOTH 0x01
  350. #define USB_DT_CONFIG_SIZE 9
  351. struct usb_config_descriptor {
  352. uByte bLength;
  353. uByte bDescriptorType;
  354. uWord wTotalLength;
  355. uByte bNumInterface;
  356. uByte bConfigurationValue;
  357. #define USB_UNCONFIG_NO 0
  358. uByte iConfiguration;
  359. uByte bmAttributes;
  360. #define UC_BUS_POWERED 0x80
  361. #define UC_SELF_POWERED 0x40
  362. #define UC_REMOTE_WAKEUP 0x20
  363. uByte bMaxPower; /* max current in 2 mA units */
  364. #define UC_POWER_FACTOR 2
  365. } __attribute__((packed));
  366. typedef struct usb_config_descriptor usb_config_descriptor_t;
  367. #define USB_DT_INTERFACE_SIZE 9
  368. struct usb_interface_descriptor {
  369. uByte bLength;
  370. uByte bDescriptorType;
  371. uByte bInterfaceNumber;
  372. uByte bAlternateSetting;
  373. uByte bNumEndpoints;
  374. uByte bInterfaceClass;
  375. uByte bInterfaceSubClass;
  376. uByte bInterfaceProtocol;
  377. uByte iInterface;
  378. } __attribute__((packed));
  379. typedef struct usb_interface_descriptor usb_interface_descriptor_t;
  380. struct usb_interface_assoc_descriptor {
  381. uByte bLength;
  382. uByte bDescriptorType;
  383. uByte bFirstInterface;
  384. uByte bInterfaceCount;
  385. uByte bFunctionClass;
  386. uByte bFunctionSubClass;
  387. uByte bFunctionProtocol;
  388. uByte iFunction;
  389. } __attribute__((packed));
  390. typedef struct usb_interface_assoc_descriptor usb_interface_assoc_descriptor_t;
  391. /* Interface class codes */
  392. #define UICLASS_UNSPEC 0x00
  393. #define UICLASS_AUDIO 0x01 /* audio */
  394. #define UISUBCLASS_AUDIOCONTROL 1
  395. #define UISUBCLASS_AUDIOSTREAM 2
  396. #define UISUBCLASS_MIDISTREAM 3
  397. #define UICLASS_CDC 0x02 /* communication */
  398. #define UISUBCLASS_DIRECT_LINE_CONTROL_MODEL 1
  399. #define UISUBCLASS_ABSTRACT_CONTROL_MODEL 2
  400. #define UISUBCLASS_TELEPHONE_CONTROL_MODEL 3
  401. #define UISUBCLASS_MULTICHANNEL_CONTROL_MODEL 4
  402. #define UISUBCLASS_CAPI_CONTROLMODEL 5
  403. #define UISUBCLASS_ETHERNET_NETWORKING_CONTROL_MODEL 6
  404. #define UISUBCLASS_ATM_NETWORKING_CONTROL_MODEL 7
  405. #define UISUBCLASS_WIRELESS_HANDSET_CM 8
  406. #define UISUBCLASS_DEVICE_MGMT 9
  407. #define UISUBCLASS_MOBILE_DIRECT_LINE_MODEL 10
  408. #define UISUBCLASS_OBEX 11
  409. #define UISUBCLASS_ETHERNET_EMULATION_MODEL 12
  410. #define UISUBCLASS_NETWORK_CONTROL_MODEL 13
  411. #define UIPROTO_CDC_NONE 0
  412. #define UIPROTO_CDC_AT 1
  413. #define UICLASS_HID 0x03
  414. #define UISUBCLASS_BOOT 1
  415. #define UIPROTO_BOOT_KEYBOARD 1
  416. #define UIPROTO_MOUSE 2
  417. #define UICLASS_PHYSICAL 0x05
  418. #define UICLASS_IMAGE 0x06
  419. #define UISUBCLASS_SIC 1 /* still image class */
  420. #define UICLASS_PRINTER 0x07
  421. #define UISUBCLASS_PRINTER 1
  422. #define UIPROTO_PRINTER_UNI 1
  423. #define UIPROTO_PRINTER_BI 2
  424. #define UIPROTO_PRINTER_1284 3
  425. #define UICLASS_MASS 0x08
  426. #define UISUBCLASS_RBC 1
  427. #define UISUBCLASS_SFF8020I 2
  428. #define UISUBCLASS_QIC157 3
  429. #define UISUBCLASS_UFI 4
  430. #define UISUBCLASS_SFF8070I 5
  431. #define UISUBCLASS_SCSI 6
  432. #define UIPROTO_MASS_CBI_I 0
  433. #define UIPROTO_MASS_CBI 1
  434. #define UIPROTO_MASS_BBB_OLD 2 /* Not in the spec anymore */
  435. #define UIPROTO_MASS_BBB 80 /* 'P' for the Iomega Zip drive */
  436. #define UICLASS_HUB 0x09
  437. #define UISUBCLASS_HUB 0
  438. #define UIPROTO_FSHUB 0
  439. #define UIPROTO_HSHUBSTT 0 /* Yes, same as previous */
  440. #define UIPROTO_HSHUBMTT 1
  441. #define UICLASS_CDC_DATA 0x0a
  442. #define UISUBCLASS_DATA 0x00
  443. #define UIPROTO_DATA_ISDNBRI 0x30 /* Physical iface */
  444. #define UIPROTO_DATA_HDLC 0x31 /* HDLC */
  445. #define UIPROTO_DATA_TRANSPARENT 0x32 /* Transparent */
  446. #define UIPROTO_DATA_Q921M 0x50 /* Management for Q921 */
  447. #define UIPROTO_DATA_Q921 0x51 /* Data for Q921 */
  448. #define UIPROTO_DATA_Q921TM 0x52 /* TEI multiplexer for Q921 */
  449. #define UIPROTO_DATA_V42BIS 0x90 /* Data compression */
  450. #define UIPROTO_DATA_Q931 0x91 /* Euro-ISDN */
  451. #define UIPROTO_DATA_V120 0x92 /* V.24 rate adaption */
  452. #define UIPROTO_DATA_CAPI 0x93 /* CAPI 2.0 commands */
  453. #define UIPROTO_DATA_HOST_BASED 0xfd /* Host based driver */
  454. #define UIPROTO_DATA_PUF 0xfe /* see Prot. Unit Func. Desc. */
  455. #define UIPROTO_DATA_VENDOR 0xff /* Vendor specific */
  456. #define UIPROTO_DATA_NCM 0x01 /* Network Control Model */
  457. #define UICLASS_SMARTCARD 0x0b
  458. #define UICLASS_FIRM_UPD 0x0c
  459. #define UICLASS_SECURITY 0x0d
  460. #define UICLASS_DIAGNOSTIC 0xdc
  461. #define UICLASS_WIRELESS 0xe0
  462. #define UISUBCLASS_RF 0x01
  463. #define UIPROTO_BLUETOOTH 0x01
  464. #define UIPROTO_RNDIS 0x03
  465. #define UICLASS_IAD 0xEF /* Interface Association Descriptor */
  466. #define UISUBCLASS_SYNC 0x01
  467. #define UIPROTO_ACTIVESYNC 0x01
  468. #define UICLASS_APPL_SPEC 0xfe
  469. #define UISUBCLASS_FIRMWARE_DOWNLOAD 1
  470. #define UISUBCLASS_IRDA 2
  471. #define UIPROTO_IRDA 0
  472. #define UICLASS_VENDOR 0xff
  473. #define UISUBCLASS_XBOX360_CONTROLLER 0x5d
  474. #define UIPROTO_XBOX360_GAMEPAD 0x01
  475. #define USB_DT_ENDPOINT_SIZE 7
  476. struct usb_endpoint_descriptor {
  477. uByte bLength;
  478. uByte bDescriptorType;
  479. uByte bEndpointAddress;
  480. #define UE_GET_DIR(a) ((a) & 0x80)
  481. #define UE_SET_DIR(a,d) ((a) | (((d)&1) << 7))
  482. #define UE_DIR_IN 0x80 /* IN-token endpoint, fixed */
  483. #define UE_DIR_OUT 0x00 /* OUT-token endpoint, fixed */
  484. #define UE_DIR_RX 0xfd /* for internal use only! */
  485. #define UE_DIR_TX 0xfe /* for internal use only! */
  486. #define UE_DIR_ANY 0xff /* for internal use only! */
  487. #define UE_ADDR 0x0f
  488. #define UE_ADDR_ANY 0xff /* for internal use only! */
  489. #define UE_GET_ADDR(a) ((a) & UE_ADDR)
  490. uByte bmAttributes;
  491. #define UE_XFERTYPE 0x03
  492. #define UE_CONTROL 0x00
  493. #define UE_ISOCHRONOUS 0x01
  494. #define UE_BULK 0x02
  495. #define UE_INTERRUPT 0x03
  496. #define UE_BULK_INTR 0xfe /* for internal use only! */
  497. #define UE_TYPE_ANY 0xff /* for internal use only! */
  498. #define UE_GET_XFERTYPE(a) ((a) & UE_XFERTYPE)
  499. #define UE_ISO_TYPE 0x0c
  500. #define UE_ISO_ASYNC 0x04
  501. #define UE_ISO_ADAPT 0x08
  502. #define UE_ISO_SYNC 0x0c
  503. #define UE_GET_ISO_TYPE(a) ((a) & UE_ISO_TYPE)
  504. #define UE_ISO_USAGE 0x30
  505. #define UE_ISO_USAGE_DATA 0x00
  506. #define UE_ISO_USAGE_FEEDBACK 0x10
  507. #define UE_ISO_USAGE_IMPLICT_FB 0x20
  508. #define UE_GET_ISO_USAGE(a) ((a) & UE_ISO_USAGE)
  509. uWord wMaxPacketSize;
  510. #define UE_ZERO_MPS 0xFFFF /* for internal use only */
  511. uByte bInterval;
  512. } __attribute__((packed));
  513. typedef struct usb_endpoint_descriptor usb_endpoint_descriptor_t;
  514. struct usb_endpoint_ss_comp_descriptor {
  515. uByte bLength;
  516. uByte bDescriptorType;
  517. uByte bMaxBurst;
  518. uByte bmAttributes;
  519. #define UE_GET_BULK_STREAMS(x) ((x) & 0x0F)
  520. #define UE_GET_SS_ISO_MULT(x) ((x) & 0x03)
  521. uWord wBytesPerInterval;
  522. } __attribute__((packed));
  523. typedef struct usb_endpoint_ss_comp_descriptor
  524. usb_endpoint_ss_comp_descriptor_t;
  525. struct usb_string_descriptor {
  526. uByte bLength;
  527. uByte bDescriptorType;
  528. uWord wData[1];
  529. // uWord bString[126];
  530. // uByte bUnused;
  531. } __attribute__((packed));
  532. typedef struct usb_string_descriptor usb_string_descriptor_t;
  533. #define USB_MAKE_STRING_DESC(m,name) \
  534. static const struct { \
  535. uByte bLength; \
  536. uByte bDescriptorType; \
  537. uByte bData[sizeof((uint8_t []){m})]; \
  538. } __attribute__((packed)) name = { \
  539. .bLength = sizeof(name), \
  540. .bDescriptorType = UDESC_STRING, \
  541. .bData = { m }, \
  542. }
  543. struct usb_string_lang {
  544. uByte bLength;
  545. uByte bDescriptorType;
  546. uByte bData[2];
  547. } __attribute__((packed));
  548. typedef struct usb_string_lang usb_string_lang_t;
  549. struct usb_hub_descriptor {
  550. uByte bDescLength;
  551. uByte bDescriptorType;
  552. uByte bNbrPorts;
  553. uWord wHubCharacteristics;
  554. #define UHD_PWR 0x0003
  555. #define UHD_PWR_GANGED 0x0000
  556. #define UHD_PWR_INDIVIDUAL 0x0001
  557. #define UHD_PWR_NO_SWITCH 0x0002
  558. #define UHD_COMPOUND 0x0004
  559. #define UHD_OC 0x0018
  560. #define UHD_OC_GLOBAL 0x0000
  561. #define UHD_OC_INDIVIDUAL 0x0008
  562. #define UHD_OC_NONE 0x0010
  563. #define UHD_TT_THINK 0x0060
  564. #define UHD_TT_THINK_8 0x0000
  565. #define UHD_TT_THINK_16 0x0020
  566. #define UHD_TT_THINK_24 0x0040
  567. #define UHD_TT_THINK_32 0x0060
  568. #define UHD_PORT_IND 0x0080
  569. uByte bPwrOn2PwrGood; /* delay in 2 ms units */
  570. #define UHD_PWRON_FACTOR 2
  571. uByte bHubContrCurrent;
  572. uByte DeviceRemovable[32]; /* max 255 ports */
  573. #define UHD_NOT_REMOV(desc, i) \
  574. (((desc)->DeviceRemovable[(i)/8] >> ((i) % 8)) & 1)
  575. uByte PortPowerCtrlMask[1]; /* deprecated */
  576. } __attribute__((packed));
  577. typedef struct usb_hub_descriptor usb_hub_descriptor_t;
  578. struct usb_hub_ss_descriptor {
  579. uByte bLength;
  580. uByte bDescriptorType;
  581. uByte bNbrPorts;
  582. uWord wHubCharacteristics;
  583. uByte bPwrOn2PwrGood; /* delay in 2 ms units */
  584. uByte bHubContrCurrent;
  585. uByte bHubHdrDecLat;
  586. uWord wHubDelay;
  587. uByte DeviceRemovable[32]; /* max 255 ports */
  588. } __attribute__((packed));
  589. typedef struct usb_hub_ss_descriptor usb_hub_ss_descriptor_t;
  590. /* minimum HUB descriptor (8-ports maximum) */
  591. struct usb_hub_descriptor_min {
  592. uByte bDescLength;
  593. uByte bDescriptorType;
  594. uByte bNbrPorts;
  595. uWord wHubCharacteristics;
  596. uByte bPwrOn2PwrGood;
  597. uByte bHubContrCurrent;
  598. uByte DeviceRemovable[1];
  599. uByte PortPowerCtrlMask[1];
  600. } __attribute__((packed));
  601. typedef struct usb_hub_descriptor_min usb_hub_descriptor_min_t;
  602. #define USB_DT_DEVICE_QUALIFIER_SIZE 10
  603. struct usb_device_qualifier {
  604. uByte bLength;
  605. uByte bDescriptorType;
  606. uWord bcdUSB;
  607. uByte bDeviceClass;
  608. uByte bDeviceSubClass;
  609. uByte bDeviceProtocol;
  610. uByte bMaxPacketSize0;
  611. uByte bNumConfigurations;
  612. uByte bReserved;
  613. } __attribute__((packed));
  614. typedef struct usb_device_qualifier usb_device_qualifier_t;
  615. struct usb_otg_descriptor {
  616. uByte bLength;
  617. uByte bDescriptorType;
  618. uByte bmAttributes;
  619. #define UOTG_SRP 0x01
  620. #define UOTG_HNP 0x02
  621. } __attribute__((packed));
  622. typedef struct usb_otg_descriptor usb_otg_descriptor_t;
  623. /* OTG feature selectors */
  624. #define UOTG_B_HNP_ENABLE 3
  625. #define UOTG_A_HNP_SUPPORT 4
  626. #define UOTG_A_ALT_HNP_SUPPORT 5
  627. struct usb_status {
  628. uWord wStatus;
  629. /* Device status flags */
  630. #define UDS_SELF_POWERED 0x0001
  631. #define UDS_REMOTE_WAKEUP 0x0002
  632. /* Endpoint status flags */
  633. #define UES_HALT 0x0001
  634. } __attribute__((packed));
  635. typedef struct usb_status usb_status_t;
  636. struct usb_hub_status {
  637. uWord wHubStatus;
  638. #define UHS_LOCAL_POWER 0x0001
  639. #define UHS_OVER_CURRENT 0x0002
  640. uWord wHubChange;
  641. } __attribute__((packed));
  642. typedef struct usb_hub_status usb_hub_status_t;
  643. struct usb_port_status {
  644. uWord wPortStatus;
  645. #define UPS_CURRENT_CONNECT_STATUS 0x0001
  646. #define UPS_PORT_ENABLED 0x0002
  647. #define UPS_SUSPEND 0x0004
  648. #define UPS_OVERCURRENT_INDICATOR 0x0008
  649. #define UPS_RESET 0x0010
  650. #define UPS_PORT_L1 0x0020 /* USB 2.0 only */
  651. /* The link-state bits are valid for Super-Speed USB HUBs */
  652. #define UPS_PORT_LINK_STATE_GET(x) (((x) >> 5) & 0xF)
  653. #define UPS_PORT_LINK_STATE_SET(x) (((x) & 0xF) << 5)
  654. #define UPS_PORT_LS_U0 0x00
  655. #define UPS_PORT_LS_U1 0x01
  656. #define UPS_PORT_LS_U2 0x02
  657. #define UPS_PORT_LS_U3 0x03
  658. #define UPS_PORT_LS_SS_DIS 0x04
  659. #define UPS_PORT_LS_RX_DET 0x05
  660. #define UPS_PORT_LS_SS_INA 0x06
  661. #define UPS_PORT_LS_POLL 0x07
  662. #define UPS_PORT_LS_RECOVER 0x08
  663. #define UPS_PORT_LS_HOT_RST 0x09
  664. #define UPS_PORT_LS_COMP_MODE 0x0A
  665. #define UPS_PORT_LS_LOOPBACK 0x0B
  666. #define UPS_PORT_LS_RESUME 0x0F
  667. #define UPS_PORT_POWER 0x0100
  668. #define UPS_PORT_POWER_SS 0x0200 /* super-speed only */
  669. #define UPS_LOW_SPEED 0x0200
  670. #define UPS_HIGH_SPEED 0x0400
  671. #define UPS_OTHER_SPEED 0x0600 /* currently FreeBSD specific */
  672. #define UPS_PORT_TEST 0x0800
  673. #define UPS_PORT_INDICATOR 0x1000
  674. #define UPS_PORT_MODE_DEVICE 0x8000 /* currently FreeBSD specific */
  675. uWord wPortChange;
  676. #define UPS_C_CONNECT_STATUS 0x0001
  677. #define UPS_C_PORT_ENABLED 0x0002
  678. #define UPS_C_SUSPEND 0x0004
  679. #define UPS_C_OVERCURRENT_INDICATOR 0x0008
  680. #define UPS_C_PORT_RESET 0x0010
  681. #define UPS_C_PORT_L1 0x0020 /* USB 2.0 only */
  682. #define UPS_C_BH_PORT_RESET 0x0020 /* USB 3.0 only */
  683. #define UPS_C_PORT_LINK_STATE 0x0040
  684. #define UPS_C_PORT_CONFIG_ERROR 0x0080
  685. } __attribute__((packed));
  686. typedef struct usb_port_status usb_port_status_t;
  687. /*
  688. * The "USB_SPEED" macros defines all the supported USB speeds.
  689. */
  690. enum usb_dev_speed {
  691. USB_SPEED_VARIABLE,
  692. USB_SPEED_LOW,
  693. USB_SPEED_FULL,
  694. USB_SPEED_HIGH,
  695. USB_SPEED_SUPER,
  696. };
  697. #define USB_SPEED_MAX (USB_SPEED_SUPER+1)
  698. /*
  699. * The "USB_REV" macros defines all the supported USB revisions.
  700. */
  701. enum usb_revision {
  702. USB_REV_UNKNOWN,
  703. USB_REV_PRE_1_0,
  704. USB_REV_1_0,
  705. USB_REV_1_1,
  706. USB_REV_2_0,
  707. USB_REV_2_5,
  708. USB_REV_3_0
  709. };
  710. #define USB_REV_MAX (USB_REV_3_0+1)
  711. /*
  712. * Supported host controller modes.
  713. */
  714. enum usb_hc_mode {
  715. USB_MODE_HOST, /* initiates transfers */
  716. USB_MODE_DEVICE, /* bus transfer target */
  717. USB_MODE_DUAL /* can be host or device */
  718. };
  719. #define USB_MODE_MAX (USB_MODE_DUAL+1)
  720. /*
  721. * The "USB_STATE" enums define all the supported device states.
  722. */
  723. enum usb_dev_state {
  724. USB_STATE_DETACHED,
  725. USB_STATE_ATTACHED,
  726. USB_STATE_POWERED,
  727. USB_STATE_ADDRESSED,
  728. USB_STATE_CONFIGURED,
  729. };
  730. #define USB_STATE_MAX (USB_STATE_CONFIGURED+1)
  731. /*
  732. * The "USB_EP_MODE" macros define all the currently supported
  733. * endpoint modes.
  734. */
  735. enum usb_ep_mode {
  736. USB_EP_MODE_DEFAULT,
  737. USB_EP_MODE_STREAMS, /* USB3.0 specific */
  738. USB_EP_MODE_HW_MASS_STORAGE,
  739. USB_EP_MODE_HW_SERIAL,
  740. USB_EP_MODE_HW_ETHERNET_CDC,
  741. USB_EP_MODE_HW_ETHERNET_NCM,
  742. USB_EP_MODE_MAX
  743. };
  744. /*
  745. * Test Mode Selectors
  746. * See USB 2.0 spec Table 9-7
  747. */
  748. enum test_selector
  749. {
  750. TEST_J = 1,
  751. TEST_K = 2,
  752. TEST_SE0_NAK = 3,
  753. TEST_PACKET = 4,
  754. TEST_FORCE_EN = 5,
  755. };
  756. #endif /* _USB_STANDARD_H_ */