aboutsummaryrefslogtreecommitdiffstats
path: root/attrib/client.c
diff options
context:
space:
mode:
authorVinicius Costa Gomes <vinicius.gomes@openbossa.org>2010-08-05 17:13:50 -0300
committerJohan Hedberg <johan.hedberg@nokia.com>2010-08-09 18:06:49 -0400
commitc2b9e70040defcf6105e5704e4f0a6b16072193a (patch)
treedc06c34cfa16076ed66a0d0b7cc24d0f34838806 /attrib/client.c
parentc4fe3b3a0b3da660d3ec59bfc392bd05c9a29e5a (diff)
downloadbluez-c2b9e70040defcf6105e5704e4f0a6b16072193a.tar.gz
bluez-c2b9e70040defcf6105e5704e4f0a6b16072193a.tar.xz
bluez-c2b9e70040defcf6105e5704e4f0a6b16072193a.zip
Add support for discovering all the descriptors
All descriptors associated to every characteristic are discovered, which means, that we know its handle and type. With this information we can later read the values of the descriptors that we find interesting.
Diffstat (limited to 'attrib/client.c')
-rw-r--r--attrib/client.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/attrib/client.c b/attrib/client.c
index 422d30f7..4ca2ea35 100644
--- a/attrib/client.c
+++ b/attrib/client.c
@@ -64,6 +64,8 @@ struct characteristic {
uint16_t end;
uint8_t perm;
uuid_t type;
+ char *name;
+ char *desc;
};
struct primary {
@@ -79,6 +81,11 @@ struct discovered_data {
struct primary *prim;
};
+struct descriptor_data {
+ struct gatt_service *gatt;
+ struct characteristic *chr;
+};
+
static GSList *services = NULL;
static DBusConnection *connection;
@@ -366,6 +373,60 @@ static void load_characteristics(gpointer data, gpointer user_data)
return;
}
+static void descriptor_cb(guint8 status, const guint8 *pdu, guint16 plen,
+ gpointer user_data)
+{
+ struct descriptor_data *current = user_data;
+ struct att_data_list *list;
+ guint8 format;
+ int i;
+
+ if (status != 0)
+ goto fail;
+
+ DBG("Find Information Response received");
+
+ list = dec_find_info_resp(pdu, plen, &format);
+ if (list == NULL) {
+ g_free(current);
+ return;
+ }
+
+ for (i = 0; i < list->num; i++) {
+ guint16 handle;
+ uuid_t uuid;
+ guint16 *u16;
+ uint8_t *info = list->data[i];
+
+ u16 = (void *) info;
+ handle = btohs(*u16);
+
+ if (format == 0x01) {
+ u16 = (void *) &info[2];
+ sdp_uuid16_create(&uuid, btohs(*u16));
+ }
+
+ /* FIXME: do something useful here */
+ }
+
+fail:
+ g_free(current);
+}
+
+static void find_all_descriptors(gpointer data, gpointer user_data)
+{
+ struct descriptor_data *current;
+ struct characteristic *chr = data;
+ struct gatt_service *gatt = user_data;
+
+ current = g_new0(struct descriptor_data, 1);
+ current->gatt = gatt;
+ current->chr = chr;
+
+ gatt_find_info(gatt->attrib, chr->handle, chr->end, descriptor_cb,
+ current);
+}
+
static void char_discovered_cb(guint8 status, const guint8 *pdu, guint16 plen,
gpointer user_data)
{
@@ -379,6 +440,8 @@ static void char_discovered_cb(guint8 status, const guint8 *pdu, guint16 plen,
if (status == ATT_ECODE_ATTR_NOT_FOUND) {
store_characteristics(gatt, prim);
register_characteristics(prim);
+
+ g_slist_foreach(prim->chars, find_all_descriptors, gatt);
g_free(current);
return;
}