Update cable pairing patch

This commit is contained in:
Bastien Nocera 2010-12-19 14:41:05 +00:00
parent a6d564f749
commit 9befcf2c86

View File

@ -1,4 +1,4 @@
From 450e51afd466497f7d2c981a61bf56c5fb7883a8 Mon Sep 17 00:00:00 2001 From 14d6380cb9921ea09dc63d9401cb31c8f691449e 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
@ -12,8 +12,12 @@ 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 | 385 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/cable.c | 382 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 409 insertions(+), 2 deletions(-) src/adapter.c | 19 +++
src/adapter.h | 3 +
src/manager.c | 5 +
src/manager.h | 1 +
8 files changed, 434 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
@ -104,7 +108,7 @@ index 287f07d..aab0c15 100644
+ AM_CONDITIONAL(CABLE, test "${cable_enable}" = "yes" && test "${cable_found}" = "yes") + AM_CONDITIONAL(CABLE, test "${cable_enable}" = "yes" && test "${cable_found}" = "yes")
]) ])
diff --git a/configure.ac b/configure.ac diff --git a/configure.ac b/configure.ac
index 50617fd..3348ee8 100644 index 5f09cb6..0f73314 100644
--- a/configure.ac --- a/configure.ac
+++ b/configure.ac +++ b/configure.ac
@@ -40,6 +40,7 @@ AC_PATH_GLIB @@ -40,6 +40,7 @@ AC_PATH_GLIB
@ -117,10 +121,10 @@ index 50617fd..3348ee8 100644
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..21f7257 index 0000000..e8cff76
--- /dev/null --- /dev/null
+++ b/plugins/cable.c +++ b/plugins/cable.c
@@ -0,0 +1,385 @@ @@ -0,0 +1,382 @@
+/* +/*
+ * + *
+ * BlueZ - Bluetooth protocol stack for Linux + * BlueZ - Bluetooth protocol stack for Linux
@ -159,8 +163,8 @@ index 0000000..21f7257
+#include "plugin.h" +#include "plugin.h"
+#include "log.h" +#include "log.h"
+ +
+#include "manager.h"
+#include "adapter.h" +#include "adapter.h"
+#include "manager.h"
+#include "device.h" +#include "device.h"
+ +
+#include "storage.h" +#include "storage.h"
@ -186,8 +190,11 @@ index 0000000..21f7257
+ char srcaddr[18]; + char srcaddr[18];
+ +
+ device = adapter_find_device(adapter, address); + device = adapter_find_device(adapter, address);
+ if (device == NULL) + if (device == NULL) {
+ device = adapter_create_device(conn, adapter, address, FALSE); + device = device_create(conn, adapter, address, DEVICE_TYPE_UNKNOWN);
+ if (device != NULL)
+ adapter_create_device_for_device(conn, adapter, device);
+ }
+ if (device != NULL) { + if (device != NULL) {
+ device_set_temporary(device, FALSE); + device_set_temporary(device, FALSE);
+ device_set_name(device, name); + device_set_name(device, name);
@ -337,7 +344,6 @@ index 0000000..21f7257
+static void handle_device_plug(struct udev_device *udevice) +static void handle_device_plug(struct udev_device *udevice)
+{ +{
+ struct btd_adapter *adapter; + struct btd_adapter *adapter;
+ int adapter_id;
+ guint i; + guint i;
+ +
+ libusb_device **list, *usbdev; + libusb_device **list, *usbdev;
@ -355,12 +361,7 @@ index 0000000..21f7257
+ DBG("Found Sixaxis device"); + DBG("Found Sixaxis device");
+ +
+ /* Look for the default adapter */ + /* Look for the default adapter */
+ adapter_id = manager_get_default_adapter(); + adapter = manager_get_default_adapter();
+ if (adapter_id == -1) {
+ DBG("No adapters, exiting");
+ return;
+ }
+ adapter = manager_find_adapter_by_id(adapter_id);
+ if (adapter == NULL) + if (adapter == NULL)
+ return; + return;
+ +
@ -506,6 +507,78 @@ index 0000000..21f7257
+ +
+BLUETOOTH_PLUGIN_DEFINE(cable, VERSION, +BLUETOOTH_PLUGIN_DEFINE(cable, VERSION,
+ BLUETOOTH_PLUGIN_PRIORITY_DEFAULT, cable_init, cable_exit) + BLUETOOTH_PLUGIN_PRIORITY_DEFAULT, cable_init, cable_exit)
diff --git a/src/adapter.c b/src/adapter.c
index 5118306..6318d12 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -1056,6 +1056,25 @@ static struct btd_device *adapter_create_device(DBusConnection *conn,
return device;
}
+void adapter_create_device_for_device(DBusConnection *conn,
+ struct btd_adapter *adapter,
+ struct btd_device *device)
+{
+ const char *path;
+
+ device_set_temporary(device, TRUE);
+
+ adapter->devices = g_slist_append(adapter->devices, device);
+
+ path = device_get_path(device);
+ g_dbus_emit_signal(conn, adapter->path,
+ ADAPTER_INTERFACE, "DeviceCreated",
+ DBUS_TYPE_OBJECT_PATH, &path,
+ DBUS_TYPE_INVALID);
+
+ adapter_update_devices(adapter);
+}
+
void adapter_remove_device(DBusConnection *conn, struct btd_adapter *adapter,
struct btd_device *device,
gboolean remove_storage)
diff --git a/src/adapter.h b/src/adapter.h
index a02f61c..472cc0e 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -133,6 +133,9 @@ int adapter_remove_found_device(struct btd_adapter *adapter, bdaddr_t *bdaddr);
void adapter_emit_device_found(struct btd_adapter *adapter,
struct remote_dev_info *dev,
uint8_t *eir_data, size_t eir_length);
+void adapter_create_device_for_device(DBusConnection *conn,
+ struct btd_adapter *adapter,
+ struct btd_device *device);
void adapter_mode_changed(struct btd_adapter *adapter, uint8_t scan_mode);
void adapter_update_local_name(struct btd_adapter *adapter, const char *name);
void adapter_service_insert(const bdaddr_t *bdaddr, void *rec);
diff --git a/src/manager.c b/src/manager.c
index c8ec7e5..1bfc021 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -245,6 +245,11 @@ static void manager_update_adapters(void)
g_free(array);
}
+struct btd_adapter *manager_get_default_adapter(void)
+{
+ return manager_find_adapter_by_id(default_adapter_id);
+}
+
static void manager_remove_adapter(struct btd_adapter *adapter)
{
uint16_t dev_id = adapter_get_dev_id(adapter);
diff --git a/src/manager.h b/src/manager.h
index e6d5dd9..894dcb7 100644
--- a/src/manager.h
+++ b/src/manager.h
@@ -35,6 +35,7 @@ struct btd_adapter *manager_find_adapter(const bdaddr_t *sba);
struct btd_adapter *manager_find_adapter_by_address(const char *address);
struct btd_adapter *manager_find_adapter_by_path(const char *path);
struct btd_adapter *manager_find_adapter_by_id(int id);
+struct btd_adapter *manager_get_default_adapter(void);
GSList *manager_get_adapters(void);
int manager_register_adapter(int id, gboolean devup);
int manager_unregister_adapter(int id);
-- --
1.7.3.2 1.7.3.2