From 76deb657d7dee79c8a2aede32f1db536177339cf Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Mon, 11 Mar 2019 23:07:10 +0200 Subject: [PATCH] Bluetooth: GATT: Skip certain attributes when discovering descriptors When discovering descriptor Find Information procedure is used which does not allow any filtering by the server so it will return all attributes in the given range including services and characteristics. Fixes #14265 Signed-off-by: Luiz Augusto von Dentz --- subsys/bluetooth/host/gatt.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/subsys/bluetooth/host/gatt.c b/subsys/bluetooth/host/gatt.c index 1e4ed4a3128..6d4b5024f67 100644 --- a/subsys/bluetooth/host/gatt.c +++ b/subsys/bluetooth/host/gatt.c @@ -2252,6 +2252,14 @@ 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) || + !bt_uuid_cmp(&u.uuid, BT_UUID_GATT_CHRC)) { + continue; + } + attr = (&(struct bt_gatt_attr) BT_GATT_DESCRIPTOR(&u.uuid, 0, NULL, NULL, NULL)); attr->handle = handle; @@ -2320,6 +2328,13 @@ int bt_gatt_discover(struct bt_conn *conn, case BT_GATT_DISCOVER_CHARACTERISTIC: return gatt_read_type(conn, params); case BT_GATT_DISCOVER_DESCRIPTOR: + /* Only descriptors can be filtered */ + if (!bt_uuid_cmp(params->uuid, BT_UUID_GATT_PRIMARY) || + !bt_uuid_cmp(params->uuid, BT_UUID_GATT_SECONDARY) || + !bt_uuid_cmp(params->uuid, BT_UUID_GATT_INCLUDE) || + !bt_uuid_cmp(params->uuid, BT_UUID_GATT_CHRC)) { + return -EINVAL; + } return gatt_find_info(conn, params); default: BT_ERR("Invalid discovery type: %u", params->type);