webusb_template.c 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Copyright (c) 2024, sakumisu
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include "usbd_core.h"
  7. #define MS_OS_20_DESCRIPTOR_LENGTH (0xB2)
  8. #define WEBUSB_URL_STRINGS \
  9. 'd', 'e', 'v', 'a', 'n', 'l', 'a', 'i', '.', 'g', 'i', 't', 'h', 'u', 'b', '.', 'i', 'o', '/', 'w', 'e', 'b', 'd', 'f', 'u', '/', 'd', 'f', 'u', '-', 'u', 't', 'i', 'l'
  10. #define WL_REQUEST_WEBUSB (0x22)
  11. #define WL_REQUEST_WINUSB (0x21)
  12. #define URL_DESCRIPTOR_LENGTH 0x2C
  13. // 描述符集信息
  14. const uint8_t MS_OS_20_DESCRIPTOR_SET[MS_OS_20_DESCRIPTOR_LENGTH] = {
  15. // Microsoft OS 2.0 描述符集标头
  16. 0x0A, 0x00, // Descriptor size (10 bytes)
  17. 0x00, 0x00, // MS OS 2.0 descriptor set header
  18. 0x00, 0x00, 0x03, 0x06, // Windows version (8.1) (0x06030000)
  19. MS_OS_20_DESCRIPTOR_LENGTH, 0x00, // Size, MS OS 2.0 descriptor set
  20. // Microsoft OS 2.0 配置子集标头
  21. 0x08, 0x00, // wLength
  22. 0x01, 0x00, // wDescriptorType
  23. 0x00, // 适用于配置 1
  24. 0x00, // bReserved
  25. 0XA8, 0X00, // Size, MS OS 2.0 configuration subset
  26. // Microsoft OS 2.0 功能子集头
  27. 0x08, 0x00, // Descriptor size (8 bytes)
  28. 0x02, 0x00, // MS OS 2.0 function subset header
  29. 0x01, // 第2个接口
  30. 0x00, // 必须设置为 0
  31. 0xA0, 0x00,
  32. // Microsoft OS 2.0 兼容 ID 描述符
  33. // 兼容 ID 描述符告诉 Windows 此设备与 WinUSB 驱动程序兼容
  34. 0x14, 0x00, // wLength 20
  35. 0x03, 0x00, // MS_OS_20_FEATURE_COMPATIBLE_ID
  36. 'W', 'I', 'N', 'U', 'S', 'B', 0x00, 0x00,
  37. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  38. // Microsoft OS 2.0 注册表属性描述符
  39. // 注册表属性分配设备接口 GUID
  40. 0x84, 0x00, //wLength: 132
  41. 0x04, 0x00, // wDescriptorType: MS_OS_20_FEATURE_REG_PROPERTY: 0x04 (Table 9)
  42. 0x07, 0x00, //wPropertyDataType: REG_MULTI_SZ (Table 15)
  43. 0x2a, 0x00, //wPropertyNameLength:
  44. //bPropertyName: “DeviceInterfaceGUID”
  45. 'D', 0x00, 'e', 0x00, 'v', 0x00, 'i', 0x00, 'c', 0x00, 'e', 0x00, 'I', 0x00, 'n', 0x00, 't', 0x00, 'e', 0x00,
  46. 'r', 0x00, 'f', 0x00, 'a', 0x00, 'c', 0x00, 'e', 0x00, 'G', 0x00, 'U', 0x00, 'I', 0x00, 'D', 0x00, 's', 0x00,
  47. 0x00, 0x00,
  48. 0x50, 0x00, // wPropertyDataLength
  49. //bPropertyData: “{975F44D9-0D08-43FD-8B3E-127CA8AFFF9D}”.
  50. '{', 0x00, '9', 0x00, 'd', 0x00, '7', 0x00, 'd', 0x00, 'e', 0x00, 'b', 0x00, 'b', 0x00, 'c', 0x00, '-', 0x00,
  51. 'c', 0x00, '8', 0x00, '5', 0x00, 'd', 0x00, '-', 0x00, '1', 0x00, '1', 0x00, 'd', 0x00, '1', 0x00, '-', 0x00,
  52. '9', 0x00, 'e', 0x00, 'b', 0x00, '4', 0x00, '-', 0x00, '0', 0x00, '0', 0x00, '6', 0x00, '0', 0x00, '0', 0x00,
  53. '8', 0x00, 'c', 0x00, '3', 0x00, 'a', 0x00, '1', 0x00, '9', 0x00, 'a', 0x00, '}', 0x00, 0x00, 0x00, 0x00, 0x00
  54. };
  55. const uint8_t USBD_WebUSBURLDescriptor[URL_DESCRIPTOR_LENGTH] = {
  56. URL_DESCRIPTOR_LENGTH,
  57. WEBUSB_URL_TYPE,
  58. WEBUSB_URL_SCHEME_HTTPS,
  59. WEBUSB_URL_STRINGS
  60. };
  61. struct usb_webusb_url_ex_descriptor webusb_url_desc = {
  62. .vendor_code = WL_REQUEST_WEBUSB,
  63. .string = MS_OS_20_DESCRIPTOR_SET,
  64. .string_len = MS_OS_20_DESCRIPTOR_LENGTH
  65. };