Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH BlueZ 3/4] hog: Refactor hog init and exit functions
From: Andre Guedes @ 2012-12-18 14:41 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1355841681-2589-1-git-send-email-andre.guedes@openbossa.org>

This patch simply renames hog_manager_init and hog_manager_exit
functions to hog_init and hog_exit.
---
 profiles/input/hog_device.c | 14 ++------------
 1 file changed, 2 insertions(+), 12 deletions(-)

diff --git a/profiles/input/hog_device.c b/profiles/input/hog_device.c
index 7efabf2..47f0e43 100644
--- a/profiles/input/hog_device.c
+++ b/profiles/input/hog_device.c
@@ -873,7 +873,7 @@ static struct btd_profile hog_profile = {
 	.device_remove	= hog_device_remove,
 };
 
-static int hog_manager_init(void)
+static int hog_init(void)
 {
 	int err;
 
@@ -886,7 +886,7 @@ static int hog_manager_init(void)
 	return btd_profile_register(&hog_profile);
 }
 
-static void hog_manager_exit(void)
+static void hog_exit(void)
 {
 	if (suspend_supported)
 		suspend_exit();
@@ -894,15 +894,5 @@ static void hog_manager_exit(void)
 	btd_profile_unregister(&hog_profile);
 }
 
-static int hog_init(void)
-{
-	return hog_manager_init();
-}
-
-static void hog_exit(void)
-{
-	hog_manager_exit();
-}
-
 BLUETOOTH_PLUGIN_DEFINE(hog, VERSION, BLUETOOTH_PLUGIN_PRIORITY_DEFAULT,
 							hog_init, hog_exit)
-- 
1.8.0.1


^ permalink raw reply related

* [PATCH BlueZ 2/4] hog: Merge hog_device.h code into hog_device.c
From: Andre Guedes @ 2012-12-18 14:41 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1355841681-2589-1-git-send-email-andre.guedes@openbossa.org>

This patch merges hog_device.h code into hog_device.c and removes
hog_device.h file. As long as hog_manager.c was merged into hog_
device.c, there is no need to have a header for hog_device.

This patch also adds the static modifier to functions which are
now used only in hog_device.c.
---
 Makefile.plugins            |  5 ++---
 profiles/input/hog_device.c |  8 ++++----
 profiles/input/hog_device.h | 33 ---------------------------------
 3 files changed, 6 insertions(+), 40 deletions(-)
 delete mode 100644 profiles/input/hog_device.h

diff --git a/Makefile.plugins b/Makefile.plugins
index 781218c..41b6876 100644
--- a/Makefile.plugins
+++ b/Makefile.plugins
@@ -59,9 +59,8 @@ builtin_sources += profiles/input/manager.h profiles/input/manager.c \
 			profiles/input/device.h profiles/input/device.c
 
 builtin_modules += hog
-builtin_sources += profiles/input/hog_device.h profiles/input/hog_device.c \
-			profiles/input/uhid_copy.h profiles/input/suspend.h \
-			profiles/input/suspend-dummy.c
+builtin_sources += profiles/input/hog_device.c profiles/input/uhid_copy.h \
+			profiles/input/suspend.h profiles/input/suspend-dummy.c
 
 builtin_modules += health
 builtin_sources += profiles/health/mcap_lib.h profiles/health/mcap_internal.h \
diff --git a/profiles/input/hog_device.c b/profiles/input/hog_device.c
index 310eb53..7efabf2 100644
--- a/profiles/input/hog_device.c
+++ b/profiles/input/hog_device.c
@@ -54,7 +54,7 @@
 #include "attio.h"
 #include "attrib/gatt.h"
 
-#include "hog_device.h"
+#define HOG_UUID		"00001812-0000-1000-8000-00805f9b34fb"
 
 #define HOG_INFO_UUID		0x2A4A
 #define HOG_REPORT_MAP_UUID	0x2A4B
@@ -716,7 +716,7 @@ static void hog_device_free(struct hog_device *hogdev)
 	g_free(hogdev);
 }
 
