Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/winebus.sys/main.c | 65 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-)
diff --git a/dlls/winebus.sys/main.c b/dlls/winebus.sys/main.c index 3616ebe8152..34f0490fc0c 100644 --- a/dlls/winebus.sys/main.c +++ b/dlls/winebus.sys/main.c @@ -66,6 +66,9 @@ static const WORD PID_XBOX_CONTROLLERS[] = {
static DRIVER_OBJECT *driver_obj;
+/* The root-enumerated device stack. */ +static DEVICE_OBJECT *bus_pdo, *bus_fdo; + HANDLE driver_key;
struct pnp_device @@ -464,7 +467,33 @@ static NTSTATUS handle_IRP_MN_QUERY_ID(DEVICE_OBJECT *device, IRP *irp) return status; }
-static NTSTATUS WINAPI common_pnp_dispatch(DEVICE_OBJECT *device, IRP *irp) +static NTSTATUS fdo_pnp_dispatch(DEVICE_OBJECT *device, IRP *irp) +{ + IO_STACK_LOCATION *irpsp = IoGetCurrentIrpStackLocation(irp); + NTSTATUS ret; + + switch (irpsp->MinorFunction) + { + case IRP_MN_START_DEVICE: + case IRP_MN_SURPRISE_REMOVAL: + irp->IoStatus.u.Status = STATUS_SUCCESS; + break; + case IRP_MN_REMOVE_DEVICE: + irp->IoStatus.u.Status = STATUS_SUCCESS; + IoSkipCurrentIrpStackLocation(irp); + ret = IoCallDriver(bus_pdo, irp); + IoDetachDevice(bus_pdo); + IoDeleteDevice(device); + return ret; + default: + FIXME("Unhandled minor function %#x.\n", irpsp->MinorFunction); + } + + IoSkipCurrentIrpStackLocation(irp); + return IoCallDriver(bus_pdo, irp); +} + +static NTSTATUS pdo_pnp_dispatch(DEVICE_OBJECT *device, IRP *irp) { NTSTATUS status = irp->IoStatus.u.Status; IO_STACK_LOCATION *irpsp = IoGetCurrentIrpStackLocation(irp); @@ -493,6 +522,13 @@ static NTSTATUS WINAPI common_pnp_dispatch(DEVICE_OBJECT *device, IRP *irp) return status; }
+static NTSTATUS WINAPI common_pnp_dispatch(DEVICE_OBJECT *device, IRP *irp) +{ + if (device == bus_fdo) + return fdo_pnp_dispatch(device, irp); + return pdo_pnp_dispatch(device, irp); +} + static NTSTATUS deliver_last_report(struct device_extension *ext, DWORD buffer_length, BYTE* buffer, ULONG_PTR *out_length) { if (buffer_length < ext->last_report_size) @@ -517,6 +553,12 @@ static NTSTATUS WINAPI hid_internal_dispatch(DEVICE_OBJECT *device, IRP *irp)
TRACE("(%p, %p)\n", device, irp);
+ if (device == bus_fdo) + { + IoSkipCurrentIrpStackLocation(irp); + return IoCallDriver(bus_pdo, irp); + } + switch (irpsp->Parameters.DeviceIoControl.IoControlCode) { case IOCTL_HID_GET_DEVICE_ATTRIBUTES: @@ -759,6 +801,26 @@ BOOL is_xbox_gamepad(WORD vid, WORD pid) return FALSE; }
+static NTSTATUS WINAPI driver_add_device(DRIVER_OBJECT *driver, DEVICE_OBJECT *pdo) +{ + NTSTATUS ret; + + TRACE("driver %p, pdo %p.\n", driver, pdo); + + if ((ret = IoCreateDevice(driver, 0, NULL, FILE_DEVICE_BUS_EXTENDER, 0, FALSE, &bus_fdo))) + { + ERR("Failed to create FDO, status %#x.\n", ret); + return ret; + } + + IoAttachDeviceToDeviceStack(bus_fdo, pdo); + bus_pdo = pdo; + + bus_fdo->Flags &= ~DO_DEVICE_INITIALIZING; + + return STATUS_SUCCESS; +} + static void WINAPI driver_unload(DRIVER_OBJECT *driver) { udev_driver_unload(); @@ -786,6 +848,7 @@ NTSTATUS WINAPI DriverEntry( DRIVER_OBJECT *driver, UNICODE_STRING *path )
driver->MajorFunction[IRP_MJ_PNP] = common_pnp_dispatch; driver->MajorFunction[IRP_MJ_INTERNAL_DEVICE_CONTROL] = hid_internal_dispatch; + driver->DriverExtension->AddDevice = driver_add_device; driver->DriverUnload = driver_unload;
if (check_bus_option(&SDL_enabled, 1))