Bluetooth: GATT: Allow Characterist to be used with bt_gatt_notify

Since BT_GATT_CHARACTERISTIC now expands to 2 attributes it may be
confusing to use bt_gatt_notify 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:41:34 +03:00 committed by Anas Nashif
commit c3edc82fe7
2 changed files with 22 additions and 8 deletions

View file

@ -683,12 +683,14 @@ ssize_t bt_gatt_attr_read_cpf(struct bt_conn *conn,
* all peer that have notification enabled via CCC otherwise do a direct
* notification only the given connection.
*
* The attribute object must be the so called Characteristic Value Descriptor,
* its usually declared with BT_GATT_DESCRIPTOR after BT_GATT_CHARACTERISTIC
* and before BT_GATT_CCC.
* The attribute object can be the so called Characteristic Declaration,
* which is usually declared with BT_GATT_CHARACTERISTIC followed by
* BT_GATT_CCC, or the Characteristic Value Declaration which is automatically
* created after the Characteristic Declaration when using
* BT_GATT_CHARACTERISTIC.
*
* @param conn Connection object.
* @param attr Characteristic Value Descriptor attribute.
* @param attr Characteristic or Characteristic Value attribute.
* @param data Pointer to Attribute data.
* @param len Attribute value length.
*/

View file

@ -786,7 +786,7 @@ static u8_t notify_cb(const struct bt_gatt_attr *attr, void *user_data)
if (data->type == BT_GATT_CCC_INDICATE) {
err = gatt_indicate(conn, data->params);
} else {
err = gatt_notify(conn, data->attr->handle, data->data,
err = gatt_notify(conn, attr->handle, data->data,
data->len);
}
@ -806,11 +806,23 @@ int bt_gatt_notify(struct bt_conn *conn, const struct bt_gatt_attr *attr,
const void *data, u16_t len)
{
struct notify_data nfy;
u16_t value_handle = attr->handle;
__ASSERT(attr && attr->handle, "invalid parameters\n");
/* Check if attribute is a characteristic then adjust the handle */
if (!bt_uuid_cmp(attr->uuid, BT_UUID_GATT_CHRC)) {
struct bt_gatt_chrc *chrc = attr->user_data;
if (!(chrc->properties & BT_GATT_CHRC_NOTIFY)) {
return -EINVAL;
}
value_handle += 1;
}
if (conn) {
return gatt_notify(conn, attr->handle, data, len);
return gatt_notify(conn, attr->handle + 1, data, len);
}
nfy.err = -ENOTCONN;
@ -819,7 +831,7 @@ int bt_gatt_notify(struct bt_conn *conn, const struct bt_gatt_attr *attr,
nfy.data = data;
nfy.len = len;
bt_gatt_foreach_attr(attr->handle, 0xffff, notify_cb, &nfy);
bt_gatt_foreach_attr(value_handle, 0xffff, notify_cb, &nfy);
return nfy.err;
}