gatt_db_attribute_get_index was calculating the index based on
attrib->handle - service->attributes[0]->handle which doesn't work when
there are gaps in between handles.
Fixes: https://github.com/bluez/bluez/issues/326
Signed-off-by: Manika Shrivastava <manika.sh@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
return -1;
service = attrib->service;
- index = attrib->handle - service->attributes[0]->handle;
-
- if (index > (service->num_handles - 1))
- return -1;
+ for (index = 0; index < service->num_handles; index++) {
+ if (service->attributes[index] == attrib)
+ return index;
+ }
- return index;
+ return -1;
}
static struct gatt_db_attribute *