Diff between f7610d058c9940564609f29ffe7cc4e4d74b7d85 and 5fb7e25988e888c2cf3e16c031d793cc24f2ff02

Changed Files

File Additions Deletions Status
deviceinfo/deviceinfo.c +46 -1 modified
deviceinfo/deviceinfo.h +1 -1 modified
deviceinfo/manager.c +21 -1 modified

Full Patch

diff --git a/deviceinfo/deviceinfo.c b/deviceinfo/deviceinfo.c
index 150b061..8e4e8cb 100644
--- a/deviceinfo/deviceinfo.c
+++ b/deviceinfo/deviceinfo.c
@@ -33,16 +33,26 @@
 #include "att.h"
 #include "gattrib.h"
 #include "gatt.h"
+#include "log.h"
 #include "deviceinfo.h"
 
+#define PNPID_UUID		"00002a50-0000-1000-8000-00805f9b34fb"
+
 struct deviceinfo {
 	struct btd_device	*dev;		/* Device reference */
 	GAttrib			*attrib;	/* GATT connection */
 	guint			attioid;	/* Att watcher id */
+	struct att_range	*svc_range;	/* DeviceInfo range */
+	GSList			*chars;		/* Characteristics */
 };
 
 static GSList *servers = NULL;
 
+struct characteristic {
+	struct gatt_char	attr;	/* Characteristic */
+	struct deviceinfo	*d;	/* deviceinfo where the char belongs */
+};
+
 static void deviceinfo_free(gpointer user_data)
 {
 	struct deviceinfo *d = user_data;
@@ -53,7 +63,10 @@ static void deviceinfo_free(gpointer user_data)
 	if (d->attrib != NULL)
 		g_attrib_unref(d->attrib);
 
+	g_slist_free_full(d->chars, g_free);
+
 	btd_device_unref(d->dev);
+	g_free(d->svc_range);
 	g_free(d);
 }
 
@@ -68,11 +81,40 @@ static gint cmp_device(gconstpointer a, gconstpointer b)
 	return -1;
 }
 
+static void configure_deviceinfo_cb(GSList *characteristics, guint8 status,
+							gpointer user_data)
+{
+	struct deviceinfo *d = user_data;
+	GSList *l;
+
+	if (status != 0) {
+		error("Discover deviceinfo characteristics: %s",
+							att_ecode2str(status));
+		return;
+	}
+
+	for (l = characteristics; l; l = l->next) {
+		struct gatt_char *c = l->data;
+		struct characteristic *ch;
+
+		ch = g_new0(struct characteristic, 1);
+		ch->attr.handle = c->handle;
+		ch->attr.properties = c->properties;
+		ch->attr.value_handle = c->value_handle;
+		memcpy(ch->attr.uuid, c->uuid, MAX_LEN_UUID_STR + 1);
+		ch->d = d;
+
+		d->chars = g_slist_append(d->chars, ch);
+	}
+}
 static void attio_connected_cb(GAttrib *attrib, gpointer user_data)
 {
 	struct deviceinfo *d = user_data;
 
 	d->attrib = g_attrib_ref(attrib);
+
+	gatt_discover_char(d->attrib, d->svc_range->start, d->svc_range->end,
+					NULL, configure_deviceinfo_cb, d);
 }
 
 static void attio_disconnected_cb(gpointer user_data)
@@ -83,12 +125,15 @@ static void attio_disconnected_cb(gpointer user_data)
 	d->attrib = NULL;
 }
 
-int deviceinfo_register(struct btd_device *device)
+int deviceinfo_register(struct btd_device *device, struct gatt_primary *prim)
 {
 	struct deviceinfo *d;
 
 	d = g_new0(struct deviceinfo, 1);
 	d->dev = btd_device_ref(device);
+	d->svc_range = g_new0(struct att_range, 1);
+	d->svc_range->start = prim->range.start;
+	d->svc_range->end = prim->range.end;
 
 	servers = g_slist_prepend(servers, d);
 
diff --git a/deviceinfo/deviceinfo.h b/deviceinfo/deviceinfo.h
index 0ea6ff5..7a804a5 100644
--- a/deviceinfo/deviceinfo.h
+++ b/deviceinfo/deviceinfo.h
@@ -20,5 +20,5 @@
  *
  */
 
-int deviceinfo_register(struct btd_device *device);
+int deviceinfo_register(struct btd_device *device, struct gatt_primary *prim);
 void deviceinfo_unregister(struct btd_device *device);
diff --git a/deviceinfo/manager.c b/deviceinfo/manager.c
index d5de171..c2378c2 100644
--- a/deviceinfo/manager.c
+++ b/deviceinfo/manager.c
@@ -34,9 +34,29 @@
 
 #define DEVICE_INFORMATION_UUID		"0000180a-0000-1000-8000-00805f9b34fb"
 
+static gint primary_uuid_cmp(gconstpointer a, gconstpointer b)
+{
+	const struct gatt_primary *prim = a;
+	const char *uuid = b;
+
+	return g_strcmp0(prim->uuid, uuid);
+}
+
 static int deviceinfo_driver_probe(struct btd_device *device, GSList *uuids)
 {
-	return deviceinfo_register(device);
+	struct gatt_primary *prim;
+	GSList *primaries, *l;
+
+	primaries = btd_device_get_primaries(device);
+
+	l = g_slist_find_custom(primaries, DEVICE_INFORMATION_UUID,
+							primary_uuid_cmp);
+	if (l == NULL)
+		return -EINVAL;
+
+	prim = l->data;
+
+	return deviceinfo_register(device, prim);
 }
 
 static void deviceinfo_driver_remove(struct btd_device *device)