Skip to content

Commit 0d38060

Browse files
committed
auto-install WinUSB device driver
1 parent 98f29a4 commit 0d38060

File tree

1 file changed

+69
-1
lines changed

1 file changed

+69
-1
lines changed

board/drivers/usb.h

+69-1
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,15 @@ uint8_t resp[MAX_RESP_LEN];
7171
#define ENDPOINT_TYPE_BULK 2
7272
#define ENDPOINT_TYPE_INT 3
7373

74+
// This is an arbitrary value used in bRequest
75+
#define MS_VENDOR_CODE 0xFF
76+
7477
//Convert machine byte order to USB byte order
7578
#define TOUSBORDER(num)\
7679
(num&0xFF), ((num>>8)&0xFF)
7780

7881
uint8_t device_desc[] = {
79-
DSCR_DEVICE_LEN, DSCR_DEVICE_TYPE, 0x00, 0x01, //Length, Type, bcdUSB
82+
DSCR_DEVICE_LEN, DSCR_DEVICE_TYPE, 0x00, 0x02, //Length, Type, bcdUSB
8083
0xFF, 0xFF, 0xFF, 0x40, // Class, Subclass, Protocol, Max Packet Size
8184
TOUSBORDER(USB_VID), // idVendor
8285
TOUSBORDER(USB_PID), // idProduct
@@ -165,6 +168,49 @@ uint16_t string_3_desc[] = {
165168
'n', 'o', 'n', 'e'
166169
};
167170

171+
#ifdef PANDA
172+
// WCID (auto install WinUSB driver)
173+
// https://github.com/pbatard/libwdi/wiki/WCID-Devices
174+
// https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/winusb-installation#automatic-installation-of--winusb-without-an-inf-file
175+
uint8_t string_238_desc[] = {
176+
0x12, 0x03, // bLength, bDescriptorType
177+
'M',0, 'S',0, 'F',0, 'T',0, '1',0, '0',0, '0',0, // qwSignature (MSFT100)
178+
MS_VENDOR_CODE, 0x00 // bMS_VendorCode, bPad
179+
};
180+
uint8_t winusb_ext_compatid_os_desc[] = {
181+
0x28, 0x00, 0x00, 0x00, // dwLength
182+
0x00, 0x01, // bcdVersion
183+
0x04, 0x00, // wIndex
184+
0x01, // bCount
185+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Reserved
186+
0x00, // bFirstInterfaceNumber
187+
0x00, // Reserved
188+
'W', 'I', 'N', 'U', 'S', 'B', 0x00, 0x00, // compatible ID (WINUSB)
189+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // subcompatible ID (none)
190+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // Reserved
191+
};
192+
uint8_t winusb_ext_prop_os_desc[] = {
193+
0xCC, 0x00, 0x00, 0x00, // dwLength
194+
0x00, 0x01, // bcdVersion
195+
0x05, 0x00, // wIndex
196+
0x02, 0x00, // wCount
197+
// first property
198+
0x84, 0x00, 0x00, 0x00, // dwSize
199+
0x01, 0x00, 0x00, 0x00, // dwPropertyDataType
200+
0x28, 0x00, // wPropertyNameLength
201+
'D',0, 'e',0, 'v',0, 'i',0, 'c',0, 'e',0, 'I',0, 'n',0, 't',0, 'e',0, 'r',0, 'f',0, 'a',0, 'c',0, 'e',0, 'G',0, 'U',0, 'I',0, 'D',0, 0, 0, // bPropertyName (DeviceInterfaceGUID)
202+
0x4E, 0x00, 0x00, 0x00, // dwPropertyDataLength
203+
'{',0, 'C',0, 'C',0, 'E',0, '5',0, '2',0, '9',0, '1',0, 'C',0, '-',0, 'A',0, '6',0, '9',0, 'F',0, '-',0, '4',0, '9',0, '9',0, '5',0, '-',0, 'A',0, '4',0, 'C',0, '2',0, '-',0, '2',0, 'A',0, 'E',0, '5',0, '7',0, 'A',0, '5',0, '1',0, 'A',0, 'D',0, 'E',0, '9',0, '}',0, 0, 0, // bPropertyData ({CCE5291C-A69F-4995-A4C2-2AE57A51ADE9})
204+
// second property
205+
0x3E, 0x00, 0x00, 0x00, // dwSize
206+
0x01, 0x00, 0x00, 0x00, // dwPropertyDataType
207+
0x0C, 0x00, // wPropertyNameLength
208+
'L',0, 'a',0, 'b',0, 'e',0, 'l',0, 0, 0, // bPropertyName (Label)
209+
0x24, 0x00, 0x00, 0x00, // dwPropertyDataLength
210+
'p',0, 'a',0, 'n',0, 'd',0, 'a',0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // bPropertyData (panda)
211+
};
212+
#endif
213+
168214
// current packet
169215
USB_Setup_TypeDef setup;
170216
uint8_t usbdata[0x100];
@@ -345,6 +391,11 @@ void usb_setup() {
345391
USB_WritePacket((const uint8_t *)string_3_desc, min(sizeof(string_3_desc), setup.b.wLength.w), 0);
346392
#endif
347393
break;
394+
#ifdef PANDA
395+
case 238:
396+
USB_WritePacket((uint8_t*)string_238_desc, min(sizeof(string_238_desc), setup.b.wLength.w), 0);
397+
break;
398+
#endif
348399
default:
349400
// nothing
350401
USB_WritePacket(0, 0, 0);
@@ -372,6 +423,23 @@ void usb_setup() {
372423
USB_WritePacket(0, 0, 0);
373424
USBx_OUTEP(0)->DOEPCTL |= USB_OTG_DOEPCTL_CNAK;
374425
break;
426+
#ifdef PANDA
427+
case MS_VENDOR_CODE:
428+
switch (setup.b.wIndex.w) {
429+
// Extended Compat ID OS Descriptor
430+
case 4:
431+
USB_WritePacket((uint8_t*)winusb_ext_compatid_os_desc, min(sizeof(winusb_ext_compatid_os_desc), setup.b.wLength.w), 0);
432+
break;
433+
// Extended Properties OS Descriptor
434+
case 5:
435+
USB_WritePacket((uint8_t*)winusb_ext_prop_os_desc, min(sizeof(winusb_ext_prop_os_desc), setup.b.wLength.w), 0);
436+
break;
437+
default:
438+
USB_WritePacket(0, 0, 0);
439+
}
440+
USBx_OUTEP(0)->DOEPCTL |= USB_OTG_DOEPCTL_CNAK;
441+
break;
442+
#endif
375443
default:
376444
resp_len = usb_cb_control_msg(&setup, resp, 1);
377445
USB_WritePacket(resp, min(resp_len, setup.b.wLength.w), 0);

0 commit comments

Comments
 (0)