Bluetooth: GATT: Allow Characterist to be used with bt_gatt_indicate

Since BT_GATT_CHARACTERISTIC now expands to 2 attributes it may be
confusing to use bt_gatt_indicate as that expects the Value attribute to
be given which is no longer visible, so this enables the user to use
the Characteristic attribute in addition to its value.

Fixes #8231

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This commit is contained in:
Luiz Augusto von Dentz 2018-06-07 12:58:05 +03:00 committed by Anas Nashif
commit 679a0b395f

View file

@ -685,6 +685,18 @@ static int gatt_indicate(struct bt_conn *conn,
{
struct net_buf *buf;
struct bt_att_indicate *ind;
u16_t value_handle = params->attr->handle;
/* Check if attribute is a characteristic then adjust the handle */
if (!bt_uuid_cmp(params->attr->uuid, BT_UUID_GATT_CHRC)) {
struct bt_gatt_chrc *chrc = params->attr->user_data;
if (!(chrc->properties & BT_GATT_CHRC_INDICATE)) {
return -EINVAL;
}
value_handle += 1;
}
buf = bt_att_create_pdu(conn, BT_ATT_OP_INDICATE,
sizeof(*ind) + params->len);
@ -693,10 +705,10 @@ static int gatt_indicate(struct bt_conn *conn,
return -ENOMEM;
}
BT_DBG("conn %p handle 0x%04x", conn, params->attr->handle);
BT_DBG("conn %p handle 0x%04x", conn, value_handle);
ind = net_buf_add(buf, sizeof(*ind));
ind->handle = sys_cpu_to_le16(params->attr->handle);
ind->handle = sys_cpu_to_le16(value_handle);
net_buf_add(buf, params->len);
memcpy(ind->value, params->data, params->len);