Skip to contentSkip to conversation

auto-pairing plugin

RFC PATCH In review Scott James Remnant 2 participants 4 messages Jan 21, 2012 – Jan 23, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover auto-pairing plugin

A few core changes here to support retrying of connections without losing the original connection request, temporary D-Bus device object or Agent information - and plugin callbacks for when bonding is complete and cancelled.

This lets us implement an auto-pair plugin that tries the PIN 0000 for commonly dumb devices, and retries using the Agent when that PIN fails. For added cutesyness we save the blacklist we use to avoid repeatedly sending 0000, so if there really are any devices out there with different default PINs we can learn about them over time.

Net effect - another thing done in the UI Agent moved into bluetoothd where it belongs.

*** BLURB HERE ***

Scott James Remnant (2):
plugin: add bonding complete and cancel callbacks with optional retry
autopair: add autopair plugin

 Makefile.am        |    5 +
 acinclude.m4       |    6 ++
 plugins/autopair.c |  209 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/adapter.c      |    2 +-
 src/device.c       |   86 +++++++++++++++++++++
 src/device.h       |   12 +++
 6 files changed, 319 insertions(+), 1 deletions(-)
 create mode 100644 plugins/autopair.c
Signature · 1 line
1.7.7.3
#1 lore raw

RFC PATCH 1/2 plugin: add bonding complete and cancel callbacks with optional retry

Allow plugins to register a device-level bonding complete callback which, if it returns TRUE, specifies that a failed bonding attempt should be retried after a short backoff period.

Since these will likely store state, require them to register a bonding cancelled callback at the same time so they can clean up.

---
 src/adapter.c |    2 +-
 src/device.c  |   86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/device.h  |   12 ++++++++
 3 files changed, 99 insertions(+), 1 deletions(-)
