winebus.sys: Add initial udev stub driver. (v7)

Sebastian Lackner sebastian at fds-team.de
Thu Sep 8 03:12:50 CDT 2016


From: Aric Stewart <aric at codeweavers.com>

Signed-off-by: Aric Stewart <aric at codeweavers.com>
Signed-off-by: Sebastian Lackner <sebastian at fds-team.de>
---

Changes in v7:
* Merge with configure changes.
* Fix pkg-config package name (at least for Archlinux, not sure about other systems).
* Do not explicitly set UDEV_LIBS, instead use the value returned by pkg-config.
* Remove udev driver unload function - winedevice does not explicitly try to unload
  drivers manually created with IoCreateDriver yet.
* Give a more meaningful message when Wine is compiled without udev support. For now
  its just a warn, but we could later promote it to a winediag FIXME.
* Do not add stub driver when udev support is not available.
* Show a FIXME for unhandled PNP functions.
* Some improvements for TRACES - when the function is called "udev_driver_init",
  a message with identical content does not add much value. Trace function arguments
  instead.
* Remove a bunch of unnecessary includes.
* Some minor style improvements.

 configure.ac                 |   14 ++++++++++
 dlls/winebus.sys/Makefile.in |    2 +
 dlls/winebus.sys/bus.h       |   23 ++++++++++++++++
 dlls/winebus.sys/bus_udev.c  |   60 +++++++++++++++++++++++++++++++++++++++++++
 dlls/winebus.sys/main.c      |   34 ++++++++++++++++++++++++
 5 files changed, 133 insertions(+)

