winebus.sys: Pass HID_XFER_PACKET and IO_STATUS_BLOCK to callbacks.

Signed-off-by: Rémi Bernon <rbernon@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Rémi Bernon 2021-08-18 09:14:22 +02:00 committed by Alexandre Julliard
parent ee5cde83da
commit 6e7ca58374
5 changed files with 114 additions and 107 deletions

View File

@ -22,6 +22,7 @@
#include <winbase.h> #include <winbase.h>
#include <winternl.h> #include <winternl.h>
#include <ddk/wdm.h> #include <ddk/wdm.h>
#include <ddk/hidclass.h>
#include <hidusage.h> #include <hidusage.h>
typedef int(*enum_func)(DEVICE_OBJECT *device, void *context); typedef int(*enum_func)(DEVICE_OBJECT *device, void *context);
@ -42,9 +43,9 @@ typedef struct
NTSTATUS (*start_device)(DEVICE_OBJECT *device); NTSTATUS (*start_device)(DEVICE_OBJECT *device);
NTSTATUS (*get_reportdescriptor)(DEVICE_OBJECT *device, BYTE *buffer, DWORD length, DWORD *out_length); NTSTATUS (*get_reportdescriptor)(DEVICE_OBJECT *device, BYTE *buffer, DWORD length, DWORD *out_length);
NTSTATUS (*get_string)(DEVICE_OBJECT *device, DWORD index, WCHAR *buffer, DWORD length); NTSTATUS (*get_string)(DEVICE_OBJECT *device, DWORD index, WCHAR *buffer, DWORD length);
NTSTATUS (*set_output_report)(DEVICE_OBJECT *device, UCHAR id, BYTE *report, DWORD length, ULONG_PTR *written); void (*set_output_report)(DEVICE_OBJECT *device, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io);
NTSTATUS (*get_feature_report)(DEVICE_OBJECT *device, UCHAR id, BYTE *report, DWORD length, ULONG_PTR *read); void (*get_feature_report)(DEVICE_OBJECT *device, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io);
NTSTATUS (*set_feature_report)(DEVICE_OBJECT *device, UCHAR id, BYTE *report, DWORD length, ULONG_PTR *written); void (*set_feature_report)(DEVICE_OBJECT *device, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io);
} platform_vtbl; } platform_vtbl;
void *get_platform_private(DEVICE_OBJECT *device) DECLSPEC_HIDDEN; void *get_platform_private(DEVICE_OBJECT *device) DECLSPEC_HIDDEN;

View File

