- Update cable pairing plugin to use libudev
This commit is contained in:
parent
c7a736cb45
commit
d02faea259
@ -1,44 +1,57 @@
|
|||||||
From df50f89ea8967fa0ba0d21aac0ce905801d31c70 Mon Sep 17 00:00:00 2001
|
From 7194839445edb3fd112b2bc79878c303e3b7c9e2 Mon Sep 17 00:00:00 2001
|
||||||
From: Bastien Nocera <hadess@hadess.net>
|
From: Bastien Nocera <hadess@hadess.net>
|
||||||
Date: Tue, 1 Sep 2009 17:32:48 +0100
|
Date: Tue, 1 Sep 2009 17:32:48 +0100
|
||||||
Subject: [PATCH] Add sixaxis cable-pairing plugin
|
Subject: [PATCH] Add sixaxis cable-pairing plugin
|
||||||
|
|
||||||
Implement the old "sixpair" using gudev (a GObject layer on top
|
Implement the old "sixpair" using libudev and libusb-1.0.
|
||||||
of udev's monitoring system), and libusb-1.0.
|
|
||||||
|
|
||||||
When a Sixaxis device is plugged in, events are filtered, and
|
When a Sixaxis device is plugged in, events are filtered, and
|
||||||
the device is selected, poked around to set the default Bluetooth
|
the device is selected, poked around to set the default Bluetooth
|
||||||
address, and added to the database of the current default adapter.
|
address, and added to the database of the current default adapter.
|
||||||
---
|
---
|
||||||
Makefile.am | 9 ++
|
Makefile.am | 9 +-
|
||||||
acinclude.m4 | 16 +++
|
acinclude.m4 | 16 +++
|
||||||
configure.ac | 1 +
|
configure.ac | 1 +
|
||||||
plugins/cable.c | 362 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
plugins/cable.c | 384 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
4 files changed, 388 insertions(+), 0 deletions(-)
|
4 files changed, 408 insertions(+), 2 deletions(-)
|
||||||
create mode 100644 plugins/cable.c
|
create mode 100644 plugins/cable.c
|
||||||
|
|
||||||
diff --git a/Makefile.am b/Makefile.am
|
diff --git a/Makefile.am b/Makefile.am
|
||||||
index c8337d6..0bdf694 100644
|
index c8337d6..e5eccdf 100644
|
||||||
--- a/Makefile.am
|
--- a/Makefile.am
|
||||||
+++ b/Makefile.am
|
+++ b/Makefile.am
|
||||||
@@ -162,6 +162,15 @@ builtin_modules += service
|
@@ -162,6 +162,11 @@ builtin_modules += service
|
||||||
builtin_sources += plugins/service.c
|
builtin_sources += plugins/service.c
|
||||||
endif
|
endif
|
||||||
|
|
||||||
+if CABLE
|
+if CABLE
|
||||||
+plugin_LTLIBRARIES += plugins/cable.la
|
+builtin_modules += cable
|
||||||
+
|
+builtin_sources += plugins/cable.c
|
||||||
+plugins_cable_la_LIBADD = @CABLE_LIBS@
|
|
||||||
+plugins_cable_la_LDFLAGS = -module -avoid-version -no-undefined
|
|
||||||
+plugins_cable_la_CFLAGS = -fvisibility=hidden @DBUS_CFLAGS@ \
|
|
||||||
+ @GLIB_CFLAGS@ @CABLE_CFLAGS@
|
|
||||||
+endif
|
+endif
|
||||||
+
|
+
|
||||||
builtin_modules += hciops
|
builtin_modules += hciops
|
||||||
builtin_sources += plugins/hciops.c
|
builtin_sources += plugins/hciops.c
|
||||||
|
|
||||||
|
@@ -192,7 +197,7 @@ src_bluetoothd_SOURCES = $(gdbus_sources) $(builtin_sources) \
|
||||||
|
src/dbus-common.c src/dbus-common.h \
|
||||||
|
src/dbus-hci.h src/dbus-hci.c
|
||||||
|
src_bluetoothd_LDADD = lib/libbluetooth.la @GLIB_LIBS@ @DBUS_LIBS@ \
|
||||||
|
- @CAPNG_LIBS@ -ldl
|
||||||
|
+ @CAPNG_LIBS@ @CABLE_LIBS@ -ldl
|
||||||
|
src_bluetoothd_LDFLAGS = -Wl,--export-dynamic \
|
||||||
|
-Wl,--version-script=src/bluetooth.ver
|
||||||
|
src_bluetoothd_DEPENDENCIES = src/bluetooth.ver lib/libbluetooth.la
|
||||||
|
@@ -305,7 +310,7 @@ EXTRA_DIST += doc/manager-api.txt \
|
||||||
|
|
||||||
|
AM_YFLAGS = -d
|
||||||
|
|
||||||
|
-AM_CFLAGS = @DBUS_CFLAGS@ @GLIB_CFLAGS@ @CAPNG_CFLAGS@ \
|
||||||
|
+AM_CFLAGS = @DBUS_CFLAGS@ @GLIB_CFLAGS@ @CAPNG_CFLAGS@ @CABLE_CFLAGS@ \
|
||||||
|
-DBLUETOOTH_PLUGIN_BUILTIN -DPLUGINDIR=\""$(plugindir)"\"
|
||||||
|
|
||||||
|
INCLUDES = -I$(builddir)/lib -I$(builddir)/src -I$(srcdir)/src \
|
||||||
diff --git a/acinclude.m4 b/acinclude.m4
|
diff --git a/acinclude.m4 b/acinclude.m4
|
||||||
index e7d1c32..3feddf8 100644
|
index e7d1c32..10e5241 100644
|
||||||
--- a/acinclude.m4
|
--- a/acinclude.m4
|
||||||
+++ b/acinclude.m4
|
+++ b/acinclude.m4
|
||||||
@@ -142,6 +142,12 @@ AC_DEFUN([AC_PATH_USB], [
|
@@ -142,6 +142,12 @@ AC_DEFUN([AC_PATH_USB], [
|
||||||
@ -46,7 +59,7 @@ index e7d1c32..3feddf8 100644
|
|||||||
])
|
])
|
||||||
|
|
||||||
+AC_DEFUN([AC_PATH_CABLE], [
|
+AC_DEFUN([AC_PATH_CABLE], [
|
||||||
+ PKG_CHECK_MODULES(CABLE, gudev-1.0 libusb-1.0, cable_found=yes, cable_found=no)
|
+ PKG_CHECK_MODULES(CABLE, libudev libusb-1.0, cable_found=yes, cable_found=no)
|
||||||
+ AC_SUBST(CABLE_CFLAGS)
|
+ AC_SUBST(CABLE_CFLAGS)
|
||||||
+ AC_SUBST(CABLE_LIBS)
|
+ AC_SUBST(CABLE_LIBS)
|
||||||
+])
|
+])
|
||||||
@ -104,10 +117,10 @@ index b93cca0..5df134f 100644
|
|||||||
AC_PATH_CAPNG
|
AC_PATH_CAPNG
|
||||||
diff --git a/plugins/cable.c b/plugins/cable.c
|
diff --git a/plugins/cable.c b/plugins/cable.c
|
||||||
new file mode 100644
|
new file mode 100644
|
||||||
index 0000000..6e81ba0
|
index 0000000..0b7cc7a
|
||||||
--- /dev/null
|
--- /dev/null
|
||||||
+++ b/plugins/cable.c
|
+++ b/plugins/cable.c
|
||||||
@@ -0,0 +1,362 @@
|
@@ -0,0 +1,384 @@
|
||||||
+/*
|
+/*
|
||||||
+ *
|
+ *
|
||||||
+ * BlueZ - Bluetooth protocol stack for Linux
|
+ * BlueZ - Bluetooth protocol stack for Linux
|
||||||
@ -135,8 +148,9 @@ index 0000000..6e81ba0
|
|||||||
+#include <config.h>
|
+#include <config.h>
|
||||||
+#endif
|
+#endif
|
||||||
+
|
+
|
||||||
+#define G_UDEV_API_IS_SUBJECT_TO_CHANGE
|
+#include <glib.h>
|
||||||
+#include <gudev/gudev.h>
|
+#define LIBUDEV_I_KNOW_THE_API_IS_SUBJECT_TO_CHANGE 1
|
||||||
|
+#include <libudev.h>
|
||||||
+#include <dbus/dbus.h>
|
+#include <dbus/dbus.h>
|
||||||
+#include <bluetooth/bluetooth.h>
|
+#include <bluetooth/bluetooth.h>
|
||||||
+#include <bluetooth/sdp.h>
|
+#include <bluetooth/sdp.h>
|
||||||
@ -319,7 +333,7 @@ index 0000000..6e81ba0
|
|||||||
+ libusb_close(devh);
|
+ libusb_close(devh);
|
||||||
+}
|
+}
|
||||||
+
|
+
|
||||||
+static void handle_device_plug(GUdevDevice *device)
|
+static void handle_device_plug(struct udev_device *udevice)
|
||||||
+{
|
+{
|
||||||
+ struct btd_adapter *adapter;
|
+ struct btd_adapter *adapter;
|
||||||
+ int adapter_id;
|
+ int adapter_id;
|
||||||
@ -330,11 +344,11 @@ index 0000000..6e81ba0
|
|||||||
+ struct libusb_device_descriptor desc;
|
+ struct libusb_device_descriptor desc;
|
||||||
+ guint8 j;
|
+ guint8 j;
|
||||||
+
|
+
|
||||||
+ if (g_udev_device_has_property(device, "ID_SERIAL") == FALSE ||
|
+ if (g_strcmp0(udev_device_get_property_value(udevice, "ID_SERIAL"),
|
||||||
+ g_strcmp0(g_udev_device_get_property(device, "ID_SERIAL"), "Sony_PLAYSTATION_R_3_Controller") != 0)
|
+ "Sony_PLAYSTATION_R_3_Controller") != 0)
|
||||||
+ return;
|
+ return;
|
||||||
+ /* Don't look at events with an associated driver */
|
+ /* Don't look at events with an associated driver */
|
||||||
+ if (g_udev_device_has_property(device, "ID_USB_DRIVER") != FALSE)
|
+ if (udev_device_get_property_value(udevice, "ID_USB_DRIVER") != NULL)
|
||||||
+ return;
|
+ return;
|
||||||
+
|
+
|
||||||
+ debug("Found Sixaxis device");
|
+ debug("Found Sixaxis device");
|
||||||
@ -365,7 +379,7 @@ index 0000000..6e81ba0
|
|||||||
+ path = g_strdup_printf("%s/%03d/%03d", "/dev/bus/usb",
|
+ path = g_strdup_printf("%s/%03d/%03d", "/dev/bus/usb",
|
||||||
+ libusb_get_bus_number(list[i]),
|
+ libusb_get_bus_number(list[i]),
|
||||||
+ libusb_get_device_address(list[i]));
|
+ libusb_get_device_address(list[i]));
|
||||||
+ if (g_strcmp0(path, g_udev_device_get_device_file(device)) == 0) {
|
+ if (g_strcmp0(path, udev_device_get_devnode(udevice)) == 0) {
|
||||||
+ g_free(path);
|
+ g_free(path);
|
||||||
+ usbdev = libusb_ref_device(list[i]);
|
+ usbdev = libusb_ref_device(list[i]);
|
||||||
+ break;
|
+ break;
|
||||||
@ -415,45 +429,58 @@ index 0000000..6e81ba0
|
|||||||
+ libusb_exit(NULL);
|
+ libusb_exit(NULL);
|
||||||
+}
|
+}
|
||||||
+
|
+
|
||||||
+static gboolean device_event_idle(GUdevDevice *device)
|
+static gboolean device_event_idle(struct udev_device *udevice)
|
||||||
+{
|
+{
|
||||||
+ handle_device_plug(device);
|
+ handle_device_plug(udevice);
|
||||||
+ g_object_unref (device);
|
+ udev_device_unref(udevice);
|
||||||
+ return FALSE;
|
+ return FALSE;
|
||||||
+}
|
+}
|
||||||
+
|
+
|
||||||
+static void uevent_cb(GUdevClient *client,
|
+static struct udev *ctx = NULL;
|
||||||
+ const char *action,
|
+static struct udev_monitor *monitor = NULL;
|
||||||
+ GUdevDevice *device,
|
+static guint watch_id = 0;
|
||||||
+ gpointer user_data)
|
+
|
||||||
|
+static gboolean
|
||||||
|
+monitor_event(GIOChannel *source,
|
||||||
|
+ GIOCondition condition,
|
||||||
|
+ gpointer data)
|
||||||
+{
|
+{
|
||||||
+ if (g_strcmp0(action, "add") == 0) {
|
+ struct udev_device *udevice;
|
||||||
+ /* FIXME:
|
+
|
||||||
+ * This happens because we need to wait for the
|
+ udevice = udev_monitor_receive_device(monitor);
|
||||||
+ * device node to be created by udev,
|
+ if (udevice == NULL)
|
||||||
+ * we should really just call: handle_device_plug(device); */
|
+ goto out;
|
||||||
+ g_object_ref(device);
|
+ if (g_strcmp0(udev_device_get_action(udevice), "add") != 0)
|
||||||
+ g_timeout_add_seconds(1, (GSourceFunc) device_event_idle, device);
|
+ goto out;
|
||||||
+ }
|
+
|
||||||
|
+ g_timeout_add_seconds(1, (GSourceFunc) device_event_idle, udevice);
|
||||||
|
+
|
||||||
|
+out:
|
||||||
|
+ return TRUE;
|
||||||
+}
|
+}
|
||||||
+
|
+
|
||||||
+GUdevClient *client = NULL;
|
|
||||||
+
|
+
|
||||||
+static int cable_init(void)
|
+static int cable_init(void)
|
||||||
+{
|
+{
|
||||||
+ const char * subsystems[] = { "usb", NULL };
|
+ GIOChannel *channel;
|
||||||
+
|
+
|
||||||
+ debug("Setup cable plugin");
|
+ debug("Setup cable plugin");
|
||||||
+
|
+
|
||||||
+ g_type_init();
|
+ ctx = udev_new();
|
||||||
|
+ monitor = udev_monitor_new_from_netlink(ctx, "udev");
|
||||||
|
+ if (monitor == NULL) {
|
||||||
|
+ error ("Could not get udev monitor");
|
||||||
|
+ return -1;
|
||||||
|
+ }
|
||||||
+
|
+
|
||||||
+ client = g_udev_client_new(subsystems);
|
+ /* Listen for newly connected usb device */
|
||||||
|
+ udev_monitor_filter_add_match_subsystem_devtype(monitor,
|
||||||
|
+ "usb", NULL);
|
||||||
|
+ udev_monitor_enable_receiving(monitor);
|
||||||
+
|
+
|
||||||
+ /* Listen for newly connected devices */
|
+ channel = g_io_channel_unix_new(udev_monitor_get_fd(monitor));
|
||||||
+ g_signal_connect(G_OBJECT(client),
|
+ watch_id = g_io_add_watch(channel, G_IO_IN, monitor_event, NULL);
|
||||||
+ "uevent",
|
+ g_io_channel_unref(channel);
|
||||||
+ G_CALLBACK(uevent_cb),
|
|
||||||
+ NULL);
|
|
||||||
+
|
+
|
||||||
+ return 0;
|
+ return 0;
|
||||||
+}
|
+}
|
||||||
@ -462,9 +489,17 @@ index 0000000..6e81ba0
|
|||||||
+{
|
+{
|
||||||
+ debug("Cleanup cable plugin");
|
+ debug("Cleanup cable plugin");
|
||||||
+
|
+
|
||||||
+ if (client != NULL) {
|
+ if (watch_id != 0) {
|
||||||
+ g_object_unref(client);
|
+ g_source_remove(watch_id);
|
||||||
+ client = NULL;
|
+ watch_id = 0;
|
||||||
|
+ }
|
||||||
|
+ if (monitor != NULL) {
|
||||||
|
+ udev_monitor_unref(monitor);
|
||||||
|
+ monitor = NULL;
|
||||||
|
+ }
|
||||||
|
+ if (ctx != NULL) {
|
||||||
|
+ udev_unref(ctx);
|
||||||
|
+ ctx = NULL;
|
||||||
+ }
|
+ }
|
||||||
+}
|
+}
|
||||||
+
|
+
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
Summary: Bluetooth utilities
|
Summary: Bluetooth utilities
|
||||||
Name: bluez
|
Name: bluez
|
||||||
Version: 4.55
|
Version: 4.55
|
||||||
Release: 1%{?dist}
|
Release: 2%{?dist}
|
||||||
License: GPLv2+
|
License: GPLv2+
|
||||||
Group: Applications/System
|
Group: Applications/System
|
||||||
Source: http://www.kernel.org/pub/linux/bluetooth/%{name}-%{version}.tar.gz
|
Source: http://www.kernel.org/pub/linux/bluetooth/%{name}-%{version}.tar.gz
|
||||||
@ -34,7 +34,7 @@ BuildRequires: gstreamer-plugins-base-devel, gstreamer-devel
|
|||||||
BuildRequires: libsndfile-devel
|
BuildRequires: libsndfile-devel
|
||||||
BuildRequires: libcap-ng-devel
|
BuildRequires: libcap-ng-devel
|
||||||
# For cable pairing
|
# For cable pairing
|
||||||
BuildRequires: libgudev-devel
|
BuildRequires: libudev-devel
|
||||||
%ifnarch s390 s390x
|
%ifnarch s390 s390x
|
||||||
BuildRequires: libusb1-devel
|
BuildRequires: libusb1-devel
|
||||||
%endif
|
%endif
|
||||||
@ -272,6 +272,9 @@ fi
|
|||||||
%config(noreplace) %{_sysconfdir}/sysconfig/pand
|
%config(noreplace) %{_sysconfdir}/sysconfig/pand
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Fri Oct 09 2009 Bastien Nocera <bnocera@redhat.com> 4.55-2
|
||||||
|
- Update cable pairing plugin to use libudev
|
||||||
|
|
||||||
* Mon Oct 05 2009 Bastien Nocera <bnocera@redhat.com> 4.55-1
|
* Mon Oct 05 2009 Bastien Nocera <bnocera@redhat.com> 4.55-1
|
||||||
- Update to 4.55
|
- Update to 4.55
|
||||||
- Add libcap-ng support to drop capabilities (#517660)
|
- Add libcap-ng support to drop capabilities (#517660)
|
||||||
|
Loading…
Reference in New Issue
Block a user