linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH BlueZ 0/6] Proximity configs and LinkLoss alert write
@ 2011-07-27 21:53 Claudio Takahasi
  2011-07-27 21:53 ` [PATCH BlueZ 1/6] Proximity Monitor: Write Alert Level to Reporter Claudio Takahasi
                   ` (6 more replies)
  0 siblings, 7 replies; 18+ messages in thread
From: Claudio Takahasi @ 2011-07-27 21:53 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

Dependency: "[PATCH BlueZ 0/5] Add Get/Set Property for Link Loss"

The following patches implement the configuration file to allow
disabling Proximity Monitor services and Find Me. First patch using
attio connection callback registration mechanism to write Link Loss
Alert level.

Anderson Lizardo (1):
  Proximity Monitor: Write Alert Level to Reporter

Claudio Takahasi (5):
  Add Tx Power and Immediate Alert UUID
  Add config file for proximity monitor
  Match probed UUIDs and enabled services
  Return an error if LinkLoss is disabled
  Return LinkLossAlertLevel if enabled

 Makefile.am              |    4 +-
 proximity/main.c         |   30 ++++++++++++-
 proximity/manager.c      |   52 ++++++++++++++++++++--
 proximity/manager.h      |    2 +-
 proximity/monitor.c      |  108 ++++++++++++++++++++++++++++++++++++++++++++-
 proximity/monitor.h      |    9 +++-
 proximity/proximity.conf |    9 ++++
 7 files changed, 201 insertions(+), 13 deletions(-)
 create mode 100644 proximity/proximity.conf

-- 
1.7.6


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

* [PATCH BlueZ 1/6] Proximity Monitor: Write Alert Level to Reporter
  2011-07-27 21:53 [PATCH BlueZ 0/6] Proximity configs and LinkLoss alert write Claudio Takahasi
@ 2011-07-27 21:53 ` Claudio Takahasi
  2011-07-28  4:40   ` Santiago Carot
       [not found]   ` <CACLukz+g-994zKLK1aPkBusEhv=ti850KhMSjGZQjJOdL9kdcw@mail.gmail.com>
  2011-07-27 21:53 ` [PATCH BlueZ 2/6] Add Tx Power and Immediate Alert UUID Claudio Takahasi
                   ` (5 subsequent siblings)
  6 siblings, 2 replies; 18+ messages in thread
From: Claudio Takahasi @ 2011-07-27 21:53 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Anderson Lizardo

From: Anderson Lizardo <anderson.lizardo@openbossa.org>

When the Proximity Monitor connects to the Reporter, it shall write its
current Alert Level (usually defined by the user) into the Alert Level
characteristic on the Monitor. So once the link is lost, the Monitor
will alert with the appropriate level.

Note: Register connection callback to write alert level to the Reporter.
---
 proximity/monitor.c |   92 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 92 insertions(+), 0 deletions(-)

diff --git a/proximity/monitor.c b/proximity/monitor.c
index 8465f92..f7995aa 100644
--- a/proximity/monitor.c
+++ b/proximity/monitor.c
@@ -35,19 +35,28 @@
 #include <sys/stat.h>
 
 #include <bluetooth/bluetooth.h>
+#include <bluetooth/uuid.h>
 
 #include "dbus-common.h"
 #include "adapter.h"
 #include "device.h"
 #include "error.h"
 #include "log.h"
+#include "att.h"
+#include "gattrib.h"
+#include "gatt.h"
+#include "attio.h"
 #include "monitor.h"
 #include "textfile.h"
 
 #define PROXIMITY_INTERFACE "org.bluez.Proximity"
 
+#define LINK_LOSS_UUID "00001803-0000-1000-8000-00805f9b34fb"
+#define ALERT_LEVEL_CHR_UUID 0x2A06
+
 struct monitor {
 	struct btd_device *device;
+	GAttrib *attrib;
 	char *linklosslevel;		/* Link Loss Alert Level */
 };
 
@@ -90,6 +99,86 @@ static char *read_proximity_config(bdaddr_t *sba, bdaddr_t *dba,
 	return textfile_caseget(filename, key);
 }
 
+static void char_discovered_cb(GSList *characteristics, guint8 status,
+							gpointer user_data)
+{
+	struct monitor *monitor = user_data;
+	struct att_char *chr;
+	uint8_t value;
+
+	if (status) {
+		error("Discover Link Loss handle: %s", att_ecode2str(status));
+		return;
+	}
+
+	if (strcmp(monitor->linklosslevel, "none") == 0)
+		value = 0x00;
+	else if (strcmp(monitor->linklosslevel, "mild") == 0)
+		value = 0x01;
+	else if (strcmp(monitor->linklosslevel, "high") == 0)
+		value = 0x02;
+
+	DBG("Setting alert level \"%s\" on Reporter", monitor->linklosslevel);
+
+	/* Assume there is a single Alert Level characteristic */
+	chr = characteristics->data;
+
+	gatt_write_cmd(monitor->attrib, chr->value_handle, &value, 1, NULL, NULL);
+}
+
+static int write_alert_level(struct monitor *monitor)
+{
+	GSList *l, *primaries;
+	uint16_t start = 0, end = 0;
+	bt_uuid_t uuid;
+
+	primaries = btd_device_get_primaries(monitor->device);
+	if (primaries == NULL) {
+		DBG("No primary services found");
+		return -1;
+	}
+
+	for (l = primaries; l; l = l->next) {
+		struct att_primary *primary = l->data;
+
+		if (strcmp(primary->uuid, LINK_LOSS_UUID) == 0) {
+			start = primary->start;
+			end = primary->end;
+			break;
+		}
+	}
+
+	if (!start) {
+		DBG("Link Loss service not found");
+		return -1;
+	}
+
+	DBG("Link Loss service found at range 0x%04x-0x%04x", start, end);
+
+	bt_uuid16_create(&uuid, ALERT_LEVEL_CHR_UUID);
+
+	/* FIXME: use cache (requires service changed support) ? */
+	gatt_discover_char(monitor->attrib, start, end, &uuid, char_discovered_cb,
+								monitor);
+
+	return 0;
+}
+
+static void attio_connected_cb(GAttrib *attrib, gpointer user_data)
+{
+	struct monitor *monitor = user_data;
+
+	monitor->attrib = attrib;
+	write_alert_level(monitor);
+}
+
+static void attio_disconnected_cb(gpointer user_data)
+{
+	struct monitor *monitor = user_data;
+
+	monitor->attrib = NULL;
+}
+
 static DBusMessage *set_link_loss_alert(DBusConnection *conn, DBusMessage *msg,
 						const char *level, void *data)
 {
@@ -229,6 +318,9 @@ int monitor_register(DBusConnection *conn, struct btd_device *device)
 
 	DBG("Registered interface %s on path %s", PROXIMITY_INTERFACE, path);
 
+	btd_device_add_attio_callback(device, attio_connected_cb,
+					attio_disconnected_cb, monitor);
+
 	return 0;
 }
 
-- 
1.7.6


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

* [PATCH BlueZ 2/6] Add Tx Power and Immediate Alert UUID
  2011-07-27 21:53 [PATCH BlueZ 0/6] Proximity configs and LinkLoss alert write Claudio Takahasi
  2011-07-27 21:53 ` [PATCH BlueZ 1/6] Proximity Monitor: Write Alert Level to Reporter Claudio Takahasi
