2 * Plug and Play support for hid devices found through udev
4 * Copyright 2016 CodeWeavers, Aric Stewart
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
33 #ifdef HAVE_SYS_POLL_H
34 # include <sys/poll.h>
39 #ifdef HAVE_LINUX_HIDRAW_H
40 # include <linux/hidraw.h>
42 #ifdef HAVE_SYS_IOCTL_H
43 # include <sys/ioctl.h>
46 #ifdef HAVE_LINUX_INPUT_H
47 # include <linux/input.h>
49 # if defined(EVIOCGBIT) && defined(EV_ABS) && defined(BTN_PINKIE)
50 # define HAS_PROPER_INPUT_HEADER
53 # define SYN_DROPPED 3
57 #define NONAMELESSUNION
60 #define WIN32_NO_STATUS
66 #include "ddk/hidtypes.h"
67 #include "wine/debug.h"
68 #include "wine/heap.h"
69 #include "wine/unicode.h"
71 #ifdef HAS_PROPER_INPUT_HEADER
72 # include "hidusage.h"
75 #ifdef WORDS_BIGENDIAN
76 #define LE_WORD(x) RtlUshortByteSwap(x)
77 #define LE_DWORD(x) RtlUlongByteSwap(x)
79 #define LE_WORD(x) (x)
80 #define LE_DWORD(x) (x)
83 #include "controller.h"
86 WINE_DEFAULT_DEBUG_CHANNEL(plugplay
);
90 WINE_DECLARE_DEBUG_CHANNEL(hid_report
);
92 static struct udev
*udev_context
= NULL
;
93 static DRIVER_OBJECT
*udev_driver_obj
= NULL
;
94 static DWORD disable_hidraw
= 0;
95 static DWORD disable_input
= 0;
97 static const WCHAR hidraw_busidW
[] = {'H','I','D','R','A','W',0};
98 static const WCHAR lnxev_busidW
[] = {'L','N','X','E','V',0};
100 #include "initguid.h"
101 DEFINE_GUID(GUID_DEVCLASS_HIDRAW
, 0x3def44ad,0x242e,0x46e5,0x82,0x6d,0x70,0x72,0x13,0xf3,0xaa,0x81);
102 DEFINE_GUID(GUID_DEVCLASS_LINUXEVENT
, 0x1b932c0d,0xfea7,0x42cd,0x8e,0xaa,0x0e,0x48,0x79,0xb6,0x9e,0xaa);
104 struct platform_private
106 struct udev_device
*udev_device
;
109 HANDLE report_thread
;
113 static inline struct platform_private
*impl_from_DEVICE_OBJECT(DEVICE_OBJECT
*device
)
115 return (struct platform_private
*)get_platform_private(device
);
118 #ifdef HAS_PROPER_INPUT_HEADER
120 static const BYTE REPORT_ABS_AXIS_TAIL
[] = {
121 0x17, 0x00, 0x00, 0x00, 0x00, /* LOGICAL_MINIMUM (0) */
122 0x27, 0xff, 0x00, 0x00, 0x00, /* LOGICAL_MAXIMUM (0xff) */
123 0x37, 0x00, 0x00, 0x00, 0x00, /* PHYSICAL_MINIMUM (0) */
124 0x47, 0xff, 0x00, 0x00, 0x00, /* PHYSICAL_MAXIMUM (256) */
125 0x75, 0x20, /* REPORT_SIZE (32) */
126 0x95, 0x00, /* REPORT_COUNT (2) */
127 0x81, 0x02, /* INPUT (Data,Var,Abs) */
129 #define IDX_ABS_LOG_MINIMUM 1
130 #define IDX_ABS_LOG_MAXIMUM 6
131 #define IDX_ABS_PHY_MINIMUM 11
132 #define IDX_ABS_PHY_MAXIMUM 16
133 #define IDX_ABS_AXIS_COUNT 23
135 static const BYTE ABS_TO_HID_MAP
[][2] = {
136 {HID_USAGE_PAGE_GENERIC
, HID_USAGE_GENERIC_X
}, /*ABS_X*/
137 {HID_USAGE_PAGE_GENERIC
, HID_USAGE_GENERIC_Y
}, /*ABS_Y*/
138 {HID_USAGE_PAGE_GENERIC
, HID_USAGE_GENERIC_Z
}, /*ABS_Z*/
139 {HID_USAGE_PAGE_GENERIC
, HID_USAGE_GENERIC_RX
}, /*ABS_RX*/
140 {HID_USAGE_PAGE_GENERIC
, HID_USAGE_GENERIC_RY
}, /*ABS_RY*/
141 {HID_USAGE_PAGE_GENERIC
, HID_USAGE_GENERIC_RZ
}, /*ABS_RZ*/
142 {HID_USAGE_PAGE_SIMULATION
, HID_USAGE_SIMULATION_THROTTLE
}, /*ABS_THROTTLE*/
143 {HID_USAGE_PAGE_SIMULATION
, HID_USAGE_SIMULATION_RUDDER
}, /*ABS_RUDDER*/
144 {HID_USAGE_PAGE_GENERIC
, HID_USAGE_GENERIC_WHEEL
}, /*ABS_WHEEL*/
145 {HID_USAGE_PAGE_SIMULATION
, 0xC4}, /*ABS_GAS*/
146 {HID_USAGE_PAGE_SIMULATION
, 0xC5}, /*ABS_BRAKE*/
155 {HID_USAGE_PAGE_DIGITIZER
, 0x30}, /*ABS_PRESSURE*/
156 {0, 0}, /*ABS_DISTANCE*/
157 {HID_USAGE_PAGE_DIGITIZER
, 0x3D}, /*ABS_TILT_X*/
158 {HID_USAGE_PAGE_DIGITIZER
, 0x3F}, /*ABS_TILT_Y*/
159 {0, 0}, /*ABS_TOOL_WIDTH*/
163 {HID_USAGE_PAGE_CONSUMER
, 0xE0} /*ABS_VOLUME*/
165 #define HID_ABS_MAX (ABS_VOLUME+1)
166 #define TOP_ABS_PAGE (HID_USAGE_PAGE_DIGITIZER+1)
168 static const BYTE REL_TO_HID_MAP
[][2] = {
169 {HID_USAGE_PAGE_GENERIC
, HID_USAGE_GENERIC_X
}, /* REL_X */
170 {HID_USAGE_PAGE_GENERIC
, HID_USAGE_GENERIC_Y
}, /* REL_Y */
171 {HID_USAGE_PAGE_GENERIC
, HID_USAGE_GENERIC_Z
}, /* REL_Z */
172 {HID_USAGE_PAGE_GENERIC
, HID_USAGE_GENERIC_RX
}, /* REL_RX */
173 {HID_USAGE_PAGE_GENERIC
, HID_USAGE_GENERIC_RY
}, /* REL_RY */
174 {HID_USAGE_PAGE_GENERIC
, HID_USAGE_GENERIC_RZ
}, /* REL_RZ */
175 {0, 0}, /* REL_HWHEEL */
176 {HID_USAGE_PAGE_GENERIC
, HID_USAGE_GENERIC_DIAL
}, /* REL_DIAL */
177 {HID_USAGE_PAGE_GENERIC
, HID_USAGE_GENERIC_WHEEL
}, /* REL_WHEEL */
178 {0, 0} /* REL_MISC */
181 #define HID_REL_MAX (REL_MISC+1)
182 #define TOP_REL_PAGE (HID_USAGE_PAGE_CONSUMER+1)
184 struct wine_input_absinfo
{
185 struct input_absinfo info
;
189 struct wine_input_private
{
190 struct platform_private base
;
193 BYTE
*last_report_buffer
;
194 BYTE
*current_report_buffer
;
195 enum { FIRST
, NORMAL
, DROPPED
} report_state
;
197 int report_descriptor_size
;
198 BYTE
*report_descriptor
;
200 BYTE button_map
[KEY_MAX
];
201 BYTE rel_map
[HID_REL_MAX
];
204 struct wine_input_absinfo abs_map
[HID_ABS_MAX
];
207 #define test_bit(arr,bit) (((BYTE*)(arr))[(bit)>>3]&(1<<((bit)&7)))
209 static BYTE
*add_axis_block(BYTE
*report_ptr
, BYTE count
, BYTE page
, BYTE
*usages
, BOOL absolute
, const struct wine_input_absinfo
*absinfo
)
212 memcpy(report_ptr
, REPORT_AXIS_HEADER
, sizeof(REPORT_AXIS_HEADER
));
213 report_ptr
[IDX_AXIS_PAGE
] = page
;
214 report_ptr
+= sizeof(REPORT_AXIS_HEADER
);
215 for (i
= 0; i
< count
; i
++)
217 memcpy(report_ptr
, REPORT_AXIS_USAGE
, sizeof(REPORT_AXIS_USAGE
));
218 report_ptr
[IDX_AXIS_USAGE
] = usages
[i
];
219 report_ptr
+= sizeof(REPORT_AXIS_USAGE
);
223 memcpy(report_ptr
, REPORT_ABS_AXIS_TAIL
, sizeof(REPORT_ABS_AXIS_TAIL
));
226 *((int*)&report_ptr
[IDX_ABS_LOG_MINIMUM
]) = LE_DWORD(absinfo
->info
.minimum
);
227 *((int*)&report_ptr
[IDX_ABS_LOG_MAXIMUM
]) = LE_DWORD(absinfo
->info
.maximum
);
228 *((int*)&report_ptr
[IDX_ABS_PHY_MINIMUM
]) = LE_DWORD(absinfo
->info
.minimum
);
229 *((int*)&report_ptr
[IDX_ABS_PHY_MAXIMUM
]) = LE_DWORD(absinfo
->info
.maximum
);
231 report_ptr
[IDX_ABS_AXIS_COUNT
] = count
;
232 report_ptr
+= sizeof(REPORT_ABS_AXIS_TAIL
);
236 memcpy(report_ptr
, REPORT_REL_AXIS_TAIL
, sizeof(REPORT_REL_AXIS_TAIL
));
237 report_ptr
[IDX_REL_AXIS_COUNT
] = count
;
238 report_ptr
+= sizeof(REPORT_REL_AXIS_TAIL
);
243 static const BYTE
* what_am_I(struct udev_device
*dev
)
245 static const BYTE Unknown
[2] = {HID_USAGE_PAGE_GENERIC
, 0};
246 static const BYTE Mouse
[2] = {HID_USAGE_PAGE_GENERIC
, HID_USAGE_GENERIC_MOUSE
};
247 static const BYTE Keyboard
[2] = {HID_USAGE_PAGE_GENERIC
, HID_USAGE_GENERIC_KEYBOARD
};
248 static const BYTE Gamepad
[2] = {HID_USAGE_PAGE_GENERIC
, HID_USAGE_GENERIC_GAMEPAD
};
249 static const BYTE Keypad
[2] = {HID_USAGE_PAGE_GENERIC
, HID_USAGE_GENERIC_KEYPAD
};
250 static const BYTE Tablet
[2] = {HID_USAGE_PAGE_DIGITIZER
, 0x2};
251 static const BYTE Touchscreen
[2] = {HID_USAGE_PAGE_DIGITIZER
, 0x4};
252 static const BYTE Touchpad
[2] = {HID_USAGE_PAGE_DIGITIZER
, 0x5};
254 struct udev_device
*parent
= dev
;
256 /* Look to the parents until we get a clue */
259 if (udev_device_get_property_value(parent
, "ID_INPUT_MOUSE"))
261 else if (udev_device_get_property_value(parent
, "ID_INPUT_KEYBOARD"))
263 else if (udev_device_get_property_value(parent
, "ID_INPUT_JOYSTICK"))
265 else if (udev_device_get_property_value(parent
, "ID_INPUT_KEY"))
267 else if (udev_device_get_property_value(parent
, "ID_INPUT_TOUCHPAD"))
269 else if (udev_device_get_property_value(parent
, "ID_INPUT_TOUCHSCREEN"))
271 else if (udev_device_get_property_value(parent
, "ID_INPUT_TABLET"))
274 parent
= udev_device_get_parent_with_subsystem_devtype(parent
, "input", NULL
);
279 static void set_abs_axis_value(struct wine_input_private
*ext
, int code
, int value
)
282 /* check for hatswitches */
283 if (code
<= ABS_HAT3Y
&& code
>= ABS_HAT0X
)
285 index
= code
- ABS_HAT0X
;
286 ext
->hat_values
[index
] = value
;
287 if ((code
- ABS_HAT0X
) % 2)
289 if (ext
->hat_values
[index
] == 0)
291 if (ext
->hat_values
[index
+1] == 0)
293 else if (ext
->hat_values
[index
+1] < 0)
298 else if (ext
->hat_values
[index
] > 0)
300 if (ext
->hat_values
[index
+1] == 0)
302 else if (ext
->hat_values
[index
+1] < 0)
309 if (ext
->hat_values
[index
+1] == 0)
311 else if (ext
->hat_values
[index
+1] < 0)
316 ext
->current_report_buffer
[ext
->hat_map
[index
]] = value
;
318 else if (code
< HID_ABS_MAX
&& ABS_TO_HID_MAP
[code
][0] != 0)
320 index
= ext
->abs_map
[code
].report_index
;
321 *((DWORD
*)&ext
->current_report_buffer
[index
]) = LE_DWORD(value
);
325 static void set_rel_axis_value(struct wine_input_private
*ext
, int code
, int value
)
328 if (code
< HID_REL_MAX
&& REL_TO_HID_MAP
[code
][0] != 0)
330 index
= ext
->rel_map
[code
];
331 if (value
> 127) value
= 127;
332 if (value
< -127) value
= -127;
333 ext
->current_report_buffer
[index
] = value
;
337 static INT
count_buttons(int device_fd
, BYTE
*map
)
340 int button_count
= 0;
341 BYTE keybits
[(KEY_MAX
+7)/8];
343 if (ioctl(device_fd
, EVIOCGBIT(EV_KEY
, sizeof(keybits
)), keybits
) == -1)
345 WARN("ioctl(EVIOCGBIT, EV_KEY) failed: %d %s\n", errno
, strerror(errno
));
349 for (i
= BTN_MISC
; i
< KEY_MAX
; i
++)
351 if (test_bit(keybits
, i
))
353 if (map
) map
[i
] = button_count
;
360 static INT
count_abs_axis(int device_fd
)
362 BYTE absbits
[(ABS_MAX
+7)/8];
366 if (ioctl(device_fd
, EVIOCGBIT(EV_ABS
, sizeof(absbits
)), absbits
) == -1)
368 WARN("ioctl(EVIOCGBIT, EV_ABS) failed: %d %s\n", errno
, strerror(errno
));
372 for (i
= 0; i
< HID_ABS_MAX
; i
++)
373 if (test_bit(absbits
, i
) &&
374 (ABS_TO_HID_MAP
[i
][1] >= HID_USAGE_GENERIC_X
&&
375 ABS_TO_HID_MAP
[i
][1] <= HID_USAGE_GENERIC_WHEEL
))
380 static BOOL
build_report_descriptor(struct wine_input_private
*ext
, struct udev_device
*dev
)
382 int abs_pages
[TOP_ABS_PAGE
][HID_ABS_MAX
+1];
383 int rel_pages
[TOP_REL_PAGE
][HID_REL_MAX
+1];
384 BYTE absbits
[(ABS_MAX
+7)/8];
385 BYTE relbits
[(REL_MAX
+7)/8];
387 INT i
, descript_size
;
389 INT button_count
, abs_count
, rel_count
, hat_count
;
390 const BYTE
*device_usage
= what_am_I(dev
);
392 if (ioctl(ext
->base
.device_fd
, EVIOCGBIT(EV_REL
, sizeof(relbits
)), relbits
) == -1)
394 WARN("ioctl(EVIOCGBIT, EV_REL) failed: %d %s\n", errno
, strerror(errno
));
397 if (ioctl(ext
->base
.device_fd
, EVIOCGBIT(EV_ABS
, sizeof(absbits
)), absbits
) == -1)
399 WARN("ioctl(EVIOCGBIT, EV_ABS) failed: %d %s\n", errno
, strerror(errno
));
403 descript_size
= sizeof(REPORT_HEADER
) + sizeof(REPORT_TAIL
);
406 /* For now lump all buttons just into incremental usages, Ignore Keys */
407 button_count
= count_buttons(ext
->base
.device_fd
, ext
->button_map
);
410 descript_size
+= sizeof(REPORT_BUTTONS
);
411 if (button_count
% 8)
412 descript_size
+= sizeof(REPORT_PADDING
);
413 report_size
= (button_count
+ 7) / 8;
417 memset(abs_pages
, 0, sizeof(abs_pages
));
418 for (i
= 0; i
< HID_ABS_MAX
; i
++)
419 if (test_bit(absbits
, i
))
421 abs_pages
[ABS_TO_HID_MAP
[i
][0]][0]++;
422 abs_pages
[ABS_TO_HID_MAP
[i
][0]][abs_pages
[ABS_TO_HID_MAP
[i
][0]][0]] = i
;
424 ioctl(ext
->base
.device_fd
, EVIOCGABS(i
), &(ext
->abs_map
[i
]));
425 if (abs_pages
[ABS_TO_HID_MAP
[i
][0]][0] == 1)
427 descript_size
+= sizeof(REPORT_AXIS_HEADER
);
428 descript_size
+= sizeof(REPORT_ABS_AXIS_TAIL
);
431 /* Skip page 0, aka HID_USAGE_PAGE_UNDEFINED */
432 for (i
= 1; i
< TOP_ABS_PAGE
; i
++)
433 if (abs_pages
[i
][0] > 0)
436 descript_size
+= sizeof(REPORT_AXIS_USAGE
) * abs_pages
[i
][0];
437 for (j
= 1; j
<= abs_pages
[i
][0]; j
++)
439 ext
->abs_map
[abs_pages
[i
][j
]].report_index
= report_size
;
446 memset(rel_pages
, 0, sizeof(rel_pages
));
447 for (i
= 0; i
< HID_REL_MAX
; i
++)
448 if (test_bit(relbits
, i
))
450 rel_pages
[REL_TO_HID_MAP
[i
][0]][0]++;
451 rel_pages
[REL_TO_HID_MAP
[i
][0]][rel_pages
[REL_TO_HID_MAP
[i
][0]][0]] = i
;
452 if (rel_pages
[REL_TO_HID_MAP
[i
][0]][0] == 1)
454 descript_size
+= sizeof(REPORT_AXIS_HEADER
);
455 descript_size
+= sizeof(REPORT_REL_AXIS_TAIL
);
458 /* Skip page 0, aka HID_USAGE_PAGE_UNDEFINED */
459 for (i
= 1; i
< TOP_REL_PAGE
; i
++)
460 if (rel_pages
[i
][0] > 0)
463 descript_size
+= sizeof(REPORT_AXIS_USAGE
) * rel_pages
[i
][0];
464 for (j
= 1; j
<= rel_pages
[i
][0]; j
++)
466 ext
->rel_map
[rel_pages
[i
][j
]] = report_size
;
473 for (i
= ABS_HAT0X
; i
<=ABS_HAT3X
; i
+=2)
474 if (test_bit(absbits
, i
))
476 ext
->hat_map
[i
- ABS_HAT0X
] = report_size
;
477 ext
->hat_values
[i
- ABS_HAT0X
] = 0;
478 ext
->hat_values
[i
- ABS_HAT0X
+ 1] = 0;
483 TRACE("Report Descriptor will be %i bytes\n", descript_size
);
484 TRACE("Report will be %i bytes\n", report_size
);
486 ext
->report_descriptor
= HeapAlloc(GetProcessHeap(), 0, descript_size
);
487 if (!ext
->report_descriptor
)
489 ERR("Failed to alloc report descriptor\n");
492 report_ptr
= ext
->report_descriptor
;
494 memcpy(report_ptr
, REPORT_HEADER
, sizeof(REPORT_HEADER
));
495 report_ptr
[IDX_HEADER_PAGE
] = device_usage
[0];
496 report_ptr
[IDX_HEADER_USAGE
] = device_usage
[1];
497 report_ptr
+= sizeof(REPORT_HEADER
);
500 report_ptr
= add_button_block(report_ptr
, 1, button_count
);
501 if (button_count
% 8)
503 BYTE padding
= 8 - (button_count
% 8);
504 report_ptr
= add_padding_block(report_ptr
, padding
);
509 for (i
= 1; i
< TOP_ABS_PAGE
; i
++)
513 BYTE usages
[HID_ABS_MAX
];
515 for (j
= 0; j
< abs_pages
[i
][0]; j
++)
516 usages
[j
] = ABS_TO_HID_MAP
[abs_pages
[i
][j
+1]][1];
517 report_ptr
= add_axis_block(report_ptr
, abs_pages
[i
][0], i
, usages
, TRUE
, &ext
->abs_map
[abs_pages
[i
][1]]);
523 for (i
= 1; i
< TOP_REL_PAGE
; i
++)
527 BYTE usages
[HID_REL_MAX
];
529 for (j
= 0; j
< rel_pages
[i
][0]; j
++)
530 usages
[j
] = REL_TO_HID_MAP
[rel_pages
[i
][j
+1]][1];
531 report_ptr
= add_axis_block(report_ptr
, rel_pages
[i
][0], i
, usages
, FALSE
, NULL
);
536 report_ptr
= add_hatswitch(report_ptr
, hat_count
);
538 memcpy(report_ptr
, REPORT_TAIL
, sizeof(REPORT_TAIL
));
540 ext
->report_descriptor_size
= descript_size
;
541 ext
->buffer_length
= report_size
;
542 ext
->current_report_buffer
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, report_size
);
543 if (ext
->current_report_buffer
== NULL
)
545 ERR("Failed to alloc report buffer\n");
546 HeapFree(GetProcessHeap(), 0, ext
->report_descriptor
);
549 ext
->last_report_buffer
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, report_size
);
550 if (ext
->last_report_buffer
== NULL
)
552 ERR("Failed to alloc report buffer\n");
553 HeapFree(GetProcessHeap(), 0, ext
->report_descriptor
);
554 HeapFree(GetProcessHeap(), 0, ext
->current_report_buffer
);
557 ext
->report_state
= FIRST
;
559 /* Initialize axis in the report */
560 for (i
= 0; i
< HID_ABS_MAX
; i
++)
561 if (test_bit(absbits
, i
))
562 set_abs_axis_value(ext
, i
, ext
->abs_map
[i
].info
.value
);
567 static BOOL
set_report_from_event(struct wine_input_private
*ext
, struct input_event
*ie
)
576 if (ext
->report_state
== NORMAL
)
578 memcpy(ext
->last_report_buffer
, ext
->current_report_buffer
, ext
->buffer_length
);
583 if (ext
->report_state
== DROPPED
)
584 memcpy(ext
->current_report_buffer
, ext
->last_report_buffer
, ext
->buffer_length
);
585 ext
->report_state
= NORMAL
;
589 TRACE_(hid_report
)("received SY_DROPPED\n");
590 ext
->report_state
= DROPPED
;
599 set_button_value(ext
->button_map
[ie
->code
], ie
->value
, ext
->current_report_buffer
);
602 set_abs_axis_value(ext
, ie
->code
, ie
->value
);
605 set_rel_axis_value(ext
, ie
->code
, ie
->value
);
608 ERR("TODO: Process Report (%i, %i)\n",ie
->type
, ie
->code
);
614 static inline WCHAR
*strdupAtoW(const char *src
)
618 if (!src
) return NULL
;
619 len
= MultiByteToWideChar(CP_UNIXCP
, 0, src
, -1, NULL
, 0);
620 if ((dst
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
))))
621 MultiByteToWideChar(CP_UNIXCP
, 0, src
, -1, dst
, len
);
625 static WCHAR
*get_sysattr_string(struct udev_device
*dev
, const char *sysattr
)
627 const char *attr
= udev_device_get_sysattr_value(dev
, sysattr
);
630 WARN("Could not get %s from device\n", sysattr
);
633 return strdupAtoW(attr
);
636 static int compare_platform_device(DEVICE_OBJECT
*device
, void *platform_dev
)
638 struct udev_device
*dev1
= impl_from_DEVICE_OBJECT(device
)->udev_device
;
639 struct udev_device
*dev2
= platform_dev
;
640 return strcmp(udev_device_get_syspath(dev1
), udev_device_get_syspath(dev2
));
643 static NTSTATUS
hidraw_get_reportdescriptor(DEVICE_OBJECT
*device
, BYTE
*buffer
, DWORD length
, DWORD
*out_length
)
645 #ifdef HAVE_LINUX_HIDRAW_H
646 struct hidraw_report_descriptor descriptor
;
647 struct platform_private
*private = impl_from_DEVICE_OBJECT(device
);
649 if (ioctl(private->device_fd
, HIDIOCGRDESCSIZE
, &descriptor
.size
) == -1)
651 WARN("ioctl(HIDIOCGRDESCSIZE) failed: %d %s\n", errno
, strerror(errno
));
652 return STATUS_UNSUCCESSFUL
;
655 *out_length
= descriptor
.size
;
657 if (length
< descriptor
.size
)
658 return STATUS_BUFFER_TOO_SMALL
;
659 if (!descriptor
.size
)
660 return STATUS_SUCCESS
;
662 if (ioctl(private->device_fd
, HIDIOCGRDESC
, &descriptor
) == -1)
664 WARN("ioctl(HIDIOCGRDESC) failed: %d %s\n", errno
, strerror(errno
));
665 return STATUS_UNSUCCESSFUL
;
668 memcpy(buffer
, descriptor
.value
, descriptor
.size
);
669 return STATUS_SUCCESS
;
671 return STATUS_NOT_IMPLEMENTED
;
675 static NTSTATUS
hidraw_get_string(DEVICE_OBJECT
*device
, DWORD index
, WCHAR
*buffer
, DWORD length
)
677 struct udev_device
*hiddev
;
678 struct platform_private
*private = impl_from_DEVICE_OBJECT(device
);
681 hiddev
= udev_device_get_parent_with_subsystem_devtype(private->udev_device
, "hid", NULL
);
686 case HID_STRING_ID_IPRODUCT
:
687 str
= get_sysattr_string(hiddev
, "product");
689 case HID_STRING_ID_IMANUFACTURER
:
690 str
= get_sysattr_string(hiddev
, "manufacturer");
692 case HID_STRING_ID_ISERIALNUMBER
:
693 str
= get_sysattr_string(hiddev
, "serial");
696 ERR("Unhandled string index %08x\n", index
);
697 return STATUS_NOT_IMPLEMENTED
;
702 #ifdef HAVE_LINUX_HIDRAW_H
705 case HID_STRING_ID_IPRODUCT
:
708 if (ioctl(private->device_fd
, HIDIOCGRAWNAME(MAX_PATH
), buf
) == -1)
709 WARN("ioctl(HIDIOCGRAWNAME) failed: %d %s\n", errno
, strerror(errno
));
711 str
= strdupAtoW(buf
);
714 case HID_STRING_ID_IMANUFACTURER
:
716 case HID_STRING_ID_ISERIALNUMBER
:
719 ERR("Unhandled string index %08x\n", index
);
720 return STATUS_NOT_IMPLEMENTED
;
723 return STATUS_NOT_IMPLEMENTED
;
729 if (!length
) return STATUS_BUFFER_TOO_SMALL
;
731 return STATUS_SUCCESS
;
734 if (length
<= strlenW(str
))
736 HeapFree(GetProcessHeap(), 0, str
);
737 return STATUS_BUFFER_TOO_SMALL
;
740 strcpyW(buffer
, str
);
741 HeapFree(GetProcessHeap(), 0, str
);
742 return STATUS_SUCCESS
;
745 static DWORD CALLBACK
device_report_thread(void *args
)
747 DEVICE_OBJECT
*device
= (DEVICE_OBJECT
*)args
;
748 struct platform_private
*private = impl_from_DEVICE_OBJECT(device
);
749 struct pollfd plfds
[2];
751 plfds
[0].fd
= private->device_fd
;
752 plfds
[0].events
= POLLIN
;
753 plfds
[0].revents
= 0;
754 plfds
[1].fd
= private->control_pipe
[0];
755 plfds
[1].events
= POLLIN
;
756 plfds
[1].revents
= 0;
761 BYTE report_buffer
[1024];
763 if (poll(plfds
, 2, -1) <= 0) continue;
764 if (plfds
[1].revents
)
766 size
= read(plfds
[0].fd
, report_buffer
, sizeof(report_buffer
));
768 TRACE_(hid_report
)("Read failed. Likely an unplugged device\n");
770 TRACE_(hid_report
)("Failed to read report\n");
772 process_hid_report(device
, report_buffer
, size
);
777 static NTSTATUS
begin_report_processing(DEVICE_OBJECT
*device
)
779 struct platform_private
*private = impl_from_DEVICE_OBJECT(device
);
781 if (private->report_thread
)
782 return STATUS_SUCCESS
;
784 if (pipe(private->control_pipe
) != 0)
786 ERR("Control pipe creation failed\n");
787 return STATUS_UNSUCCESSFUL
;
790 private->report_thread
= CreateThread(NULL
, 0, device_report_thread
, device
, 0, NULL
);
791 if (!private->report_thread
)
793 ERR("Unable to create device report thread\n");
794 close(private->control_pipe
[0]);
795 close(private->control_pipe
[1]);
796 return STATUS_UNSUCCESSFUL
;
799 return STATUS_SUCCESS
;
802 static NTSTATUS
hidraw_set_output_report(DEVICE_OBJECT
*device
, UCHAR id
, BYTE
*report
, DWORD length
, ULONG_PTR
*written
)
804 struct platform_private
* ext
= impl_from_DEVICE_OBJECT(device
);
808 rc
= write(ext
->device_fd
, report
, length
);
811 BYTE report_buffer
[1024];
813 if (length
+ 1 > sizeof(report_buffer
))
815 ERR("Output report buffer too small\n");
816 return STATUS_UNSUCCESSFUL
;
819 report_buffer
[0] = 0;
820 memcpy(&report_buffer
[1], report
, length
);
821 rc
= write(ext
->device_fd
, report_buffer
, length
+ 1);
826 return STATUS_SUCCESS
;
831 return STATUS_UNSUCCESSFUL
;
835 static NTSTATUS
hidraw_get_feature_report(DEVICE_OBJECT
*device
, UCHAR id
, BYTE
*report
, DWORD length
, ULONG_PTR
*read
)
837 #if defined(HAVE_LINUX_HIDRAW_H) && defined(HIDIOCGFEATURE)
839 struct platform_private
* ext
= impl_from_DEVICE_OBJECT(device
);
841 length
= min(length
, 0x1fff);
842 rc
= ioctl(ext
->device_fd
, HIDIOCGFEATURE(length
), report
);
846 return STATUS_SUCCESS
;
851 return STATUS_UNSUCCESSFUL
;
855 return STATUS_NOT_IMPLEMENTED
;
859 static NTSTATUS
hidraw_set_feature_report(DEVICE_OBJECT
*device
, UCHAR id
, BYTE
*report
, DWORD length
, ULONG_PTR
*written
)
861 #if defined(HAVE_LINUX_HIDRAW_H) && defined(HIDIOCSFEATURE)
863 struct platform_private
* ext
= impl_from_DEVICE_OBJECT(device
);
864 BYTE
*feature_buffer
;
869 if (length
+ 1 > sizeof(buffer
))
871 ERR("Output feature buffer too small\n");
872 return STATUS_UNSUCCESSFUL
;
875 memcpy(&buffer
[1], report
, length
);
876 feature_buffer
= buffer
;
880 feature_buffer
= report
;
881 length
= min(length
, 0x1fff);
882 rc
= ioctl(ext
->device_fd
, HIDIOCSFEATURE(length
), feature_buffer
);
886 return STATUS_SUCCESS
;
891 return STATUS_UNSUCCESSFUL
;
895 return STATUS_NOT_IMPLEMENTED
;
899 static const platform_vtbl hidraw_vtbl
=
901 compare_platform_device
,
902 hidraw_get_reportdescriptor
,
904 begin_report_processing
,
905 hidraw_set_output_report
,
906 hidraw_get_feature_report
,
907 hidraw_set_feature_report
,
910 #ifdef HAS_PROPER_INPUT_HEADER
912 static inline struct wine_input_private
*input_impl_from_DEVICE_OBJECT(DEVICE_OBJECT
*device
)
914 return (struct wine_input_private
*)get_platform_private(device
);
917 static NTSTATUS
lnxev_get_reportdescriptor(DEVICE_OBJECT
*device
, BYTE
*buffer
, DWORD length
, DWORD
*out_length
)
919 struct wine_input_private
*ext
= input_impl_from_DEVICE_OBJECT(device
);
921 *out_length
= ext
->report_descriptor_size
;
923 if (length
< ext
->report_descriptor_size
)
924 return STATUS_BUFFER_TOO_SMALL
;
926 memcpy(buffer
, ext
->report_descriptor
, ext
->report_descriptor_size
);
928 return STATUS_SUCCESS
;
931 static NTSTATUS
lnxev_get_string(DEVICE_OBJECT
*device
, DWORD index
, WCHAR
*buffer
, DWORD length
)
933 struct wine_input_private
*ext
= input_impl_from_DEVICE_OBJECT(device
);
939 case HID_STRING_ID_IPRODUCT
:
940 ioctl(ext
->base
.device_fd
, EVIOCGNAME(sizeof(str
)), str
);
942 case HID_STRING_ID_IMANUFACTURER
:
945 case HID_STRING_ID_ISERIALNUMBER
:
946 ioctl(ext
->base
.device_fd
, EVIOCGUNIQ(sizeof(str
)), str
);
949 ERR("Unhandled string index %i\n", index
);
952 MultiByteToWideChar(CP_ACP
, 0, str
, -1, buffer
, length
);
953 return STATUS_SUCCESS
;
956 static DWORD CALLBACK
lnxev_device_report_thread(void *args
)
958 DEVICE_OBJECT
*device
= (DEVICE_OBJECT
*)args
;
959 struct wine_input_private
*private = input_impl_from_DEVICE_OBJECT(device
);
960 struct pollfd plfds
[2];
962 plfds
[0].fd
= private->base
.device_fd
;
963 plfds
[0].events
= POLLIN
;
964 plfds
[0].revents
= 0;
965 plfds
[1].fd
= private->base
.control_pipe
[0];
966 plfds
[1].events
= POLLIN
;
967 plfds
[1].revents
= 0;
972 struct input_event ie
;
974 if (poll(plfds
, 2, -1) <= 0) continue;
975 if (plfds
[1].revents
|| !private->current_report_buffer
|| private->buffer_length
== 0)
977 size
= read(plfds
[0].fd
, &ie
, sizeof(ie
));
979 TRACE_(hid_report
)("Read failed. Likely an unplugged device\n");
981 TRACE_(hid_report
)("Failed to read report\n");
982 else if (set_report_from_event(private, &ie
))
983 process_hid_report(device
, private->current_report_buffer
, private->buffer_length
);
988 static NTSTATUS
lnxev_begin_report_processing(DEVICE_OBJECT
*device
)
990 struct wine_input_private
*private = input_impl_from_DEVICE_OBJECT(device
);
992 if (private->base
.report_thread
)
993 return STATUS_SUCCESS
;
995 if (pipe(private->base
.control_pipe
) != 0)
997 ERR("Control pipe creation failed\n");
998 return STATUS_UNSUCCESSFUL
;
1001 private->base
.report_thread
= CreateThread(NULL
, 0, lnxev_device_report_thread
, device
, 0, NULL
);
1002 if (!private->base
.report_thread
)
1004 ERR("Unable to create device report thread\n");
1005 close(private->base
.control_pipe
[0]);
1006 close(private->base
.control_pipe
[1]);
1007 return STATUS_UNSUCCESSFUL
;
1009 return STATUS_SUCCESS
;
1012 static NTSTATUS
lnxev_set_output_report(DEVICE_OBJECT
*device
, UCHAR id
, BYTE
*report
, DWORD length
, ULONG_PTR
*written
)
1015 return STATUS_NOT_IMPLEMENTED
;
1018 static NTSTATUS
lnxev_get_feature_report(DEVICE_OBJECT
*device
, UCHAR id
, BYTE
*report
, DWORD length
, ULONG_PTR
*read
)
1021 return STATUS_NOT_IMPLEMENTED
;
1024 static NTSTATUS
lnxev_set_feature_report(DEVICE_OBJECT
*device
, UCHAR id
, BYTE
*report
, DWORD length
, ULONG_PTR
*written
)
1027 return STATUS_NOT_IMPLEMENTED
;
1030 static const platform_vtbl lnxev_vtbl
= {
1031 compare_platform_device
,
1032 lnxev_get_reportdescriptor
,
1034 lnxev_begin_report_processing
,
1035 lnxev_set_output_report
,
1036 lnxev_get_feature_report
,
1037 lnxev_set_feature_report
,
1041 static int check_same_device(DEVICE_OBJECT
*device
, void* context
)
1043 return !compare_platform_device(device
, context
);
1046 static int parse_uevent_info(const char *uevent
, DWORD
*vendor_id
,
1047 DWORD
*product_id
, WCHAR
**serial_number
)
1051 char *saveptr
= NULL
;
1057 int found_serial
= 0;
1059 tmp
= heap_alloc(strlen(uevent
) + 1);
1060 strcpy(tmp
, uevent
);
1061 line
= strtok_r(tmp
, "\n", &saveptr
);
1062 while (line
!= NULL
)
1064 /* line: "KEY=value" */
1066 value
= strchr(line
, '=');
1074 if (strcmp(key
, "HID_ID") == 0)
1077 * type vendor product
1078 * HID_ID=0003:000005AC:00008242
1080 int ret
= sscanf(value
, "%x:%x:%x", &bus_type
, vendor_id
, product_id
);
1084 else if (strcmp(key
, "HID_UNIQ") == 0)
1086 /* The caller has to free the serial number */
1089 *serial_number
= (WCHAR
*)strdupAtoW(value
);
1095 line
= strtok_r(NULL
, "\n", &saveptr
);
1099 return (found_id
&& found_serial
);
1102 static void try_add_device(struct udev_device
*dev
)
1104 DWORD vid
= 0, pid
= 0, version
= 0;
1105 struct udev_device
*hiddev
= NULL
;
1106 DEVICE_OBJECT
*device
= NULL
;
1107 const char *subsystem
;
1108 const char *devnode
;
1109 WCHAR
*serial
= NULL
;
1110 BOOL is_gamepad
= FALSE
;
1112 static const CHAR
*base_serial
= "0000";
1114 if (!(devnode
= udev_device_get_devnode(dev
)))
1117 if ((fd
= open(devnode
, O_RDWR
)) == -1)
1119 WARN("Unable to open udev device %s: %s\n", debugstr_a(devnode
), strerror(errno
));
1123 subsystem
= udev_device_get_subsystem(dev
);
1124 hiddev
= udev_device_get_parent_with_subsystem_devtype(dev
, "hid", NULL
);
1127 #ifdef HAS_PROPER_INPUT_HEADER
1128 const platform_vtbl
*other_vtbl
= NULL
;
1129 DEVICE_OBJECT
*dup
= NULL
;
1130 if (strcmp(subsystem
, "hidraw") == 0)
1131 other_vtbl
= &lnxev_vtbl
;
1132 else if (strcmp(subsystem
, "input") == 0)
1133 other_vtbl
= &hidraw_vtbl
;
1136 dup
= bus_enumerate_hid_devices(other_vtbl
, check_same_device
, dev
);
1139 TRACE("Duplicate cross bus device (%p) found, not adding the new one\n", dup
);
1144 parse_uevent_info(udev_device_get_sysattr_value(hiddev
, "uevent"),
1145 &vid
, &pid
, &serial
);
1147 serial
= strdupAtoW(base_serial
);
1149 #ifdef HAS_PROPER_INPUT_HEADER
1152 struct input_id device_id
= {0};
1153 char device_uid
[255];
1155 if (ioctl(fd
, EVIOCGID
, &device_id
) < 0)
1156 WARN("ioctl(EVIOCGID) failed: %d %s\n", errno
, strerror(errno
));
1158 if (ioctl(fd
, EVIOCGUNIQ(254), device_uid
) >= 0 && device_uid
[0])
1159 serial
= strdupAtoW(device_uid
);
1161 vid
= device_id
.vendor
;
1162 pid
= device_id
.product
;
1163 version
= device_id
.version
;
1167 WARN("Could not get device to query VID, PID, Version and Serial\n");
1170 if (is_xbox_gamepad(vid
, pid
))
1172 #ifdef HAS_PROPER_INPUT_HEADER
1175 int axes
=0, buttons
=0;
1176 axes
= count_abs_axis(fd
);
1177 buttons
= count_buttons(fd
, NULL
);
1178 is_gamepad
= (axes
== 6 && buttons
>= 14);
1183 TRACE("Found udev device %s (vid %04x, pid %04x, version %u, serial %s)\n",
1184 debugstr_a(devnode
), vid
, pid
, version
, debugstr_w(serial
));
1186 if (strcmp(subsystem
, "hidraw") == 0)
1188 device
= bus_create_hid_device(udev_driver_obj
, hidraw_busidW
, vid
, pid
, version
, 0, serial
, is_gamepad
,
1189 &GUID_DEVCLASS_HIDRAW
, &hidraw_vtbl
, sizeof(struct platform_private
));
1191 #ifdef HAS_PROPER_INPUT_HEADER
1192 else if (strcmp(subsystem
, "input") == 0)
1194 device
= bus_create_hid_device(udev_driver_obj
, lnxev_busidW
, vid
, pid
, version
, 0, serial
, is_gamepad
,
1195 &GUID_DEVCLASS_LINUXEVENT
, &lnxev_vtbl
, sizeof(struct wine_input_private
));
1201 struct platform_private
*private = impl_from_DEVICE_OBJECT(device
);
1202 private->udev_device
= udev_device_ref(dev
);
1203 private->device_fd
= fd
;
1204 #ifdef HAS_PROPER_INPUT_HEADER
1205 if (strcmp(subsystem
, "input") == 0)
1206 if (!build_report_descriptor((struct wine_input_private
*)private, dev
))
1208 ERR("Building report descriptor failed, removing device\n");
1210 udev_device_unref(dev
);
1211 bus_remove_hid_device(device
);
1212 HeapFree(GetProcessHeap(), 0, serial
);
1216 IoInvalidateDeviceRelations(device
, BusRelations
);
1220 WARN("Ignoring device %s with subsystem %s\n", debugstr_a(devnode
), subsystem
);
1224 HeapFree(GetProcessHeap(), 0, serial
);
1227 static void try_remove_device(struct udev_device
*dev
)
1229 DEVICE_OBJECT
*device
= NULL
;
1230 struct platform_private
* private;
1231 #ifdef HAS_PROPER_INPUT_HEADER
1232 BOOL is_input
= FALSE
;
1235 device
= bus_find_hid_device(&hidraw_vtbl
, dev
);
1236 #ifdef HAS_PROPER_INPUT_HEADER
1239 device
= bus_find_hid_device(&lnxev_vtbl
, dev
);
1243 if (!device
) return;
1245 IoInvalidateDeviceRelations(device
, RemovalRelations
);
1247 private = impl_from_DEVICE_OBJECT(device
);
1249 if (private->report_thread
)
1251 write(private->control_pipe
[1], "q", 1);
1252 WaitForSingleObject(private->report_thread
, INFINITE
);
1253 close(private->control_pipe
[0]);
1254 close(private->control_pipe
[1]);
1255 CloseHandle(private->report_thread
);
1256 #ifdef HAS_PROPER_INPUT_HEADER
1257 if (strcmp(udev_device_get_subsystem(dev
), "input") == 0)
1259 HeapFree(GetProcessHeap(), 0, ((struct wine_input_private
*)private)->current_report_buffer
);
1260 HeapFree(GetProcessHeap(), 0, ((struct wine_input_private
*)private)->last_report_buffer
);
1265 #ifdef HAS_PROPER_INPUT_HEADER
1268 struct wine_input_private
*ext
= (struct wine_input_private
*)private;
1269 HeapFree(GetProcessHeap(), 0, ext
->report_descriptor
);
1273 dev
= private->udev_device
;
1274 close(private->device_fd
);
1275 bus_remove_hid_device(device
);
1276 udev_device_unref(dev
);
1279 static void build_initial_deviceset(void)
1281 struct udev_enumerate
*enumerate
;
1282 struct udev_list_entry
*devices
, *dev_list_entry
;
1284 enumerate
= udev_enumerate_new(udev_context
);
1287 WARN("Unable to create udev enumeration object\n");
1291 if (!disable_hidraw
)
1292 if (udev_enumerate_add_match_subsystem(enumerate
, "hidraw") < 0)
1293 WARN("Failed to add subsystem 'hidraw' to enumeration\n");
1294 #ifdef HAS_PROPER_INPUT_HEADER
1297 if (udev_enumerate_add_match_subsystem(enumerate
, "input") < 0)
1298 WARN("Failed to add subsystem 'input' to enumeration\n");
1302 if (udev_enumerate_scan_devices(enumerate
) < 0)
1303 WARN("Enumeration scan failed\n");
1305 devices
= udev_enumerate_get_list_entry(enumerate
);
1306 udev_list_entry_foreach(dev_list_entry
, devices
)
1308 struct udev_device
*dev
;
1311 path
= udev_list_entry_get_name(dev_list_entry
);
1312 if ((dev
= udev_device_new_from_syspath(udev_context
, path
)))
1314 try_add_device(dev
);
1315 udev_device_unref(dev
);
1319 udev_enumerate_unref(enumerate
);
1322 static struct udev_monitor
*create_monitor(struct pollfd
*pfd
)
1324 struct udev_monitor
*monitor
;
1327 monitor
= udev_monitor_new_from_netlink(udev_context
, "udev");
1330 WARN("Unable to get udev monitor object\n");
1334 if (!disable_hidraw
)
1336 if (udev_monitor_filter_add_match_subsystem_devtype(monitor
, "hidraw", NULL
) < 0)
1337 WARN("Failed to add 'hidraw' subsystem to monitor\n");
1341 #ifdef HAS_PROPER_INPUT_HEADER
1344 if (udev_monitor_filter_add_match_subsystem_devtype(monitor
, "input", NULL
) < 0)
1345 WARN("Failed to add 'input' subsystem to monitor\n");
1352 WARN("No subsystems added to monitor\n");
1356 if (udev_monitor_enable_receiving(monitor
) < 0)
1359 if ((pfd
->fd
= udev_monitor_get_fd(monitor
)) >= 0)
1361 pfd
->events
= POLLIN
;
1366 WARN("Failed to start monitoring\n");
1367 udev_monitor_unref(monitor
);
1371 static void process_monitor_event(struct udev_monitor
*monitor
)
1373 struct udev_device
*dev
;
1376 dev
= udev_monitor_receive_device(monitor
);
1379 FIXME("Failed to get device that has changed\n");
1383 action
= udev_device_get_action(dev
);
1384 TRACE("Received action %s for udev device %s\n", debugstr_a(action
),
1385 debugstr_a(udev_device_get_devnode(dev
)));
1388 WARN("No action received\n");
1389 else if (strcmp(action
, "add") == 0)
1390 try_add_device(dev
);
1391 else if (strcmp(action
, "remove") == 0)
1392 try_remove_device(dev
);
1394 WARN("Unhandled action %s\n", debugstr_a(action
));
1396 udev_device_unref(dev
);
1399 static DWORD CALLBACK
deviceloop_thread(void *args
)
1401 struct udev_monitor
*monitor
;
1402 HANDLE init_done
= args
;
1405 monitor
= create_monitor(&pfd
);
1406 build_initial_deviceset();
1407 SetEvent(init_done
);
1411 if (poll(&pfd
, 1, -1) <= 0) continue;
1412 process_monitor_event(monitor
);
1415 TRACE("Monitor thread exiting\n");
1417 udev_monitor_unref(monitor
);
1421 void udev_driver_unload( void )
1423 TRACE("Unload Driver\n");
1426 NTSTATUS WINAPI
udev_driver_init(DRIVER_OBJECT
*driver
, UNICODE_STRING
*registry_path
)
1430 static const WCHAR hidraw_disabledW
[] = {'D','i','s','a','b','l','e','H','i','d','r','a','w',0};
1431 static const UNICODE_STRING hidraw_disabled
= {sizeof(hidraw_disabledW
) - sizeof(WCHAR
), sizeof(hidraw_disabledW
), (WCHAR
*)hidraw_disabledW
};
1432 static const WCHAR input_disabledW
[] = {'D','i','s','a','b','l','e','I','n','p','u','t',0};
1433 static const UNICODE_STRING input_disabled
= {sizeof(input_disabledW
) - sizeof(WCHAR
), sizeof(input_disabledW
), (WCHAR
*)input_disabledW
};
1435 TRACE("(%p, %s)\n", driver
, debugstr_w(registry_path
->Buffer
));
1437 if (!(udev_context
= udev_new()))
1439 ERR("Can't create udev object\n");
1440 return STATUS_UNSUCCESSFUL
;
1443 udev_driver_obj
= driver
;
1444 driver
->MajorFunction
[IRP_MJ_PNP
] = common_pnp_dispatch
;
1445 driver
->MajorFunction
[IRP_MJ_INTERNAL_DEVICE_CONTROL
] = hid_internal_dispatch
;
1447 disable_hidraw
= check_bus_option(registry_path
, &hidraw_disabled
, 0);
1449 TRACE("UDEV hidraw devices disabled in registry\n");
1451 #ifdef HAS_PROPER_INPUT_HEADER
1452 disable_input
= check_bus_option(registry_path
, &input_disabled
, 0);
1454 TRACE("UDEV input devices disabled in registry\n");
1457 if (!(events
[0] = CreateEventW(NULL
, TRUE
, FALSE
, NULL
)))
1459 if (!(events
[1] = CreateThread(NULL
, 0, deviceloop_thread
, events
[0], 0, NULL
)))
1461 CloseHandle(events
[0]);
1465 result
= WaitForMultipleObjects(2, events
, FALSE
, INFINITE
);
1466 CloseHandle(events
[0]);
1467 CloseHandle(events
[1]);
1468 if (result
== WAIT_OBJECT_0
)
1470 TRACE("Initialization successful\n");
1471 return STATUS_SUCCESS
;
1475 ERR("Failed to initialize udev device thread\n");
1476 udev_unref(udev_context
);
1477 udev_context
= NULL
;
1478 udev_driver_obj
= NULL
;
1479 return STATUS_UNSUCCESSFUL
;
1484 NTSTATUS WINAPI
udev_driver_init(DRIVER_OBJECT
*driver
, UNICODE_STRING
*registry_path
)
1486 WARN("Wine was compiled without UDEV support\n");
1487 return STATUS_NOT_IMPLEMENTED
;
1490 void udev_driver_unload( void )
1492 TRACE("Stub: Unload Driver\n");
1495 #endif /* HAVE_UDEV */