@ -213,57 +213,60 @@ static NTSTATUS get_string(DEVICE_OBJECT *device, DWORD index, WCHAR *buffer, DW
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
static NTSTATUS set_output_report(DEVICE_OBJECT *device, UCHAR id, BYTE *report, DWORD length, ULONG_PTR *written) static void set_output_report(DEVICE_OBJECT *device, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io)
{ {
IOReturn result; IOReturn result;
struct platform_private *private = impl_from_DEVICE_OBJECT(device); struct platform_private *private = impl_from_DEVICE_OBJECT(device);
result = IOHIDDeviceSetReport(private->device, kIOHIDReportTypeOutput, id, report, length); result = IOHIDDeviceSetReport(private->device, kIOHIDReportTypeOutput, packet->reportId,
packet->reportBuffer, packet->reportBufferLen);
if (result == kIOReturnSuccess) if (result == kIOReturnSuccess)
{ {
*written = length; io->Information = packet->reportBufferLen;
return STATUS_SUCCESS; io->Status = STATUS_SUCCESS;
} }
else else
{ {
*written = 0; io->Information = 0;
return STATUS_UNSUCCESSFUL; io->Status = STATUS_UNSUCCESSFUL;
} }
} }
static NTSTATUS get_feature_report(DEVICE_OBJECT *device, UCHAR id, BYTE *report, DWORD length, ULONG_PTR *read) static void get_feature_report(DEVICE_OBJECT *device, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io)
{ {
IOReturn ret; IOReturn ret;
CFIndex report_length = length; CFIndex report_length = packet->reportBufferLen;
struct platform_private *private = impl_from_DEVICE_OBJECT(device); struct platform_private *private = impl_from_DEVICE_OBJECT(device);
ret = IOHIDDeviceGetReport(private->device, kIOHIDReportTypeFeature, id, report, &report_length); ret = IOHIDDeviceGetReport(private->device, kIOHIDReportTypeFeature, packet->reportId,
packet->reportBuffer, &report_length);
if (ret == kIOReturnSuccess) if (ret == kIOReturnSuccess)
{ {
*read = report_length; io->Information = report_length;
return STATUS_SUCCESS; io->Status = STATUS_SUCCESS;
} }
else else
{ {
*read = 0; io->Information = 0;
return STATUS_UNSUCCESSFUL; io->Status = STATUS_UNSUCCESSFUL;
} }
} }
static NTSTATUS set_feature_report(DEVICE_OBJECT *device, UCHAR id, BYTE *report, DWORD length, ULONG_PTR *written) static void set_feature_report(DEVICE_OBJECT *device, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io)
{ {
IOReturn result; IOReturn result;
struct platform_private *private = impl_from_DEVICE_OBJECT(device); struct platform_private *private = impl_from_DEVICE_OBJECT(device);
result = IOHIDDeviceSetReport(private->device, kIOHIDReportTypeFeature, id, report, length); result = IOHIDDeviceSetReport(private->device, kIOHIDReportTypeFeature, packet->reportId,
packet->reportBuffer, packet->reportBufferLen);
if (result == kIOReturnSuccess) if (result == kIOReturnSuccess)
{ {
*written = length; io->Information = packet->reportBufferLen;
return STATUS_SUCCESS; io->Status = STATUS_SUCCESS;
} }
else else
{ {
*written = 0; io->Information = 0;
return STATUS_UNSUCCESSFUL; io->Status = STATUS_UNSUCCESSFUL;
} }
} }

View File

@ -536,14 +536,14 @@ static NTSTATUS get_string(DEVICE_OBJECT *device, DWORD index, WCHAR *buffer, DW
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
static NTSTATUS set_output_report(DEVICE_OBJECT *device, UCHAR id, BYTE *report, DWORD length, ULONG_PTR *written) static void set_output_report(DEVICE_OBJECT *device, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io)
{ {
struct platform_private *ext = impl_from_DEVICE_OBJECT(device); struct platform_private *ext = impl_from_DEVICE_OBJECT(device);
if (ext->sdl_haptic && id == 0) if (ext->sdl_haptic && packet->reportId == 0)
{ {
WORD left = report[2] * 128; WORD left = packet->reportBuffer[2] * 128;
WORD right = report[3] * 128; WORD right = packet->reportBuffer[3] * 128;
if (ext->haptic_effect_id >= 0) if (ext->haptic_effect_id >= 0)
{ {
@ -572,26 +572,27 @@ static NTSTATUS set_output_report(DEVICE_OBJECT *device, UCHAR id, BYTE *report,
pSDL_HapticRumblePlay(ext->sdl_haptic, i, -1); pSDL_HapticRumblePlay(ext->sdl_haptic, i, -1);
} }
} }
*written = length;
return STATUS_SUCCESS; io->Information = packet->reportBufferLen;
io->Status = STATUS_SUCCESS;
} }
else else
{ {
*written = 0; io->Information = 0;
return STATUS_NOT_IMPLEMENTED; io->Status = STATUS_NOT_IMPLEMENTED;
} }
} }
static NTSTATUS get_feature_report(DEVICE_OBJECT *device, UCHAR id, BYTE *report, DWORD length, ULONG_PTR *read) static void get_feature_report(DEVICE_OBJECT *device, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io)
{ {
*read = 0; io->Information = 0;
return STATUS_NOT_IMPLEMENTED; io->Status = STATUS_NOT_IMPLEMENTED;
} }
static NTSTATUS set_feature_report(DEVICE_OBJECT *device, UCHAR id, BYTE *report, DWORD length, ULONG_PTR *written) static void set_feature_report(DEVICE_OBJECT *device, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io)
{ {
*written = 0; io->Information = 0;
return STATUS_NOT_IMPLEMENTED; io->Status = STATUS_NOT_IMPLEMENTED;
} }
static const platform_vtbl sdl_vtbl = static const platform_vtbl sdl_vtbl =

View File

@ -716,100 +716,103 @@ static DWORD CALLBACK device_report_thread(void *args)
return 0; return 0;
} }
static NTSTATUS hidraw_set_output_report(DEVICE_OBJECT *device, UCHAR id, BYTE *report, DWORD length, ULONG_PTR *written) static void hidraw_set_output_report(DEVICE_OBJECT *device, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io)
{ {
struct platform_private* ext = impl_from_DEVICE_OBJECT(device); struct platform_private* ext = impl_from_DEVICE_OBJECT(device);
ULONG length = packet->reportBufferLen;
BYTE buffer[8192]; BYTE buffer[8192];
int count = 0; int count = 0;
if ((buffer[0] = id)) if ((buffer[0] = packet->reportId))
count = write(ext->device_fd, report, length); count = write(ext->device_fd, packet->reportBuffer, length);
else if (length > sizeof(buffer) - 1) else if (length > sizeof(buffer) - 1)
ERR_(hid_report)("id %d length %u >= 8192, cannot write\n", id, length); ERR_(hid_report)("id %d length %u >= 8192, cannot write\n", packet->reportId, length);
else else
{ {
memcpy(buffer + 1, report, length); memcpy(buffer + 1, packet->reportBuffer, length);
count = write(ext->device_fd, buffer, length + 1); count = write(ext->device_fd, buffer, length + 1);
} }
if (count > 0) if (count > 0)
{ {
*written = count; io->Information = count;
return STATUS_SUCCESS; io->Status = STATUS_SUCCESS;
} }
else else
{ {
ERR_(hid_report)("id %d write failed error: %d %s\n", id, errno, strerror(errno)); ERR_(hid_report)("id %d write failed error: %d %s\n", packet->reportId, errno, strerror(errno));
*written = 0; io->Information = 0;
return STATUS_UNSUCCESSFUL; io->Status = STATUS_UNSUCCESSFUL;
} }
} }
static NTSTATUS hidraw_get_feature_report(DEVICE_OBJECT *device, UCHAR id, BYTE *report, DWORD length, ULONG_PTR *read) static void hidraw_get_feature_report(DEVICE_OBJECT *device, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io)
{ {
#if defined(HAVE_LINUX_HIDRAW_H) && defined(HIDIOCGFEATURE) #if defined(HAVE_LINUX_HIDRAW_H) && defined(HIDIOCGFEATURE)
struct platform_private* ext = impl_from_DEVICE_OBJECT(device); struct platform_private* ext = impl_from_DEVICE_OBJECT(device);
ULONG length = packet->reportBufferLen;
BYTE buffer[8192]; BYTE buffer[8192];
int count = 0; int count = 0;
if ((buffer[0] = id) && length <= 0x1fff) if ((buffer[0] = packet->reportId) && length <= 0x1fff)
count = ioctl(ext->device_fd, HIDIOCGFEATURE(length), report); count = ioctl(ext->device_fd, HIDIOCGFEATURE(length), packet->reportBuffer);
else if (length > sizeof(buffer) - 1) else if (length > sizeof(buffer) - 1)
ERR_(hid_report)("id %d length %u >= 8192, cannot read\n", id, length); ERR_(hid_report)("id %d length %u >= 8192, cannot read\n", packet->reportId, length);
else else
{ {
count = ioctl(ext->device_fd, HIDIOCGFEATURE(length + 1), buffer); count = ioctl(ext->device_fd, HIDIOCGFEATURE(length + 1), buffer);
memcpy(report, buffer + 1, length); memcpy(packet->reportBuffer, buffer + 1, length);
} }
if (count > 0) if (count > 0)
{ {
*read = count; io->Information = count;
return STATUS_SUCCESS; io->Status = STATUS_SUCCESS;
} }
else else
{ {
ERR_(hid_report)("id %d read failed, error: %d %s\n", id, errno, strerror(errno)); ERR_(hid_report)("id %d read failed, error: %d %s\n", packet->reportId, errno, strerror(errno));
*read = 0; io->Information = 0;
return STATUS_UNSUCCESSFUL; io->Status = STATUS_UNSUCCESSFUL;
} }
#else #else
*read = 0; io->Information = 0;
return STATUS_NOT_IMPLEMENTED; io->Status = STATUS_NOT_IMPLEMENTED;
#endif #endif
} }
static NTSTATUS hidraw_set_feature_report(DEVICE_OBJECT *device, UCHAR id, BYTE *report, DWORD length, ULONG_PTR *written) static void hidraw_set_feature_report(DEVICE_OBJECT *device, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io)
{ {
#if defined(HAVE_LINUX_HIDRAW_H) && defined(HIDIOCSFEATURE) #if defined(HAVE_LINUX_HIDRAW_H) && defined(HIDIOCSFEATURE)
struct platform_private* ext = impl_from_DEVICE_OBJECT(device); struct platform_private* ext = impl_from_DEVICE_OBJECT(device);
ULONG length = packet->reportBufferLen;
BYTE buffer[8192]; BYTE buffer[8192];
int count = 0; int count = 0;
if ((buffer[0] = id) && length <= 0x1fff) if ((buffer[0] = packet->reportId) && length <= 0x1fff)
count = ioctl(ext->device_fd, HIDIOCSFEATURE(length), report); count = ioctl(ext->device_fd, HIDIOCSFEATURE(length), packet->reportBuffer);
else if (length > sizeof(buffer) - 1) else if (length > sizeof(buffer) - 1)
ERR_(hid_report)("id %d length %u >= 8192, cannot write\n", id, length); ERR_(hid_report)("id %d length %u >= 8192, cannot write\n", packet->reportId, length);
else else
{ {
memcpy(buffer + 1, report, length); memcpy(buffer + 1, packet->reportBuffer, length);
count = ioctl(ext->device_fd, HIDIOCSFEATURE(length + 1), buffer); count = ioctl(ext->device_fd, HIDIOCSFEATURE(length + 1), buffer);
} }
if (count > 0) if (count > 0)
{ {
*written = count; io->Information = count;
return STATUS_SUCCESS; io->Status = STATUS_SUCCESS;
} }
else else
{ {
ERR_(hid_report)("id %d write failed, error: %d %s\n", id, errno, strerror(errno)); ERR_(hid_report)("id %d write failed, error: %d %s\n", packet->reportId, errno, strerror(errno));
*written = 0; io->Information = 0;
return STATUS_UNSUCCESSFUL; io->Status = STATUS_UNSUCCESSFUL;
} }
#else #else
*written = 0; io->Information = 0;
return STATUS_NOT_IMPLEMENTED; io->Status = STATUS_NOT_IMPLEMENTED;
#endif #endif
} }
@ -949,22 +952,22 @@ static DWORD CALLBACK lnxev_device_report_thread(void *args)
return 0; return 0;
} }
static NTSTATUS lnxev_set_output_report(DEVICE_OBJECT *device, UCHAR id, BYTE *report, DWORD length, ULONG_PTR *written) static void lnxev_set_output_report(DEVICE_OBJECT *device, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io)
{ {
*written = 0; io->Information = 0;
return STATUS_NOT_IMPLEMENTED; io->Status = STATUS_NOT_IMPLEMENTED;
} }
static NTSTATUS lnxev_get_feature_report(DEVICE_OBJECT *device, UCHAR id, BYTE *report, DWORD length, ULONG_PTR *read) static void lnxev_get_feature_report(DEVICE_OBJECT *device, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io)
{ {
*read = 0; io->Information = 0;
return STATUS_NOT_IMPLEMENTED; io->Status = STATUS_NOT_IMPLEMENTED;
} }
static NTSTATUS lnxev_set_feature_report(DEVICE_OBJECT *device, UCHAR id, BYTE *report, DWORD length, ULONG_PTR *written) static void lnxev_set_feature_report(DEVICE_OBJECT *device, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io)
{ {
*written = 0; io->Information = 0;
return STATUS_NOT_IMPLEMENTED; io->Status = STATUS_NOT_IMPLEMENTED;
} }
static const platform_vtbl lnxev_vtbl = { static const platform_vtbl lnxev_vtbl = {

View File

@ -502,22 +502,25 @@ static NTSTATUS mouse_get_string(DEVICE_OBJECT *device, DWORD index, WCHAR *buff
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
static NTSTATUS mouse_set_output_report(DEVICE_OBJECT *device, UCHAR id, BYTE *report, DWORD length, ULONG_PTR *ret_length) static void mouse_set_output_report(DEVICE_OBJECT *device, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io)
{ {
FIXME("id %u, stub!\n", id); FIXME("id %u, stub!\n", packet->reportId);
return STATUS_NOT_IMPLEMENTED; io->Information = 0;
io->Status = STATUS_NOT_IMPLEMENTED;
} }
static NTSTATUS mouse_get_feature_report(DEVICE_OBJECT *device, UCHAR id, BYTE *report, DWORD length, ULONG_PTR *ret_length) static void mouse_get_feature_report(DEVICE_OBJECT *device, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io)
{ {
FIXME("id %u, stub!\n", id); FIXME("id %u, stub!\n", packet->reportId);
return STATUS_NOT_IMPLEMENTED; io->Information = 0;
io->Status = STATUS_NOT_IMPLEMENTED;
} }
static NTSTATUS mouse_set_feature_report(DEVICE_OBJECT *device, UCHAR id, BYTE *report, DWORD length, ULONG_PTR *ret_length) static void mouse_set_feature_report(DEVICE_OBJECT *device, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io)
{ {
FIXME("id %u, stub!\n", id); FIXME("id %u, stub!\n", packet->reportId);
return STATUS_NOT_IMPLEMENTED; io->Information = 0;
io->Status = STATUS_NOT_IMPLEMENTED;
} }
static const platform_vtbl mouse_vtbl = static const platform_vtbl mouse_vtbl =
@ -576,22 +579,25 @@ static NTSTATUS keyboard_get_string(DEVICE_OBJECT *device, DWORD index, WCHAR *b
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
static NTSTATUS keyboard_set_output_report(DEVICE_OBJECT *device, UCHAR id, BYTE *report, DWORD length, ULONG_PTR *ret_length) static void keyboard_set_output_report(DEVICE_OBJECT *device, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io)
{ {
FIXME("id %u, stub!\n", id); FIXME("id %u, stub!\n", packet->reportId);
return STATUS_NOT_IMPLEMENTED; io->Information = 0;
io->Status = STATUS_NOT_IMPLEMENTED;
} }
static NTSTATUS keyboard_get_feature_report(DEVICE_OBJECT *device, UCHAR id, BYTE *report, DWORD length, ULONG_PTR *ret_length) static void keyboard_get_feature_report(DEVICE_OBJECT *device, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io)
{ {
FIXME("id %u, stub!\n", id); FIXME("id %u, stub!\n", packet->reportId);
return STATUS_NOT_IMPLEMENTED; io->Information = 0;
io->Status = STATUS_NOT_IMPLEMENTED;
} }
static NTSTATUS keyboard_set_feature_report(DEVICE_OBJECT *device, UCHAR id, BYTE *report, DWORD length, ULONG_PTR *ret_length) static void keyboard_set_feature_report(DEVICE_OBJECT *device, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io)
{ {
FIXME("id %u, stub!\n", id); FIXME("id %u, stub!\n", packet->reportId);
return STATUS_NOT_IMPLEMENTED; io->Information = 0;
io->Status = STATUS_NOT_IMPLEMENTED;
} }
static const platform_vtbl keyboard_vtbl = static const platform_vtbl keyboard_vtbl =
@ -939,28 +945,21 @@ static NTSTATUS WINAPI hid_internal_dispatch(DEVICE_OBJECT *device, IRP *irp)
{ {
HID_XFER_PACKET *packet = (HID_XFER_PACKET*)(irp->UserBuffer); HID_XFER_PACKET *packet = (HID_XFER_PACKET*)(irp->UserBuffer);
TRACE_(hid_report)("IOCTL_HID_WRITE_REPORT / IOCTL_HID_SET_OUTPUT_REPORT\n"); TRACE_(hid_report)("IOCTL_HID_WRITE_REPORT / IOCTL_HID_SET_OUTPUT_REPORT\n");
irp->IoStatus.Status = ext->vtbl->set_output_report( ext->vtbl->set_output_report(device, packet, &irp->IoStatus);
device, packet->reportId, packet->reportBuffer,
packet->reportBufferLen, &irp->IoStatus.Information);
break; break;
} }
case IOCTL_HID_GET_FEATURE: case IOCTL_HID_GET_FEATURE:
{ {
HID_XFER_PACKET *packet = (HID_XFER_PACKET*)(irp->UserBuffer); HID_XFER_PACKET *packet = (HID_XFER_PACKET*)(irp->UserBuffer);
TRACE_(hid_report)("IOCTL_HID_GET_FEATURE\n"); TRACE_(hid_report)("IOCTL_HID_GET_FEATURE\n");
irp->IoStatus.Status = ext->vtbl->get_feature_report( ext->vtbl->get_feature_report(device, packet, &irp->IoStatus);
device, packet->reportId, packet->reportBuffer,
packet->reportBufferLen, &irp->IoStatus.Information);
packet->reportBufferLen = irp->IoStatus.Information;
break; break;
} }
case IOCTL_HID_SET_FEATURE: case IOCTL_HID_SET_FEATURE:
{ {
HID_XFER_PACKET *packet = (HID_XFER_PACKET*)(irp->UserBuffer); HID_XFER_PACKET *packet = (HID_XFER_PACKET*)(irp->UserBuffer);
TRACE_(hid_report)("IOCTL_HID_SET_FEATURE\n"); TRACE_(hid_report)("IOCTL_HID_SET_FEATURE\n");
irp->IoStatus.Status = ext->vtbl->set_feature_report( ext->vtbl->set_feature_report(device, packet, &irp->IoStatus);
device, packet->reportId, packet->reportBuffer,
packet->reportBufferLen, &irp->IoStatus.Information);
break; break;
} }
default: default: