From: Gerald Pfeifer gerald@pfeifer.com
commit 40a9f69a1de088fb72c6b8966bc4333dea5fdfff
winebus.sys: Rename UDEV bus device variables to be consistent.
Introducing a struct base_device, and hidraw_device / lnxev_device depending on the sub-type of the device.
moved an existing use of ABS_VOLUME that was guarded by
#ifdef HAS_PROPER_INPUT_HEADER
outside that guard, breaking the build on non-Linux platforms.
Address this by putting appropriate guards in place.
Signed-off-by: Gerald Pfeifer gerald@pfeifer.com Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/winebus.sys/bus_udev.c | 48 ++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 22 deletions(-)
diff --git a/dlls/winebus.sys/bus_udev.c b/dlls/winebus.sys/bus_udev.c index 88db78360e2..fce3a7672d9 100644 --- a/dlls/winebus.sys/bus_udev.c +++ b/dlls/winebus.sys/bus_udev.c @@ -110,11 +110,23 @@ struct base_device int device_fd; };
+static inline struct base_device *impl_from_unix_device(struct unix_device *iface) +{ + return CONTAINING_RECORD(iface, struct base_device, unix_device); +} + struct hidraw_device { struct base_device base; };
+static inline struct hidraw_device *hidraw_impl_from_unix_device(struct unix_device *iface) +{ + return CONTAINING_RECORD(impl_from_unix_device(iface), struct hidraw_device, base); +} + +#ifdef HAS_PROPER_INPUT_HEADER + #define HID_REL_MAX (REL_MISC+1) #define HID_ABS_MAX (ABS_VOLUME+1)
@@ -130,21 +142,13 @@ struct lnxev_device int haptic_effect_id; };
-static inline struct base_device *impl_from_unix_device(struct unix_device *iface) -{ - return CONTAINING_RECORD(iface, struct base_device, unix_device); -} - -static inline struct hidraw_device *hidraw_impl_from_unix_device(struct unix_device *iface) -{ - return CONTAINING_RECORD(impl_from_unix_device(iface), struct hidraw_device, base); -} - static inline struct lnxev_device *lnxev_impl_from_unix_device(struct unix_device *iface) { return CONTAINING_RECORD(impl_from_unix_device(iface), struct lnxev_device, base); }
+#endif /* HAS_PROPER_INPUT_HEADER */ + #define MAX_DEVICES 128 static int close_fds[MAX_DEVICES]; static struct pollfd poll_fds[MAX_DEVICES]; @@ -201,6 +205,18 @@ static struct base_device *find_device_from_fd(int fd) return NULL; }
+static struct base_device *find_device_from_udev(struct udev_device *dev) +{ + struct base_device *impl; + + LIST_FOR_EACH_ENTRY(impl, &device_list, struct base_device, unix_device.entry) + if (impl->udev_device == dev) return impl; + + return NULL; +} + +#ifdef HAS_PROPER_INPUT_HEADER + static const char *get_device_syspath(struct udev_device *dev) { struct udev_device *parent; @@ -224,18 +240,6 @@ static struct base_device *find_device_from_syspath(const char *path) return NULL; }
-static struct base_device *find_device_from_udev(struct udev_device *dev) -{ - struct base_device *impl; - - LIST_FOR_EACH_ENTRY(impl, &device_list, struct base_device, unix_device.entry) - if (impl->udev_device == dev) return impl; - - return NULL; -} - -#ifdef HAS_PROPER_INPUT_HEADER - static const BYTE ABS_TO_HID_MAP[][2] = { {HID_USAGE_PAGE_GENERIC, HID_USAGE_GENERIC_X}, /*ABS_X*/ {HID_USAGE_PAGE_GENERIC, HID_USAGE_GENERIC_Y}, /*ABS_Y*/
To keep lnxev_device functions and related helpers all together.
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/winebus.sys/bus_udev.c | 375 ++++++++++++++++++------------------ 1 file changed, 186 insertions(+), 189 deletions(-)
diff --git a/dlls/winebus.sys/bus_udev.c b/dlls/winebus.sys/bus_udev.c index fce3a7672d9..909d91667e1 100644 --- a/dlls/winebus.sys/bus_udev.c +++ b/dlls/winebus.sys/bus_udev.c @@ -215,6 +215,191 @@ static struct base_device *find_device_from_udev(struct udev_device *dev) return NULL; }
+static void hidraw_device_destroy(struct unix_device *iface) +{ + struct hidraw_device *impl = hidraw_impl_from_unix_device(iface); + + udev_device_unref(impl->base.udev_device); +} + +static NTSTATUS hidraw_device_start(struct unix_device *iface) +{ + pthread_mutex_lock(&udev_cs); + start_polling_device(iface); + pthread_mutex_unlock(&udev_cs); + return STATUS_SUCCESS; +} + +static void hidraw_device_stop(struct unix_device *iface) +{ + struct hidraw_device *impl = hidraw_impl_from_unix_device(iface); + + pthread_mutex_lock(&udev_cs); + stop_polling_device(iface); + list_remove(&impl->base.unix_device.entry); + pthread_mutex_unlock(&udev_cs); +} + +static NTSTATUS hidraw_device_get_report_descriptor(struct unix_device *iface, BYTE *buffer, + DWORD length, DWORD *out_length) +{ +#ifdef HAVE_LINUX_HIDRAW_H + struct hidraw_report_descriptor descriptor; + struct hidraw_device *impl = hidraw_impl_from_unix_device(iface); + + if (ioctl(impl->base.device_fd, HIDIOCGRDESCSIZE, &descriptor.size) == -1) + { + WARN("ioctl(HIDIOCGRDESCSIZE) failed: %d %s\n", errno, strerror(errno)); + return STATUS_UNSUCCESSFUL; + } + + *out_length = descriptor.size; + + if (length < descriptor.size) + return STATUS_BUFFER_TOO_SMALL; + if (!descriptor.size) + return STATUS_SUCCESS; + + if (ioctl(impl->base.device_fd, HIDIOCGRDESC, &descriptor) == -1) + { + WARN("ioctl(HIDIOCGRDESC) failed: %d %s\n", errno, strerror(errno)); + return STATUS_UNSUCCESSFUL; + } + + memcpy(buffer, descriptor.value, descriptor.size); + return STATUS_SUCCESS; +#else + return STATUS_NOT_IMPLEMENTED; +#endif +} + +static void hidraw_device_read_report(struct unix_device *iface) +{ + struct hidraw_device *impl = hidraw_impl_from_unix_device(iface); + BYTE report_buffer[1024]; + + int size = read(impl->base.device_fd, report_buffer, sizeof(report_buffer)); + if (size == -1) + TRACE_(hid_report)("Read failed. Likely an unplugged device %d %s\n", errno, strerror(errno)); + else if (size == 0) + TRACE_(hid_report)("Failed to read report\n"); + else + bus_event_queue_input_report(&event_queue, iface, report_buffer, size); +} + +static void hidraw_device_set_output_report(struct unix_device *iface, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io) +{ + struct hidraw_device *impl = hidraw_impl_from_unix_device(iface); + ULONG length = packet->reportBufferLen; + BYTE buffer[8192]; + int count = 0; + + if ((buffer[0] = packet->reportId)) + count = write(impl->base.device_fd, packet->reportBuffer, length); + else if (length > sizeof(buffer) - 1) + ERR_(hid_report)("id %d length %u >= 8192, cannot write\n", packet->reportId, length); + else + { + memcpy(buffer + 1, packet->reportBuffer, length); + count = write(impl->base.device_fd, buffer, length + 1); + } + + if (count > 0) + { + io->Information = count; + io->Status = STATUS_SUCCESS; + } + else + { + ERR_(hid_report)("id %d write failed error: %d %s\n", packet->reportId, errno, strerror(errno)); + io->Information = 0; + io->Status = STATUS_UNSUCCESSFUL; + } +} + +static void hidraw_device_get_feature_report(struct unix_device *iface, HID_XFER_PACKET *packet, + IO_STATUS_BLOCK *io) +{ +#if defined(HAVE_LINUX_HIDRAW_H) && defined(HIDIOCGFEATURE) + struct hidraw_device *impl = hidraw_impl_from_unix_device(iface); + ULONG length = packet->reportBufferLen; + BYTE buffer[8192]; + int count = 0; + + if ((buffer[0] = packet->reportId) && length <= 0x1fff) + count = ioctl(impl->base.device_fd, HIDIOCGFEATURE(length), packet->reportBuffer); + else if (length > sizeof(buffer) - 1) + ERR_(hid_report)("id %d length %u >= 8192, cannot read\n", packet->reportId, length); + else + { + count = ioctl(impl->base.device_fd, HIDIOCGFEATURE(length + 1), buffer); + memcpy(packet->reportBuffer, buffer + 1, length); + } + + if (count > 0) + { + io->Information = count; + io->Status = STATUS_SUCCESS; + } + else + { + ERR_(hid_report)("id %d read failed, error: %d %s\n", packet->reportId, errno, strerror(errno)); + io->Information = 0; + io->Status = STATUS_UNSUCCESSFUL; + } +#else + io->Information = 0; + io->Status = STATUS_NOT_IMPLEMENTED; +#endif +} + +static void hidraw_device_set_feature_report(struct unix_device *iface, HID_XFER_PACKET *packet, + IO_STATUS_BLOCK *io) +{ +#if defined(HAVE_LINUX_HIDRAW_H) && defined(HIDIOCSFEATURE) + struct hidraw_device *impl = hidraw_impl_from_unix_device(iface); + ULONG length = packet->reportBufferLen; + BYTE buffer[8192]; + int count = 0; + + if ((buffer[0] = packet->reportId) && length <= 0x1fff) + count = ioctl(impl->base.device_fd, HIDIOCSFEATURE(length), packet->reportBuffer); + else if (length > sizeof(buffer) - 1) + ERR_(hid_report)("id %d length %u >= 8192, cannot write\n", packet->reportId, length); + else + { + memcpy(buffer + 1, packet->reportBuffer, length); + count = ioctl(impl->base.device_fd, HIDIOCSFEATURE(length + 1), buffer); + } + + if (count > 0) + { + io->Information = count; + io->Status = STATUS_SUCCESS; + } + else + { + ERR_(hid_report)("id %d write failed, error: %d %s\n", packet->reportId, errno, strerror(errno)); + io->Information = 0; + io->Status = STATUS_UNSUCCESSFUL; + } +#else + io->Information = 0; + io->Status = STATUS_NOT_IMPLEMENTED; +#endif +} + +static const struct raw_device_vtbl hidraw_device_vtbl = +{ + hidraw_device_destroy, + hidraw_device_start, + hidraw_device_stop, + hidraw_device_get_report_descriptor, + hidraw_device_set_output_report, + hidraw_device_get_feature_report, + hidraw_device_set_feature_report, +}; + #ifdef HAS_PROPER_INPUT_HEADER
static const char *get_device_syspath(struct udev_device *dev) @@ -529,194 +714,6 @@ static BOOL set_report_from_event(struct unix_device *iface, struct input_event return FALSE; } } -#endif - -static void hidraw_device_destroy(struct unix_device *iface) -{ - struct hidraw_device *impl = hidraw_impl_from_unix_device(iface); - - udev_device_unref(impl->base.udev_device); -} - -static NTSTATUS hidraw_device_start(struct unix_device *iface) -{ - pthread_mutex_lock(&udev_cs); - start_polling_device(iface); - pthread_mutex_unlock(&udev_cs); - return STATUS_SUCCESS; -} - -static void hidraw_device_stop(struct unix_device *iface) -{ - struct hidraw_device *impl = hidraw_impl_from_unix_device(iface); - - pthread_mutex_lock(&udev_cs); - stop_polling_device(iface); - list_remove(&impl->base.unix_device.entry); - pthread_mutex_unlock(&udev_cs); -} - -static NTSTATUS hidraw_device_get_report_descriptor(struct unix_device *iface, BYTE *buffer, - DWORD length, DWORD *out_length) -{ -#ifdef HAVE_LINUX_HIDRAW_H - struct hidraw_report_descriptor descriptor; - struct hidraw_device *impl = hidraw_impl_from_unix_device(iface); - - if (ioctl(impl->base.device_fd, HIDIOCGRDESCSIZE, &descriptor.size) == -1) - { - WARN("ioctl(HIDIOCGRDESCSIZE) failed: %d %s\n", errno, strerror(errno)); - return STATUS_UNSUCCESSFUL; - } - - *out_length = descriptor.size; - - if (length < descriptor.size) - return STATUS_BUFFER_TOO_SMALL; - if (!descriptor.size) - return STATUS_SUCCESS; - - if (ioctl(impl->base.device_fd, HIDIOCGRDESC, &descriptor) == -1) - { - WARN("ioctl(HIDIOCGRDESC) failed: %d %s\n", errno, strerror(errno)); - return STATUS_UNSUCCESSFUL; - } - - memcpy(buffer, descriptor.value, descriptor.size); - return STATUS_SUCCESS; -#else - return STATUS_NOT_IMPLEMENTED; -#endif -} - -static void hidraw_device_read_report(struct unix_device *iface) -{ - struct hidraw_device *impl = hidraw_impl_from_unix_device(iface); - BYTE report_buffer[1024]; - - int size = read(impl->base.device_fd, report_buffer, sizeof(report_buffer)); - if (size == -1) - TRACE_(hid_report)("Read failed. Likely an unplugged device %d %s\n", errno, strerror(errno)); - else if (size == 0) - TRACE_(hid_report)("Failed to read report\n"); - else - bus_event_queue_input_report(&event_queue, iface, report_buffer, size); -} - -static void hidraw_device_set_output_report(struct unix_device *iface, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io) -{ - struct hidraw_device *impl = hidraw_impl_from_unix_device(iface); - ULONG length = packet->reportBufferLen; - BYTE buffer[8192]; - int count = 0; - - if ((buffer[0] = packet->reportId)) - count = write(impl->base.device_fd, packet->reportBuffer, length); - else if (length > sizeof(buffer) - 1) - ERR_(hid_report)("id %d length %u >= 8192, cannot write\n", packet->reportId, length); - else - { - memcpy(buffer + 1, packet->reportBuffer, length); - count = write(impl->base.device_fd, buffer, length + 1); - } - - if (count > 0) - { - io->Information = count; - io->Status = STATUS_SUCCESS; - } - else - { - ERR_(hid_report)("id %d write failed error: %d %s\n", packet->reportId, errno, strerror(errno)); - io->Information = 0; - io->Status = STATUS_UNSUCCESSFUL; - } -} - -static void hidraw_device_get_feature_report(struct unix_device *iface, HID_XFER_PACKET *packet, - IO_STATUS_BLOCK *io) -{ -#if defined(HAVE_LINUX_HIDRAW_H) && defined(HIDIOCGFEATURE) - struct hidraw_device *impl = hidraw_impl_from_unix_device(iface); - ULONG length = packet->reportBufferLen; - BYTE buffer[8192]; - int count = 0; - - if ((buffer[0] = packet->reportId) && length <= 0x1fff) - count = ioctl(impl->base.device_fd, HIDIOCGFEATURE(length), packet->reportBuffer); - else if (length > sizeof(buffer) - 1) - ERR_(hid_report)("id %d length %u >= 8192, cannot read\n", packet->reportId, length); - else - { - count = ioctl(impl->base.device_fd, HIDIOCGFEATURE(length + 1), buffer); - memcpy(packet->reportBuffer, buffer + 1, length); - } - - if (count > 0) - { - io->Information = count; - io->Status = STATUS_SUCCESS; - } - else - { - ERR_(hid_report)("id %d read failed, error: %d %s\n", packet->reportId, errno, strerror(errno)); - io->Information = 0; - io->Status = STATUS_UNSUCCESSFUL; - } -#else - io->Information = 0; - io->Status = STATUS_NOT_IMPLEMENTED; -#endif -} - -static void hidraw_device_set_feature_report(struct unix_device *iface, HID_XFER_PACKET *packet, - IO_STATUS_BLOCK *io) -{ -#if defined(HAVE_LINUX_HIDRAW_H) && defined(HIDIOCSFEATURE) - struct hidraw_device *impl = hidraw_impl_from_unix_device(iface); - ULONG length = packet->reportBufferLen; - BYTE buffer[8192]; - int count = 0; - - if ((buffer[0] = packet->reportId) && length <= 0x1fff) - count = ioctl(impl->base.device_fd, HIDIOCSFEATURE(length), packet->reportBuffer); - else if (length > sizeof(buffer) - 1) - ERR_(hid_report)("id %d length %u >= 8192, cannot write\n", packet->reportId, length); - else - { - memcpy(buffer + 1, packet->reportBuffer, length); - count = ioctl(impl->base.device_fd, HIDIOCSFEATURE(length + 1), buffer); - } - - if (count > 0) - { - io->Information = count; - io->Status = STATUS_SUCCESS; - } - else - { - ERR_(hid_report)("id %d write failed, error: %d %s\n", packet->reportId, errno, strerror(errno)); - io->Information = 0; - io->Status = STATUS_UNSUCCESSFUL; - } -#else - io->Information = 0; - io->Status = STATUS_NOT_IMPLEMENTED; -#endif -} - -static const struct raw_device_vtbl hidraw_device_vtbl = -{ - hidraw_device_destroy, - hidraw_device_start, - hidraw_device_stop, - hidraw_device_get_report_descriptor, - hidraw_device_set_output_report, - hidraw_device_get_feature_report, - hidraw_device_set_feature_report, -}; - -#ifdef HAS_PROPER_INPUT_HEADER
static void lnxev_device_destroy(struct unix_device *iface) { @@ -812,7 +809,7 @@ static const struct hid_device_vtbl lnxev_device_vtbl = lnxev_device_stop, lnxev_device_haptics_start, }; -#endif +#endif /* HAS_PROPER_INPUT_HEADER */
static void get_device_subsystem_info(struct udev_device *dev, char const *subsystem, struct device_desc *desc) {