Bluetooth: Add macro for CEP and long descriptors

Add BT_GATT_CEP and BT_GATT_LONG_DESCRIPTOR so which can be used by
a task to declare long attributes.

Change-Id: I37a0bb1851b60f3cdfa7e2f00ade70d5c344abbf
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This commit is contained in:
Luiz Augusto von Dentz 2015-06-11 15:33:21 +03:00 committed by Anas Nashif
commit 7250393678
2 changed files with 73 additions and 0 deletions

View file

@ -512,6 +512,43 @@ int bt_gatt_attr_write_ccc(const bt_addr_le_t *peer,
.cfg_changed = _cfg_changed, }),\ .cfg_changed = _cfg_changed, }),\
} }
/*! @brief Read Characteristic Extended Properties Attribute helper
*
* Read CEP attribute value storing the result into buffer after
* enconding it.
* NOTE: Only use this with attributes which user_data is a bt_gatt_cep.
*
* @param peer remote address
* @param attr attribute to read
* @param buf buffer to store the value read
* @param len buffer length
* @param offset start offset
*
* @return number of bytes read in case of success or negative values in
* case of error.
*/
int bt_gatt_attr_read_cep(const bt_addr_le_t *peer,
const struct bt_gatt_attr *attr, void *buf,
uint8_t len, uint16_t offset);
/*! @def BT_GATT_CEP
* @brief Characteristic Extended Properties Declaration Macro.
*
* Helper macro to declare a CEP attribute.
*
* @param _handle descriptor attribute handle.
* @param _value descriptor attribute value.
*/
#define BT_GATT_CEP(_handle, _value) \
{ \
.handle = _handle, \
.uuid = (&(struct bt_uuid) { .type = BT_UUID_16, \
.u16 = BT_UUID_GATT_CEP }), \
.perm = BT_GATT_PERM_READ, \
.read = bt_gatt_attr_read_cep, \
.user_data = _value, \
}
/*! @def BT_GATT_DESCRIPTOR /*! @def BT_GATT_DESCRIPTOR
* @brief Descriptor Declaration Macro. * @brief Descriptor Declaration Macro.
* *
@ -534,6 +571,31 @@ int bt_gatt_attr_write_ccc(const bt_addr_le_t *peer,
.user_data = _value, \ .user_data = _value, \
} }
/*! @def BT_GATT_LONG_DESCRIPTOR
* @brief Descriptor Declaration Macro.
*
* Helper macro to declare a descriptor attribute.
*
* @param _handle descriptor attribute handle.
* @param _value descriptor attribute value.
* @param _perm descriptor attribute access permissions.
* @param _read descriptor attribute read callback.
* @param _write descriptor attribute write callback.
* @param _flush descriptor attribute flush callback.
* @param _value descriptor attribute value.
*/
#define BT_GATT_LONG_DESCRIPTOR(_handle, _uuid, _perm, _read, _write, _flush, \
_value) \
{ \
.handle = _handle, \
.uuid = _uuid, \
.perm = _perm, \
.read = _read, \
.write = _write, \
.flush = _flush, \
.user_data = _value, \
}
/*! @brief Notify attribute value change. /*! @brief Notify attribute value change.
* *
* Send notification of attribute value change. * Send notification of attribute value change.

View file

@ -277,6 +277,17 @@ int bt_gatt_attr_write_ccc(const bt_addr_le_t *peer,
return len; return len;
} }
int bt_gatt_attr_read_cep(const bt_addr_le_t *peer,
const struct bt_gatt_attr *attr, void *buf,
uint8_t len, uint16_t offset)
{
struct bt_gatt_cep *value = attr->user_data;
uint16_t props = sys_cpu_to_le16(value->properties);
return bt_gatt_attr_read(peer, attr, buf, len, offset, &props,
sizeof(props));
}
struct notify_data { struct notify_data {
uint8_t handle; uint8_t handle;
const void *data; const void *data;