All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC BlueZ 00/11] Re-connections triggered by platform event
@ 2011-09-02 21:38 Claudio Takahasi
  2011-09-02 21:38 ` [RFC BlueZ 01/11] Remove timer to trigger connection attempts Claudio Takahasi
                   ` (10 more replies)
  0 siblings, 11 replies; 14+ messages in thread
From: Claudio Takahasi @ 2011-09-02 21:38 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

Initial proposal to enable re-connection(for ATT) started by platform/
user actions. eg: Screen unlocked.

Use case: When the user unlock the screen, automatic re-connections for
bonded devices will be started. It will remain active for 3 minutes
(configurable).

The code needs cleanup, I am exposing the idea to get feedback before
clean the code and fix corner cases. In order to achieve better control
of re-connections, "Pending" state needs to be extended to LE. At the
moment, only BR/EDR supports setting a connection request as pending
when the controller returns Command Disallowed.

Development branch:
git://git.infradead.org/users/cktakahasi/bluez.git proximity-devel-w35

Comments/Suggestions?

BR,
Claudio.

Anderson Briglia (1):
  Add display lock watcher on maemo6 plugin

Claudio Takahasi (10):
  Remove timer to trigger connection attempts
  Add set auto connect in device
  Add continuous connection attempt
  Add checking if profiles are requesting connection
  Add tracking of connect sources
  Disable automatic connections after 3 minutes
  Notify unlocked event when using maemo6 plugin
  Add automatic connect timeout config option
  Add an interval between connection attempts
  Enable re-connections when disconnected

 plugins/maemo6.c |   33 ++++++++++++++++++
 src/adapter.c    |   43 +++++++++++++++++++++++
 src/adapter.h    |    1 +
 src/device.c     |   99 ++++++++++++++++++++++++++++++++++++++----------------
 src/device.h     |    1 +
 src/hcid.h       |    1 +
 src/main.c       |   12 ++++++
 src/main.conf    |    6 +++
 8 files changed, 167 insertions(+), 29 deletions(-)

-- 
1.7.6


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [RFC BlueZ 01/11] Remove timer to trigger connection attempts
  2011-09-02 21:38 [RFC BlueZ 00/11] Re-connections triggered by platform event Claudio Takahasi
@ 2011-09-02 21:38 ` Claudio Takahasi
  2011-09-02 21:38 ` [RFC BlueZ 02/11] Add set auto connect in device Claudio Takahasi
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 14+ messages in thread
From: Claudio Takahasi @ 2011-09-02 21:38 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

Removes continuous timer for ATTIO connection attempts. A new approach
is being implemented managing scanning and connection attempts driven
by platform/user actions. eg: screen unlocked.
---
 src/device.c |   35 +++++------------------------------
 1 files changed, 5 insertions(+), 30 deletions(-)

diff --git a/src/device.c b/src/device.c
index e5e0819..b35e3d4 100644
--- a/src/device.c
+++ b/src/device.c
@@ -65,7 +65,6 @@
 
 #define DISCONNECT_TIMER	2
 #define DISCOVERY_TIMER		2
-#define AUTOCONNECT_INTERVAL	45
 
 /* When all services should trust a remote device */
 #define GLOBAL_TRUST "[all]"
@@ -138,7 +137,6 @@ struct btd_device {
 	GSList		*attios;
 	GSList		*attios_offline;
 	guint		attachid;		/* Attrib server attach */
-	guint		attioid;
 
 	gboolean	connected;
 
@@ -235,9 +233,6 @@ static void device_free(gpointer user_data)
 	if (device->discov_timer)
 		g_source_remove(device->discov_timer);
 
-	if (device->attioid)
-		g_source_remove(device->attioid);
-
 	DBG("%p", device);
 
 	g_free(device->authr);
@@ -1614,19 +1609,12 @@ static void attio_disconnected(gpointer data, gpointer user_data)
 		attio->dcfunc(attio->user_data);
 }
 
-static gboolean att_auto_connect(gpointer user_data);
-
 static void attrib_disconnected(gpointer user_data)
 {
 	struct btd_device *device = user_data;
 
 	g_slist_foreach(device->attios, attio_disconnected, NULL);
 
-	if ((device->attios || device->attios_offline) && device->attioid == 0)
-		device->attioid = g_timeout_add_seconds(AUTOCONNECT_INTERVAL,
-							att_auto_connect,
-							device);
-
 	attrib_channel_detach(device->attachid);
 	g_attrib_unref(device->attrib);
 	device->attrib = NULL;
@@ -1707,11 +1695,6 @@ static void att_connect_cb(GIOChannel *io, GError *gerr, gpointer user_data)
 		return;
 	}
 
-	if (device->attioid) {
-		g_source_remove(device->attioid);
-		device->attioid = 0;
-	}
-
 	attrib = g_attrib_new(io);
 	device->attachid = attrib_channel_attach(attrib, TRUE);
 	if (device->attachid == 0)
