cyclingspeed: Discover CCC using gatt_discover_desc

This commit is contained in:
Andrzej Kaczmarek 2014-05-02 12:57:38 +02:00 committed by Johan Hedberg
parent 87d9617b06
commit d83acdf45f

View File

@ -419,13 +419,12 @@ static void read_location_cb(guint8 status, const guint8 *pdu,
CYCLINGSPEED_INTERFACE, "Location");
}
static void discover_desc_cb(guint8 status, const guint8 *pdu,
guint16 len, gpointer user_data)
static void discover_desc_cb(guint8 status, GSList *descs, gpointer user_data)
{
struct characteristic *ch = user_data;
struct att_data_list *list = NULL;
uint8_t format;
int i;
struct gatt_desc *desc;
uint8_t attr_val[2];
char *msg = NULL;
if (status != 0) {
error("Discover %s descriptors failed: %s", ch->uuid,
@ -433,28 +432,11 @@ static void discover_desc_cb(guint8 status, const guint8 *pdu,
goto done;
}
list = dec_find_info_resp(pdu, len, &format);
if (list == NULL)
goto done;
if (format != ATT_FIND_INFO_RESP_FMT_16BIT)
goto done;
for (i = 0; i < list->num; i++) {
uint8_t *value;
uint16_t handle, uuid;
uint8_t attr_val[2];
char *msg;
value = list->data[i];
handle = get_le16(value);
uuid = get_le16(value + 2);
if (uuid != GATT_CLIENT_CHARAC_CFG_UUID)
continue;
/* There will be only one descriptor on list and it will be CCC */
desc = descs->data;
if (g_strcmp0(ch->uuid, CSC_MEASUREMENT_UUID) == 0) {
ch->csc->measurement_ccc_handle = handle;
ch->csc->measurement_ccc_handle = desc->handle;
if (g_slist_length(ch->csc->cadapter->watchers) == 0) {
put_le16(0x0000, attr_val);
@ -464,24 +446,17 @@ static void discover_desc_cb(guint8 status, const guint8 *pdu,
attr_val);
msg = g_strdup("Enable measurement");
}
} else if (g_strcmp0(ch->uuid, SC_CONTROL_POINT_UUID) == 0) {
put_le16(GATT_CLIENT_CHARAC_CFG_IND_BIT, attr_val);
msg = g_strdup("Enable SC Control Point indications");
} else {
break;
goto done;
}
gatt_write_char(ch->csc->attrib, handle, attr_val,
gatt_write_char(ch->csc->attrib, desc->handle, attr_val,
sizeof(attr_val), char_write_cb, msg);
/* We only want CCC, can break here */
break;
}
done:
if (list)
att_data_list_free(list);
g_free(ch);
}
@ -490,6 +465,7 @@ static void discover_desc(struct csc *csc, struct gatt_char *c,
{
struct characteristic *ch;
uint16_t start, end;
bt_uuid_t uuid;
start = c->value_handle + 1;
@ -507,7 +483,10 @@ static void discover_desc(struct csc *csc, struct gatt_char *c,
ch->csc = csc;
memcpy(ch->uuid, c->uuid, sizeof(c->uuid));
gatt_discover_char_desc(csc->attrib, start, end, discover_desc_cb, ch);
bt_uuid16_create(&uuid, GATT_CLIENT_CHARAC_CFG_UUID);
gatt_discover_desc(csc->attrib, start, end, &uuid, discover_desc_cb,
ch);
}
static void update_watcher(gpointer data, gpointer user_data)