Discover and store each of the Heart Rate Service characteristic descriptors. --- profiles/heartrate/heartrate.c | 61 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/profiles/heartrate/heartrate.c b/profiles/heartrate/heartrate.c index 1114cff..e917f27 100644 --- a/profiles/heartrate/heartrate.c +++ b/profiles/heartrate/heartrate.c @@ -47,9 +47,16 @@ struct heartrate { struct characteristic { struct gatt_char attr; /*Characteristic*/ + GSList *desc; /*Descriptors*/ struct heartrate *hr; /*Parent Heart Rate Service*/ }; +struct descriptor { + struct characteristic *ch; + uint16_t handle; + bt_uuid_t uuid; +}; + static GSList *hr_servers = NULL; static gint cmp_device(gconstpointer a, gconstpointer b) @@ -82,6 +89,44 @@ static void heartrate_destroy(gpointer user_data) } +static void discover_desc_cb(guint8 status, const guint8 *pdu, + guint16 len, gpointer user_data) +{ + struct characteristic *ch = user_data; + struct att_data_list *list; + uint8_t format; + int i; + + if (status != 0) { + error("Discover all characteristic descriptors failed [%s]: %s", + ch->attr.uuid, att_ecode2str(status)); + return; + } + + list = dec_find_info_resp(pdu, len, &format); + if (list == NULL) + return; + + for (i = 0; i < list->num; i++) { + struct descriptor *desc; + uint8_t *value; + + value = list->data[i]; + desc = g_new0(struct descriptor, 1); + desc->handle = att_get_u16(value); + desc->ch = ch; + + if (format == 0x01) + desc->uuid = att_get_uuid16(&value[2]); + else + desc->uuid = att_get_uuid128(&value[2]); + + ch->desc = g_slist_append(ch->desc, desc); + } + + att_data_list_free(list); +} + static void configure_heartrate_cb(GSList *characteristics, guint8 status, gpointer user_data) { @@ -97,6 +142,7 @@ static void configure_heartrate_cb(GSList *characteristics, guint8 status, for (l = characteristics; l; l = l->next) { struct gatt_char *c = l->data; struct characteristic *ch; + uint16_t start, end; ch = g_new0(struct characteristic, 1); ch->attr.handle = c->handle; @@ -106,6 +152,21 @@ static void configure_heartrate_cb(GSList *characteristics, guint8 status, ch->hr = hr; hr->chars = g_slist_append(hr->chars, ch); + + start = c->value_handle + 1; + + if (l->next != NULL) { + struct gatt_char *c = l->next->data; + if (start == c->handle) + continue; + end = c->handle - 1; + } else if (c->value_handle != hr->svc_range->end) { + end = hr->svc_range->end; + } else { + continue; + } + + gatt_find_info(hr->attrib, start, end, discover_desc_cb, ch); } } -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html