@@ -1729,7 +1712,7 @@ static void att_connect_cb(GIOChannel *io, GError *gerr, gpointer user_data)
 	}
 }
 
-static gboolean att_auto_connect(gpointer user_data)
+static gboolean att_connect(gpointer user_data)
 {
 	struct btd_device *device = user_data;
 	struct btd_adapter *adapter = device->adapter;
@@ -1764,12 +1747,12 @@ static gboolean att_auto_connect(gpointer user_data)
 	if (io == NULL) {
 		error("ATT bt_io_connect(%s): %s", addr, gerr->message);
 		g_error_free(gerr);
-		return TRUE;
+		return FALSE;
 	}
 
 	g_io_channel_unref(io);
 
-	return TRUE;
+	return FALSE;
 }
 
 int device_browse_primary(struct btd_device *device, DBusConnection *conn,
@@ -2613,11 +2596,8 @@ guint btd_device_add_attio_callback(struct btd_device *device,
 		device->attios_offline = g_slist_append(device->attios_offline,
 									attio);
 		g_idle_add(notify_attios, device);
-	} else if (device->attioid == 0) {
-		att_auto_connect(device);
-		device->attioid = g_timeout_add_seconds(AUTOCONNECT_INTERVAL,
-							att_auto_connect,
-							device);
+	} else {
+		g_idle_add(att_connect, device);
 		device->attios = g_slist_append(device->attios, attio);
 	}
 
@@ -2658,11 +2638,6 @@ gboolean btd_device_remove_attio_callback(struct btd_device *device, guint id)
 	if (device->attios != NULL || device->attios_offline != NULL)
 		return TRUE;
 
-	if (device->attioid) {
-		g_source_remove(device->attioid);
-		device->attioid = 0;
-	}
-
 	if (device->attachid) {
 		attrib_channel_detach(device->attachid);
 		device->attachid = 0;
-- 
1.7.6


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [RFC BlueZ 02/11] Add set auto connect in device
  2011-09-02 21:38 [RFC BlueZ 00/11] Re-connections triggered by platform event Claudio Takahasi
  2011-09-02 21:38 ` [RFC BlueZ 01/11] Remove timer to trigger connection attempts Claudio Takahasi
@ 2011-09-02 21:38 ` Claudio Takahasi
  2011-09-05  9:55   ` Johan Hedberg
  2011-09-02 21:38 ` [RFC BlueZ 03/11] Add continuous connection attempt Claudio Takahasi
                   ` (8 subsequent siblings)
  10 siblings, 1 reply; 14+ messages in thread
From: Claudio Takahasi @ 2011-09-02 21:38 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

Skeleton of automatic connections driven by platform/user event.
Two layers will manage connections: Profiles can request on demand
connections registering ATTIO connection callbacks(one attempt) for
a given device and platform/user action can trigger automatic
connections for all bonded devices with ATTIO callbacks registered.
---
 src/adapter.c |   20 ++++++++++++++++++++
 src/adapter.h |    1 +
 src/device.c  |   11 +++++++++++
 src/device.h  |    1 +
 4 files changed, 33 insertions(+), 0 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 2eeeab5..eec721c 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -3538,6 +3538,26 @@ int btd_adapter_switch_offline(struct btd_adapter *adapter)
 	return 0;
 }
 
+static void set_auto_connect(gpointer data, gpointer user_data)
+{
+	struct btd_device *device = data;
+
+	if (device_is_bonded(device) == FALSE)
+		return;
+
+	device_set_auto_connect(device, TRUE);
+}
+
+void btd_adapter_system_unlocked(struct btd_adapter *adapter)
+{
+	if (!adapter->up)
+		return;
+
+	DBG("Unlocked");
+
+	g_slist_foreach(adapter->devices, set_auto_connect, NULL);
+}
+
 void btd_adapter_register_pin_cb(struct btd_adapter *adapter,
 							btd_adapter_pin_cb_t cb)
 {
diff --git a/src/adapter.h b/src/adapter.h
index 4e6d7eb..eeac448 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -171,6 +171,7 @@ gboolean adapter_powering_down(struct btd_adapter *adapter);
 int btd_adapter_restore_powered(struct btd_adapter *adapter);
 int btd_adapter_switch_online(struct btd_adapter *adapter);
 int btd_adapter_switch_offline(struct btd_adapter *adapter);
+void btd_adapter_system_unlocked(struct btd_adapter *adapter);
 
 typedef ssize_t (*btd_adapter_pin_cb_t) (struct btd_adapter *adapter,
 					struct btd_device *dev, char *out);
diff --git a/src/device.c b/src/device.c
index b35e3d4..4af6c1d 100644
--- a/src/device.c
+++ b/src/device.c
@@ -146,6 +146,7 @@ struct btd_device {
 	gboolean	paired;
 	gboolean	blocked;
 	gboolean	bonded;
+	gboolean	auto_connect;
 
 	gboolean	authorizing;
 	gint		ref;
@@ -1919,6 +1920,16 @@ void device_set_bonded(struct btd_device *device, gboolean bonded)
 	device->bonded = bonded;
 }
 
+void device_set_auto_connect(struct btd_device *device, gboolean enable)
+{
+	if (!device)
+		return;
+
+	DBG("auto connect: %d", enable);
+
+	device->auto_connect = enable;
+}
+
 void device_set_type(struct btd_device *device, device_type_t type)
 {
 	if (!device)
diff --git a/src/device.h b/src/device.h
index 6efcf63..59355aa 100644
--- a/src/device.h
+++ b/src/device.h
@@ -74,6 +74,7 @@ void device_set_paired(struct btd_device *device, gboolean paired);
 void device_set_temporary(struct btd_device *device, gboolean temporary);
 void device_set_type(struct btd_device *device, device_type_t type);
 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);
 DBusMessage *device_create_bonding(struct btd_device *device,
 				DBusConnection *conn, DBusMessage *msg,
-- 
1.7.6


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [RFC BlueZ 03/11] Add continuous connection attempt
  2011-09-02 21:38 [RFC BlueZ 00/11] Re-connections triggered by platform event Claudio Takahasi
  2011-09-02 21:38 ` [RFC BlueZ 01/11] Remove timer to trigger connection attempts Claudio Takahasi
  2011-09-02 21:38 ` [RFC BlueZ 02/11] Add set auto connect in device Claudio Takahasi
@ 2011-09-02 21:38 ` Claudio Takahasi
  2011-09-02 21:38 ` [RFC BlueZ 04/11] Add checking if profiles are requesting connection Claudio Takahasi
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 14+ messages in thread
From: Claudio Takahasi @ 2011-09-02 21:38 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

If auto connect is enabled, queue another connection attempt until
the adapter sets auto connect to FALSE(after 3 minutes).
---
 src/device.c |   12 +++++++++++-
 1 files changed, 11 insertions(+), 1 deletions(-)

diff --git a/src/device.c b/src/device.c
index 4af6c1d..e812e01 100644
--- a/src/device.c
+++ b/src/device.c
@@ -1674,6 +1674,8 @@ done:
 	browse_request_free(req, shutdown);
 }
 
+static gboolean att_connect(gpointer user_data);
+
 static void att_connect_cb(GIOChannel *io, GError *gerr, gpointer user_data)
 {
 	struct btd_device *device = user_data;
@@ -1691,7 +1693,8 @@ static void att_connect_cb(GIOChannel *io, GError *gerr, gpointer user_data)
 
 			device->browse = NULL;
 			browse_request_free(req, TRUE);
-		}
+		} else if (device->auto_connect)
+			g_idle_add(att_connect, device);
 
 		return;
 	}
@@ -1928,6 +1931,13 @@ void device_set_auto_connect(struct btd_device *device, gboolean enable)
 	DBG("auto connect: %d", enable);
 
 	device->auto_connect = enable;
+
+	if (device->attrib) {
+		DBG("Already connected");
+		return;
+	}
+
+	g_idle_add(att_connect, device);
 }
 
 void device_set_type(struct btd_device *device, device_type_t type)
-- 
1.7.6


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [RFC BlueZ 04/11] Add checking if profiles are requesting connection
  2011-09-02 21:38 [RFC BlueZ 00/11] Re-connections triggered by platform event Claudio Takahasi
                   ` (2 preceding siblings ...)
  2011-09-02 21:38 ` [RFC BlueZ 03/11] Add continuous connection attempt Claudio Takahasi
@ 2011-09-02 21:38 ` Claudio Takahasi
  2011-09-02 21:38 ` [RFC BlueZ 05/11] Add tracking of connect sources Claudio Takahasi
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 14+ messages in thread
From: Claudio Takahasi @ 2011-09-02 21:38 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

Before triggering automatic ATTIO connections driven by platform event,
the device needs to check if there is at least one entry in the ATTIO
connection callback, meaning that there is profile requesting connection
and the state is auto connection.
---
 src/device.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/src/device.c b/src/device.c
index e812e01..432c02b 100644
--- a/src/device.c
+++ b/src/device.c
@@ -1937,6 +1937,9 @@ void device_set_auto_connect(struct btd_device *device, gboolean enable)
 		return;
 	}
 
+	if (device->attios == NULL && device->attios_offline == NULL)
+		return;
+
 	g_idle_add(att_connect, device);
 }
 
-- 
1.7.6


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [RFC BlueZ 05/11] Add tracking of connect sources
  2011-09-02 21:38 [RFC BlueZ 00/11] Re-connections triggered by platform event Claudio Takahasi
                   ` (3 preceding siblings ...)
  2011-09-02 21:38 ` [RFC BlueZ 04/11] Add checking if profiles are requesting connection Claudio Takahasi
@ 2011-09-02 21:38 ` Claudio Takahasi
  2011-09-02 21:38 ` [RFC BlueZ 06/11] Disable automatic connections after 3 minutes Claudio Takahasi
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 14+ messages in thread
From: Claudio Takahasi @ 2011-09-02 21:38 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

Avoids queue dupplicated requests connects for the same device. Sources
can be triggered by auto connect or on demand connection request when a
given profile registers ATTIO connection callbacks.
---
 src/device.c |   28 +++++++++++++++++++++++++---
 1 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/src/device.c b/src/device.c
index 432c02b..4f5c6d8 100644
--- a/src/device.c
+++ b/src/device.c
@@ -137,6 +137,7 @@ struct btd_device {
 	GSList		*attios;
 	GSList		*attios_offline;
 	guint		attachid;		/* Attrib server attach */
+	guint		auto_id;		/* Auto connect source id */
 
 	gboolean	connected;
 
@@ -234,6 +235,9 @@ static void device_free(gpointer user_data)
 	if (device->discov_timer)
 		g_source_remove(device->discov_timer);
 
+	if (device->auto_id)
+		g_source_remove(device->auto_id);
+
 	DBG("%p", device);
 
 	g_free(device->authr);
@@ -1676,6 +1680,13 @@ done:
 
 static gboolean att_connect(gpointer user_data);
 
+static void att_connect_dispatched(gpointer user_data)
+{
+	struct btd_device *device = user_data;
+
+	device->auto_id = 0;
+}
+
 static void att_connect_cb(GIOChannel *io, GError *gerr, gpointer user_data)
 {
 	struct btd_device *device = user_data;
@@ -1694,7 +1705,10 @@ static void att_connect_cb(GIOChannel *io, GError *gerr, gpointer user_data)
 			device->browse = NULL;
 			browse_request_free(req, TRUE);
 		} else if (device->auto_connect)
-			g_idle_add(att_connect, device);
+			device->auto_id = g_idle_add_full(
+						G_PRIORITY_DEFAULT_IDLE,
+						att_connect, device,
+						att_connect_dispatched);
 
 		return;
 	}
@@ -1932,6 +1946,9 @@ void device_set_auto_connect(struct btd_device *device, gboolean enable)
 
 	device->auto_connect = enable;
 
+	if (device->auto_id != 0)
+		return;
+
 	if (device->attrib) {
 		DBG("Already connected");
 		return;
@@ -1940,7 +1957,9 @@ void device_set_auto_connect(struct btd_device *device, gboolean enable)
 	if (device->attios == NULL && device->attios_offline == NULL)
 		return;
 
-	g_idle_add(att_connect, device);
+	device->auto_id = g_idle_add_full(G_PRIORITY_DEFAULT_IDLE,
+						att_connect, device,
+						att_connect_dispatched);
 }
 
 void device_set_type(struct btd_device *device, device_type_t type)
@@ -2621,7 +2640,10 @@ guint btd_device_add_attio_callback(struct btd_device *device,
 									attio);
 		g_idle_add(notify_attios, device);
 	} else {
-		g_idle_add(att_connect, device);
+		device->auto_id = g_idle_add_full(G_PRIORITY_DEFAULT_IDLE,
+						att_connect, device,
+						att_connect_dispatched);
+
 		device->attios = g_slist_append(device->attios, attio);
 	}
 
-- 
1.7.6


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [RFC BlueZ 06/11] Disable automatic connections after 3 minutes
  2011-09-02 21:38 [RFC BlueZ 00/11] Re-connections triggered by platform event Claudio Takahasi
                   ` (4 preceding siblings ...)
  2011-09-02 21:38 ` [RFC BlueZ 05/11] Add tracking of connect sources Claudio Takahasi
@ 2011-09-02 21:38 ` Claudio Takahasi
  2011-09-02 21:38 ` [RFC BlueZ 07/11] Add display lock watcher on maemo6 plugin Claudio Takahasi
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 14+ messages in thread
From: Claudio Takahasi @ 2011-09-02 21:38 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

---
 src/adapter.c |   24 ++++++++++++++++++++++++
 src/device.c  |    8 ++++++++
 2 files changed, 32 insertions(+), 0 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index eec721c..d282157 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -78,6 +78,7 @@
 #define check_address(address) bachk(address)
 
 #define OFF_TIMER 3
+#define AUTO_TIMER	180
 
 static DBusConnection *connection = NULL;
 static GSList *adapter_drivers = NULL;
@@ -134,6 +135,7 @@ struct btd_adapter {
 	GSList *mode_sessions;		/* Request Mode sessions */
 	GSList *disc_sessions;		/* Discovery sessions */
 	guint scheduler_id;		/* Scheduler handle */
+	guint auto_timeout_id;		/* Automatic connections timeout */
 	sdp_list_t *services;		/* Services associated to adapter */
 
 	gboolean pairable;		/* pairable state */
@@ -3538,6 +3540,22 @@ int btd_adapter_switch_offline(struct btd_adapter *adapter)
 	return 0;
 }
 
+static gboolean disable_auto(gpointer user_data)
+{
+	struct btd_adapter *adapter = user_data;
+	GSList *l;
+
+	for (l = adapter->devices; l; l = l->next) {
+		struct btd_device *device = l->data;
+
+		device_set_auto_connect(device, FALSE);
+	}
+
+	adapter->auto_timeout_id = 0;
+
+	return FALSE;
+}
+
 static void set_auto_connect(gpointer data, gpointer user_data)
 {
 	struct btd_device *device = data;
@@ -3555,7 +3573,13 @@ void btd_adapter_system_unlocked(struct btd_adapter *adapter)
 
 	DBG("Unlocked");
 
+	if (adapter->auto_timeout_id)
+		return;
+
 	g_slist_foreach(adapter->devices, set_auto_connect, NULL);
+
+	adapter->auto_timeout_id = g_timeout_add_seconds(AUTO_TIMER,
+						disable_auto, adapter);
 }
 
 void btd_adapter_register_pin_cb(struct btd_adapter *adapter,
diff --git a/src/device.c b/src/device.c
index 4f5c6d8..1daa063 100644
--- a/src/device.c
+++ b/src/device.c
@@ -1946,6 +1946,14 @@ void device_set_auto_connect(struct btd_device *device, gboolean enable)
 
 	device->auto_connect = enable;
 
+	/* Disabling auto connect */
+	if (enable == FALSE) {
+		if (device->auto_id)
+			g_source_remove(device->auto_id);
+		return;
+	}
+
+	/* Enabling auto connect */
 	if (device->auto_id != 0)
 		return;
 
-- 
1.7.6


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [RFC BlueZ 07/11] Add display lock watcher on maemo6 plugin
  2011-09-02 21:38 [RFC BlueZ 00/11] Re-connections triggered by platform event Claudio Takahasi
                   ` (5 preceding siblings ...)
  2011-09-02 21:38 ` [RFC BlueZ 06/11] Disable automatic connections after 3 minutes Claudio Takahasi
@ 2011-09-02 21:38 ` Claudio Takahasi
  2011-09-02 21:38 ` [RFC BlueZ 08/11] Notify unlocked event when using " Claudio Takahasi
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 14+ messages in thread
From: Claudio Takahasi @ 2011-09-02 21:38 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Anderson Briglia

From: Anderson Briglia <anderson.briglia@openbossa.org>

Implements display status signal watcher in maemo6 plugin.
---
 plugins/maemo6.c |   30 ++++++++++++++++++++++++++++++
 1 files changed, 30 insertions(+), 0 deletions(-)

diff --git a/plugins/maemo6.c b/plugins/maemo6.c
index 56f2664..0247f20 100644
--- a/plugins/maemo6.c
+++ b/plugins/maemo6.c
@@ -46,12 +46,35 @@
 #define MCE_RADIO_STATES_CHANGE_REQ	"req_radio_states_change"
 #define MCE_RADIO_STATES_GET		"get_radio_states"
 #define MCE_RADIO_STATES_SIG		"radio_states_ind"
+#define MCE_TKLOCK_MODE_SIG		"tklock_mode_ind"
 
 static guint watch_id;
+static guint tklock_watch_id;
 static DBusConnection *conn = NULL;
 static gboolean mce_bt_set = FALSE;
 static gboolean collision = FALSE;
 
+static void mce_tklock_mode_cb(DBusConnection *connection,
+					DBusMessage *message, void *user_data)
+{
+	DBusMessageIter args;
+	const char *sigvalue;
+	struct btd_adapter *adapter = user_data;
+
+	if (!dbus_message_iter_init(message, &args)) {
+		error("message has no arguments");
+		return;
+	}
+
+	if (dbus_message_iter_get_arg_type(&args) != DBUS_TYPE_STRING) {
+		error("argument is not string");
+		return;
+	}
+
+	dbus_message_iter_get_basic(&args, &sigvalue);
+	DBG("got signal with value %s", sigvalue);
+}
+
 static gboolean mce_signal_callback(DBusConnection *connection,
 					DBusMessage *message, void *user_data)
 {
@@ -204,6 +227,10 @@ static int mce_probe(struct btd_adapter *adapter)
 					MCE_SIGNAL_IF, MCE_RADIO_STATES_SIG,
 					mce_signal_callback, adapter, NULL);
 
+	tklock_watch_id = g_dbus_add_signal_watch(conn, NULL, MCE_SIGNAL_PATH,
+					MCE_SIGNAL_IF, MCE_TKLOCK_MODE_SIG,
+					mce_tklock_mode_cb, adapter, NULL);
+
 	btd_adapter_register_powered_callback(adapter, adapter_powered);
 
 	return 0;
@@ -216,6 +243,9 @@ static void mce_remove(struct btd_adapter *adapter)
 	if (watch_id > 0)
 		g_dbus_remove_watch(conn, watch_id);
 
+	if (tklock_watch_id > 0)
+		g_dbus_remove_watch(conn, tklock_watch_id);
+
 	btd_adapter_unregister_powered_callback(adapter, adapter_powered);
 }
 
-- 
1.7.6


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [RFC BlueZ 08/11] Notify unlocked event when using maemo6 plugin
  2011-09-02 21:38 [RFC BlueZ 00/11] Re-connections triggered by platform event Claudio Takahasi
                   ` (6 preceding siblings ...)
  2011-09-02 21:38 ` [RFC BlueZ 07/11] Add display lock watcher on maemo6 plugin Claudio Takahasi
@ 2011-09-02 21:38 ` Claudio Takahasi
  2011-09-02 21:38 ` [RFC BlueZ 09/11] Add automatic connect timeout config option Claudio Takahasi
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 14+ messages in thread
From: Claudio Takahasi @ 2011-09-02 21:38 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

Inform the adapter that the system has been unlocked when the MCE
sends the tklock_mode_ind signal. This signal will trigger the
automatic re-connections for bonded devices.
---
 plugins/maemo6.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/plugins/maemo6.c b/plugins/maemo6.c
index 0247f20..8d203df 100644
--- a/plugins/maemo6.c
+++ b/plugins/maemo6.c
@@ -73,6 +73,9 @@ static void mce_tklock_mode_cb(DBusConnection *connection,
 
 	dbus_message_iter_get_basic(&args, &sigvalue);
 	DBG("got signal with value %s", sigvalue);
+
+	if (g_strcmp0("unlocked", sigvalue) == 0)
+		btd_adapter_system_unlocked(adapter);
 }
 
 static gboolean mce_signal_callback(DBusConnection *connection,
-- 
1.7.6


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [RFC BlueZ 09/11] Add automatic connect timeout config option
  2011-09-02 21:38 [RFC BlueZ 00/11] Re-connections triggered by platform event Claudio Takahasi
                   ` (7 preceding siblings ...)
  2011-09-02 21:38 ` [RFC BlueZ 08/11] Notify unlocked event when using " Claudio Takahasi
@ 2011-09-02 21:38 ` Claudio Takahasi
  2011-09-02 21:38 ` [RFC BlueZ 10/11] Add an interval between connection attempts Claudio Takahasi
  2011-09-02 21:38 ` [RFC BlueZ 11/11] Enable re-connections when disconnected Claudio Takahasi
  10 siblings, 0 replies; 14+ messages in thread
From: Claudio Takahasi @ 2011-09-02 21:38 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

Add new option in main.conf allowing change the default automatic
connection timer. This value defines how many seconds re-connection
for bonded devices will be active when a platform/user event triggers
the automatic re-connections.
---
 src/adapter.c |    3 +--
 src/hcid.h    |    1 +
 src/main.c    |   12 ++++++++++++
 src/main.conf |    6 ++++++
 4 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index d282157..6b1cce6 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -78,7 +78,6 @@
 #define check_address(address) bachk(address)
 
 #define OFF_TIMER 3
-#define AUTO_TIMER	180
 
 static DBusConnection *connection = NULL;
 static GSList *adapter_drivers = NULL;
@@ -3578,7 +3577,7 @@ void btd_adapter_system_unlocked(struct btd_adapter *adapter)
 
 	g_slist_foreach(adapter->devices, set_auto_connect, NULL);
 
-	adapter->auto_timeout_id = g_timeout_add_seconds(AUTO_TIMER,
+	adapter->auto_timeout_id = g_timeout_add_seconds(main_opts.autoto,
 						disable_auto, adapter);
 }
 
diff --git a/src/hcid.h b/src/hcid.h
index ef25c79..e993a16 100644
--- a/src/hcid.h
+++ b/src/hcid.h
@@ -29,6 +29,7 @@ struct main_opts {
 	char		*name;
 	uint32_t	class;
 	uint16_t	pageto;
+	uint16_t	autoto;
 	uint32_t	discovto;
 	uint32_t	pairto;
 	uint16_t	link_mode;
diff --git a/src/main.c b/src/main.c
index 06becfe..9b23803 100644
--- a/src/main.c
+++ b/src/main.c
@@ -63,6 +63,7 @@
 #define LAST_ADAPTER_EXIT_TIMEOUT 30
 
 #define DEFAULT_DISCOVERABLE_TIMEOUT 180 /* 3 minutes */
+#define DEFAULT_AUTO_CONNECT_TIMEOUT 180 /* 3 minutes */
 
 struct main_opts main_opts;
 
@@ -128,6 +129,16 @@ static void parse_config(GKeyFile *config)
 		main_opts.flags |= 1 << HCID_SET_PAGETO;
 	}
 
+	val = g_key_file_get_integer(config, "General", "AutoConnectTimeout",
+									&err);
+	if (err) {
+		DBG("%s", err->message);
+		g_clear_error(&err);
+	} else {
+		DBG("auto_to=%d", val);
+		main_opts.autoto = val;
+	}
+
 	str = g_key_file_get_string(config, "General", "Name", &err);
 	if (err) {
 		DBG("%s", err->message);
@@ -230,6 +241,7 @@ static void init_defaults(void)
 	main_opts.mode	= MODE_CONNECTABLE;
 	main_opts.name	= g_strdup("BlueZ");
 	main_opts.discovto	= DEFAULT_DISCOVERABLE_TIMEOUT;
+	main_opts.autoto = DEFAULT_AUTO_CONNECT_TIMEOUT;
 	main_opts.remember_powered = TRUE;
 	main_opts.reverse_sdp = TRUE;
 	main_opts.name_resolv = TRUE;
diff --git a/src/main.conf b/src/main.conf
index a9e2060..8ae817d 100644
--- a/src/main.conf
+++ b/src/main.conf
@@ -30,6 +30,12 @@ PageTimeout = 8192
 # The value is in seconds. Defaults is 30.
 DiscoverSchedulerInterval = 30
 
+# Automatic connection for bonded devices driven by platform/user events.
+# If a platform plugin uses this mechanism, automatic connections will be
+# enabled during the interval defined below. Initially, this feature
+# intends to be used to establish connections to ATT channels.
+AutoConnectTimeout = 180
+
 # What value should be assumed for the adapter Powered property when
 # SetProperty(Powered, ...) hasn't been called yet. Defaults to true
 InitiallyPowered = true
-- 
1.7.6


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [RFC BlueZ 10/11] Add an interval between connection attempts
  2011-09-02 21:38 [RFC BlueZ 00/11] Re-connections triggered by platform event Claudio Takahasi
                   ` (8 preceding siblings ...)
  2011-09-02 21:38 ` [RFC BlueZ 09/11] Add automatic connect timeout config option Claudio Takahasi
@ 2011-09-02 21:38 ` Claudio Takahasi
  2011-09-02 21:38 ` [RFC BlueZ 11/11] Enable re-connections when disconnected Claudio Takahasi
  10 siblings, 0 replies; 14+ messages in thread
From: Claudio Takahasi @ 2011-09-02 21:38 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

For connection attempts to the same remote device, add 5 seconds
interval until the next connect attempt.
---
 src/device.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/src/device.c b/src/device.c
index 1daa063..4f58afc 100644
--- a/src/device.c
+++ b/src/device.c
@@ -66,6 +66,8 @@
 #define DISCONNECT_TIMER	2
 #define DISCOVERY_TIMER		2
 
+#define AUTO_CONNECTION_INTERVAL	5 /* Next connection attempt */
+
 /* When all services should trust a remote device */
 #define GLOBAL_TRUST "[all]"
 
@@ -1705,8 +1707,9 @@ static void att_connect_cb(GIOChannel *io, GError *gerr, gpointer user_data)
 			device->browse = NULL;
 			browse_request_free(req, TRUE);
 		} else if (device->auto_connect)
-			device->auto_id = g_idle_add_full(
+			device->auto_id = g_timeout_add_seconds_full(
 						G_PRIORITY_DEFAULT_IDLE,
+						AUTO_CONNECTION_INTERVAL,
 						att_connect, device,
 						att_connect_dispatched);
 
-- 
1.7.6


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [RFC BlueZ 11/11] Enable re-connections when disconnected
  2011-09-02 21:38 [RFC BlueZ 00/11] Re-connections triggered by platform event Claudio Takahasi
                   ` (9 preceding siblings ...)
  2011-09-02 21:38 ` [RFC BlueZ 10/11] Add an interval between connection attempts Claudio Takahasi
@ 2011-09-02 21:38 ` Claudio Takahasi
  10 siblings, 0 replies; 14+ messages in thread
From: Claudio Takahasi @ 2011-09-02 21:38 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

If the device is still on auto connect mode, re-connections should
be enabled. The current implementation has a limitation: it ignores
the disconnection reason. Re-connection should be enabled if the host
initiated the disconnection.
---
 src/device.c |   13 +++++++++++--
 1 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/device.c b/src/device.c
index 4f58afc..b7b7bb8 100644
--- a/src/device.c
+++ b/src/device.c
@@ -1616,6 +1616,9 @@ static void attio_disconnected(gpointer data, gpointer user_data)
 		attio->dcfunc(attio->user_data);
 }
 
+static gboolean att_connect(gpointer user_data);
+static void att_connect_dispatched(gpointer user_data);
+
 static void attrib_disconnected(gpointer user_data)
 {
 	struct btd_device *device = user_data;
@@ -1625,6 +1628,14 @@ static void attrib_disconnected(gpointer user_data)
 	attrib_channel_detach(device->attachid);
 	g_attrib_unref(device->attrib);
 	device->attrib = NULL;
+
+	if (device->auto_connect == FALSE)
+		return;
+
+	device->auto_id = g_timeout_add_seconds_full(G_PRIORITY_DEFAULT_IDLE,
+						AUTO_CONNECTION_INTERVAL,
+						att_connect, device,
+						att_connect_dispatched);
 }
 
 static void primary_cb(GSList *services, guint8 status, gpointer user_data)
@@ -1680,8 +1691,6 @@ done:
 	browse_request_free(req, shutdown);
 }
 
-static gboolean att_connect(gpointer user_data);
-
 static void att_connect_dispatched(gpointer user_data)
 {
 	struct btd_device *device = user_data;
-- 
1.7.6


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [RFC BlueZ 02/11] Add set auto connect in device
  2011-09-02 21:38 ` [RFC BlueZ 02/11] Add set auto connect in device Claudio Takahasi
@ 2011-09-05  9:55   ` Johan Hedberg
  2011-09-05 13:47     ` Claudio Takahasi
  0 siblings, 1 reply; 14+ messages in thread
From: Johan Hedberg @ 2011-09-05  9:55 UTC (permalink / raw)
  To: Claudio Takahasi; +Cc: linux-bluetooth

Hi Claudio,

On Fri, Sep 02, 2011, Claudio Takahasi wrote:
> +void btd_adapter_system_unlocked(struct btd_adapter *adapter)
> +{
> +	if (!adapter->up)
> +		return;
> +
> +	DBG("Unlocked");
> +
> +	g_slist_foreach(adapter->devices, set_auto_connect, NULL);
> +}

While the concept seems fine I think you've got the wrong name for the
function. You shouldn't assume that "system unlocked" is the only reason
for enabling auto-connect for the devices. It's as if you'd be pushing
policy into the core daemon ("if unlocked, then auto-connect"). Instead
the function should be named according to what it does, e.g.
btd_adapter_enable_auto_connect or btd_adapter_auto_connect_devices.

Johan

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [RFC BlueZ 02/11] Add set auto connect in device
  2011-09-05  9:55   ` Johan Hedberg
@ 2011-09-05 13:47     ` Claudio Takahasi
  0 siblings, 0 replies; 14+ messages in thread
From: Claudio Takahasi @ 2011-09-05 13:47 UTC (permalink / raw)
  To: johan.hedberg, linux-bluetooth

Hi Johan,

On Mon, Sep 5, 2011 at 6:55 AM, Johan Hedberg <johan.hedberg@gmail.com> wrote:
> Hi Claudio,
>
> On Fri, Sep 02, 2011, Claudio Takahasi wrote:
>> +void btd_adapter_system_unlocked(struct btd_adapter *adapter)
>> +{
>> +     if (!adapter->up)
>> +             return;
>> +
>> +     DBG("Unlocked");
>> +
>> +     g_slist_foreach(adapter->devices, set_auto_connect, NULL);
>> +}
>
> While the concept seems fine I think you've got the wrong name for the
> function. You shouldn't assume that "system unlocked" is the only reason
> for enabling auto-connect for the devices. It's as if you'd be pushing
> policy into the core daemon ("if unlocked, then auto-connect"). Instead
> the function should be named according to what it does, e.g.
> btd_adapter_enable_auto_connect or btd_adapter_auto_connect_devices.
>
> Johan

Thanks for the feedback. I gonna rename the function. I was more
afraid of the concept, in theory it could be more generic, triggering
connections to other services.
But one step at a time, first we need to improve the handling of
multiple LE connection requests(Including LE passive scanning).

BR,
Claudio

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2011-09-05 13:47 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-02 21:38 [RFC BlueZ 00/11] Re-connections triggered by platform event Claudio Takahasi
2011-09-02 21:38 ` [RFC BlueZ 01/11] Remove timer to trigger connection attempts Claudio Takahasi
2011-09-02 21:38 ` [RFC BlueZ 02/11] Add set auto connect in device Claudio Takahasi
2011-09-05  9:55   ` Johan Hedberg
2011-09-05 13:47     ` Claudio Takahasi
2011-09-02 21:38 ` [RFC BlueZ 03/11] Add continuous connection attempt Claudio Takahasi
2011-09-02 21:38 ` [RFC BlueZ 04/11] Add checking if profiles are requesting connection Claudio Takahasi
2011-09-02 21:38 ` [RFC BlueZ 05/11] Add tracking of connect sources Claudio Takahasi
2011-09-02 21:38 ` [RFC BlueZ 06/11] Disable automatic connections after 3 minutes Claudio Takahasi
2011-09-02 21:38 ` [RFC BlueZ 07/11] Add display lock watcher on maemo6 plugin Claudio Takahasi
2011-09-02 21:38 ` [RFC BlueZ 08/11] Notify unlocked event when using " Claudio Takahasi
2011-09-02 21:38 ` [RFC BlueZ 09/11] Add automatic connect timeout config option Claudio Takahasi
2011-09-02 21:38 ` [RFC BlueZ 10/11] Add an interval between connection attempts Claudio Takahasi
2011-09-02 21:38 ` [RFC BlueZ 11/11] Enable re-connections when disconnected Claudio Takahasi

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.