Bluetooth: GATT: Use UUID of attribute to check for a characteristic

Update check in the bt_gatt_attr_value_handle API function to use the
UUID of the function, in case the attribute has been declared with a
different read handler, or the attribute is a temporary object
where the read attribute has not been set.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
This commit is contained in:
Joakim Andersson 2020-10-13 15:48:11 +02:00 committed by Carles Cufí
commit 24f62eeea1
2 changed files with 4 additions and 3 deletions

View file

@ -403,7 +403,9 @@ 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.
*
* @note The user_data of the attribute must of type @ref bt_gatt_chrc.
* *
* @return the handle of the corresponding Characteristic Value. The value will * @return the handle of the corresponding Characteristic Value. The value will
* be zero (the invalid handle) if @p attr was not a characteristic * be zero (the invalid handle) if @p attr was not a characteristic

View file

@ -1363,8 +1363,7 @@ uint16_t bt_gatt_attr_value_handle(const struct bt_gatt_attr *attr)
{ {
uint16_t handle = 0; uint16_t handle = 0;
if ((attr != NULL) if (attr != NULL && bt_uuid_cmp(attr->uuid, BT_UUID_GATT_CHRC) == 0) {
&& (attr->read == bt_gatt_attr_read_chrc)) {
struct bt_gatt_chrc *chrc = attr->user_data; struct bt_gatt_chrc *chrc = attr->user_data;
handle = chrc->value_handle; handle = chrc->value_handle;