@ 2011-07-27 21:53 ` Claudio Takahasi
  2011-07-28 14:43   ` [PATCH BlueZ v2 " Claudio Takahasi
  2011-07-27 21:53 ` [PATCH BlueZ 3/6] Add config file for proximity monitor Claudio Takahasi
                   ` (4 subsequent siblings)
  6 siblings, 1 reply; 18+ messages in thread
From: Claudio Takahasi @ 2011-07-27 21:53 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

Changes Proximity Monitor driver declaration adding the Tx Power and
Immediate Alert UUIDs. UUIDs are required to support Path Loss and
Find ME.
---
 proximity/manager.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/proximity/manager.c b/proximity/manager.c
index 8d0aee1..98ac59f 100644
--- a/proximity/manager.c
+++ b/proximity/manager.c
@@ -35,7 +35,9 @@
 #include "reporter.h"
 #include "manager.h"
 
-#define LINK_LOSS_UUID "00001803-0000-1000-8000-00805f9b34fb"
+#define IMMEDIATE_ALERT_UUID	"00001802-0000-1000-8000-00805f9b34fb"
+#define LINK_LOSS_UUID		"00001803-0000-1000-8000-00805f9b34fb"
+#define TX_POWER_UUID		"00001804-0000-1000-8000-00805f9b34fb"
 
 static DBusConnection *connection = NULL;
 
@@ -51,7 +53,7 @@ static void attio_device_remove(struct btd_device *device)
 
 static struct btd_device_driver monitor_driver = {
 	.name = "Proximity GATT Driver",
-	.uuids = BTD_UUIDS(LINK_LOSS_UUID),
+	.uuids = BTD_UUIDS(IMMEDIATE_ALERT_UUID, LINK_LOSS_UUID, TX_POWER_UUID),
 	.probe = attio_device_probe,
 	.remove = attio_device_remove,
 };
-- 
1.7.6


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

* [PATCH BlueZ 3/6] Add config file for proximity monitor
  2011-07-27 21:53 [PATCH BlueZ 0/6] Proximity configs and LinkLoss alert write Claudio Takahasi
  2011-07-27 21:53 ` [PATCH BlueZ 1/6] Proximity Monitor: Write Alert Level to Reporter Claudio Takahasi
  2011-07-27 21:53 ` [PATCH BlueZ 2/6] Add Tx Power and Immediate Alert UUID Claudio Takahasi
@ 2011-07-27 21:53 ` Claudio Takahasi
  2011-07-28 14:43   ` [PATCH BlueZ v2 " Claudio Takahasi
  2011-07-27 21:53 ` [PATCH BlueZ 4/6] Match probed UUIDs and enabled services Claudio Takahasi
                   ` (3 subsequent siblings)
  6 siblings, 1 reply; 18+ messages in thread
From: Claudio Takahasi @ 2011-07-27 21:53 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

Initial config file to disable Proximity and Find ME support in the
proximity monitor side. By default all services will be supported.
Config file is necessary at least to disable Find ME profile since the
Immediate Alert service is shared between Pass Loss and Find ME.
---
 Makefile.am              |    4 ++--
 proximity/main.c         |   30 +++++++++++++++++++++++++++++-
 proximity/manager.c      |   34 ++++++++++++++++++++++++++++++++--
 proximity/manager.h      |    2 +-
 proximity/proximity.conf |    9 +++++++++
 5 files changed, 73 insertions(+), 6 deletions(-)
 create mode 100644 proximity/proximity.conf

diff --git a/Makefile.am b/Makefile.am
index 0783666..9a980e5 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -298,8 +298,8 @@ EXTRA_DIST += src/genbuiltin src/bluetooth.conf \
 			input/input.conf serial/serial.conf \
 			audio/audio.conf audio/telephony-dummy.c \
 			audio/telephony-maemo5.c audio/telephony-ofono.c \
-			audio/telephony-maemo6.c sap/sap-dummy.c sap/sap-u8500.c
-
+			audio/telephony-maemo6.c sap/sap-dummy.c sap/sap-u8500.c \
+			proximity/proximity.conf
 
 if ALSA
 alsadir = $(libdir)/alsa-lib
diff --git a/proximity/main.c b/proximity/main.c
index ee7e4fb..5f0fc12 100644
--- a/proximity/main.c
+++ b/proximity/main.c
@@ -28,20 +28,45 @@
 
 #include <errno.h>
 
+#include <glib.h>
 #include <gdbus.h>
 
+#include "log.h"
 #include "plugin.h"
 #include "manager.h"
 
 static DBusConnection *connection = NULL;
+static GKeyFile *config = NULL;
+
+static GKeyFile *open_config_file(const char *file)
+{
+	GError *gerr = NULL;
+	GKeyFile *keyfile;
+
+	keyfile = g_key_file_new();
+
+	g_key_file_set_list_separator(keyfile, ',');
+
+	if (!g_key_file_load_from_file(keyfile, file, 0, &gerr)) {
+		error("Parsing %s failed: %s", file, gerr->message);
+		g_error_free(gerr);
+		g_key_file_free(keyfile);
+		return NULL;
+	}
+
+	return keyfile;
+}
 
 static int proximity_init(void)
 {
+
 	connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
 	if (connection == NULL)
 		return -EIO;
 
-	if (proximity_manager_init(connection) < 0) {
+	config = open_config_file(CONFIGDIR "/proximity.conf");
+
+	if (proximity_manager_init(connection, config) < 0) {
 		dbus_connection_unref(connection);
 		return -EIO;
 	}
@@ -51,6 +76,9 @@ static int proximity_init(void)
 
 static void proximity_exit(void)
 {
+	if (config)
+		g_key_file_free(config);
+
 	proximity_manager_exit();
 	dbus_connection_unref(connection);
 }
diff --git a/proximity/manager.c b/proximity/manager.c
index 98ac59f..e3e049d 100644
--- a/proximity/manager.c
+++ b/proximity/manager.c
@@ -41,6 +41,16 @@
 
 static DBusConnection *connection = NULL;
 
+static struct {
+	gboolean linkloss;
+	gboolean pathloss;
+	gboolean findme;
+} enabled  = {
+	.linkloss = TRUE,
+	.pathloss = TRUE,
+	.findme = TRUE,
+};
+
 static int attio_device_probe(struct btd_device *device, GSList *uuids)
 {
 	return monitor_register(connection, device);
@@ -58,10 +68,30 @@ static struct btd_device_driver monitor_driver = {
 	.remove = attio_device_remove,
 };
 
-int proximity_manager_init(DBusConnection *conn)
+static void load_config_file(GKeyFile *config)
+{
+	char **list;
+	int i;
+
+	list = g_key_file_get_string_list(config, "General", "Disable",
+								NULL, NULL);
+	for (i = 0; list && list[i] != NULL; i++) {
+		if (g_str_equal(list[i], "FindMe"))
+			enabled.findme = FALSE;
+		else if (g_str_equal(list[i], "LinkLoss"))
+			enabled.linkloss = FALSE;
+		else if (g_str_equal(list[i], "PathLoss"))
+			enabled.pathloss = FALSE;
+	}
+
+	g_strfreev(list);
+}
+
+int proximity_manager_init(DBusConnection *conn, GKeyFile *config)
 {
 	int ret;
-	/* TODO: Add Proximity Monitor/Reporter config */
+
+	load_config_file(config);
 
 	/* TODO: Register Proximity Monitor/Reporter drivers */
 	ret = btd_register_device_driver(&monitor_driver);
diff --git a/proximity/manager.h b/proximity/manager.h
index 7557a68..b0fe7c8 100644
--- a/proximity/manager.h
+++ b/proximity/manager.h
@@ -22,5 +22,5 @@
  *
  */
 
-int proximity_manager_init(DBusConnection *conn);
+int proximity_manager_init(DBusConnection *conn, GKeyFile *conf);
 void proximity_manager_exit(void);
diff --git a/proximity/proximity.conf b/proximity/proximity.conf
new file mode 100644
index 0000000..f4ef6f5
--- /dev/null
+++ b/proximity/proximity.conf
@@ -0,0 +1,9 @@
+# Configuration file for the proximity service
+
+# This section contains options which are not specific to any
+# particular interface
+[General]
+
+# If we want to disable support for specific services
+# Defaults to supporting all implemented services
+#Disable=LinkLoss,PathLoss,FindMe
-- 
1.7.6


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

* [PATCH BlueZ 4/6] Match probed UUIDs and enabled services
  2011-07-27 21:53 [PATCH BlueZ 0/6] Proximity configs and LinkLoss alert write Claudio Takahasi
                   ` (2 preceding siblings ...)
  2011-07-27 21:53 ` [PATCH BlueZ 3/6] Add config file for proximity monitor Claudio Takahasi
@ 2011-07-27 21:53 ` Claudio Takahasi
  2011-07-28 14:43   ` [PATCH BlueZ v2 " Claudio Takahasi
  2011-07-27 21:53 ` [PATCH BlueZ 5/6] Return an error if LinkLoss is disabled Claudio Takahasi
                   ` (2 subsequent siblings)
  6 siblings, 1 reply; 18+ messages in thread
From: Claudio Takahasi @ 2011-07-27 21:53 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

Verify if the service is enabled in the proximity configuration file
before to register the Proximity Monitor.
---
 proximity/manager.c |   22 ++++++++++++++++------
 proximity/monitor.c |    7 ++++++-
 proximity/monitor.h |    9 ++++++++-
 3 files changed, 30 insertions(+), 8 deletions(-)

diff --git a/proximity/manager.c b/proximity/manager.c
index e3e049d..a9526a1 100644
--- a/proximity/manager.c
+++ b/proximity/manager.c
@@ -41,11 +41,7 @@
 
 static DBusConnection *connection = NULL;
 
-static struct {
-	gboolean linkloss;
-	gboolean pathloss;
-	gboolean findme;
-} enabled  = {
+static struct enabled enabled  = {
 	.linkloss = TRUE,
 	.pathloss = TRUE,
 	.findme = TRUE,
@@ -53,7 +49,21 @@ static struct {
 
 static int attio_device_probe(struct btd_device *device, GSList *uuids)
 {
-	return monitor_register(connection, device);
+	gboolean linkloss = FALSE, pathloss = FALSE, findme = FALSE;
+
+	if (g_slist_find_custom(uuids, IMMEDIATE_ALERT_UUID,
+					(GCompareFunc) strcasecmp)) {
+		findme = enabled.findme;
+		if (g_slist_find_custom(uuids, TX_POWER_UUID,
+					(GCompareFunc) strcasecmp))
+			pathloss = enabled.pathloss;
+	}
+
+	if (g_slist_find_custom(uuids, LINK_LOSS_UUID,
+				(GCompareFunc) strcasecmp))
+		linkloss = enabled.linkloss;
+
+	return monitor_register(connection, device, linkloss, pathloss, findme);
 }
 
 static void attio_device_remove(struct btd_device *device)
diff --git a/proximity/monitor.c b/proximity/monitor.c
index f7995aa..6cea5df 100644
--- a/proximity/monitor.c
+++ b/proximity/monitor.c
@@ -57,6 +57,7 @@
 struct monitor {
 	struct btd_device *device;
 	GAttrib *attrib;
+	struct enabled enabled;
 	char *linklosslevel;		/* Link Loss Alert Level */
 };
 
@@ -290,7 +291,8 @@ static void monitor_destroy(gpointer user_data)
 	g_free(monitor);
 }
 
-int monitor_register(DBusConnection *conn, struct btd_device *device)
+int monitor_register(DBusConnection *conn, struct btd_device *device,
+			gboolean linkloss, gboolean pathloss, gboolean findme)
 {
 	const char *path = device_get_path(device);
 	struct monitor *monitor;
@@ -305,6 +307,9 @@ int monitor_register(DBusConnection *conn, struct btd_device *device)
 	monitor = g_new0(struct monitor, 1);
 	monitor->device = btd_device_ref(device);
 	monitor->linklosslevel = (level ? : g_strdup("none"));
+	monitor->enabled.linkloss = linkloss;
+	monitor->enabled.pathloss = pathloss;
+	monitor->enabled.findme = findme;
 
 	if (g_dbus_register_interface(conn, path,
 				PROXIMITY_INTERFACE,
diff --git a/proximity/monitor.h b/proximity/monitor.h
index 5c6ebf6..ef47ee1 100644
--- a/proximity/monitor.h
+++ b/proximity/monitor.h
@@ -22,5 +22,12 @@
  *
  */
 
-int monitor_register(DBusConnection *conn, struct btd_device *device);
+struct enabled {
+	gboolean linkloss;
+	gboolean pathloss;
+	gboolean findme;
+};
+
+int monitor_register(DBusConnection *conn, struct btd_device *device,
+			gboolean linkloss, gboolean pathloss, gboolean findme);
 void monitor_unregister(DBusConnection *conn, struct btd_device *device);
-- 
1.7.6


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

* [PATCH BlueZ 5/6] Return an error if LinkLoss is disabled
  2011-07-27 21:53 [PATCH BlueZ 0/6] Proximity configs and LinkLoss alert write Claudio Takahasi
                   ` (3 preceding siblings ...)
  2011-07-27 21:53 ` [PATCH BlueZ 4/6] Match probed UUIDs and enabled services Claudio Takahasi
@ 2011-07-27 21:53 ` Claudio Takahasi
  2011-07-28 14:43   ` [PATCH BlueZ v2 " Claudio Takahasi
  2011-07-27 21:53 ` [PATCH BlueZ 6/6] Return LinkLossAlertLevel if enabled Claudio Takahasi
  2011-07-28 14:42 ` [PATCH BlueZ v2 0/6] Proximity configs and LinkLoss alert write Claudio Takahasi
  6 siblings, 1 reply; 18+ messages in thread
From: Claudio Takahasi @ 2011-07-27 21:53 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

Changes SetProperty method of the Proximity Monitor to verify if the
LinkLoss service is enabled before allowing to change the alert level.
Not available error is returned if LinkLoss service is disabled in the
Proximity configuration file.
---
 proximity/monitor.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/proximity/monitor.c b/proximity/monitor.c
index 6cea5df..5aa954d 100644
--- a/proximity/monitor.c
+++ b/proximity/monitor.c
@@ -240,6 +240,7 @@ static DBusMessage *get_properties(DBusConnection *conn,
 static DBusMessage *set_property(DBusConnection *conn,
 					DBusMessage *msg, void *data)
 {
+	struct monitor *monitor = data;
 	const char *property;
 	DBusMessageIter iter;
 	DBusMessageIter sub;
@@ -259,6 +260,9 @@ static DBusMessage *set_property(DBusConnection *conn,
 	dbus_message_iter_recurse(&iter, &sub);
 
 	if (g_str_equal("LinkLossAlertLevel", property)) {
+		if (monitor->enabled.linkloss == FALSE)
+			return btd_error_not_available(msg);
+
 		if (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_STRING)
 			return btd_error_invalid_args(msg);
 
-- 
1.7.6


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

* [PATCH BlueZ 6/6] Return LinkLossAlertLevel if enabled
  2011-07-27 21:53 [PATCH BlueZ 0/6] Proximity configs and LinkLoss alert write Claudio Takahasi
                   ` (4 preceding siblings ...)
  2011-07-27 21:53 ` [PATCH BlueZ 5/6] Return an error if LinkLoss is disabled Claudio Takahasi
@ 2011-07-27 21:53 ` Claudio Takahasi
  2011-07-28 14:43   ` [PATCH BlueZ v2 " Claudio Takahasi
  2011-07-28 14:42 ` [PATCH BlueZ v2 0/6] Proximity configs and LinkLoss alert write Claudio Takahasi
  6 siblings, 1 reply; 18+ messages in thread
From: Claudio Takahasi @ 2011-07-27 21:53 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

GetProperties method of Proximity Monitor should not append the
LinkLossAlertLevel property if the LinkLoss service is not enabled
in the configuration file.
---
 proximity/monitor.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/proximity/monitor.c b/proximity/monitor.c
index 5aa954d..96a2ee1 100644
--- a/proximity/monitor.c
+++ b/proximity/monitor.c
@@ -229,8 +229,9 @@ static DBusMessage *get_properties(DBusConnection *conn,
 			DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
 			DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict);
 
-	dict_append_entry(&dict, "LinkLossAlertLevel",
-			DBUS_TYPE_STRING, &monitor->linklosslevel);
+	if (monitor->enabled.linkloss)
+		dict_append_entry(&dict, "LinkLossAlertLevel",
+				DBUS_TYPE_STRING, &monitor->linklosslevel);
 
 	dbus_message_iter_close_container(&iter, &dict);
 
-- 
1.7.6


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

* Re: [PATCH BlueZ 1/6] Proximity Monitor: Write Alert Level to Reporter
  2011-07-27 21:53 ` [PATCH BlueZ 1/6] Proximity Monitor: Write Alert Level to Reporter Claudio Takahasi
@ 2011-07-28  4:40   ` Santiago Carot
       [not found]   ` <CACLukz+g-994zKLK1aPkBusEhv=ti850KhMSjGZQjJOdL9kdcw@mail.gmail.com>
  1 sibling, 0 replies; 18+ messages in thread
From: Santiago Carot @ 2011-07-28  4:40 UTC (permalink / raw)
  To: Claudio Takahasi; +Cc: linux-bluetooth, Anderson Lizardo

Hello Claudio,

Some comments below.

2011/7/27 Claudio Takahasi <claudio.takahasi@openbossa.org>:
> From: Anderson Lizardo <anderson.lizardo@openbossa.org>
>
> When the Proximity Monitor connects to the Reporter, it shall write its
> current Alert Level (usually defined by the user) into the Alert Level
> characteristic on the Monitor. So once the link is lost, the Monitor
> will alert with the appropriate level.
>
> Note: Register connection callback to write alert level to the Reporter.
> ---
>  proximity/monitor.c |   92 +++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 files changed, 92 insertions(+), 0 deletions(-)
>
> diff --git a/proximity/monitor.c b/proximity/monitor.c
> index 8465f92..f7995aa 100644
> --- a/proximity/monitor.c
> +++ b/proximity/monitor.c
> @@ -35,19 +35,28 @@
>  #include <sys/stat.h>
>
>  #include <bluetooth/bluetooth.h>
> +#include <bluetooth/uuid.h>
>
>  #include "dbus-common.h"
>  #include "adapter.h"
>  #include "device.h"
>  #include "error.h"
>  #include "log.h"
> +#include "att.h"
> +#include "gattrib.h"
> +#include "gatt.h"
> +#include "attio.h"
>  #include "monitor.h"
>  #include "textfile.h"
>
>  #define PROXIMITY_INTERFACE "org.bluez.Proximity"
>
> +#define LINK_LOSS_UUID "00001803-0000-1000-8000-00805f9b34fb"
> +#define ALERT_LEVEL_CHR_UUID 0x2A06
> +
>  struct monitor {
>        struct btd_device *device;
> +       GAttrib *attrib;
>        char *linklosslevel;            /* Link Loss Alert Level */
>  };
>
> @@ -90,6 +99,86 @@ static char *read_proximity_config(bdaddr_t *sba, bdaddr_t *dba,
>        return textfile_caseget(filename, key);
>  }
>
> +static void char_discovered_cb(GSList *characteristics, guint8 status,
> +                                                       gpointer user_data)
> +{
> +       struct monitor *monitor = user_data;
> +       struct att_char *chr;
> +       uint8_t value;
> +
> +       if (status) {
> +               error("Discover Link Loss handle: %s", att_ecode2str(status));
> +               return;
> +       }
> +
> +       if (strcmp(monitor->linklosslevel, "none") == 0)
> +               value = 0x00;
> +       else if (strcmp(monitor->linklosslevel, "mild") == 0)
> +               value = 0x01;
> +       else if (strcmp(monitor->linklosslevel, "high") == 0)
> +               value = 0x02;
> +
> +       DBG("Setting alert level \"%s\" on Reporter", monitor->linklosslevel);
> +
> +       /* Assume there is a single Alert Level characteristic */
> +       chr = characteristics->data;
> +
> +       gatt_write_cmd(monitor->attrib, chr->value_handle, &value, 1, NULL, NULL);
> +}
> +
> +static int write_alert_level(struct monitor *monitor)
> +{
> +       GSList *l, *primaries;
> +       uint16_t start = 0, end = 0;
> +       bt_uuid_t uuid;
> +
> +       primaries = btd_device_get_primaries(monitor->device);
> +       if (primaries == NULL) {
> +               DBG("No primary services found");
> +               return -1;
> +       }
> +
> +       for (l = primaries; l; l = l->next) {
> +               struct att_primary *primary = l->data;
> +
> +               if (strcmp(primary->uuid, LINK_LOSS_UUID) == 0) {
> +                       start = primary->start;
> +                       end = primary->end;
> +                       break;
> +               }
> +       }
> +
> +       if (!start) {
> +               DBG("Link Loss service not found");
> +               return -1;
> +       }
> +
> +       DBG("Link Loss service found at range 0x%04x-0x%04x", start, end);
> +
> +       bt_uuid16_create(&uuid, ALERT_LEVEL_CHR_UUID);
> +
> +       /* FIXME: use cache (requires service changed support) ? */
> +       gatt_discover_char(monitor->attrib, start, end, &uuid, char_discovered_cb,
> +                                                               monitor);
> +
> +       return 0;
> +}
> +
> +static void attio_connected_cb(GAttrib *attrib, gpointer user_data)
> +{
> +       struct monitor *monitor = user_data;
> +
> +       monitor->attrib = attrib;

GAttrib is a referenciable structure. Don't you increment the
reference counter if you are storing an internal reference in
monitor?.

> +       write_alert_level(monitor);
> +}
> +
> +static void attio_disconnected_cb(gpointer user_data)
> +{
> +       struct monitor *monitor = user_data;
> +
> +       monitor->attrib = NULL;

unref above?

> +}
> +
>  static DBusMessage *set_link_loss_alert(DBusConnection *conn, DBusMessage *msg,
>                                                const char *level, void *data)
>  {
> @@ -229,6 +318,9 @@ int monitor_register(DBusConnection *conn, struct btd_device *device)
>
>        DBG("Registered interface %s on path %s", PROXIMITY_INTERFACE, path);
>
> +       btd_device_add_attio_callback(device, attio_connected_cb,
> +                                       attio_disconnected_cb, monitor);
> +

Could we use a GDestroyNotify function here to avoid possible memory
leaks or other memory related problems?.
We could call to GDestroyNotify when btd_device_remove_attio_callback.
The procedure look me similar to g_dbus_register_interface and
g_dbus_unregister_interface when destroy function is provided

>        return 0;
>  }
>
> --
> 1.7.6
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

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

* Re: [PATCH BlueZ 1/6] Proximity Monitor: Write Alert Level to Reporter
       [not found]   ` <CACLukz+g-994zKLK1aPkBusEhv=ti850KhMSjGZQjJOdL9kdcw@mail.gmail.com>
@ 2011-07-28 13:05     ` Claudio Takahasi
  2011-07-28 13:12       ` Johan Hedberg
  0 siblings, 1 reply; 18+ messages in thread
From: Claudio Takahasi @ 2011-07-28 13:05 UTC (permalink / raw)
  To: Santiago Carot; +Cc: BlueZ development

Hi Santiago.

Our initial plan was to implement a "queue" to send commands
supporting "offline" mode. The "queue" reference could be "informed"
to the profiles in the probe callback or a reference to it could be
obtained using a function similar to btd_device_add_attio_callback.
The problem is MTU, MTU is negotiated over ATT protocol, meaning that
we can not encode the commands and add it into the queue without a
huge change in our code.

The intermediate solution was to expose GAttrib and add the connection
callback registration to "request" connections.

On Thu, Jul 28, 2011 at 1:36 AM, Santiago Carot <sancane@gmail.com> wrote:
> Hello Claudio,
>
> Some questions below.
>
> 2011/7/27 Claudio Takahasi <claudio.takahasi@openbossa.org>:
>> From: Anderson Lizardo <anderson.lizardo@openbossa.org>
>>
>> When the Proximity Monitor connects to the Reporter, it shall write its
>> current Alert Level (usually defined by the user) into the Alert Level
>> characteristic on the Monitor. So once the link is lost, the Monitor
>> will alert with the appropriate level.
>>
>> Note: Register connection callback to write alert level to the Reporter.
>> ---
>>  proximity/monitor.c |   92 +++++++++++++++++++++++++++++++++++++++++++++++++++
>>  1 files changed, 92 insertions(+), 0 deletions(-)
>>
>> diff --git a/proximity/monitor.c b/proximity/monitor.c
>> index 8465f92..f7995aa 100644
>> --- a/proximity/monitor.c
>> +++ b/proximity/monitor.c
>> @@ -35,19 +35,28 @@
>>  #include <sys/stat.h>
<snip>
>> +static void attio_connected_cb(GAttrib *attrib, gpointer user_data)
>> +{
>> +       struct monitor *monitor = user_data;
>> +
>> +       monitor->attrib = attrib;
>
> GAttrib is a referenciable structure. Don't you increment the
> reference counter if you are storing an internal reference in monitor?

References are controlled by the core. The last reference for the
GAttrib will not be release by the core until the last connection
callback is unregistered. This is the reason why reference control
inside the profiles are not needed. If it is more clear to everybody
we can add reference counting in the profiles, but it will be a
duplicated logic. Every btd_device_remove_attio_callback call will be
followed by g_attrib_unref.

>
>> +       write_alert_level(monitor);
>> +}
>> +
>> +static void attio_disconnected_cb(gpointer user_data)
>> +{
>> +       struct monitor *monitor = user_data;
>> +
>> +       monitor->attrib = NULL;
>
> unref above?
>
>> +}
>> +
>>  static DBusMessage *set_link_loss_alert(DBusConnection *conn, DBusMessage *msg,
>>                                                const char *level, void *data)
>>  {
>> @@ -229,6 +318,9 @@ int monitor_register(DBusConnection *conn, struct btd_device *device)
>>
>>        DBG("Registered interface %s on path %s", PROXIMITY_INTERFACE, path);
>>
>> +       btd_device_add_attio_callback(device, attio_connected_cb,
>> +                                       attio_disconnected_cb, monitor);
>
> Could we use a GDestroyNotify function here to avoid possible memory
> leaks or other memory related problems?.
> We could call to GDestroyNotify when btd_device_remove_attio_callback.
> The procedure look me similar to g_dbus_register_interface and
> g_dbus_unregister_interface when destroy function is provided
>

we can add it if necessary. Feel free to send a patch for it.

Regards,
Claudio.

>> +
>>        return 0;
>>  }
>>
>> --
>> 1.7.6

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

* Re: [PATCH BlueZ 1/6] Proximity Monitor: Write Alert Level to Reporter
  2011-07-28 13:05     ` Claudio Takahasi
@ 2011-07-28 13:12       ` Johan Hedberg
  2011-07-28 14:43         ` [PATCH BlueZ v2 " Claudio Takahasi
  0 siblings, 1 reply; 18+ messages in thread
From: Johan Hedberg @ 2011-07-28 13:12 UTC (permalink / raw)
  To: Claudio Takahasi; +Cc: Santiago Carot, BlueZ development

Hi Claudio,

On Thu, Jul 28, 2011, Claudio Takahasi wrote:
> On Thu, Jul 28, 2011 at 1:36 AM, Santiago Carot <sancane@gmail.com> wrote:
> >> --- a/proximity/monitor.c
> >> +++ b/proximity/monitor.c
> >> @@ -35,19 +35,28 @@
> >>  #include <sys/stat.h>
> <snip>
> >> +static void attio_connected_cb(GAttrib *attrib, gpointer user_data)
> >> +{
> >> +       struct monitor *monitor = user_data;
> >> +
> >> +       monitor->attrib = attrib;
> >
> > GAttrib is a referenciable structure. Don't you increment the
> > reference counter if you are storing an internal reference in monitor?
> 
> References are controlled by the core. The last reference for the
> GAttrib will not be release by the core until the last connection
> callback is unregistered. This is the reason why reference control
> inside the profiles are not needed. If it is more clear to everybody
> we can add reference counting in the profiles, but it will be a
> duplicated logic. Every btd_device_remove_attio_callback call will be
> followed by g_attrib_unref.

The general rule should be that you never copy a reference counted
pointer without the use of ref(). So in this case I do think it'd be
better to ref() when you copy (from attrib to monitor->attrib) and
unref() before you set to NULL.

Johan

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

* [PATCH BlueZ v2 0/6] Proximity configs and LinkLoss alert write
  2011-07-27 21:53 [PATCH BlueZ 0/6] Proximity configs and LinkLoss alert write Claudio Takahasi
                   ` (5 preceding siblings ...)
  2011-07-27 21:53 ` [PATCH BlueZ 6/6] Return LinkLossAlertLevel if enabled Claudio Takahasi
@ 2011-07-28 14:42 ` Claudio Takahasi
  2011-08-03  9:38   ` Johan Hedberg
  6 siblings, 1 reply; 18+ messages in thread
From: Claudio Takahasi @ 2011-07-28 14:42 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

Dependency: "[PATCH BlueZ 0/5] Add Get/Set Property for Link Loss"

Changes from the last series: ref counting inside Proximity Monitor based
on the feedbacks/comments in the ML.

The following patches implement the configuration file to allow
disabling Proximity Monitor services and Find Me. First patch using
attio connection callback registration mechanism to write Link Loss
Alert level.

Anderson Lizardo (1):
  Proximity Monitor: Write Alert Level to Reporter

Claudio Takahasi (5):
  Add Tx Power and Immediate Alert UUID
  Add config file for proximity monitor
  Match probed UUIDs and enabled services
  Return an error if LinkLoss is disabled
  Return LinkLossAlertLevel if enabled

 Makefile.am              |    4 +-
 proximity/main.c         |   30 ++++++++++++-
 proximity/manager.c      |   52 ++++++++++++++++++++--
 proximity/manager.h      |    2 +-
 proximity/monitor.c      |  109 ++++++++++++++++++++++++++++++++++++++++++++-
 proximity/monitor.h      |    9 +++-
 proximity/proximity.conf |    9 ++++
 7 files changed, 202 insertions(+), 13 deletions(-)
 create mode 100644 proximity/proximity.conf

-- 
1.7.6


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

* [PATCH BlueZ v2 1/6] Proximity Monitor: Write Alert Level to Reporter
  2011-07-28 13:12       ` Johan Hedberg
@ 2011-07-28 14:43         ` Claudio Takahasi
  0 siblings, 0 replies; 18+ messages in thread
From: Claudio Takahasi @ 2011-07-28 14:43 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Anderson Lizardo

From: Anderson Lizardo <anderson.lizardo@openbossa.org>

When the Proximity Monitor connects to the Reporter, it shall write its
current Alert Level (usually defined by the user) into the Alert Level
characteristic on the Monitor. So once the link is lost, the Monitor
will alert with the appropriate level.

Note: Register connection callback to write alert level to the Reporter.
---
 proximity/monitor.c |   93 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 93 insertions(+), 0 deletions(-)

diff --git a/proximity/monitor.c b/proximity/monitor.c
index 8465f92..c16385a 100644
--- a/proximity/monitor.c
+++ b/proximity/monitor.c
@@ -35,19 +35,28 @@
 #include <sys/stat.h>
 
 #include <bluetooth/bluetooth.h>
+#include <bluetooth/uuid.h>
 
 #include "dbus-common.h"
 #include "adapter.h"
 #include "device.h"
 #include "error.h"
 #include "log.h"
+#include "att.h"
+#include "gattrib.h"
+#include "gatt.h"
+#include "attio.h"
 #include "monitor.h"
 #include "textfile.h"
 
 #define PROXIMITY_INTERFACE "org.bluez.Proximity"
 
+#define LINK_LOSS_UUID "00001803-0000-1000-8000-00805f9b34fb"
+#define ALERT_LEVEL_CHR_UUID 0x2A06
+
 struct monitor {
 	struct btd_device *device;
+	GAttrib *attrib;
 	char *linklosslevel;		/* Link Loss Alert Level */
 };
 
@@ -90,6 +99,87 @@ static char *read_proximity_config(bdaddr_t *sba, bdaddr_t *dba,
 	return textfile_caseget(filename, key);
 }
 
+static void char_discovered_cb(GSList *characteristics, guint8 status,
+							gpointer user_data)
+{
+	struct monitor *monitor = user_data;
+	struct att_char *chr;
+	uint8_t value;
+
+	if (status) {
+		error("Discover Link Loss handle: %s", att_ecode2str(status));
+		return;
+	}
+
+	if (strcmp(monitor->linklosslevel, "none") == 0)
+		value = 0x00;
+	else if (strcmp(monitor->linklosslevel, "mild") == 0)
+		value = 0x01;
+	else if (strcmp(monitor->linklosslevel, "high") == 0)
+		value = 0x02;
+
+	DBG("Setting alert level \"%s\" on Reporter", monitor->linklosslevel);
+
+	/* Assume there is a single Alert Level characteristic */
+	chr = characteristics->data;
+
+	gatt_write_cmd(monitor->attrib, chr->value_handle, &value, 1, NULL, NULL);
+}
+
+static int write_alert_level(struct monitor *monitor)
+{
+	GSList *l, *primaries;
+	uint16_t start = 0, end = 0;
+	bt_uuid_t uuid;
+
+	primaries = btd_device_get_primaries(monitor->device);
+	if (primaries == NULL) {
+		DBG("No primary services found");
+		return -1;
+	}
+
+	for (l = primaries; l; l = l->next) {
+		struct att_primary *primary = l->data;
+
+		if (strcmp(primary->uuid, LINK_LOSS_UUID) == 0) {
+			start = primary->start;
+			end = primary->end;
+			break;
+		}
+	}
+
+	if (!start) {
+		DBG("Link Loss service not found");
+		return -1;
+	}
+
+	DBG("Link Loss service found at range 0x%04x-0x%04x", start, end);
+
+	bt_uuid16_create(&uuid, ALERT_LEVEL_CHR_UUID);
+
+	/* FIXME: use cache (requires service changed support) ? */
+	gatt_discover_char(monitor->attrib, start, end, &uuid, char_discovered_cb,
+								monitor);
+
+	return 0;
+}
+
+static void attio_connected_cb(GAttrib *attrib, gpointer user_data)
+{
+	struct monitor *monitor = user_data;
+
+	monitor->attrib = g_attrib_ref(attrib);
+	write_alert_level(monitor);
+}
+
+static void attio_disconnected_cb(gpointer user_data)
+{
+	struct monitor *monitor = user_data;
+
+	g_attrib_unref(monitor->attrib);
+	monitor->attrib = NULL;
+}
+
 static DBusMessage *set_link_loss_alert(DBusConnection *conn, DBusMessage *msg,
 						const char *level, void *data)
 {
@@ -229,6 +319,9 @@ int monitor_register(DBusConnection *conn, struct btd_device *device)
 
 	DBG("Registered interface %s on path %s", PROXIMITY_INTERFACE, path);
 
+	btd_device_add_attio_callback(device, attio_connected_cb,
+					attio_disconnected_cb, monitor);
+
 	return 0;
 }
 
-- 
1.7.6


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

* [PATCH BlueZ v2 2/6] Add Tx Power and Immediate Alert UUID
  2011-07-27 21:53 ` [PATCH BlueZ 2/6] Add Tx Power and Immediate Alert UUID Claudio Takahasi
@ 2011-07-28 14:43   ` Claudio Takahasi
  0 siblings, 0 replies; 18+ messages in thread
From: Claudio Takahasi @ 2011-07-28 14:43 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

Changes Proximity Monitor driver declaration adding the Tx Power and
Immediate Alert UUIDs. UUIDs are required to support Path Loss and
Find ME.
---
 proximity/manager.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/proximity/manager.c b/proximity/manager.c
index 8d0aee1..98ac59f 100644
--- a/proximity/manager.c
+++ b/proximity/manager.c
@@ -35,7 +35,9 @@
 #include "reporter.h"
 #include "manager.h"
 
-#define LINK_LOSS_UUID "00001803-0000-1000-8000-00805f9b34fb"
+#define IMMEDIATE_ALERT_UUID	"00001802-0000-1000-8000-00805f9b34fb"
+#define LINK_LOSS_UUID		"00001803-0000-1000-8000-00805f9b34fb"
+#define TX_POWER_UUID		"00001804-0000-1000-8000-00805f9b34fb"
 
 static DBusConnection *connection = NULL;
 
@@ -51,7 +53,7 @@ static void attio_device_remove(struct btd_device *device)
 
 static struct btd_device_driver monitor_driver = {
 	.name = "Proximity GATT Driver",
-	.uuids = BTD_UUIDS(LINK_LOSS_UUID),
+	.uuids = BTD_UUIDS(IMMEDIATE_ALERT_UUID, LINK_LOSS_UUID, TX_POWER_UUID),
 	.probe = attio_device_probe,
 	.remove = attio_device_remove,
 };
-- 
1.7.6


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

* [PATCH BlueZ v2 3/6] Add config file for proximity monitor
  2011-07-27 21:53 ` [PATCH BlueZ 3/6] Add config file for proximity monitor Claudio Takahasi
@ 2011-07-28 14:43   ` Claudio Takahasi
  0 siblings, 0 replies; 18+ messages in thread
From: Claudio Takahasi @ 2011-07-28 14:43 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

Initial config file to disable Proximity and Find ME support in the
proximity monitor side. By default all services will be supported.
Config file is necessary at least to disable Find ME profile since the
Immediate Alert service is shared between Pass Loss and Find ME.
---
 Makefile.am              |    4 ++--
 proximity/main.c         |   30 +++++++++++++++++++++++++++++-
 proximity/manager.c      |   34 ++++++++++++++++++++++++++++++++--
 proximity/manager.h      |    2 +-
 proximity/proximity.conf |    9 +++++++++
 5 files changed, 73 insertions(+), 6 deletions(-)
 create mode 100644 proximity/proximity.conf

diff --git a/Makefile.am b/Makefile.am
index 91232d9..24b75e7 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -297,8 +297,8 @@ EXTRA_DIST += src/genbuiltin src/bluetooth.conf \
 			input/input.conf serial/serial.conf \
 			audio/audio.conf audio/telephony-dummy.c \
 			audio/telephony-maemo5.c audio/telephony-ofono.c \
-			audio/telephony-maemo6.c sap/sap-dummy.c sap/sap-u8500.c
-
+			audio/telephony-maemo6.c sap/sap-dummy.c sap/sap-u8500.c \
+			proximity/proximity.conf
 
 if ALSA
 alsadir = $(libdir)/alsa-lib
diff --git a/proximity/main.c b/proximity/main.c
index ee7e4fb..5f0fc12 100644
--- a/proximity/main.c
+++ b/proximity/main.c
@@ -28,20 +28,45 @@
 
 #include <errno.h>
 
+#include <glib.h>
 #include <gdbus.h>
 
+#include "log.h"
 #include "plugin.h"
 #include "manager.h"
 
 static DBusConnection *connection = NULL;
+static GKeyFile *config = NULL;
+
+static GKeyFile *open_config_file(const char *file)
+{
+	GError *gerr = NULL;
+	GKeyFile *keyfile;
+
+	keyfile = g_key_file_new();
+
+	g_key_file_set_list_separator(keyfile, ',');
+
+	if (!g_key_file_load_from_file(keyfile, file, 0, &gerr)) {
+		error("Parsing %s failed: %s", file, gerr->message);
+		g_error_free(gerr);
+		g_key_file_free(keyfile);
+		return NULL;
+	}
+
+	return keyfile;
+}
 
 static int proximity_init(void)
 {
+
 	connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
 	if (connection == NULL)
 		return -EIO;
 
-	if (proximity_manager_init(connection) < 0) {
+	config = open_config_file(CONFIGDIR "/proximity.conf");
+
+	if (proximity_manager_init(connection, config) < 0) {
 		dbus_connection_unref(connection);
 		return -EIO;
 	}
@@ -51,6 +76,9 @@ static int proximity_init(void)
 
 static void proximity_exit(void)
 {
+	if (config)
+		g_key_file_free(config);
+
 	proximity_manager_exit();
 	dbus_connection_unref(connection);
 }
diff --git a/proximity/manager.c b/proximity/manager.c
index 98ac59f..e3e049d 100644
--- a/proximity/manager.c
+++ b/proximity/manager.c
@@ -41,6 +41,16 @@
 
 static DBusConnection *connection = NULL;
 
+static struct {
+	gboolean linkloss;
+	gboolean pathloss;
+	gboolean findme;
+} enabled  = {
+	.linkloss = TRUE,
+	.pathloss = TRUE,
+	.findme = TRUE,
+};
+
 static int attio_device_probe(struct btd_device *device, GSList *uuids)
 {
 	return monitor_register(connection, device);
@@ -58,10 +68,30 @@ static struct btd_device_driver monitor_driver = {
 	.remove = attio_device_remove,
 };
 
-int proximity_manager_init(DBusConnection *conn)
+static void load_config_file(GKeyFile *config)
+{
+	char **list;
+	int i;
+
+	list = g_key_file_get_string_list(config, "General", "Disable",
+								NULL, NULL);
+	for (i = 0; list && list[i] != NULL; i++) {
+		if (g_str_equal(list[i], "FindMe"))
+			enabled.findme = FALSE;
+		else if (g_str_equal(list[i], "LinkLoss"))
+			enabled.linkloss = FALSE;
+		else if (g_str_equal(list[i], "PathLoss"))
+			enabled.pathloss = FALSE;
+	}
+
+	g_strfreev(list);
+}
+
+int proximity_manager_init(DBusConnection *conn, GKeyFile *config)
 {
 	int ret;
-	/* TODO: Add Proximity Monitor/Reporter config */
+
+	load_config_file(config);
 
 	/* TODO: Register Proximity Monitor/Reporter drivers */
 	ret = btd_register_device_driver(&monitor_driver);
diff --git a/proximity/manager.h b/proximity/manager.h
index 7557a68..b0fe7c8 100644
--- a/proximity/manager.h
+++ b/proximity/manager.h
@@ -22,5 +22,5 @@
  *
  */
 
-int proximity_manager_init(DBusConnection *conn);
+int proximity_manager_init(DBusConnection *conn, GKeyFile *conf);
 void proximity_manager_exit(void);
diff --git a/proximity/proximity.conf b/proximity/proximity.conf
new file mode 100644
index 0000000..f4ef6f5
--- /dev/null
+++ b/proximity/proximity.conf
@@ -0,0 +1,9 @@
+# Configuration file for the proximity service
+
+# This section contains options which are not specific to any
+# particular interface
+[General]
+
+# If we want to disable support for specific services
+# Defaults to supporting all implemented services
+#Disable=LinkLoss,PathLoss,FindMe
-- 
1.7.6


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

* [PATCH BlueZ v2 4/6] Match probed UUIDs and enabled services
  2011-07-27 21:53 ` [PATCH BlueZ 4/6] Match probed UUIDs and enabled services Claudio Takahasi
@ 2011-07-28 14:43   ` Claudio Takahasi
  0 siblings, 0 replies; 18+ messages in thread
From: Claudio Takahasi @ 2011-07-28 14:43 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

Verify if the service is enabled in the proximity configuration file
before to register the Proximity Monitor.
---
 proximity/manager.c |   22 ++++++++++++++++------
 proximity/monitor.c |    7 ++++++-
 proximity/monitor.h |    9 ++++++++-
 3 files changed, 30 insertions(+), 8 deletions(-)

diff --git a/proximity/manager.c b/proximity/manager.c
index e3e049d..a9526a1 100644
--- a/proximity/manager.c
+++ b/proximity/manager.c
@@ -41,11 +41,7 @@
 
 static DBusConnection *connection = NULL;
 
-static struct {
-	gboolean linkloss;
-	gboolean pathloss;
-	gboolean findme;
-} enabled  = {
+static struct enabled enabled  = {
 	.linkloss = TRUE,
 	.pathloss = TRUE,
 	.findme = TRUE,
@@ -53,7 +49,21 @@ static struct {
 
 static int attio_device_probe(struct btd_device *device, GSList *uuids)
 {
-	return monitor_register(connection, device);
+	gboolean linkloss = FALSE, pathloss = FALSE, findme = FALSE;
+
+	if (g_slist_find_custom(uuids, IMMEDIATE_ALERT_UUID,
+					(GCompareFunc) strcasecmp)) {
+		findme = enabled.findme;
+		if (g_slist_find_custom(uuids, TX_POWER_UUID,
+					(GCompareFunc) strcasecmp))
+			pathloss = enabled.pathloss;
+	}
+
+	if (g_slist_find_custom(uuids, LINK_LOSS_UUID,
+				(GCompareFunc) strcasecmp))
+		linkloss = enabled.linkloss;
+
+	return monitor_register(connection, device, linkloss, pathloss, findme);
 }
 
 static void attio_device_remove(struct btd_device *device)
diff --git a/proximity/monitor.c b/proximity/monitor.c
index c16385a..31691ff 100644
--- a/proximity/monitor.c
+++ b/proximity/monitor.c
@@ -57,6 +57,7 @@
 struct monitor {
 	struct btd_device *device;
 	GAttrib *attrib;
+	struct enabled enabled;
 	char *linklosslevel;		/* Link Loss Alert Level */
 };
 
@@ -291,7 +292,8 @@ static void monitor_destroy(gpointer user_data)
 	g_free(monitor);
 }
 
-int monitor_register(DBusConnection *conn, struct btd_device *device)
+int monitor_register(DBusConnection *conn, struct btd_device *device,
+			gboolean linkloss, gboolean pathloss, gboolean findme)
 {
 	const char *path = device_get_path(device);
 	struct monitor *monitor;
@@ -306,6 +308,9 @@ int monitor_register(DBusConnection *conn, struct btd_device *device)
 	monitor = g_new0(struct monitor, 1);
 	monitor->device = btd_device_ref(device);
 	monitor->linklosslevel = (level ? : g_strdup("none"));
+	monitor->enabled.linkloss = linkloss;
+	monitor->enabled.pathloss = pathloss;
+	monitor->enabled.findme = findme;
 
 	if (g_dbus_register_interface(conn, path,
 				PROXIMITY_INTERFACE,
diff --git a/proximity/monitor.h b/proximity/monitor.h
index 5c6ebf6..ef47ee1 100644
--- a/proximity/monitor.h
+++ b/proximity/monitor.h
@@ -22,5 +22,12 @@
  *
  */
 
-int monitor_register(DBusConnection *conn, struct btd_device *device);
+struct enabled {
+	gboolean linkloss;
+	gboolean pathloss;
+	gboolean findme;
+};
+
+int monitor_register(DBusConnection *conn, struct btd_device *device,
+			gboolean linkloss, gboolean pathloss, gboolean findme);
 void monitor_unregister(DBusConnection *conn, struct btd_device *device);
-- 
1.7.6


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

* [PATCH BlueZ v2 5/6] Return an error if LinkLoss is disabled
  2011-07-27 21:53 ` [PATCH BlueZ 5/6] Return an error if LinkLoss is disabled Claudio Takahasi
@ 2011-07-28 14:43   ` Claudio Takahasi
  0 siblings, 0 replies; 18+ messages in thread
From: Claudio Takahasi @ 2011-07-28 14:43 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

Changes SetProperty method of the Proximity Monitor to verify if the
LinkLoss service is enabled before allowing to change the alert level.
Not available error is returned if LinkLoss service is disabled in the
Proximity configuration file.
---
 proximity/monitor.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/proximity/monitor.c b/proximity/monitor.c
index 31691ff..dc480ab 100644
--- a/proximity/monitor.c
+++ b/proximity/monitor.c
@@ -241,6 +241,7 @@ static DBusMessage *get_properties(DBusConnection *conn,
 static DBusMessage *set_property(DBusConnection *conn,
 					DBusMessage *msg, void *data)
 {
+	struct monitor *monitor = data;
 	const char *property;
 	DBusMessageIter iter;
 	DBusMessageIter sub;
@@ -260,6 +261,9 @@ static DBusMessage *set_property(DBusConnection *conn,
 	dbus_message_iter_recurse(&iter, &sub);
 
 	if (g_str_equal("LinkLossAlertLevel", property)) {
+		if (monitor->enabled.linkloss == FALSE)
+			return btd_error_not_available(msg);
+
 		if (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_STRING)
 			return btd_error_invalid_args(msg);
 
-- 
1.7.6


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

* [PATCH BlueZ v2 6/6] Return LinkLossAlertLevel if enabled
  2011-07-27 21:53 ` [PATCH BlueZ 6/6] Return LinkLossAlertLevel if enabled Claudio Takahasi
@ 2011-07-28 14:43   ` Claudio Takahasi
  0 siblings, 0 replies; 18+ messages in thread
From: Claudio Takahasi @ 2011-07-28 14:43 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

GetProperties method of Proximity Monitor should not append the
LinkLossAlertLevel property if the LinkLoss service is not enabled
in the configuration file.
---
 proximity/monitor.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/proximity/monitor.c b/proximity/monitor.c
index dc480ab..d068142 100644
--- a/proximity/monitor.c
+++ b/proximity/monitor.c
@@ -230,8 +230,9 @@ static DBusMessage *get_properties(DBusConnection *conn,
 			DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
 			DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict);
 
-	dict_append_entry(&dict, "LinkLossAlertLevel",
-			DBUS_TYPE_STRING, &monitor->linklosslevel);
+	if (monitor->enabled.linkloss)
+		dict_append_entry(&dict, "LinkLossAlertLevel",
+				DBUS_TYPE_STRING, &monitor->linklosslevel);
 
 	dbus_message_iter_close_container(&iter, &dict);
 
-- 
1.7.6


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

* Re: [PATCH BlueZ v2 0/6] Proximity configs and LinkLoss alert write
  2011-07-28 14:42 ` [PATCH BlueZ v2 0/6] Proximity configs and LinkLoss alert write Claudio Takahasi
@ 2011-08-03  9:38   ` Johan Hedberg
  0 siblings, 0 replies; 18+ messages in thread
From: Johan Hedberg @ 2011-08-03  9:38 UTC (permalink / raw)
  To: Claudio Takahasi; +Cc: linux-bluetooth

Hi,

On Thu, Jul 28, 2011, Claudio Takahasi wrote:
> Dependency: "[PATCH BlueZ 0/5] Add Get/Set Property for Link Loss"
> 
> Changes from the last series: ref counting inside Proximity Monitor based
> on the feedbacks/comments in the ML.
> 
> The following patches implement the configuration file to allow
> disabling Proximity Monitor services and Find Me. First patch using
> attio connection callback registration mechanism to write Link Loss
> Alert level.
> 
> Anderson Lizardo (1):
>   Proximity Monitor: Write Alert Level to Reporter
> 
> Claudio Takahasi (5):
>   Add Tx Power and Immediate Alert UUID
>   Add config file for proximity monitor
>   Match probed UUIDs and enabled services
>   Return an error if LinkLoss is disabled
>   Return LinkLossAlertLevel if enabled
> 
>  Makefile.am              |    4 +-
>  proximity/main.c         |   30 ++++++++++++-
>  proximity/manager.c      |   52 ++++++++++++++++++++--
>  proximity/manager.h      |    2 +-
>  proximity/monitor.c      |  109 ++++++++++++++++++++++++++++++++++++++++++++-
>  proximity/monitor.h      |    9 +++-
>  proximity/proximity.conf |    9 ++++
>  7 files changed, 202 insertions(+), 13 deletions(-)
>  create mode 100644 proximity/proximity.conf

This patch-set has also been applied. Thanks.

Johan

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

end of thread, other threads:[~2011-08-03  9:38 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-07-27 21:53 [PATCH BlueZ 0/6] Proximity configs and LinkLoss alert write Claudio Takahasi
2011-07-27 21:53 ` [PATCH BlueZ 1/6] Proximity Monitor: Write Alert Level to Reporter Claudio Takahasi
2011-07-28  4:40   ` Santiago Carot
     [not found]   ` <CACLukz+g-994zKLK1aPkBusEhv=ti850KhMSjGZQjJOdL9kdcw@mail.gmail.com>
2011-07-28 13:05     ` Claudio Takahasi
2011-07-28 13:12       ` Johan Hedberg
2011-07-28 14:43         ` [PATCH BlueZ v2 " Claudio Takahasi
2011-07-27 21:53 ` [PATCH BlueZ 2/6] Add Tx Power and Immediate Alert UUID Claudio Takahasi
2011-07-28 14:43   ` [PATCH BlueZ v2 " Claudio Takahasi
2011-07-27 21:53 ` [PATCH BlueZ 3/6] Add config file for proximity monitor Claudio Takahasi
2011-07-28 14:43   ` [PATCH BlueZ v2 " Claudio Takahasi
2011-07-27 21:53 ` [PATCH BlueZ 4/6] Match probed UUIDs and enabled services Claudio Takahasi
2011-07-28 14:43   ` [PATCH BlueZ v2 " Claudio Takahasi
2011-07-27 21:53 ` [PATCH BlueZ 5/6] Return an error if LinkLoss is disabled Claudio Takahasi
2011-07-28 14:43   ` [PATCH BlueZ v2 " Claudio Takahasi
2011-07-27 21:53 ` [PATCH BlueZ 6/6] Return LinkLossAlertLevel if enabled Claudio Takahasi
2011-07-28 14:43   ` [PATCH BlueZ v2 " Claudio Takahasi
2011-07-28 14:42 ` [PATCH BlueZ v2 0/6] Proximity configs and LinkLoss alert write Claudio Takahasi
2011-08-03  9:38   ` Johan Hedberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).