Bluetooth: GATT: Fix Read by Group Type response

This fixes bug where wrong service handles have been sent while
discovering the primary services. We should skip Secondary Service
contained in range 0x0006-0x0009 in this case:

      ATT: Read By Group Type Response (0x11) len 13
        Attribute data length: 6
        Attribute group list: 2 entries
        Handle range: 0x0001-0x0009
        UUID: Generic Access Profile (0x1800)
        Handle range: 0x000a-0x000e
        UUID: Unknown (0xaa50)

With this patch:

      ATT: Read By Group Type Response (0x11) len 13
        Attribute data length: 6
        Attribute group list: 2 entries
        Handle range: 0x0001-0x0005
        UUID: Generic Access Profile (0x1800)
        Handle range: 0x000a-0x000e
        UUID: Unknown (0xaa50)

Change-Id: I8121521e76476826296a2bedf9e18ef008f81363
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
This commit is contained in:
Mariusz Skamra 2016-01-14 14:50:58 +01:00 committed by Anas Nashif
commit 76bc832607

View file

@ -889,14 +889,21 @@ static uint8_t read_group_cb(const struct bt_gatt_attr *attr, void *user_data)
struct bt_conn *conn = att->chan.conn;
int read;
/* If UUID don't match update group end_handle */
if (bt_uuid_cmp(attr->uuid, data->uuid)) {
/* Update group end_handle if attribute is not a service */
if (bt_uuid_cmp(attr->uuid, BT_UUID_GATT_PRIMARY) &&
bt_uuid_cmp(attr->uuid, BT_UUID_GATT_SECONDARY)) {
if (data->group && attr->handle > data->group->end_handle) {
data->group->end_handle = sys_cpu_to_le16(attr->handle);
}
return BT_GATT_ITER_CONTINUE;
}
/* If Group Type don't match skip */
if (bt_uuid_cmp(attr->uuid, data->uuid)) {
data->group = NULL;
return BT_GATT_ITER_CONTINUE;
}
BT_DBG("handle 0x%04x", attr->handle);
/* Stop if there is no space left */
@ -952,6 +959,7 @@ static uint8_t att_read_group_rsp(struct bt_att *att, struct bt_uuid *uuid,
data.uuid = uuid;
data.rsp = net_buf_add(data.buf, sizeof(*data.rsp));
data.rsp->len = 0;
data.group = NULL;
bt_gatt_foreach_attr(start_handle, end_handle, read_group_cb, &data);