* Reference table 3.5: Characteristic Properties bit field.
*/
- attr = btd_gatt_add_char(&uuid, 0x00);
+ attr = btd_gatt_add_char(&uuid, 0x00, NULL);
if (attr == NULL)
return -EINVAL;
struct btd_attribute {
uint16_t handle;
bt_uuid_t type;
+ btd_attr_read_t read_cb;
uint16_t value_len;
uint8_t value[0];
};
}
struct btd_attribute *btd_gatt_add_char(const bt_uuid_t *uuid,
- uint8_t properties)
+ uint8_t properties,
+ btd_attr_read_t read_cb)
{
struct btd_attribute *char_decl, *char_value = NULL;
*/
char_value->type = *uuid;
+ char_value->read_cb = read_cb;
- /* TODO: Read & Write callbacks */
+ /* TODO: Write callbacks */
if (local_database_add(next_handle, char_value) < 0)
/* TODO: remove declaration */
void gatt_cleanup(void);
+/*
+ * Callbacks of this type are called once the value from the attribute is
+ * ready to be read from the service implementation. Result callback is
+ * the asynchronous function that should be used to inform the caller
+ * the read value.
+ * @err: error in errno format.
+ * @value: pointer to value
+ * @len: length of value
+ * @user_data: user_data passed in btd_attr_read_t callback
+ */
+typedef void (*btd_attr_read_result_t) (int err, uint8_t *value, size_t len,
+ void *user_data);
+typedef void (*btd_attr_read_t) (struct btd_attribute *attr,
+ btd_attr_read_result_t result,
+ void *user_data);
+
/* btd_gatt_add_service - Add a service declaration to local attribute database.
* @uuid: Service UUID.
*
* to local attribute database.
* @uuid: Characteristic UUID (16-bits or 128-bits).
* @properties: Characteristic properties. See Core SPEC 4.1 page 2183.
+ * @read_cb: Callback used to provide the characteristic value.
*
* Returns a reference to characteristic value attribute. In case of error,
* NULL is returned.
*/
struct btd_attribute *btd_gatt_add_char(const bt_uuid_t *uuid,
- uint8_t properties);
+ uint8_t properties,
+ btd_attr_read_t read_cb);