Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/winebus.sys/bus.h | 4 ++-- dlls/winebus.sys/bus_iohid.c | 2 +- dlls/winebus.sys/bus_sdl.c | 6 +++--- dlls/winebus.sys/bus_udev.c | 9 ++++----- dlls/winebus.sys/main.c | 12 ++++++------ 5 files changed, 16 insertions(+), 17 deletions(-)
diff --git a/dlls/winebus.sys/bus.h b/dlls/winebus.sys/bus.h index bf2e157af4d..72bd071135b 100644 --- a/dlls/winebus.sys/bus.h +++ b/dlls/winebus.sys/bus.h @@ -53,11 +53,11 @@ void *get_platform_private(DEVICE_OBJECT *device) DECLSPEC_HIDDEN; DEVICE_OBJECT *bus_create_hid_device(const WCHAR *busidW, WORD vid, WORD pid, WORD input, DWORD version, DWORD uid, const WCHAR *serialW, BOOL is_gamepad, const platform_vtbl *vtbl, DWORD platform_data_size) DECLSPEC_HIDDEN; -DEVICE_OBJECT *bus_find_hid_device(const platform_vtbl *vtbl, void *platform_dev) DECLSPEC_HIDDEN; +DEVICE_OBJECT *bus_find_hid_device(const WCHAR *bus_id, void *platform_dev) DECLSPEC_HIDDEN; void bus_unlink_hid_device(DEVICE_OBJECT *device) DECLSPEC_HIDDEN; void bus_remove_hid_device(DEVICE_OBJECT *device) DECLSPEC_HIDDEN; void process_hid_report(DEVICE_OBJECT *device, BYTE *report, DWORD length) DECLSPEC_HIDDEN; -DEVICE_OBJECT* bus_enumerate_hid_devices(const platform_vtbl *vtbl, enum_func function, void* context) DECLSPEC_HIDDEN; +DEVICE_OBJECT *bus_enumerate_hid_devices(const WCHAR *bus_id, enum_func function, void *context) DECLSPEC_HIDDEN;
/* General Bus Functions */ DWORD check_bus_option(const UNICODE_STRING *option, DWORD default_value) DECLSPEC_HIDDEN; diff --git a/dlls/winebus.sys/bus_iohid.c b/dlls/winebus.sys/bus_iohid.c index f660a3c789a..eb6765d6aac 100644 --- a/dlls/winebus.sys/bus_iohid.c +++ b/dlls/winebus.sys/bus_iohid.c @@ -377,7 +377,7 @@ static void handle_RemovalCallback(void *context, IOReturn result, void *sender, safe way to deallocate that buffer. */ IOHIDDeviceUnscheduleFromRunLoop(IOHIDDevice, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); IOHIDDeviceClose(IOHIDDevice, 0); - device = bus_find_hid_device(&iohid_vtbl, IOHIDDevice); + device = bus_find_hid_device(busidW, IOHIDDevice); if (device) { bus_unlink_hid_device(device); diff --git a/dlls/winebus.sys/bus_sdl.c b/dlls/winebus.sys/bus_sdl.c index 8c9886c7d3c..3607634b7a0 100644 --- a/dlls/winebus.sys/bus_sdl.c +++ b/dlls/winebus.sys/bus_sdl.c @@ -617,7 +617,7 @@ static BOOL set_report_from_event(SDL_Event *event) struct platform_private *private; /* All the events coming in will have 'which' as a 3rd field */ SDL_JoystickID id = ((SDL_JoyButtonEvent*)event)->which; - device = bus_enumerate_hid_devices(&sdl_vtbl, compare_joystick_id, ULongToPtr(id)); + device = bus_enumerate_hid_devices(sdl_busidW, compare_joystick_id, ULongToPtr(id)); if (!device) { ERR("Failed to find device at index %i\n",id); @@ -681,7 +681,7 @@ static BOOL set_mapped_report_from_event(SDL_Event *event) struct platform_private *private; /* All the events coming in will have 'which' as a 3rd field */ SDL_JoystickID id = ((SDL_ControllerButtonEvent*)event)->which; - device = bus_enumerate_hid_devices(&sdl_vtbl, compare_joystick_id, ULongToPtr(id)); + device = bus_enumerate_hid_devices(sdl_busidW, compare_joystick_id, ULongToPtr(id)); if (!device) { ERR("Failed to find device at index %i\n",id); @@ -748,7 +748,7 @@ static void try_remove_device(SDL_JoystickID id) { DEVICE_OBJECT *device = NULL;
- device = bus_enumerate_hid_devices(&sdl_vtbl, compare_joystick_id, ULongToPtr(id)); + device = bus_enumerate_hid_devices(sdl_busidW, compare_joystick_id, ULongToPtr(id)); if (!device) return;
bus_unlink_hid_device(device); diff --git a/dlls/winebus.sys/bus_udev.c b/dlls/winebus.sys/bus_udev.c index 887996daf49..864ffc0bf09 100644 --- a/dlls/winebus.sys/bus_udev.c +++ b/dlls/winebus.sys/bus_udev.c @@ -1095,8 +1095,8 @@ static void try_add_device(struct udev_device *dev) TRACE("udev %s syspath %s\n", debugstr_a(devnode), udev_device_get_syspath(dev));
#ifdef HAS_PROPER_INPUT_HEADER - device = bus_enumerate_hid_devices(&lnxev_vtbl, check_device_syspath, (void *)get_device_syspath(dev)); - if (!device) device = bus_enumerate_hid_devices(&hidraw_vtbl, check_device_syspath, (void *)get_device_syspath(dev)); + device = bus_enumerate_hid_devices(lnxev_busidW, check_device_syspath, (void *)get_device_syspath(dev)); + if (!device) device = bus_enumerate_hid_devices(hidraw_busidW, check_device_syspath, (void *)get_device_syspath(dev)); if (device) { TRACE("duplicate device found, not adding the new one\n"); @@ -1212,10 +1212,9 @@ static void try_remove_device(struct udev_device *dev) { DEVICE_OBJECT *device = NULL;
- device = bus_find_hid_device(&hidraw_vtbl, dev); + device = bus_find_hid_device(hidraw_busidW, dev); #ifdef HAS_PROPER_INPUT_HEADER - if (device == NULL) - device = bus_find_hid_device(&lnxev_vtbl, dev); + if (device == NULL) device = bus_find_hid_device(lnxev_busidW, dev); #endif if (!device) return;
diff --git a/dlls/winebus.sys/main.c b/dlls/winebus.sys/main.c index b7230cf2e33..23c40e6895e 100644 --- a/dlls/winebus.sys/main.c +++ b/dlls/winebus.sys/main.c @@ -312,18 +312,18 @@ DEVICE_OBJECT *bus_create_hid_device(const WCHAR *busidW, WORD vid, WORD pid, return device; }
-DEVICE_OBJECT *bus_find_hid_device(const platform_vtbl *vtbl, void *platform_dev) +DEVICE_OBJECT *bus_find_hid_device(const WCHAR *bus_id, void *platform_dev) { struct pnp_device *dev; DEVICE_OBJECT *ret = NULL;
- TRACE("(%p, %p)\n", vtbl, platform_dev); + TRACE("bus_id %s, platform_dev %p\n", debugstr_w(bus_id), platform_dev);
EnterCriticalSection(&device_list_cs); LIST_FOR_EACH_ENTRY(dev, &pnp_devset, struct pnp_device, entry) { struct device_extension *ext = (struct device_extension *)dev->device->DeviceExtension; - if (ext->vtbl != vtbl) continue; + if (strcmpW(ext->busid, bus_id)) continue; if (ext->vtbl->compare_platform_device(dev->device, platform_dev) == 0) { ret = dev->device; @@ -336,19 +336,19 @@ DEVICE_OBJECT *bus_find_hid_device(const platform_vtbl *vtbl, void *platform_dev return ret; }
-DEVICE_OBJECT* bus_enumerate_hid_devices(const platform_vtbl *vtbl, enum_func function, void* context) +DEVICE_OBJECT *bus_enumerate_hid_devices(const WCHAR *bus_id, enum_func function, void *context) { struct pnp_device *dev, *dev_next; DEVICE_OBJECT *ret = NULL; int cont;
- TRACE("(%p)\n", vtbl); + TRACE("bus_id %p\n", debugstr_w(bus_id));
EnterCriticalSection(&device_list_cs); LIST_FOR_EACH_ENTRY_SAFE(dev, dev_next, &pnp_devset, struct pnp_device, entry) { struct device_extension *ext = (struct device_extension *)dev->device->DeviceExtension; - if (ext->vtbl != vtbl) continue; + if (strcmpW(ext->busid, bus_id)) continue; LeaveCriticalSection(&device_list_cs); cont = function(dev->device, context); EnterCriticalSection(&device_list_cs);
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/winebus.sys/bus_sdl.c | 64 ++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 38 deletions(-)
diff --git a/dlls/winebus.sys/bus_sdl.c b/dlls/winebus.sys/bus_sdl.c index 3607634b7a0..676010c38c3 100644 --- a/dlls/winebus.sys/bus_sdl.c +++ b/dlls/winebus.sys/bus_sdl.c @@ -482,11 +482,9 @@ static void free_device(DEVICE_OBJECT *device) pSDL_HapticClose(ext->sdl_haptic); }
-static int compare_platform_device(DEVICE_OBJECT *device, void *platform_dev) +static int compare_platform_device(DEVICE_OBJECT *device, void *context) { - SDL_JoystickID id1 = impl_from_DEVICE_OBJECT(device)->id; - SDL_JoystickID id2 = PtrToUlong(platform_dev); - return (id1 != id2); + return impl_from_DEVICE_OBJECT(device)->id - PtrToUlong(context); }
static NTSTATUS get_reportdescriptor(DEVICE_OBJECT *device, BYTE *buffer, DWORD length, DWORD *out_length) @@ -606,23 +604,9 @@ static const platform_vtbl sdl_vtbl = set_feature_report, };
-static int compare_joystick_id(DEVICE_OBJECT *device, void* context) +static BOOL set_report_from_event(DEVICE_OBJECT *device, SDL_Event *event) { - return impl_from_DEVICE_OBJECT(device)->id - PtrToUlong(context); -} - -static BOOL set_report_from_event(SDL_Event *event) -{ - DEVICE_OBJECT *device; struct platform_private *private; - /* All the events coming in will have 'which' as a 3rd field */ - SDL_JoystickID id = ((SDL_JoyButtonEvent*)event)->which; - device = bus_enumerate_hid_devices(sdl_busidW, compare_joystick_id, ULongToPtr(id)); - if (!device) - { - ERR("Failed to find device at index %i\n",id); - return FALSE; - } private = impl_from_DEVICE_OBJECT(device); if (private->sdl_controller) { @@ -675,18 +659,9 @@ static BOOL set_report_from_event(SDL_Event *event) return FALSE; }
-static BOOL set_mapped_report_from_event(SDL_Event *event) +static BOOL set_mapped_report_from_event(DEVICE_OBJECT *device, SDL_Event *event) { - DEVICE_OBJECT *device; struct platform_private *private; - /* All the events coming in will have 'which' as a 3rd field */ - SDL_JoystickID id = ((SDL_ControllerButtonEvent*)event)->which; - device = bus_enumerate_hid_devices(sdl_busidW, compare_joystick_id, ULongToPtr(id)); - if (!device) - { - ERR("Failed to find device at index %i\n",id); - return FALSE; - } private = impl_from_DEVICE_OBJECT(device);
switch(event->type) @@ -744,13 +719,8 @@ static BOOL set_mapped_report_from_event(SDL_Event *event) return FALSE; }
-static void try_remove_device(SDL_JoystickID id) +static void try_remove_device(DEVICE_OBJECT *device) { - DEVICE_OBJECT *device = NULL; - - device = bus_enumerate_hid_devices(sdl_busidW, compare_joystick_id, ULongToPtr(id)); - if (!device) return; - bus_unlink_hid_device(device); IoInvalidateDeviceRelations(bus_pdo, BusRelations); } @@ -850,16 +820,34 @@ static void try_add_device(unsigned int index)
static void process_device_event(SDL_Event *event) { + DEVICE_OBJECT *device; + SDL_JoystickID id; + TRACE_(hid_report)("Received action %x\n", event->type);
if (event->type == SDL_JOYDEVICEADDED) try_add_device(((SDL_JoyDeviceEvent*)event)->which); else if (event->type == SDL_JOYDEVICEREMOVED) - try_remove_device(((SDL_JoyDeviceEvent*)event)->which); + { + id = ((SDL_JoyDeviceEvent *)event)->which; + device = bus_find_hid_device(sdl_busidW, ULongToPtr(id)); + if (device) try_remove_device(device); + else WARN("failed to find device with id %d\n", id); + } else if (event->type >= SDL_JOYAXISMOTION && event->type <= SDL_JOYBUTTONUP) - set_report_from_event(event); + { + id = ((SDL_JoyButtonEvent *)event)->which; + device = bus_find_hid_device(sdl_busidW, ULongToPtr(id)); + if (device) set_report_from_event(device, event); + else WARN("failed to find device with id %d\n", id); + } else if (event->type >= SDL_CONTROLLERAXISMOTION && event->type <= SDL_CONTROLLERBUTTONUP) - set_mapped_report_from_event(event); + { + id = ((SDL_ControllerButtonEvent *)event)->which; + device = bus_find_hid_device(sdl_busidW, ULongToPtr(id)); + if (device) set_mapped_report_from_event(device, event); + else WARN("failed to find device with id %d\n", id); + } }
static void sdl_load_mappings(void)
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/winebus.sys/bus_udev.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/dlls/winebus.sys/bus_udev.c b/dlls/winebus.sys/bus_udev.c index 864ffc0bf09..5db1014c09f 100644 --- a/dlls/winebus.sys/bus_udev.c +++ b/dlls/winebus.sys/bus_udev.c @@ -1105,7 +1105,6 @@ static void try_add_device(struct udev_device *dev) } #endif
- subsystem = udev_device_get_subsystem(dev); hiddev = udev_device_get_parent_with_subsystem_devtype(dev, "hid", NULL); if (hiddev) { @@ -1126,8 +1125,10 @@ static void try_add_device(struct udev_device *dev) version = a_to_bcd(bcdDevice); } } + + subsystem = udev_device_get_subsystem(dev); #ifdef HAS_PROPER_INPUT_HEADER - else + if (!strcmp(subsystem, "input")) { struct input_id device_id = {0}; char device_uid[255]; @@ -1142,9 +1143,6 @@ static void try_add_device(struct udev_device *dev) pid = device_id.product; version = device_id.version; } -#else - else - WARN("Could not get device to query VID, PID, Version and Serial\n"); #endif
if (is_xbox_gamepad(vid, pid))
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/winebus.sys/bus_udev.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/dlls/winebus.sys/bus_udev.c b/dlls/winebus.sys/bus_udev.c index 5db1014c09f..174311b87ef 100644 --- a/dlls/winebus.sys/bus_udev.c +++ b/dlls/winebus.sys/bus_udev.c @@ -1135,13 +1135,16 @@ static void try_add_device(struct udev_device *dev)
if (ioctl(fd, EVIOCGID, &device_id) < 0) WARN("ioctl(EVIOCGID) failed: %d %s\n", errno, strerror(errno)); + else + { + vid = device_id.vendor; + pid = device_id.product; + version = device_id.version; + } + device_uid[0] = 0; if (ioctl(fd, EVIOCGUNIQ(254), device_uid) >= 0 && device_uid[0]) serial = strdupAtoW(device_uid); - - vid = device_id.vendor; - pid = device_id.product; - version = device_id.version; } #endif
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/winebus.sys/bus_udev.c | 84 ++++++++++++------------------------- 1 file changed, 27 insertions(+), 57 deletions(-)
diff --git a/dlls/winebus.sys/bus_udev.c b/dlls/winebus.sys/bus_udev.c index 174311b87ef..8086b76b287 100644 --- a/dlls/winebus.sys/bus_udev.c +++ b/dlls/winebus.sys/bus_udev.c @@ -995,66 +995,38 @@ static int check_device_syspath(DEVICE_OBJECT *device, void* context) return strcmp(get_device_syspath(private->udev_device), context); }
-static int parse_uevent_info(const char *uevent, DWORD *vendor_id, - DWORD *product_id, WORD *input, WCHAR **serial_number) +static void parse_uevent_info(struct udev_device *dev, DWORD *vendor_id, DWORD *product_id, + DWORD *input, WCHAR **serial_number) { - DWORD bus_type; - char *tmp; - char *saveptr = NULL; - char *line; - char *key; - char *value; - - int found_id = 0; - int found_serial = 0; - - tmp = heap_alloc(strlen(uevent) + 1); - strcpy(tmp, uevent); - line = strtok_r(tmp, "\n", &saveptr); - while (line != NULL) - { - /* line: "KEY=value" */ - key = line; - value = strchr(line, '='); - if (!value) - { - goto next_line; - } - *value = '\0'; - value++; + const char *ptr, *next, *tmp; + char buffer[256]; + DWORD bus = 0;
- if (strcmp(key, "HID_ID") == 0) - { - /** - * type vendor product - * HID_ID=0003:000005AC:00008242 - **/ - int ret = sscanf(value, "%x:%x:%x", &bus_type, vendor_id, product_id); - if (ret == 3) - found_id = 1; - } - else if (strcmp(key, "HID_UNIQ") == 0) + if ((next = udev_device_get_sysattr_value(dev, "uevent"))) + { + while ((ptr = next) && *ptr) { - /* The caller has to free the serial number */ - if (*value) + if ((next = strchr(next, '\n'))) next += 1; + else next = ptr + strlen(ptr); + TRACE("uevent %s\n", debugstr_an(ptr, next - ptr - 1)); + + if (!strncmp(ptr, "HID_UNIQ=", 9)) { - *serial_number = strdupAtoW(value); - found_serial = 1; + if (sscanf(ptr, "HID_UNIQ=%256s\n", buffer) != 1 || !*buffer) continue; + if (!*serial_number) *serial_number = strdupAtoW(buffer); + } + if (!strncmp(ptr, "HID_PHYS=", 9)) + { + if (!(tmp = strstr(ptr, "/input")) || tmp >= next) continue; + if (*input == -1) sscanf(tmp, "/input%d\n", input); + } + if (!strncmp(ptr, "HID_ID=", 7)) + { + if (bus || *vendor_id || *product_id) continue; + sscanf(ptr, "HID_ID=%x:%x:%x\n", &bus, vendor_id, product_id); } } - else if (strcmp(key, "HID_PHYS") == 0) - { - const char *input_no = strstr(value, "input"); - if (input_no) - *input = atoi(input_no+5 ); - } - -next_line: - line = strtok_r(NULL, "\n", &saveptr); } - - heap_free(tmp); - return (found_id && found_serial); }
static DWORD a_to_bcd(const char *s) @@ -1072,14 +1044,13 @@ static DWORD a_to_bcd(const char *s)
static void try_add_device(struct udev_device *dev) { - DWORD vid = 0, pid = 0, version = 0; + DWORD vid = 0, pid = 0, version = 0, input = -1; struct udev_device *hiddev = NULL, *walk_device; DEVICE_OBJECT *device = NULL; const char *subsystem; const char *devnode; WCHAR *serial = NULL; BOOL is_gamepad = FALSE; - WORD input = -1; int fd; static const CHAR *base_serial = "0000";
@@ -1109,8 +1080,7 @@ static void try_add_device(struct udev_device *dev) if (hiddev) { const char *bcdDevice = NULL; - parse_uevent_info(udev_device_get_sysattr_value(hiddev, "uevent"), - &vid, &pid, &input, &serial); + parse_uevent_info(hiddev, &vid, &pid, &input, &serial); if (serial == NULL) serial = strdupAtoW(base_serial);
And try parsing it from the hid or input and usb parent nodes, but not beyond.
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/winebus.sys/bus_udev.c | 64 +++++++++++++------------------------ 1 file changed, 23 insertions(+), 41 deletions(-)
diff --git a/dlls/winebus.sys/bus_udev.c b/dlls/winebus.sys/bus_udev.c index 8086b76b287..bcf3267e9f4 100644 --- a/dlls/winebus.sys/bus_udev.c +++ b/dlls/winebus.sys/bus_udev.c @@ -995,27 +995,30 @@ static int check_device_syspath(DEVICE_OBJECT *device, void* context) return strcmp(get_device_syspath(private->udev_device), context); }
-static void parse_uevent_info(struct udev_device *dev, DWORD *vendor_id, DWORD *product_id, - DWORD *input, WCHAR **serial_number) +static void get_device_subsystem_info(struct udev_device *dev, char const *subsystem, DWORD *vendor_id, + DWORD *product_id, DWORD *input, DWORD *version, WCHAR **serial_number) { + struct udev_device *parent = NULL; const char *ptr, *next, *tmp; char buffer[256]; DWORD bus = 0;
- if ((next = udev_device_get_sysattr_value(dev, "uevent"))) + if (!(parent = udev_device_get_parent_with_subsystem_devtype(dev, subsystem, NULL))) return; + + if ((next = udev_device_get_sysattr_value(parent, "uevent"))) { while ((ptr = next) && *ptr) { if ((next = strchr(next, '\n'))) next += 1; else next = ptr + strlen(ptr); - TRACE("uevent %s\n", debugstr_an(ptr, next - ptr - 1)); + TRACE("%s uevent %s\n", subsystem, debugstr_an(ptr, next - ptr - 1));
if (!strncmp(ptr, "HID_UNIQ=", 9)) { if (sscanf(ptr, "HID_UNIQ=%256s\n", buffer) != 1 || !*buffer) continue; if (!*serial_number) *serial_number = strdupAtoW(buffer); } - if (!strncmp(ptr, "HID_PHYS=", 9)) + if (!strncmp(ptr, "HID_PHYS=", 9) || !strncmp(ptr, "PHYS="", 6)) { if (!(tmp = strstr(ptr, "/input")) || tmp >= next) continue; if (*input == -1) sscanf(tmp, "/input%d\n", input); @@ -1025,27 +1028,21 @@ static void parse_uevent_info(struct udev_device *dev, DWORD *vendor_id, DWORD * if (bus || *vendor_id || *product_id) continue; sscanf(ptr, "HID_ID=%x:%x:%x\n", &bus, vendor_id, product_id); } + if (!strncmp(ptr, "PRODUCT=", 8)) + { + if (*version) continue; + if (!strcmp(subsystem, "usb")) + sscanf(ptr, "PRODUCT=%x/%x/%x\n", vendor_id, product_id, version); + else + sscanf(ptr, "PRODUCT=%x/%x/%x/%x\n", &bus, vendor_id, product_id, version); + } } } }
-static DWORD a_to_bcd(const char *s) -{ - DWORD r = 0; - const char *c; - int shift = strlen(s) - 1; - for (c = s; *c; ++c) - { - r |= (*c - '0') << (shift * 4); - --shift; - } - return r; -} - static void try_add_device(struct udev_device *dev) { DWORD vid = 0, pid = 0, version = 0, input = -1; - struct udev_device *hiddev = NULL, *walk_device; DEVICE_OBJECT *device = NULL; const char *subsystem; const char *devnode; @@ -1076,25 +1073,9 @@ static void try_add_device(struct udev_device *dev) } #endif
- hiddev = udev_device_get_parent_with_subsystem_devtype(dev, "hid", NULL); - if (hiddev) - { - const char *bcdDevice = NULL; - parse_uevent_info(hiddev, &vid, &pid, &input, &serial); - if (serial == NULL) - serial = strdupAtoW(base_serial); - - walk_device = dev; - while (walk_device && !bcdDevice) - { - bcdDevice = udev_device_get_sysattr_value(walk_device, "bcdDevice"); - walk_device = udev_device_get_parent(walk_device); - } - if (bcdDevice) - { - version = a_to_bcd(bcdDevice); - } - } + get_device_subsystem_info(dev, "hid", &vid, &pid, &input, &version, &serial); + get_device_subsystem_info(dev, "input", &vid, &pid, &input, &version, &serial); + get_device_subsystem_info(dev, "usb", &vid, &pid, &input, &version, &serial);
subsystem = udev_device_get_subsystem(dev); #ifdef HAS_PROPER_INPUT_HEADER @@ -1118,6 +1099,8 @@ static void try_add_device(struct udev_device *dev) } #endif
+ if (serial == NULL) serial = strdupAtoW(base_serial); + if (is_xbox_gamepad(vid, pid)) is_gamepad = TRUE; #ifdef HAS_PROPER_INPUT_HEADER @@ -1132,9 +1115,8 @@ static void try_add_device(struct udev_device *dev) if (input == (WORD)-1 && is_gamepad) input = 0;
- - TRACE("Found udev device %s (vid %04x, pid %04x, version %u, serial %s)\n", - debugstr_a(devnode), vid, pid, version, debugstr_w(serial)); + TRACE("Found udev device %s (vid %04x, pid %04x, version %04x, input %d, serial %s)\n", + debugstr_a(devnode), vid, pid, version, input, debugstr_w(serial));
if (strcmp(subsystem, "hidraw") == 0) {
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/winebus.sys/bus_udev.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/dlls/winebus.sys/bus_udev.c b/dlls/winebus.sys/bus_udev.c index bcf3267e9f4..3f29050d601 100644 --- a/dlls/winebus.sys/bus_udev.c +++ b/dlls/winebus.sys/bus_udev.c @@ -357,12 +357,12 @@ static BOOL build_report_descriptor(struct wine_input_private *ext, struct udev_ if (ioctl(ext->base.device_fd, EVIOCGBIT(EV_REL, sizeof(relbits)), relbits) == -1) { WARN("ioctl(EVIOCGBIT, EV_REL) failed: %d %s\n", errno, strerror(errno)); - return FALSE; + memset(relbits, 0, sizeof(relbits)); } if (ioctl(ext->base.device_fd, EVIOCGBIT(EV_ABS, sizeof(absbits)), absbits) == -1) { WARN("ioctl(EVIOCGBIT, EV_ABS) failed: %d %s\n", errno, strerror(errno)); - return FALSE; + memset(absbits, 0, sizeof(absbits)); }
report_size = 0;
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/winebus.sys/bus_sdl.c | 56 ++++++++++++++++++------------------- dlls/winebus.sys/bus_udev.c | 22 +++++++-------- 2 files changed, 39 insertions(+), 39 deletions(-)
diff --git a/dlls/winebus.sys/bus_sdl.c b/dlls/winebus.sys/bus_sdl.c index 676010c38c3..c833b4e4c06 100644 --- a/dlls/winebus.sys/bus_sdl.c +++ b/dlls/winebus.sys/bus_sdl.c @@ -251,7 +251,7 @@ static BOOL descriptor_add_haptic(struct platform_private *ext) return TRUE; }
-static BOOL build_report_descriptor(struct platform_private *ext) +static NTSTATUS build_report_descriptor(struct platform_private *ext) { INT i; INT report_size; @@ -317,36 +317,36 @@ static BOOL build_report_descriptor(struct platform_private *ext) TRACE("Report will be %i bytes\n", report_size);
if (!hid_descriptor_begin(&ext->desc, device_usage[0], device_usage[1])) - return FALSE; + return STATUS_NO_MEMORY;
if (axis_count == 6 && button_count >= 14) { if (!hid_descriptor_add_axes(&ext->desc, axis_count, HID_USAGE_PAGE_GENERIC, controller_usages, FALSE, 16, 0, 0xffff)) - return FALSE; + return STATUS_NO_MEMORY; } else if (axis_count) { if (!hid_descriptor_add_axes(&ext->desc, axis_count, HID_USAGE_PAGE_GENERIC, joystick_usages, FALSE, 16, 0, 0xffff)) - return FALSE; + return STATUS_NO_MEMORY; }
if (ball_count && !hid_descriptor_add_axes(&ext->desc, ball_count * 2, HID_USAGE_PAGE_GENERIC, &joystick_usages[axis_count], TRUE, 8, 0x81, 0x7f)) - return FALSE; + return STATUS_NO_MEMORY;
if (button_count && !hid_descriptor_add_buttons(&ext->desc, HID_USAGE_PAGE_BUTTON, 1, button_count)) - return FALSE; + return STATUS_NO_MEMORY;
if (hat_count && !hid_descriptor_add_hatswitch(&ext->desc, hat_count)) - return FALSE; + return STATUS_NO_MEMORY;
if (!descriptor_add_haptic(ext)) - return FALSE; + return STATUS_NO_MEMORY;
if (!hid_descriptor_end(&ext->desc)) - return FALSE; + return STATUS_NO_MEMORY;
ext->buffer_length = report_size; if (!(ext->report_buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, report_size))) @@ -358,12 +358,12 @@ static BOOL build_report_descriptor(struct platform_private *ext) for (i = 0; i < hat_count; i++) set_hat_value(ext, i, pSDL_JoystickGetHat(ext->sdl_joystick, i));
- return TRUE; + return STATUS_SUCCESS;
failed: HeapFree(GetProcessHeap(), 0, ext->report_buffer); hid_descriptor_free(&ext->desc); - return FALSE; + return STATUS_NO_MEMORY; }
static SHORT compose_dpad_value(SDL_GameController *joystick) @@ -393,7 +393,7 @@ static SHORT compose_dpad_value(SDL_GameController *joystick) return SDL_HAT_CENTERED; }
-static BOOL build_mapped_report_descriptor(struct platform_private *ext) +static NTSTATUS build_mapped_report_descriptor(struct platform_private *ext) { static const USAGE left_axis_usages[] = {HID_USAGE_GENERIC_X, HID_USAGE_GENERIC_Y}; static const USAGE right_axis_usages[] = {HID_USAGE_GENERIC_RX, HID_USAGE_GENERIC_RY}; @@ -413,42 +413,42 @@ static BOOL build_mapped_report_descriptor(struct platform_private *ext) TRACE("Report will be %i bytes\n", ext->buffer_length);
if (!hid_descriptor_begin(&ext->desc, HID_USAGE_PAGE_GENERIC, HID_USAGE_GENERIC_GAMEPAD)) - return FALSE; + return STATUS_NO_MEMORY;
if (!hid_descriptor_add_axes(&ext->desc, 2, HID_USAGE_PAGE_GENERIC, left_axis_usages, FALSE, 16, 0, 0xffff)) - return FALSE; + return STATUS_NO_MEMORY;
if (!hid_descriptor_add_axes(&ext->desc, 2, HID_USAGE_PAGE_GENERIC, right_axis_usages, FALSE, 16, 0, 0xffff)) - return FALSE; + return STATUS_NO_MEMORY;
if (!hid_descriptor_add_axes(&ext->desc, 2, HID_USAGE_PAGE_GENERIC, trigger_axis_usages, FALSE, 16, 0, 0x7fff)) - return FALSE; + return STATUS_NO_MEMORY;
if (!hid_descriptor_add_buttons(&ext->desc, HID_USAGE_PAGE_BUTTON, 1, CONTROLLER_NUM_BUTTONS)) - return FALSE; + return STATUS_NO_MEMORY;
if (!hid_descriptor_add_hatswitch(&ext->desc, 1)) - return FALSE; + return STATUS_NO_MEMORY;
if (BUTTON_BIT_COUNT % 8 != 0) { /* unused bits between hatswitch and following constant */ if (!hid_descriptor_add_padding(&ext->desc, 8 - (BUTTON_BIT_COUNT % 8))) - return FALSE; + return STATUS_NO_MEMORY; }
/* unknown constant */ if (!hid_descriptor_add_padding(&ext->desc, 16)) - return FALSE; + return STATUS_NO_MEMORY;
if (!descriptor_add_haptic(ext)) - return FALSE; + return STATUS_NO_MEMORY;
if (!hid_descriptor_end(&ext->desc)) - return FALSE; + return STATUS_NO_MEMORY;
if (!(ext->report_buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, ext->buffer_length))) goto failed; @@ -463,12 +463,12 @@ static BOOL build_mapped_report_descriptor(struct platform_private *ext) ext->report_buffer[14] = 0x89; ext->report_buffer[15] = 0xc5;
- return TRUE; + return STATUS_SUCCESS;
failed: HeapFree(GetProcessHeap(), 0, ext->report_buffer); hid_descriptor_free(&ext->desc); - return FALSE; + return STATUS_NO_MEMORY; }
static void free_device(DEVICE_OBJECT *device) @@ -791,7 +791,7 @@ static void try_add_device(unsigned int index)
if (device) { - BOOL rc; + NTSTATUS status; struct platform_private *private = impl_from_DEVICE_OBJECT(device); private->sdl_joystick = joystick; private->sdl_controller = controller; @@ -799,10 +799,10 @@ static void try_add_device(unsigned int index)
/* FIXME: We should probably move this to IRP_MN_START_DEVICE. */ if (controller) - rc = build_mapped_report_descriptor(private); + status = build_mapped_report_descriptor(private); else - rc = build_report_descriptor(private); - if (!rc) + status = build_report_descriptor(private); + if (status) { ERR("Building report descriptor failed, removing device\n"); bus_unlink_hid_device(device); diff --git a/dlls/winebus.sys/bus_udev.c b/dlls/winebus.sys/bus_udev.c index 3f29050d601..9176dff69a7 100644 --- a/dlls/winebus.sys/bus_udev.c +++ b/dlls/winebus.sys/bus_udev.c @@ -343,7 +343,7 @@ static INT count_abs_axis(int device_fd) return abs_count; }
-static BOOL build_report_descriptor(struct wine_input_private *ext, struct udev_device *dev) +static NTSTATUS build_report_descriptor(struct wine_input_private *ext, struct udev_device *dev) { struct input_absinfo abs_info[HID_ABS_MAX]; BYTE absbits[(ABS_MAX+7)/8]; @@ -368,7 +368,7 @@ static BOOL build_report_descriptor(struct wine_input_private *ext, struct udev_ report_size = 0;
if (!hid_descriptor_begin(&ext->desc, device_usage[0], device_usage[1])) - return FALSE; + return STATUS_NO_MEMORY;
abs_count = 0; for (i = 0; i < HID_ABS_MAX; i++) @@ -381,7 +381,7 @@ static BOOL build_report_descriptor(struct wine_input_private *ext, struct udev_
if (!hid_descriptor_add_axes(&ext->desc, 1, usage.UsagePage, &usage.Usage, FALSE, 32, LE_DWORD(abs_info[i].minimum), LE_DWORD(abs_info[i].maximum))) - return FALSE; + return STATUS_NO_MEMORY;
ext->abs_map[i] = report_size; report_size += 4; @@ -397,7 +397,7 @@ static BOOL build_report_descriptor(struct wine_input_private *ext, struct udev_
if (!hid_descriptor_add_axes(&ext->desc, 1, usage.UsagePage, &usage.Usage, TRUE, 8, 0x81, 0x7f)) - return FALSE; + return STATUS_NO_MEMORY;
ext->rel_map[i] = report_size; report_size++; @@ -410,13 +410,13 @@ static BOOL build_report_descriptor(struct wine_input_private *ext, struct udev_ if (button_count) { if (!hid_descriptor_add_buttons(&ext->desc, HID_USAGE_PAGE_BUTTON, 1, button_count)) - return FALSE; + return STATUS_NO_MEMORY;
if (button_count % 8) { BYTE padding = 8 - (button_count % 8); if (!hid_descriptor_add_padding(&ext->desc, padding)) - return FALSE; + return STATUS_NO_MEMORY; }
report_size += (button_count + 7) / 8; @@ -436,11 +436,11 @@ static BOOL build_report_descriptor(struct wine_input_private *ext, struct udev_ if (hat_count) { if (!hid_descriptor_add_hatswitch(&ext->desc, hat_count)) - return FALSE; + return STATUS_NO_MEMORY; }
if (!hid_descriptor_end(&ext->desc)) - return FALSE; + return STATUS_NO_MEMORY;
TRACE("Report will be %i bytes\n", report_size);
@@ -456,13 +456,13 @@ static BOOL build_report_descriptor(struct wine_input_private *ext, struct udev_ if (test_bit(absbits, i)) set_abs_axis_value(ext, i, abs_info[i].value);
- return TRUE; + return STATUS_SUCCESS;
failed: HeapFree(GetProcessHeap(), 0, ext->current_report_buffer); HeapFree(GetProcessHeap(), 0, ext->last_report_buffer); hid_descriptor_free(&ext->desc); - return FALSE; + return STATUS_NO_MEMORY; }
static BOOL set_report_from_event(struct wine_input_private *ext, struct input_event *ie) @@ -1139,7 +1139,7 @@ static void try_add_device(struct udev_device *dev) #ifdef HAS_PROPER_INPUT_HEADER if (strcmp(subsystem, "input") == 0) /* FIXME: We should probably move this to IRP_MN_START_DEVICE. */ - if (!build_report_descriptor((struct wine_input_private*)private, dev)) + if (build_report_descriptor((struct wine_input_private *)private, dev)) { ERR("Building report descriptor failed, removing device\n"); close(fd);