diff options
author | Marcin Kraglak <marcin.kraglak@tieto.com> | 2014-10-23 12:15:29 +0200 |
---|---|---|
committer | Szymon Janc <szymon.janc@tieto.com> | 2014-10-23 14:45:52 +0200 |
commit | b4b9c9d5037676eced3306e584076737097fbbfa (patch) | |
tree | 323a09c5933a42e741314ba28b5d3c5f83249e54 /src | |
parent | 4ed0d8f4257d727076c3113c2cbc1fe13ed66bbb (diff) | |
download | bluez-b4b9c9d5037676eced3306e584076737097fbbfa.tar.gz |
shared/gatt: Add function bt_gatt_result_included_count()
It will return number of included services in result.
Diffstat (limited to 'src')
-rw-r--r-- | src/shared/gatt-helpers.c | 28 | ||||
-rw-r--r-- | src/shared/gatt-helpers.h | 1 |
2 files changed, 29 insertions, 0 deletions
diff --git a/src/shared/gatt-helpers.c b/src/shared/gatt-helpers.c index 1516e79c2..f993243d9 100644 --- a/src/shared/gatt-helpers.c +++ b/src/shared/gatt-helpers.c @@ -147,6 +147,34 @@ unsigned int bt_gatt_result_descriptor_count(struct bt_gatt_result *result) return result_element_count(result); } +unsigned int bt_gatt_result_included_count(struct bt_gatt_result *result) +{ + struct bt_gatt_result *cur; + unsigned int count = 0; + + if (!result) + return 0; + + if (result->opcode != BT_ATT_OP_READ_BY_TYPE_RSP) + return 0; + + /* + * Data length can be of length 6 or 8 octets: + * 2 octets - include service handle + * 2 octets - start handle of included service + * 2 octets - end handle of included service + * 2 octets (optionally) - 16 bit Bluetooth UUID + */ + if (result->data_len != 6 && result->data_len != 8) + return 0; + + for (cur = result; cur; cur = cur->next) + if (cur->opcode == BT_ATT_OP_READ_BY_TYPE_RSP) + count += cur->pdu_len / cur->data_len; + + return count; +} + bool bt_gatt_iter_init(struct bt_gatt_iter *iter, struct bt_gatt_result *result) { if (!iter || !result) diff --git a/src/shared/gatt-helpers.h b/src/shared/gatt-helpers.h index 8c434c1a3..df003ac3f 100644 --- a/src/shared/gatt-helpers.h +++ b/src/shared/gatt-helpers.h @@ -38,6 +38,7 @@ struct bt_gatt_iter { unsigned int bt_gatt_result_service_count(struct bt_gatt_result *result); unsigned int bt_gatt_result_characteristic_count(struct bt_gatt_result *result); unsigned int bt_gatt_result_descriptor_count(struct bt_gatt_result *result); +unsigned int bt_gatt_result_included_count(struct bt_gatt_result *result); bool bt_gatt_iter_init(struct bt_gatt_iter *iter, struct bt_gatt_result *result); bool bt_gatt_iter_next_service(struct bt_gatt_iter *iter, |