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