usb_def.h 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844
  1. /*
  2. * Copyright (c) 2022, sakumisu
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #ifndef USB_DEF_H
  7. #define USB_DEF_H
  8. /* Useful define */
  9. #define USB_1_1 0x0110
  10. #define USB_2_0 0x0200
  11. /* Set USB version to 2.1 so that the host will request the BOS descriptor */
  12. #define USB_2_1 0x0210
  13. #define USB_3_0 0x0300
  14. #define USB_3_1 0x0310
  15. #define USB_3_2 0x0320
  16. /* Device speeds */
  17. #define USB_SPEED_UNKNOWN 0 /* Transfer rate not yet set */
  18. #define USB_SPEED_LOW 1 /* USB 1.1 */
  19. #define USB_SPEED_FULL 2 /* USB 1.1 */
  20. #define USB_SPEED_HIGH 3 /* USB 2.0 */
  21. #define USB_SPEED_WIRELESS 4 /* Wireless USB 2.5 */
  22. #define USB_SPEED_SUPER 5 /* USB 3.0 */
  23. #define USB_SPEED_SUPER_PLUS 6 /* USB 3.1 */
  24. /* Maximum number of devices per controller */
  25. #define USB_MAX_DEVICES (127)
  26. /* Default USB control EP, always 0 and 0x80 */
  27. #define USB_CONTROL_OUT_EP0 0
  28. #define USB_CONTROL_IN_EP0 0x80
  29. /**< maximum packet size (MPS) for EP 0 */
  30. #define USB_CTRL_EP_MPS 64
  31. /**< maximum packet size (MPS) for bulk EP */
  32. #define USB_BULK_EP_MPS_HS 512
  33. #define USB_BULK_EP_MPS_FS 64
  34. /* USB PID Types */
  35. #define USB_PID_OUT (0x01) /* Tokens */
  36. #define USB_PID_IN (0x09)
  37. #define USB_PID_SOF (0x05)
  38. #define USB_PID_SETUP (0x0d)
  39. #define USB_PID_DATA0 (0x03) /* Data */
  40. #define USB_PID_DATA1 (0x0b)
  41. #define USB_PID_DATA2 (0x07)
  42. #define USB_PID_MDATA (0x0f)
  43. #define USB_PID_ACK (0x02) /* Handshake */
  44. #define USB_PID_NAK (0x0a)
  45. #define USB_PID_STALL (0x0e)
  46. #define USB_PID_NYET (0x06)
  47. #define USB_PID_PRE (0x0c) /* Special */
  48. #define USB_PID_ERR (0x0c)
  49. #define USB_PID_SPLIT (0x08)
  50. #define USB_PID_PING (0x04)
  51. #define USB_PID_RESERVED (0x00)
  52. #define USB_REQUEST_DIR_SHIFT 7U /* Bits 7: Request dir */
  53. #define USB_REQUEST_DIR_OUT (0U << USB_REQUEST_DIR_SHIFT) /* Bit 7=0: Host-to-device */
  54. #define USB_REQUEST_DIR_IN (1U << USB_REQUEST_DIR_SHIFT) /* Bit 7=1: Device-to-host */
  55. #define USB_REQUEST_DIR_MASK (1U << USB_REQUEST_DIR_SHIFT) /* Bit 7=1: Direction bit */
  56. #define USB_REQUEST_TYPE_SHIFT 5U /* Bits 5:6: Request type */
  57. #define USB_REQUEST_STANDARD (0U << USB_REQUEST_TYPE_SHIFT)
  58. #define USB_REQUEST_CLASS (1U << USB_REQUEST_TYPE_SHIFT)
  59. #define USB_REQUEST_VENDOR (2U << USB_REQUEST_TYPE_SHIFT)
  60. #define USB_REQUEST_RESERVED (3U << USB_REQUEST_TYPE_SHIFT)
  61. #define USB_REQUEST_TYPE_MASK (3U << USB_REQUEST_TYPE_SHIFT)
  62. #define USB_REQUEST_RECIPIENT_SHIFT 0U /* Bits 0:4: Recipient */
  63. #define USB_REQUEST_RECIPIENT_DEVICE (0U << USB_REQUEST_RECIPIENT_SHIFT)
  64. #define USB_REQUEST_RECIPIENT_INTERFACE (1U << USB_REQUEST_RECIPIENT_SHIFT)
  65. #define USB_REQUEST_RECIPIENT_ENDPOINT (2U << USB_REQUEST_RECIPIENT_SHIFT)
  66. #define USB_REQUEST_RECIPIENT_OTHER (3U << USB_REQUEST_RECIPIENT_SHIFT)
  67. #define USB_REQUEST_RECIPIENT_MASK (3U << USB_REQUEST_RECIPIENT_SHIFT)
  68. /* USB Standard Request Codes */
  69. #define USB_REQUEST_GET_STATUS 0x00
  70. #define USB_REQUEST_CLEAR_FEATURE 0x01
  71. #define USB_REQUEST_SET_FEATURE 0x03
  72. #define USB_REQUEST_SET_ADDRESS 0x05
  73. #define USB_REQUEST_GET_DESCRIPTOR 0x06
  74. #define USB_REQUEST_SET_DESCRIPTOR 0x07
  75. #define USB_REQUEST_GET_CONFIGURATION 0x08
  76. #define USB_REQUEST_SET_CONFIGURATION 0x09
  77. #define USB_REQUEST_GET_INTERFACE 0x0A
  78. #define USB_REQUEST_SET_INTERFACE 0x0B
  79. #define USB_REQUEST_SYNCH_FRAME 0x0C
  80. #define USB_REQUEST_SET_ENCRYPTION 0x0D
  81. #define USB_REQUEST_GET_ENCRYPTION 0x0E
  82. #define USB_REQUEST_RPIPE_ABORT 0x0E
  83. #define USB_REQUEST_SET_HANDSHAKE 0x0F
  84. #define USB_REQUEST_RPIPE_RESET 0x0F
  85. #define USB_REQUEST_GET_HANDSHAKE 0x10
  86. #define USB_REQUEST_SET_CONNECTION 0x11
  87. #define USB_REQUEST_SET_SECURITY_DATA 0x12
  88. #define USB_REQUEST_GET_SECURITY_DATA 0x13
  89. #define USB_REQUEST_SET_WUSB_DATA 0x14
  90. #define USB_REQUEST_LOOPBACK_DATA_WRITE 0x15
  91. #define USB_REQUEST_LOOPBACK_DATA_READ 0x16
  92. #define USB_REQUEST_SET_INTERFACE_DS 0x17
  93. /* USB Standard Feature selectors */
  94. #define USB_FEATURE_ENDPOINT_HALT 0
  95. #define USB_FEATURE_SELF_POWERED 0
  96. #define USB_FEATURE_REMOTE_WAKEUP 1
  97. #define USB_FEATURE_TEST_MODE 2
  98. #define USB_FEATURE_BATTERY 2
  99. #define USB_FEATURE_BHNPENABLE 3
  100. #define USB_FEATURE_WUSBDEVICE 3
  101. #define USB_FEATURE_AHNPSUPPORT 4
  102. #define USB_FEATURE_AALTHNPSUPPORT 5
  103. #define USB_FEATURE_DEBUGMODE 6
  104. /* USB GET_STATUS Bit Values */
  105. #define USB_GETSTATUS_ENDPOINT_HALT 0x01
  106. #define USB_GETSTATUS_SELF_POWERED 0x01
  107. #define USB_GETSTATUS_REMOTE_WAKEUP 0x02
  108. /* USB Descriptor Types */
  109. #define USB_DESCRIPTOR_TYPE_DEVICE 0x01U
  110. #define USB_DESCRIPTOR_TYPE_CONFIGURATION 0x02U
  111. #define USB_DESCRIPTOR_TYPE_STRING 0x03U
  112. #define USB_DESCRIPTOR_TYPE_INTERFACE 0x04U
  113. #define USB_DESCRIPTOR_TYPE_ENDPOINT 0x05U
  114. #define USB_DESCRIPTOR_TYPE_DEVICE_QUALIFIER 0x06U
  115. #define USB_DESCRIPTOR_TYPE_OTHER_SPEED 0x07U
  116. #define USB_DESCRIPTOR_TYPE_INTERFACE_POWER 0x08U
  117. #define USB_DESCRIPTOR_TYPE_OTG 0x09U
  118. #define USB_DESCRIPTOR_TYPE_DEBUG 0x0AU
  119. #define USB_DESCRIPTOR_TYPE_INTERFACE_ASSOCIATION 0x0BU
  120. #define USB_DESCRIPTOR_TYPE_BINARY_OBJECT_STORE 0x0FU
  121. #define USB_DESCRIPTOR_TYPE_DEVICE_CAPABILITY 0x10U
  122. #define USB_DESCRIPTOR_TYPE_WIRELESS_ENDPOINTCOMP 0x11U
  123. /* Class Specific Descriptor */
  124. #define USB_CS_DESCRIPTOR_TYPE_DEVICE 0x21U
  125. #define USB_CS_DESCRIPTOR_TYPE_CONFIGURATION 0x22U
  126. #define USB_CS_DESCRIPTOR_TYPE_STRING 0x23U
  127. #define USB_CS_DESCRIPTOR_TYPE_INTERFACE 0x24U
  128. #define USB_CS_DESCRIPTOR_TYPE_ENDPOINT 0x25U
  129. #define USB_DESCRIPTOR_TYPE_SUPERSPEED_ENDPOINT_COMPANION 0x30U
  130. #define USB_DESCRIPTOR_TYPE_SUPERSPEED_ISO_ENDPOINT_COMPANION 0x31U
  131. /* USB Device Classes */
  132. #define USB_DEVICE_CLASS_RESERVED 0x00
  133. #define USB_DEVICE_CLASS_AUDIO 0x01
  134. #define USB_DEVICE_CLASS_CDC 0x02
  135. #define USB_DEVICE_CLASS_HID 0x03
  136. #define USB_DEVICE_CLASS_MONITOR 0x04
  137. #define USB_DEVICE_CLASS_PHYSICAL 0x05
  138. #define USB_DEVICE_CLASS_IMAGE 0x06
  139. #define USB_DEVICE_CLASS_PRINTER 0x07
  140. #define USB_DEVICE_CLASS_MASS_STORAGE 0x08
  141. #define USB_DEVICE_CLASS_HUB 0x09
  142. #define USB_DEVICE_CLASS_CDC_DATA 0x0a
  143. #define USB_DEVICE_CLASS_SMART_CARD 0x0b
  144. #define USB_DEVICE_CLASS_SECURITY 0x0d
  145. #define USB_DEVICE_CLASS_VIDEO 0x0e
  146. #define USB_DEVICE_CLASS_HEALTHCARE 0x0f
  147. #define USB_DEVICE_CLASS_DIAG_DEVICE 0xdc
  148. #define USB_DEVICE_CLASS_WIRELESS 0xe0
  149. #define USB_DEVICE_CLASS_MISC 0xef
  150. #define USB_DEVICE_CLASS_APP_SPECIFIC 0xfe
  151. #define USB_DEVICE_CLASS_VEND_SPECIFIC 0xff
  152. /* usb string index define */
  153. #define USB_STRING_LANGID_INDEX 0x00
  154. #define USB_STRING_MFC_INDEX 0x01
  155. #define USB_STRING_PRODUCT_INDEX 0x02
  156. #define USB_STRING_SERIAL_INDEX 0x03
  157. #define USB_STRING_CONFIG_INDEX 0x04
  158. #define USB_STRING_INTERFACE_INDEX 0x05
  159. #define USB_STRING_OS_INDEX 0x06
  160. #define USB_STRING_MAX USB_STRING_OS_INDEX
  161. /*
  162. * Devices supporting Microsoft OS Descriptors store special string
  163. * descriptor at fixed index (0xEE). It is read when a new device is
  164. * attached to a computer for the first time.
  165. */
  166. #define USB_OSDESC_STRING_DESC_INDEX 0xEE
  167. /* bmAttributes in Configuration Descriptor */
  168. #define USB_CONFIG_REMOTE_WAKEUP 0x20
  169. #define USB_CONFIG_POWERED_MASK 0x40
  170. #define USB_CONFIG_BUS_POWERED 0x80
  171. #define USB_CONFIG_SELF_POWERED 0xC0
  172. /* bMaxPower in Configuration Descriptor */
  173. #define USB_CONFIG_POWER_MA(mA) ((mA) / 2)
  174. /* bEndpointAddress in Endpoint Descriptor */
  175. #define USB_ENDPOINT_DIRECTION_MASK 0x80
  176. #define USB_ENDPOINT_OUT(addr) ((addr) | 0x00)
  177. #define USB_ENDPOINT_IN(addr) ((addr) | 0x80)
  178. /**
  179. * USB endpoint direction and number.
  180. */
  181. #define USB_EP_DIR_MASK 0x80U
  182. #define USB_EP_DIR_IN 0x80U
  183. #define USB_EP_DIR_OUT 0x00U
  184. /** Get endpoint index (number) from endpoint address */
  185. #define USB_EP_GET_IDX(ep) ((ep) & ~USB_EP_DIR_MASK)
  186. /** Get direction from endpoint address */
  187. #define USB_EP_GET_DIR(ep) ((ep)&USB_EP_DIR_MASK)
  188. /** Get endpoint address from endpoint index and direction */
  189. #define USB_EP_GET_ADDR(idx, dir) ((idx) | ((dir)&USB_EP_DIR_MASK))
  190. /** True if the endpoint is an IN endpoint */
  191. #define USB_EP_DIR_IS_IN(ep) (USB_EP_GET_DIR(ep) == USB_EP_DIR_IN)
  192. /** True if the endpoint is an OUT endpoint */
  193. #define USB_EP_DIR_IS_OUT(ep) (USB_EP_GET_DIR(ep) == USB_EP_DIR_OUT)
  194. /* bmAttributes in Endpoint Descriptor */
  195. #define USB_ENDPOINT_TYPE_SHIFT 0
  196. #define USB_ENDPOINT_TYPE_CONTROL (0 << USB_ENDPOINT_TYPE_SHIFT)
  197. #define USB_ENDPOINT_TYPE_ISOCHRONOUS (1 << USB_ENDPOINT_TYPE_SHIFT)
  198. #define USB_ENDPOINT_TYPE_BULK (2 << USB_ENDPOINT_TYPE_SHIFT)
  199. #define USB_ENDPOINT_TYPE_INTERRUPT (3 << USB_ENDPOINT_TYPE_SHIFT)
  200. #define USB_ENDPOINT_TYPE_MASK (3 << USB_ENDPOINT_TYPE_SHIFT)
  201. #define USB_GET_ENDPOINT_TYPE(x) ((x & USB_ENDPOINT_TYPE_MASK) >> USB_ENDPOINT_TYPE_SHIFT)
  202. #define USB_ENDPOINT_SYNC_SHIFT 2
  203. #define USB_ENDPOINT_SYNC_NO_SYNCHRONIZATION (0 << USB_ENDPOINT_SYNC_SHIFT)
  204. #define USB_ENDPOINT_SYNC_ASYNCHRONOUS (1 << USB_ENDPOINT_SYNC_SHIFT)
  205. #define USB_ENDPOINT_SYNC_ADAPTIVE (2 << USB_ENDPOINT_SYNC_SHIFT)
  206. #define USB_ENDPOINT_SYNC_SYNCHRONOUS (3 << USB_ENDPOINT_SYNC_SHIFT)
  207. #define USB_ENDPOINT_SYNC_MASK (3 << USB_ENDPOINT_SYNC_SHIFT)
  208. #define USB_ENDPOINT_USAGE_SHIFT 4
  209. #define USB_ENDPOINT_USAGE_DATA (0 << USB_ENDPOINT_USAGE_SHIFT)
  210. #define USB_ENDPOINT_USAGE_FEEDBACK (1 << USB_ENDPOINT_USAGE_SHIFT)
  211. #define USB_ENDPOINT_USAGE_IMPLICIT_FEEDBACK (2 << USB_ENDPOINT_USAGE_SHIFT)
  212. #define USB_ENDPOINT_USAGE_MASK (3 << USB_ENDPOINT_USAGE_SHIFT)
  213. #define USB_ENDPOINT_MAX_ADJUSTABLE (1 << 7)
  214. /* wMaxPacketSize in Endpoint Descriptor */
  215. #define USB_MAXPACKETSIZE_SHIFT 0
  216. #define USB_MAXPACKETSIZE_MASK (0x7ff << USB_MAXPACKETSIZE_SHIFT)
  217. #define USB_MAXPACKETSIZE_ADDITIONAL_TRANSCATION_SHIFT 11
  218. #define USB_MAXPACKETSIZE_ADDITIONAL_TRANSCATION_NONE (0 << USB_MAXPACKETSIZE_ADDITIONAL_TRANSCATION_SHIFT)
  219. #define USB_MAXPACKETSIZE_ADDITIONAL_TRANSCATION_ONE (1 << USB_MAXPACKETSIZE_ADDITIONAL_TRANSCATION_SHIFT)
  220. #define USB_MAXPACKETSIZE_ADDITIONAL_TRANSCATION_TWO (2 << USB_MAXPACKETSIZE_ADDITIONAL_TRANSCATION_SHIFT)
  221. #define USB_MAXPACKETSIZE_ADDITIONAL_TRANSCATION_MASK (3 << USB_MAXPACKETSIZE_ADDITIONAL_TRANSCATION_SHIFT)
  222. #define USB_GET_MAXPACKETSIZE(x) ((x & USB_MAXPACKETSIZE_MASK) >> USB_MAXPACKETSIZE_SHIFT)
  223. #define USB_GET_MULT(x) ((x & USB_MAXPACKETSIZE_ADDITIONAL_TRANSCATION_MASK) >> USB_MAXPACKETSIZE_ADDITIONAL_TRANSCATION_SHIFT)
  224. /* bDevCapabilityType in Device Capability Descriptor */
  225. #define USB_DEVICE_CAPABILITY_WIRELESS_USB 1
  226. #define USB_DEVICE_CAPABILITY_USB_2_0_EXTENSION 2
  227. #define USB_DEVICE_CAPABILITY_SUPERSPEED_USB 3
  228. #define USB_DEVICE_CAPABILITY_CONTAINER_ID 4
  229. #define USB_DEVICE_CAPABILITY_PLATFORM 5
  230. #define USB_DEVICE_CAPABILITY_POWER_DELIVERY_CAPABILITY 6
  231. #define USB_DEVICE_CAPABILITY_BATTERY_INFO_CAPABILITY 7
  232. #define USB_DEVICE_CAPABILITY_PD_CONSUMER_PORT_CAPABILITY 8
  233. #define USB_DEVICE_CAPABILITY_PD_PROVIDER_PORT_CAPABILITY 9
  234. #define USB_DEVICE_CAPABILITY_SUPERSPEED_PLUS 10
  235. #define USB_DEVICE_CAPABILITY_PRECISION_TIME_MEASUREMENT 11
  236. #define USB_DEVICE_CAPABILITY_WIRELESS_USB_EXT 12
  237. #define USB_BOS_CAPABILITY_EXTENSION 0x02
  238. #define USB_BOS_CAPABILITY_PLATFORM 0x05
  239. /* OTG SET FEATURE Constants */
  240. #define USB_OTG_FEATURE_B_HNP_ENABLE 3 /* Enable B device to perform HNP */
  241. #define USB_OTG_FEATURE_A_HNP_SUPPORT 4 /* A device supports HNP */
  242. #define USB_OTG_FEATURE_A_ALT_HNP_SUPPORT 5 /* Another port on the A device supports HNP */
  243. /* WinUSB Microsoft OS 2.0 descriptor request codes */
  244. #define WINUSB_REQUEST_GET_DESCRIPTOR_SET 0x07
  245. #define WINUSB_REQUEST_SET_ALT_ENUM 0x08
  246. /* WinUSB Microsoft OS 2.0 descriptor sizes */
  247. #define WINUSB_DESCRIPTOR_SET_HEADER_SIZE 10
  248. #define WINUSB_FUNCTION_SUBSET_HEADER_SIZE 8
  249. #define WINUSB_FEATURE_COMPATIBLE_ID_SIZE 20
  250. /* WinUSB Microsoft OS 2.0 Descriptor Types */
  251. #define WINUSB_SET_HEADER_DESCRIPTOR_TYPE 0x00
  252. #define WINUSB_SUBSET_HEADER_CONFIGURATION_TYPE 0x01
  253. #define WINUSB_SUBSET_HEADER_FUNCTION_TYPE 0x02
  254. #define WINUSB_FEATURE_COMPATIBLE_ID_TYPE 0x03
  255. #define WINUSB_FEATURE_REG_PROPERTY_TYPE 0x04
  256. #define WINUSB_FEATURE_MIN_RESUME_TIME_TYPE 0x05
  257. #define WINUSB_FEATURE_MODEL_ID_TYPE 0x06
  258. #define WINUSB_FEATURE_CCGP_DEVICE_TYPE 0x07
  259. #define WINUSB_PROP_DATA_TYPE_REG_SZ 0x01
  260. #define WINUSB_PROP_DATA_TYPE_REG_MULTI_SZ 0x07
  261. /* WebUSB Descriptor Types */
  262. #define WEBUSB_DESCRIPTOR_SET_HEADER_TYPE 0x00
  263. #define WEBUSB_CONFIGURATION_SUBSET_HEADER_TYPE 0x01
  264. #define WEBUSB_FUNCTION_SUBSET_HEADER_TYPE 0x02
  265. #define WEBUSB_URL_TYPE 0x03
  266. /* WebUSB Request Codes */
  267. #define WEBUSB_REQUEST_GET_URL 0x02
  268. /* bScheme in URL descriptor */
  269. #define WEBUSB_URL_SCHEME_HTTP 0x00
  270. #define WEBUSB_URL_SCHEME_HTTPS 0x01
  271. /* WebUSB Descriptor sizes */
  272. #define WEBUSB_DESCRIPTOR_SET_HEADER_SIZE 5
  273. #define WEBUSB_CONFIGURATION_SUBSET_HEADER_SIZE 4
  274. #define WEBUSB_FUNCTION_SUBSET_HEADER_SIZE 3
  275. /* Setup packet definition used to read raw data from USB line */
  276. struct usb_setup_packet {
  277. /** Request type. Bits 0:4 determine recipient, see
  278. * \ref usb_request_recipient. Bits 5:6 determine type, see
  279. * \ref usb_request_type. Bit 7 determines data transfer direction, see
  280. * \ref usb_endpoint_direction.
  281. */
  282. uint8_t bmRequestType;
  283. /** Request. If the type bits of bmRequestType are equal to
  284. * \ref usb_request_type::LIBUSB_REQUEST_TYPE_STANDARD
  285. * "USB_REQUEST_TYPE_STANDARD" then this field refers to
  286. * \ref usb_standard_request. For other cases, use of this field is
  287. * application-specific. */
  288. uint8_t bRequest;
  289. /** Value. Varies according to request */
  290. uint16_t wValue;
  291. /** Index. Varies according to request, typically used to pass an index
  292. * or offset */
  293. uint16_t wIndex;
  294. /** Number of bytes to transfer */
  295. uint16_t wLength;
  296. } __PACKED;
  297. #define USB_SIZEOF_SETUP_PACKET 8
  298. /** Standard Device Descriptor */
  299. struct usb_device_descriptor {
  300. uint8_t bLength; /* Descriptor size in bytes = 18 */
  301. uint8_t bDescriptorType; /* DEVICE descriptor type = 1 */
  302. uint16_t bcdUSB; /* USB spec in BCD, e.g. 0x0200 */
  303. uint8_t bDeviceClass; /* Class code, if 0 see interface */
  304. uint8_t bDeviceSubClass; /* Sub-Class code, 0 if class = 0 */
  305. uint8_t bDeviceProtocol; /* Protocol, if 0 see interface */
  306. uint8_t bMaxPacketSize0; /* Endpoint 0 max. size */
  307. uint16_t idVendor; /* Vendor ID per USB-IF */
  308. uint16_t idProduct; /* Product ID per manufacturer */
  309. uint16_t bcdDevice; /* Device release # in BCD */
  310. uint8_t iManufacturer; /* Index to manufacturer string */
  311. uint8_t iProduct; /* Index to product string */
  312. uint8_t iSerialNumber; /* Index to serial number string */
  313. uint8_t bNumConfigurations; /* Number of possible configurations */
  314. } __PACKED;
  315. #define USB_SIZEOF_DEVICE_DESC 18
  316. /** Standard Configuration Descriptor */
  317. struct usb_configuration_descriptor {
  318. uint8_t bLength; /* Descriptor size in bytes = 9 */
  319. uint8_t bDescriptorType; /* CONFIGURATION type = 2 or 7 */
  320. uint16_t wTotalLength; /* Length of concatenated descriptors */
  321. uint8_t bNumInterfaces; /* Number of interfaces, this config. */
  322. uint8_t bConfigurationValue; /* Value to set this config. */
  323. uint8_t iConfiguration; /* Index to configuration string */
  324. uint8_t bmAttributes; /* Config. characteristics */
  325. uint8_t bMaxPower; /* Max.power from bus, 2mA units */
  326. } __PACKED;
  327. #define USB_SIZEOF_CONFIG_DESC 9
  328. /** Standard Interface Descriptor */
  329. struct usb_interface_descriptor {
  330. uint8_t bLength; /* Descriptor size in bytes = 9 */
  331. uint8_t bDescriptorType; /* INTERFACE descriptor type = 4 */
  332. uint8_t bInterfaceNumber; /* Interface no.*/
  333. uint8_t bAlternateSetting; /* Value to select this IF */
  334. uint8_t bNumEndpoints; /* Number of endpoints excluding 0 */
  335. uint8_t bInterfaceClass; /* Class code, 0xFF = vendor */
  336. uint8_t bInterfaceSubClass; /* Sub-Class code, 0 if class = 0 */
  337. uint8_t bInterfaceProtocol; /* Protocol, 0xFF = vendor */
  338. uint8_t iInterface; /* Index to interface string */
  339. } __PACKED;
  340. #define USB_SIZEOF_INTERFACE_DESC 9
  341. /** Standard Endpoint Descriptor */
  342. struct usb_endpoint_descriptor {
  343. uint8_t bLength; /* Descriptor size in bytes = 7 */
  344. uint8_t bDescriptorType; /* ENDPOINT descriptor type = 5 */
  345. uint8_t bEndpointAddress; /* Endpoint # 0 - 15 | IN/OUT */
  346. uint8_t bmAttributes; /* Transfer type */
  347. uint16_t wMaxPacketSize; /* Bits 10:0 = max. packet size */
  348. uint8_t bInterval; /* Polling interval in (micro) frames */
  349. } __PACKED;
  350. #define USB_SIZEOF_ENDPOINT_DESC 7
  351. /** Unicode (UTF16LE) String Descriptor */
  352. struct usb_string_descriptor {
  353. uint8_t bLength;
  354. uint8_t bDescriptorType;
  355. uint16_t bString;
  356. } __PACKED;
  357. #define USB_SIZEOF_STRING_LANGID_DESC 4
  358. /* USB Interface Association Descriptor */
  359. struct usb_interface_association_descriptor {
  360. uint8_t bLength;
  361. uint8_t bDescriptorType;
  362. uint8_t bFirstInterface;
  363. uint8_t bInterfaceCount;
  364. uint8_t bFunctionClass;
  365. uint8_t bFunctionSubClass;
  366. uint8_t bFunctionProtocol;
  367. uint8_t iFunction;
  368. } __PACKED;
  369. #define USB_SIZEOF_IAD_DESC 8
  370. /** USB device_qualifier descriptor */
  371. struct usb_device_qualifier_descriptor {
  372. uint8_t bLength; /* Descriptor size in bytes = 10 */
  373. uint8_t bDescriptorType; /* DEVICE QUALIFIER type = 6 */
  374. uint16_t bcdUSB; /* USB spec in BCD, e.g. 0x0200 */
  375. uint8_t bDeviceClass; /* Class code, if 0 see interface */
  376. uint8_t bDeviceSubClass; /* Sub-Class code, 0 if class = 0 */
  377. uint8_t bDeviceProtocol; /* Protocol, if 0 see interface */
  378. uint8_t bMaxPacketSize; /* Endpoint 0 max. size */
  379. uint8_t bNumConfigurations; /* Number of possible configurations */
  380. uint8_t bReserved; /* Reserved = 0 */
  381. } __PACKED;
  382. #define USB_SIZEOF_DEVICE_QUALIFIER_DESC 10
  383. /* Microsoft OS function descriptor.
  384. * This can be used to request a specific driver (such as WINUSB) to be
  385. * loaded on Windows. Unlike other descriptors, it is requested by a special
  386. * request USB_REQ_GETMSFTOSDESCRIPTOR.
  387. * More details:
  388. * https://msdn.microsoft.com/en-us/windows/hardware/gg463179
  389. * And excellent explanation:
  390. * https://github.com/pbatard/libwdi/wiki/WCID-Devices
  391. *
  392. * The device will have exactly one "Extended Compat ID Feature Descriptor",
  393. * which may contain multiple "Function Descriptors" associated with
  394. * different interfaces.
  395. */
  396. /* MS OS 1.0 string descriptor */
  397. struct usb_msosv1_string_descriptor {
  398. uint8_t bLength;
  399. uint8_t bDescriptorType;
  400. uint8_t bString[14];
  401. uint8_t bMS_VendorCode; /* Vendor Code, used for a control request */
  402. uint8_t bPad; /* Padding byte for VendorCode look as UTF16 */
  403. } __PACKED;
  404. /* MS OS 1.0 Header descriptor */
  405. struct usb_msosv1_compat_id_header_descriptor {
  406. uint32_t dwLength;
  407. uint16_t bcdVersion;
  408. uint16_t wIndex;
  409. uint8_t bCount;
  410. uint8_t reserved[7];
  411. } __PACKED;
  412. /* MS OS 1.0 Function descriptor */
  413. struct usb_msosv1_comp_id_function_descriptor {
  414. uint8_t bFirstInterfaceNumber;
  415. uint8_t reserved1;
  416. uint8_t compatibleID[8];
  417. uint8_t subCompatibleID[8];
  418. uint8_t reserved2[6];
  419. } __PACKED;
  420. #define usb_msosv1_comp_id_create(x) \
  421. struct usb_msosv1_comp_id { \
  422. struct usb_msosv1_compat_id_header_descriptor compat_id_header; \
  423. struct usb_msosv1_comp_id_function_descriptor compat_id_function[x]; \
  424. };
  425. struct usb_msosv1_descriptor {
  426. const uint8_t *string;
  427. uint8_t vendor_code;
  428. const uint8_t *compat_id;
  429. const uint8_t **comp_id_property;
  430. };
  431. /* MS OS 2.0 Header descriptor */
  432. struct usb_msosv2_header_descriptor {
  433. uint32_t dwLength;
  434. uint16_t bcdVersion;
  435. uint16_t wIndex;
  436. uint8_t bCount;
  437. } __PACKED;
  438. /*Microsoft OS 2.0 set header descriptor*/
  439. struct usb_msosv2_set_header_descriptor {
  440. uint16_t wLength;
  441. uint16_t wDescriptorType;
  442. uint32_t dwWindowsVersion;
  443. uint16_t wDescriptorSetTotalLength;
  444. } __PACKED;
  445. /* Microsoft OS 2.0 compatibleID descriptor*/
  446. struct usb_msosv2_comp_id_descriptor {
  447. uint16_t wLength;
  448. uint16_t wDescriptorType;
  449. uint8_t compatibleID[8];
  450. uint8_t subCompatibleID[8];
  451. } __PACKED;
  452. /* MS OS 2.0 property descriptor */
  453. struct usb_msosv2_property_descriptor {
  454. uint16_t wLength;
  455. uint16_t wDescriptorType;
  456. uint32_t dwPropertyDataType;
  457. uint16_t wPropertyNameLength;
  458. const char *bPropertyName;
  459. uint32_t dwPropertyDataLength;
  460. const char *bPropertyData;
  461. };
  462. /* Microsoft OS 2.0 subset function descriptor */
  463. struct usb_msosv2_subset_function_descriptor {
  464. uint16_t wLength;
  465. uint16_t wDescriptorType;
  466. uint8_t bFirstInterface;
  467. uint8_t bReserved;
  468. uint16_t wSubsetLength;
  469. } __PACKED;
  470. struct usb_msosv2_descriptor {
  471. const uint8_t *compat_id;
  472. uint16_t compat_id_len;
  473. uint8_t vendor_code;
  474. };
  475. /* BOS header Descriptor */
  476. struct usb_bos_header_descriptor {
  477. uint8_t bLength;
  478. uint8_t bDescriptorType;
  479. uint16_t wTotalLength;
  480. uint8_t bNumDeviceCaps;
  481. } __PACKED;
  482. /* BOS Capability platform Descriptor */
  483. struct usb_bos_capability_platform_common_descriptor {
  484. uint8_t bLength;
  485. uint8_t bDescriptorType;
  486. uint8_t bDevCapabilityType;
  487. uint8_t bReserved;
  488. uint8_t PlatformCapabilityUUID[16];
  489. } __PACKED;
  490. /* Microsoft OS 2.0 Platform Capability Descriptor
  491. * See https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/
  492. * microsoft-defined-usb-descriptors
  493. * Adapted from the source:
  494. * https://github.com/sowbug/weblight/blob/master/firmware/webusb.c
  495. * (BSD-2) Thanks http://janaxelson.com/files/ms_os_20_descriptors.c
  496. */
  497. struct usb_bos_capability_platform_winusb_descriptor {
  498. struct usb_bos_capability_platform_common_descriptor common;
  499. uint32_t dwWindowsVersion;
  500. uint16_t wMSOSDescriptorSetTotalLength;
  501. uint8_t bVendorCode;
  502. uint8_t bAltEnumCode;
  503. } __PACKED;
  504. /* WebUSB Platform Capability Descriptor:
  505. * https://wicg.github.io/webusb/#webusb-platform-capability-descriptor
  506. */
  507. struct usb_bos_capability_platform_webusb_descriptor {
  508. struct usb_bos_capability_platform_common_descriptor common;
  509. uint16_t bcdVersion;
  510. uint8_t bVendorCode;
  511. uint8_t iLandingPage;
  512. } __PACKED;
  513. /* BOS Capability extension Descriptor*/
  514. struct usb_bos_capability_extension_descriptor {
  515. uint8_t bLength;
  516. uint8_t bDescriptorType;
  517. uint8_t bDevCapabilityType;
  518. uint32_t bmAttributes;
  519. } __PACKED;
  520. struct usb_webusb_url_descriptor {
  521. uint8_t bLength;
  522. uint8_t bDescriptorType;
  523. uint8_t bScheme;
  524. char URL[];
  525. } __PACKED;
  526. struct usb_webusb_descriptor {
  527. uint8_t vendor_code;
  528. const uint8_t *string;
  529. uint32_t string_len;
  530. } __PACKED;
  531. struct usb_bos_descriptor {
  532. const uint8_t *string;
  533. uint32_t string_len;
  534. };
  535. /** USB descriptor header */
  536. struct usb_desc_header {
  537. uint8_t bLength; /**< descriptor length */
  538. uint8_t bDescriptorType; /**< descriptor type */
  539. };
  540. // clang-format off
  541. #define USB_DEVICE_DESCRIPTOR_INIT(bcdUSB, bDeviceClass, bDeviceSubClass, bDeviceProtocol, idVendor, idProduct, bcdDevice, bNumConfigurations) \
  542. 0x12, /* bLength */ \
  543. USB_DESCRIPTOR_TYPE_DEVICE, /* bDescriptorType */ \
  544. WBVAL(bcdUSB), /* bcdUSB */ \
  545. bDeviceClass, /* bDeviceClass */ \
  546. bDeviceSubClass, /* bDeviceSubClass */ \
  547. bDeviceProtocol, /* bDeviceProtocol */ \
  548. 0x40, /* bMaxPacketSize */ \
  549. WBVAL(idVendor), /* idVendor */ \
  550. WBVAL(idProduct), /* idProduct */ \
  551. WBVAL(bcdDevice), /* bcdDevice */ \
  552. USB_STRING_MFC_INDEX, /* iManufacturer */ \
  553. USB_STRING_PRODUCT_INDEX, /* iProduct */ \
  554. USB_STRING_SERIAL_INDEX, /* iSerial */ \
  555. bNumConfigurations /* bNumConfigurations */
  556. #define USB_CONFIG_DESCRIPTOR_INIT(wTotalLength, bNumInterfaces, bConfigurationValue, bmAttributes, bMaxPower) \
  557. 0x09, /* bLength */ \
  558. USB_DESCRIPTOR_TYPE_CONFIGURATION, /* bDescriptorType */ \
  559. WBVAL(wTotalLength), /* wTotalLength */ \
  560. bNumInterfaces, /* bNumInterfaces */ \
  561. bConfigurationValue, /* bConfigurationValue */ \
  562. 0x00, /* iConfiguration */ \
  563. bmAttributes, /* bmAttributes */ \
  564. USB_CONFIG_POWER_MA(bMaxPower) /* bMaxPower */
  565. #define USB_DEVICE_QUALIFIER_DESCRIPTOR_INIT(bcdUSB, bDeviceClass, bDeviceSubClass, bDeviceProtocol, bNumConfigurations) \
  566. 0x0A, /* bLength */ \
  567. USB_DESCRIPTOR_TYPE_DEVICE_QUALIFIER, /* bDescriptorType */ \
  568. WBVAL(bcdUSB), /* bcdUSB */ \
  569. bDeviceClass, /* bDeviceClass */ \
  570. bDeviceSubClass, /* bDeviceSubClass */ \
  571. bDeviceProtocol, /* bDeviceProtocol */ \
  572. 0x40, /* bMaxPacketSize */ \
  573. bNumConfigurations, /* bNumConfigurations */ \
  574. 0x00 /* bReserved */
  575. #define USB_OTHER_SPEED_CONFIG_DESCRIPTOR_INIT(wTotalLength, bNumInterfaces, bConfigurationValue, bmAttributes, bMaxPower) \
  576. 0x09, /* bLength */ \
  577. USB_DESCRIPTOR_TYPE_OTHER_SPEED, /* bDescriptorType */ \
  578. WBVAL(wTotalLength), /* wTotalLength */ \
  579. bNumInterfaces, /* bNumInterfaces */ \
  580. bConfigurationValue, /* bConfigurationValue */ \
  581. 0x00, /* iConfiguration */ \
  582. bmAttributes, /* bmAttributes */ \
  583. USB_CONFIG_POWER_MA(bMaxPower) /* bMaxPower */
  584. #define USB_INTERFACE_DESCRIPTOR_INIT(bInterfaceNumber, bAlternateSetting, bNumEndpoints, \
  585. bInterfaceClass, bInterfaceSubClass, bInterfaceProtocol, iInterface) \
  586. 0x09, /* bLength */ \
  587. USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType */ \
  588. bInterfaceNumber, /* bInterfaceNumber */ \
  589. bAlternateSetting, /* bAlternateSetting */ \
  590. bNumEndpoints, /* bNumEndpoints */ \
  591. bInterfaceClass, /* bInterfaceClass */ \
  592. bInterfaceSubClass, /* bInterfaceSubClass */ \
  593. bInterfaceProtocol, /* bInterfaceProtocol */ \
  594. iInterface /* iInterface */
  595. #define USB_ENDPOINT_DESCRIPTOR_INIT(bEndpointAddress, bmAttributes, wMaxPacketSize, bInterval) \
  596. 0x07, /* bLength */ \
  597. USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType */ \
  598. bEndpointAddress, /* bEndpointAddress */ \
  599. bmAttributes, /* bmAttributes */ \
  600. WBVAL(wMaxPacketSize), /* wMaxPacketSize */ \
  601. bInterval /* bInterval */
  602. #define USB_IAD_DESCRIPTOR_INIT(bFirstInterface, bInterfaceCount, bFunctionClass, bFunctionSubClass, bFunctionProtocol) \
  603. 0x08, /* bLength */ \
  604. USB_DESCRIPTOR_TYPE_INTERFACE_ASSOCIATION, /* bDescriptorType */ \
  605. bFirstInterface, /* bFirstInterface */ \
  606. bInterfaceCount, /* bInterfaceCount */ \
  607. bFunctionClass, /* bFunctionClass */ \
  608. bFunctionSubClass, /* bFunctionSubClass */ \
  609. bFunctionProtocol, /* bFunctionProtocol */ \
  610. 0x00 /* iFunction */
  611. #define USB_LANGID_INIT(id) \
  612. 0x04, /* bLength */ \
  613. USB_DESCRIPTOR_TYPE_STRING, /* bDescriptorType */ \
  614. WBVAL(id) /* wLangID0 */
  615. #define USB_BOS_HEADER_DESCRIPTOR_INIT(wTotalLength, bNumDeviceCaps) \
  616. 0x05, /* bLength */ \
  617. USB_DESCRIPTOR_TYPE_BINARY_OBJECT_STORE, /* bDescriptorType */\
  618. WBVAL(wTotalLength), /* wTotalLength */ \
  619. bNumDeviceCaps /* bNumDeviceCaps */
  620. #define USB_BOS_CAP_PLATFORM_WEBUSB_DESCRIPTOR_INIT(bVendorCode, iLandingPage) \
  621. 0x18, /* bLength */ \
  622. USB_DESCRIPTOR_TYPE_DEVICE_CAPABILITY, /* bDescriptorType */ \
  623. USB_DEVICE_CAPABILITY_PLATFORM, /* bDevCapabilityType */ \
  624. 0x00, /* bReserved */ \
  625. 0x38, 0xB6, 0x08, 0x34, 0xA9, 0x09, 0xA0, 0x47, /* PlatformCapabilityUUID */ \
  626. 0x8B, 0xFD, 0xA0, 0x76, 0x88, 0x15, 0xB6, 0x65, \
  627. WBVAL(0x0100), /* bcdVersion */ \
  628. bVendorCode, /* bVendorCode */ \
  629. iLandingPage /* iLandingPage */
  630. #define USB_BOS_CAP_PLATFORM_WINUSB_DESCRIPTOR_INIT(bVendorCode, wMSOSDescriptorSetTotalLength) \
  631. 0x1C, /* bLength */ \
  632. USB_DESCRIPTOR_TYPE_DEVICE_CAPABILITY, /* bDescriptorType */ \
  633. USB_DEVICE_CAPABILITY_PLATFORM, /* bDevCapabilityType */ \
  634. 0x00, /* bReserved */ \
  635. 0xDF, 0x60, 0xDD, 0xD8, 0x89, 0x45, 0xC7, 0x4C, /* PlatformCapabilityUUID */ \
  636. 0x9C, 0xD2, 0x65, 0x9D, 0x9E, 0x64, 0x8A, 0x9F, \
  637. DBVAL(0x06030000), /* dwWindowsVersion */ \
  638. WBVAL(wMSOSDescriptorSetTotalLength), /* wMSOSDescriptorSetTotalLength */ \
  639. bVendorCode, /* bVendorCode */ \
  640. 0x00 /* bAltEnumCode */
  641. #define USB_BOS_CAP_PLATFORM_WEBUSB_DESCRIPTOR_LEN 24
  642. #define USB_BOS_CAP_PLATFORM_WINUSB_DESCRIPTOR_LEN 28
  643. #define USB_MSOSV1_STRING_DESCRIPTOR_INIT(vendor_code) \
  644. 0x12, /* bLength */ \
  645. USB_DESCRIPTOR_TYPE_STRING, /* bDescriptorType */ \
  646. 'M', 0, /* bString[0] */ \
  647. 'S', 0, /* bString[1] */ \
  648. 'F', 0, /* bString[2] */ \
  649. 'T', 0, /* bString[3] */ \
  650. '1', 0, /* bString[4] */ \
  651. '0', 0, /* bString[5] */ \
  652. '0', 0, /* bString[6] */ \
  653. vendor_code, /* bMS_VendorCode */ \
  654. 0x00 /* bPad */
  655. #define USB_MSOSV1_COMP_ID_HEADER_DESCRIPTOR_INIT(bCount) \
  656. DBVAL((sizeof(struct usb_msosv1_compat_id_header_descriptor) + sizeof(struct usb_msosv1_comp_id_function_descriptor) * bCount)), /* dwLength */ \
  657. WBVAL(0x0100), /* bcdVersion */ \
  658. WBVAL(0x0004), /* wIndex */ \
  659. bCount, /* bCount */ \
  660. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* reserved[7] */
  661. #define USB_MSOSV1_COMP_ID_FUNCTION_WINUSB_DESCRIPTOR_INIT(bFirstInterfaceNumber) \
  662. bFirstInterfaceNumber, /* bFirstInterfaceNumber */\
  663. 0x01, /* reserved1 */ \
  664. 'W', 'I', 'N', 'U', 'S', 'B', 0x00, 0x00, /* compatibleID[8] */ \
  665. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* subCompatibleID[8] */ \
  666. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* reserved2[6] */
  667. #define USB_MSOSV1_COMP_ID_FUNCTION_MTP_DESCRIPTOR_INIT(bFirstInterfaceNumber)\
  668. bFirstInterfaceNumber, /* bFirstInterfaceNumber */\
  669. 0x01, /* reserved1 */ \
  670. 'M', 'T', 'P', 'U', 'S', 'B', 0x00, 0x00, /* compatibleID[8] */ \
  671. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* subCompatibleID[8] */ \
  672. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* reserved2[6] */
  673. #define USB_MSOSV1_COMP_ID_FUNCTION_ADB_DESCRIPTOR_INIT(bFirstInterfaceNumber)\
  674. bFirstInterfaceNumber, * bFirstInterfaceNumber */\
  675. 0x01, /* reserved1 */ \
  676. 'A', 'D', 'B', 0x00, 0x00, 0x00, 0x00, 0x00, /* compatibleID[8] */ \
  677. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* subCompatibleID[8] */ \
  678. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* reserved2[6] */
  679. #define USB_MSOSV1_COMP_ID_DESCRIPTOR_LEN(bCount) \
  680. (sizeof(struct usb_msosv1_compat_id_header_descriptor) + sizeof(struct usb_msosv1_comp_id_function_descriptor) * (bCount))
  681. #define USB_MSOSV2_COMP_ID_SET_HEADER_DESCRIPTOR_INIT(wDescriptorSetTotalLength) \
  682. WBVAL(WINUSB_DESCRIPTOR_SET_HEADER_SIZE), /* wLength */ \
  683. WBVAL(WINUSB_SET_HEADER_DESCRIPTOR_TYPE), /* wDescriptorType */ \
  684. DBVAL(0x06030000), /* dwWindowsVersion */ \
  685. WBVAL(wDescriptorSetTotalLength) /* wDescriptorSetTotalLength */
  686. #define USB_MSOSV2_COMP_ID_FUNCTION_WINUSB_SINGLE_DESCRIPTOR_INIT() \
  687. WBVAL(WINUSB_FEATURE_COMPATIBLE_ID_SIZE), /* wLength */ \
  688. WBVAL(WINUSB_FEATURE_COMPATIBLE_ID_TYPE), /* wDescriptorType */ \
  689. 'W', 'I', 'N', 'U', 'S', 'B', 0, 0, /* CompatibleId*/ \
  690. 0, 0, 0, 0, 0, 0, 0, 0, /* SubCompatibleId*/ \
  691. WBVAL(132), /* wLength */ \
  692. WBVAL(WINUSB_FEATURE_REG_PROPERTY_TYPE), /* wDescriptorType */ \
  693. WBVAL(WINUSB_PROP_DATA_TYPE_REG_SZ), /* wPropertyDataType */ \
  694. WBVAL(42), /* wPropertyNameLength bPropertyName: "DeviceInterfaceGUID" */ \
  695. 'D', 0, 'e', 0, 'v', 0, 'i', 0, 'c', 0, 'e', 0, \
  696. 'I', 0, 'n', 0, 't', 0, 'e', 0, 'r', 0, 'f', 0, 'a', 0, 'c', 0, 'e', 0, \
  697. 'G', 0, 'U', 0, 'I', 0, 'D', 0, 's', 0, 0, 0, \
  698. WBVAL(80), /* wPropertyDataLength */ \
  699. '{', 0, \
  700. 'C', 0, 'D', 0, 'B', 0, '3', 0, 'B', 0, '5', 0, 'A', 0, 'D', 0, '-', 0, \
  701. '2', 0, '9', 0, '3', 0, 'B', 0, '-', 0, \
  702. '4', 0, '6', 0, '6', 0, '3', 0, '-', 0, \
  703. 'A', 0, 'A', 0, '3', 0, '6', 0, '-', \
  704. 0, '1', 0, 'A', 0, 'A', 0, 'E', 0, '4', 0, '6', 0, '4', 0, '6', 0, '3', 0, '7', 0, '7', 0, '6', 0, \
  705. '}', 0, 0, 0, 0, 0
  706. #define USB_MSOSV2_COMP_ID_FUNCTION_WINUSB_SINGLE_DESCRIPTOR_LEN \
  707. (WINUSB_FEATURE_COMPATIBLE_ID_SIZE + 132)
  708. #define USB_MSOSV2_COMP_ID_FUNCTION_WINUSB_MULTI_DESCRIPTOR_INIT(bFirstInterfaceNumber) \
  709. WBVAL(WINUSB_FUNCTION_SUBSET_HEADER_SIZE), /* wLength */ \
  710. WBVAL(WINUSB_SUBSET_HEADER_FUNCTION_TYPE), /* wDescriptorType */ \
  711. bFirstInterfaceNumber, /* bFirstInterface*/ \
  712. 0, /* bReserved */ \
  713. WBVAL((WINUSB_FUNCTION_SUBSET_HEADER_SIZE + WINUSB_FEATURE_COMPATIBLE_ID_SIZE + 132)), /* wSubsetLength */\
  714. WBVAL(WINUSB_FEATURE_COMPATIBLE_ID_SIZE), /* wLength */ \
  715. WBVAL(WINUSB_FEATURE_COMPATIBLE_ID_TYPE), /* wDescriptorType */ \
  716. 'W', 'I', 'N', 'U', 'S', 'B', 0, 0, /* CompatibleId*/ \
  717. 0, 0, 0, 0, 0, 0, 0, 0, /* SubCompatibleId*/ \
  718. WBVAL(132), /* wLength */ \
  719. WBVAL(WINUSB_FEATURE_REG_PROPERTY_TYPE), /* wDescriptorType */ \
  720. WBVAL(WINUSB_PROP_DATA_TYPE_REG_MULTI_SZ), /* wPropertyDataType */ \
  721. WBVAL(42), /* wPropertyNameLength bPropertyName: "DeviceInterfaceGUID" */ \
  722. 'D', 0, 'e', 0, 'v', 0, 'i', 0, 'c', 0, 'e', 0, \
  723. 'I', 0, 'n', 0, 't', 0, 'e', 0, 'r', 0, 'f', 0, 'a', 0, 'c', 0, 'e', 0, \
  724. 'G', 0, 'U', 0, 'I', 0, 'D', 0, 's', 0, 0, 0, \
  725. WBVAL(80), /* wPropertyDataLength */ \
  726. '{', 0, \
  727. 'C', 0, 'D', 0, 'B', 0, '3', 0, 'B', 0, '5', 0, 'A', 0, 'D', 0, '-', 0, \
  728. '2', 0, '9', 0, '3', 0, 'B', 0, '-', 0, \
  729. '4', 0, '6', 0, '6', 0, '3', 0, '-', 0, \
  730. 'A', 0, 'A', 0, '3', 0, '6', 0, '-', \
  731. 0, '1', 0, 'A', 0, 'A', 0, 'E', 0, '4', 0, '6', 0, '4', 0, '6', 0, '3', 0, '7', 0, '7', 0, '6', 0, \
  732. '}', 0, 0, 0, 0, 0
  733. #define USB_MSOSV2_COMP_ID_FUNCTION_WINUSB_MULTI_DESCRIPTOR_LEN \
  734. (WINUSB_FUNCTION_SUBSET_HEADER_SIZE + WINUSB_FEATURE_COMPATIBLE_ID_SIZE + 132)
  735. // clang-format on
  736. #endif /* USB_DEF_H */