From d02faea2591b51b346c224680ffa99e87fb8cfe9 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Oct 09 2009 15:08:22 +0000 Subject: - Update cable pairing plugin to use libudev --- diff --git a/0001-Add-sixaxis-cable-pairing-plugin.patch b/0001-Add-sixaxis-cable-pairing-plugin.patch index e3fe50c..299916c 100644 --- a/0001-Add-sixaxis-cable-pairing-plugin.patch +++ b/0001-Add-sixaxis-cable-pairing-plugin.patch @@ -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 Date: Tue, 1 Sep 2009 17:32:48 +0100 Subject: [PATCH] Add sixaxis cable-pairing plugin -Implement the old "sixpair" using gudev (a GObject layer on top -of udev's monitoring system), and libusb-1.0. +Implement the old "sixpair" using libudev and libusb-1.0. When a Sixaxis device is plugged in, events are filtered, and the device is selected, poked around to set the default Bluetooth address, and added to the database of the current default adapter. --- - Makefile.am | 9 ++ + Makefile.am | 9 +- acinclude.m4 | 16 +++ configure.ac | 1 + - plugins/cable.c | 362 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ - 4 files changed, 388 insertions(+), 0 deletions(-) + plugins/cable.c | 384 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ + 4 files changed, 408 insertions(+), 2 deletions(-) create mode 100644 plugins/cable.c diff --git a/Makefile.am b/Makefile.am -index c8337d6..0bdf694 100644 +index c8337d6..e5eccdf 100644 --- a/Makefile.am +++ b/Makefile.am -@@ -162,6 +162,15 @@ builtin_modules += service +@@ -162,6 +162,11 @@ builtin_modules += service builtin_sources += plugins/service.c endif +if CABLE -+plugin_LTLIBRARIES += plugins/cable.la -+ -+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@ ++builtin_modules += cable ++builtin_sources += plugins/cable.c +endif + builtin_modules += hciops 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 -index e7d1c32..3feddf8 100644 +index e7d1c32..10e5241 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -142,6 +142,12 @@ AC_DEFUN([AC_PATH_USB], [ @@ -46,7 +59,7 @@ index e7d1c32..3feddf8 100644 ]) +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_LIBS) +]) @@ -104,10 +117,10 @@ index b93cca0..5df134f 100644 AC_PATH_CAPNG diff --git a/plugins/cable.c b/plugins/cable.c new file mode 100644 -index 0000000..6e81ba0 +index 0000000..0b7cc7a --- /dev/null +++ b/plugins/cable.c -@@ -0,0 +1,362 @@ +@@ -0,0 +1,384 @@ +/* + * + * BlueZ - Bluetooth protocol stack for Linux @@ -135,8 +148,9 @@ index 0000000..6e81ba0 +#include +#endif + -+#define G_UDEV_API_IS_SUBJECT_TO_CHANGE -+#include ++#include ++#define LIBUDEV_I_KNOW_THE_API_IS_SUBJECT_TO_CHANGE 1 ++#include +#include +#include +#include @@ -319,7 +333,7 @@ index 0000000..6e81ba0 + libusb_close(devh); +} + -+static void handle_device_plug(GUdevDevice *device) ++static void handle_device_plug(struct udev_device *udevice) +{ + struct btd_adapter *adapter; + int adapter_id; @@ -330,11 +344,11 @@ index 0000000..6e81ba0 + struct libusb_device_descriptor desc; + guint8 j; + -+ if (g_udev_device_has_property(device, "ID_SERIAL") == FALSE || -+ g_strcmp0(g_udev_device_get_property(device, "ID_SERIAL"), "Sony_PLAYSTATION_R_3_Controller") != 0) ++ if (g_strcmp0(udev_device_get_property_value(udevice, "ID_SERIAL"), ++ "Sony_PLAYSTATION_R_3_Controller") != 0) + return; + /* 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; + + debug("Found Sixaxis device"); @@ -365,7 +379,7 @@ index 0000000..6e81ba0 + path = g_strdup_printf("%s/%03d/%03d", "/dev/bus/usb", + libusb_get_bus_number(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); + usbdev = libusb_ref_device(list[i]); + break; @@ -415,45 +429,58 @@ index 0000000..6e81ba0 + libusb_exit(NULL); +} + -+static gboolean device_event_idle(GUdevDevice *device) ++static gboolean device_event_idle(struct udev_device *udevice) +{ -+ handle_device_plug(device); -+ g_object_unref (device); ++ handle_device_plug(udevice); ++ udev_device_unref(udevice); + return FALSE; +} + -+static void uevent_cb(GUdevClient *client, -+ const char *action, -+ GUdevDevice *device, -+ gpointer user_data) ++static struct udev *ctx = NULL; ++static struct udev_monitor *monitor = NULL; ++static guint watch_id = 0; ++ ++static gboolean ++monitor_event(GIOChannel *source, ++ GIOCondition condition, ++ gpointer data) +{ -+ if (g_strcmp0(action, "add") == 0) { -+ /* FIXME: -+ * This happens because we need to wait for the -+ * device node to be created by udev, -+ * we should really just call: handle_device_plug(device); */ -+ g_object_ref(device); -+ g_timeout_add_seconds(1, (GSourceFunc) device_event_idle, device); -+ } ++ struct udev_device *udevice; ++ ++ udevice = udev_monitor_receive_device(monitor); ++ if (udevice == NULL) ++ goto out; ++ if (g_strcmp0(udev_device_get_action(udevice), "add") != 0) ++ goto out; ++ ++ g_timeout_add_seconds(1, (GSourceFunc) device_event_idle, udevice); ++ ++out: ++ return TRUE; +} + -+GUdevClient *client = NULL; + +static int cable_init(void) +{ -+ const char * subsystems[] = { "usb", NULL }; ++ GIOChannel *channel; + + 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 */ -+ g_signal_connect(G_OBJECT(client), -+ "uevent", -+ G_CALLBACK(uevent_cb), -+ NULL); ++ channel = g_io_channel_unix_new(udev_monitor_get_fd(monitor)); ++ watch_id = g_io_add_watch(channel, G_IO_IN, monitor_event, NULL); ++ g_io_channel_unref(channel); + + return 0; +} @@ -462,9 +489,17 @@ index 0000000..6e81ba0 +{ + debug("Cleanup cable plugin"); + -+ if (client != NULL) { -+ g_object_unref(client); -+ client = NULL; ++ if (watch_id != 0) { ++ g_source_remove(watch_id); ++ watch_id = 0; ++ } ++ if (monitor != NULL) { ++ udev_monitor_unref(monitor); ++ monitor = NULL; ++ } ++ if (ctx != NULL) { ++ udev_unref(ctx); ++ ctx = NULL; + } +} + diff --git a/bluez.spec b/bluez.spec index ab79ae8..625a75b 100644 --- a/bluez.spec +++ b/bluez.spec @@ -1,7 +1,7 @@ Summary: Bluetooth utilities Name: bluez Version: 4.55 -Release: 1%{?dist} +Release: 2%{?dist} License: GPLv2+ Group: Applications/System 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: libcap-ng-devel # For cable pairing -BuildRequires: libgudev-devel +BuildRequires: libudev-devel %ifnarch s390 s390x BuildRequires: libusb1-devel %endif @@ -272,6 +272,9 @@ fi %config(noreplace) %{_sysconfdir}/sysconfig/pand %changelog +* Fri Oct 09 2009 Bastien Nocera 4.55-2 +- Update cable pairing plugin to use libudev + * Mon Oct 05 2009 Bastien Nocera 4.55-1 - Update to 4.55 - Add libcap-ng support to drop capabilities (#517660)