-struct hog_device *hog_device_register(struct btd_device *device,
+static struct hog_device *hog_device_register(struct btd_device *device,
 						struct gatt_primary *prim)
 {
 	struct hog_device *hogdev;
@@ -753,7 +753,7 @@ struct hog_device *hog_device_register(struct btd_device *device,
 	return hogdev;
 }
 
-int hog_device_unregister(struct hog_device *hogdev)
+static int hog_device_unregister(struct hog_device *hogdev)
 {
 	struct uhid_event ev;
 
@@ -777,7 +777,7 @@ int hog_device_unregister(struct hog_device *hogdev)
 	return 0;
 }
 
-int hog_device_set_control_point(struct hog_device *hogdev, gboolean suspend)
+static int hog_device_set_control_point(struct hog_device *hogdev, gboolean suspend)
 {
 	uint8_t value = suspend ? 0x00 : 0x01;
 
diff --git a/profiles/input/hog_device.h b/profiles/input/hog_device.h
deleted file mode 100644
index d1bfc08..0000000
--- a/profiles/input/hog_device.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- *
- *  BlueZ - Bluetooth protocol stack for Linux
- *
- *  Copyright (C) 2012  Marcel Holtmann <marcel@holtmann.org>
- *  Copyright (C) 2012  Nordic Semiconductor Inc.
- *  Copyright (C) 2012  Instituto Nokia de Tecnologia - INdT
- *
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- *
- */
-
-#define HOG_UUID		"00001812-0000-1000-8000-00805f9b34fb"
-
-struct hog_device;
-
-struct hog_device *hog_device_register(struct btd_device *device,
-						struct gatt_primary *prim);
-int hog_device_unregister(struct hog_device *hogdev);
-int hog_device_set_control_point(struct hog_device *hogdev, gboolean suspend);
-- 
1.8.0.1


^ permalink raw reply related

* [PATCH BlueZ 1/4] hog: Merge hog_manager.c code into hog_device.c
From: Andre Guedes @ 2012-12-18 14:41 UTC (permalink / raw)
  To: linux-bluetooth

This patch merges hog_manager.c code into hog_device.c and removes
hog_manager.c file. hog_manager.c is a very small file, so there is
no need to keep it separated.
---
 Makefile.plugins             |   6 +-
 profiles/input/hog_device.c  | 117 +++++++++++++++++++++++++++++++
 profiles/input/hog_manager.c | 161 -------------------------------------------
 3 files changed, 120 insertions(+), 164 deletions(-)
 delete mode 100644 profiles/input/hog_manager.c

diff --git a/Makefile.plugins b/Makefile.plugins
index a8f1231..781218c 100644
--- a/Makefile.plugins
+++ b/Makefile.plugins
@@ -59,9 +59,9 @@ builtin_sources += profiles/input/manager.h profiles/input/manager.c \
 			profiles/input/device.h profiles/input/device.c
 
 builtin_modules += hog
-builtin_sources += profiles/input/hog_manager.c profiles/input/hog_device.h \
-			profiles/input/hog_device.c profiles/input/uhid_copy.h \
-			profiles/input/suspend.h profiles/input/suspend-dummy.c
+builtin_sources += profiles/input/hog_device.h profiles/input/hog_device.c \
+			profiles/input/uhid_copy.h profiles/input/suspend.h \
+			profiles/input/suspend-dummy.c
 
 builtin_modules += health
 builtin_sources += profiles/health/mcap_lib.h profiles/health/mcap_internal.h \
diff --git a/profiles/input/hog_device.c b/profiles/input/hog_device.c
index 06dab6d..310eb53 100644
--- a/profiles/input/hog_device.c
+++ b/profiles/input/hog_device.c
@@ -45,7 +45,10 @@
 
 #include "src/adapter.h"
 #include "src/device.h"
+#include "src/profile.h"
 
+#include "plugin.h"
+#include "suspend.h"
 #include "attrib/att.h"
 #include "attrib/gattrib.h"
 #include "attio.h"
@@ -101,6 +104,9 @@ struct disc_desc_cb_data {
 	gpointer data;
 };
 
+static gboolean suspend_supported = FALSE;
+static GSList *devices = NULL;
+
 static void report_value_cb(const uint8_t *pdu, uint16_t len,
 							gpointer user_data)
 {
@@ -789,3 +795,114 @@ int hog_device_set_control_point(struct hog_device *hogdev, gboolean suspend)
 
 	return 0;
 }
+
+static void set_suspend(gpointer data, gpointer user_data)
+{
+	struct hog_device *hogdev = data;
+	gboolean suspend = GPOINTER_TO_INT(user_data);
+
+	hog_device_set_control_point(hogdev, suspend);
+}
+
+static void suspend_callback(void)
+{
+	gboolean suspend = TRUE;
+
+	DBG("Suspending ...");
+
+	g_slist_foreach(devices, set_suspend, GINT_TO_POINTER(suspend));
+}
+
+static void resume_callback(void)
+{
+	gboolean suspend = FALSE;
+
+	DBG("Resuming ...");
+
+	g_slist_foreach(devices, set_suspend, GINT_TO_POINTER(suspend));
+}
+
+static int hog_device_probe(struct btd_profile *p, struct btd_device *device,
+								GSList *uuids)
+{
+	const char *path = device_get_path(device);
+	GSList *primaries, *l;
+
+	DBG("path %s", path);
+
+	primaries = btd_device_get_primaries(device);
+	if (primaries == NULL)
+		return -EINVAL;
+
+	for (l = primaries; l; l = g_slist_next(l)) {
+		struct gatt_primary *prim = l->data;
+		struct hog_device *hogdev;
+
+		if (strcmp(prim->uuid, HOG_UUID) != 0)
+			continue;
+
+		hogdev = hog_device_register(device, prim);
+		if (hogdev == NULL)
+			continue;
+
+		devices = g_slist_append(devices, hogdev);
+	}
+
+	return 0;
+}
+
+static void remove_device(gpointer hogdev, gpointer b)
+{
+	devices = g_slist_remove(devices, hogdev);
+	hog_device_unregister(hogdev);
+}
+
+static void hog_device_remove(struct btd_profile *p, struct btd_device *device)
+{
+	const gchar *path = device_get_path(device);
+
+	DBG("path %s", path);
+
+	g_slist_foreach(devices, remove_device, NULL);
+}
+
+static struct btd_profile hog_profile = {
+	.name		= "input-hog",
+	.remote_uuids	= BTD_UUIDS(HOG_UUID),
+	.device_probe	= hog_device_probe,
+	.device_remove	= hog_device_remove,
+};
+
+static int hog_manager_init(void)
+{
+	int err;
+
+	err = suspend_init(suspend_callback, resume_callback);
+	if (err < 0)
+		DBG("Suspend: %s(%d)", strerror(-err), -err);
+	else
+		suspend_supported = TRUE;
+
+	return btd_profile_register(&hog_profile);
+}
+
+static void hog_manager_exit(void)
+{
+	if (suspend_supported)
+		suspend_exit();
+
+	btd_profile_unregister(&hog_profile);
+}
+
+static int hog_init(void)
+{
+	return hog_manager_init();
+}
+
+static void hog_exit(void)
+{
+	hog_manager_exit();
+}
+
+BLUETOOTH_PLUGIN_DEFINE(hog, VERSION, BLUETOOTH_PLUGIN_PRIORITY_DEFAULT,
+							hog_init, hog_exit)
diff --git a/profiles/input/hog_manager.c b/profiles/input/hog_manager.c
deleted file mode 100644
index 595b160..0000000
--- a/profiles/input/hog_manager.c
+++ /dev/null
@@ -1,161 +0,0 @@
-/*
- *
- *  BlueZ - Bluetooth protocol stack for Linux
- *
- *  Copyright (C) 2012  Nordic Semiconductor Inc.
- *  Copyright (C) 2012  Instituto Nokia de Tecnologia
- *
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- *
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <errno.h>
-#include <stdbool.h>
-
-#include <bluetooth/bluetooth.h>
-#include <bluetooth/uuid.h>
-
-#include "log.h"
-#include "src/adapter.h"
-#include "src/device.h"
-#include "src/profile.h"
-
-#include "plugin.h"
-#include "hcid.h"
-#include "device.h"
-#include "suspend.h"
-#include "attrib/att.h"
-#include "attrib/gattrib.h"
-#include "attrib/gatt.h"
-#include "hog_device.h"
-
-static gboolean suspend_supported = FALSE;
-static GSList *devices = NULL;
-
-static void set_suspend(gpointer data, gpointer user_data)
-{
-	struct hog_device *hogdev = data;
-	gboolean suspend = GPOINTER_TO_INT(user_data);
-
-	hog_device_set_control_point(hogdev, suspend);
-}
-
-static void suspend_callback(void)
-{
-	gboolean suspend = TRUE;
-
-	DBG("Suspending ...");
-
-	g_slist_foreach(devices, set_suspend, GINT_TO_POINTER(suspend));
-}
-
-static void resume_callback(void)
-{
-	gboolean suspend = FALSE;
-
-	DBG("Resuming ...");
-
-	g_slist_foreach(devices, set_suspend, GINT_TO_POINTER(suspend));
-}
-
-static int hog_device_probe(struct btd_profile *p, struct btd_device *device,
-								GSList *uuids)
-{
-	const char *path = device_get_path(device);
-	GSList *primaries, *l;
-
-	DBG("path %s", path);
-
-	primaries = btd_device_get_primaries(device);
-	if (primaries == NULL)
-		return -EINVAL;
-
-	for (l = primaries; l; l = g_slist_next(l)) {
-		struct gatt_primary *prim = l->data;
-		struct hog_device *hogdev;
-
-		if (strcmp(prim->uuid, HOG_UUID) != 0)
-			continue;
-
-		hogdev = hog_device_register(device, prim);
-		if (hogdev == NULL)
-			continue;
-
-		devices = g_slist_append(devices, hogdev);
-	}
-
-	return 0;
-}
-
-static void remove_device(gpointer hogdev, gpointer b)
-{
-	devices = g_slist_remove(devices, hogdev);
-	hog_device_unregister(hogdev);
-}
-
-static void hog_device_remove(struct btd_profile *p, struct btd_device *device)
-{
-	const gchar *path = device_get_path(device);
-
-	DBG("path %s", path);
-
-	g_slist_foreach(devices, remove_device, NULL);
-}
-
-static struct btd_profile hog_profile = {
-	.name		= "input-hog",
-	.remote_uuids	= BTD_UUIDS(HOG_UUID),
-	.device_probe	= hog_device_probe,
-	.device_remove	= hog_device_remove,
-};
-
-static int hog_manager_init(void)
-{
-	int err;
-
-	err = suspend_init(suspend_callback, resume_callback);
-	if (err < 0)
-		DBG("Suspend: %s(%d)", strerror(-err), -err);
-	else
-		suspend_supported = TRUE;
-
-	return btd_profile_register(&hog_profile);
-}
-
-static void hog_manager_exit(void)
-{
-	if (suspend_supported)
-		suspend_exit();
-
-	btd_profile_unregister(&hog_profile);
-}
-
-static int hog_init(void)
-{
-	return hog_manager_init();
-}
-
-static void hog_exit(void)
-{
-	hog_manager_exit();
-}
-
-BLUETOOTH_PLUGIN_DEFINE(hog, VERSION, BLUETOOTH_PLUGIN_PRIORITY_DEFAULT,
-							hog_init, hog_exit)
-- 
1.8.0.1


^ permalink raw reply related

* [RFC v0 5/5] gatt: List only GATT_UUID as remote UUID
From: Mikel Astiz @ 2012-12-18 14:01 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Mikel Astiz
In-Reply-To: <1355839287-8373-1-git-send-email-mikel.astiz.oss@gmail.com>

From: Mikel Astiz <mikel.astiz@bmw-carit.de>

The probe function checks if both UUIDs are present, so there is no
need to list both in btd_profile.
---
 profiles/gatt/manager.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/profiles/gatt/manager.c b/profiles/gatt/manager.c
index ce0ed91..e554007 100644
--- a/profiles/gatt/manager.c
+++ b/profiles/gatt/manager.c
@@ -59,7 +59,7 @@ static void gatt_driver_remove(struct btd_profile *p,
 
 static struct btd_profile gatt_profile = {
 	.name		= "gap-gatt-profile",
-	.remote_uuids	= BTD_UUIDS(GAP_UUID, GATT_UUID),
+	.remote_uuids	= BTD_UUIDS(GATT_UUID),
 	.device_probe	= gatt_driver_probe,
 	.device_remove	= gatt_driver_remove
 };
-- 
1.7.11.7


^ permalink raw reply related

* [RFC v0 4/5] proximity: Split monitor into three btd_profile
From: Mikel Astiz @ 2012-12-18 14:01 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Mikel Astiz
In-Reply-To: <1355839287-8373-1-git-send-email-mikel.astiz.oss@gmail.com>

From: Mikel Astiz <mikel.astiz@bmw-carit.de>

Split into three btd_profile such that each of them handles one single
UUID.
---
 profiles/proximity/manager.c | 102 +++++++++++++++++++++++++++++++------------
 1 file changed, 75 insertions(+), 27 deletions(-)

diff --git a/profiles/proximity/manager.c b/profiles/proximity/manager.c
index 75f71ad..59c4456 100644
--- a/profiles/proximity/manager.c
+++ b/profiles/proximity/manager.c
@@ -48,42 +48,79 @@ static struct enabled enabled  = {
 	.findme = TRUE,
 };
 
-static int monitor_device_probe(struct btd_profile *p,
+static int monitor_linkloss_probe(struct btd_profile *p,
 				struct btd_device *device, GSList *uuids)
 {
-	struct gatt_primary *linkloss, *txpower, *immediate;
-	int err = 0;
+	struct gatt_primary *linkloss;
 
-	immediate = btd_device_get_primary(device, IMMEDIATE_ALERT_UUID);
-	txpower = btd_device_get_primary(device, TX_POWER_UUID);
 	linkloss = btd_device_get_primary(device, LINK_LOSS_UUID);
+	if (linkloss == NULL)
+		return -1;
 
-	if (linkloss)
-		err = monitor_register_linkloss(device, &enabled, linkloss);
+	return monitor_register_linkloss(device, &enabled, linkloss);
+}
 
-	if (err >= 0 && txpower)
-		err = monitor_register_txpower(device, &enabled, txpower);
+static int monitor_immediate_probe(struct btd_profile *p,
+				struct btd_device *device, GSList *uuids)
+{
+	struct gatt_primary *immediate;
 
-	if (err >= 0 && immediate)
-		err = monitor_register_immediate(device, &enabled, immediate);
+	immediate = btd_device_get_primary(device, IMMEDIATE_ALERT_UUID);
+	if (immediate == NULL)
+		return -1;
 
-	return err;
+	return monitor_register_immediate(device, &enabled, immediate);
 }
 
-static void monitor_device_remove(struct btd_profile *p,
+static int monitor_txpower_probe(struct btd_profile *p,
+				struct btd_device *device, GSList *uuids)
+{
+	struct gatt_primary *txpower;
+
+	txpower = btd_device_get_primary(device, TX_POWER_UUID);
+	if (txpower == NULL)
+		return -1;
+
+	return monitor_register_txpower(device, &enabled, txpower);
+}
+
+static void monitor_linkloss_remove(struct btd_profile *p,
+						struct btd_device *device)
+{
+	monitor_unregister_linkloss(device);
+}
+
+static void monitor_immediate_remove(struct btd_profile *p,
 						struct btd_device *device)
 {
 	monitor_unregister_immediate(device);
+}
+
+static void monitor_txpower_remove(struct btd_profile *p,
+						struct btd_device *device)
+{
 	monitor_unregister_txpower(device);
-	monitor_unregister_linkloss(device);
 }
 
-static struct btd_profile pxp_monitor_profile = {
-	.name		= "Proximity Monitor GATT Driver",
-	.remote_uuids	= BTD_UUIDS(IMMEDIATE_ALERT_UUID,
-						LINK_LOSS_UUID, TX_POWER_UUID),
-	.device_probe	= monitor_device_probe,
-	.device_remove	= monitor_device_remove,
+static struct btd_profile pxp_monitor_linkloss_profile = {
+	.name		= "proximity-linkloss",
+	.remote_uuids	= BTD_UUIDS(LINK_LOSS_UUID),
+	.device_probe	= monitor_linkloss_probe,
+	.device_remove	= monitor_linkloss_remove,
+};
+
+static struct btd_profile pxp_monitor_immediate_profile = {
+	.name		= "proximity-immediate",
+	.remote_uuids	= BTD_UUIDS(IMMEDIATE_ALERT_UUID),
+	.device_probe	= monitor_immediate_probe,
+	.device_remove	= monitor_immediate_remove,
+};
+
+static struct btd_profile pxp_monitor_txpower_profile = {
+	.name		= "proximity-txpower",
+	.remote_uuids	= BTD_UUIDS(TX_POWER_UUID),
+	.device_probe	= monitor_txpower_probe,
+	.device_remove	= monitor_txpower_remove,
 };
 
 static struct btd_profile pxp_reporter_profile = {
@@ -122,19 +159,30 @@ int proximity_manager_init(GKeyFile *config)
 {
 	load_config_file(config);
 
-	if (btd_profile_register(&pxp_monitor_profile) < 0)
-		return -1;
+	if (btd_profile_register(&pxp_monitor_linkloss_profile) < 0)
+		goto fail;
 
-	if (btd_profile_register(&pxp_reporter_profile) < 0) {
-		btd_profile_unregister(&pxp_monitor_profile);
-		return -1;
-	}
+	if (btd_profile_register(&pxp_monitor_immediate_profile) < 0)
+		goto fail;
+
+	if (btd_profile_register(&pxp_monitor_txpower_profile) < 0)
+		goto fail;
+
+	if (btd_profile_register(&pxp_reporter_profile) < 0)
+		goto fail;
 
 	return 0;
+
+fail:
+	proximity_manager_exit();
+
+	return -1;
 }
 
 void proximity_manager_exit(void)
 {
-	btd_profile_unregister(&pxp_monitor_profile);
 	btd_profile_unregister(&pxp_reporter_profile);
+	btd_profile_unregister(&pxp_monitor_txpower_profile);
+	btd_profile_unregister(&pxp_monitor_immediate_profile);
+	btd_profile_unregister(&pxp_monitor_linkloss_profile);
 }
-- 
1.7.11.7


^ permalink raw reply related

* [RFC v0 3/5] proximity: Split internal monitor registration API
From: Mikel Astiz @ 2012-12-18 14:01 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Mikel Astiz
In-Reply-To: <1355839287-8373-1-git-send-email-mikel.astiz.oss@gmail.com>

From: Mikel Astiz <mikel.astiz@bmw-carit.de>

Split the monitor registration API into three independent registrations
each of them taking one specific GATT primary.
---
 profiles/proximity/manager.c |  16 +++-
 profiles/proximity/monitor.c | 220 ++++++++++++++++++++++++++++++++++---------
 profiles/proximity/monitor.h |  17 +++-
 3 files changed, 204 insertions(+), 49 deletions(-)

diff --git a/profiles/proximity/manager.c b/profiles/proximity/manager.c
index c3d0933..75f71ad 100644
--- a/profiles/proximity/manager.c
+++ b/profiles/proximity/manager.c
@@ -52,18 +52,30 @@ static int monitor_device_probe(struct btd_profile *p,
 				struct btd_device *device, GSList *uuids)
 {
 	struct gatt_primary *linkloss, *txpower, *immediate;
+	int err = 0;
 
 	immediate = btd_device_get_primary(device, IMMEDIATE_ALERT_UUID);
 	txpower = btd_device_get_primary(device, TX_POWER_UUID);
 	linkloss = btd_device_get_primary(device, LINK_LOSS_UUID);
 
-	return monitor_register(device, linkloss, txpower, immediate, &enabled);
+	if (linkloss)
+		err = monitor_register_linkloss(device, &enabled, linkloss);
+
+	if (err >= 0 && txpower)
+		err = monitor_register_txpower(device, &enabled, txpower);
+
+	if (err >= 0 && immediate)
+		err = monitor_register_immediate(device, &enabled, immediate);
+
+	return err;
 }
 
 static void monitor_device_remove(struct btd_profile *p,
 						struct btd_device *device)
 {
-	monitor_unregister(device);
+	monitor_unregister_immediate(device);
+	monitor_unregister_txpower(device);
+	monitor_unregister_linkloss(device);
 }
 
 static struct btd_profile pxp_monitor_profile = {
diff --git a/profiles/proximity/monitor.c b/profiles/proximity/monitor.c
index 0be0ae4..82f3a42 100644
--- a/profiles/proximity/monitor.c
+++ b/profiles/proximity/monitor.c
@@ -34,6 +34,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/stat.h>
+#include <glib.h>
 
 #include <bluetooth/bluetooth.h>
 #include <bluetooth/uuid.h>
@@ -83,6 +84,22 @@ struct monitor {
 	guint attioid;
 };
 
+static GSList *monitors = NULL;
+
+static struct monitor *find_monitor(struct btd_device *device)
+{
+	GSList *l;
+
+	for (l = monitors; l; l = l->next) {
+		struct monitor *monitor = l->data;
+
+		if (monitor->device == device)
+			return monitor;
+	}
+
+	return NULL;
+}
+
 static void write_proximity_config(struct btd_device *device, const char *alert,
 					const char *level)
 {
@@ -572,33 +589,25 @@ static void monitor_destroy(gpointer user_data)
 {
 	struct monitor *monitor = user_data;
 
-	if (monitor->immediateto)
-		g_source_remove(monitor->immediateto);
-
-	if (monitor->attioid)
-		btd_device_remove_attio_callback(monitor->device,
-						monitor->attioid);
-	if (monitor->attrib)
-		g_attrib_unref(monitor->attrib);
-
 	btd_device_unref(monitor->device);
-	g_free(monitor->linkloss);
-	g_free(monitor->immediate);
-	g_free(monitor->txpower);
 	g_free(monitor->linklosslevel);
 	g_free(monitor->immediatelevel);
 	g_free(monitor->signallevel);
 	g_free(monitor);
+
+	monitors = g_slist_remove(monitors, monitor);
 }
 
-int monitor_register(struct btd_device *device,
-		struct gatt_primary *linkloss, struct gatt_primary *txpower,
-		struct gatt_primary *immediate, struct enabled *enabled)
+static struct monitor *register_monitor(struct btd_device *device)
 {
 	const char *path = device_get_path(device);
 	struct monitor *monitor;
 	char *level;
 
+	monitor = find_monitor(device);
+	if (monitor != NULL)
+		return monitor;
+
 	level = read_proximity_config(device, "LinkLossAlertLevel");
 
 	monitor = g_new0(struct monitor, 1);
@@ -607,6 +616,8 @@ int monitor_register(struct btd_device *device,
 	monitor->signallevel = g_strdup("unknown");
 	monitor->immediatelevel = g_strdup("none");
 
+	monitors = g_slist_append(monitors, monitor);
+
 	if (g_dbus_register_interface(btd_get_dbus_connection(), path,
 				PROXIMITY_INTERFACE,
 				NULL, NULL, monitor_device_properties,
@@ -614,57 +625,180 @@ int monitor_register(struct btd_device *device,
 		error("D-Bus failed to register %s interface",
 						PROXIMITY_INTERFACE);
 		monitor_destroy(monitor);
-		return -1;
+		return NULL;
 	}
 
 	DBG("Registered interface %s on path %s", PROXIMITY_INTERFACE, path);
 
-	if (linkloss && enabled->linkloss) {
-		monitor->linkloss = g_new0(struct att_range, 1);
-		monitor->linkloss->start = linkloss->range.start;
-		monitor->linkloss->end = linkloss->range.end;
-
-		monitor->enabled.linkloss = TRUE;
-	}
-
-	if (immediate) {
-		if (txpower && enabled->pathloss) {
-			monitor->txpower = g_new0(struct att_range, 1);
-			monitor->txpower->start = txpower->range.start;
-			monitor->txpower->end = txpower->range.end;
-
-			monitor->enabled.pathloss = TRUE;
-		}
+	device_set_auto_connect(device, TRUE);
 
-		if (enabled->pathloss || enabled->findme) {
-			monitor->immediate = g_new0(struct att_range, 1);
-			monitor->immediate->start = immediate->range.start;
-			monitor->immediate->end = immediate->range.end;
-		}
+	return monitor;
+}
 
-		monitor->enabled.findme = enabled->findme;
-	}
+static void update_monitor(struct monitor *monitor)
+{
+	if (monitor->txpower != NULL && monitor->immediate != NULL)
+		monitor->enabled.pathloss = TRUE;
+	else
+		monitor->enabled.pathloss = FALSE;
 
 	DBG("Link Loss: %s, Path Loss: %s, FindMe: %s",
 				monitor->enabled.linkloss ? "TRUE" : "FALSE",
 				monitor->enabled.pathloss ? "TRUE" : "FALSE",
 				monitor->enabled.findme ? "TRUE" : "FALSE");
 
-	if (monitor->enabled.linkloss || monitor->enabled.pathloss)
-		monitor->attioid = btd_device_add_attio_callback(device,
+	if (!monitor->enabled.linkloss && !monitor->enabled.pathloss)
+		return;
+
+	if (monitor->attioid != 0)
+		return;
+
+	monitor->attioid = btd_device_add_attio_callback(monitor->device,
 							attio_connected_cb,
 							attio_disconnected_cb,
 							monitor);
+}
 
-	device_set_auto_connect(device, TRUE);
+int monitor_register_linkloss(struct btd_device *device,
+						struct enabled *enabled,
+						struct gatt_primary *linkloss)
+{
+	struct monitor *monitor;
+
+	if (!enabled->linkloss)
+		return 0;
+
+	monitor = register_monitor(device);
+	if (monitor == NULL)
+		return -1;
+
+	monitor->linkloss = g_new0(struct att_range, 1);
+	monitor->linkloss->start = linkloss->range.start;
+	monitor->linkloss->end = linkloss->range.end;
+	monitor->enabled.linkloss = TRUE;
+
+	update_monitor(monitor);
 
 	return 0;
 }
 
-void monitor_unregister(struct btd_device *device)
+int monitor_register_txpower(struct btd_device *device,
+						struct enabled *enabled,
+						struct gatt_primary *txpower)
 {
+	struct monitor *monitor;
+
+	if (!enabled->pathloss)
+		return 0;
+
+	monitor = register_monitor(device);
+	if (monitor == NULL)
+		return -1;
+
+	monitor->txpower = g_new0(struct att_range, 1);
+	monitor->txpower->start = txpower->range.start;
+	monitor->txpower->end = txpower->range.end;
+
+	update_monitor(monitor);
+
+	return 0;
+}
+
+int monitor_register_immediate(struct btd_device *device,
+						struct enabled *enabled,
+						struct gatt_primary *immediate)
+{
+	struct monitor *monitor;
+
+	if (!enabled->pathloss && !enabled->findme)
+		return 0;
+
+	monitor = register_monitor(device);
+	if (monitor == NULL)
+		return -1;
+
+	monitor->immediate = g_new0(struct att_range, 1);
+	monitor->immediate->start = immediate->range.start;
+	monitor->immediate->end = immediate->range.end;
+	monitor->enabled.findme = enabled->findme;
+
+	update_monitor(monitor);
+
+	return 0;
+}
+
+static void cleanup_monitor(struct monitor *monitor)
+{
+	struct btd_device *device = monitor->device;
 	const char *path = device_get_path(device);
 
+	if (monitor->immediate != NULL || monitor->txpower != NULL)
+		return;
+
+	if (monitor->immediateto != 0) {
+		g_source_remove(monitor->immediateto);
+		monitor->immediateto = 0;
+	}
+
+	if (monitor->attioid != 0) {
+		btd_device_remove_attio_callback(device, monitor->attioid);
+		monitor->attioid = 0;
+	}
+
+	if (monitor->attrib != NULL) {
+		g_attrib_unref(monitor->attrib);
+		monitor->attrib = NULL;
+	}
+
+	if (monitor->linkloss != NULL)
+		return;
+
 	g_dbus_unregister_interface(btd_get_dbus_connection(), path,
 							PROXIMITY_INTERFACE);
 }
+
+void monitor_unregister_linkloss(struct btd_device *device)
+{
+	struct monitor *monitor;
+
+	monitor = find_monitor(device);
+	if (monitor == NULL)
+		return;
+
+	g_free(monitor->linkloss);
+	monitor->linkloss = NULL;
+	monitor->enabled.linkloss = TRUE;
+
+	cleanup_monitor(monitor);
+}
+
+void monitor_unregister_txpower(struct btd_device *device)
+{
+	struct monitor *monitor;
+
+	monitor = find_monitor(device);
+	if (monitor == NULL)
+		return;
+
+	g_free(monitor->txpower);
+	monitor->txpower = NULL;
+	monitor->enabled.pathloss = FALSE;
+
+	cleanup_monitor(monitor);
+}
+
+void monitor_unregister_immediate(struct btd_device *device)
+{
+	struct monitor *monitor;
+
+	monitor = find_monitor(device);
+	if (monitor == NULL)
+		return;
+
+	g_free(monitor->immediate);
+	monitor->immediate = NULL;
+	monitor->enabled.findme = FALSE;
+	monitor->enabled.pathloss = FALSE;
+
+	cleanup_monitor(monitor);
+}
diff --git a/profiles/proximity/monitor.h b/profiles/proximity/monitor.h
index 191b562..d9a40c6 100644
--- a/profiles/proximity/monitor.h
+++ b/profiles/proximity/monitor.h
@@ -28,7 +28,16 @@ struct enabled {
 	gboolean findme;
 };
 
-int monitor_register(struct btd_device *device, struct gatt_primary *linkloss,
-		struct gatt_primary *txpower, struct gatt_primary *immediate,
-		struct enabled *enabled);
-void monitor_unregister(struct btd_device *device);
+int monitor_register_linkloss(struct btd_device *device,
+						struct enabled *enabled,
+						struct gatt_primary *linkloss);
+int monitor_register_txpower(struct btd_device *device,
+						struct enabled *enabled,
+						struct gatt_primary *txpower);
+int monitor_register_immediate(struct btd_device *device,
+						struct enabled *enabled,
+						struct gatt_primary *immediate);
+
+void monitor_unregister_linkloss(struct btd_device *device);
+void monitor_unregister_txpower(struct btd_device *device);
+void monitor_unregister_immediate(struct btd_device *device);
-- 
1.7.11.7


^ permalink raw reply related

* [RFC v0 2/5] audio: Split AVRCP into two btd_profile
From: Mikel Astiz @ 2012-12-18 14:01 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Mikel Astiz
In-Reply-To: <1355839287-8373-1-git-send-email-mikel.astiz.oss@gmail.com>

From: Mikel Astiz <mikel.astiz@bmw-carit.de>

Register a separate btd_profile for each role of AVRCP.
---
 profiles/audio/audio.conf |  2 +-
 profiles/audio/avrcp.c    | 80 ++++++++++++++++++++++++++++++++++++-----------
 profiles/audio/avrcp.h    |  6 ++--
 profiles/audio/manager.c  | 80 ++++++++++++++++++++++++++++++++++++++++-------
 profiles/audio/manager.h  |  1 +
 5 files changed, 137 insertions(+), 32 deletions(-)

diff --git a/profiles/audio/audio.conf b/profiles/audio/audio.conf
index f556610..566454b 100644
--- a/profiles/audio/audio.conf
+++ b/profiles/audio/audio.conf
@@ -8,5 +8,5 @@
 #Master=true
 
 # If we want to disable support for specific services
-# Defaults to supporting the services: Sink, Control
+# Defaults to supporting the services: Sink, Control, Target
 #Disable=Source
diff --git a/profiles/audio/avrcp.c b/profiles/audio/avrcp.c
index b32c422..22dd1a5 100644
--- a/profiles/audio/avrcp.c
+++ b/profiles/audio/avrcp.c
@@ -2305,41 +2305,63 @@ static struct avrcp_server *avrcp_server_register(const bdaddr_t *src,
 	return server;
 }
 
-int avrcp_register(const bdaddr_t *src, GKeyFile *config)
+int avrcp_target_register(const bdaddr_t *src, GKeyFile *config)
 {
 	sdp_record_t *record;
 	struct avrcp_server *server;
 
+	server = find_server(servers, src);
+	if (server != NULL)
+		goto done;
+
 	server = avrcp_server_register(src, config);
 	if (server == NULL)
 		return -EPROTONOSUPPORT;
 
+done:
 	record = avrcp_tg_record();
 	if (!record) {
 		error("Unable to allocate new service record");
-		avrcp_unregister(src);
+		avrcp_target_unregister(src);
 		return -1;
 	}
 
 	if (add_record_to_server(src, record) < 0) {
 		error("Unable to register AVRCP target service record");
-		avrcp_unregister(src);
+		avrcp_target_unregister(src);
 		sdp_record_free(record);
 		return -1;
 	}
 	server->tg_record_id = record->handle;
 
+	return 0;
+}
+
+int avrcp_control_register(const bdaddr_t *src, GKeyFile *config)
+{
+	sdp_record_t *record;
+	struct avrcp_server *server;
+
+	server = find_server(servers, src);
+	if (server != NULL)
+		goto done;
+
+	server = avrcp_server_register(src, config);
+	if (server == NULL)
+		return -EPROTONOSUPPORT;
+
+done:
 	record = avrcp_ct_record();
 	if (!record) {
 		error("Unable to allocate new service record");
-		avrcp_unregister(src);
+		avrcp_control_unregister(src);
 		return -1;
 	}
 
 	if (add_record_to_server(src, record) < 0) {
 		error("Unable to register AVRCP service record");
 		sdp_record_free(record);
-		avrcp_unregister(src);
+		avrcp_control_unregister(src);
 		return -1;
 	}
 	server->ct_record_id = record->handle;
@@ -2347,25 +2369,13 @@ int avrcp_register(const bdaddr_t *src, GKeyFile *config)
 	return 0;
 }
 
-void avrcp_unregister(const bdaddr_t *src)
+static void avrcp_server_unregister(struct avrcp_server *server)
 {
-	struct avrcp_server *server;
-
-	server = find_server(servers, src);
-	if (!server)
-		return;
-
 	g_slist_free_full(server->sessions, g_free);
 	g_slist_free_full(server->players, player_destroy);
 
 	servers = g_slist_remove(servers, server);
 
-	if (server->ct_record_id != 0)
-		remove_record_from_server(server->ct_record_id);
-
-	if (server->tg_record_id != 0)
-		remove_record_from_server(server->tg_record_id);
-
 	avctp_unregister(&server->src);
 	g_free(server);
 
@@ -2378,6 +2388,40 @@ void avrcp_unregister(const bdaddr_t *src)
 	}
 }
 
+void avrcp_target_unregister(const bdaddr_t *src)
+{
+	struct avrcp_server *server;
+
+	server = find_server(servers, src);
+	if (!server)
+		return;
+
+	if (server->tg_record_id != 0) {
+		remove_record_from_server(server->tg_record_id);
+		server->tg_record_id = 0;
+	}
+
+	if (server->ct_record_id == 0)
+		avrcp_server_unregister(server);
+}
+
+void avrcp_control_unregister(const bdaddr_t *src)
+{
+	struct avrcp_server *server;
+
+	server = find_server(servers, src);
+	if (!server)
+		return;
+
+	if (server->ct_record_id != 0) {
+		remove_record_from_server(server->ct_record_id);
+		server->ct_record_id = 0;
+	}
+
+	if (server->tg_record_id == 0)
+		avrcp_server_unregister(server);
+}
+
 struct avrcp_player *avrcp_register_player(const bdaddr_t *src,
 						struct avrcp_player_cb *cb,
 						void *user_data,
diff --git a/profiles/audio/avrcp.h b/profiles/audio/avrcp.h
index e607fb1..cddf40b 100644
--- a/profiles/audio/avrcp.h
+++ b/profiles/audio/avrcp.h
@@ -92,8 +92,10 @@ struct avrcp_player_cb {
 							void *user_data);
 };
 
-int avrcp_register(const bdaddr_t *src, GKeyFile *config);
-void avrcp_unregister(const bdaddr_t *src);
+int avrcp_target_register(const bdaddr_t *src, GKeyFile *config);
+void avrcp_target_unregister(const bdaddr_t *src);
+int avrcp_control_register(const bdaddr_t *src, GKeyFile *config);
+void avrcp_control_unregister(const bdaddr_t *src);
 
 gboolean avrcp_connect(struct audio_device *dev);
 void avrcp_disconnect(struct audio_device *dev);
diff --git a/profiles/audio/manager.c b/profiles/audio/manager.c
index 422316e..976a879 100644
--- a/profiles/audio/manager.c
+++ b/profiles/audio/manager.c
@@ -82,6 +82,7 @@ static struct enabled_interfaces enabled = {
 	.sink		= TRUE,
 	.source		= FALSE,
 	.control	= TRUE,
+	.target		= TRUE,
 };
 
 static struct audio_adapter *find_adapter(GSList *list,
@@ -371,7 +372,7 @@ static int a2dp_sink_server_probe(struct btd_profile *p,
 	return a2dp_sink_register(adapter_get_address(adapter), config);
 }
 
-static int avrcp_server_probe(struct btd_profile *p,
+static int avrcp_target_server_probe(struct btd_profile *p,
 						struct btd_adapter *adapter)
 {
 	struct audio_adapter *adp;
@@ -384,14 +385,50 @@ static int avrcp_server_probe(struct btd_profile *p,
 	if (!adp)
 		return -EINVAL;
 
-	err = avrcp_register(adapter_get_address(adapter), config);
+	err = avrcp_target_register(adapter_get_address(adapter), config);
 	if (err < 0)
 		audio_adapter_unref(adp);
 
 	return err;
 }
 
-static void avrcp_server_remove(struct btd_profile *p,
+static int avrcp_control_server_probe(struct btd_profile *p,
+						struct btd_adapter *adapter)
+{
+	struct audio_adapter *adp;
+	const gchar *path = adapter_get_path(adapter);
+	int err;
+
+	DBG("path %s", path);
+
+	adp = audio_adapter_get(adapter);
+	if (!adp)
+		return -EINVAL;
+
+	err = avrcp_control_register(adapter_get_address(adapter), config);
+	if (err < 0)
+		audio_adapter_unref(adp);
+
+	return err;
+}
+
+static void avrcp_target_server_remove(struct btd_profile *p,
+						struct btd_adapter *adapter)
+{
+	struct audio_adapter *adp;
+	const gchar *path = adapter_get_path(adapter);
+
+	DBG("path %s", path);
+
+	adp = find_adapter(adapters, adapter);
+	if (!adp)
+		return;
+
+	avrcp_target_unregister(adapter_get_address(adapter));
+	audio_adapter_unref(adp);
+}
+
+static void avrcp_control_server_remove(struct btd_profile *p,
 						struct btd_adapter *adapter)
 {
 	struct audio_adapter *adp;
@@ -403,7 +440,7 @@ static void avrcp_server_remove(struct btd_profile *p,
 	if (!adp)
 		return;
 
-	avrcp_unregister(adapter_get_address(adapter));
+	avrcp_control_unregister(adapter_get_address(adapter));
 	audio_adapter_unref(adp);
 }
 
@@ -471,10 +508,21 @@ static struct btd_profile a2dp_sink_profile = {
 	.adapter_probe	= a2dp_sink_server_probe,
 };
 
-static struct btd_profile avrcp_profile = {
-	.name		= "audio-avrcp",
+static struct btd_profile avrcp_target_profile = {
+	.name		= "audio-avrcp-target",
+
+	.remote_uuids	= BTD_UUIDS(AVRCP_TARGET_UUID),
+	.device_probe	= avrcp_probe,
+	.device_remove	= audio_remove,
+
+	.adapter_probe	= avrcp_target_server_probe,
+	.adapter_remove = avrcp_target_server_remove,
+};
+
+static struct btd_profile avrcp_control_profile = {
+	.name		= "audio-avrcp-control",
 
-	.remote_uuids	= BTD_UUIDS(AVRCP_TARGET_UUID, AVRCP_REMOTE_UUID),
+	.remote_uuids	= BTD_UUIDS(AVRCP_REMOTE_UUID),
 	.device_probe	= avrcp_probe,
 	.device_remove	= audio_remove,
 
@@ -482,8 +530,8 @@ static struct btd_profile avrcp_profile = {
 	.connect	= avrcp_control_connect,
 	.disconnect	= avrcp_control_disconnect,
 
-	.adapter_probe	= avrcp_server_probe,
-	.adapter_remove = avrcp_server_remove,
+	.adapter_probe	= avrcp_control_server_probe,
+	.adapter_remove = avrcp_control_server_remove,
 };
 
 static struct btd_adapter_driver media_driver = {
@@ -531,6 +579,8 @@ int audio_manager_init(GKeyFile *conf)
 			enabled.source = TRUE;
 		else if (g_str_equal(list[i], "Control"))
 			enabled.control = TRUE;
+		else if (g_str_equal(list[i], "Target"))
+			enabled.target = TRUE;
 	}
 	g_strfreev(list);
 
@@ -543,6 +593,8 @@ int audio_manager_init(GKeyFile *conf)
 			enabled.source = FALSE;
 		else if (g_str_equal(list[i], "Control"))
 			enabled.control = FALSE;
+		else if (g_str_equal(list[i], "Target"))
+			enabled.target = FALSE;
 	}
 	g_strfreev(list);
 
@@ -554,7 +606,10 @@ proceed:
 		btd_profile_register(&a2dp_sink_profile);
 
 	if (enabled.control)
-		btd_profile_register(&avrcp_profile);
+		btd_profile_register(&avrcp_control_profile);
+
+	if (enabled.target)
+		btd_profile_register(&avrcp_target_profile);
 
 	btd_register_adapter_driver(&media_driver);
 
@@ -575,7 +630,10 @@ void audio_manager_exit(void)
 		btd_profile_unregister(&a2dp_sink_profile);
 
 	if (enabled.control)
-		btd_profile_unregister(&avrcp_profile);
+		btd_profile_unregister(&avrcp_control_profile);
+
+	if (enabled.target)
+		btd_profile_unregister(&avrcp_target_profile);
 
 	btd_unregister_adapter_driver(&media_driver);
 }
diff --git a/profiles/audio/manager.h b/profiles/audio/manager.h
index 2b924dc..fc5362b 100644
--- a/profiles/audio/manager.h
+++ b/profiles/audio/manager.h
@@ -26,6 +26,7 @@ struct enabled_interfaces {
 	gboolean sink;
 	gboolean source;
 	gboolean control;
+	gboolean target;
 	gboolean media_player;
 };
 
-- 
1.7.11.7


^ permalink raw reply related

* [RFC v0 1/5] avrcp: Refactor server registration
From: Mikel Astiz @ 2012-12-18 14:01 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Mikel Astiz
In-Reply-To: <1355839287-8373-1-git-send-email-mikel.astiz.oss@gmail.com>

From: Mikel Astiz <mikel.astiz@bmw-carit.de>

Use a helper function to install the AVRCP server, just like other audio
profiles such as in a2dp.c do.
---
 profiles/audio/avrcp.c | 55 +++++++++++++++++++++++++++++---------------------
 1 file changed, 32 insertions(+), 23 deletions(-)

diff --git a/profiles/audio/avrcp.c b/profiles/audio/avrcp.c
index 3ab7d35..b32c422 100644
--- a/profiles/audio/avrcp.c
+++ b/profiles/audio/avrcp.c
@@ -2275,12 +2275,12 @@ void avrcp_disconnect(struct audio_device *dev)
 	avctp_disconnect(session);
 }
 
-int avrcp_register(const bdaddr_t *src, GKeyFile *config)
+static struct avrcp_server *avrcp_server_register(const bdaddr_t *src,
+							GKeyFile *config)
 {
-	sdp_record_t *record;
+	struct avrcp_server *server;
 	gboolean tmp, master = TRUE;
 	GError *err = NULL;
-	struct avrcp_server *server;
 
 	if (config) {
 		tmp = g_key_file_get_boolean(config, "General",
@@ -2292,18 +2292,38 @@ int avrcp_register(const bdaddr_t *src, GKeyFile *config)
 			master = tmp;
 	}
 
+	if (avctp_register(src, master) < 0)
+		return NULL;
+
 	server = g_new0(struct avrcp_server, 1);
+	bacpy(&server->src, src);
+	servers = g_slist_append(servers, server);
+
+	if (!avctp_id)
+		avctp_id = avctp_add_state_cb(state_changed, NULL);
+
+	return server;
+}
+
+int avrcp_register(const bdaddr_t *src, GKeyFile *config)
+{
+	sdp_record_t *record;
+	struct avrcp_server *server;
+
+	server = avrcp_server_register(src, config);
+	if (server == NULL)
+		return -EPROTONOSUPPORT;
 
 	record = avrcp_tg_record();
 	if (!record) {
 		error("Unable to allocate new service record");
-		g_free(server);
+		avrcp_unregister(src);
 		return -1;
 	}
 
 	if (add_record_to_server(src, record) < 0) {
 		error("Unable to register AVRCP target service record");
-		g_free(server);
+		avrcp_unregister(src);
 		sdp_record_free(record);
 		return -1;
 	}
@@ -2312,32 +2332,18 @@ int avrcp_register(const bdaddr_t *src, GKeyFile *config)
 	record = avrcp_ct_record();
 	if (!record) {
 		error("Unable to allocate new service record");
-		g_free(server);
+		avrcp_unregister(src);
 		return -1;
 	}
 
 	if (add_record_to_server(src, record) < 0) {
 		error("Unable to register AVRCP service record");
 		sdp_record_free(record);
-		g_free(server);
+		avrcp_unregister(src);
 		return -1;
 	}
 	server->ct_record_id = record->handle;
 
-	if (avctp_register(src, master) < 0) {
-		remove_record_from_server(server->ct_record_id);
-		remove_record_from_server(server->tg_record_id);
-		g_free(server);
-		return -1;
-	}
-
-	bacpy(&server->src, src);
-
-	servers = g_slist_append(servers, server);
-
-	if (!avctp_id)
-		avctp_id = avctp_add_state_cb(state_changed, NULL);
-
 	return 0;
 }
 
@@ -2354,8 +2360,11 @@ void avrcp_unregister(const bdaddr_t *src)
 
 	servers = g_slist_remove(servers, server);
 
-	remove_record_from_server(server->ct_record_id);
-	remove_record_from_server(server->tg_record_id);
+	if (server->ct_record_id != 0)
+		remove_record_from_server(server->ct_record_id);
+
+	if (server->tg_record_id != 0)
+		remove_record_from_server(server->tg_record_id);
 
 	avctp_unregister(&server->src);
 	g_free(server);
-- 
1.7.11.7


^ permalink raw reply related

* [RFC v0 0/5] One remote UUID per btd_profile
From: Mikel Astiz @ 2012-12-18 14:01 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Mikel Astiz

From: Mikel Astiz <mikel.astiz@bmw-carit.de>

Disclaimer: this RFC is WIP and hasn't been tested, specially because I don't have the necessary hardware for it.

The goal is to have one remote_uuid per btd_profile. There are only a few exceptions to this rule, and this patchset tries to fix three of them. This basically means splitting one btd_profile per role.

Cheers,
Mikel

Mikel Astiz (5):
  avrcp: Refactor server registration
  audio: Split AVRCP into two btd_profile
  proximity: Split internal monitor registration API
  proximity: Split monitor into three btd_profile
  gatt: List only GATT_UUID as remote UUID

 profiles/audio/audio.conf    |   2 +-
 profiles/audio/avrcp.c       | 115 ++++++++++++++++------
 profiles/audio/avrcp.h       |   6 +-
 profiles/audio/manager.c     |  80 +++++++++++++---
 profiles/audio/manager.h     |   1 +
 profiles/gatt/manager.c      |   2 +-
 profiles/proximity/manager.c |  98 +++++++++++++++----
 profiles/proximity/monitor.c | 220 ++++++++++++++++++++++++++++++++++---------
 profiles/proximity/monitor.h |  17 +++-
 9 files changed, 429 insertions(+), 112 deletions(-)

-- 
1.7.11.7


^ permalink raw reply

* Re: [PATCH 3/3 v1] Bluetooth: Fix stop discovery while in STARTING state
From: Jaganath Kanakkassery @ 2012-12-18 13:27 UTC (permalink / raw)
  To: Gustavo Padovan; +Cc: linux-bluetooth
In-Reply-To: <20121211221534.GA7912@joana>

Hi Gustavo,

--------------------------------------------------
From: "Gustavo Padovan" <gustavo@padovan.org>
Sent: Wednesday, December 12, 2012 3:45 AM
To: "Jaganath Kanakkassery" <jaganath.k@samsung.com>
Cc: <linux-bluetooth@vger.kernel.org>
Subject: Re: [PATCH 3/3 v1] Bluetooth: Fix stop discovery while in STARTING 
state

> Hi Jaganath,
>
> * Jaganath Kanakkassery <jaganath.k@samsung.com> [2012-12-06 16:35:58 
> +0530]:
>
>> If stop_discovery() is called when discovery state is STARTING, it
>> will be failed currently. This patch fixes this.
>>
>> Signed-off-by: Jaganath Kanakkassery <jaganath.k@samsung.com>
>> ---
>>  include/net/bluetooth/hci_core.h |    1 +
>>  net/bluetooth/hci_core.c         |    9 ++++++++-
>>  net/bluetooth/hci_event.c        |   15 +++++++++++++--
>>  net/bluetooth/mgmt.c             |    9 +++++++++
>>  4 files changed, 31 insertions(+), 3 deletions(-)
>>
>> diff --git a/include/net/bluetooth/hci_core.h 
>> b/include/net/bluetooth/hci_core.h
>> index bd63a9f..d09777a 100644
>> --- a/include/net/bluetooth/hci_core.h
>> +++ b/include/net/bluetooth/hci_core.h
>> @@ -64,6 +64,7 @@ struct discovery_state {
>>  DISCOVERY_RESOLVING,
>>  DISCOVERY_STOPPING,
>>  } state;
>> + int prev_state;
>>  struct list_head all; /* All devices found during inquiry */
>>  struct list_head unknown; /* Name state not known */
>>  struct list_head resolve; /* Name needs to be resolved */
>> diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
>> index c6c67b2..93d0261 100644
>> --- a/net/bluetooth/hci_core.c
>> +++ b/net/bluetooth/hci_core.c
>> @@ -391,7 +391,13 @@ void hci_discovery_set_state(struct hci_dev *hdev, 
>> int state)
>>
>>  switch (state) {
>>  case DISCOVERY_STOPPED:
>> - if (hdev->discovery.state != DISCOVERY_STARTING)
>> + if (hdev->discovery.state == DISCOVERY_STARTING)
>> + break;
>> +
>> + if (hdev->discovery.state == DISCOVERY_STOPPING &&
>> +     hdev->discovery.prev_state == DISCOVERY_STARTING)
>> + mgmt_stop_discovery_complete(hdev, 0);
>> + else
>>  mgmt_discovering(hdev, 0);
>
> I don't think we need to be this complicated here, I don't think that add
> discovery.prev_state is a good a idea. I would prefer if you add
> discovery.discovering that will tell if we are discovering or not, then 
> check
> inside mgmt_discovering() if the value is the same and return right away.
> You would just need to add the mgmt_stop_discovery_complete() in case 
> state is
> DISCOVERY_STOPPING.
>

I think in this case no need to call mgmt_stop_discovery_complete() 
explicitly.
mgmt_discovering() with discovering 0 will send stop_discovery_complete().
So after sending command complete we can check the value of discovering and
return.

But one thing I see in this scenario is, when we should send 
start_discovery_complete()?
What I think is in SCAN_ENABLED event if state is STOPPING we can send
start_discovery_complete with MGMT_STATUS _CANCELLED error code.
What do you think?

>>  break;
>>  case DISCOVERY_STARTING:
>> @@ -405,6 +411,7 @@ void hci_discovery_set_state(struct hci_dev *hdev, 
>> int state)
>>  break;
>>  }
>>
>> + hdev->discovery.prev_state = hdev->discovery.state;
>>  hdev->discovery.state = state;
>>  }
>>
>> diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
>> index 1fadba5..3f9f317 100644
>> --- a/net/bluetooth/hci_event.c
>> +++ b/net/bluetooth/hci_event.c
>> @@ -1085,6 +1085,8 @@ static void hci_cc_le_set_scan_enable(struct 
>> hci_dev *hdev,
>>  if (status) {
>>  hci_dev_lock(hdev);
>>  mgmt_start_discovery_failed(hdev, status);
>> + if (hdev->discovery.state == DISCOVERY_STOPPING)
>> + mgmt_stop_discovery_complete(hdev, status);
>
> I think this case will be handled by hci_discovery_set_state(), and you 
> could
> just remove this from here. And why you return the set_scan_enable status
> error to the stop discovery command?
>
Ok

>>  hci_dev_unlock(hdev);
>>  return;
>>  }
>> @@ -1092,7 +1094,10 @@ static void hci_cc_le_set_scan_enable(struct 
>> hci_dev *hdev,
>>  set_bit(HCI_LE_SCAN, &hdev->dev_flags);
>>
>>  hci_dev_lock(hdev);
>> - hci_discovery_set_state(hdev, DISCOVERY_FINDING);
>> + if (hdev->discovery.state == DISCOVERY_STOPPING)
>> + hci_cancel_le_scan(hdev);
>> + else
>> + hci_discovery_set_state(hdev, DISCOVERY_FINDING);
>>  hci_dev_unlock(hdev);
>>  break;
>>
>> @@ -1180,8 +1185,11 @@ static void hci_cs_inquiry(struct hci_dev *hdev, 
>> __u8 status)
>>  hci_req_complete(hdev, HCI_OP_INQUIRY, status);
>>  hci_conn_check_pending(hdev);
>>  hci_dev_lock(hdev);
>> - if (test_bit(HCI_MGMT, &hdev->dev_flags))
>> + if (test_bit(HCI_MGMT, &hdev->dev_flags)) {
>>  mgmt_start_discovery_failed(hdev, status);
>> + if (hdev->discovery.state == DISCOVERY_STOPPING)
>> + mgmt_stop_discovery_complete(hdev, status);
>> + }
>
> Saome thing as the previous comment, you don't need this.
> mgmt_start_discovery_failed() calls hci_discovery_set_state().
>

Ok

>>  hci_dev_unlock(hdev);
>>  return;
>>  }
>> @@ -1189,6 +1197,9 @@ static void hci_cs_inquiry(struct hci_dev *hdev, 
>> __u8 status)
>>  set_bit(HCI_INQUIRY, &hdev->flags);
>>
>>  hci_dev_lock(hdev);
>> + if (hdev->discovery.state == DISCOVERY_STOPPING)
>> + hci_cancel_inquiry(hdev);
>> + else
>>  hci_discovery_set_state(hdev, DISCOVERY_FINDING);
>
> Wrong indentation level inside the else.
>

Will correct in the next patch.

>>  hci_dev_unlock(hdev);
>>  }
>> diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
>> index 332152b..a645494 100644
>> --- a/net/bluetooth/mgmt.c
>> +++ b/net/bluetooth/mgmt.c
>> @@ -2387,6 +2387,11 @@ static int stop_discovery(struct sock *sk, struct 
>> hci_dev *hdev, void *data,
>>
>>  hci_dev_lock(hdev);
>>
>> + if (hdev->discovery.state == DISCOVERY_STARTING) {
>> + err = 0;
>> + goto proceed;
>> + }
>> +
>>  if (!hci_discovery_active(hdev)) {
>
> I would do something like this instead:
>
>        if (hdev->discovery.state != DISCOVERY_STARTING &&
>             !hci_discovery_active(hdev)) {
>
>
> And remove the label jump from here...
>

Ok

>>  err = cmd_complete(sk, hdev->id, MGMT_OP_STOP_DISCOVERY,
>>     MGMT_STATUS_REJECTED, &mgmt_cp->type,
>> @@ -2401,6 +2406,7 @@ static int stop_discovery(struct sock *sk, struct 
>> hci_dev *hdev, void *data,
>>  goto unlock;
>>  }
>>
>> +proceed:
>>  cmd = mgmt_pending_add(sk, MGMT_OP_STOP_DISCOVERY, hdev, NULL, 0);
>>  if (!cmd) {
>>  err = -ENOMEM;
>> @@ -2435,6 +2441,9 @@ static int stop_discovery(struct sock *sk, struct 
>> hci_dev *hdev, void *data,
>>
>>  break;
>>
>> + case DISCOVERY_STARTING:
>
> and add err = 0 here.
>
Ok

Thanks,
Jaganath 


^ permalink raw reply

* Re: [PATCH 1/2] hcidump: Fix compilation errors due to unaligned memory access
From: Johan Hedberg @ 2012-12-18 11:45 UTC (permalink / raw)
  To: Szymon Janc; +Cc: linux-bluetooth
In-Reply-To: <1355829058-10033-1-git-send-email-szymon.janc@tieto.com>

Hi Szymon,

On Tue, Dec 18, 2012, Szymon Janc wrote:
> Use bt_get_le* helper functions to access unaligned memory. This fix
> number of compilation errors on ARM similar to:
> 
> CC     tools/parser/hci.o
> tools/parser/hci.c: In function ‘ext_inquiry_data_dump’:
> tools/parser/hci.c:797:10 error: cast increases required alignment of
> 	target type [-Werror=cast-align]
> tools/parser/hci.c:797:10: error: cast increases required alignment of
> 	target type [-Werror=cast-align]
> cc1: all warnings being treated as errors
> make[1]: *** [tools/parser/hci.o] Error 1
> ---
>  tools/parser/hci.c   |  7 ++-----
>  tools/parser/l2cap.c | 22 +++++++++++-----------
>  2 files changed, 13 insertions(+), 16 deletions(-)

Both patches have been applied. Thanks.

Johan

^ permalink raw reply

* [PATCH 2/2] adapter: Use int for storing signed value
From: Szymon Janc @ 2012-12-18 11:10 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1355829058-10033-1-git-send-email-szymon.janc@tieto.com>

char can be signed or unsigned depending on architecture. This fix
following compilation error on ARM:

src/adapter.c: In function 'convert_primaries_entry`:
src/adapter:2272:2: error: comparison is always true due to limited
	range of data type [-Werror=type-limits]
cc1: all warnings being treated as errors
make[1]: *** [src/adapter.o] Error 1
---
 src/adapter.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/adapter.c b/src/adapter.c
index a41eb15..bb54d8b 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2215,7 +2215,7 @@ failed:
 static void convert_primaries_entry(char *key, char *value, void *user_data)
 {
 	char *address = user_data;
-	char device_type = -1;
+	int device_type = -1;
 	uuid_t uuid;
 	char **services, **service, *prim_uuid;
 	char filename[PATH_MAX + 1];
-- 
1.8.0


^ permalink raw reply related

* [PATCH 1/2] hcidump: Fix compilation errors due to unaligned memory access
From: Szymon Janc @ 2012-12-18 11:10 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

Use bt_get_le* helper functions to access unaligned memory. This fix
number of compilation errors on ARM similar to:

CC     tools/parser/hci.o
tools/parser/hci.c: In function ‘ext_inquiry_data_dump’:
tools/parser/hci.c:797:10 error: cast increases required alignment of
	target type [-Werror=cast-align]
tools/parser/hci.c:797:10: error: cast increases required alignment of
	target type [-Werror=cast-align]
cc1: all warnings being treated as errors
make[1]: *** [tools/parser/hci.o] Error 1
---
 tools/parser/hci.c   |  7 ++-----
 tools/parser/l2cap.c | 22 +++++++++++-----------
 2 files changed, 13 insertions(+), 16 deletions(-)

diff --git a/tools/parser/hci.c b/tools/parser/hci.c
index 4d2b91b..17b776d 100644
--- a/tools/parser/hci.c
+++ b/tools/parser/hci.c
@@ -791,12 +791,9 @@ static inline void ext_inquiry_data_dump(int level, struct frame *frm,
 		printf("%s service classes:",
 				type == 0x02 ? "Shortened" : "Complete");
 
-		for (i = 0; i < len / 2; i++) {
-			uint16_t val;
+		for (i = 0; i < len / 2; i++)
+			printf(" 0x%4.4x", bt_get_le16(data + i * 2));
 
-			val = btohs(bt_get_unaligned(((uint16_t *) (data + i * 2))));
-			printf(" 0x%4.4x", val);
-		}
 		printf("\n");
 		break;
 
diff --git a/tools/parser/l2cap.c b/tools/parser/l2cap.c
index 6b3e17a..42f5e1a 100644
--- a/tools/parser/l2cap.c
+++ b/tools/parser/l2cap.c
@@ -250,9 +250,9 @@ static uint32_t get_val(uint8_t *ptr, uint8_t len)
 	case 1:
 		return *ptr;
 	case 2:
-		return btohs(bt_get_unaligned((uint16_t *) ptr));
+		return bt_get_le16(ptr);
 	case 4:
-		return btohl(bt_get_unaligned((uint32_t *) ptr));
+		return bt_get_le32(ptr);
 	}
 	return 0;
 }
@@ -595,9 +595,9 @@ static void conf_rfc(void *ptr, int len, int in, uint16_t handle,
 		uint16_t rto, mto, mps;
 		txwin = *((uint8_t *) (ptr + 1));
 		maxtrans = *((uint8_t *) (ptr + 2));
-		rto = btohs(bt_get_unaligned((uint16_t *) (ptr + 3)));
-		mto = btohs(bt_get_unaligned((uint16_t *) (ptr + 5)));
-		mps = btohs(bt_get_unaligned((uint16_t *) (ptr + 7)));
+		rto = bt_get_le16(ptr + 3);
+		mto = bt_get_le16(ptr + 5);
+		mps = bt_get_le16(ptr + 7);
 		printf(", TxWin %d, MaxTx %d, RTo %d, MTo %d, MPS %d",
 					txwin, maxtrans, rto, mto, mps);
 	}
@@ -916,7 +916,7 @@ static void l2cap_ctrl_ext_parse(int level, struct frame *frm, uint32_t ctrl)
 		printf(" %s", sar2str(sar));
 		if (sar == L2CAP_SAR_START) {
 			uint16_t len;
-			len = btohs(bt_get_unaligned((uint16_t *) frm->ptr));
+			len = bt_get_le16(frm->ptr);
 			frm->ptr += L2CAP_SDULEN_SIZE;
 			frm->len -= L2CAP_SDULEN_SIZE;
 			printf(" (len %d)", len);
@@ -949,7 +949,7 @@ static void l2cap_ctrl_parse(int level, struct frame *frm, uint32_t ctrl)
 		printf(" %s", sar2str(sar));
 		if (sar == L2CAP_SAR_START) {
 			uint16_t len;
-			len = btohs(bt_get_unaligned((uint16_t *) frm->ptr));
+			len = bt_get_le16(frm->ptr);
 			frm->ptr += L2CAP_SDULEN_SIZE;
 			frm->len -= L2CAP_SDULEN_SIZE;
 			printf(" (len %d)", len);
@@ -1062,7 +1062,7 @@ static inline void a2mp_discover_req(int level, struct frame *frm, uint16_t len)
 
 	do {
 		len -= 2;
-		mask = btohs(*(uint16_t *)(&octet[0]));
+		mask = bt_get_le16(octet);
 		printf(" 0x%4.4x", mask);
 
 		extension = octet[1] & 0x80;
@@ -1102,7 +1102,7 @@ static inline void a2mp_discover_rsp(int level, struct frame *frm, uint16_t len)
 
 	do {
 		len -= 2;
-		mask = btohs(*(uint16_t *)(&octet[0]));
+		mask = bt_get_le16(octet);
 		printf(" 0x%4.4x", mask);
 
 		extension = octet[1] & 0x80;
@@ -1324,7 +1324,7 @@ static void l2cap_parse(int level, struct frame *frm)
 		if (p_filter(FILT_L2CAP))
 			return;
 
-		psm = btohs(bt_get_unaligned((uint16_t *) frm->ptr));
+		psm = bt_get_le16(frm->ptr);
 		frm->ptr += 2;
 		frm->len -= 2;
 
@@ -1433,7 +1433,7 @@ static void l2cap_parse(int level, struct frame *frm)
 				frm->ptr += 2;
 				frm->len -= 4;
 			}
-			fcs = btohs(bt_get_unaligned((uint16_t *) (frm->ptr + frm->len)));
+			fcs = bt_get_le16(frm->ptr + frm->len);
 		}
 
 		if (!p_filter(FILT_L2CAP)) {
-- 
1.8.0


^ permalink raw reply related

* Re: PulseAudio branch to test BlueZ master
From: Mikel Astiz @ 2012-12-18 10:19 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Tanu Kaskinen
In-Reply-To: <CANT-zCWNUkTW9pmcvuDEhaEuSxdhphYLwvQkSYz5dLvYE2ENjg@mail.gmail.com>

Hi all,

On Thu, Dec 6, 2012 at 5:03 PM, Mikel Astiz <mikel.astiz.oss@gmail.com> wrote:
> Hi all,
>
> It's been recently quite hard to test the audio part of BlueZ without
> having an updated PulseAudio which keeps up with the new D-Bus API in
> BlueZ.
>
> I've been doing some work to solve this and here you have the result:
> git://github.com/mastiz/pulseaudio-bluez5.git

I just updated the PulseAudio branch to test the BlueZ 5 API and the
patches for oFono. It's once again in:
git://github.com/mastiz/pulseaudio-bluez5.git branch bluez5-head

The main changes include the rebase on top of a more recent PA "next"
branch and some minor fixes. In addition, the feedback from Vinicious
has been integrated, affecting the PropertiesChanged signals from
oFono to PA.

> It's a big patchset on top of Tanu's next branch for PulseAudio. Only
> the last patches are related to BlueZ 5, and the rest should slowly
> get merged into PA master, in some way or another (first patches
> already submitted upstream).

Many of these patches are now merged in the "next" PA branch, so the
remaining patches are BlueZ 5-specific (except the first one).

> I warn you that it's not going to be stable in general, and in
> particular I haven't done any testing with oFono. So I'd expect quite
> a few issues.

For the first time, I got HFP working with BlueZ+oFono+PA. Still
unstable though.

On the other hand, A2DP is not working for me any more. I think this
might be an unrelated issue, probably a regression in BlueZ, but I
have to do further research.

> Consider this work-in-progress and note that it will get rebased
> periodically on top of Tanu's tree. If you have any feedback or code
> contributions, I'd suggest you contact me directly.

I will post the patches as RFC to PA mailing list once Tanu's "next"
branch gets merged into master.

Cheers,
Mikel

^ permalink raw reply

* [PATCH] Bluetooth: remove an unused variable in a header file.
From: Rami Rosen @ 2012-12-18  9:48 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: marcel, gustavo, johan.hedberg, Rami Rosen

This patch removes srej_queue_next from include/net/bluetooth/l2cap.h as it 
is not used.

Signed-off-by: Rami Rosen <ramirose@gmail.com>
---
 include/net/bluetooth/l2cap.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
index 7588ef4..cdd3302 100644
--- a/include/net/bluetooth/l2cap.h
+++ b/include/net/bluetooth/l2cap.h
@@ -496,7 +496,6 @@ struct l2cap_chan {
 	__u16		frames_sent;
 	__u16		unacked_frames;
 	__u8		retry_count;
-	__u16		srej_queue_next;
 	__u16		sdu_len;
 	struct sk_buff	*sdu;
 	struct sk_buff	*sdu_last_frag;
-- 
1.7.11.7

^ permalink raw reply related

* Re: [PATCH BlueZ] test: Update simple-agent to new API
From: Marcel Holtmann @ 2012-12-17 23:23 UTC (permalink / raw)
  To: João Paulo Rechi Vita; +Cc: linux-bluetooth
In-Reply-To: <1355784500-28062-1-git-send-email-jprvita@openbossa.org>

Hi Joao Paulo,

> The method org.bluez.Device.Pair() doesn't have arguments anymore. This
> commit fixes the following error:
> 
>   $ test/simple-agent hci0 4C:B1:99:F1:BC:E9
>   Agent registered
>   ERROR:dbus.connection:Unable to set arguments (u'/test/agent', u'Keybo
>   ardDisplay') according to signature '': <type 'exceptions.TypeError'>:
>    Fewer items found in D-Bus signature than in Python arguments
>   Traceback (most recent call last):
>     File "/usr/lib/python2.7/site-packages/dbus/connection.py", line 586
>   , in msg_reply_handler
>       reply_handler(*message.get_args_list(**get_args_opts))
>     File "/usr/lib/python2.7/site-packages/dbus/proxies.py", line 391, i
>   n _introspect_reply_handler
>       self._introspect_execute_queue()
>     File "/usr/lib/python2.7/site-packages/dbus/proxies.py", line 378, i
>   n _introspect_execute_queue
>       proxy_method(*args, **keywords)
>     File "/usr/lib/python2.7/site-packages/dbus/proxies.py", line 132, i
>   n __call__
>       **keywords)
>     File "/usr/lib/python2.7/site-packages/dbus/connection.py", line 566
>   , in call_async
>       message.append(signature=signature, *args)
>   TypeError: Fewer items found in D-Bus signature than in Python argumen
>   ts
> ---
>  test/simple-agent | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)

patch has been applied.

Regards

Marcel



^ permalink raw reply

* [PATCH BlueZ] test: Update simple-agent to new API
From: João Paulo Rechi Vita @ 2012-12-17 22:48 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: João Paulo Rechi Vita

The method org.bluez.Device.Pair() doesn't have arguments anymore. This
commit fixes the following error:

  $ test/simple-agent hci0 4C:B1:99:F1:BC:E9
  Agent registered
  ERROR:dbus.connection:Unable to set arguments (u'/test/agent', u'Keybo
  ardDisplay') according to signature '': <type 'exceptions.TypeError'>:
   Fewer items found in D-Bus signature than in Python arguments
  Traceback (most recent call last):
    File "/usr/lib/python2.7/site-packages/dbus/connection.py", line 586
  , in msg_reply_handler
      reply_handler(*message.get_args_list(**get_args_opts))
    File "/usr/lib/python2.7/site-packages/dbus/proxies.py", line 391, i
  n _introspect_reply_handler
      self._introspect_execute_queue()
    File "/usr/lib/python2.7/site-packages/dbus/proxies.py", line 378, i
  n _introspect_execute_queue
      proxy_method(*args, **keywords)
    File "/usr/lib/python2.7/site-packages/dbus/proxies.py", line 132, i
  n __call__
      **keywords)
    File "/usr/lib/python2.7/site-packages/dbus/connection.py", line 566
  , in call_async
      message.append(signature=signature, *args)
  TypeError: Fewer items found in D-Bus signature than in Python argumen
  ts
---
 test/simple-agent | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/test/simple-agent b/test/simple-agent
index deb6497..bb40eae 100755
--- a/test/simple-agent
+++ b/test/simple-agent
@@ -169,9 +169,7 @@ if __name__ == '__main__':
 						options.adapter_pattern)
 		dev_path = device.object_path
 		agent.set_exit_on_release(False)
-		device.Pair(path, capability, timeout=options.timeout,
-					reply_handler=pair_reply,
-					error_handler=pair_error)
+		device.Pair(reply_handler=pair_reply, error_handler=pair_error)
 		device_obj = device
 	else:
 		manager.RequestDefault()
-- 
1.7.11.7


^ permalink raw reply related

* Re: [PATCH BlueZ] hog: Fix removing HoG device bug
From: Andre Guedes @ 2012-12-17 20:20 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1355771003-2518-1-git-send-email-andre.guedes@openbossa.org>

Please ignore this patch. I'll do some code refactoring in HoG code
before fixing the bug.

On Mon, Dec 17, 2012 at 4:03 PM, Andre Guedes
<andre.guedes@openbossa.org> wrote:
> We should remove only hog_devices from the given btd_device.
> Otherwise, all hog_devices will be removed.
> ---
>  profiles/input/hog_device.c  | 5 +++++
>  profiles/input/hog_device.h  | 1 +
>  profiles/input/hog_manager.c | 5 ++++-
>  3 files changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/profiles/input/hog_device.c b/profiles/input/hog_device.c
> index 06dab6d..cc68080 100644
> --- a/profiles/input/hog_device.c
> +++ b/profiles/input/hog_device.c
> @@ -789,3 +789,8 @@ int hog_device_set_control_point(struct hog_device *hogdev, gboolean suspend)
>
>         return 0;
>  }
> +
> +struct btd_device *hog_device_get_device(struct hog_device *hogdev)
> +{
> +       return hogdev->device;
> +}
> diff --git a/profiles/input/hog_device.h b/profiles/input/hog_device.h
> index d1bfc08..60c4f12 100644
> --- a/profiles/input/hog_device.h
> +++ b/profiles/input/hog_device.h
> @@ -31,3 +31,4 @@ struct hog_device *hog_device_register(struct btd_device *device,
>                                                 struct gatt_primary *prim);
>  int hog_device_unregister(struct hog_device *hogdev);
>  int hog_device_set_control_point(struct hog_device *hogdev, gboolean suspend);
> +struct btd_device *hog_device_get_device(struct hog_device *hogdev);
> diff --git a/profiles/input/hog_manager.c b/profiles/input/hog_manager.c
> index 595b160..c7b98c5 100644
> --- a/profiles/input/hog_manager.c
> +++ b/profiles/input/hog_manager.c
> @@ -106,6 +106,9 @@ static int hog_device_probe(struct btd_profile *p, struct btd_device *device,
>
>  static void remove_device(gpointer hogdev, gpointer b)
>  {
> +       if (hog_device_get_device(hogdev) != b)
> +               return;
> +
>         devices = g_slist_remove(devices, hogdev);
>         hog_device_unregister(hogdev);
>  }
> @@ -116,7 +119,7 @@ static void hog_device_remove(struct btd_profile *p, struct btd_device *device)
>
>         DBG("path %s", path);
>
> -       g_slist_foreach(devices, remove_device, NULL);
> +       g_slist_foreach(devices, remove_device, device);
>  }
>
>  static struct btd_profile hog_profile = {
> --
> 1.8.0.1
>

^ permalink raw reply

* [PATCH BlueZ] hog: Fix removing HoG device bug
From: Andre Guedes @ 2012-12-17 19:03 UTC (permalink / raw)
  To: linux-bluetooth

We should remove only hog_devices from the given btd_device.
Otherwise, all hog_devices will be removed.
---
 profiles/input/hog_device.c  | 5 +++++
 profiles/input/hog_device.h  | 1 +
 profiles/input/hog_manager.c | 5 ++++-
 3 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/profiles/input/hog_device.c b/profiles/input/hog_device.c
index 06dab6d..cc68080 100644
--- a/profiles/input/hog_device.c
+++ b/profiles/input/hog_device.c
@@ -789,3 +789,8 @@ int hog_device_set_control_point(struct hog_device *hogdev, gboolean suspend)
 
 	return 0;
 }
+
+struct btd_device *hog_device_get_device(struct hog_device *hogdev)
+{
+	return hogdev->device;
+}
diff --git a/profiles/input/hog_device.h b/profiles/input/hog_device.h
index d1bfc08..60c4f12 100644
--- a/profiles/input/hog_device.h
+++ b/profiles/input/hog_device.h
@@ -31,3 +31,4 @@ struct hog_device *hog_device_register(struct btd_device *device,
 						struct gatt_primary *prim);
 int hog_device_unregister(struct hog_device *hogdev);
 int hog_device_set_control_point(struct hog_device *hogdev, gboolean suspend);
+struct btd_device *hog_device_get_device(struct hog_device *hogdev);
diff --git a/profiles/input/hog_manager.c b/profiles/input/hog_manager.c
index 595b160..c7b98c5 100644
--- a/profiles/input/hog_manager.c
+++ b/profiles/input/hog_manager.c
@@ -106,6 +106,9 @@ static int hog_device_probe(struct btd_profile *p, struct btd_device *device,
 
 static void remove_device(gpointer hogdev, gpointer b)
 {
+	if (hog_device_get_device(hogdev) != b)
+		return;
+
 	devices = g_slist_remove(devices, hogdev);
 	hog_device_unregister(hogdev);
 }
@@ -116,7 +119,7 @@ static void hog_device_remove(struct btd_profile *p, struct btd_device *device)
 
 	DBG("path %s", path);
 
-	g_slist_foreach(devices, remove_device, NULL);
+	g_slist_foreach(devices, remove_device, device);
 }
 
 static struct btd_profile hog_profile = {
-- 
1.8.0.1


^ permalink raw reply related

* Re: [PATCH BlueZ 3/5] core: Simplify set_powered to not use set_mode
From: Johan Hedberg @ 2012-12-17 18:30 UTC (permalink / raw)
  To: Anderson Lizardo; +Cc: Luiz Augusto von Dentz, linux-bluetooth
In-Reply-To: <CAJdJm_N+5_wcvGw7wkgx+Ryr3EkB-Mcd0hfGmK4u=42LL9=fHg@mail.gmail.com>

Hi Lizardo,

On Mon, Dec 17, 2012, Anderson Lizardo wrote:
> On Mon, Dec 17, 2012 at 11:45 AM, Luiz Augusto von Dentz
> <luiz.dentz@gmail.com> wrote:
> > -       err = set_mode(adapter, mode);
> > +       err = mgmt_set_powered(adapter->dev_id, powered);
> >         if (err < 0)
> >                 return g_dbus_pending_property_error(id,
> >                                                 ERROR_INTERFACE ".Failed",
> > -                                               strerror(-err));
> > +                                               strerror(err));
> 
> Looks like you changed the line above by mistake, err is negative and
> thus need to be made positive to pass to strerror().

Since I missed this one and already pushed the patch set I went ahead
and applied a separate fix for it.

Johan

^ permalink raw reply

* Re: [PATCH BlueZ 3/5] core: Simplify set_powered to not use set_mode
From: Anderson Lizardo @ 2012-12-17 15:55 UTC (permalink / raw)
  To: Luiz Augusto von Dentz; +Cc: linux-bluetooth
In-Reply-To: <1355759155-27921-3-git-send-email-luiz.dentz@gmail.com>

Hi Luiz,

On Mon, Dec 17, 2012 at 11:45 AM, Luiz Augusto von Dentz
<luiz.dentz@gmail.com> wrote:
> -       err = set_mode(adapter, mode);
> +       err = mgmt_set_powered(adapter->dev_id, powered);
>         if (err < 0)
>                 return g_dbus_pending_property_error(id,
>                                                 ERROR_INTERFACE ".Failed",
> -                                               strerror(-err));
> +                                               strerror(err));

Looks like you changed the line above by mistake, err is negative and
thus need to be made positive to pass to strerror().

Regards,
-- 
Anderson Lizardo
Instituto Nokia de Tecnologia - INdT
Manaus - Brazil

^ permalink raw reply

* Re: [PATCH 01/13] adapter: Add btd_adapter_for_each_device()
From: Johan Hedberg @ 2012-12-17 15:54 UTC (permalink / raw)
  To: Frédéric Danis; +Cc: linux-bluetooth
In-Reply-To: <1355756994-18953-1-git-send-email-frederic.danis@linux.intel.com>

Hi Frédéric,

On Mon, Dec 17, 2012, Frédéric Danis wrote:
> ---
>  src/adapter.c |    7 +++++++
>  src/adapter.h |    4 ++++
>  2 files changed, 11 insertions(+)

All patches in this set have been applied. Thanks.

Johan

^ permalink raw reply

* Re: [PATCH BlueZ 1/5] core: Fix set_pairable to not attempt to power on the adapter
From: Johan Hedberg @ 2012-12-17 15:51 UTC (permalink / raw)
  To: Luiz Augusto von Dentz; +Cc: linux-bluetooth
In-Reply-To: <1355759155-27921-1-git-send-email-luiz.dentz@gmail.com>

Hi Luiz,

On Mon, Dec 17, 2012, Luiz Augusto von Dentz wrote:
> Pairable flag is completely independent flag for the kernel so we can
> reflect this in the D-Bus API.
> ---
>  src/adapter.c | 20 --------------------
>  1 file changed, 20 deletions(-)

All five patches have been applied. Thanks.

Johan

^ permalink raw reply

* [PATCH BlueZ 5/5] core: Fix emitting changes to properties on power off
From: Luiz Augusto von Dentz @ 2012-12-17 15:45 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1355759155-27921-1-git-send-email-luiz.dentz@gmail.com>

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Discoverable and pairable are independent to the powered state so they
should not be changed just because the controller power state is set to
off.
---
 src/adapter.c | 15 ---------------
 1 file changed, 15 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index b15c8b7..5fe3010 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -1688,7 +1688,6 @@ static void unload_drivers(struct btd_adapter *adapter)
 int btd_adapter_stop(struct btd_adapter *adapter)
 {
 	DBusConnection *conn = btd_get_dbus_connection();
-	bool emit_discoverable = false, emit_pairable = false;
 	bool emit_discovering = false;
 
 	/* check pending requests */
@@ -1711,24 +1710,10 @@ int btd_adapter_stop(struct btd_adapter *adapter)
 		adapter_remove_connection(adapter, device);
 	}
 
-	if (adapter->discoverable)
-		emit_discoverable = true;
-
-	if (adapter->connectable && adapter->pairable == TRUE)
-		emit_pairable = true;
-
-	adapter->discoverable = FALSE;
 	adapter->connectable = false;
 
 	adapter->off_requested = FALSE;
 
-	if (emit_discoverable)
-		g_dbus_emit_property_changed(conn, adapter->path,
-					ADAPTER_INTERFACE, "Discoverable");
-	if (emit_pairable)
-		g_dbus_emit_property_changed(conn, adapter->path,
-					ADAPTER_INTERFACE, "Pairable");
-
 	if (emit_discovering)
 		g_dbus_emit_property_changed(conn, adapter->path,
 					ADAPTER_INTERFACE, "Discovering");
-- 
1.7.11.7


^ permalink raw reply related

* [PATCH BlueZ 4/5] core: Remove mode session code
From: Luiz Augusto von Dentz @ 2012-12-17 15:45 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1355759155-27921-1-git-send-email-luiz.dentz@gmail.com>

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Mode session no longer are needed since RequestSession is gone
---
 src/adapter.c | 210 +++++-----------------------------------------------------
 1 file changed, 15 insertions(+), 195 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 2d81f66..b15c8b7 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -89,8 +89,6 @@ static const char *base_path = "/org/bluez";
 static GSList *adapter_drivers = NULL;
 
 enum session_req_type {
-	SESSION_TYPE_MODE_GLOBAL = 0,
-	SESSION_TYPE_MODE_SESSION,
 	SESSION_TYPE_DISC_INTERLEAVED,
 	SESSION_TYPE_DISC_LE_SCAN
 };
@@ -99,10 +97,8 @@ struct session_req {
 	struct btd_adapter	*adapter;
 	enum session_req_type	type;
 	DBusMessage		*msg;		/* Unreplied message ref */
-	GDBusPendingPropertySet prop_id;	/* Pending Properties.Set() */
 	char			*owner;		/* Bus name of the owner */
 	guint			id;		/* Listener id */
-	uint8_t			mode;		/* Requested mode */
 	int			refcount;	/* Session refcount */
 	gboolean		got_reply;	/* Agent reply received */
 };
@@ -135,16 +131,12 @@ struct btd_adapter {
 	uint32_t discov_timeout;	/* discoverable time(sec) */
 	guint pairable_timeout_id;	/* pairable timeout id */
 	uint32_t pairable_timeout;	/* pairable time(sec) */
-	uint8_t mode;			/* off, connectable, discoverable,
-					 * limited */
-	uint8_t global_mode;		/* last valid global mode */
 	struct session_req *pending_mode;
 	guint auth_idle_id;		/* Pending authorization dequeue */
 	GQueue *auths;			/* Ongoing and pending auths */
 	GSList *connections;		/* Connected devices */
 	GSList *devices;		/* Devices structure pointers */
 	guint	remove_temp;		/* Remove devices timer */
-	GSList *mode_sessions;		/* Request Mode sessions */
 	GSList *disc_sessions;		/* Discovery sessions */
 	struct session_req *scanning_session;
 	GSList *connect_list;		/* Devices to connect when found */
@@ -181,20 +173,6 @@ int btd_adapter_set_class(struct btd_adapter *adapter, uint8_t major,
 	return mgmt_set_dev_class(adapter->dev_id, major, minor);
 }
 
-static const char *mode2str(uint8_t mode)
-{
-	switch(mode) {
-	case MODE_OFF:
-		return "off";
-	case MODE_CONNECTABLE:
-		return "connectable";
-	case MODE_DISCOVERABLE:
-		return "discoverable";
-	default:
-		return "unknown";
-	}
-}
-
 static uint8_t get_mode(const char *mode)
 {
 	if (strcasecmp("off", mode) == 0)
@@ -288,16 +266,15 @@ static struct session_req *session_ref(struct session_req *req)
 }
 
 static struct session_req *create_session(struct btd_adapter *adapter,
-					DBusMessage *msg, uint8_t mode,
-					enum session_req_type type,
-					GDBusWatchFunction cb)
+						DBusMessage *msg,
+						enum session_req_type type,
+						GDBusWatchFunction cb)
 {
 	const char *sender;
 	struct session_req *req;
 
 	req = g_new0(struct session_req, 1);
 	req->adapter = adapter;
-	req->mode = mode;
 	req->type = type;
 
 	if (msg == NULL)
@@ -313,56 +290,11 @@ static struct session_req *create_session(struct btd_adapter *adapter,
 	req->id = g_dbus_add_disconnect_watch(btd_get_dbus_connection(),
 							sender, cb, req, NULL);
 
-	info("%s session %p with %s activated",
-		req->mode ? "Mode" : "Discovery", req, sender);
+	info("session %p with %s activated", req, sender);
 
 	return session_ref(req);
 }
 
-static int set_mode(struct btd_adapter *adapter, uint8_t new_mode)
-{
-	int err;
-
-	if (adapter->pending_mode != NULL)
-		return -EALREADY;
-
-	if (!adapter->powered && new_mode != MODE_OFF) {
-		err = mgmt_set_powered(adapter->dev_id, TRUE);
-		if (err < 0)
-			return err;
-
-		goto done;
-	}
-
-	if (adapter->powered && new_mode == MODE_OFF) {
-		err = mgmt_set_powered(adapter->dev_id, FALSE);
-		if (err < 0)
-			return err;
-
-		adapter->off_requested = TRUE;
-
-		goto done;
-	}
-
-	if (new_mode == adapter->mode)
-		return 0;
-
-	if (new_mode == MODE_CONNECTABLE)
-		err = mgmt_set_discoverable(adapter->dev_id, FALSE, 0);
-	else
-		err = mgmt_set_discoverable(adapter->dev_id, TRUE,
-						adapter->discov_timeout);
-	if (err < 0)
-		return err;
-
-done:
-	store_adapter_info(adapter);
-
-	DBG("%s", mode2str(new_mode));
-
-	return 0;
-}
-
 static void set_discoverable(struct btd_adapter *adapter,
 			gboolean discoverable, GDBusPendingPropertySet id)
 {
@@ -386,6 +318,8 @@ static void set_powered(struct btd_adapter *adapter, gboolean powered,
 
 	if (powered == FALSE)
 		adapter->off_requested = TRUE;
+
+	g_dbus_pending_property_success(id);
 }
 
 static void set_pairable(struct btd_adapter *adapter, gboolean pairable,
@@ -453,23 +387,6 @@ static struct session_req *find_session(GSList *list, const char *sender)
 	return NULL;
 }
 
-static uint8_t get_needed_mode(struct btd_adapter *adapter, uint8_t mode)
-{
-	GSList *l;
-
-	if (adapter->global_mode > mode)
-		mode = adapter->global_mode;
-
-	for (l = adapter->mode_sessions; l; l = l->next) {
-		struct session_req *req = l->data;
-
-		if (req->mode > mode)
-			mode = req->mode;
-	}
-
-	return mode;
-}
-
 static void send_devices_found(struct btd_adapter *adapter)
 {
 	struct discovery *discovery = adapter->discovery;
@@ -565,38 +482,16 @@ static void session_remove(struct session_req *req)
 {
 	struct btd_adapter *adapter = req->adapter;
 
-	/* Ignore global requests */
-	if (req->type == SESSION_TYPE_MODE_GLOBAL)
-		return;
-
-	DBG("%s session %p with %s deactivated",
-		req->mode ? "Mode" : "Discovery", req, req->owner);
-
-	if (req->mode) {
-		uint8_t mode;
+	DBG("session %p with %s deactivated", req, req->owner);
 
-		adapter->mode_sessions = g_slist_remove(adapter->mode_sessions,
-							req);
+	adapter->disc_sessions = g_slist_remove(adapter->disc_sessions, req);
 
-		mode = get_needed_mode(adapter, adapter->global_mode);
-
-		if (mode == adapter->mode)
-			return;
-
-		DBG("Switching to '%s' mode", mode2str(mode));
-
-		set_mode(adapter, mode);
-	} else {
-		adapter->disc_sessions = g_slist_remove(adapter->disc_sessions,
-							req);
-
-		if (adapter->disc_sessions)
-			return;
+	if (adapter->disc_sessions)
+		return;
 
-		DBG("Stopping discovery");
+	DBG("Stopping discovery");
 
-		stop_discovery(adapter);
-	}
+	stop_discovery(adapter);
 }
 
 static void session_free(void *data)
@@ -1000,7 +895,7 @@ static DBusMessage *adapter_start_discovery(DBusConnection *conn,
 		return btd_error_failed(msg, strerror(-err));
 
 done:
-	req = create_session(adapter, msg, 0, SESSION_TYPE_DISC_INTERLEAVED,
+	req = create_session(adapter, msg, SESSION_TYPE_DISC_INTERLEAVED,
 							session_owner_exit);
 
 	adapter->disc_sessions = g_slist_append(adapter->disc_sessions, req);
@@ -1701,8 +1596,7 @@ void adapter_connect_list_add(struct btd_adapter *adapter,
 	if (adapter->disc_sessions == NULL)
 		adapter->discov_id = g_idle_add(discovery_cb, adapter);
 
-	req = create_session(adapter, NULL, 0, SESSION_TYPE_DISC_LE_SCAN,
-									NULL);
+	req = create_session(adapter, NULL, SESSION_TYPE_DISC_LE_SCAN, NULL);
 	adapter->disc_sessions = g_slist_append(adapter->disc_sessions, req);
 	adapter->scanning_session = req;
 }
@@ -1738,8 +1632,7 @@ void btd_adapter_start(struct btd_adapter *adapter)
 					adapter->disc_sessions != NULL)
 		return;
 
-	req = create_session(adapter, NULL, 0, SESSION_TYPE_DISC_LE_SCAN,
-									NULL);
+	req = create_session(adapter, NULL, SESSION_TYPE_DISC_LE_SCAN, NULL);
 	adapter->disc_sessions = g_slist_append(adapter->disc_sessions, req);
 	adapter->scanning_session = req;
 
@@ -1792,57 +1685,6 @@ static void unload_drivers(struct btd_adapter *adapter)
 	adapter->profiles = NULL;
 }
 
-static void set_mode_complete(struct btd_adapter *adapter)
-{
-	DBusConnection *conn = btd_get_dbus_connection();
-	struct session_req *pending;
-	int err;
-
-	DBG("%s", mode2str(adapter->mode));
-
-	if (adapter->mode == MODE_OFF) {
-		g_slist_free_full(adapter->mode_sessions, session_free);
-		adapter->mode_sessions = NULL;
-	}
-
-	if (adapter->pending_mode == NULL)
-		return;
-
-	pending = adapter->pending_mode;
-	adapter->pending_mode = NULL;
-
-	err = (pending->mode != adapter->mode) ? -EINVAL : 0;
-
-	if (pending->type == SESSION_TYPE_MODE_GLOBAL) {
-		if (err < 0)
-			g_dbus_pending_property_error(pending->prop_id,
-						ERROR_INTERFACE ".Failed",
-						strerror(-err));
-		else {
-			adapter->global_mode = adapter->mode;
-			g_dbus_pending_property_success(pending->prop_id);
-		}
-	} else if (pending->msg != NULL) {
-		DBusMessage *msg = pending->msg;
-		DBusMessage *reply;
-
-		if (err < 0)
-			reply = btd_error_failed(msg, strerror(-err));
-		else
-			reply = g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
-
-		g_dbus_send_message(conn, reply);
-	}
-
-	if (err != 0)
-		error("unable to set mode: %s", mode2str(pending->mode));
-
-	if (adapter->mode != MODE_DISCOVERABLE || adapter->discov_timeout == 0)
-		store_adapter_info(adapter);
-
-	session_unref(pending);
-}
-
 int btd_adapter_stop(struct btd_adapter *adapter)
 {
 	DBusConnection *conn = btd_get_dbus_connection();
@@ -1878,7 +1720,6 @@ int btd_adapter_stop(struct btd_adapter *adapter)
 	adapter->discoverable = FALSE;
 	adapter->connectable = false;
 
-	adapter->mode = MODE_OFF;
 	adapter->off_requested = FALSE;
 
 	if (emit_discoverable)
@@ -1897,8 +1738,6 @@ int btd_adapter_stop(struct btd_adapter *adapter)
 
 	info("Adapter %s has been disabled", adapter->path);
 
-	set_mode_complete(adapter);
-
 	return 0;
 }
 
@@ -2710,8 +2549,6 @@ static void load_config(struct btd_adapter *adapter)
 		gerr = NULL;
 	}
 
-	adapter->mode = MODE_OFF;
-
 	mgmt_set_connectable(adapter->dev_id, TRUE);
 	mgmt_set_discoverable(adapter->dev_id, adapter->discoverable,
 				adapter->discov_timeout);
@@ -3089,17 +2926,6 @@ void adapter_update_found_devices(struct btd_adapter *adapter,
 	}
 }
 
-static uint8_t create_mode(bool connectable, bool discoverable)
-{
-	if (connectable && discoverable)
-		return MODE_DISCOVERABLE;
-
-	if (connectable && !discoverable)
-		return MODE_CONNECTABLE;
-
-	return MODE_OFF;
-}
-
 void adapter_mode_changed(struct btd_adapter *adapter, bool connectable,
 							bool discoverable)
 {
@@ -3118,7 +2944,6 @@ void adapter_mode_changed(struct btd_adapter *adapter, bool connectable,
 
 	adapter->connectable = connectable;
 	adapter->discoverable = discoverable;
-	adapter->mode = create_mode(connectable, discoverable);
 
 	if (emit_pairable)
 		g_dbus_emit_property_changed(btd_get_dbus_connection(),
@@ -3126,8 +2951,6 @@ void adapter_mode_changed(struct btd_adapter *adapter, bool connectable,
 
 	g_dbus_emit_property_changed(btd_get_dbus_connection(), adapter->path,
 					ADAPTER_INTERFACE, "Discoverable");
-
-	set_mode_complete(adapter);
 }
 
 struct agent *adapter_get_agent(struct btd_adapter *adapter)
@@ -3385,9 +3208,6 @@ int btd_adapter_restore_powered(struct btd_adapter *adapter)
 	if (adapter->powered)
 		return 0;
 
-	if (adapter->mode == MODE_OFF)
-		return 0;
-
 	return mgmt_set_powered(adapter->dev_id, TRUE);
 }
 
-- 
1.7.11.7


^ permalink raw reply related


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox