usb_winusb.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. // SPDX-License-Identifier: BSD-3-Clause
  2. // Copyright (c) 2022, Alex Taradov <alex@taradov.com>. All rights reserved.
  3. #ifndef _USB_WINUSB_H_
  4. #define _USB_WINUSB_H_
  5. // WinUSB device information is stored in the Windows registry at:
  6. // HKEY_LOCAL_MACHINE\System\CurrentControlSet\Enum\USB\<Device>\<Instance>\Device Parameters
  7. /*- Includes ----------------------------------------------------------------*/
  8. #include "usb_std.h"
  9. /*- Definitions -------------------------------------------------------------*/
  10. #define USB_WINUSB_VENDOR_CODE 0x20
  11. #define USB_WINUSB_WINDOWS_VERSION 0x06030000 // Windows 8.1
  12. #define USB_WINUSB_PLATFORM_CAPABILITY_ID \
  13. { 0xdf, 0x60, 0xdd, 0xd8, 0x89, 0x45, 0xc7, 0x4c, \
  14. 0x9c, 0xd2, 0x65, 0x9d, 0x9e, 0x64, 0x8a, 0x9f }
  15. enum // WinUSB Microsoft OS 2.0 descriptor request codes
  16. {
  17. USB_WINUSB_DESCRIPTOR_INDEX = 0x07,
  18. USB_WINUSB_SET_ALT_ENUMERATION = 0x08,
  19. };
  20. enum // wDescriptorType
  21. {
  22. USB_WINUSB_SET_HEADER_DESCRIPTOR = 0x00,
  23. USB_WINUSB_SUBSET_HEADER_CONFIGURATION = 0x01,
  24. USB_WINUSB_SUBSET_HEADER_FUNCTION = 0x02,
  25. USB_WINUSB_FEATURE_COMPATBLE_ID = 0x03,
  26. USB_WINUSB_FEATURE_REG_PROPERTY = 0x04,
  27. USB_WINUSB_FEATURE_MIN_RESUME_TIME = 0x05,
  28. USB_WINUSB_FEATURE_MODEL_ID = 0x06,
  29. USB_WINUSB_FEATURE_CCGP_DEVICE = 0x07,
  30. USB_WINUSB_FEATURE_VENDOR_REVISION = 0x08,
  31. };
  32. enum // wPropertyDataType
  33. {
  34. USB_WINUSB_PROPERTY_DATA_TYPE_SZ = 1,
  35. USB_WINUSB_PROPERTY_DATA_TYPE_EXPAND_SZ = 2,
  36. USB_WINUSB_PROPERTY_DATA_TYPE_BINARY = 3,
  37. USB_WINUSB_PROPERTY_DATA_TYPE_DWORD_LITTLE_ENDIAN = 4,
  38. USB_WINUSB_PROPERTY_DATA_TYPE_DWORD_BIG_ENDIAN = 5,
  39. USB_WINUSB_PROPERTY_DATA_TYPE_LINK = 6,
  40. USB_WINUSB_PROPERTY_DATA_TYPE_MULTI_SZ = 7,
  41. };
  42. /*- Types -------------------------------------------------------------------*/
  43. typedef struct USB_PACK
  44. {
  45. uint8_t bLength;
  46. uint8_t bDescriptorType;
  47. uint8_t bDevCapabilityType;
  48. uint8_t bReserved;
  49. uint8_t PlatformCapabilityUUID[16];
  50. uint32_t dwWindowsVersion;
  51. uint16_t wMSOSDescriptorSetTotalLength;
  52. uint8_t bMS_VendorCode;
  53. uint8_t bAltEnumCode;
  54. } usb_winusb_capability_descriptor_t;
  55. typedef struct USB_PACK
  56. {
  57. uint16_t wLength;
  58. uint16_t wDescriptorType;
  59. uint32_t dwWindowsVersion;
  60. uint16_t wDescriptorSetTotalLength;
  61. } usb_winusb_set_header_descriptor_t;
  62. typedef struct USB_PACK
  63. {
  64. uint16_t wLength;
  65. uint16_t wDescriptorType;
  66. uint8_t bConfigurationValue;
  67. uint8_t bReserved;
  68. uint16_t wTotalLength;
  69. } usb_winusb_subset_header_configuration_t;
  70. typedef struct USB_PACK
  71. {
  72. uint16_t wLength;
  73. uint16_t wDescriptorType;
  74. uint8_t bFirstInterface;
  75. uint8_t bReserved;
  76. uint16_t wSubsetLength;
  77. } usb_winusb_subset_header_function_t;
  78. typedef struct USB_PACK
  79. {
  80. uint16_t wLength;
  81. uint16_t wDescriptorType;
  82. uint8_t CompatibleID[8];
  83. uint8_t SubCompatibleID[8];
  84. } usb_winusb_feature_compatble_id_t;
  85. typedef struct USB_PACK
  86. {
  87. uint16_t wLength;
  88. uint16_t wDescriptorType;
  89. uint16_t wPropertyDataType;
  90. //uint16_t wPropertyNameLength;
  91. //uint8_t PropertyName[...];
  92. //uint16_t wPropertyDataLength
  93. //uint8_t PropertyData[...];
  94. } usb_winusb_feature_reg_property_t;
  95. typedef struct USB_PACK
  96. {
  97. uint16_t wLength;
  98. uint16_t wDescriptorType;
  99. uint16_t wPropertyDataType;
  100. uint16_t wPropertyNameLength;
  101. uint8_t PropertyName[42];
  102. uint16_t wPropertyDataLength;
  103. uint8_t PropertyData[80];
  104. } usb_winusb_feature_reg_property_guids_t;
  105. typedef struct USB_PACK
  106. {
  107. uint16_t wLength;
  108. uint16_t wDescriptorType;
  109. uint8_t bResumeRecoveryTime;
  110. uint8_t bResumeSignalingTime;
  111. } usb_winusb_feature_min_resume_time_t;
  112. typedef struct USB_PACK
  113. {
  114. uint16_t wLength;
  115. uint16_t wDescriptorType;
  116. uint8_t ModelID[16];
  117. } usb_winusb_feature_model_id_t;
  118. typedef struct USB_PACK
  119. {
  120. uint16_t wLength;
  121. uint16_t wDescriptorType;
  122. } usb_winusb_feature_ccgp_device_t;
  123. typedef struct USB_PACK
  124. {
  125. uint16_t wLength;
  126. uint16_t wDescriptorType;
  127. uint16_t VendorRevision;
  128. } usb_winusb_feature_vendor_revision_t;
  129. /*- Prototypes --------------------------------------------------------------*/
  130. bool usb_winusb_handle_request(usb_request_t *request);
  131. #endif // _USB_WINUSB_H_