src/adapter.c +1 -1
index a75a0c4..d489e50 100644
@@ -2975,7 +2975,7 @@ void adapter_remove_connection(struct btd_adapter *adapter,
 	if (device_is_authenticating(device))
 		device_cancel_authentication(device, TRUE);
 
-	if (device_is_temporary(device)) {
+	if (device_is_temporary(device) && !device_is_retrying(device)) {
 		const char *path = device_get_path(device);
 
 		DBG("Removing temporary device %s", path);
src/device.c +86 -0

134 lines not on this page · raw message

src/device.h +12 -0
index 13005ae..4f7fd53 100644
@@ -73,6 +73,7 @@ void device_set_temporary(struct btd_device *device, gboolean temporary);
 void device_set_bonded(struct btd_device *device, gboolean bonded);
 void device_set_auto_connect(struct btd_device *device, gboolean enable);
 gboolean device_is_connected(struct btd_device *device);
+gboolean device_is_retrying(struct btd_device *device);
 DBusMessage *device_create_bonding(struct btd_device *device,
 				DBusConnection *conn, DBusMessage *msg,
 				const char *agent_path, uint8_t capability);
@@ -100,6 +101,17 @@ guint device_add_disconnect_watch(struct btd_device *device,
 void device_remove_disconnect_watch(struct btd_device *device, guint id);
 void device_set_class(struct btd_device *device, uint32_t value);
 
+typedef gboolean (*btd_device_bonding_cb_t) (struct btd_device *device,
+								uint8_t status);
+typedef void (*btd_device_bonding_cancel_cb_t) (struct btd_device *device);
+
+void btd_device_register_bonding_cb(struct btd_device *dev,
+				btd_device_bonding_cb_t cb,
+				btd_device_bonding_cancel_cb_t ccb);
+void btd_device_unregister_bonding_cb(struct btd_device *dev, 
+				btd_device_bonding_cb_t cb,
+				btd_device_bonding_cancel_cb_t ccb);
+
 #define BTD_UUIDS(args...) ((const char *[]) { args, NULL } )
 
 struct btd_device_driver {
Signature · 1 line
1.7.7.3
#2 lore raw

RFC PATCH 2/2 autopair: add autopair plugin

In reply to Scott James Remnant

The autopair plugin sends an initial PIN of 0000 to "dumb" devices such as mice and headsets (list of classes unashamedly stolen from Android) and registers a bonding complete callback for that device.

If bonding should fail with the fixed PIN, the device is blacklisted from auto-pairing and the pairing tried again after a short back-off period, this time using the Agent's RequestPinCode method.

---
 Makefile.am        |    5 +
 acinclude.m4       |    6 ++
 plugins/autopair.c |  209 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 220 insertions(+), 0 deletions(-)
 create mode 100644 plugins/autopair.c
Makefile.am +5 -0
index 8dbe603..cdfdb93 100644
@@ -278,6 +278,11 @@ builtin_modules += dbusoob
 builtin_sources += plugins/dbusoob.c
 endif
 
+if AUTOPAIRPLUGIN
+builtin_modules += autopair
+builtin_sources += plugins/autopair.c
+endif
+
 if MAINTAINER_MODE
 plugin_LTLIBRARIES += plugins/external-dummy.la
 plugins_external_dummy_la_SOURCES = plugins/external-dummy.c
acinclude.m4 +6 -0
index 57fc5e0..187a049 100644
@@ -218,6 +218,7 @@ AC_DEFUN([AC_ARG_BLUEZ], [
 	dbusoob_enable=no
 	wiimote_enable=no
 	thermometer_enable=no
+	autopair_enable=no
 
 	AC_ARG_ENABLE(optimization, AC_HELP_STRING([--disable-optimization], [disable code optimization]), [
 		optimization_enable=${enableval}
@@ -374,6 +375,10 @@ AC_DEFUN([AC_ARG_BLUEZ], [
 		thermometer_enable=${enableval}
 	])
 
+	AC_ARG_ENABLE(autopair, AC_HELP_STRING([--enable-autopair], [enable auto-pairplugin]), [
+		autopair_enable=${enableval}
+	])
+
 	if (test "${fortify_enable}" = "yes"); then
 		CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=2"
 	fi
@@ -432,4 +437,5 @@ AC_DEFUN([AC_ARG_BLUEZ], [
 	AM_CONDITIONAL(DBUSOOBPLUGIN, test "${dbusoob_enable}" = "yes")
 	AM_CONDITIONAL(WIIMOTEPLUGIN, test "${wiimote_enable}" = "yes")
 	AM_CONDITIONAL(THERMOMETERPLUGIN, test "${thermometer_enable}" = "yes")
+	AM_CONDITIONAL(AUTOPAIRPLUGIN, test "${autopair_enable}" = "yes")
 ])
plugins/autopair.c new file +209 -0

209 lines not on this page · raw message

Signature · 1 line
1.7.7.3
#3 lore raw
In reply to Scott James Remnant
Quoted 10 lines · Scott James Remnant

A few core changes here to support retrying of connections without losing the original connection request, temporary D-Bus device object or Agent information - and plugin callbacks for when bonding is complete and cancelled.

This lets us implement an auto-pair plugin that tries the PIN 0000 for commonly dumb devices, and retries using the Agent when that PIN fails. For added cutesyness we save the blacklist we use to avoid repeatedly sending 0000, so if there really are any devices out there with different default PINs we can learn about them over time.

I'd agree to this if you could make it use the XML database that gnome-bluetooth uses:
http://git.gnome.org/browse/gnome-bluetooth/tree/wizard/pin-code-database.xml

That would mean that we can try the automatic password, and then fallback to asking for a PIN if it fails (like it would have for those devices without any input that use "1234" as the pairing).

Quoted 18 lines

Net effect - another thing done in the UI Agent moved into bluetoothd where it belongs.

*** BLURB HERE ***

Scott James Remnant (2):
plugin: add bonding complete and cancel callbacks with optional retry
autopair: add autopair plugin

 Makefile.am        |    5 +
 acinclude.m4       |    6 ++
 plugins/autopair.c |  209 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/adapter.c      |    2 +-
 src/device.c       |   86 +++++++++++++++++++++
 src/device.h       |   12 +++
 6 files changed, 319 insertions(+), 1 deletions(-)
 create mode 100644 plugins/autopair.c