Bluetooth: add CPF descriptor support
In order to support more standard descriptors, the PF macro and helper function are added. Change-Id: I52db3c32f40f39b9c6bfdb9573d0a614d0f3295e Signed-off-by: Louis Caron <louis.caron@intel.com>
This commit is contained in:
parent
d566c3314b
commit
7fdb42a46f
3 changed files with 62 additions and 0 deletions
|
@ -212,6 +212,20 @@ struct bt_gatt_ccc {
|
||||||
uint16_t flags;
|
uint16_t flags;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** @brief GATT Characteristic Presentation Format Attribute Value. */
|
||||||
|
struct bt_gatt_cpf {
|
||||||
|
/** Format of the value of the characteristic */
|
||||||
|
uint8_t format;
|
||||||
|
/** Exponent field to determine how the value of this characteristic is further formatted */
|
||||||
|
int8_t exponent;
|
||||||
|
/** Unit of the characteristic */
|
||||||
|
uint16_t unit;
|
||||||
|
/** Name space of the description */
|
||||||
|
uint8_t name_space;
|
||||||
|
/** Description of the characteristic as defined in a higher layer profile */
|
||||||
|
uint16_t description;
|
||||||
|
} __packed;
|
||||||
|
|
||||||
/* Server API */
|
/* Server API */
|
||||||
|
|
||||||
/** @brief Register attribute database.
|
/** @brief Register attribute database.
|
||||||
|
@ -552,6 +566,40 @@ int bt_gatt_attr_read_cud(struct bt_conn *conn,
|
||||||
.user_data = _value, \
|
.user_data = _value, \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @brief Read Characteristic Presentation format Descriptor Attribute helper
|
||||||
|
*
|
||||||
|
* Read CPF attribute value storing the result into buffer after
|
||||||
|
* encoding it.
|
||||||
|
* NOTE: Only use this with attributes which user_data is a bt_gatt_pf.
|
||||||
|
*
|
||||||
|
* @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_cpf(struct bt_conn *conn,
|
||||||
|
const struct bt_gatt_attr *attr, void *buf,
|
||||||
|
uint16_t len, uint16_t offset);
|
||||||
|
|
||||||
|
/** @def BT_GATT_CPF
|
||||||
|
* @brief Characteristic Presentation Format Descriptor Declaration Macro.
|
||||||
|
*
|
||||||
|
* Helper macro to declare a CPF attribute.
|
||||||
|
*
|
||||||
|
* @param _value Descriptor attribute value.
|
||||||
|
*/
|
||||||
|
#define BT_GATT_CPF(_value) \
|
||||||
|
{ \
|
||||||
|
.uuid = BT_UUID_GATT_CPF, \
|
||||||
|
.perm = BT_GATT_PERM_READ, \
|
||||||
|
.read = bt_gatt_attr_read_cpf, \
|
||||||
|
.user_data = _value, \
|
||||||
|
}
|
||||||
|
|
||||||
/** @def BT_GATT_DESCRIPTOR
|
/** @def BT_GATT_DESCRIPTOR
|
||||||
* @brief Descriptor Declaration Macro.
|
* @brief Descriptor Declaration Macro.
|
||||||
*
|
*
|
||||||
|
|
|
@ -80,6 +80,10 @@
|
||||||
* @brief GATT Server Characteristic Configuration
|
* @brief GATT Server Characteristic Configuration
|
||||||
*/
|
*/
|
||||||
#define BT_UUID_GATT_SCC BT_UUID_DECLARE_16(0x2903)
|
#define BT_UUID_GATT_SCC BT_UUID_DECLARE_16(0x2903)
|
||||||
|
/** @def BT_UUID_GATT_CPF
|
||||||
|
* @brief GATT Characteristic Presentation Format
|
||||||
|
*/
|
||||||
|
#define BT_UUID_GATT_CPF BT_UUID_DECLARE_16(0x2904)
|
||||||
/** @def BT_UUID_GAP_DEVICE_NAME
|
/** @def BT_UUID_GAP_DEVICE_NAME
|
||||||
* @brief GAP Characteristic Device Name
|
* @brief GAP Characteristic Device Name
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -358,6 +358,16 @@ int bt_gatt_attr_read_cud(struct bt_conn *conn,
|
||||||
return bt_gatt_attr_read(conn, attr, buf, len, offset, value, strlen(value));
|
return bt_gatt_attr_read(conn, attr, buf, len, offset, value, strlen(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int bt_gatt_attr_read_cpf(struct bt_conn *conn,
|
||||||
|
const struct bt_gatt_attr *attr, void *buf,
|
||||||
|
uint16_t len, uint16_t offset)
|
||||||
|
{
|
||||||
|
struct bt_gatt_cpf *value = attr->user_data;
|
||||||
|
|
||||||
|
return bt_gatt_attr_read(conn, attr, buf, len, offset, value,
|
||||||
|
sizeof(*value));
|
||||||
|
}
|
||||||
|
|
||||||
struct notify_data {
|
struct notify_data {
|
||||||
const void *data;
|
const void *data;
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue