usb: add support for microsoft os descriptors
PATCH 1/2 usb: add support for microsoft os descriptors
This patch adds support for special usb descriptors used by microsoft windows. They allow more fine-grained control over driver binding and adding entries to the registry for configuration.
As this is a guest-visible change the "msos-desc" compat property has been added to turn this off for 1.7 + older
Signed-off-by Gerd Hoffmann <[email protected]>
--- hw/i386/pc_piix.c | 4 + hw/i386/pc_q35.c | 4 + hw/usb/Makefile.objs | 2 +- hw/usb/bus.c | 2 + hw/usb/desc-msos.c | 234 +++++++++++++++++++++++++++++++++++++++++++++++++++ hw/usb/desc.c | 37 +++++++- hw/usb/desc.h | 11 ++- include/hw/i386/pc.h | 8 ++ include/hw/usb.h | 3 + trace-events | 1 + 10 files changed, 300 insertions(+), 6 deletions(-) create mode 100644 hw/usb/desc-msos.c
hw/i386/pc_piix.c +4 -0
@@ -357,6 +357,10 @@ static QEMUMachine pc_i440fx_machine_v1_7 = { PC_I440FX_1_7_MACHINE_OPTIONS, .name = "pc-i440fx-1.7", .init = pc_init_pci, + .compat_props = (GlobalProperty []) { +PC_COMPAT_1_7 , + {/* end of list */ } + }, };#define PC_I440FX_1_6_MACHINE_OPTIONS PC_I440FX_MACHINE_OPTIONS
hw/i386/pc_q35.c +4 -0
@@ -276,6 +276,10 @@ static QEMUMachine pc_q35_machine_v1_7 = { PC_Q35_1_7_MACHINE_OPTIONS, .name = "pc-q35-1.7", .init = pc_q35_init, + .compat_props = (GlobalProperty []) { +PC_COMPAT_1_7 , + {/* end of list */ } + }, };#define PC_Q35_1_6_MACHINE_OPTIONS PC_Q35_MACHINE_OPTIONS
hw/usb/Makefile.objs +1 -1
@@ -1,5 +1,5 @@ # usb subsystem core -common-obj-y += core.o combined-packet.o bus.o desc.o +common-obj-y += core.o combined-packet.o bus.o desc.o desc-msos.o common-obj-y += libhw.o # usb host adapters
hw/usb/bus.c +2 -0
@@ -16,6 +16,8 @@ static Property usb_props[] = {DEFINE_PROP_STRING ("serial" , USBDevice, serial),DEFINE_PROP_BIT ("full-path" , USBDevice, flags,USB_DEV_FLAG_FULL_PATH , true), +DEFINE_PROP_BIT ("msos-desc" , USBDevice, flags, +USB_DEV_FLAG_MSOS_DESC_ENABLE , true), DEFINE_PROP_END_OF_LIST() };
hw/usb/desc-msos.c new file +234 -0
234 lines not on this page · raw message
hw/usb/desc.c +33 -4
@@ -7,7 +7,7 @@/* ------------------------------------------------------------------ */ int usb_desc_device (const USBDescID *id,const USBDescDevice *dev, -uint8_t *dest,size_t len) +bool msos,uint8_t *dest,size_t len) {uint8_t bLength =0x12 ;USBDescriptor *d = (void *)dest;
@@ -19,8 +19,18 @@ int usb_desc_device(const USBDescID *id, const USBDescDevice *dev, d->bLength = bLength; d->bDescriptorType =USB_DT_DEVICE ; - d->u.device.bcdUSB_lo =usb_lo (dev->bcdUSB); - d->u.device.bcdUSB_hi =usb_hi (dev->bcdUSB); +if (msos && dev->bcdUSB <0x0200 ) { +/* +* Version 2.0+ required for microsoft os descriptors to work. +* Done this way so msos-desc compat property will handle both +* the version and the new descriptors being present. +*/ + d->u.device.bcdUSB_lo =usb_lo (0x0200 ); + d->u.device.bcdUSB_hi =usb_hi (0x0200 ); + }else { + d->u.device.bcdUSB_lo =usb_lo (dev->bcdUSB); + d->u.device.bcdUSB_hi =usb_hi (dev->bcdUSB); + } d->u.device.bDeviceClass = dev->bDeviceClass; d->u.device.bDeviceSubClass = dev->bDeviceSubClass; d->u.device.bDeviceProtocol = dev->bDeviceProtocol;
@@ -499,6 +509,10 @@ void usb_desc_init(USBDevice *dev)if (desc->super) { dev->speedmask |=USB_SPEED_MASK_SUPER ; } +if (desc->msos && (dev->flags & (1 <<USB_DEV_FLAG_MSOS_DESC_ENABLE ))) { + dev->flags |= (1 <<USB_DEV_FLAG_MSOS_DESC_IN_USE ); +usb_desc_set_string (dev,0xee ,"MSFT100Q" ); + }usb_desc_setdefaults (dev); }
@@ -626,6 +640,7 @@ int usb_desc_string(USBDevice *dev, int index, uint8_t *dest, size_t len)int usb_desc_get_descriptor (USBDevice *dev,USBPacket *p,int value,uint8_t *dest,size_t len) { +bool msos = (dev->flags & (1 <<USB_DEV_FLAG_MSOS_DESC_IN_USE ));const USBDesc *desc =usb_device_get_usb_desc (dev);const USBDescDevice *other_dev;uint8_t buf[256 ];
@@ -646,7 +661,7 @@ int usb_desc_get_descriptor(USBDevice *dev, USBPacket *p,switch (type) {case USB_DT_DEVICE : - ret =usb_desc_device (&desc->id, dev->device, buf,sizeof (buf)); + ret =usb_desc_device (&desc->id, dev->device, msos, buf,sizeof (buf));trace_usb_desc_device (dev->addr, len, ret);break ;case USB_DT_CONFIG :
@@ -703,6 +718,7 @@ int usb_desc_get_descriptor(USBDevice *dev, USBPacket *p,int usb_desc_handle_control (USBDevice *dev,USBPacket *p,int request,int value,int index,int length,uint8_t *data) { +bool msos = (dev->flags & (1 <<USB_DEV_FLAG_MSOS_DESC_IN_USE ));const USBDesc *desc =usb_device_get_usb_desc (dev);int ret =-1 ;
@@ -782,6 +798,19 @@ int usb_desc_handle_control(USBDevice *dev, USBPacket *p,trace_usb_set_interface (dev->addr, index, value, ret);break ; +case VendorDeviceRequest |'Q' : +if (msos) { + ret =usb_desc_msos (desc, p, index, data, length); +trace_usb_desc_msos (dev->addr, index, length, ret); + } +break ; +case VendorInterfaceRequest |'Q' : +if (msos) { + ret =usb_desc_msos (desc, p, index, data, length); +trace_usb_desc_msos (dev->addr, index, length, ret); + } +break ; + }return ret; }
hw/usb/desc.h +10 -1
@@ -2,6 +2,7 @@#define QEMU_HW_USB_DESC_H #include <inttypes.h> +#include <wchar.h> /* binary representation */ typedef struct USBDescriptor {
@@ -182,6 +183,11 @@ struct USBDescOther {const uint8_t *data; }; +struct USBDescMSOS { +const wchar_t *Label; +bool SelectiveSuspendEnabled; +}; +typedef const char *USBDescStrings [256 ];struct USBDesc {
@@ -190,6 +196,7 @@ struct USBDesc {const USBDescDevice *high;const USBDescDevice *super;const char *const *str; +const USBDescMSOS *msos; };#define USB_DESC_FLAG_SUPER (1 << 1)
@@ -207,7 +214,7 @@ static inline uint8_t usb_hi(uint16_t val)/* generate usb packages from structs */ int usb_desc_device (const USBDescID *id,const USBDescDevice *dev, -uint8_t *dest,size_t len); +bool msos,uint8_t *dest,size_t len);int usb_desc_device_qualifier (const USBDescDevice *dev,uint8_t *dest,size_t len); int usb_desc_config(const USBDescConfig *conf, int flags,
@@ -219,6 +226,8 @@ int usb_desc_iface(const USBDescIface *iface, int flags,int usb_desc_endpoint (const USBDescEndpoint *ep,int flags,uint8_t *dest,size_t len);int usb_desc_other (const USBDescOther *desc,uint8_t *dest,size_t len); +int usb_desc_msos (const USBDesc *desc,USBPacket *p, +int index,uint8_t *dest,size_t len);/* control message emulation helpers */ void usb_desc_init (USBDevice *dev);
include/hw/i386/pc.h +8 -0
@@ -246,7 +246,15 @@ uint16_t pvpanic_port(void);int e820_add_entry (uint64_t ,uint64_t ,uint32_t ); +#define PC_COMPAT_1_7 \ + {\ + .driver = TYPE_USB_DEVICE,\ + .property = "msos-desc",\ + .value = "no",\ + } +#define PC_COMPAT_1_6 \ + PC_COMPAT_1_7, \ {\ .driver = "e1000",\ .property = "mitigation",\
include/hw/usb.h +3 -0
@@ -182,6 +182,7 @@ typedef struct USBDescIface USBDescIface;typedef struct USBDescEndpoint USBDescEndpoint ;typedef struct USBDescOther USBDescOther ;typedef struct USBDescString USBDescString ; +typedef struct USBDescMSOS USBDescMSOS ;struct USBDescString {uint8_t index;
@@ -208,6 +209,8 @@ struct USBEndpoint {enum USBDeviceFlags {USB_DEV_FLAG_FULL_PATH ,USB_DEV_FLAG_IS_HOST , +USB_DEV_FLAG_MSOS_DESC_ENABLE , +USB_DEV_FLAG_MSOS_DESC_IN_USE , };/* definition of a USB device */
trace-events +1 -0
@@ -402,6 +402,7 @@ usb_desc_config(int addr, int index, int len, int ret) "dev %d query config %d, usb_desc_other_speed_config(int addr, int index, int len, int ret) "dev %d query config %d, len %d, ret %d" usb_desc_string(int addr, int index, int len, int ret) "dev %d query string %d, len %d, ret %d" usb_desc_bos(int addr, int len, int ret) "dev %d bos, len %d, ret %d" +usb_desc_msos(int addr, int index, int len, int ret) "dev %d msos, index 0x%x, len %d, ret %d" usb_set_addr(int addr) "dev %d" usb_set_config(int addr, int config, int ret) "dev %d, config %d, ret %d" usb_set_interface(int addr, int iface, int alt, int ret) "dev %d, interface %d, altsetting %d, ret %d"
Signature · 1 line
1.8.3.1
PATCH 2/2 usb-hid: add microsoft os descriptor support
Set SelectiveSuspendEnabled registy entry to one.
This makes Windows use remote suspend by default,
without manual registry fiddeling.
Signed-off-by Gerd Hoffmann <[email protected]>
--- hw/usb/dev-hid.c | 8 ++++++++ 1 file changed, 8 insertions(+)
hw/usb/dev-hid.c +8 -0
@@ -261,6 +261,10 @@ static const USBDescDevice desc_device_keyboard = { }, }; +static const USBDescMSOS desc_msos_suspend = { + .SelectiveSuspendEnabled = true, +}; +static const USBDesc desc_mouse = { .id = { .idVendor =0x0627 ,
@@ -272,6 +276,7 @@ static const USBDesc desc_mouse = { }, .full = &desc_device_mouse, .str = desc_strings, + .msos = &desc_msos_suspend, };static const USBDesc desc_tablet = {
@@ -285,6 +290,7 @@ static const USBDesc desc_tablet = { }, .full = &desc_device_tablet, .str = desc_strings, + .msos = &desc_msos_suspend, };static const USBDesc desc_tablet2 = {
@@ -299,6 +305,7 @@ static const USBDesc desc_tablet2 = { .full = &desc_device_tablet, .high = &desc_device_tablet2, .str = desc_strings, + .msos = &desc_msos_suspend, };static const USBDesc desc_keyboard = {
@@ -312,6 +319,7 @@ static const USBDesc desc_keyboard = { }, .full = &desc_device_keyboard, .str = desc_strings, + .msos = &desc_msos_suspend, };static const uint8_t qemu_mouse_hid_report_descriptor[] = {
Signature · 1 line
1.8.3.1