diff --git a/android/gatt.c b/android/gatt.c
index ebda377..67a1330 100644
--- a/android/gatt.c
+++ b/android/gatt.c
return ATT_ECODE_REQ_NOT_SUPP;
}
- if (!gatt_db_read(gatt_db, handle, offset, cmd[0], &dev->bdaddr))
+ if (!gatt_db_read(gatt_db, handle, offset, cmd[0], &dev->bdaddr, NULL,
+ NULL))
return ATT_ECODE_UNLIKELY;
return 0;
diff --git a/src/shared/gatt-db.c b/src/shared/gatt-db.c
index ebfd586..41db7d2 100644
--- a/src/shared/gatt-db.c
+++ b/src/shared/gatt-db.c
}
bool gatt_db_read(struct gatt_db *db, uint16_t handle, uint16_t offset,
- uint8_t att_opcode, bdaddr_t *bdaddr)
+ uint8_t att_opcode, bdaddr_t *bdaddr,
+ uint8_t **value, int *length)
{
struct gatt_db_service *service;
uint16_t service_handle;
struct gatt_db_attribute *a;
+ if (!value || !length)
+ return false;
+
service = queue_find(db->services, find_service_for_handle,
INT_TO_PTR(handle));
if (!service)
service_handle = service->attributes[0]->handle;
a = service->attributes[handle - service_handle];
- if (!a || !a->read_func)
+ if (!a)
return false;
- a->read_func(handle, offset, att_opcode, bdaddr, a->user_data);
+ /*
+ * We call callback, and set length to -1, to notify user that callback
+ * has been called. Otherwise we set length to value length in database.
+ */
+ if (a->read_func) {
+ *value = NULL;
+ *length = -1;
+ a->read_func(handle, offset, att_opcode, bdaddr, a->user_data);
+ } else {
+ if (offset > a->value_len)
+ return false;
+
+ *value = &a->value[offset];
+ *length = a->value_len - offset;
+ }
return true;
}
diff --git a/src/shared/gatt-db.h b/src/shared/gatt-db.h
index f704b8e..62bac41 100644
--- a/src/shared/gatt-db.h
+++ b/src/shared/gatt-db.h
struct queue *queue);
bool gatt_db_read(struct gatt_db *db, uint16_t handle, uint16_t offset,
- uint8_t att_opcode, bdaddr_t *bdaddr);
+ uint8_t att_opcode, bdaddr_t *bdaddr,
+ uint8_t **value, int *length);
bool gatt_db_write(struct gatt_db *db, uint16_t handle, uint16_t offset,
const uint8_t *value, size_t len,