Skip to content

Commit f28c0f3

Browse files
committed
add microsoft os descriptors
1 parent 4e6214c commit f28c0f3

File tree

2 files changed

+58
-3
lines changed

2 files changed

+58
-3
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ First let's install a few dependencies.
6666
- Install [Visual Studio C++](https://visualstudio.microsoft.com/vs/features/cplusplus/) for its C++ compiler.
6767
- Use [winget](https://docs.microsoft.com/en-us/windows/package-manager/winget/) to install [git](https://winget.run/pkg/Git/Git) and [CMake](https://winget.run/pkg/Kitware/CMake).
6868
- Use [vcpkg](https://github.com/microsoft/vcpkg) to install `libusb`, `gRPC`, `OpenSSL`, and `getopt`.
69-
- From Device Manager, associate the "WinUsb Device" driver (under "Universal Serial Bus devices") with any `JABI USB` devices.
7069

7170
We use CMake for our build system which has the following standard build process.
7271

firmware/src/interfaces/usb.c

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ LOG_MODULE_REGISTER(iface_usb, CONFIG_LOG_DEFAULT_LEVEL);
1010

1111
/* USB configuration */
1212
#define JABI_IF_STR "JABI USB" // host will search for this
13+
#define JABI_VENDOR_CODE (0x69)
1314

1415
USBD_CLASS_DESCR_DEFINE(primary, 0) struct {
1516
struct usb_if_descriptor if0;
@@ -73,15 +74,70 @@ static void usb_jabi_interface_config(struct usb_desc_header *head,
7374
usb_if_desc.if0.iInterface = usb_get_str_descriptor_idx(&usb_str_desc);
7475
}
7576

77+
static int custom_handler(struct usb_setup_packet *setup, int32_t *len, uint8_t **data) {
78+
// from https://github.com/pbatard/libwdi/wiki/WCID-Devices
79+
static uint8_t msos1_str_desc[] = {
80+
0x12, // 18 byte length
81+
0x03, // string type
82+
0x4D, 0x00, 0x53, 0x00, // "MSFT100" in UTF16LE
83+
0x46, 0x00, 0x54, 0x00,
84+
0x31, 0x00, 0x30, 0x00,
85+
0x30, 0x00,
86+
JABI_VENDOR_CODE, // vendor code
87+
0x00, // pad
88+
};
89+
90+
// from zephyr/samples/subsys/usb/webusb/src/main.c
91+
if (usb_reqtype_is_to_device(setup)) {
92+
return -ENOTSUP;
93+
}
94+
if (USB_GET_DESCRIPTOR_TYPE(setup->wValue) == USB_DESC_STRING &&
95+
USB_GET_DESCRIPTOR_INDEX(setup->wValue) == 0xEE) {
96+
*data = msos1_str_desc;
97+
*len = sizeof(msos1_str_desc);
98+
return 0;
99+
}
100+
return -EINVAL;
101+
}
102+
103+
static int vendor_handler(struct usb_setup_packet *setup, int32_t *len, uint8_t **data) {
104+
// from https://github.com/pbatard/libwdi/wiki/WCID-Devices
105+
static uint8_t msos1_compatid_desc[] = {
106+
0x28, 0x00, 0x00, 0x00, // 40 byte length
107+
0x00, 0x01, // version 1.0
108+
0x04, 0x00, // wIndex
109+
0x01, // 1 section
110+
0x00, 0x00, 0x00, 0x00, // reserved
111+
0x00, 0x00, 0x00,
112+
0x00, // interface this applies to
113+
0x01, // reserved
114+
'W', 'I', 'N', 'U', 'S', 'B', 0x00, 0x00, // compatible ID
115+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // sub-compatible ID
116+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // reserved
117+
};
118+
msos1_compatid_desc[16] = usb_if_desc.if0.bInterfaceNumber;
119+
120+
// from zephyr/samples/subsys/usb/webusb/src/main.c
121+
if (usb_reqtype_is_to_device(setup)) {
122+
return -ENOTSUP;
123+
}
124+
if (setup->bRequest == JABI_VENDOR_CODE && setup->wIndex == 0x0004) {
125+
*data = msos1_compatid_desc;
126+
*len = sizeof(msos1_compatid_desc);
127+
return 0;
128+
}
129+
return -EINVAL;
130+
}
131+
76132
USBD_DEFINE_CFG_DATA(usb_config) = {
77133
.usb_device_description = NULL,
78134
.interface_descriptor = &usb_if_desc.if0,
79135
.interface_config = usb_jabi_interface_config,
80136
.cb_usb_status = NULL,
81137
.interface = {
82138
.class_handler = NULL,
83-
.vendor_handler = NULL,
84-
.custom_handler = NULL,
139+
.vendor_handler = vendor_handler,
140+
.custom_handler = custom_handler,
85141
},
86142
.num_endpoints = ARRAY_SIZE(ep_cfg),
87143
.endpoint = ep_cfg,

0 commit comments

Comments
 (0)