Linux bluetooth development
 help / color / mirror / Atom feed
* [RFC v1 08/16] manager: Expose default adapter using property
From: Mikel Astiz @ 2012-11-15 15:09 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Mikel Astiz
In-Reply-To: <1352992159-11559-1-git-send-email-mikel.astiz.oss@gmail.com>

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

Replace previous method in the Manager interface with a property. If no
default adapter exists, the property will not be present.
---
 doc/manager-api.txt | 20 +++------------
 src/manager.c       | 71 +++++++++++++++++++++++------------------------------
 2 files changed, 35 insertions(+), 56 deletions(-)

diff --git a/doc/manager-api.txt b/doc/manager-api.txt
index cf3284a..b89ab68 100644
--- a/doc/manager-api.txt
+++ b/doc/manager-api.txt
@@ -14,13 +14,6 @@ Service		org.bluez
 Interface	org.bluez.Manager
 Object path	/org/bluez
 
-		object DefaultAdapter()
-
-			Returns object path for the default adapter.
-
-			Possible errors: org.bluez.Error.InvalidArguments
-					 org.bluez.Error.NoSuchAdapter
-
 		object FindAdapter(string pattern)
 
 			Returns object path for the specified adapter. Valid
@@ -40,15 +33,10 @@ Signals		AdapterAdded(object adapter)
 
 			Parameter is object path of removed adapter.
 
-		DefaultAdapterChanged(object adapter)
-
-			Parameter is object path of the new default adapter.
-
-			In case all adapters are removed this signal will not
-			be emitted. The AdapterRemoved signal has to be used
-			to detect that no default adapter is selected or
-			available anymore.
-
 Properties	array{object} Adapters [readonly]
 
 			List of adapter object paths.
+
+		object DefaultAdapter [readonly, optional]
+
+			Object path for the default adapter, if any.
diff --git a/src/manager.c b/src/manager.c
index d6e7b80..08d6625 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -64,29 +64,6 @@ const char *manager_get_base_path(void)
 	return base_path;
 }
 
