Update cable plugin

This commit is contained in:
Bastien Nocera 2010-06-14 10:45:59 +00:00
parent 43c645615e
commit f1feb4889a

View File

@ -1,4 +1,4 @@
From 09ef06047b1b180e68853786cd9efb9a1c5b2379 Mon Sep 17 00:00:00 2001 From 5e78f3524c73fe5041bf88dada41f5dd3105e9fc 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
@ -129,7 +129,7 @@ index f7bb047..25005c0 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 ec090aa..0c6fd97 100644 index 154d0dc..0e7084f 100644
--- a/configure.ac --- a/configure.ac
+++ b/configure.ac +++ b/configure.ac
@@ -40,7 +40,10 @@ AC_PATH_GLIB @@ -40,7 +40,10 @@ AC_PATH_GLIB
@ -145,7 +145,7 @@ index ec090aa..0c6fd97 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..698d5e6 index 0000000..d74c771
--- /dev/null --- /dev/null
+++ b/plugins/cable.c +++ b/plugins/cable.c
@@ -0,0 +1,385 @@ @@ -0,0 +1,385 @@
@ -253,14 +253,14 @@ index 0000000..698d5e6
+ 5000); + 5000);
+ +
+ if (res < 0) { + if (res < 0) {
+ debug("Getting the device Bluetooth address failed"); + DBG("Getting the device Bluetooth address failed");
+ return NULL; + return NULL;
+ } + }
+ +
+ address = g_strdup_printf("%02X:%02X:%02X:%02X:%02X:%02X", + address = g_strdup_printf("%02X:%02X:%02X:%02X:%02X:%02X",
+ msg[4], msg[5], msg[6], msg[7], msg[8], msg[9]); + msg[4], msg[5], msg[6], msg[7], msg[8], msg[9]);
+ +
+ debug("Device Bluetooth address: %s\n", address); + DBG("Device Bluetooth address: %s\n", address);
+ +
+ return address; + return address;
+} +}
@ -292,7 +292,7 @@ index 0000000..698d5e6
+ 5000); + 5000);
+ +
+ if (res < 0) { + if (res < 0) {
+ debug("Setting the master Bluetooth address failed"); + DBG("Setting the master Bluetooth address failed");
+ return FALSE; + return FALSE;
+ } + }
+ +
@ -314,24 +314,24 @@ index 0000000..698d5e6
+ device_bdaddr = NULL; + device_bdaddr = NULL;
+ conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL); + conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
+ if (conn == NULL) { + if (conn == NULL) {
+ debug("Failed to get on the bus"); + DBG("Failed to get on the bus");
+ return; + return;
+ } + }
+ +
+ if (libusb_open(dev, &devh) < 0) { + if (libusb_open(dev, &devh) < 0) {
+ debug("Can't open device"); + DBG("Can't open device");
+ goto bail; + goto bail;
+ } + }
+ libusb_detach_kernel_driver(devh, itfnum); + libusb_detach_kernel_driver(devh, itfnum);
+ +
+ if (libusb_claim_interface(devh, itfnum) < 0) { + if (libusb_claim_interface(devh, itfnum) < 0) {
+ debug("Can't claim interface %d", itfnum); + DBG("Can't claim interface %d", itfnum);
+ goto bail; + goto bail;
+ } + }
+ +
+ device_bdaddr = get_bdaddr(devh, itfnum); + device_bdaddr = get_bdaddr(devh, itfnum);
+ if (device_bdaddr == NULL) { + if (device_bdaddr == NULL) {
+ debug("Failed to get the Bluetooth address from the device"); + DBG("Failed to get the Bluetooth address from the device");
+ goto bail; + goto bail;
+ } + }
+ +
@ -344,10 +344,10 @@ index 0000000..698d5e6
+ +
+ adapter_get_address(adapter, &dst); + adapter_get_address(adapter, &dst);
+ ba2str(&dst, adapter_bdaddr); + ba2str(&dst, adapter_bdaddr);
+ debug("Adapter bdaddr %s", adapter_bdaddr); + DBG("Adapter bdaddr %s", adapter_bdaddr);
+ +
+ if (set_master_bdaddr(devh, itfnum, adapter_bdaddr) == FALSE) { + if (set_master_bdaddr(devh, itfnum, adapter_bdaddr) == FALSE) {
+ debug("Failed to set the master Bluetooth address"); + DBG("Failed to set the master Bluetooth address");
+ goto bail; + goto bail;
+ } + }
+ +
@ -380,12 +380,12 @@ index 0000000..698d5e6
+ if (udev_device_get_property_value(udevice, "ID_USB_DRIVER") != NULL) + if (udev_device_get_property_value(udevice, "ID_USB_DRIVER") != NULL)
+ return; + return;
+ +
+ debug("Found Sixaxis device"); + DBG("Found Sixaxis device");
+ +
+ /* Look for the default adapter */ + /* Look for the default adapter */
+ adapter_id = manager_get_default_adapter(); + adapter_id = manager_get_default_adapter();
+ if (adapter_id == -1) { + if (adapter_id == -1) {
+ debug("No adapters, exiting"); + DBG("No adapters, exiting");
+ return; + return;
+ } + }
+ adapter = manager_find_adapter_by_id(adapter_id); + adapter = manager_find_adapter_by_id(adapter_id);
@ -397,7 +397,7 @@ index 0000000..698d5e6
+ +
+ num_devices = libusb_get_device_list(NULL, &list); + num_devices = libusb_get_device_list(NULL, &list);
+ if (num_devices < 0) { + if (num_devices < 0) {
+ debug("libusb_get_device_list failed"); + DBG("libusb_get_device_list failed");
+ return; + return;
+ } + }
+ +
@ -418,12 +418,12 @@ index 0000000..698d5e6
+ +
+ libusb_free_device_list(list, TRUE); + libusb_free_device_list(list, TRUE);
+ if (usbdev == NULL) { + if (usbdev == NULL) {
+ debug("Found a Sixaxis, but couldn't find it via libusb"); + DBG("Found a Sixaxis, but couldn't find it via libusb");
+ goto out; + goto out;
+ } + }
+ +
+ if (libusb_get_device_descriptor(usbdev, &desc) < 0) { + if (libusb_get_device_descriptor(usbdev, &desc) < 0) {
+ debug("libusb_get_device_descriptor() failed"); + DBG("libusb_get_device_descriptor() failed");
+ goto out; + goto out;
+ } + }
+ +
@ -433,7 +433,7 @@ index 0000000..698d5e6
+ guint8 k; + guint8 k;
+ +
+ if (libusb_get_config_descriptor(usbdev, j, &config) < 0) { + if (libusb_get_config_descriptor(usbdev, j, &config) < 0) {
+ debug("Failed to get config descriptor %d", j); + DBG("Failed to get config descriptor %d", j);
+ continue; + continue;
+ } + }
+ +
@ -493,7 +493,7 @@ index 0000000..698d5e6
+{ +{
+ GIOChannel *channel; + GIOChannel *channel;
+ +
+ debug("Setup cable plugin"); + DBG("Setup cable plugin");
+ +
+ ctx = udev_new(); + ctx = udev_new();
+ monitor = udev_monitor_new_from_netlink(ctx, "udev"); + monitor = udev_monitor_new_from_netlink(ctx, "udev");
@ -516,7 +516,7 @@ index 0000000..698d5e6
+ +
+static void cable_exit(void) +static void cable_exit(void)
+{ +{
+ debug("Cleanup cable plugin"); + DBG("Cleanup cable plugin");
+ +
+ if (watch_id != 0) { + if (watch_id != 0) {
+ g_source_remove(watch_id); + g_source_remove(watch_id);