Bluetooth: add CUD descriptor support
In order to support more standard descriptors, the UD macro and helper function are added. Change-Id: Ic9a82658668107b40abc5c98002fe5091dc10f08 Signed-off-by: Louis Caron <louis.caron@intel.com>
This commit is contained in:
parent
b90d2c6dbd
commit
d566c3314b
2 changed files with 44 additions and 6 deletions
|
@ -191,12 +191,6 @@ struct bt_gatt_cep {
|
|||
uint16_t properties;
|
||||
};
|
||||
|
||||
/** @brief Characteristic User Description Attribute Value. */
|
||||
struct bt_gatt_cud {
|
||||
/** Characteristic User Description string. */
|
||||
char *string;
|
||||
};
|
||||
|
||||
/* Client Characteristic Configuration Values */
|
||||
|
||||
/** @def BT_GATT_CCC_NOTIFY
|
||||
|
@ -523,6 +517,41 @@ int bt_gatt_attr_read_cep(struct bt_conn *conn,
|
|||
.user_data = _value, \
|
||||
}
|
||||
|
||||
/** @brief Read Characteristic User Description Descriptor Attribute helper
|
||||
*
|
||||
* Read CUD attribute value storing the result into buffer after
|
||||
* encoding it.
|
||||
* NOTE: Only use this with attributes which user_data is a NULL-terminated C string.
|
||||
*
|
||||
* @param conn Connection object
|
||||
* @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_cud(struct bt_conn *conn,
|
||||
const struct bt_gatt_attr *attr, void *buf,
|
||||
uint16_t len, uint16_t offset);
|
||||
|
||||
/** @def BT_GATT_CUD
|
||||
* @brief Characteristic User Format Descriptor Declaration Macro.
|
||||
*
|
||||
* Helper macro to declare a CUD attribute.
|
||||
*
|
||||
* @param _value User description NULL-terminated C string.
|
||||
* @param _perm Descriptor attribute access permissions.
|
||||
*/
|
||||
#define BT_GATT_CUD(_value, _perm) \
|
||||
{ \
|
||||
.uuid = BT_UUID_GATT_CUD, \
|
||||
.perm = _perm, \
|
||||
.read = bt_gatt_attr_read_cud, \
|
||||
.user_data = _value, \
|
||||
}
|
||||
|
||||
/** @def BT_GATT_DESCRIPTOR
|
||||
* @brief Descriptor Declaration Macro.
|
||||
*
|
||||
|
|
|
@ -349,6 +349,15 @@ int bt_gatt_attr_read_cep(struct bt_conn *conn,
|
|||
sizeof(props));
|
||||
}
|
||||
|
||||
int bt_gatt_attr_read_cud(struct bt_conn *conn,
|
||||
const struct bt_gatt_attr *attr, void *buf,
|
||||
uint16_t len, uint16_t offset)
|
||||
{
|
||||
char *value = attr->user_data;
|
||||
|
||||
return bt_gatt_attr_read(conn, attr, buf, len, offset, value, strlen(value));
|
||||
}
|
||||
|
||||
struct notify_data {
|
||||
const void *data;
|
||||
size_t len;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue