Bluetooth: GATT: Add BT_GATT_DISCOVER_ATTRIBUTE type

This adds BT_GATT_DISCOVER_ATTRIBUTE which can be used to discover any
type of attribute in a given range.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This commit is contained in:
Luiz Augusto von Dentz 2019-03-13 10:09:41 +02:00 committed by Johan Hedberg
commit bcf3d8e16b
2 changed files with 30 additions and 15 deletions

View file

@ -887,6 +887,15 @@ enum {
* as it may incur in extra round trips.
*/
BT_GATT_DISCOVER_DESCRIPTOR,
/** Discover Attributes.
*
* Discover Attributes of any type.
*
* Note: The use of this type of discover is not recommended for
* discovering in ranges across multiple services/characteristics as
* it may incur in more round trips.
*/
BT_GATT_DISCOVER_ATTRIBUTE,
};
/** @brief GATT Discover Attributes parameters */

View file

@ -2252,22 +2252,26 @@ static void gatt_find_info_rsp(struct bt_conn *conn, u8_t err,
continue;
}
/* Skip attributes that are not considered descriptors */
if (!bt_uuid_cmp(&u.uuid, BT_UUID_GATT_PRIMARY) ||
!bt_uuid_cmp(&u.uuid, BT_UUID_GATT_SECONDARY) ||
!bt_uuid_cmp(&u.uuid, BT_UUID_GATT_INCLUDE)) {
continue;
}
/* If Characteristic Declaration skip ahead as the next entry
* must be its value.
*/
if (!bt_uuid_cmp(&u.uuid, bt_uuid_gatt_chrc)) {
if (length >= len) {
pdu = (const u8_t *)pdu + len;
length -= len;
if (params->type == BT_GATT_DISCOVER_DESCRIPTOR) {
/* Skip attributes that are not considered
* descriptors.
*/
if (!bt_uuid_cmp(&u.uuid, BT_UUID_GATT_PRIMARY) ||
!bt_uuid_cmp(&u.uuid, BT_UUID_GATT_SECONDARY) ||
!bt_uuid_cmp(&u.uuid, BT_UUID_GATT_INCLUDE)) {
continue;
}
/* If Characteristic Declaration skip ahead as the next
* entry must be its value.
*/
if (!bt_uuid_cmp(&u.uuid, BT_UUID_GATT_CHRC)) {
if (length >= len) {
pdu = (const u8_t *)pdu + len;
length -= len;
}
continue;
}
continue;
}
attr = (&(struct bt_gatt_attr)
@ -2345,6 +2349,8 @@ int bt_gatt_discover(struct bt_conn *conn,
!bt_uuid_cmp(params->uuid, BT_UUID_GATT_CHRC)) {
return -EINVAL;
}
/* Fallthrough. */
case BT_GATT_DISCOVER_ATTRIBUTE:
return gatt_find_info(conn, params);
default:
BT_ERR("Invalid discovery type: %u", params->type);