usb_define.h 25 KB

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