[bluez] Add PS3 BD Remote patches (power saving)

Bastien Nocera hadess at fedoraproject.org
Sat Jun 16 23:37:08 UTC 2012


commit d5c31c07900a1dabc89cc5d6ba64eb582d2b87aa
Author: Bastien Nocera <hadess at hadess.net>
Date:   Sun Jun 17 01:37:06 2012 +0200

    Add PS3 BD Remote patches (power saving)

 ...Add-helper-function-to-request-disconnect.patch |   37 ++++++
 ...-Disconnect-from-PS3-remote-after-10-mins.patch |  118 ++++++++++++++++++++
 ...fakehid-Use-the-same-constant-as-declared.patch |   26 +++++
 bluez.spec                                         |   12 ++-
 4 files changed, 192 insertions(+), 1 deletions(-)
---
diff --git a/0001-input-Add-helper-function-to-request-disconnect.patch b/0001-input-Add-helper-function-to-request-disconnect.patch
new file mode 100644
index 0000000..481b72c
--- /dev/null
+++ b/0001-input-Add-helper-function-to-request-disconnect.patch
@@ -0,0 +1,37 @@
+From c70bf65af6e301f18063491b22112300c0fb9b89 Mon Sep 17 00:00:00 2001
+From: Bastien Nocera <hadess at hadess.net>
+Date: Sun, 17 Jun 2012 01:25:46 +0200
+Subject: [PATCH 1/3] input: Add helper function to request disconnect
+
+---
+ input/device.c |    7 +++++++
+ input/device.h |    1 +
+ 2 files changed, 8 insertions(+)
+
+diff --git a/input/device.c b/input/device.c
+index 0e3f4a9..8fdd4e0 100644
+--- a/input/device.c
++++ b/input/device.c
+@@ -1306,3 +1306,10 @@ int input_device_close_channels(const bdaddr_t *src, const bdaddr_t *dst)
+ 
+ 	return 0;
+ }
++
++void input_device_request_disconnect(struct fake_input *fake)
++{
++	if (fake == NULL || fake->idev == NULL)
++		return;
++	device_request_disconnect(fake->idev->device, NULL);
++}
+diff --git a/input/device.h b/input/device.h
+index 509a353..ff52967 100644
+--- a/input/device.h
++++ b/input/device.h
+@@ -49,3 +49,4 @@ int input_device_unregister(const char *path, const char *uuid);
+ int input_device_set_channel(const bdaddr_t *src, const bdaddr_t *dst, int psm,
+ 							GIOChannel *io);
+ int input_device_close_channels(const bdaddr_t *src, const bdaddr_t *dst);
++void input_device_request_disconnect(struct fake_input *fake);
+-- 
+1.7.10
+
diff --git a/0002-fakehid-Disconnect-from-PS3-remote-after-10-mins.patch b/0002-fakehid-Disconnect-from-PS3-remote-after-10-mins.patch
new file mode 100644
index 0000000..8941126
--- /dev/null
+++ b/0002-fakehid-Disconnect-from-PS3-remote-after-10-mins.patch
@@ -0,0 +1,118 @@
+From cca11542bcd4d1748c850806c1599ed1b76ea19a Mon Sep 17 00:00:00 2001
+From: Bastien Nocera <hadess at hadess.net>
+Date: Sun, 17 Jun 2012 01:26:18 +0200
+Subject: [PATCH 2/3] fakehid: Disconnect from PS3 remote after 10 mins
+
+After 10 minutes, disconnect the PS3 BD Remote to avoid draining its
+battery. This is consistent with its behaviour on the PS3.
+
+Original patch by Ruslan N. Marchenko <rufferson at gmail.com>
+---
+ input/device.h  |    1 +
+ input/fakehid.c |   36 ++++++++++++++++++++++++++++++++++++
+ 2 files changed, 37 insertions(+)
+
+diff --git a/input/device.h b/input/device.h
+index ff52967..d8baa2c 100644
+--- a/input/device.h
++++ b/input/device.h
+@@ -33,6 +33,7 @@ struct fake_input {
+ 	int		uinput;		/* uinput socket */
+ 	int		rfcomm;		/* RFCOMM socket */
+ 	uint8_t		ch;		/* RFCOMM channel number */
++	guint           timeout_id;	/* Disconnect timeout ID */
+ 	gboolean	(*connect) (struct input_conn *iconn, GError **err);
+ 	int		(*disconnect) (struct input_conn *iconn);
+ 	void		*priv;
+diff --git a/input/fakehid.c b/input/fakehid.c
+index 3181538..a125356 100644
+--- a/input/fakehid.c
++++ b/input/fakehid.c
+@@ -44,6 +44,9 @@
+ #include "fakehid.h"
+ #include "uinput.h"
+ 
++/* Timeout to get the PS3 remote disconnected, in seconds */
++#define PS3_REMOTE_TIMEOUT 10 * 60
++
+ enum ps3remote_special_keys {
+ 	PS3R_BIT_PS = 0,
+ 	PS3R_BIT_ENTER = 3,
+@@ -141,6 +144,20 @@ static unsigned int ps3remote_keymap[] = {
+ 	[0xff] = KEY_MAX,
+ };
+ 
++static gboolean ps3_remote_timeout_cb(gpointer user_data);
++
++static void ps3remote_set_timeout(struct fake_input *fake, gboolean enable)
++{
++	if (enable) {
++		fake->timeout_id = g_timeout_add_seconds(PS3_REMOTE_TIMEOUT, ps3_remote_timeout_cb, fake);
++	} else {
++		if (fake->timeout_id > 0) {
++			g_source_remove(fake->timeout_id);
++			fake->timeout_id = 0;
++		}
++	}
++}
++
+ static int ps3remote_decode(char *buff, int size, unsigned int *value)
+ {
+ 	static unsigned int lastkey = 0;
+@@ -203,6 +220,16 @@ error:
+ 	return -1;
+ }
+ 
++static gboolean
++ps3_remote_timeout_cb(gpointer user_data)
++{
++	struct fake_input *fake = (struct fake_input *) user_data;
++	input_device_request_disconnect(fake);
++	DBG("Disconnected PS3 BD Remote after timeout");
++	fake->timeout_id = 0;
++	return FALSE;
++}
++
+ static gboolean ps3remote_event(GIOChannel *chan, GIOCondition cond,
+ 				gpointer data)
+ {
+@@ -221,6 +248,9 @@ static gboolean ps3remote_event(GIOChannel *chan, GIOCondition cond,
+ 		goto failed;
+ 	}
+ 
++	/* Remove the old timeout */
++	ps3remote_set_timeout(fake, FALSE);
++
+ 	fd = g_io_channel_unix_get_fd(chan);
+ 
+ 	memset(buff, 0, sizeof(buff));
+@@ -256,6 +286,8 @@ static gboolean ps3remote_event(GIOChannel *chan, GIOCondition cond,
+ 		goto failed;
+ 	}
+ 
++	ps3remote_set_timeout(fake, TRUE);
++
+ 	return TRUE;
+ 
+ failed:
+@@ -318,6 +350,8 @@ static int ps3remote_setup_uinput(struct fake_input *fake,
+ 		goto err;
+ 	}
+ 
++	ps3remote_set_timeout(fake, TRUE);
++
+ 	return 0;
+ 
+ err:
+@@ -378,6 +412,8 @@ struct fake_input *fake_hid_connadd(struct fake_input *fake,
+ 	for (l = fake_hid->devices; l != NULL; l = l->next) {
+ 		old = l->data;
+ 		if (old->idev == fake->idev) {
++			if (fake->timeout_id > 0)
++				g_source_remove(fake->timeout_id);
+ 			g_free(fake);
+ 			fake = old;
+ 			fake_hid->connect(fake, NULL);
+-- 
+1.7.10
+
diff --git a/0003-fakehid-Use-the-same-constant-as-declared.patch b/0003-fakehid-Use-the-same-constant-as-declared.patch
new file mode 100644
index 0000000..b6adf77
--- /dev/null
+++ b/0003-fakehid-Use-the-same-constant-as-declared.patch
@@ -0,0 +1,26 @@
+From a354165e58f937ee12c16ab48ce334b664c8f163 Mon Sep 17 00:00:00 2001
+From: Bastien Nocera <hadess at hadess.net>
+Date: Sun, 17 Jun 2012 01:29:01 +0200
+Subject: [PATCH 3/3] fakehid: Use the same constant as declared
+
+ps3remote_keymap[] uses 0xff as the max value, so should we.
+---
+ input/fakehid.c |    2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/input/fakehid.c b/input/fakehid.c
+index a125356..a758413 100644
+--- a/input/fakehid.c
++++ b/input/fakehid.c
+@@ -335,7 +335,7 @@ static int ps3remote_setup_uinput(struct fake_input *fake,
+ 	}
+ 
+ 	/* enabling keys */
+-	for (i = 0; i < 256; i++)
++	for (i = 0; i < 0xff; i++)
+ 		if (ps3remote_keymap[i] != KEY_RESERVED)
+ 			if (ioctl(fake->uinput, UI_SET_KEYBIT,
+ 						ps3remote_keymap[i]) < 0) {
+-- 
+1.7.10
+
diff --git a/bluez.spec b/bluez.spec
index 10de621..155f64d 100644
--- a/bluez.spec
+++ b/bluez.spec
@@ -1,7 +1,7 @@
 Summary: Bluetooth utilities
 Name: bluez
 Version: 4.100
-Release: 1%{?dist}
+Release: 2%{?dist}
 License: GPLv2+
 Group: Applications/System
 URL: http://www.bluez.org/
@@ -22,6 +22,10 @@ Patch2: 0001-Fix-ALSA-plugin-having-full-soname.patch
 Patch4: bluez-socket-mobile-cf-connection-kit.patch
 # http://thread.gmane.org/gmane.linux.bluez.kernel/2396
 Patch5: 0001-Add-sixaxis-cable-pairing-plugin.patch
+# PS3 BD Remote patches
+Patch6: 0001-input-Add-helper-function-to-request-disconnect.patch
+Patch7: 0002-fakehid-Disconnect-from-PS3-remote-after-10-mins.patch
+Patch8: 0003-fakehid-Use-the-same-constant-as-declared.patch
 
 BuildRequires: flex
 BuildRequires: dbus-devel >= 0.90
@@ -147,6 +151,9 @@ and mouse.
 %patch2 -p1 -b .typo
 %patch4 -p1 -b .socket-mobile
 %patch5 -p1 -b .cable-pairing
+%patch6 -p1
+%patch7 -p1
+%patch8 -p1
 
 %build
 libtoolize -f -c
@@ -311,6 +318,9 @@ fi
 %exclude /usr/lib/udev/rules.d/97-bluetooth-hid2hci.rules
 
 %changelog
+* Sun Jun 17 2012 Bastien Nocera <bnocera at redhat.com> 4.100-2
+- Add PS3 BD Remote patches (power saving)
+
 * Thu Jun 14 2012 Bastien Nocera <bnocera at redhat.com> 4.100-1
 - Update to 4.100
 


More information about the scm-commits mailing list