-static DBusMessage *default_adapter(DBusConnection *conn,
-					DBusMessage *msg, void *data)
-{
-	DBusMessage *reply;
-	struct btd_adapter *adapter;
-	const gchar *path;
-
-	adapter = manager_find_adapter_by_id(default_adapter_id);
-	if (!adapter)
-		return btd_error_no_such_adapter(msg);
-
-	reply = dbus_message_new_method_return(msg);
-	if (!reply)
-		return NULL;
-
-	path = adapter_get_path(adapter);
-
-	dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &path,
-				DBUS_TYPE_INVALID);
-
-	return reply;
-}
-
 static DBusMessage *find_adapter(DBusConnection *conn,
 					DBusMessage *msg, void *data)
 {
@@ -157,10 +134,32 @@ static gboolean manager_property_get_adapters(
 	return TRUE;
 }
 
+static gboolean manager_property_get_default_adapter(
+					const GDBusPropertyTable *property,
+					DBusMessageIter *iter, void *data)
+{
+	struct btd_adapter *adapter;
+	const char *path;
+
+	adapter = manager_find_adapter_by_id(default_adapter_id);
+	path = adapter_get_path(adapter);
+
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH, &path);
+
+	return TRUE;
+}
+
+static gboolean manager_property_exists_default_adapter(
+					const GDBusPropertyTable *property,
+					void *data)
+{
+	if (manager_find_adapter_by_id(default_adapter_id) == NULL)
+		return FALSE;
+	else
+		return TRUE;
+}
+
 static const GDBusMethodTable manager_methods[] = {
-	{ GDBUS_METHOD("DefaultAdapter",
-			NULL, GDBUS_ARGS({ "adapter", "o" }),
-			default_adapter) },
 	{ GDBUS_METHOD("FindAdapter",
 			GDBUS_ARGS({ "pattern", "s" }),
 			GDBUS_ARGS({ "adapter", "o" }),
@@ -173,13 +172,13 @@ static const GDBusSignalTable manager_signals[] = {
 			GDBUS_ARGS({ "adapter", "o" })) },
 	{ GDBUS_SIGNAL("AdapterRemoved",
 			GDBUS_ARGS({ "adapter", "o" })) },
-	{ GDBUS_SIGNAL("DefaultAdapterChanged",
-			GDBUS_ARGS({ "adapter", "o" })) },
 	{ }
 };
 
 static const GDBusPropertyTable manager_properties[] = {
 	{ "Adapters", "ao", manager_property_get_adapters },
+	{ "DefaultAdapter", "o", manager_property_get_default_adapter, NULL,
+				manager_property_exists_default_adapter },
 	{ }
 };
 
@@ -198,21 +197,13 @@ bool manager_init(const char *path)
 
 static void manager_set_default_adapter(int id)
 {
-	struct btd_adapter *adapter;
-	const gchar *path;
-
-	default_adapter_id = id;
-
-	adapter = manager_find_adapter_by_id(id);
-	if (!adapter)
+	if (id == default_adapter_id)
 		return;
 
-	path = adapter_get_path(adapter);
+	default_adapter_id = id;
 
-	g_dbus_emit_signal(btd_get_dbus_connection(), base_path,
-				MANAGER_INTERFACE, "DefaultAdapterChanged",
-				DBUS_TYPE_OBJECT_PATH, &path,
-				DBUS_TYPE_INVALID);
+	g_dbus_emit_property_changed(btd_get_dbus_connection(), base_path,
+					MANAGER_INTERFACE, "DefaultAdapter");
 }
 
 struct btd_adapter *manager_get_default_adapter(void)
-- 
1.7.11.7


^ permalink raw reply related

* [RFC v1 09/16] test: Update test-manager script to ObjectManager
From: Mikel Astiz @ 2012-11-15 15:09 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Mikel Astiz
In-Reply-To: <1352992159-11559-1-git-send-email-mikel.astiz.oss@gmail.com>

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

Make the script compatible with the new API provided by the
ObjectManager and Properties interfaces.
---
 test/test-manager | 33 +++++++++++++++++++++++----------
 1 file changed, 23 insertions(+), 10 deletions(-)

diff --git a/test/test-manager b/test/test-manager
index 2a9c1e9..e35db83 100755
--- a/test/test-manager
+++ b/test/test-manager
@@ -7,14 +7,20 @@ from gi.repository import GObject
 import dbus
 import dbus.mainloop.glib
 
-def adapter_added(path):
-	print("Adapter with path %s added" % (path))
+def property_changed(interface, changed, invalidated, path):
+	if interface != "org.bluez.Manager":
+		return
+	path = changed.get("DefaultAdapter")
+	if path != None:
+		print("Default adapter is now at path %s" % (path))
 
-def adapter_removed(path):
-	print("Adapter with path %s removed" % (path))
+def interfaces_added(path, interfaces):
+	if interfaces.get("org.bluez.Adapter") != None:
+		print("Adapter with path %s added" % (path))
 
-def default_changed(path):
-	print("Default adapter is now at path %s" % (path))
+def interfaces_removed(path, interfaces):
+	if "org.bluez.Adapter" in interfaces:
+		print("Adapter with path %s removed" % (path))
 
 if __name__ == "__main__":
 	dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
@@ -24,15 +30,22 @@ if __name__ == "__main__":
 	manager = dbus.Interface(bus.get_object('org.bluez', '/org/bluez'),
 							'org.bluez.Manager')
 
-	manager.connect_to_signal("AdapterAdded", adapter_added)
+	bus.add_signal_receiver(property_changed, bus_name="org.bluez",
+			dbus_interface="org.freedesktop.DBus.Properties",
+			signal_name="PropertiesChanged",
+			path_keyword="path")
 
-	manager.connect_to_signal("AdapterRemoved", adapter_removed)
+	bus.add_signal_receiver(interfaces_added, bus_name="org.bluez",
+			dbus_interface="org.freedesktop.DBus.ObjectManager",
+			signal_name="InterfacesAdded")
 
-	manager.connect_to_signal("DefaultAdapterChanged", default_changed)
+	bus.add_signal_receiver(interfaces_removed, bus_name="org.bluez",
+			dbus_interface="org.freedesktop.DBus.ObjectManager",
+			signal_name="InterfacesRemoved")
 
 	try:
 		path = manager.FindAdapter("default")
-		default_changed(path)
+		print("Default adapter is now at path %s" % (path))
 	except:
 		pass
 
-- 
1.7.11.7


^ permalink raw reply related

* [RFC v1 10/16] manager: Remove AdapterAdded/AdapterRemoved signals
From: Mikel Astiz @ 2012-11-15 15:09 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Mikel Astiz
In-Reply-To: <1352992159-11559-1-git-send-email-mikel.astiz.oss@gmail.com>

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

The Manager interface already reports changes in the adapter list in
form of property changes, so there is no need to keep these two signals
any more.
---
 doc/manager-api.txt |  8 --------
 src/manager.c       | 20 +-------------------
 2 files changed, 1 insertion(+), 27 deletions(-)

diff --git a/doc/manager-api.txt b/doc/manager-api.txt
index b89ab68..693a981 100644
--- a/doc/manager-api.txt
+++ b/doc/manager-api.txt
@@ -25,14 +25,6 @@ Object path	/org/bluez
 			Possible errors: org.bluez.Error.InvalidArguments
 					 org.bluez.Error.NoSuchAdapter
 
-Signals		AdapterAdded(object adapter)
-
-			Parameter is object path of added adapter.
-
-		AdapterRemoved(object adapter)
-
-			Parameter is object path of removed adapter.
-
 Properties	array{object} Adapters [readonly]
 
 			List of adapter object paths.
diff --git a/src/manager.c b/src/manager.c
index 08d6625..954ab8a 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -167,14 +167,6 @@ static const GDBusMethodTable manager_methods[] = {
 	{ }
 };
 
-static const GDBusSignalTable manager_signals[] = {
-	{ GDBUS_SIGNAL("AdapterAdded",
-			GDBUS_ARGS({ "adapter", "o" })) },
-	{ GDBUS_SIGNAL("AdapterRemoved",
-			GDBUS_ARGS({ "adapter", "o" })) },
-	{ }
-};
-
 static const GDBusPropertyTable manager_properties[] = {
 	{ "Adapters", "ao", manager_property_get_adapters },
 	{ "DefaultAdapter", "o", manager_property_get_default_adapter, NULL,
@@ -186,7 +178,7 @@ bool manager_init(const char *path)
 {
 	if (!g_dbus_register_interface(btd_get_dbus_connection(),
 					base_path, MANAGER_INTERFACE,
-					manager_methods, manager_signals,
+					manager_methods, NULL,
 					manager_properties, NULL, NULL))
 		return false;
 
@@ -214,7 +206,6 @@ struct btd_adapter *manager_get_default_adapter(void)
 static void manager_remove_adapter(struct btd_adapter *adapter)
 {
 	uint16_t dev_id = adapter_get_dev_id(adapter);
-	const gchar *path = adapter_get_path(adapter);
 
 	adapters = g_slist_remove(adapters, adapter);
 
@@ -227,11 +218,6 @@ static void manager_remove_adapter(struct btd_adapter *adapter)
 		manager_set_default_adapter(new_default);
 	}
 
-	g_dbus_emit_signal(btd_get_dbus_connection(), base_path,
-				MANAGER_INTERFACE, "AdapterRemoved",
-				DBUS_TYPE_OBJECT_PATH, &path,
-				DBUS_TYPE_INVALID);
-
 	adapter_remove(adapter);
 	btd_adapter_unref(adapter);
 
@@ -331,10 +317,6 @@ struct btd_adapter *btd_manager_register_adapter(int id, gboolean up)
 	}
 
 	path = adapter_get_path(adapter);
-	g_dbus_emit_signal(btd_get_dbus_connection(), base_path,
-				MANAGER_INTERFACE, "AdapterAdded",
-				DBUS_TYPE_OBJECT_PATH, &path,
-				DBUS_TYPE_INVALID);
 
 	g_dbus_emit_property_changed(btd_get_dbus_connection(),  base_path,
 					MANAGER_INTERFACE, "Adapters");
-- 
1.7.11.7


^ permalink raw reply related

* [RFC v1 11/16] manager: Remove redundant Adapters property
From: Mikel Astiz @ 2012-11-15 15:09 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Mikel Astiz
In-Reply-To: <1352992159-11559-1-git-send-email-mikel.astiz.oss@gmail.com>

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

The ObjectManager interface already reports the available adapters, so
the property can be entirely removed.
---
 doc/manager-api.txt |  6 +-----
 src/manager.c       | 30 ------------------------------
 2 files changed, 1 insertion(+), 35 deletions(-)

diff --git a/doc/manager-api.txt b/doc/manager-api.txt
index 693a981..a8f570b 100644
--- a/doc/manager-api.txt
+++ b/doc/manager-api.txt
@@ -25,10 +25,6 @@ Object path	/org/bluez
 			Possible errors: org.bluez.Error.InvalidArguments
 					 org.bluez.Error.NoSuchAdapter
 
-Properties	array{object} Adapters [readonly]
-
-			List of adapter object paths.
-
-		object DefaultAdapter [readonly, optional]
+Properties	object DefaultAdapter [readonly, optional]
 
 			Object path for the default adapter, if any.
diff --git a/src/manager.c b/src/manager.c
index 954ab8a..d861031 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -111,29 +111,6 @@ done:
 	return reply;
 }
 
-static gboolean manager_property_get_adapters(
-					const GDBusPropertyTable *property,
-					DBusMessageIter *iter, void *data)
-{
-	DBusMessageIter entry;
-	GSList *l;
-
-	dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
-				DBUS_TYPE_OBJECT_PATH_AS_STRING, &entry);
-
-	for (l = adapters; l != NULL; l = l->next) {
-		struct btd_adapter *adapter = l->data;
-		const char *path = adapter_get_path(adapter);
-
-		dbus_message_iter_append_basic(&entry, DBUS_TYPE_OBJECT_PATH,
-								&path);
-	}
-
-	dbus_message_iter_close_container(iter, &entry);
-
-	return TRUE;
-}
-
 static gboolean manager_property_get_default_adapter(
 					const GDBusPropertyTable *property,
 					DBusMessageIter *iter, void *data)
@@ -168,7 +145,6 @@ static const GDBusMethodTable manager_methods[] = {
 };
 
 static const GDBusPropertyTable manager_properties[] = {
-	{ "Adapters", "ao", manager_property_get_adapters },
 	{ "DefaultAdapter", "o", manager_property_get_default_adapter, NULL,
 				manager_property_exists_default_adapter },
 	{ }
@@ -209,9 +185,6 @@ static void manager_remove_adapter(struct btd_adapter *adapter)
 
 	adapters = g_slist_remove(adapters, adapter);
 
-	g_dbus_emit_property_changed(btd_get_dbus_connection(), base_path,
-					MANAGER_INTERFACE, "Adapters");
-
 	if (default_adapter_id == dev_id || default_adapter_id < 0) {
 		int new_default = hci_get_route(NULL);
 
@@ -318,9 +291,6 @@ struct btd_adapter *btd_manager_register_adapter(int id, gboolean up)
 
 	path = adapter_get_path(adapter);
 
-	g_dbus_emit_property_changed(btd_get_dbus_connection(),  base_path,
-					MANAGER_INTERFACE, "Adapters");
-
 	btd_stop_exit_timer();
 
 	if (default_adapter_id < 0)
-- 
1.7.11.7


^ permalink raw reply related

* [RFC v1 12/16] test: Use ObjectManager instead of Adapters property
From: Mikel Astiz @ 2012-11-15 15:09 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Mikel Astiz
In-Reply-To: <1352992159-11559-1-git-send-email-mikel.astiz.oss@gmail.com>

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

Use the objects and interfaces reported by the ObjectManager in order
to list the available adapters.
---
 test/test-health      | 11 ++++++++---
 test/test-health-sink | 12 +++++++++---
 2 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/test/test-health b/test/test-health
index 21d1776..9d2f62f 100755
--- a/test/test-health
+++ b/test/test-health
@@ -131,10 +131,15 @@ if not con:
 	enter_mainloop()
 	sys.exit()
 
-manager = dbus.Interface(bus.get_object("org.bluez", "/org/bluez"),
-						"org.bluez.Manager")
+manager = dbus.Interface(bus.get_object("org.bluez", "/"),
+					"org.freedesktop.DBus.ObjectManager")
 
-adapters = manager.GetProperties()["Adapters"]
+objects = manager.GetManagedObjects()
+adapters = []
+
+for path, ifaces in objects.iteritems():
+	if ifaces.has_key("org.bluez.Adapter"):
+		adapters.append(path)
 
 i = 1
 for ad in adapters:
diff --git a/test/test-health-sink b/test/test-health-sink
index 7bf1af4..a886d85 100755
--- a/test/test-health-sink
+++ b/test/test-health-sink
@@ -21,10 +21,16 @@ app_path = hdp_manager.CreateApplication({"DataType": dbus.types.UInt16(4103),
 
 print(app_path)
 
-manager = dbus.Interface(bus.get_object("org.bluez", "/org/bluez"),
-						"org.bluez.Manager")
+manager = dbus.Interface(bus.get_object("org.bluez", "/"),
+					"org.freedesktop.DBus.ObjectManager")
+
+objects = manager.GetManagedObjects()
+adapters = []
+
+for path, ifaces in objects.iteritems():
+	if ifaces.has_key("org.bluez.Adapter"):
+		adapters.append(path)
 
-adapters = manager.GetProperties()["Adapters"]
 i = 1
 for ad in adapters:
 	print("%d. %s" % (i, ad))
-- 
1.7.11.7


^ permalink raw reply related

* [RFC v1 13/16] adapter: Remove DeviceCreated/DeviceRemoved signals
From: Mikel Astiz @ 2012-11-15 15:09 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Mikel Astiz
In-Reply-To: <1352992159-11559-1-git-send-email-mikel.astiz.oss@gmail.com>

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

The Adapter interface already reports changes in the device list in form
of property changes, so there is no need to keep these two signals.
---
 doc/adapter-api.txt |  8 --------
 src/adapter.c       | 17 -----------------
 2 files changed, 25 deletions(-)

diff --git a/doc/adapter-api.txt b/doc/adapter-api.txt
index b638586..132e60f 100644
--- a/doc/adapter-api.txt
+++ b/doc/adapter-api.txt
@@ -116,14 +116,6 @@ Signals		DevicesFound(array{object path, dict values})
 			The dictionary contains the properties from the
 			org.bluez.Device interface.
 
-		DeviceCreated(object device)
-
-			Parameter is object path of created device.
-
-		DeviceRemoved(object device)
-
-			Parameter is object path of removed device.
-
 Properties	string Address [readonly]
 
 			The Bluetooth device address.
diff --git a/src/adapter.c b/src/adapter.c
index ea2d2ad..aa93785 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -1007,7 +1007,6 @@ static struct btd_device *adapter_create_device(struct btd_adapter *adapter,
 						uint8_t bdaddr_type)
 {
 	struct btd_device *device;
-	const char *path;
 
 	DBG("%s", address);
 
@@ -1019,12 +1018,6 @@ static struct btd_device *adapter_create_device(struct btd_adapter *adapter,
 
 	adapter->devices = g_slist_append(adapter->devices, device);
 
-	path = device_get_path(device);
-	g_dbus_emit_signal(btd_get_dbus_connection(), adapter->path,
-			ADAPTER_INTERFACE, "DeviceCreated",
-			DBUS_TYPE_OBJECT_PATH, &path,
-			DBUS_TYPE_INVALID);
-
 	g_dbus_emit_property_changed(btd_get_dbus_connection(),
 				adapter->path, ADAPTER_INTERFACE, "Devices");
 
@@ -1052,7 +1045,6 @@ void adapter_remove_device(struct btd_adapter *adapter,
 						struct btd_device *dev,
 						gboolean remove_storage)
 {
-	const gchar *dev_path = device_get_path(dev);
 	struct discovery *discovery = adapter->discovery;
 	GList *l;
 
@@ -1084,11 +1076,6 @@ void adapter_remove_device(struct btd_adapter *adapter,
 	g_dbus_emit_property_changed(btd_get_dbus_connection(),
 				adapter->path, ADAPTER_INTERFACE, "Devices");
 
-	g_dbus_emit_signal(btd_get_dbus_connection(), adapter->path,
-			ADAPTER_INTERFACE, "DeviceRemoved",
-			DBUS_TYPE_OBJECT_PATH, &dev_path,
-			DBUS_TYPE_INVALID);
-
 	device_remove(dev, remove_storage);
 }
 
@@ -1680,10 +1667,6 @@ static const GDBusMethodTable adapter_methods[] = {
 };
 
 static const GDBusSignalTable adapter_signals[] = {
-	{ GDBUS_SIGNAL("DeviceCreated",
-			GDBUS_ARGS({ "device", "o" })) },
-	{ GDBUS_SIGNAL("DeviceRemoved",
-			GDBUS_ARGS({ "device", "o" })) },
 	{ GDBUS_SIGNAL("DevicesFound",
 			GDBUS_ARGS({ "devices", "a{oa{sv}}" })) },
 	{ }
-- 
1.7.11.7


^ permalink raw reply related

* [RFC v1 14/16] adapter: Remove redundant Devices property
From: Mikel Astiz @ 2012-11-15 15:09 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Mikel Astiz
In-Reply-To: <1352992159-11559-1-git-send-email-mikel.astiz.oss@gmail.com>

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

The ObjectManager interface already reports the list of devices, so the
the property can be entirely removed.
---
 doc/adapter-api.txt |  4 ----
 src/adapter.c       | 30 ------------------------------
 2 files changed, 34 deletions(-)

diff --git a/doc/adapter-api.txt b/doc/adapter-api.txt
index 132e60f..3582793 100644
--- a/doc/adapter-api.txt
+++ b/doc/adapter-api.txt
@@ -180,10 +180,6 @@ Properties	string Address [readonly]
 
 			Indicates that a device discovery procedure is active.
 
-		array{object} Devices [readonly]
-
-			List of device object paths.
-
 		array{string} UUIDs [readonly]
 
 			List of 128-bit UUIDs that represents the available
diff --git a/src/adapter.c b/src/adapter.c
index aa93785..eb82102 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -1018,9 +1018,6 @@ static struct btd_device *adapter_create_device(struct btd_adapter *adapter,
 
 	adapter->devices = g_slist_append(adapter->devices, device);
 
-	g_dbus_emit_property_changed(btd_get_dbus_connection(),
-				adapter->path, ADAPTER_INTERFACE, "Devices");
-
 	return device;
 }
 
@@ -1073,9 +1070,6 @@ void adapter_remove_device(struct btd_adapter *adapter,
 		service_auth_cancel(auth);
 	}
 
-	g_dbus_emit_property_changed(btd_get_dbus_connection(),
-				adapter->path, ADAPTER_INTERFACE, "Devices");
-
 	device_remove(dev, remove_storage);
 }
 
@@ -1381,29 +1375,6 @@ static gboolean adapter_property_get_discovering(
 	return TRUE;
 }
 
-static gboolean adapter_property_get_devices(
-					const GDBusPropertyTable *property,
-					DBusMessageIter *iter, void *data)
-{
-	struct btd_adapter *adapter = data;
-	DBusMessageIter entry;
-	GSList *l;
-
-	dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
-				DBUS_TYPE_OBJECT_PATH_AS_STRING, &entry);
-
-	for (l = adapter->devices; l != NULL; l = l->next) {
-		const char *path = device_get_path(l->data);
-
-		dbus_message_iter_append_basic(&entry, DBUS_TYPE_OBJECT_PATH,
-								&path);
-	}
-
-	dbus_message_iter_close_container(iter, &entry);
-
-	return TRUE;
-}
-
 static gboolean adapter_property_get_uuids(const GDBusPropertyTable *property,
 					DBusMessageIter *iter, void *data)
 {
@@ -1688,7 +1659,6 @@ static const GDBusPropertyTable adapter_properties[] = {
 	{ "PairableTimeout", "u", adapter_property_get_pairable_timeout,
 				adapter_property_set_pairable_timeout },
 	{ "Discovering", "b", adapter_property_get_discovering },
-	{ "Devices", "ao", adapter_property_get_devices },
 	{ "UUIDs", "as", adapter_property_get_uuids },
 	{ }
 };
-- 
1.7.11.7


^ permalink raw reply related

* [RFC v1 15/16] test: Use ObjectManager instead of Devices property
From: Mikel Astiz @ 2012-11-15 15:09 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Mikel Astiz
In-Reply-To: <1352992159-11559-1-git-send-email-mikel.astiz.oss@gmail.com>

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

Use the objects and interfaces reported by the ObjectManager in order
to list the available devices per adapter.
---
 test/list-devices | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/test/list-devices b/test/list-devices
index fcff3e7..e8f3f24 100755
--- a/test/list-devices
+++ b/test/list-devices
@@ -30,6 +30,10 @@ def extract_uuids(uuid_list):
 	return list
 
 objects = manager.GetManagedObjects()
+
+all_devices = (str(path) for path, interfaces in objects.iteritems() if
+					"org.bluez.Device" in interfaces.keys())
+
 for path, interfaces in objects.iteritems():
 	if "org.bluez.Adapter" not in interfaces.keys():
 		continue
@@ -39,19 +43,13 @@ for path, interfaces in objects.iteritems():
 	properties = interfaces["org.bluez.Adapter"]
 	for key in properties.keys():
 		value = properties[key]
-		if (key == "Devices"):
-			list = extract_objects(value)
-			print("    %s = %s" % (key, list))
-		elif (key == "UUIDs"):
+		if (key == "UUIDs"):
 			list = extract_uuids(value)
 			print("    %s = %s" % (key, list))
 		else:
 			print("    %s = %s" % (key, value))
 
-	try:
-		device_list = properties["Devices"]
-	except:
-		device_list = []
+	device_list = [d for d in all_devices if d.startswith(path + "/")]
 
 	for dev_path in device_list:
 		print("    [ " + dev_path + " ]")
-- 
1.7.11.7


^ permalink raw reply related

* [RFC v1 16/16] adapter: Remove FindDevice method from D-Bus API
From: Mikel Astiz @ 2012-11-15 15:09 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Mikel Astiz
In-Reply-To: <1352992159-11559-1-git-send-email-mikel.astiz.oss@gmail.com>

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

ObjectManager.GetManagedObjects() returns all devices and their
corresponding properties to any interested client. The device address is
included in the property dictionary and therefore having such a
FindDevice method is an unnecessary duplication.
---
 doc/adapter-api.txt |  7 -------
 src/adapter.c       | 38 --------------------------------------
 2 files changed, 45 deletions(-)

diff --git a/doc/adapter-api.txt b/doc/adapter-api.txt
index 3582793..983a20d 100644
--- a/doc/adapter-api.txt
+++ b/doc/adapter-api.txt
@@ -64,13 +64,6 @@ Methods		void RequestSession()
 					 org.bluez.Error.Failed
 					 org.bluez.Error.NotAuthorized
 
-		object FindDevice(string address)
-
-			Returns the object path of device for given address.
-
-			Possible Errors: org.bluez.Error.DoesNotExist
-					 org.bluez.Error.InvalidArguments
-
 		void RemoveDevice(object device)
 
 			This removes the remote device object at the given
diff --git a/src/adapter.c b/src/adapter.c
index eb82102..71b5232 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -1518,40 +1518,6 @@ static DBusMessage *remove_device(DBusConnection *conn, DBusMessage *msg,
 	return NULL;
 }
 
-static DBusMessage *find_device(DBusConnection *conn, DBusMessage *msg,
-								void *data)
-{
-	struct btd_adapter *adapter = data;
-	struct btd_device *device;
-	DBusMessage *reply;
-	const gchar *address;
-	GSList *l;
-	const gchar *dev_path;
-
-	if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &address,
-						DBUS_TYPE_INVALID))
-		return btd_error_invalid_args(msg);
-
-	l = g_slist_find_custom(adapter->devices,
-			address, (GCompareFunc) device_address_cmp);
-	if (!l)
-		return btd_error_does_not_exist(msg);
-
-	device = l->data;
-
-	reply = dbus_message_new_method_return(msg);
-	if (!reply)
-		return NULL;
-
-	dev_path = device_get_path(device);
-
-	dbus_message_append_args(reply,
-				DBUS_TYPE_OBJECT_PATH, &dev_path,
-				DBUS_TYPE_INVALID);
-
-	return reply;
-}
-
 static void agent_removed(struct agent *agent, struct btd_adapter *adapter)
 {
 	mgmt_set_io_capability(adapter->dev_id, IO_CAPABILITY_NOINPUTNOOUTPUT);
@@ -1623,10 +1589,6 @@ static const GDBusMethodTable adapter_methods[] = {
 	{ GDBUS_ASYNC_METHOD("RemoveDevice",
 			GDBUS_ARGS({ "device", "o" }), NULL,
 			remove_device) },
-	{ GDBUS_METHOD("FindDevice",
-			GDBUS_ARGS({ "address", "s" }),
-			GDBUS_ARGS({ "device", "o" }),
-			find_device) },
 	{ GDBUS_METHOD("RegisterAgent",
 			GDBUS_ARGS({ "agent", "o" },
 					{ "capability", "s" }), NULL,
-- 
1.7.11.7


^ permalink raw reply related

* [RFC 1/4] Bluetooth: Use __l2cap_no_conn_pending helper
From: Andrei Emeltchenko @ 2012-11-15 16:14 UTC (permalink / raw)
  To: linux-bluetooth

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

Use helper instead of test_bit. This is the only place left using
test CONF_CONNECT_PEND flag.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
---
 net/bluetooth/l2cap_core.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 04e26e6..751d8a7 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -6469,7 +6469,7 @@ int l2cap_security_cfm(struct hci_conn *hcon, u8 status, u8 encrypt)
 			continue;
 		}
 
-		if (test_bit(CONF_CONNECT_PEND, &chan->conf_state)) {
+		if (!__l2cap_no_conn_pending(chan)) {
 			l2cap_chan_unlock(chan);
 			continue;
 		}
-- 
1.7.10.4


^ permalink raw reply related

* [RFC 2/4] Bluetooth: Fix sending L2CAP Create Chan Req
From: Andrei Emeltchenko @ 2012-11-15 16:14 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1352996096-27374-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

When receiving Physical Link Completed event we need to create L2CAP
channel with L2CAP Create Chan Request. Current code was sending
this command only if connection was pending (which is probably
needed in channel move case). If channel is not moved but created
Create Chan should be sent for outgoing channel which is checked
with BT_CONNECT flag.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
---
 net/bluetooth/l2cap_core.c |   29 ++++++++++++++++++-----------
 1 file changed, 18 insertions(+), 11 deletions(-)

diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 751d8a7..f6a8960 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -4594,15 +4594,31 @@ void l2cap_move_start(struct l2cap_chan *chan)
 static void l2cap_do_create(struct l2cap_chan *chan, int result,
 			    u8 local_amp_id, u8 remote_amp_id)
 {
+	BT_DBG("chan %p state %s %u -> %u", chan, state_to_string(chan->state),
+	       local_amp_id, remote_amp_id);
+
 	chan->fcs = L2CAP_FCS_NONE;
 
-	if (!test_bit(CONF_CONNECT_PEND, &chan->conf_state)) {
+	/* Outgoing channel on AMP */
+	if (chan->state == BT_CONNECT) {
+		if (result == L2CAP_CR_SUCCESS) {
+			chan->local_amp_id = local_amp_id;
+			l2cap_send_create_chan_req(chan, remote_amp_id);
+		} else {
+			/* Revert to BR/EDR connect */
+			l2cap_send_conn_req(chan);
+		}
+
+		return;
+	}
+
+	/* Incoming channel on AMP */
+	if (__l2cap_no_conn_pending(chan)) {
 		struct l2cap_conn_rsp rsp;
 		char buf[128];
 		rsp.scid = cpu_to_le16(chan->dcid);
 		rsp.dcid = cpu_to_le16(chan->scid);
 
-		/* Incoming channel on AMP */
 		if (result == L2CAP_CR_SUCCESS) {
 			/* Send successful response */
 			rsp.result = __constant_cpu_to_le16(L2CAP_CR_SUCCESS);
@@ -4624,15 +4640,6 @@ static void l2cap_do_create(struct l2cap_chan *chan, int result,
 				       l2cap_build_conf_req(chan, buf), buf);
 			chan->num_conf_req++;
 		}
-	} else {
-		/* Outgoing channel on AMP */
-		if (result == L2CAP_CR_SUCCESS) {
-			chan->local_amp_id = local_amp_id;
-			l2cap_send_create_chan_req(chan, remote_amp_id);
-		} else {
-			/* Revert to BR/EDR connect */
-			l2cap_send_conn_req(chan);
-		}
 	}
 }
 
-- 
1.7.10.4


^ permalink raw reply related

* [RFC 3/4] Bluetooth: Remove unneeded local_amp_id initialization
From: Andrei Emeltchenko @ 2012-11-15 16:14 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1352996096-27374-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

local_amp_id is already set in l2cap_connect() which is called several
lines above.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
---
 net/bluetooth/l2cap_core.c |    1 -
 1 file changed, 1 deletion(-)

diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index f6a8960..33eb3f4 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -4360,7 +4360,6 @@ static int l2cap_create_channel_req(struct l2cap_conn *conn,
 
 		BT_DBG("mgr %p bredr_chan %p hs_hcon %p", mgr, chan, hs_hcon);
 
-		chan->local_amp_id = req->amp_id;
 		mgr->bredr_chan = chan;
 		chan->hs_hcon = hs_hcon;
 		conn->mtu = hdev->block_mtu;
-- 
1.7.10.4


^ permalink raw reply related

* [RFC 4/4] Bluetooth: Set local_amp_id after getting Phylink Completed evt
From: Andrei Emeltchenko @ 2012-11-15 16:14 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1352996096-27374-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

local_amp_id is used in l2cap_physical_cfm and shall be set up
before calling it.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
---
 net/bluetooth/amp.c |    1 +
 1 file changed, 1 insertion(+)

diff --git a/net/bluetooth/amp.c b/net/bluetooth/amp.c
index eb61aaa..ac9e8fe 100644
--- a/net/bluetooth/amp.c
+++ b/net/bluetooth/amp.c
@@ -392,6 +392,7 @@ void amp_physical_cfm(struct hci_conn *bredr_hcon, struct hci_conn *hs_hcon)
 
 	set_bit(FLAG_EFS_ENABLE, &bredr_chan->flags);
 	bredr_chan->remote_amp_id = hs_hcon->remote_id;
+	bredr_chan->local_amp_id = hs_hcon->hdev->id;
 	bredr_chan->hs_hcon = hs_hcon;
 	bredr_chan->conn->mtu = hs_hcon->hdev->block_mtu;
 
-- 
1.7.10.4


^ permalink raw reply related

* [PATCH 1/8] device: Remove storage path #defines
From: Frédéric Danis @ 2012-11-15 17:31 UTC (permalink / raw)
  To: linux-bluetooth

INFO_PATH and CACHE_PATH will be static for the
entire 5.x series
---
 src/device.c |   10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/src/device.c b/src/device.c
index 4ca375b..e3570cb 100644
--- a/src/device.c
+++ b/src/device.c
@@ -76,9 +76,6 @@
 #define DISCONNECT_TIMER	2
 #define DISCOVERY_TIMER		2
 
-#define INFO_PATH STORAGEDIR "/%s/%s/info"
-#define CACHE_PATH STORAGEDIR "/%s/cache/%s"
-
 struct btd_disconnect_data {
 	guint id;
 	disconnect_watch watch;
@@ -231,7 +228,8 @@ static gboolean store_device_info_cb(gpointer user_data)
 
 	ba2str(adapter_get_address(device->adapter), adapter_addr);
 	ba2str(&device->bdaddr, device_addr);
-	snprintf(filename, PATH_MAX, INFO_PATH, adapter_addr, device_addr);
+	snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/info", adapter_addr,
+			device_addr);
 	filename[PATH_MAX] = '\0';
 
 	create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
@@ -1693,7 +1691,7 @@ static char *load_cached_name(struct btd_device *device, const char *local,
 	char *str = NULL;
 	int len;
 
-	snprintf(filename, PATH_MAX, CACHE_PATH, local, peer);
+	snprintf(filename, PATH_MAX, STORAGEDIR "/%s/cache/%s", local, peer);
 	filename[PATH_MAX] = '\0';
 
 	key_file = g_key_file_new();
@@ -1722,7 +1720,7 @@ static void load_info(struct btd_device *device, const gchar *local,
 	char *str;
 	gboolean store_needed = FALSE;
 
-	snprintf(filename, PATH_MAX, INFO_PATH, local, peer);
+	snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/info", local, peer);
 	filename[PATH_MAX] = '\0';
 
 	key_file = g_key_file_new();
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH 2/8] device: Device_remove_stored removes device directory
From: Frédéric Danis @ 2012-11-15 17:31 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1353000701-16605-1-git-send-email-frederic.danis@linux.intel.com>

When a device is removed we should remove the device info
file and storage directory.
---
 src/device.c |   16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/src/device.c b/src/device.c
index e3570cb..5969f15 100644
--- a/src/device.c
+++ b/src/device.c
@@ -1873,6 +1873,9 @@ static void device_remove_stored(struct btd_device *device)
 {
 	const bdaddr_t *src = adapter_get_address(device->adapter);
 	uint8_t dst_type = device->bdaddr_type;
+	char adapter_addr[18];
+	char device_addr[18];
+	char filename[PATH_MAX + 1];
 
 	delete_entry(src, "profiles", &device->bdaddr, dst_type);
 	delete_entry(src, "trusts", &device->bdaddr, dst_type);
@@ -1893,6 +1896,19 @@ static void device_remove_stored(struct btd_device *device)
 
 	if (device->blocked)
 		device_unblock(device, TRUE, FALSE);
+
+	ba2str(src, adapter_addr);
+	ba2str(&device->bdaddr, device_addr);
+
+	snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/info", adapter_addr,
+			device_addr);
+	filename[PATH_MAX] = '\0';
+	remove(filename);
+
+	snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s", adapter_addr,
+			device_addr);
+	filename[PATH_MAX] = '\0';
+	remove(filename);
 }
 
 void device_remove(struct btd_device *device, gboolean remove_stored)
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH 3/8] adapter: Convert storage classes
From: Frédéric Danis @ 2012-11-15 17:31 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1353000701-16605-1-git-send-email-frederic.danis@linux.intel.com>

---
 src/adapter.c |    8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/adapter.c b/src/adapter.c
index ea2d2ad..5157b46 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2545,6 +2545,11 @@ static void convert_trusts_entry(GKeyFile *key_file, void *value)
 	g_key_file_set_boolean(key_file, "General", "Trusted", TRUE);
 }
 
+static void convert_classes_entry(GKeyFile *key_file, void *value)
+{
+	g_key_file_set_string(key_file, "General", "Class", value);
+}
+
 static void convert_entry(char *key, char *value, void *user_data)
 {
 	struct device_converter *converter = user_data;
@@ -2624,6 +2629,9 @@ static void convert_device_storage(struct btd_adapter *adapter)
 
 	/* Convert trusts */
 	convert_file("trusts", address, convert_trusts_entry);
+
+	/* Convert classes */
+	convert_file("classes", address, convert_classes_entry);
 }
 
 static void convert_config(struct btd_adapter *adapter, const char *filename,
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH 4/8] device: Retrieve class from storage
From: Frédéric Danis @ 2012-11-15 17:31 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1353000701-16605-1-git-send-email-frederic.danis@linux.intel.com>

When device class is updated, save it and emit property changed signal.
---
 src/device.c |   60 ++++++++++++++++++++++++++++++++++++++--------------------
 src/device.h |    1 +
 2 files changed, 41 insertions(+), 20 deletions(-)

diff --git a/src/device.c b/src/device.c
index 5969f15..d4d649b 100644
--- a/src/device.c
+++ b/src/device.c
@@ -149,6 +149,7 @@ struct btd_device {
 	GSList		*eir_uuids;
 	char		name[MAX_NAME_LENGTH + 1];
 	char		*alias;
+	uint32_t	class;
 	uint16_t	vendor_src;
 	uint16_t	vendor;
 	uint16_t	product;
@@ -211,6 +212,7 @@ static gboolean store_device_info_cb(gpointer user_data)
 	char adapter_addr[18];
 	char device_addr[18];
 	char *str;
+	char class[9];
 	gsize length = 0;
 
 	device->store_id = 0;
@@ -223,6 +225,11 @@ static gboolean store_device_info_cb(gpointer user_data)
 		g_key_file_set_string(key_file, "General", "Alias",
 								device->alias);
 
+	if (device->class) {
+		sprintf(class, "0x%6.6x", device->class);
+		g_key_file_set_string(key_file, "General", "Class", class);
+	}
+
 	g_key_file_set_boolean(key_file, "General", "Trusted",
 							device->trusted);
 
@@ -470,35 +477,23 @@ static void dev_property_set_alias(const GDBusPropertyTable *property,
 	set_alias(id, alias, data);
 }
 
-static gboolean get_class(const GDBusPropertyTable *property, void *data,
-							uint32_t *class)
-{
-	struct btd_device *device = data;
-
-	if (read_remote_class(adapter_get_address(device->adapter),
-						&device->bdaddr, class) == 0)
-		return TRUE;
-
-	return FALSE;
-}
-
 static gboolean dev_property_exists_class(const GDBusPropertyTable *property,
 								void *data)
 {
-	uint32_t class;
+	struct btd_device *device = data;
 
-	return get_class(property, data, &class);
+	return device->class != 0;
 }
 
 static gboolean dev_property_get_class(const GDBusPropertyTable *property,
 					DBusMessageIter *iter, void *data)
 {
-	uint32_t class;
+	struct btd_device *device = data;
 
-	if (!get_class(property, data, &class))
+	if (device->class == 0)
 		return FALSE;
 
-	dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT32, &class);
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT32, &device->class);
 
 	return TRUE;
 }
@@ -542,12 +537,12 @@ static gboolean dev_property_get_appearance(const GDBusPropertyTable *property,
 
 static const char *get_icon(const GDBusPropertyTable *property, void *data)
 {
+	struct btd_device *device = data;
 	const char *icon = NULL;
-	uint32_t class;
 	uint16_t appearance;
 
-	if (get_class(property, data, &class))
-		icon = class_to_icon(class);
+	if (device->class != 0)
+		icon = class_to_icon(device->class);
 	else if (get_appearance(property, data, &appearance))
 		icon = gap_appearance_to_icon(appearance);
 
@@ -1745,6 +1740,16 @@ static void load_info(struct btd_device *device, const gchar *local,
 	device->alias = g_key_file_get_string(key_file, "General", "Alias",
 									NULL);
 
+	/* Load class */
+	str = g_key_file_get_string(key_file, "General", "Class", NULL);
+	if (str) {
+		uint32_t class;
+
+		if (sscanf(str, "%x", &class) == 1)
+			device->class = class;
+		g_free(str);
+	}
+
 	/* Load trust */
 	device->trusted = g_key_file_get_boolean(key_file, "General",
 							"Trusted", NULL);
@@ -1849,6 +1854,21 @@ bool device_name_known(struct btd_device *device)
 	return device->name[0] != '\0';
 }
 
+void device_set_class(struct btd_device *device, uint32_t class)
+{
+	if (device->class == class)
+		return;
+
+	DBG("%s 0x%06X", device->path, class);
+
+	device->class = class;
+
+	store_device_info(device);
+
+	g_dbus_emit_property_changed(btd_get_dbus_connection(), device->path,
+						DEVICE_INTERFACE, "Class");
+}
+
 uint16_t btd_device_get_vendor(struct btd_device *device)
 {
 	return device->vendor;
diff --git a/src/device.h b/src/device.h
index ea646a8..3715698 100644
--- a/src/device.h
+++ b/src/device.h
@@ -32,6 +32,7 @@ struct btd_device *device_create(struct btd_adapter *adapter,
 void device_set_name(struct btd_device *device, const char *name);
 void device_get_name(struct btd_device *device, char *name, size_t len);
 bool device_name_known(struct btd_device *device);
+void device_set_class(struct btd_device *device, uint32_t class);
 uint16_t btd_device_get_vendor(struct btd_device *device);
 uint16_t btd_device_get_vendor_src(struct btd_device *device);
 uint16_t btd_device_get_product(struct btd_device *device);
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH 5/8] adapter: Set device class in device object
From: Frédéric Danis @ 2012-11-15 17:31 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1353000701-16605-1-git-send-email-frederic.danis@linux.intel.com>

Move storage of device class after device object creation.
---
 src/adapter.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 5157b46..9ecc0fa 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -3070,9 +3070,6 @@ void adapter_update_found_devices(struct btd_adapter *adapter,
 		return;
 	}
 
-	if (eir_data.class != 0)
-		write_remote_class(&adapter->bdaddr, bdaddr, eir_data.class);
-
 	if (eir_data.appearance != 0)
 		write_remote_appearance(&adapter->bdaddr, bdaddr, bdaddr_type,
 							eir_data.appearance);
@@ -3102,6 +3099,9 @@ void adapter_update_found_devices(struct btd_adapter *adapter,
 	if (eir_data.name)
 		device_set_name(dev, eir_data.name);
 
+	if (eir_data.class != 0)
+		device_set_class(dev, eir_data.class);
+
 	device_add_eir_uuids(dev, eir_data.services);
 
 	eir_data_free(&eir_data);
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH 6/8] event: Set device class in device object
From: Frédéric Danis @ 2012-11-15 17:31 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1353000701-16605-1-git-send-email-frederic.danis@linux.intel.com>

---
 src/event.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/event.c b/src/event.c
index 5f1fc9f..7fc8f02 100644
--- a/src/event.c
+++ b/src/event.c
@@ -419,7 +419,7 @@ void btd_event_conn_complete(bdaddr_t *local, bdaddr_t *peer, uint8_t bdaddr_typ
 	update_lastused(local, peer, bdaddr_type);
 
 	if (class != 0)
-		write_remote_class(local, peer, class);
+		device_set_class(device, class);
 
 	device_set_addr_type(device, bdaddr_type);
 
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH 7/8] dbusoob: Set device class in device object
From: Frédéric Danis @ 2012-11-15 17:31 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1353000701-16605-1-git-send-email-frederic.danis@linux.intel.com>

---
 plugins/dbusoob.c |    9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/plugins/dbusoob.c b/plugins/dbusoob.c
index b59ffa8..e58b353 100644
--- a/plugins/dbusoob.c
+++ b/plugins/dbusoob.c
@@ -191,7 +191,9 @@ static gboolean parse_data(DBusMessageIter *data, struct oob_data *remote_data)
 	return TRUE;
 }
 
-static gboolean store_data(struct btd_adapter *adapter, struct oob_data *data)
+static gboolean store_data(struct btd_adapter *adapter,
+				struct btd_device *device,
+				struct oob_data *data)
 {
 	bdaddr_t bdaddr;
 
@@ -204,8 +206,7 @@ static gboolean store_data(struct btd_adapter *adapter, struct oob_data *data)
 	}
 
 	if (data->class)
-		write_remote_class(adapter_get_address(adapter), &bdaddr,
-								data->class);
+		device_set_class(device, data->class);
 
 	if (data->name)
 		btd_event_remote_name(adapter_get_address(adapter), &bdaddr,
@@ -255,7 +256,7 @@ static DBusMessage *add_remote_data(DBusConnection *conn, DBusMessage *msg,
 	if (!parse_data(&data, &remote_data))
 		return btd_error_invalid_args(msg);
 
-	if (!store_data(adapter, &remote_data))
+	if (!store_data(adapter, device, &remote_data))
 		return btd_error_failed(msg, "Request failed");
 
 	reply = dbus_message_new_method_return(msg);
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH 8/8] neard: Set device class in device object
From: Frédéric Danis @ 2012-11-15 17:31 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1353000701-16605-1-git-send-email-frederic.danis@linux.intel.com>

This will create a new device object and generate
DeviceCreated signal
---
 plugins/neard.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/plugins/neard.c b/plugins/neard.c
index 8f8381c..069953a 100644
--- a/plugins/neard.c
+++ b/plugins/neard.c
@@ -287,10 +287,11 @@ static int process_eir(struct btd_adapter *adapter, uint8_t *eir, size_t size,
 	if (device)
 		adapter_remove_device(adapter, device, TRUE);
 
+	device = adapter_get_device(adapter, remote_address);
+
 	/* store OOB data */
 	if (eir_data.class != 0)
-		write_remote_class(adapter_get_address(adapter),
-					&eir_data.addr, eir_data.class);
+		device_set_class(device, eir_data.class);
 
 	/* TODO handle incomplete name? */
 	if (eir_data.name)
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH] doc: Add HFP design document
From: Frédéric Danis @ 2012-11-15 17:35 UTC (permalink / raw)
  To: linux-bluetooth

---
 Makefile.am                    |    2 +-
 doc/audio-telephony-design.txt |  320 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 321 insertions(+), 1 deletion(-)
 create mode 100644 doc/audio-telephony-design.txt

diff --git a/Makefile.am b/Makefile.am
index e8a247a..a167a24 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -342,7 +342,7 @@ EXTRA_DIST += doc/manager-api.txt \
 		doc/media-api.txt doc/assigned-numbers.txt \
 		doc/supported-features.txt doc/alert-api.txt doc/mgmt-api.txt \
 		doc/oob-api.txt doc/proximity-api.txt doc/heartrate-api.txt \
-		doc/thermometer-api.txt
+		doc/thermometer-api.txt doc/audio-telephony-design.txt
 
 AM_CFLAGS += @DBUS_CFLAGS@ @GLIB_CFLAGS@
 
diff --git a/doc/audio-telephony-design.txt b/doc/audio-telephony-design.txt
new file mode 100644
index 0000000..7604f9f
--- /dev/null
+++ b/doc/audio-telephony-design.txt
@@ -0,0 +1,320 @@
+Telephony Interface Design
+**************************
+
+Introduction
+============
+
+The aim of this document is to briefly describe usage of profile interface which
+will allow external application to implement telephony related profiles
+(headset, handsfree).
+
+
+The goal
+========
+
+Previous version of headset code in BlueZ needs the implementation of an AT
+parser for each modem target or external telephony application (Maemo, oFono)
+which is not the aim of Bluez.
+
+The profile interface allows BlueZ to focus on Bluetooth communication part
+(connection, disconnection, authentication, authorization) and let external
+application (i.e. oFono) take charge of the Telephony tasks (AT parsing and
+modem specific code).
+This will allow code to be simpler, easier to maintain and debug in both BlueZ
+and telephony application.
+
+
+Design
+======
+
+External applications, which should implement AT parsing and telephony part
+will have to register an org.bluez.Profile1 agent using RegisterProfile of
+org.bluez.ProfileManager1 interface.
+This will setup a SDP record for the profile and a RFCOMM server listening for
+incoming connection.
+
+When a new device is connected, NewConnection method of Profile1 agent is
+called with informations related to connecting profile (like RFCOMM client file
+descriptor, version, features, media end point path, ...).
+
+The telephony application is in charge to implement a MediaTransport for its
+audio connection with remote device and interact with the MediaTransport of the
+audio component (i.e. PulseAudio).
+
+
+Flow charts
+===========
+
+Here is some flowcharts of interactions between BlueZ, telephony agent (oFono)
+and audio component (PulseAudio):
+
+        .....>  Bluetooth communication between headset and phone
+        ----->  Dbus messages and signals
+
+Start up
+--------
+
+When PulseAudio starts it registers media endpoints to BlueZ.
+When oFono starts it registers profile agent for HFP.
+
+	PulseAudio              BlueZ                    oFono
+	|                         |                        |
+	| register media endpoint |                        |
+	|------------------------>|                        |
+	|                         | register profile agent |
+	|                         |<-----------------------|
+	|                         |                        |
+
+HFP Connection
+--------------
+
+On incoming connection, BlueZ performs (if needed) authentication and
+authorization then passes RFCOMM file descriptor and media end point path to
+oFono.
+oFono should create a media transport and register it to PulseAudio using the
+media end point path.
+
+	PulseAudio          oFono            BlueZ           HF
+	|                     |                |              |
+	|                     |                |  connection  |
+	|                     |                |    set-up    |
+	|                     |                |<............>|
+	|                     | NewConnection  |              |
+	|                     |<---------------|              |
+	| SelectConfiguration |                |              |
+	|<--------------------|                |              |
+	|                     |                |              |
+	|   SetConfiguration  |                |              |
+	|<--------------------|                |              |
+	|                     |                |              |
+
+Outgoing SCO connection - HFP <= 1.5
+------------------------------------
+
+When PulseAudio needs to setup the audio connection it will call media
+transport acquire method. This will perform a SCO connection and return the SCO
+socket file descriptor to PulseAudio.
+
+	PulseAudio              oFono           HF/AG
+	|                         |               |
+	|    transport acquire    |               |
+	|------------------------>|               |
+	|                         |  connect SCO  |
+	|                         |..............>|
+	|      return SCO fd      |               |
+	|<------------------------|               |
+	|                         |               |
+
+Incoming SCO connection - HFP <= 1.5
+------------------------------------
+
+On an incoming SCO connection oFono will change to playing state.
+On reception of this state change, PulseAudio will call media transport acquire
+method to retrieve the SCO socket file descriptor.
+
+	PulseAudio              oFono           HF/AG
+	|                         |               |
+	|                         |  connect SCO  |
+	|                         |<..............|
+	|  state changed signal   |               |
+	|<------------------------|               |
+	|                         |               |
+	|    transport acquire    |               |
+	|------------------------>|               |
+	|                         |               |
+	|      return SCO fd      |               |
+	|<------------------------|               |
+	|                         |               |
+
+Codec negotiation - HFP AG - HFP v1.6
+-------------------------------------------
+
+On reception of HF available codecs command (AT+BAC), the gateway may start a
+codec selection procedure which will setup the correct media transport.
+When a media transport already exists and it uses a different codec, it should
+be closed before correct one is setup.
+
+	PulseAudio          oFono           HF
+	|                     |              |
+	|                     | AT+BAC=u1,u2 |
+	|                     |<.............|
+	|                     |              |
+	|                     |      OK      |
+	|                     |.............>|
+	|                     |              |
+	|                     |   +BCS:id    |
+	|                     |.............>|
+	|                     |              |
+	|                     |  AT+BCS=id   |
+	|                     |<.............|
+	|                     |              |
+	|                     |      OK      |
+	|                     |.............>|
+	| configure Transport |              |
+	|<--------------------|              |
+	|                     |              |
+
+It may also be possible to force a codec selection from oFono.
+
+	PulseAudio          oFono          HF
+	|                     |             |
+	|                     |   +BCS:id   |
+	|                     |............>|
+	|                     |             |
+	|                     |  AT+BCS=id  |
+	|                     |<............|
+	|                     |             |
+	|                     |      OK     |
+	|                     |............>|
+	| configure Transport |             |
+	|<--------------------|             |
+	|                     |             |
+
+Outgoing SCO connection - HFP AG - HFP v1.6
+-------------------------------------------
+
+Idem than for HFP v1.5
+
+Incoming SCO connection - HFP AG - HFP v1.6
+-------------------------------------------
+
+It is pretty the same here as for outgoing SCO connection, except that it is
+started upon reception of AT+BCC from the headset.
+
+	PulseAudio           oFono          HF
+	|                      |             |
+	|                      |    AT+BCC   |
+	|                      |<............|
+	|                      |             |
+	|                      |     OK      |
+	|                      |............>|
+	|                      |             |
+	|                      | connect SCO |
+	|                      |............>|
+	| state changed signal |             |
+	|<---------------------|             |
+	|                      |             |
+	|  transport acquire   |             |
+	|--------------------->|             |
+	|                      |             |
+	|    return SCO fd     |             |
+	|<---------------------|             |
+
+
+Codec negotiation - HFP HF - HFP v1.6
+-------------------------------------------
+
+Codec selection procedure started by gateway will end up by codec property
+update and setup of the correct media transport.
+When a media transport already exists and it uses a different codec, it should
+be closed before correct one is setup.
+
+	PulseAudio          oFono           AG
+	|                     |              |
+	|                     |   +BCS:id    |
+	|                     |<.............|
+	|                     |              |
+	|                     |  AT+BCS=id   |
+	|                     |.............>|
+	|                     |              |
+	|                     |      OK      |
+	|                     |<.............|
+	| configure Transport |              |
+	|<--------------------|              |
+	|                     |              |
+
+Outgoing SCO connection - HFP HF - HFP v1.6
+-------------------------------------------
+
+On media transport acquire, oFono requests connection from the gateway.
+Then incoming SCO socket file descriptor will be returned to PulseAudio.
+
+	PulseAudio             oFono          AG
+	|                        |             |
+	|   transport acquire    |             |
+	|----------------------->|             |
+	|                        |   AT+BCC    |
+	|                        |............>|
+	|                        |             |
+	|                        |      OK     |
+	|                        |<............|
+	|                        |             |
+	|                        | connect SCO |
+	|                        |<............|
+	|      return SCO fd     |             |
+	|<-----------------------|             |
+	|                        |             |
+
+Incoming SCO connection - HFP HF - HFP v1.6
+-------------------------------------------
+
+Idem than for HFP v1.5
+
+AT+NREC - HFP AG
+----------------
+
+Reception of AT+NREC will update the NREC property of media transport interface
+(listened by PulseAudio).
+
+	HF          oFono         PulseAudio
+	|   AT+NREC   |                |
+	|............>|                |
+	|             |    property    |
+	|             | changed signal |
+	|             |--------------->|
+	|     OK      |                |
+	|<............|                |
+	|             |                |
+
++BSIR - HFP AG
+--------------
+
+PulseAudio can change in-band ring tone by calling SetProperty method of media
+transport interface, which will send the proper +BSIR unsolicited event.
+
+	HF          oFono         PulseAudio        app
+	|             |                |             |
+	|             |                |<------------|
+	|             |  SetProperty   |             |
+	|             |<---------------|             |
+	|   +BSIR:x   |                |             |
+	|<............|                |             |
+	|             |    property    |             |
+	|             | changed signal |             |
+	|             |--------------->|             |
+	|             |                |             |
+
+AT+VGS,AT+VGM - HFP AG
+----------------------
+
+Reception of volume management command will update the corresponding volume
+property of media transport interface (listened by PulseAudio).
+
+	HF          oFono         PulseAudio        app
+	|             |                |             |
+	|  AT+VGS=xx  |                |             |
+	|............>|                |             |
+	|             |    property    |             |
+	|             | changed signal |             |
+	|             |--------------->|             |
+	|     OK      |                |             |
+	|<............|                |------------>|
+	|             |                |             |
+
++VGS,+VGM - HFP AG
+------------------
+
+PulseAudio can change volume by calling SetProperty method of media transport
+interface. This which will send the proper +VGx unsolicited event.
+
+	HF          oFono         PulseAudio        app
+	|             |                |             |
+	|             |                |<------------|
+	|             |  SetProperty   |             |
+	|             |<---------------|             |
+	|   +VGS:xx   |                |             |
+	|<............|    property    |             |
+	|             | changed signal |             |
+	|             |--------------->|             |
+	|             |                |------------>|
+	|             |                |             |
-- 
1.7.9.5


^ permalink raw reply related

* Re: [RFC] Bluetooth: Add BT_DEFER_SETUP option to sco socket
From: Gustavo Padovan @ 2012-11-15 20:30 UTC (permalink / raw)
  To: Frédéric Dalleau; +Cc: linux-bluetooth
In-Reply-To: <1352830825-13987-2-git-send-email-frederic.dalleau@linux.intel.com>

Hi Frédéric,

* Frédéric Dalleau <frederic.dalleau@linux.intel.com> [2012-11-13 19:20:25 +0100]:

> In order to authenticate and later configure an incoming SCO connection, the
> BT_DEFER_SETUP option is added.
> When an connection is requested, the listening socket is unblocked but the
> effective connection setup happens only on first recv.
> Any send between accept and recv fails with -ENOTCONN.
> ---
>  include/net/bluetooth/hci_core.h |   15 +++++++
>  net/bluetooth/hci_event.c        |   47 +++++++++++++++++++-
>  net/bluetooth/sco.c              |   88 ++++++++++++++++++++++++++++++++++++--
>  3 files changed, 145 insertions(+), 5 deletions(-)
> 
> diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
> index ef5b85d..2ee0ecb 100644
> --- a/include/net/bluetooth/hci_core.h
> +++ b/include/net/bluetooth/hci_core.h
> @@ -377,6 +377,7 @@ extern int l2cap_recv_acldata(struct hci_conn *hcon, struct sk_buff *skb,
>  			      u16 flags);
>  
>  extern int sco_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr);
> +extern int sco_defer(struct hci_dev *hdev, bdaddr_t *bdaddr);
>  extern void sco_connect_cfm(struct hci_conn *hcon, __u8 status);
>  extern void sco_disconn_cfm(struct hci_conn *hcon, __u8 reason);
>  extern int sco_recv_scodata(struct hci_conn *hcon, struct sk_buff *skb);
> @@ -577,6 +578,7 @@ struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst);
>  int hci_conn_del(struct hci_conn *conn);
>  void hci_conn_hash_flush(struct hci_dev *hdev);
>  void hci_conn_check_pending(struct hci_dev *hdev);
> +void hci_conn_accept(struct hci_conn *conn, int mask);
>  
>  struct hci_chan *hci_chan_create(struct hci_conn *conn);
>  void hci_chan_del(struct hci_chan *chan);
> @@ -796,6 +798,19 @@ static inline int hci_proto_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr,
>  	}
>  }
>  
> +static inline int hci_proto_defered(struct hci_dev *hdev, bdaddr_t *bdaddr,
> +								__u8 type)
> +{
> +	switch (type) {
> +	case SCO_LINK:
> +	case ESCO_LINK:
> +		return sco_defer(hdev, bdaddr);
> +
> +	default:
> +		return 0;
> +	}
> +}
> +
>  static inline void hci_proto_connect_cfm(struct hci_conn *conn, __u8 status)
>  {
>  	switch (conn->type) {
> diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
> index 9f5c5f2..167eca0 100644
> --- a/net/bluetooth/hci_event.c
> +++ b/net/bluetooth/hci_event.c
> @@ -2047,15 +2047,54 @@ unlock:
>  	hci_conn_check_pending(hdev);
>  }
>  
> +void hci_conn_accept(struct hci_conn *conn, int mask)
> +{
> +	struct hci_dev *hdev = conn->hdev;
> +
> +	BT_DBG("conn %p", conn);
> +
> +	if (!lmp_esco_capable(hdev)) {
> +		struct hci_cp_accept_conn_req cp;
> +
> +		conn->state = BT_CONNECT;
> +		bacpy(&cp.bdaddr, &conn->dst);
> +
> +		if (lmp_rswitch_capable(hdev) && (mask & HCI_LM_MASTER))
> +			cp.role = 0x00; /* Become master */
> +		else
> +			cp.role = 0x01; /* Remain slave */
> +
> +		hci_send_cmd(hdev, HCI_OP_ACCEPT_CONN_REQ, sizeof(cp),
> +			     &cp);
> +	} else /* lmp_esco_capable(hdev)) */ {
> +		struct hci_cp_accept_sync_conn_req cp;
> +
> +		conn->state = BT_CONNECT;
> +		bacpy(&cp.bdaddr, &conn->dst);
> +		cp.pkt_type = cpu_to_le16(conn->pkt_type);
> +
> +		cp.tx_bandwidth   = __constant_cpu_to_le32(0x00001f40);
> +		cp.rx_bandwidth   = __constant_cpu_to_le32(0x00001f40);
> +		cp.max_latency    = __constant_cpu_to_le16(0xffff);
> +		cp.content_format = cpu_to_le16(hdev->voice_setting);
> +		cp.retrans_effort = 0xff;
> +
> +		hci_send_cmd(hdev, HCI_OP_ACCEPT_SYNC_CONN_REQ,
> +			     sizeof(cp), &cp);
> +	}
> +}
> +
>  static void hci_conn_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
>  {
>  	struct hci_ev_conn_request *ev = (void *) skb->data;
>  	int mask = hdev->link_mode;
> +	int defered;
>  
>  	BT_DBG("%s bdaddr %pMR type 0x%x", hdev->name, &ev->bdaddr,
>  	       ev->link_type);
>  
>  	mask |= hci_proto_connect_ind(hdev, &ev->bdaddr, ev->link_type);
> +	defered = hci_proto_defered(hdev, &ev->bdaddr, ev->link_type);

I'm not really happy with this hci_proto thing. Weed need to think more on
this.

>  
>  	if ((mask & HCI_LM_ACCEPT) &&
>  	    !hci_blacklist_lookup(hdev, &ev->bdaddr)) {
> @@ -2085,7 +2124,8 @@ static void hci_conn_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
>  
>  		hci_dev_unlock(hdev);
>  
> -		if (ev->link_type == ACL_LINK || !lmp_esco_capable(hdev)) {
> +		if (ev->link_type == ACL_LINK ||
> +				(!defered && !lmp_esco_capable(hdev))) {
>  			struct hci_cp_accept_conn_req cp;
>  
>  			bacpy(&cp.bdaddr, &ev->bdaddr);
> @@ -2097,7 +2137,7 @@ static void hci_conn_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
>  
>  			hci_send_cmd(hdev, HCI_OP_ACCEPT_CONN_REQ, sizeof(cp),
>  				     &cp);
> -		} else {
> +		} else if (!defered) {
>  			struct hci_cp_accept_sync_conn_req cp;
>  
>  			bacpy(&cp.bdaddr, &ev->bdaddr);
> @@ -2111,6 +2151,9 @@ static void hci_conn_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
>  
>  			hci_send_cmd(hdev, HCI_OP_ACCEPT_SYNC_CONN_REQ,
>  				     sizeof(cp), &cp);
> +		} else {
> +			hci_proto_connect_cfm(conn, 0);
> +			hci_conn_put(conn);
>  		}
>  	} else {
>  		/* Connection rejected */
> diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c
> index 450cdcd..416801a 100644
> --- a/net/bluetooth/sco.c
> +++ b/net/bluetooth/sco.c
> @@ -662,16 +662,57 @@ static int sco_sock_sendmsg(struct kiocb *iocb, struct socket *sock,
>  	return err;
>  }
>  
> +static int sco_sock_recvmsg(struct kiocb *iocb, struct socket *sock,
> +			      struct msghdr *msg, size_t len, int flags)
> +{
> +	struct sock *sk = sock->sk;
> +	struct sco_pinfo *pi = sco_pi(sk);
> +
> +	lock_sock(sk);
> +
> +	if (sk->sk_state == BT_CONNECT &&

I think you want to use BT_CONNECT2 here...

> +			test_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags)) {
> +		hci_conn_accept(pi->conn->hcon, 0);
> +		sk->sk_state = BT_CONNECT2;

and BT_CONFIG here.

> +
> +		release_sock(sk);
> +		return 0;
> +	}
> +
> +	release_sock(sk);
> +
> +	return bt_sock_recvmsg(iocb, sock, msg, len, flags);
> +}
> +
>  static int sco_sock_setsockopt(struct socket *sock, int level, int optname, char __user *optval, unsigned int optlen)
>  {
>  	struct sock *sk = sock->sk;
>  	int err = 0;
> +	u32 opt;
>  
>  	BT_DBG("sk %p", sk);
>  
>  	lock_sock(sk);
>  
>  	switch (optname) {
> +
> +	case BT_DEFER_SETUP:
> +		if (sk->sk_state != BT_BOUND && sk->sk_state != BT_LISTEN) {
> +			err = -EINVAL;
> +			break;
> +		}
> +
> +		if (get_user(opt, (u32 __user *) optval)) {
> +			err = -EFAULT;
> +			break;
> +		}
> +
> +		if (opt)
> +			set_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags);
> +		else
> +			clear_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags);
> +		break;
> +

Please move the set/getsockopt to a separated patch and put it first in your
series.

>  	default:
>  		err = -ENOPROTOOPT;
>  		break;
> @@ -753,6 +794,19 @@ static int sco_sock_getsockopt(struct socket *sock, int level, int optname, char
>  	lock_sock(sk);
>  
>  	switch (optname) {
> +
> +	case BT_DEFER_SETUP:
> +		if (sk->sk_state != BT_BOUND && sk->sk_state != BT_LISTEN) {
> +			err = -EINVAL;
> +			break;
> +		}
> +
> +		if (put_user(test_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags),
> +			     (u32 __user *) optval))
> +			err = -EFAULT;
> +
> +		break;
> +
>  	default:
>  		err = -ENOPROTOOPT;
>  		break;
> @@ -874,7 +928,10 @@ static void sco_conn_ready(struct sco_conn *conn)
>  		hci_conn_hold(conn->hcon);
>  		__sco_chan_add(conn, sk, parent);
>  
> -		sk->sk_state = BT_CONNECTED;
> +		if (test_bit(BT_SK_DEFER_SETUP, &bt_sk(parent)->flags))
> +			sk->sk_state = BT_CONNECT;

Let's use BT_CONNECT2 here as this a incoming connection.

	Gustavo

^ permalink raw reply

* Re: [RFC 1/4] Bluetooth: Use __l2cap_no_conn_pending helper
From: Marcel Holtmann @ 2012-11-15 23:53 UTC (permalink / raw)
  To: Andrei Emeltchenko; +Cc: linux-bluetooth
In-Reply-To: <1352996096-27374-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>

Hi Andrei,

> Use helper instead of test_bit. This is the only place left using
> test CONF_CONNECT_PEND flag.
> 
> Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
> ---
>  net/bluetooth/l2cap_core.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Acked-by: Marcel Holtmann <marcel@holtmann.org>

Regards

Marcel



^ permalink raw reply

* Re: [RFC 3/4] Bluetooth: Remove unneeded local_amp_id initialization
From: Marcel Holtmann @ 2012-11-15 23:53 UTC (permalink / raw)
  To: Andrei Emeltchenko; +Cc: linux-bluetooth
In-Reply-To: <1352996096-27374-3-git-send-email-Andrei.Emeltchenko.news@gmail.com>

Hi Andrei,

> local_amp_id is already set in l2cap_connect() which is called several
> lines above.
> 
> Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
> ---
>  net/bluetooth/l2cap_core.c |    1 -
>  1 file changed, 1 deletion(-)

Acked-by: Marcel Holtmann <marcel@holtmann.org>

Regards

Marcel



^ permalink raw reply


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