Bluetooth: GATT: Introduce bt_gatt_attr_get_handle
This introduces bt_gatt_attr_get_handle which can be used to resolve handles of static attributes. Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This commit is contained in:
parent
5c4bde55d0
commit
95cec8354c
2 changed files with 23 additions and 6 deletions
|
@ -394,6 +394,15 @@ static inline void bt_gatt_foreach_attr(uint16_t start_handle, uint16_t end_hand
|
||||||
*/
|
*/
|
||||||
struct bt_gatt_attr *bt_gatt_attr_next(const struct bt_gatt_attr *attr);
|
struct bt_gatt_attr *bt_gatt_attr_next(const struct bt_gatt_attr *attr);
|
||||||
|
|
||||||
|
/** @brief Get Attribute handle.
|
||||||
|
*
|
||||||
|
* @param attr Attribute object.
|
||||||
|
*
|
||||||
|
* @return Handle of the corresponding attribute or zero if the attribute
|
||||||
|
* could not be found.
|
||||||
|
*/
|
||||||
|
uint16_t bt_gatt_attr_get_handle(const struct bt_gatt_attr *attr);
|
||||||
|
|
||||||
/** @brief Get the handle of the characteristic value descriptor.
|
/** @brief Get the handle of the characteristic value descriptor.
|
||||||
*
|
*
|
||||||
* @param attr A Characteristic Attribute
|
* @param attr A Characteristic Attribute
|
||||||
|
|
|
@ -1275,10 +1275,18 @@ static uint8_t get_service_handles(const struct bt_gatt_attr *attr,
|
||||||
return BT_GATT_ITER_CONTINUE;
|
return BT_GATT_ITER_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint16_t find_static_attr(const struct bt_gatt_attr *attr)
|
uint16_t bt_gatt_attr_get_handle(const struct bt_gatt_attr *attr)
|
||||||
{
|
{
|
||||||
uint16_t handle = 1;
|
uint16_t handle = 1;
|
||||||
|
|
||||||
|
if (!attr) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (attr->handle) {
|
||||||
|
return attr->handle;
|
||||||
|
}
|
||||||
|
|
||||||
Z_STRUCT_SECTION_FOREACH(bt_gatt_service_static, static_svc) {
|
Z_STRUCT_SECTION_FOREACH(bt_gatt_service_static, static_svc) {
|
||||||
/* Skip ahead if start is not within service attributes array */
|
/* Skip ahead if start is not within service attributes array */
|
||||||
if ((attr < &static_svc->attrs[0]) ||
|
if ((attr < &static_svc->attrs[0]) ||
|
||||||
|
@ -1302,7 +1310,7 @@ ssize_t bt_gatt_attr_read_included(struct bt_conn *conn,
|
||||||
void *buf, uint16_t len, uint16_t offset)
|
void *buf, uint16_t len, uint16_t offset)
|
||||||
{
|
{
|
||||||
struct bt_gatt_attr *incl = attr->user_data;
|
struct bt_gatt_attr *incl = attr->user_data;
|
||||||
uint16_t handle = incl->handle ? : find_static_attr(incl);
|
uint16_t handle = bt_gatt_attr_get_handle(incl);
|
||||||
struct bt_uuid *uuid = incl->user_data;
|
struct bt_uuid *uuid = incl->user_data;
|
||||||
struct gatt_incl pdu;
|
struct gatt_incl pdu;
|
||||||
uint8_t value_len;
|
uint8_t value_len;
|
||||||
|
@ -1347,7 +1355,7 @@ uint16_t bt_gatt_attr_value_handle(const struct bt_gatt_attr *attr)
|
||||||
handle = chrc->value_handle;
|
handle = chrc->value_handle;
|
||||||
if (handle == 0) {
|
if (handle == 0) {
|
||||||
/* Fall back to Zephyr value handle policy */
|
/* Fall back to Zephyr value handle policy */
|
||||||
handle = (attr->handle ? : find_static_attr(attr)) + 1U;
|
handle = bt_gatt_attr_get_handle(attr) + 1U;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1514,7 +1522,7 @@ static uint8_t find_next(const struct bt_gatt_attr *attr, uint16_t handle,
|
||||||
struct bt_gatt_attr *bt_gatt_attr_next(const struct bt_gatt_attr *attr)
|
struct bt_gatt_attr *bt_gatt_attr_next(const struct bt_gatt_attr *attr)
|
||||||
{
|
{
|
||||||
struct bt_gatt_attr *next = NULL;
|
struct bt_gatt_attr *next = NULL;
|
||||||
uint16_t handle = attr->handle ? : find_static_attr(attr);
|
uint16_t handle = bt_gatt_attr_get_handle(attr);
|
||||||
|
|
||||||
bt_gatt_foreach_attr(handle + 1, handle + 1, find_next, &next);
|
bt_gatt_foreach_attr(handle + 1, handle + 1, find_next, &next);
|
||||||
|
|
||||||
|
@ -2068,7 +2076,7 @@ int bt_gatt_notify_cb(struct bt_conn *conn,
|
||||||
return -ENOTCONN;
|
return -ENOTCONN;
|
||||||
}
|
}
|
||||||
|
|
||||||
found.handle = found.attr->handle ? : find_static_attr(found.attr);
|
found.handle = bt_gatt_attr_get_handle(found.attr);
|
||||||
if (!found.handle) {
|
if (!found.handle) {
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
|
@ -2145,7 +2153,7 @@ int bt_gatt_indicate(struct bt_conn *conn,
|
||||||
return -ENOTCONN;
|
return -ENOTCONN;
|
||||||
}
|
}
|
||||||
|
|
||||||
found.handle = found.attr->handle ? : find_static_attr(found.attr);
|
found.handle = bt_gatt_attr_get_handle(found.attr);
|
||||||
if (!found.handle) {
|
if (!found.handle) {
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue