linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/5] Implements primary service search when creating a device
@ 2010-11-24  2:30 Claudio Takahasi
  2010-11-24  2:30 ` [PATCH 2/5] Check the device type when creating the device Claudio Takahasi
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Claudio Takahasi @ 2010-11-24  2:30 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

Discover primary services implemented inside the device entity to allow
proper integration of attribute plugin. Implements a single entry point
to the attribute plugin no matter the transport(BR/EDR or LE), the device
probe callback is called for both types.

Add a new function to discover all primary services without additional
calls to fetch the remaining primary services, sub-procedure iterations
is handled inside this function.

The next action are: clean the attribute client removing implicity service
and characteristics discovery, issue the Discover Primary Service based on
the remote properties and fetch the characteristic on demand.
---
 attrib/manager.c  |   27 +++-------
 src/device.c      |  106 +++++++++++++++++++++++++++++++-------
 src/glib-helper.c |  147 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 src/glib-helper.h |    5 ++
 4 files changed, 246 insertions(+), 39 deletions(-)

diff --git a/attrib/manager.c b/attrib/manager.c
index 9bd1774..9b06c8c 100644
--- a/attrib/manager.c
+++ b/attrib/manager.c
@@ -45,26 +45,17 @@ static int client_probe(struct btd_device *device, GSList *uuids)
 {
 	const sdp_record_t *rec;
 	sdp_list_t *list;
-	int psm;
-
-	/*
-	 * Entry point for BR/EDR GATT probe. LE scanning and primary service
-	 * search will be handled temporaly inside the gatt plugin. For the
-	 * final solution all LE operations should be moved to the "core",
-	 * otherwise it will not be possible serialize/schedule BR/EDR device
-	 * discovery and LE scanning.
-	 */
+	int psm = -1;
 
 	rec = btd_device_get_record(device, GATT_UUID);
-	if (!rec)
-		return -1;
-
-	if (sdp_get_access_protos(rec, &list) < 0)
-		return -1;
-
-	psm = sdp_get_proto_port(list, L2CAP_UUID);
-	if (psm < 0)
-		return -1;
+	if (rec) {
+		if (sdp_get_access_protos(rec, &list) < 0)
+			return -1;
+
+		psm = sdp_get_proto_port(list, L2CAP_UUID);
+		if (psm < 0)
+			return -1;
+	}
 
 	return attrib_client_register(device, psm);
 }
diff --git a/src/device.c b/src/device.c
index 7c421e3..f236b29 100644
--- a/src/device.c
+++ b/src/device.c
@@ -111,6 +111,7 @@ struct browse_req {
 
 struct btd_device {
 	bdaddr_t	bdaddr;
+	gboolean	le;
 	gchar		*path;
 	char		name[MAX_NAME_LENGTH + 1];
 	char		*alias;
@@ -215,7 +216,8 @@ static void browse_request_cancel(struct browse_req *req)
 
 	adapter_get_address(adapter, &src);
 
-	bt_cancel_discovery(&src, &device->bdaddr);
+	if (device->le == FALSE)
+		bt_cancel_discovery(&src, &device->bdaddr);
 
 	device->browse = NULL;
 	browse_request_free(req);
@@ -1557,29 +1559,67 @@ static void init_browse(struct browse_req *req, gboolean reverse)
 						l->data);
 }
 
-int device_browse(struct btd_device *device, DBusConnection *conn,
-			DBusMessage *msg, uuid_t *search, gboolean reverse)
+static void primary_cb(GSList *services, int err, gpointer user_data)
+{
+	struct browse_req *req = user_data;
+	struct btd_device *device = req->device;
+
+	if (err) {
+		error_failed_errno(req->conn, req->msg, -err);
+		goto done;
+	}
+
+	services_changed(req->device);
+	device_set_temporary(req->device, FALSE);
+	device_probe_drivers(req->device, services);
+
+	create_device_reply(req->device, req);
+
+done:
+	device->browse = NULL;
+	browse_request_free(req);
+}
+
+static struct browse_req *browse_primary(struct btd_device *device, int *err)
 {
 	struct btd_adapter *adapter = device->adapter;
 	struct browse_req *req;
 	bdaddr_t src;
-	uuid_t uuid;
-	bt_callback_t cb;
-	int err;
+	int ret;
 
-	if (device->browse)
-		return -EBUSY;
+	req = g_new0(struct browse_req, 1);
+	req->device = btd_device_ref(device);
 
 	adapter_get_address(adapter, &src);
 
-	req = g_new0(struct browse_req, 1);
+	ret = bt_discover_primary(&src, &device->bdaddr, -1, primary_cb, req,
+									NULL);
 
-	if (conn == NULL)
-		conn = get_dbus_connection();
+	if (ret < 0) {
+		browse_request_free(req);
+		if (err)
+			*err = ret;
 
-	req->conn = dbus_connection_ref(conn);
-	req->device = btd_device_ref(device);
+		return NULL;
+	}
+
+	return req;
+}
+
+static struct browse_req *browse_sdp(struct btd_device *device, uuid_t *search,
+						gboolean reverse, int *err)
+{
+	struct btd_adapter *adapter = device->adapter;
+	struct browse_req *req;
+	bt_callback_t cb;
+	bdaddr_t src;
+	uuid_t uuid;
+	int ret;
 
+	adapter_get_address(adapter, &src);
+
+	req = g_new0(struct browse_req, 1);
+	req->device = btd_device_ref(device);
 	if (search) {
 		memcpy(&uuid, search, sizeof(uuid_t));
 		cb = search_cb;
@@ -1589,6 +1629,39 @@ int device_browse(struct btd_device *device, DBusConnection *conn,
 		cb = browse_cb;
 	}
 
+	ret = bt_search_service(&src, &device->bdaddr, &uuid, cb, req, NULL);
+	if (ret < 0) {
+		browse_request_free(req);
+		if (err)
+			*err = ret;
+
+		return NULL;
+	}
+
+	return req;
+}
+
+int device_browse(struct btd_device *device, DBusConnection *conn,
+			DBusMessage *msg, uuid_t *search, gboolean reverse)
+{
+	struct browse_req *req;
+	int err = 0;
+
+	if (device->browse)
+		return -EBUSY;
+
+	if (device->le)
+		req = browse_primary(device, &err);
+	else
+		req = browse_sdp(device, search, reverse, &err);
+
+	if (req == NULL)
+		return err;
+
+	if (conn == NULL)
+		conn = get_dbus_connection();
+
+	req->conn = dbus_connection_ref(conn);
 	device->browse = req;
 
 	if (msg) {
@@ -1603,13 +1676,6 @@ int device_browse(struct btd_device *device, DBusConnection *conn,
 						req, NULL);
 	}
 
-	err = bt_search_service(&src, &device->bdaddr,
-				&uuid, cb, req, NULL);
-	if (err < 0) {
-		device->browse = NULL;
-		browse_request_free(req);
-	}
-
 	return err;
 }
 
diff --git a/src/glib-helper.c b/src/glib-helper.c
index 4941d99..f0689d5 100644
--- a/src/glib-helper.c
+++ b/src/glib-helper.c
@@ -42,12 +42,26 @@
 
 #include <glib.h>
 
-#include "glib-helper.h"
+#include "btio.h"
+#include "gattrib.h"
+#include "att.h"
+#include "gatt.h"
 #include "sdpd.h"
+#include "glib-helper.h"
 
 /* Number of seconds to keep a sdp_session_t in the cache */
 #define CACHE_TIMEOUT 2
 
+struct gattrib_context {
+	bdaddr_t src;
+	bdaddr_t dst;
+	GAttrib *attrib;
+	bt_primary_t cb;
+	bt_destroy_t destroy;
+	gpointer user_data;
+	GSList *uuids;
+};
+
 struct cached_sdp_session {
 	bdaddr_t src;
 	bdaddr_t dst;
@@ -57,6 +71,17 @@ struct cached_sdp_session {
 
 static GSList *cached_sdp_sessions = NULL;
 
+static void gattrib_context_free(struct gattrib_context *ctxt)
+{
+	if (ctxt->destroy)
+		ctxt->destroy(ctxt->user_data);
+
+	g_slist_foreach(ctxt->uuids, (GFunc) g_free, NULL);
+	g_slist_free(ctxt->uuids);
+	g_attrib_unref(ctxt->attrib);
+	g_free(ctxt);
+}
+
 static gboolean cached_session_expired(gpointer user_data)
 {
 	struct cached_sdp_session *cached = user_data;
@@ -118,6 +143,7 @@ struct search_context {
 	bdaddr_t		dst;
 	sdp_session_t		*session;
 	bt_callback_t		cb;
+	bt_primary_t		prim_cb;
 	bt_destroy_t		destroy;
 	gpointer		user_data;
 	uuid_t			uuid;
@@ -378,6 +404,125 @@ int bt_cancel_discovery(const bdaddr_t *src, const bdaddr_t *dst)
 	return 0;
 }
 
+static void primary_cb(guint8 status, const guint8 *pdu, guint16 plen,
+							gpointer user_data)
+{
+	struct gattrib_context *ctxt = user_data;
+	struct att_data_list *list;
+	unsigned int i, err;
+	uint16_t end;
+
+	if (status == ATT_ECODE_ATTR_NOT_FOUND) {
+		err = 0;
+		goto done;
+	}
+
+	if (status != 0) {
+		err = -EIO;
+		goto done;
+	}
+
+	list = dec_read_by_grp_resp(pdu, plen);
+	if (list == NULL) {
+		err = -EPROTO;
+		goto done;
+	}
+
+	for (i = 0, end = 0; i < list->num; i++) {
+		const uint8_t *data = list->data[i];
+		char *prim;
+		uuid_t u128, u16;
+
+		end = att_get_u16(&data[2]);
+
+		if (list->len == 6) {
+			sdp_uuid16_create(&u16,
+					att_get_u16(&data[4]));
+			sdp_uuid16_to_uuid128(&u128, &u16);
+
+		} else if (list->len == 20)
+			sdp_uuid128_create(&u128, &data[4]);
+		else
+			/* Skipping invalid data */
+			continue;
+
+		prim = bt_uuid2string(&u128);
+		ctxt->uuids = g_slist_append(ctxt->uuids, prim);
+	}
+
+	att_data_list_free(list);
+	err = 0;
+
+	if (end != 0xffff) {
+		gatt_discover_primary(ctxt->attrib, end + 1, 0xffff, NULL,
+							primary_cb, ctxt);
+		return;
+	}
+
+done:
+	ctxt->cb(ctxt->uuids, err, ctxt->user_data);
+	gattrib_context_free(ctxt);
+}
+
+static void connect_cb(GIOChannel *io, GError *gerr, gpointer user_data)
+{
+	struct gattrib_context *ctxt = user_data;
+
+	if (gerr) {
+		ctxt->cb(NULL, -EIO, ctxt->user_data);
+		gattrib_context_free(ctxt);
+		return;
+	}
+
+	gatt_discover_primary(ctxt->attrib, 0x0001, 0xffff, NULL, primary_cb,
+									ctxt);
+}
+
+int bt_discover_primary(const bdaddr_t *src, const bdaddr_t *dst, int psm,
+					bt_primary_t cb, void *user_data,
+					bt_destroy_t destroy)
+{
+	struct gattrib_context *ctxt;
+	GIOChannel *io;
+	GError *gerr = NULL;
+
+	ctxt = g_try_malloc0(sizeof(struct gattrib_context));
+	if (ctxt == NULL)
+		return -ENOMEM;
+
+	bacpy(&ctxt->src, src);
+	bacpy(&ctxt->dst, dst);
+	ctxt->user_data = user_data;
+	ctxt->cb = cb;
+	ctxt->destroy = destroy;
+
+	if (psm < 0)
+		io = bt_io_connect(BT_IO_L2CAP, connect_cb, ctxt, NULL, &gerr,
+				BT_IO_OPT_SOURCE_BDADDR, src,
+				BT_IO_OPT_DEST_BDADDR, dst,
+				BT_IO_OPT_CID, GATT_CID,
+				BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_LOW,
+				BT_IO_OPT_INVALID);
+	else
+		io = bt_io_connect(BT_IO_L2CAP, connect_cb, ctxt, NULL, &gerr,
+				BT_IO_OPT_SOURCE_BDADDR, src,
+				BT_IO_OPT_DEST_BDADDR, dst,
+				BT_IO_OPT_PSM, psm,
+				BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_LOW,
+				BT_IO_OPT_INVALID);
+
+	if (io == NULL) {
+		gattrib_context_free(ctxt);
+		return -EIO;
+	}
+
+	ctxt->attrib = g_attrib_new(io);
+
+	g_io_channel_unref(io);
+
+	return 0;
+}
+
 char *bt_uuid2string(uuid_t *uuid)
 {
 	gchar *str;
diff --git a/src/glib-helper.h b/src/glib-helper.h
index dfe4123..018ff92 100644
--- a/src/glib-helper.h
+++ b/src/glib-helper.h
@@ -22,6 +22,7 @@
  */
 
 typedef void (*bt_callback_t) (sdp_list_t *recs, int err, gpointer user_data);
+typedef void (*bt_primary_t) (GSList *l, int err, gpointer user_data);
 typedef void (*bt_destroy_t) (gpointer user_data);
 
 int bt_discover_services(const bdaddr_t *src, const bdaddr_t *dst,
@@ -32,6 +33,10 @@ int bt_search_service(const bdaddr_t *src, const bdaddr_t *dst,
 			bt_destroy_t destroy);
 int bt_cancel_discovery(const bdaddr_t *src, const bdaddr_t *dst);
 
+int bt_discover_primary(const bdaddr_t *src, const bdaddr_t *dst, int psm,
+					bt_primary_t cb, void *user_data,
+					bt_destroy_t destroy);
+
 gchar *bt_uuid2string(uuid_t *uuid);
 uint16_t bt_name2class(const char *string);
 char *bt_name2string(const char *string);
-- 
1.7.3.2


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

* [PATCH 2/5] Check the device type when creating the device
  2010-11-24  2:30 [PATCH 1/5] Implements primary service search when creating a device Claudio Takahasi
@ 2010-11-24  2:30 ` Claudio Takahasi
  2010-11-24  2:30 ` [PATCH 3/5] Return a D-Bus error if device_browse fails Claudio Takahasi
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Claudio Takahasi @ 2010-11-24  2:30 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

For CreateDevice, if the remote device is LE capable, Discover All
Primary Services shall be issued instead of SDP queries. The logic
to define if the remote is LE capable shall be based on the result
of the interleaved discovery results. Meaning, the remote device
is classified as LE capable only if an advertising event from this
device was collected during the discovery.

Limitation: Advertising event data is not being considered yet to
infer the remote properties and CreateDevice needs to be called
during the discovery session.
---
 src/adapter.c |   25 +++++++++++++++++--------
 src/adapter.h |    3 ++-
 src/device.c  |    3 ++-
 src/device.h  |    5 +++--
 4 files changed, 24 insertions(+), 12 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 6b4a354..029bec8 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -1199,15 +1199,15 @@ sdp_list_t *adapter_get_services(struct btd_adapter *adapter)
 }
 
 struct btd_device *adapter_create_device(DBusConnection *conn,
-						struct btd_adapter *adapter,
-						const char *address)
+					struct btd_adapter *adapter,
+					const char *address, gboolean le)
 {
 	struct btd_device *device;
 	const char *path;
 
 	DBG("%s", address);
 
-	device = device_create(conn, adapter, address);
+	device = device_create(conn, adapter, address, le);
 	if (!device)
 		return NULL;
 
@@ -1266,7 +1266,7 @@ struct btd_device *adapter_get_device(DBusConnection *conn,
 	if (device)
 		return device;
 
-	return adapter_create_device(conn, adapter, address);
+	return adapter_create_device(conn, adapter, address, FALSE);
 }
 
 static gboolean stop_scanning(gpointer user_data)
@@ -1693,7 +1693,9 @@ static DBusMessage *create_device(DBusConnection *conn,
 {
 	struct btd_adapter *adapter = data;
 	struct btd_device *device;
+	struct remote_dev_info *dev, match;
 	const gchar *address;
+	gboolean le;
 
 	if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &address,
 						DBUS_TYPE_INVALID) == FALSE)
@@ -1709,7 +1711,14 @@ static DBusMessage *create_device(DBusConnection *conn,
 
 	DBG("%s", address);
 
-	device = adapter_create_device(conn, adapter, address);
+	memset(&match, 0, sizeof(struct remote_dev_info));
+	str2ba(address, &match.bdaddr);
+	match.name_status = NAME_ANY;
+
+	dev = adapter_search_found_devices(adapter, &match);
+	le  = dev ? dev->le : FALSE;
+
+	device = adapter_create_device(conn, adapter, address, le);
 	if (!device)
 		return NULL;
 
@@ -2003,7 +2012,7 @@ static void create_stored_device_from_profiles(char *key, char *value,
 				key, (GCompareFunc) device_address_cmp))
 		return;
 
-	device = device_create(connection, adapter, key);
+	device = device_create(connection, adapter, key, FALSE);
 	if (!device)
 		return;
 
@@ -2026,7 +2035,7 @@ static void create_stored_device_from_linkkeys(char *key, char *value,
 					(GCompareFunc) device_address_cmp))
 		return;
 
-	device = device_create(connection, adapter, key);
+	device = device_create(connection, adapter, key, FALSE);
 	if (device) {
 		device_set_temporary(device, FALSE);
 		adapter->devices = g_slist_append(adapter->devices, device);
@@ -2043,7 +2052,7 @@ static void create_stored_device_from_blocked(char *key, char *value,
 				key, (GCompareFunc) device_address_cmp))
 		return;
 
-	device = device_create(connection, adapter, key);
+	device = device_create(connection, adapter, key, FALSE);
 	if (device) {
 		device_set_temporary(device, FALSE);
 		adapter->devices = g_slist_append(adapter->devices, device);
diff --git a/src/adapter.h b/src/adapter.h
index de6a6f5..4f5ccdb 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -109,7 +109,8 @@ void adapter_remove_device(DBusConnection *conn, struct btd_adapter *adapter,
 						struct btd_device *device,
 						gboolean remove_storage);
 struct btd_device *adapter_create_device(DBusConnection *conn,
-				struct btd_adapter *adapter, const char *address);
+					struct btd_adapter *adapter,
+					const char *address, gboolean le);
 
 int adapter_resolve_names(struct btd_adapter *adapter);
 
diff --git a/src/device.c b/src/device.c
index f236b29..1c119d5 100644
--- a/src/device.c
+++ b/src/device.c
@@ -965,7 +965,7 @@ void device_set_secmode3_conn(struct btd_device *device, gboolean enable)
 
 struct btd_device *device_create(DBusConnection *conn,
 					struct btd_adapter *adapter,
-					const gchar *address)
+					const gchar *address, gboolean le)
 {
 	gchar *address_up;
 	struct btd_device *device;
@@ -993,6 +993,7 @@ struct btd_device *device_create(DBusConnection *conn,
 
 	str2ba(address, &device->bdaddr);
 	device->adapter = adapter;
+	device->le = le;
 	adapter_get_address(adapter, &src);
 	ba2str(&src, srcaddr);
 	read_device_name(srcaddr, address, device->name);
diff --git a/src/device.h b/src/device.h
index b570bd1..a5b6273 100644
--- a/src/device.h
+++ b/src/device.h
@@ -34,8 +34,9 @@ typedef enum {
 	AUTH_TYPE_AUTO,
 } auth_type_t;
 
-struct btd_device *device_create(DBusConnection *conn, struct btd_adapter *adapter,
-				const gchar *address);
+struct btd_device *device_create(DBusConnection *conn,
+					struct btd_adapter *adapter,
+					const gchar *address, gboolean le);
 void device_set_name(struct btd_device *device, const char *name);
 void device_get_name(struct btd_device *device, char *name, size_t len);
 void device_remove(struct btd_device *device, gboolean remove_stored);
-- 
1.7.3.2


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

* [PATCH 3/5] Return a D-Bus error if device_browse fails
  2010-11-24  2:30 [PATCH 1/5] Implements primary service search when creating a device Claudio Takahasi
  2010-11-24  2:30 ` [PATCH 2/5] Check the device type when creating the device Claudio Takahasi
@ 2010-11-24  2:30 ` Claudio Takahasi
  2010-11-24  2:30 ` [PATCH 4/5] Fix memory leak of sdp list in the attribute client Claudio Takahasi
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Claudio Takahasi @ 2010-11-24  2:30 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

If Discover All Primary Services or SDP search fails, the CreateDevice
caller will not receive a response. Error reproducible when a Discover
All Primary Services is sent over a LE link and the kernel doesn't
address properly the connections in the channel ID 4.
---
 src/adapter.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 029bec8..6c3396c 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -1696,6 +1696,7 @@ static DBusMessage *create_device(DBusConnection *conn,
 	struct remote_dev_info *dev, match;
 	const gchar *address;
 	gboolean le;
+	int err;
 
 	if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &address,
 						DBUS_TYPE_INVALID) == FALSE)
@@ -1722,7 +1723,9 @@ static DBusMessage *create_device(DBusConnection *conn,
 	if (!device)
 		return NULL;
 
-	device_browse(device, conn, msg, NULL, FALSE);
+	err = device_browse(device, conn, msg, NULL, FALSE);
+	if (err < 0)
+		return failed_strerror(msg, -err);
 
 	return NULL;
 }
-- 
1.7.3.2


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

* [PATCH 4/5] Fix memory leak of sdp list in the attribute client
  2010-11-24  2:30 [PATCH 1/5] Implements primary service search when creating a device Claudio Takahasi
  2010-11-24  2:30 ` [PATCH 2/5] Check the device type when creating the device Claudio Takahasi
  2010-11-24  2:30 ` [PATCH 3/5] Return a D-Bus error if device_browse fails Claudio Takahasi
@ 2010-11-24  2:30 ` Claudio Takahasi
  2010-11-24  2:30 ` [PATCH 5/5] Don't trigger the discovering when registering the client Claudio Takahasi
  2010-11-29 17:21 ` [PATCH 1/5] Implements primary service search when creating a device Johan Hedberg
  4 siblings, 0 replies; 6+ messages in thread
From: Claudio Takahasi @ 2010-11-24  2:30 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

---
 attrib/manager.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/attrib/manager.c b/attrib/manager.c
index 9b06c8c..f991f8e 100644
--- a/attrib/manager.c
+++ b/attrib/manager.c
@@ -44,15 +44,19 @@ static DBusConnection *connection;
 static int client_probe(struct btd_device *device, GSList *uuids)
 {
 	const sdp_record_t *rec;
-	sdp_list_t *list;
 	int psm = -1;
 
 	rec = btd_device_get_record(device, GATT_UUID);
 	if (rec) {
+		sdp_list_t *list;
 		if (sdp_get_access_protos(rec, &list) < 0)
 			return -1;
 
 		psm = sdp_get_proto_port(list, L2CAP_UUID);
+
+		sdp_list_foreach(list, (sdp_list_func_t) sdp_list_free, NULL);
+		sdp_list_free(list, NULL);
+
 		if (psm < 0)
 			return -1;
 	}
-- 
1.7.3.2


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

* [PATCH 5/5] Don't trigger the discovering when registering the client
  2010-11-24  2:30 [PATCH 1/5] Implements primary service search when creating a device Claudio Takahasi
                   ` (2 preceding siblings ...)
  2010-11-24  2:30 ` [PATCH 4/5] Fix memory leak of sdp list in the attribute client Claudio Takahasi
@ 2010-11-24  2:30 ` Claudio Takahasi
  2010-11-29 17:21 ` [PATCH 1/5] Implements primary service search when creating a device Johan Hedberg
  4 siblings, 0 replies; 6+ messages in thread
From: Claudio Takahasi @ 2010-11-24  2:30 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

Discover All Primary Services should not be trigged by the attribute
client when a given device is registered. Discover services is now done
by the device entity.
---
 attrib/client.c |   47 +----------------------------------------------
 1 files changed, 1 insertions(+), 46 deletions(-)

diff --git a/attrib/client.c b/attrib/client.c
index a851a74..a8a4051 100644
--- a/attrib/client.c
+++ b/attrib/client.c
@@ -1322,16 +1322,8 @@ int attrib_client_register(struct btd_device *device, int psm)
 	struct btd_adapter *adapter = device_get_adapter(device);
 	const char *path = device_get_path(device);
 	struct gatt_service *gatt;
-	GError *gerr = NULL;
-	GIOChannel *io;
 	bdaddr_t sba, dba;
 
-	/*
-	 * Registering fake services/characteristics. The following
-	 * paths/interfaces shall be registered after discover primary
-	 * services only.
-	 */
-
 	adapter_get_address(adapter, &sba);
 	device_get_address(device, &dba);
 
@@ -1343,46 +1335,9 @@ int attrib_client_register(struct btd_device *device, int psm)
 	bacpy(&gatt->dba, &dba);
 	gatt->psm = psm;
 
-	if (load_primary_services(gatt)) {
+	if (load_primary_services(gatt))
 		DBG("Primary services loaded");
-		goto done;
-	}
-
-	if (psm < 0) {
-		io = bt_io_connect(BT_IO_L2CAP, connect_cb, gatt, NULL, &gerr,
-					BT_IO_OPT_SOURCE_BDADDR, &sba,
-					BT_IO_OPT_DEST_BDADDR, &dba,
-					BT_IO_OPT_CID, GATT_CID,
-					BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_LOW,
-					BT_IO_OPT_INVALID);
-
-			DBG("GATT over Low Energy");
-	} else {
-		io = bt_io_connect(BT_IO_L2CAP, connect_cb, gatt, NULL, &gerr,
-					BT_IO_OPT_SOURCE_BDADDR, &sba,
-					BT_IO_OPT_DEST_BDADDR, &dba,
-					BT_IO_OPT_PSM, psm,
-					BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_LOW,
-					BT_IO_OPT_INVALID);
-
-		DBG("GATT over Basic Rate");
-	}
-
-	if (!io) {
-		error("%s", gerr->message);
-		g_error_free(gerr);
-		gatt_service_free(gatt);
-		return -1;
-	}
-
-	gatt->attrib = g_attrib_new(io);
-	g_io_channel_unref(io);
 
-	g_attrib_set_destroy_function(gatt->attrib, attrib_destroy, gatt);
-	g_attrib_set_disconnect_function(gatt->attrib, attrib_disconnect,
-									gatt);
-
-done:
 	gatt_services = g_slist_append(gatt_services, gatt);
 
 	return 0;
-- 
1.7.3.2


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

* Re: [PATCH 1/5] Implements primary service search when creating a device
  2010-11-24  2:30 [PATCH 1/5] Implements primary service search when creating a device Claudio Takahasi
                   ` (3 preceding siblings ...)
  2010-11-24  2:30 ` [PATCH 5/5] Don't trigger the discovering when registering the client Claudio Takahasi
@ 2010-11-29 17:21 ` Johan Hedberg
  4 siblings, 0 replies; 6+ messages in thread
From: Johan Hedberg @ 2010-11-29 17:21 UTC (permalink / raw)
  To: Claudio Takahasi; +Cc: linux-bluetooth

Hi Claudio,

On Wed, Nov 24, 2010, Claudio Takahasi wrote:
> Discover primary services implemented inside the device entity to allow
> proper integration of attribute plugin. Implements a single entry point
> to the attribute plugin no matter the transport(BR/EDR or LE), the device
> probe callback is called for both types.
> 
> Add a new function to discover all primary services without additional
> calls to fetch the remaining primary services, sub-procedure iterations
> is handled inside this function.
> 
> The next action are: clean the attribute client removing implicity service
> and characteristics discovery, issue the Discover Primary Service based on
> the remote properties and fetch the characteristic on demand.
> ---
>  attrib/manager.c  |   27 +++-------
>  src/device.c      |  106 +++++++++++++++++++++++++++++++-------
>  src/glib-helper.c |  147 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
>  src/glib-helper.h |    5 ++
>  4 files changed, 246 insertions(+), 39 deletions(-)

All five patches have been pushed upstream. Thanks.

Johan

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

end of thread, other threads:[~2010-11-29 17:21 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-11-24  2:30 [PATCH 1/5] Implements primary service search when creating a device Claudio Takahasi
2010-11-24  2:30 ` [PATCH 2/5] Check the device type when creating the device Claudio Takahasi
2010-11-24  2:30 ` [PATCH 3/5] Return a D-Bus error if device_browse fails Claudio Takahasi
2010-11-24  2:30 ` [PATCH 4/5] Fix memory leak of sdp list in the attribute client Claudio Takahasi
2010-11-24  2:30 ` [PATCH 5/5] Don't trigger the discovering when registering the client Claudio Takahasi
2010-11-29 17:21 ` [PATCH 1/5] Implements primary service search when creating a device Johan Hedberg

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