diff --git a/configure.ac b/configure.ac
index 52b217e..c9f7fed 100644
--- a/configure.ac
+++ b/configure.ac
@@ -75,6 +75,7 @@ AC_ARG_WITH(pthread,   AS_HELP_STRING([--without-pthread],[do not use the pthrea
 AC_ARG_WITH(pulse,     AS_HELP_STRING([--without-pulse],[do not use PulseAudio sound support]))
 AC_ARG_WITH(sane,      AS_HELP_STRING([--without-sane],[do not use SANE (scanner support)]))
 AC_ARG_WITH(tiff,      AS_HELP_STRING([--without-tiff],[do not use TIFF]))
+AC_ARG_WITH(udev,      AS_HELP_STRING([--without-udev],[do not use udev (play and play support)]))
 AC_ARG_WITH(v4l,       AS_HELP_STRING([--without-v4l],[do not use v4l1 (v4l support)]))
 AC_ARG_WITH(xcomposite,AS_HELP_STRING([--without-xcomposite],[do not use the Xcomposite extension]),
             [if test "x$withval" = "xno"; then ac_cv_header_X11_extensions_Xcomposite_h=no; fi])
@@ -1519,6 +1520,19 @@ WINE_NOTICE_WITH(oss,[test "x$ac_cv_member_oss_sysinfo_numaudioengines" != xyes]
                  [OSS sound system found but too old (OSSv4 needed), OSS won't be supported.],
                  [enable_wineoss_drv])
 
+dnl **** Check for libudev ****
+if test "x$with_udev" != "xno"
+then
+    WINE_PACKAGE_FLAGS(UDEV,[libudev],,,,
+        [AC_CHECK_HEADERS(libudev.h,
+            [AC_CHECK_LIB(udev,udev_new,
+                AC_DEFINE(HAVE_UDEV,1,[Define to 1 if you have the `udev' library (-ludev).]),
+                [UDEV_LIBS=""],[$UDEV_LIBS])],
+            [UDEV_LIBS=""])])
+fi
+WINE_NOTICE_WITH(udev,[test "x$UDEV_LIBS" = "x"],
+                 [libudev ${notice_platform}development files not found, plug and play won't be supported.])
+
 dnl **** Check for capi4linux ****
 if test "x$with_capi" != "xno"
 then
diff --git a/dlls/winebus.sys/Makefile.in b/dlls/winebus.sys/Makefile.in
index d646dc3..99ff4d2 100644
--- a/dlls/winebus.sys/Makefile.in
+++ b/dlls/winebus.sys/Makefile.in
@@ -1,5 +1,7 @@
 MODULE    = winebus.sys
+IMPORTS   = ntoskrnl
 EXTRADLLFLAGS = -Wb,--subsystem,native
 
 C_SRCS = \
+	bus_udev.c \
 	main.c
diff --git a/dlls/winebus.sys/bus.h b/dlls/winebus.sys/bus.h
new file mode 100644
index 0000000..3d53a46
--- /dev/null
+++ b/dlls/winebus.sys/bus.h
@@ -0,0 +1,23 @@
+/*
+ * Copyright 2016 Aric Stewart
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/* Busses */
+NTSTATUS WINAPI udev_driver_init(DRIVER_OBJECT *driver, UNICODE_STRING *registry_path) DECLSPEC_HIDDEN;
+
+/* HID Plug and Play Bus */
+NTSTATUS WINAPI common_pnp_dispatch(DEVICE_OBJECT *device, IRP *irp) DECLSPEC_HIDDEN;
diff --git a/dlls/winebus.sys/bus_udev.c b/dlls/winebus.sys/bus_udev.c
new file mode 100644
index 0000000..f040e60
--- /dev/null
+++ b/dlls/winebus.sys/bus_udev.c
@@ -0,0 +1,60 @@
+/*
+ * Plug and Play support for hid devices found through udev
+ *
+ * Copyright 2016 CodeWeavers, Aric Stewart
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include "config.h"
+#include <stdarg.h>
+
+#define NONAMELESSUNION
+
+#include "ntstatus.h"
+#define WIN32_NO_STATUS
+#include "windef.h"
+#include "winbase.h"
+#include "winternl.h"
+#include "ddk/wdm.h"
+#include "wine/debug.h"
+
+#include "bus.h"
+
+WINE_DEFAULT_DEBUG_CHANNEL(plugplay);
+
+#ifdef HAVE_UDEV
+
+static DRIVER_OBJECT *udev_driver_obj = NULL;
+
+NTSTATUS WINAPI udev_driver_init(DRIVER_OBJECT *driver, UNICODE_STRING *registry_path)
+{
+    TRACE("(%p, %s)\n", driver, debugstr_w(registry_path->Buffer));
+
+    udev_driver_obj = driver;
+    driver->MajorFunction[IRP_MJ_PNP] = common_pnp_dispatch;
+
+    return STATUS_SUCCESS;
+}
+
+#else
+
+NTSTATUS WINAPI udev_driver_init(DRIVER_OBJECT *driver, UNICODE_STRING *registry_path)
+{
+    WARN("Wine was compiled without UDEV support\n");
+    return STATUS_NOT_IMPLEMENTED;
+}
+
+#endif /* HAVE_UDEV */
diff --git a/dlls/winebus.sys/main.c b/dlls/winebus.sys/main.c
index d495cd9..0be1b2e 100644
--- a/dlls/winebus.sys/main.c
+++ b/dlls/winebus.sys/main.c
@@ -20,6 +20,8 @@
 
 #include <stdarg.h>
 
+#define NONAMELESSUNION
+
 #include "ntstatus.h"
 #define WIN32_NO_STATUS
 #include "windef.h"
@@ -28,11 +30,43 @@
 #include "ddk/wdm.h"
 #include "wine/debug.h"
 
+#include "bus.h"
+
 WINE_DEFAULT_DEBUG_CHANNEL(plugplay);
 
+NTSTATUS WINAPI common_pnp_dispatch(DEVICE_OBJECT *device, IRP *irp)
+{
+    NTSTATUS status = irp->IoStatus.u.Status;
+    IO_STACK_LOCATION *irpsp = IoGetCurrentIrpStackLocation(irp);
+
+    switch (irpsp->MinorFunction)
+    {
+        case IRP_MN_QUERY_DEVICE_RELATIONS:
+            TRACE("IRP_MN_QUERY_DEVICE_RELATIONS\n");
+            break;
+        case IRP_MN_QUERY_ID:
+            TRACE("IRP_MN_QUERY_ID\n");
+            break;
+        case IRP_MN_QUERY_CAPABILITIES:
+            TRACE("IRP_MN_QUERY_CAPABILITIES\n");
+            break;
+        default:
+            FIXME("Unhandled function %08x\n", irpsp->MinorFunction);
+            break;
+    }
+
+    IoCompleteRequest(irp, IO_NO_INCREMENT);
+    return status;
+}
+
 NTSTATUS WINAPI DriverEntry( DRIVER_OBJECT *driver, UNICODE_STRING *path )
 {
+    static const WCHAR udevW[] = {'\\','D','r','i','v','e','r','\\','U','D','E','V',0};
+    static UNICODE_STRING udev = {sizeof(udevW) - sizeof(WCHAR), sizeof(udevW), (WCHAR *)udevW};
+
     TRACE( "(%p, %s)\n", driver, debugstr_w(path->Buffer) );
 
+    IoCreateDriver(&udev, udev_driver_init);
+
     return STATUS_SUCCESS;
 }
-- 
2.9.0



More information about the wine-patches mailing list