usb.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947
  1. /*
  2. * Copyright (c) 1998 The NetBSD Foundation, Inc.
  3. * All rights reserved.
  4. *
  5. * This code is derived from software contributed to The NetBSD Foundation
  6. * by Lennart Augustsson (lennart@augustsson.net) at
  7. * Carlstedt Research & Technology.
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions
  11. * are met:
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in the
  16. * documentation and/or other materials provided with the distribution.
  17. * 3. All advertising materials mentioning features or use of this software
  18. * must display the following acknowledgement:
  19. * This product includes software developed by the NetBSD
  20. * Foundation, Inc. and its contributors.
  21. * 4. Neither the name of The NetBSD Foundation nor the names of its
  22. * contributors may be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
  26. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  27. * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  28. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
  29. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  30. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  31. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  32. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  33. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  34. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  35. * POSSIBILITY OF SUCH DAMAGE.
  36. */
  37. /* Modified by Synopsys, Inc, 12/12/2007 */
  38. #ifndef _USB_H_
  39. #define _USB_H_
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. /*
  44. * The USB records contain some unaligned little-endian word
  45. * components. The U[SG]ETW macros take care of both the alignment
  46. * and endian problem and should always be used to access non-byte
  47. * values.
  48. */
  49. typedef u_int8_t uByte;
  50. typedef u_int8_t uWord[2];
  51. typedef u_int8_t uDWord[4];
  52. #define USETW2(w,h,l) ((w)[0] = (u_int8_t)(l), (w)[1] = (u_int8_t)(h))
  53. #define UCONSTW(x) { (x) & 0xff, ((x) >> 8) & 0xff }
  54. #define UCONSTDW(x) { (x) & 0xff, ((x) >> 8) & 0xff, \
  55. ((x) >> 16) & 0xff, ((x) >> 24) & 0xff }
  56. #if 1
  57. #define UGETW(w) ((w)[0] | ((w)[1] << 8))
  58. #define USETW(w,v) ((w)[0] = (u_int8_t)(v), (w)[1] = (u_int8_t)((v) >> 8))
  59. #define UGETDW(w) ((w)[0] | ((w)[1] << 8) | ((w)[2] << 16) | ((w)[3] << 24))
  60. #define USETDW(w,v) ((w)[0] = (u_int8_t)(v), \
  61. (w)[1] = (u_int8_t)((v) >> 8), \
  62. (w)[2] = (u_int8_t)((v) >> 16), \
  63. (w)[3] = (u_int8_t)((v) >> 24))
  64. #else
  65. /*
  66. * On little-endian machines that can handle unanliged accesses
  67. * (e.g. i386) these macros can be replaced by the following.
  68. */
  69. #define UGETW(w) (*(u_int16_t *)(w))
  70. #define USETW(w,v) (*(u_int16_t *)(w) = (v))
  71. #define UGETDW(w) (*(u_int32_t *)(w))
  72. #define USETDW(w,v) (*(u_int32_t *)(w) = (v))
  73. #endif
  74. /*
  75. * Macros for accessing UAS IU fields, which are big-endian
  76. */
  77. #define IUSETW2(w,h,l) ((w)[0] = (u_int8_t)(h), (w)[1] = (u_int8_t)(l))
  78. #define IUCONSTW(x) { ((x) >> 8) & 0xff, (x) & 0xff }
  79. #define IUCONSTDW(x) { ((x) >> 24) & 0xff, ((x) >> 16) & 0xff, \
  80. ((x) >> 8) & 0xff, (x) & 0xff }
  81. #define IUGETW(w) (((w)[0] << 8) | (w)[1])
  82. #define IUSETW(w,v) ((w)[0] = (u_int8_t)((v) >> 8), (w)[1] = (u_int8_t)(v))
  83. #define IUGETDW(w) (((w)[0] << 24) | ((w)[1] << 16) | ((w)[2] << 8) | (w)[3])
  84. #define IUSETDW(w,v) ((w)[0] = (u_int8_t)((v) >> 24), \
  85. (w)[1] = (u_int8_t)((v) >> 16), \
  86. (w)[2] = (u_int8_t)((v) >> 8), \
  87. (w)[3] = (u_int8_t)(v))
  88. #define UPACKED __attribute__((__packed__))
  89. typedef struct {
  90. uByte bmRequestType;
  91. uByte bRequest;
  92. uWord wValue;
  93. uWord wIndex;
  94. uWord wLength;
  95. } UPACKED usb_device_request_t;
  96. #define UT_GET_DIR(a) ((a) & 0x80)
  97. #define UT_WRITE 0x00
  98. #define UT_READ 0x80
  99. #define UT_GET_TYPE(a) ((a) & 0x60)
  100. #define UT_STANDARD 0x00
  101. #define UT_CLASS 0x20
  102. #define UT_VENDOR 0x40
  103. #define UT_GET_RECIPIENT(a) ((a) & 0x1f)
  104. #define UT_DEVICE 0x00
  105. #define UT_INTERFACE 0x01
  106. #define UT_ENDPOINT 0x02
  107. #define UT_OTHER 0x03
  108. #define UT_READ_DEVICE (UT_READ | UT_STANDARD | UT_DEVICE)
  109. #define UT_READ_INTERFACE (UT_READ | UT_STANDARD | UT_INTERFACE)
  110. #define UT_READ_ENDPOINT (UT_READ | UT_STANDARD | UT_ENDPOINT)
  111. #define UT_WRITE_DEVICE (UT_WRITE | UT_STANDARD | UT_DEVICE)
  112. #define UT_WRITE_INTERFACE (UT_WRITE | UT_STANDARD | UT_INTERFACE)
  113. #define UT_WRITE_ENDPOINT (UT_WRITE | UT_STANDARD | UT_ENDPOINT)
  114. #define UT_READ_CLASS_DEVICE (UT_READ | UT_CLASS | UT_DEVICE)
  115. #define UT_READ_CLASS_INTERFACE (UT_READ | UT_CLASS | UT_INTERFACE)
  116. #define UT_READ_CLASS_OTHER (UT_READ | UT_CLASS | UT_OTHER)
  117. #define UT_READ_CLASS_ENDPOINT (UT_READ | UT_CLASS | UT_ENDPOINT)
  118. #define UT_WRITE_CLASS_DEVICE (UT_WRITE | UT_CLASS | UT_DEVICE)
  119. #define UT_WRITE_CLASS_INTERFACE (UT_WRITE | UT_CLASS | UT_INTERFACE)
  120. #define UT_WRITE_CLASS_OTHER (UT_WRITE | UT_CLASS | UT_OTHER)
  121. #define UT_WRITE_CLASS_ENDPOINT (UT_WRITE | UT_CLASS | UT_ENDPOINT)
  122. #define UT_READ_VENDOR_DEVICE (UT_READ | UT_VENDOR | UT_DEVICE)
  123. #define UT_READ_VENDOR_INTERFACE (UT_READ | UT_VENDOR | UT_INTERFACE)
  124. #define UT_READ_VENDOR_OTHER (UT_READ | UT_VENDOR | UT_OTHER)
  125. #define UT_READ_VENDOR_ENDPOINT (UT_READ | UT_VENDOR | UT_ENDPOINT)
  126. #define UT_WRITE_VENDOR_DEVICE (UT_WRITE | UT_VENDOR | UT_DEVICE)
  127. #define UT_WRITE_VENDOR_INTERFACE (UT_WRITE | UT_VENDOR | UT_INTERFACE)
  128. #define UT_WRITE_VENDOR_OTHER (UT_WRITE | UT_VENDOR | UT_OTHER)
  129. #define UT_WRITE_VENDOR_ENDPOINT (UT_WRITE | UT_VENDOR | UT_ENDPOINT)
  130. /* Requests */
  131. #define UR_GET_STATUS 0x00
  132. #define USTAT_STANDARD_STATUS 0x00
  133. #define WUSTAT_WUSB_FEATURE 0x01
  134. #define WUSTAT_CHANNEL_INFO 0x02
  135. #define WUSTAT_RECEIVED_DATA 0x03
  136. #define WUSTAT_MAS_AVAILABILITY 0x04
  137. #define WUSTAT_CURRENT_TRANSMIT_POWER 0x05
  138. #define UR_CLEAR_FEATURE 0x01
  139. #define UR_SET_FEATURE 0x03
  140. #define UR_SET_AND_TEST_FEATURE 0x0c
  141. #define UR_SET_ADDRESS 0x05
  142. #define UR_GET_DESCRIPTOR 0x06
  143. #define UDESC_DEVICE 0x01
  144. #define UDESC_CONFIG 0x02
  145. #define UDESC_STRING 0x03
  146. #define UDESC_INTERFACE 0x04
  147. #define UDESC_ENDPOINT 0x05
  148. #define UDESC_SS_USB_COMPANION 0x30
  149. #define UDESC_DEVICE_QUALIFIER 0x06
  150. #define UDESC_OTHER_SPEED_CONFIGURATION 0x07
  151. #define UDESC_INTERFACE_POWER 0x08
  152. #define UDESC_OTG 0x09
  153. #define WUDESC_SECURITY 0x0c
  154. #define WUDESC_KEY 0x0d
  155. #define WUD_GET_KEY_INDEX(_wValue_) ((_wValue_) & 0xf)
  156. #define WUD_GET_KEY_TYPE(_wValue_) (((_wValue_) & 0x30) >> 4)
  157. #define WUD_KEY_TYPE_ASSOC 0x01
  158. #define WUD_KEY_TYPE_GTK 0x02
  159. #define WUD_GET_KEY_ORIGIN(_wValue_) (((_wValue_) & 0x40) >> 6)
  160. #define WUD_KEY_ORIGIN_HOST 0x00
  161. #define WUD_KEY_ORIGIN_DEVICE 0x01
  162. #define WUDESC_ENCRYPTION_TYPE 0x0e
  163. #define WUDESC_BOS 0x0f
  164. #define WUDESC_DEVICE_CAPABILITY 0x10
  165. #define WUDESC_WIRELESS_ENDPOINT_COMPANION 0x11
  166. #define UDESC_BOS 0x0f
  167. #define UDESC_DEVICE_CAPABILITY 0x10
  168. #define UDESC_CS_DEVICE 0x21 /* class specific */
  169. #define UDESC_CS_CONFIG 0x22
  170. #define UDESC_CS_STRING 0x23
  171. #define UDESC_CS_INTERFACE 0x24
  172. #define UDESC_CS_ENDPOINT 0x25
  173. #define UDESC_HUB 0x29
  174. #define UR_SET_DESCRIPTOR 0x07
  175. #define UR_GET_CONFIG 0x08
  176. #define UR_SET_CONFIG 0x09
  177. #define UR_GET_INTERFACE 0x0a
  178. #define UR_SET_INTERFACE 0x0b
  179. #define UR_SYNCH_FRAME 0x0c
  180. #define WUR_SET_ENCRYPTION 0x0d
  181. #define WUR_GET_ENCRYPTION 0x0e
  182. #define WUR_SET_HANDSHAKE 0x0f
  183. #define WUR_GET_HANDSHAKE 0x10
  184. #define WUR_SET_CONNECTION 0x11
  185. #define WUR_SET_SECURITY_DATA 0x12
  186. #define WUR_GET_SECURITY_DATA 0x13
  187. #define WUR_SET_WUSB_DATA 0x14
  188. #define WUDATA_DRPIE_INFO 0x01
  189. #define WUDATA_TRANSMIT_DATA 0x02
  190. #define WUDATA_TRANSMIT_PARAMS 0x03
  191. #define WUDATA_RECEIVE_PARAMS 0x04
  192. #define WUDATA_TRANSMIT_POWER 0x05
  193. #define WUR_LOOPBACK_DATA_WRITE 0x15
  194. #define WUR_LOOPBACK_DATA_READ 0x16
  195. #define WUR_SET_INTERFACE_DS 0x17
  196. /* Feature numbers */
  197. #define UF_ENDPOINT_HALT 0
  198. #define UF_DEVICE_REMOTE_WAKEUP 1
  199. #define UF_TEST_MODE 2
  200. #define UF_DEVICE_B_HNP_ENABLE 3
  201. #define UF_DEVICE_A_HNP_SUPPORT 4
  202. #define UF_DEVICE_A_ALT_HNP_SUPPORT 5
  203. #define WUF_WUSB 3
  204. #define WUF_TX_DRPIE 0x0
  205. #define WUF_DEV_XMIT_PACKET 0x1
  206. #define WUF_COUNT_PACKETS 0x2
  207. #define WUF_CAPTURE_PACKETS 0x3
  208. #define UF_FUNCTION_SUSPEND 0
  209. #define UF_U1_ENABLE 48
  210. #define UF_U2_ENABLE 49
  211. #define UF_LTM_ENABLE 50
  212. /* Class requests from the USB 2.0 hub spec, table 11-15 */
  213. #define UCR_CLEAR_HUB_FEATURE (0x2000 | UR_CLEAR_FEATURE)
  214. #define UCR_CLEAR_PORT_FEATURE (0x2300 | UR_CLEAR_FEATURE)
  215. #define UCR_GET_HUB_DESCRIPTOR (0xa000 | UR_GET_DESCRIPTOR)
  216. #define UCR_GET_HUB_STATUS (0xa000 | UR_GET_STATUS)
  217. #define UCR_GET_PORT_STATUS (0xa300 | UR_GET_STATUS)
  218. #define UCR_SET_HUB_FEATURE (0x2000 | UR_SET_FEATURE)
  219. #define UCR_SET_PORT_FEATURE (0x2300 | UR_SET_FEATURE)
  220. #define UCR_SET_AND_TEST_PORT_FEATURE (0xa300 | UR_SET_AND_TEST_FEATURE)
  221. #ifdef _MSC_VER
  222. #include <pshpack1.h>
  223. #endif
  224. typedef struct {
  225. uByte bLength;
  226. uByte bDescriptorType;
  227. uByte bDescriptorSubtype;
  228. } UPACKED usb_descriptor_t;
  229. typedef struct {
  230. uByte bLength;
  231. uByte bDescriptorType;
  232. } UPACKED usb_descriptor_header_t;
  233. typedef struct {
  234. uByte bLength;
  235. uByte bDescriptorType;
  236. uWord bcdUSB;
  237. #define UD_USB_2_0 0x0200
  238. #define UD_IS_USB2(d) (UGETW((d)->bcdUSB) >= UD_USB_2_0)
  239. uByte bDeviceClass;
  240. uByte bDeviceSubClass;
  241. uByte bDeviceProtocol;
  242. uByte bMaxPacketSize;
  243. /* The fields below are not part of the initial descriptor. */
  244. uWord idVendor;
  245. uWord idProduct;
  246. uWord bcdDevice;
  247. uByte iManufacturer;
  248. uByte iProduct;
  249. uByte iSerialNumber;
  250. uByte bNumConfigurations;
  251. } UPACKED usb_device_descriptor_t;
  252. #define USB_DEVICE_DESCRIPTOR_SIZE 18
  253. typedef struct {
  254. uByte bLength;
  255. uByte bDescriptorType;
  256. uWord wTotalLength;
  257. uByte bNumInterface;
  258. uByte bConfigurationValue;
  259. uByte iConfiguration;
  260. #define UC_ATT_ONE (1 << 7) /* must be set */
  261. #define UC_ATT_SELFPOWER (1 << 6) /* self powered */
  262. #define UC_ATT_WAKEUP (1 << 5) /* can wakeup */
  263. #define UC_ATT_BATTERY (1 << 4) /* battery powered */
  264. uByte bmAttributes;
  265. #define UC_BUS_POWERED 0x80
  266. #define UC_SELF_POWERED 0x40
  267. #define UC_REMOTE_WAKEUP 0x20
  268. uByte bMaxPower; /* max current in 2 mA units */
  269. #define UC_POWER_FACTOR 2
  270. } UPACKED usb_config_descriptor_t;
  271. #define USB_CONFIG_DESCRIPTOR_SIZE 9
  272. typedef struct {
  273. uByte bLength;
  274. uByte bDescriptorType;
  275. uByte bInterfaceNumber;
  276. uByte bAlternateSetting;
  277. uByte bNumEndpoints;
  278. uByte bInterfaceClass;
  279. uByte bInterfaceSubClass;
  280. uByte bInterfaceProtocol;
  281. uByte iInterface;
  282. } UPACKED usb_interface_descriptor_t;
  283. #define USB_INTERFACE_DESCRIPTOR_SIZE 9
  284. typedef struct {
  285. uByte bLength;
  286. uByte bDescriptorType;
  287. uByte bEndpointAddress;
  288. #define UE_GET_DIR(a) ((a) & 0x80)
  289. #define UE_SET_DIR(a,d) ((a) | (((d)&1) << 7))
  290. #define UE_DIR_IN 0x80
  291. #define UE_DIR_OUT 0x00
  292. #define UE_ADDR 0x0f
  293. #define UE_GET_ADDR(a) ((a) & UE_ADDR)
  294. uByte bmAttributes;
  295. #define UE_XFERTYPE 0x03
  296. #define UE_CONTROL 0x00
  297. #define UE_ISOCHRONOUS 0x01
  298. #define UE_BULK 0x02
  299. #define UE_INTERRUPT 0x03
  300. #define UE_GET_XFERTYPE(a) ((a) & UE_XFERTYPE)
  301. #define UE_ISO_TYPE 0x0c
  302. #define UE_ISO_ASYNC 0x04
  303. #define UE_ISO_ADAPT 0x08
  304. #define UE_ISO_SYNC 0x0c
  305. #define UE_GET_ISO_TYPE(a) ((a) & UE_ISO_TYPE)
  306. uWord wMaxPacketSize;
  307. uByte bInterval;
  308. } UPACKED usb_endpoint_descriptor_t;
  309. #define USB_ENDPOINT_DESCRIPTOR_SIZE 7
  310. typedef struct ss_endpoint_companion_descriptor {
  311. uByte bLength;
  312. uByte bDescriptorType;
  313. uByte bMaxBurst;
  314. #define USSE_GET_MAX_STREAMS(a) ((a) & 0x1f)
  315. #define USSE_SET_MAX_STREAMS(a, b) ((a) | ((b) & 0x1f))
  316. #define USSE_GET_MAX_PACKET_NUM(a) ((a) & 0x03)
  317. #define USSE_SET_MAX_PACKET_NUM(a, b) ((a) | ((b) & 0x03))
  318. uByte bmAttributes;
  319. uWord wBytesPerInterval;
  320. } UPACKED ss_endpoint_companion_descriptor_t;
  321. #define USB_SS_ENDPOINT_COMPANION_DESCRIPTOR_SIZE 6
  322. typedef struct {
  323. uByte bLength;
  324. uByte bDescriptorType;
  325. uWord bString[127];
  326. } UPACKED usb_string_descriptor_t;
  327. #define USB_MAX_STRING_LEN 128
  328. #define USB_LANGUAGE_TABLE 0 /* # of the string language id table */
  329. /* Hub specific request */
  330. #define UR_GET_BUS_STATE 0x02
  331. #define UR_CLEAR_TT_BUFFER 0x08
  332. #define UR_RESET_TT 0x09
  333. #define UR_GET_TT_STATE 0x0a
  334. #define UR_STOP_TT 0x0b
  335. /* Hub features */
  336. #define UHF_C_HUB_LOCAL_POWER 0
  337. #define UHF_C_HUB_OVER_CURRENT 1
  338. #define UHF_PORT_CONNECTION 0
  339. #define UHF_PORT_ENABLE 1
  340. #define UHF_PORT_SUSPEND 2
  341. #define UHF_PORT_OVER_CURRENT 3
  342. #define UHF_PORT_RESET 4
  343. #define UHF_PORT_L1 5
  344. #define UHF_PORT_POWER 8
  345. #define UHF_PORT_LOW_SPEED 9
  346. #define UHF_PORT_HIGH_SPEED 10
  347. #define UHF_C_PORT_CONNECTION 16
  348. #define UHF_C_PORT_ENABLE 17
  349. #define UHF_C_PORT_SUSPEND 18
  350. #define UHF_C_PORT_OVER_CURRENT 19
  351. #define UHF_C_PORT_RESET 20
  352. #define UHF_C_PORT_L1 23
  353. #define UHF_PORT_TEST 21
  354. #define UHF_PORT_INDICATOR 22
  355. typedef struct {
  356. uByte bDescLength;
  357. uByte bDescriptorType;
  358. uByte bNbrPorts;
  359. uWord wHubCharacteristics;
  360. #define UHD_PWR 0x0003
  361. #define UHD_PWR_GANGED 0x0000
  362. #define UHD_PWR_INDIVIDUAL 0x0001
  363. #define UHD_PWR_NO_SWITCH 0x0002
  364. #define UHD_COMPOUND 0x0004
  365. #define UHD_OC 0x0018
  366. #define UHD_OC_GLOBAL 0x0000
  367. #define UHD_OC_INDIVIDUAL 0x0008
  368. #define UHD_OC_NONE 0x0010
  369. #define UHD_TT_THINK 0x0060
  370. #define UHD_TT_THINK_8 0x0000
  371. #define UHD_TT_THINK_16 0x0020
  372. #define UHD_TT_THINK_24 0x0040
  373. #define UHD_TT_THINK_32 0x0060
  374. #define UHD_PORT_IND 0x0080
  375. uByte bPwrOn2PwrGood; /* delay in 2 ms units */
  376. #define UHD_PWRON_FACTOR 2
  377. uByte bHubContrCurrent;
  378. uByte DeviceRemovable[32]; /* max 255 ports */
  379. #define UHD_NOT_REMOV(desc, i) \
  380. (((desc)->DeviceRemovable[(i)/8] >> ((i) % 8)) & 1)
  381. /* deprecated */ uByte PortPowerCtrlMask[1];
  382. } UPACKED usb_hub_descriptor_t;
  383. #define USB_HUB_DESCRIPTOR_SIZE 9 /* includes deprecated PortPowerCtrlMask */
  384. typedef struct {
  385. uByte bLength;
  386. uByte bDescriptorType;
  387. uWord bcdUSB;
  388. uByte bDeviceClass;
  389. uByte bDeviceSubClass;
  390. uByte bDeviceProtocol;
  391. uByte bMaxPacketSize0;
  392. uByte bNumConfigurations;
  393. uByte bReserved;
  394. } UPACKED usb_device_qualifier_t;
  395. #define USB_DEVICE_QUALIFIER_SIZE 10
  396. typedef struct {
  397. uByte bLength;
  398. uByte bDescriptorType;
  399. uByte bmAttributes;
  400. #define UOTG_SRP 0x01
  401. #define UOTG_HNP 0x02
  402. } UPACKED usb_otg_descriptor_t;
  403. /* OTG feature selectors */
  404. #define UOTG_B_HNP_ENABLE 3
  405. #define UOTG_A_HNP_SUPPORT 4
  406. #define UOTG_A_ALT_HNP_SUPPORT 5
  407. typedef struct {
  408. uWord wStatus;
  409. /* Device status flags */
  410. #define UDS_SELF_POWERED 0x0001
  411. #define UDS_REMOTE_WAKEUP 0x0002
  412. /* Endpoint status flags */
  413. #define UES_HALT 0x0001
  414. } UPACKED usb_status_t;
  415. typedef struct {
  416. uWord wHubStatus;
  417. #define UHS_LOCAL_POWER 0x0001
  418. #define UHS_OVER_CURRENT 0x0002
  419. uWord wHubChange;
  420. } UPACKED usb_hub_status_t;
  421. typedef struct {
  422. uWord wPortStatus;
  423. #define UPS_CURRENT_CONNECT_STATUS 0x0001
  424. #define UPS_PORT_ENABLED 0x0002
  425. #define UPS_SUSPEND 0x0004
  426. #define UPS_OVERCURRENT_INDICATOR 0x0008
  427. #define UPS_RESET 0x0010
  428. #define UPS_PORT_POWER 0x0100
  429. #define UPS_LOW_SPEED 0x0200
  430. #define UPS_HIGH_SPEED 0x0400
  431. #define UPS_PORT_TEST 0x0800
  432. #define UPS_PORT_INDICATOR 0x1000
  433. uWord wPortChange;
  434. #define UPS_C_CONNECT_STATUS 0x0001
  435. #define UPS_C_PORT_ENABLED 0x0002
  436. #define UPS_C_SUSPEND 0x0004
  437. #define UPS_C_OVERCURRENT_INDICATOR 0x0008
  438. #define UPS_C_PORT_RESET 0x0010
  439. } UPACKED usb_port_status_t;
  440. #ifdef _MSC_VER
  441. #include <poppack.h>
  442. #endif
  443. /* Device class codes */
  444. #define UDCLASS_IN_INTERFACE 0x00
  445. #define UDCLASS_COMM 0x02
  446. #define UDCLASS_HUB 0x09
  447. #define UDSUBCLASS_HUB 0x00
  448. #define UDPROTO_FSHUB 0x00
  449. #define UDPROTO_HSHUBSTT 0x01
  450. #define UDPROTO_HSHUBMTT 0x02
  451. #define UDCLASS_DIAGNOSTIC 0xdc
  452. #define UDCLASS_WIRELESS 0xe0
  453. #define UDSUBCLASS_RF 0x01
  454. #define UDPROTO_BLUETOOTH 0x01
  455. #define UDCLASS_VENDOR 0xff
  456. /* Interface class codes */
  457. #define UICLASS_UNSPEC 0x00
  458. #define UICLASS_AUDIO 0x01
  459. #define UISUBCLASS_AUDIOCONTROL 1
  460. #define UISUBCLASS_AUDIOSTREAM 2
  461. #define UISUBCLASS_MIDISTREAM 3
  462. #define UICLASS_CDC 0x02 /* communication */
  463. #define UISUBCLASS_DIRECT_LINE_CONTROL_MODEL 1
  464. #define UISUBCLASS_ABSTRACT_CONTROL_MODEL 2
  465. #define UISUBCLASS_TELEPHONE_CONTROL_MODEL 3
  466. #define UISUBCLASS_MULTICHANNEL_CONTROL_MODEL 4
  467. #define UISUBCLASS_CAPI_CONTROLMODEL 5
  468. #define UISUBCLASS_ETHERNET_NETWORKING_CONTROL_MODEL 6
  469. #define UISUBCLASS_ATM_NETWORKING_CONTROL_MODEL 7
  470. #define UIPROTO_CDC_AT 1
  471. #define UICLASS_HID 0x03
  472. #define UISUBCLASS_BOOT 1
  473. #define UIPROTO_BOOT_KEYBOARD 1
  474. #define UICLASS_PHYSICAL 0x05
  475. #define UICLASS_IMAGE 0x06
  476. #define UICLASS_PRINTER 0x07
  477. #define UISUBCLASS_PRINTER 1
  478. #define UIPROTO_PRINTER_UNI 1
  479. #define UIPROTO_PRINTER_BI 2
  480. #define UIPROTO_PRINTER_1284 3
  481. #define UICLASS_MASS 0x08
  482. #define UISUBCLASS_RBC 1
  483. #define UISUBCLASS_SFF8020I 2
  484. #define UISUBCLASS_QIC157 3
  485. #define UISUBCLASS_UFI 4
  486. #define UISUBCLASS_SFF8070I 5
  487. #define UISUBCLASS_SCSI 6
  488. #define UIPROTO_MASS_CBI_I 0
  489. #define UIPROTO_MASS_CBI 1
  490. #define UIPROTO_MASS_BBB_OLD 2 /* Not in the spec anymore */
  491. #define UIPROTO_MASS_BBB 80 /* 'P' for the Iomega Zip drive */
  492. #define UICLASS_HUB 0x09
  493. #define UISUBCLASS_HUB 0
  494. #define UIPROTO_FSHUB 0
  495. #define UIPROTO_HSHUBSTT 0 /* Yes, same as previous */
  496. #define UIPROTO_HSHUBMTT 1
  497. #define UICLASS_CDC_DATA 0x0a
  498. #define UISUBCLASS_DATA 0
  499. #define UIPROTO_DATA_ISDNBRI 0x30 /* Physical iface */
  500. #define UIPROTO_DATA_HDLC 0x31 /* HDLC */
  501. #define UIPROTO_DATA_TRANSPARENT 0x32 /* Transparent */
  502. #define UIPROTO_DATA_Q921M 0x50 /* Management for Q921 */
  503. #define UIPROTO_DATA_Q921 0x51 /* Data for Q921 */
  504. #define UIPROTO_DATA_Q921TM 0x52 /* TEI multiplexer for Q921 */
  505. #define UIPROTO_DATA_V42BIS 0x90 /* Data compression */
  506. #define UIPROTO_DATA_Q931 0x91 /* Euro-ISDN */
  507. #define UIPROTO_DATA_V120 0x92 /* V.24 rate adaption */
  508. #define UIPROTO_DATA_CAPI 0x93 /* CAPI 2.0 commands */
  509. #define UIPROTO_DATA_HOST_BASED 0xfd /* Host based driver */
  510. #define UIPROTO_DATA_PUF 0xfe /* see Prot. Unit Func. Desc.*/
  511. #define UIPROTO_DATA_VENDOR 0xff /* Vendor specific */
  512. #define UICLASS_SMARTCARD 0x0b
  513. /*#define UICLASS_FIRM_UPD 0x0c*/
  514. #define UICLASS_SECURITY 0x0d
  515. #define UICLASS_DIAGNOSTIC 0xdc
  516. #define UICLASS_WIRELESS 0xe0
  517. #define UISUBCLASS_RF 0x01
  518. #define UIPROTO_BLUETOOTH 0x01
  519. #define UICLASS_APPL_SPEC 0xfe
  520. #define UISUBCLASS_FIRMWARE_DOWNLOAD 1
  521. #define UISUBCLASS_IRDA 2
  522. #define UIPROTO_IRDA 0
  523. #define UICLASS_VENDOR 0xff
  524. #define USB_HUB_MAX_DEPTH 5
  525. /*
  526. * Minimum time a device needs to be powered down to go through
  527. * a power cycle. XXX Are these time in the spec?
  528. */
  529. #define USB_POWER_DOWN_TIME 200 /* ms */
  530. #define USB_PORT_POWER_DOWN_TIME 100 /* ms */
  531. #if 0
  532. /* These are the values from the spec. */
  533. #define USB_PORT_RESET_DELAY 10 /* ms */
  534. #define USB_PORT_ROOT_RESET_DELAY 50 /* ms */
  535. #define USB_PORT_RESET_RECOVERY 10 /* ms */
  536. #define USB_PORT_POWERUP_DELAY 100 /* ms */
  537. #define USB_SET_ADDRESS_SETTLE 2 /* ms */
  538. #define USB_RESUME_DELAY (20*5) /* ms */
  539. #define USB_RESUME_WAIT 10 /* ms */
  540. #define USB_RESUME_RECOVERY 10 /* ms */
  541. #define USB_EXTRA_POWER_UP_TIME 0 /* ms */
  542. #else
  543. /* Allow for marginal (i.e. non-conforming) devices. */
  544. #define USB_PORT_RESET_DELAY 50 /* ms */
  545. #define USB_PORT_ROOT_RESET_DELAY 250 /* ms */
  546. #define USB_PORT_RESET_RECOVERY 250 /* ms */
  547. #define USB_PORT_POWERUP_DELAY 300 /* ms */
  548. #define USB_SET_ADDRESS_SETTLE 10 /* ms */
  549. #define USB_RESUME_DELAY (50*5) /* ms */
  550. #define USB_RESUME_WAIT 50 /* ms */
  551. #define USB_RESUME_RECOVERY 50 /* ms */
  552. #define USB_EXTRA_POWER_UP_TIME 20 /* ms */
  553. #endif
  554. #define USB_MIN_POWER 100 /* mA */
  555. #define USB_MAX_POWER 500 /* mA */
  556. #define USB_BUS_RESET_DELAY 100 /* ms XXX?*/
  557. #define USB_UNCONFIG_NO 0
  558. #define USB_UNCONFIG_INDEX (-1)
  559. /*** ioctl() related stuff ***/
  560. struct usb_ctl_request {
  561. int ucr_addr;
  562. usb_device_request_t ucr_request;
  563. void *ucr_data;
  564. int ucr_flags;
  565. #define USBD_SHORT_XFER_OK 0x04 /* allow short reads */
  566. int ucr_actlen; /* actual length transferred */
  567. };
  568. struct usb_alt_interface {
  569. int uai_config_index;
  570. int uai_interface_index;
  571. int uai_alt_no;
  572. };
  573. #define USB_CURRENT_CONFIG_INDEX (-1)
  574. #define USB_CURRENT_ALT_INDEX (-1)
  575. struct usb_config_desc {
  576. int ucd_config_index;
  577. usb_config_descriptor_t ucd_desc;
  578. };
  579. struct usb_interface_desc {
  580. int uid_config_index;
  581. int uid_interface_index;
  582. int uid_alt_index;
  583. usb_interface_descriptor_t uid_desc;
  584. };
  585. struct usb_endpoint_desc {
  586. int ued_config_index;
  587. int ued_interface_index;
  588. int ued_alt_index;
  589. int ued_endpoint_index;
  590. usb_endpoint_descriptor_t ued_desc;
  591. };
  592. struct usb_full_desc {
  593. int ufd_config_index;
  594. u_int ufd_size;
  595. u_char *ufd_data;
  596. };
  597. struct usb_string_desc {
  598. int usd_string_index;
  599. int usd_language_id;
  600. usb_string_descriptor_t usd_desc;
  601. };
  602. struct usb_ctl_report_desc {
  603. int ucrd_size;
  604. u_char ucrd_data[1024]; /* filled data size will vary */
  605. };
  606. typedef struct { u_int32_t cookie; } usb_event_cookie_t;
  607. #define USB_MAX_DEVNAMES 4
  608. #define USB_MAX_DEVNAMELEN 16
  609. struct usb_device_info {
  610. u_int8_t udi_bus;
  611. u_int8_t udi_addr; /* device address */
  612. usb_event_cookie_t udi_cookie;
  613. char udi_product[USB_MAX_STRING_LEN];
  614. char udi_vendor[USB_MAX_STRING_LEN];
  615. char udi_release[8];
  616. u_int16_t udi_productNo;
  617. u_int16_t udi_vendorNo;
  618. u_int16_t udi_releaseNo;
  619. u_int8_t udi_class;
  620. u_int8_t udi_subclass;
  621. u_int8_t udi_protocol;
  622. u_int8_t udi_config;
  623. u_int8_t udi_speed;
  624. #define USB_SPEED_UNKNOWN 0
  625. #define USB_SPEED_LOW 1
  626. #define USB_SPEED_FULL 2
  627. #define USB_SPEED_HIGH 3
  628. #define USB_SPEED_VARIABLE 4
  629. #define USB_SPEED_SUPER 5
  630. int udi_power; /* power consumption in mA, 0 if selfpowered */
  631. int udi_nports;
  632. char udi_devnames[USB_MAX_DEVNAMES][USB_MAX_DEVNAMELEN];
  633. u_int8_t udi_ports[16];/* hub only: addresses of devices on ports */
  634. #define USB_PORT_ENABLED 0xff
  635. #define USB_PORT_SUSPENDED 0xfe
  636. #define USB_PORT_POWERED 0xfd
  637. #define USB_PORT_DISABLED 0xfc
  638. };
  639. struct usb_ctl_report {
  640. int ucr_report;
  641. u_char ucr_data[1024]; /* filled data size will vary */
  642. };
  643. struct usb_device_stats {
  644. u_long uds_requests[4]; /* indexed by transfer type UE_* */
  645. };
  646. #define WUSB_MIN_IE 0x80
  647. #define WUSB_WCTA_IE 0x80
  648. #define WUSB_WCONNECTACK_IE 0x81
  649. #define WUSB_WHOSTINFO_IE 0x82
  650. #define WUHI_GET_CA(_bmAttributes_) ((_bmAttributes_) & 0x3)
  651. #define WUHI_CA_RECONN 0x00
  652. #define WUHI_CA_LIMITED 0x01
  653. #define WUHI_CA_ALL 0x03
  654. #define WUHI_GET_MLSI(_bmAttributes_) (((_bmAttributes_) & 0x38) >> 3)
  655. #define WUSB_WCHCHANGEANNOUNCE_IE 0x83
  656. #define WUSB_WDEV_DISCONNECT_IE 0x84
  657. #define WUSB_WHOST_DISCONNECT_IE 0x85
  658. #define WUSB_WRELEASE_CHANNEL_IE 0x86
  659. #define WUSB_WWORK_IE 0x87
  660. #define WUSB_WCHANNEL_STOP_IE 0x88
  661. #define WUSB_WDEV_KEEPALIVE_IE 0x89
  662. #define WUSB_WISOCH_DISCARD_IE 0x8A
  663. #define WUSB_WRESETDEVICE_IE 0x8B
  664. #define WUSB_WXMIT_PACKET_ADJUST_IE 0x8C
  665. #define WUSB_MAX_IE 0x8C
  666. /* Device Notification Types */
  667. #define WUSB_DN_MIN 0x01
  668. #define WUSB_DN_CONNECT 0x01
  669. # define WUSB_DA_OLDCONN 0x00
  670. # define WUSB_DA_NEWCONN 0x01
  671. # define WUSB_DA_SELF_BEACON 0x02
  672. # define WUSB_DA_DIR_BEACON 0x04
  673. # define WUSB_DA_NO_BEACON 0x06
  674. #define WUSB_DN_DISCONNECT 0x02
  675. #define WUSB_DN_EPRDY 0x03
  676. #define WUSB_DN_MASAVAILCHANGED 0x04
  677. #define WUSB_DN_REMOTEWAKEUP 0x05
  678. #define WUSB_DN_SLEEP 0x06
  679. #define WUSB_DN_ALIVE 0x07
  680. #define WUSB_DN_MAX 0x07
  681. #ifdef _MSC_VER
  682. #include <pshpack1.h>
  683. #endif
  684. /* WUSB Handshake Data. Used during the SET/GET HANDSHAKE requests */
  685. typedef struct wusb_hndshk_data {
  686. uByte bMessageNumber;
  687. uByte bStatus;
  688. uByte tTKID[3];
  689. uByte bReserved;
  690. uByte CDID[16];
  691. uByte Nonce[16];
  692. uByte MIC[8];
  693. } UPACKED wusb_hndshk_data_t;
  694. #define WUSB_HANDSHAKE_LEN_FOR_MIC 38
  695. /* WUSB Connection Context */
  696. typedef struct wusb_conn_context {
  697. uByte CHID [16];
  698. uByte CDID [16];
  699. uByte CK [16];
  700. } UPACKED wusb_conn_context_t;
  701. /* WUSB Security Descriptor */
  702. typedef struct wusb_security_desc {
  703. uByte bLength;
  704. uByte bDescriptorType;
  705. uWord wTotalLength;
  706. uByte bNumEncryptionTypes;
  707. } UPACKED wusb_security_desc_t;
  708. /* WUSB Encryption Type Descriptor */
  709. typedef struct wusb_encrypt_type_desc {
  710. uByte bLength;
  711. uByte bDescriptorType;
  712. uByte bEncryptionType;
  713. #define WUETD_UNSECURE 0
  714. #define WUETD_WIRED 1
  715. #define WUETD_CCM_1 2
  716. #define WUETD_RSA_1 3
  717. uByte bEncryptionValue;
  718. uByte bAuthKeyIndex;
  719. } UPACKED wusb_encrypt_type_desc_t;
  720. /* WUSB Key Descriptor */
  721. typedef struct wusb_key_desc {
  722. uByte bLength;
  723. uByte bDescriptorType;
  724. uByte tTKID[3];
  725. uByte bReserved;
  726. uByte KeyData[1]; /* variable length */
  727. } UPACKED wusb_key_desc_t;
  728. /* WUSB BOS Descriptor (Binary device Object Store) */
  729. typedef struct wusb_bos_desc {
  730. uByte bLength;
  731. uByte bDescriptorType;
  732. uWord wTotalLength;
  733. uByte bNumDeviceCaps;
  734. } UPACKED wusb_bos_desc_t;
  735. #define USB_DEVICE_CAPABILITY_20_EXTENSION 0x02
  736. typedef struct usb_dev_cap_20_ext_desc {
  737. uByte bLength;
  738. uByte bDescriptorType;
  739. uByte bDevCapabilityType;
  740. #define USB_20_EXT_LPM 0x02
  741. uDWord bmAttributes;
  742. } UPACKED usb_dev_cap_20_ext_desc_t;
  743. #define USB_DEVICE_CAPABILITY_SS_USB 0x03
  744. typedef struct usb_dev_cap_ss_usb {
  745. uByte bLength;
  746. uByte bDescriptorType;
  747. uByte bDevCapabilityType;
  748. #define USB_DC_SS_USB_LTM_CAPABLE 0x02
  749. uByte bmAttributes;
  750. #define USB_DC_SS_USB_SPEED_SUPPORT_LOW 0x01
  751. #define USB_DC_SS_USB_SPEED_SUPPORT_FULL 0x02
  752. #define USB_DC_SS_USB_SPEED_SUPPORT_HIGH 0x04
  753. #define USB_DC_SS_USB_SPEED_SUPPORT_SS 0x08
  754. uWord wSpeedsSupported;
  755. uByte bFunctionalitySupport;
  756. uByte bU1DevExitLat;
  757. uWord wU2DevExitLat;
  758. } UPACKED usb_dev_cap_ss_usb_t;
  759. #define USB_DEVICE_CAPABILITY_CONTAINER_ID 0x04
  760. typedef struct usb_dev_cap_container_id {
  761. uByte bLength;
  762. uByte bDescriptorType;
  763. uByte bDevCapabilityType;
  764. uByte bReserved;
  765. uByte containerID[16];
  766. } UPACKED usb_dev_cap_container_id_t;
  767. /* Device Capability Type Codes */
  768. #define WUSB_DEVICE_CAPABILITY_WIRELESS_USB 0x01
  769. /* Device Capability Descriptor */
  770. typedef struct wusb_dev_cap_desc {
  771. uByte bLength;
  772. uByte bDescriptorType;
  773. uByte bDevCapabilityType;
  774. uByte caps[1]; /* Variable length */
  775. } UPACKED wusb_dev_cap_desc_t;
  776. /* Device Capability Descriptor */
  777. typedef struct wusb_dev_cap_uwb_desc {
  778. uByte bLength;
  779. uByte bDescriptorType;
  780. uByte bDevCapabilityType;
  781. uByte bmAttributes;
  782. uWord wPHYRates; /* Bitmap */
  783. uByte bmTFITXPowerInfo;
  784. uByte bmFFITXPowerInfo;
  785. uWord bmBandGroup;
  786. uByte bReserved;
  787. } UPACKED wusb_dev_cap_uwb_desc_t;
  788. /* Wireless USB Endpoint Companion Descriptor */
  789. typedef struct wusb_endpoint_companion_desc {
  790. uByte bLength;
  791. uByte bDescriptorType;
  792. uByte bMaxBurst;
  793. uByte bMaxSequence;
  794. uWord wMaxStreamDelay;
  795. uWord wOverTheAirPacketSize;
  796. uByte bOverTheAirInterval;
  797. uByte bmCompAttributes;
  798. } UPACKED wusb_endpoint_companion_desc_t;
  799. /* Wireless USB Numeric Association M1 Data Structure */
  800. typedef struct wusb_m1_data {
  801. uByte version;
  802. uWord langId;
  803. uByte deviceFriendlyNameLength;
  804. uByte sha_256_m3[32];
  805. uByte deviceFriendlyName[256];
  806. } UPACKED wusb_m1_data_t;
  807. typedef struct wusb_m2_data {
  808. uByte version;
  809. uWord langId;
  810. uByte hostFriendlyNameLength;
  811. uByte pkh[384];
  812. uByte hostFriendlyName[256];
  813. } UPACKED wusb_m2_data_t;
  814. typedef struct wusb_m3_data {
  815. uByte pkd[384];
  816. uByte nd;
  817. } UPACKED wusb_m3_data_t;
  818. typedef struct wusb_m4_data {
  819. uDWord _attributeTypeIdAndLength_1;
  820. uWord associationTypeId;
  821. uDWord _attributeTypeIdAndLength_2;
  822. uWord associationSubTypeId;
  823. uDWord _attributeTypeIdAndLength_3;
  824. uDWord length;
  825. uDWord _attributeTypeIdAndLength_4;
  826. uDWord associationStatus;
  827. uDWord _attributeTypeIdAndLength_5;
  828. uByte chid[16];
  829. uDWord _attributeTypeIdAndLength_6;
  830. uByte cdid[16];
  831. uDWord _attributeTypeIdAndLength_7;
  832. uByte bandGroups[2];
  833. } UPACKED wusb_m4_data_t;
  834. #ifdef _MSC_VER
  835. #include <poppack.h>
  836. #endif
  837. #ifdef __cplusplus
  838. }
  839. #endif
  840. #endif /* _USB_H_ */